Merge "Update fs_mgr tests for new fstab format and add to TEST_MAPPING"

This commit is contained in:
Tom Cherry 2019-01-25 17:25:58 +00:00 committed by Gerrit Code Review
commit afa0d88eea
2 changed files with 21 additions and 21 deletions

View file

@ -6,6 +6,9 @@
{ {
"name": "debuggerd_test" "name": "debuggerd_test"
}, },
{
"name": "fs_mgr_unit_test"
},
{ {
"name": "init_tests" "name": "init_tests"
}, },

View file

@ -138,38 +138,32 @@ TEST(fs_mgr, fs_mgr_get_boot_config_from_kernel_cmdline) {
} }
TEST(fs_mgr, fs_mgr_read_fstab_file_proc_mounts) { TEST(fs_mgr, fs_mgr_read_fstab_file_proc_mounts) {
auto fstab = fs_mgr_read_fstab("/proc/mounts"); Fstab fstab;
ASSERT_NE(fstab, nullptr); ASSERT_TRUE(ReadFstabFromFile("/proc/mounts", &fstab));
std::unique_ptr<std::FILE, int (*)(std::FILE*)> mounts(setmntent("/proc/mounts", "re"), std::unique_ptr<std::FILE, int (*)(std::FILE*)> mounts(setmntent("/proc/mounts", "re"),
endmntent); endmntent);
ASSERT_NE(mounts, nullptr); ASSERT_NE(mounts, nullptr);
mntent* mentry; mntent* mentry;
int i = 0; size_t i = 0;
while ((mentry = getmntent(mounts.get())) != nullptr) { while ((mentry = getmntent(mounts.get())) != nullptr) {
ASSERT_LT(i, fstab->num_entries); ASSERT_LT(i, fstab.size());
auto fsrec = &fstab->recs[i]; auto& entry = fstab[i];
std::string mnt_fsname(mentry->mnt_fsname ?: "nullptr"); EXPECT_EQ(mentry->mnt_fsname, entry.blk_device);
std::string blk_device(fsrec->blk_device ?: "nullptr"); EXPECT_EQ(mentry->mnt_dir, entry.mount_point);
EXPECT_EQ(mnt_fsname, blk_device); EXPECT_EQ(mentry->mnt_type, entry.fs_type);
std::string mnt_dir(mentry->mnt_dir ?: "nullptr");
std::string mount_point(fsrec->mount_point ?: "nullptr");
EXPECT_EQ(mnt_dir, mount_point);
std::string mnt_type(mentry->mnt_type ?: "nullptr");
std::string fs_type(fsrec->fs_type ?: "nullptr");
EXPECT_EQ(mnt_type, fs_type);
std::set<std::string> mnt_opts; std::set<std::string> mnt_opts;
for (auto& s : android::base::Split(mentry->mnt_opts ?: "nullptr", ",")) { for (auto& s : android::base::Split(mentry->mnt_opts, ",")) {
mnt_opts.emplace(s); mnt_opts.emplace(s);
} }
std::set<std::string> fs_options; std::set<std::string> fs_options;
for (auto& s : android::base::Split(fsrec->fs_options ?: "nullptr", ",")) { if (!entry.fs_options.empty()) {
fs_options.emplace(s); for (auto& s : android::base::Split(entry.fs_options, ",")) {
fs_options.emplace(s);
}
} }
// matches private content in fs_mgr_fstab.c // matches private content in fs_mgr_fstab.c
static struct flag_list { static struct flag_list {
@ -194,14 +188,17 @@ TEST(fs_mgr, fs_mgr_read_fstab_file_proc_mounts) {
{0, 0}, {0, 0},
}; };
for (auto f = 0; mount_flags[f].name; ++f) { for (auto f = 0; mount_flags[f].name; ++f) {
if (mount_flags[f].flag & fsrec->flags) { if (mount_flags[f].flag & entry.flags) {
fs_options.emplace(mount_flags[f].name); fs_options.emplace(mount_flags[f].name);
} }
} }
if (!(fsrec->flags & MS_RDONLY)) fs_options.emplace("rw"); if (!(entry.flags & MS_RDONLY)) {
fs_options.emplace("rw");
}
EXPECT_EQ(mnt_opts, fs_options); EXPECT_EQ(mnt_opts, fs_options);
++i; ++i;
} }
EXPECT_EQ(i, fstab.size());
} }
TEST(fs_mgr, ReadFstabFromFile_FsOptions) { TEST(fs_mgr, ReadFstabFromFile_FsOptions) {