From 4e904768f79e5a938874d4364e1354979ca08b1a Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Wed, 23 Jan 2019 11:24:33 -0800 Subject: [PATCH] Update fs_mgr tests for new fstab format and add to TEST_MAPPING And fix a bug in the meantime, where mounts with no filesystem specific mount options were incorrectly having an empty string in their set of mount options. Test: this test Change-Id: I9b1f14d00a90f8b95a13fcecb3cfa7fe10a2f96a --- TEST_MAPPING | 3 +++ fs_mgr/tests/fs_mgr_test.cpp | 39 +++++++++++++++++------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/TEST_MAPPING b/TEST_MAPPING index f9c3b4adc..bc5685b39 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -6,6 +6,9 @@ { "name": "debuggerd_test" }, + { + "name": "fs_mgr_unit_test" + }, { "name": "init_tests" }, diff --git a/fs_mgr/tests/fs_mgr_test.cpp b/fs_mgr/tests/fs_mgr_test.cpp index 1922a69e2..458240198 100644 --- a/fs_mgr/tests/fs_mgr_test.cpp +++ b/fs_mgr/tests/fs_mgr_test.cpp @@ -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) { - auto fstab = fs_mgr_read_fstab("/proc/mounts"); - ASSERT_NE(fstab, nullptr); + Fstab fstab; + ASSERT_TRUE(ReadFstabFromFile("/proc/mounts", &fstab)); std::unique_ptr mounts(setmntent("/proc/mounts", "re"), endmntent); ASSERT_NE(mounts, nullptr); mntent* mentry; - int i = 0; + size_t i = 0; while ((mentry = getmntent(mounts.get())) != nullptr) { - ASSERT_LT(i, fstab->num_entries); - auto fsrec = &fstab->recs[i]; + ASSERT_LT(i, fstab.size()); + auto& entry = fstab[i]; - std::string mnt_fsname(mentry->mnt_fsname ?: "nullptr"); - std::string blk_device(fsrec->blk_device ?: "nullptr"); - EXPECT_EQ(mnt_fsname, blk_device); - - 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); + EXPECT_EQ(mentry->mnt_fsname, entry.blk_device); + EXPECT_EQ(mentry->mnt_dir, entry.mount_point); + EXPECT_EQ(mentry->mnt_type, entry.fs_type); std::set 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); } std::set fs_options; - for (auto& s : android::base::Split(fsrec->fs_options ?: "nullptr", ",")) { - fs_options.emplace(s); + if (!entry.fs_options.empty()) { + for (auto& s : android::base::Split(entry.fs_options, ",")) { + fs_options.emplace(s); + } } // matches private content in fs_mgr_fstab.c static struct flag_list { @@ -194,14 +188,17 @@ TEST(fs_mgr, fs_mgr_read_fstab_file_proc_mounts) { {0, 0}, }; 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); } } - if (!(fsrec->flags & MS_RDONLY)) fs_options.emplace("rw"); + if (!(entry.flags & MS_RDONLY)) { + fs_options.emplace("rw"); + } EXPECT_EQ(mnt_opts, fs_options); ++i; } + EXPECT_EQ(i, fstab.size()); } TEST(fs_mgr, ReadFstabFromFile_FsOptions) {