1 /*
2 * Copyright (C) 2020 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 <sys/statfs.h>
18
19 #include <android-base/properties.h>
20 #include <android-base/stringprintf.h>
21 #include <fstab/fstab.h>
22 #include <gtest/gtest.h>
23
24 static constexpr const char kMetadata[] = "/metadata";
25
TEST(Metadata,Filesystem)26 TEST(Metadata, Filesystem) {
27 struct statfs buf;
28 ASSERT_EQ(0, statfs(kMetadata, &buf))
29 << "Cannot statfs " << kMetadata << ": " << strerror(errno);
30
31 int vsr_level = android::base::GetIntProperty("ro.vendor.api_level", -1);
32
33 bool is_ext4 = (buf.f_type == EXT4_SUPER_MAGIC);
34 bool is_f2fs = (buf.f_type == F2FS_SUPER_MAGIC);
35 if (vsr_level < __ANDROID_API_T__) {
36 ASSERT_TRUE(is_ext4) << "Filesystem magic: " << std::to_string(buf.f_type);
37 } else {
38 ASSERT_TRUE(is_ext4 || is_f2fs)
39 << "Filesystem magic: " << std::to_string(buf.f_type);
40 }
41 }
42
TEST(Metadata,FstabEntryFlagsAreSet)43 TEST(Metadata, FstabEntryFlagsAreSet) {
44 android::fs_mgr::Fstab fstab;
45 ASSERT_TRUE(android::fs_mgr::ReadDefaultFstab(&fstab));
46
47 auto metadata_entry =
48 android::fs_mgr::GetEntryForMountPoint(&fstab, kMetadata);
49 ASSERT_NE(metadata_entry, nullptr)
50 << "Cannot find fstab entry for " << kMetadata;
51
52 const char* message_fmt = "Fstab entry for /metadata must have %s flag set.";
53
54 EXPECT_TRUE(metadata_entry->fs_mgr_flags.check)
55 << android::base::StringPrintf(message_fmt, "check");
56 EXPECT_TRUE(metadata_entry->fs_mgr_flags.formattable)
57 << android::base::StringPrintf(message_fmt, "formattable");
58 EXPECT_TRUE(metadata_entry->fs_mgr_flags.first_stage_mount)
59 << android::base::StringPrintf(message_fmt, "first_stage_mount");
60 EXPECT_TRUE(metadata_entry->fs_mgr_flags.wait)
61 << android::base::StringPrintf(message_fmt, "wait");
62 }
63