• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2019 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include <linux/fs.h>
18 #include <sys/stat.h>
19 #include <sys/sysmacros.h>
20 #include <sys/types.h>
21 #include <sys/vfs.h>
22 #include <unistd.h>
23 
24 #include <android-base/properties.h>
25 #include <android-base/unique_fd.h>
26 #include <android/hardware/weaver/1.0/IWeaver.h>
27 #include <ext4_utils/ext4_utils.h>
28 #include <fstab/fstab.h>
29 #include <gtest/gtest.h>
30 
31 using namespace android::fs_mgr;
32 
33 using android::base::unique_fd;
34 using android::hardware::weaver::V1_0::IWeaver;
35 using android::hardware::weaver::V1_0::WeaverConfig;
36 using android::hardware::weaver::V1_0::WeaverStatus;
37 
TEST(MetadataPartition,FirstStageMount)38 TEST(MetadataPartition, FirstStageMount) {
39     Fstab fstab;
40     if (ReadFstabFromDt(&fstab)) {
41         auto entry = GetEntryForMountPoint(&fstab, "/metadata");
42         ASSERT_NE(entry, nullptr);
43     } else {
44         ASSERT_TRUE(ReadDefaultFstab(&fstab));
45         auto entry = GetEntryForMountPoint(&fstab, "/metadata");
46         ASSERT_NE(entry, nullptr);
47         EXPECT_TRUE(entry->fs_mgr_flags.first_stage_mount);
48     }
49 }
50 
GetVsrLevel()51 static int GetVsrLevel() {
52     return android::base::GetIntProperty("ro.vendor.api_level", -1);
53 }
54 
TEST(MetadataPartition,MinimumSize)55 TEST(MetadataPartition, MinimumSize) {
56     Fstab fstab;
57     ASSERT_TRUE(ReadDefaultFstab(&fstab));
58 
59     auto entry = GetEntryForMountPoint(&fstab, "/metadata");
60     ASSERT_NE(entry, nullptr);
61 
62     unique_fd fd(open(entry->blk_device.c_str(), O_RDONLY | O_CLOEXEC));
63     ASSERT_GE(fd, 0);
64 
65     uint64_t size = get_block_device_size(fd);
66     ASSERT_GE(size, 16777216);
67 }
68 
TEST(Weaver,MinimumSlots)69 TEST(Weaver, MinimumSlots) {
70     auto weaver = IWeaver::getService();
71     if (!weaver) {
72         return;
73     }
74 
75     WeaverStatus hw_status;
76     WeaverConfig hw_config;
77 
78     auto res = weaver->getConfig([&](WeaverStatus status, const WeaverConfig& config) {
79             hw_status = status;
80             hw_config = config;
81     });
82     ASSERT_TRUE(res.isOk());
83     ASSERT_EQ(hw_status, WeaverStatus::OK);
84     EXPECT_GE(hw_config.slots, 16);
85 }
86 
TEST(MetadataPartition,FsType)87 TEST(MetadataPartition, FsType) {
88     if (GetVsrLevel() < __ANDROID_API_T__) {
89         GTEST_SKIP();
90     }
91 
92     Fstab fstab;
93     ASSERT_TRUE(ReadDefaultFstab(&fstab));
94 
95     std::vector<std::string> mount_points = {"/data"};
96     for (const auto& mount_point : mount_points) {
97         auto path = mount_point + "/gsi";
98 
99         // These paths should not be symlinks.
100         struct stat s;
101         ASSERT_GE(lstat(path.c_str(), &s), 0) << path;
102         ASSERT_FALSE(S_ISLNK(s.st_mode));
103 
104         struct statfs64 fs;
105         ASSERT_GE(statfs64(path.c_str(), &fs), 0) << path;
106         ASSERT_EQ(fs.f_type, F2FS_SUPER_MAGIC);
107 
108         auto entry = GetEntryForMountPoint(&fstab, mount_point);
109         ASSERT_NE(entry, nullptr);
110         ASSERT_EQ(entry->fs_type, "f2fs");
111     }
112 }
113