diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-18 20:09:00 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-05-18 20:09:00 +0000 |
commit | 221cb97aea880f3fc73fc32af279e6603ecb36a1 (patch) | |
tree | 1f923ae32e450f25c5717a624c8e9b20f3856a3b | |
parent | 8194a6d0def16daf442183f47ee625655a10ae1c (diff) | |
parent | 3ee87759492c34b19d0b4627ce0d55bf95e8a168 (diff) | |
download | bionic-221cb97aea880f3fc73fc32af279e6603ecb36a1.tar.gz |
Merge "Snap for 8606072 from 0a5cc21c4224842623495ff86f4002ea37fe17d2 to android11-tests-release" into android11-tests-releaseandroid-vts-11.0_r9android-vts-11.0_r16android-vts-11.0_r15android-vts-11.0_r14android-vts-11.0_r13android-vts-11.0_r12android-vts-11.0_r11android-vts-11.0_r10android-cts-11.0_r9android-cts-11.0_r16android-cts-11.0_r15android-cts-11.0_r14android-cts-11.0_r13android-cts-11.0_r12android-cts-11.0_r11android-cts-11.0_r10android11-tests-release
-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) { |