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,IsExt4)26 TEST(Metadata, IsExt4) {
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 if (vsr_level < __ANDROID_API_T__) {
33 ASSERT_EQ(EXT4_SUPER_MAGIC, buf.f_type);
34 } else {
35 ASSERT_EQ(F2FS_SUPER_MAGIC, buf.f_type);
36 }
37 }
38
TEST(Metadata,FstabEntryFlagsAreSet)39 TEST(Metadata, FstabEntryFlagsAreSet) {
40 android::fs_mgr::Fstab fstab;
41 ASSERT_TRUE(android::fs_mgr::ReadDefaultFstab(&fstab));
42
43 auto metadata_entry =
44 android::fs_mgr::GetEntryForMountPoint(&fstab, kMetadata);
45 ASSERT_NE(metadata_entry, nullptr)
46 << "Cannot find fstab entry for " << kMetadata;
47
48 const char* message_fmt = "Fstab entry for /metadata must have %s flag set.";
49
50 EXPECT_TRUE(metadata_entry->fs_mgr_flags.check)
51 << android::base::StringPrintf(message_fmt, "check");
52 EXPECT_TRUE(metadata_entry->fs_mgr_flags.formattable)
53 << android::base::StringPrintf(message_fmt, "formattable");
54 EXPECT_TRUE(metadata_entry->fs_mgr_flags.first_stage_mount)
55 << android::base::StringPrintf(message_fmt, "first_stage_mount");
56 EXPECT_TRUE(metadata_entry->fs_mgr_flags.wait)
57 << android::base::StringPrintf(message_fmt, "wait");
58 }
59