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/stringprintf.h>
20 #include <fstab/fstab.h>
21 #include <gtest/gtest.h>
22
23 static constexpr const char kMetadata[] = "/metadata";
24
TEST(Metadata,IsExt4)25 TEST(Metadata, IsExt4) {
26 struct statfs buf;
27 ASSERT_EQ(0, statfs(kMetadata, &buf))
28 << "Cannot statfs " << kMetadata << ": " << strerror(errno);
29 ASSERT_EQ(EXT4_SUPER_MAGIC, buf.f_type);
30 }
31
TEST(Metadata,FstabEntryFlagsAreSet)32 TEST(Metadata, FstabEntryFlagsAreSet) {
33 android::fs_mgr::Fstab fstab;
34 ASSERT_TRUE(android::fs_mgr::ReadDefaultFstab(&fstab));
35
36 auto metadata_entry =
37 android::fs_mgr::GetEntryForMountPoint(&fstab, kMetadata);
38 ASSERT_NE(metadata_entry, nullptr)
39 << "Cannot find fstab entry for " << kMetadata;
40
41 const char* message_fmt = "Fstab entry for /metadata must have %s flag set.";
42
43 EXPECT_TRUE(metadata_entry->fs_mgr_flags.check)
44 << android::base::StringPrintf(message_fmt, "check");
45 EXPECT_TRUE(metadata_entry->fs_mgr_flags.formattable)
46 << android::base::StringPrintf(message_fmt, "formattable");
47 EXPECT_TRUE(metadata_entry->fs_mgr_flags.first_stage_mount)
48 << android::base::StringPrintf(message_fmt, "first_stage_mount");
49 EXPECT_TRUE(metadata_entry->fs_mgr_flags.wait)
50 << android::base::StringPrintf(message_fmt, "wait");
51 }
52