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
This commit is contained in:
Tom Cherry 2019-01-23 11:24:33 -08:00
parent 582a81cbe8
commit 4e904768f7
2 changed files with 21 additions and 21 deletions

View File

@ -6,6 +6,9 @@
{
"name": "debuggerd_test"
},
{
"name": "fs_mgr_unit_test"
},
{
"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) {
auto fstab = fs_mgr_read_fstab("/proc/mounts");
ASSERT_NE(fstab, nullptr);
Fstab fstab;
ASSERT_TRUE(ReadFstabFromFile("/proc/mounts", &fstab));
std::unique_ptr<std::FILE, int (*)(std::FILE*)> 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<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);
}
std::set<std::string> 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) {