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