aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-05-18 01:11:07 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-05-18 01:11:07 +0000
commitc3a2e6b23290371da78d5d6741c603f04da6c7f1 (patch)
treee1bea86394688db9596c6cbaf76c69e931d41dcf
parenteec0b88f151fe620eaafb1d3aa8a9f70993cdf82 (diff)
parent46871c040ddc95ebad8b5ee53ff7518b49598e79 (diff)
downloadbionic-c3a2e6b23290371da78d5d6741c603f04da6c7f1.tar.gz
Merge "Merge "Merge "mntent_test: don't assume /proc isn't the first mount." into android10-tests-dev am: 0462cfb766" into android11-tests-dev am: 0a5cc21c42" into android12-tests-dev am: 46871c040d
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2098734 Change-Id: I10ed03dd6f920e19dc8c62c89217bf583dd21d96 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--tests/mntent_test.cpp30
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) {