diff options
| author | George Zacharia <george.zcharia@gmail.com> | 2023-08-02 07:14:58 +0530 |
|---|---|---|
| committer | George Zacharia <george.zcharia@gmail.com> | 2023-08-02 07:14:58 +0530 |
| commit | 37897a48337da83e36a5244f5241a2bdfd257e1d (patch) | |
| tree | 6ddb0527cf33db0fa9964d4c2756c9fe7d5bf496 /tests/mntent_test.cpp | |
| parent | 43ecd869bdcf14fa9fb2297f822c25ebb4025ccd (diff) | |
| parent | e2b2fd5475b5da5866e481bd5b72ef4333032792 (diff) | |
Merge tag 'android-13.0.0_r52' of https://android.googlesource.com/platform/bionic into t13.0HEADt13.0
Android 13.0.0 Release 52 (TQ3A.230605.012)
Change-Id: Ic18bc3dfc28e9e23f5a96e2e74843d9e27dbe141
Diffstat (limited to 'tests/mntent_test.cpp')
| -rw-r--r-- | tests/mntent_test.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/tests/mntent_test.cpp b/tests/mntent_test.cpp index b86af9fb6..4b8fc9a80 100644 --- a/tests/mntent_test.cpp +++ b/tests/mntent_test.cpp @@ -19,24 +19,40 @@ #include <mntent.h> TEST(mntent, mntent_smoke) { + // Read all the entries with getmntent(). FILE* fp = setmntent("/proc/mounts", "r"); ASSERT_TRUE(fp != nullptr); - ASSERT_TRUE(getmntent(fp) != nullptr); + std::vector<std::string> fsnames; + std::vector<std::string> dirs; + mntent* me; + while ((me = getmntent(fp)) != nullptr) { + fsnames.push_back(me->mnt_fsname); + dirs.push_back(me->mnt_dir); + } + + ASSERT_EQ(1, endmntent(fp)); - bool saw_proc = false; + // Then again with getmntent_r(), checking they match. + fp = setmntent("/proc/mounts", "r"); + ASSERT_TRUE(fp != nullptr); struct mntent entry; char buf[BUFSIZ]; + size_t i = 0; while (getmntent_r(fp, &entry, buf, sizeof(buf)) != nullptr) { - if (strcmp(entry.mnt_fsname, "proc") == 0 && strcmp(entry.mnt_dir, "/proc") == 0) { - saw_proc = true; - } + ASSERT_EQ(fsnames[i], entry.mnt_fsname); + ASSERT_EQ(dirs[i], entry.mnt_dir); + i++; } - ASSERT_TRUE(saw_proc); - ASSERT_EQ(1, endmntent(fp)); + + // And just for good measure: we did see a /proc entry, right? + auto it = std::find(fsnames.begin(), fsnames.end(), "proc"); + ASSERT_TRUE(it != fsnames.end()); + size_t proc_index = it - fsnames.begin(); + ASSERT_EQ("/proc", dirs[proc_index]); } TEST(mntent, hasmntopt) { |
