summaryrefslogtreecommitdiff
path: root/tests/boot_tests.cpp
blob: 6aeded38ac46e2defc8710910a523da3d2e0cbf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// Copyright (C) 2019 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include <linux/fs.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <sys/vfs.h>
#include <unistd.h>

#include <android-base/properties.h>
#include <android-base/unique_fd.h>
#include <android/hardware/weaver/1.0/IWeaver.h>
#include <ext4_utils/ext4_utils.h>
#include <fstab/fstab.h>
#include <gtest/gtest.h>

using namespace android::fs_mgr;

using android::base::unique_fd;
using android::hardware::weaver::V1_0::IWeaver;
using android::hardware::weaver::V1_0::WeaverConfig;
using android::hardware::weaver::V1_0::WeaverStatus;

TEST(MetadataPartition, FirstStageMount) {
    Fstab fstab;
    if (ReadFstabFromDt(&fstab)) {
        auto entry = GetEntryForMountPoint(&fstab, "/metadata");
        ASSERT_NE(entry, nullptr);
    } else {
        ASSERT_TRUE(ReadDefaultFstab(&fstab));
        auto entry = GetEntryForMountPoint(&fstab, "/metadata");
        ASSERT_NE(entry, nullptr);
        EXPECT_TRUE(entry->fs_mgr_flags.first_stage_mount);
    }
}

static int GetVsrLevel() {
    return android::base::GetIntProperty("ro.vendor.api_level", -1);
}

TEST(MetadataPartition, MinimumSize) {
    Fstab fstab;
    ASSERT_TRUE(ReadDefaultFstab(&fstab));

    auto entry = GetEntryForMountPoint(&fstab, "/metadata");
    ASSERT_NE(entry, nullptr);

    unique_fd fd(open(entry->blk_device.c_str(), O_RDONLY | O_CLOEXEC));
    ASSERT_GE(fd, 0);

    uint64_t size = get_block_device_size(fd);
    ASSERT_GE(size, 16777216);
}

TEST(Weaver, MinimumSlots) {
    auto weaver = IWeaver::getService();
    if (!weaver) {
        return;
    }

    WeaverStatus hw_status;
    WeaverConfig hw_config;

    auto res = weaver->getConfig([&](WeaverStatus status, const WeaverConfig& config) {
            hw_status = status;
            hw_config = config;
    });
    ASSERT_TRUE(res.isOk());
    ASSERT_EQ(hw_status, WeaverStatus::OK);
    EXPECT_GE(hw_config.slots, 16);
}

TEST(MetadataPartition, FsType) {
    if (GetVsrLevel() < __ANDROID_API_T__) {
        GTEST_SKIP();
    }

    Fstab fstab;
    ASSERT_TRUE(ReadDefaultFstab(&fstab));

    std::vector<std::string> mount_points = {"/data"};
    for (const auto& mount_point : mount_points) {
        auto path = mount_point + "/gsi";

        // These paths should not be symlinks.
        struct stat s;
        ASSERT_GE(lstat(path.c_str(), &s), 0) << path;
        ASSERT_FALSE(S_ISLNK(s.st_mode));

        struct statfs64 fs;
        ASSERT_GE(statfs64(path.c_str(), &fs), 0) << path;
        ASSERT_EQ(fs.f_type, F2FS_SUPER_MAGIC);

        auto entry = GetEntryForMountPoint(&fstab, mount_point);
        ASSERT_NE(entry, nullptr);
        ASSERT_EQ(entry->fs_type, "f2fs");
    }
}