summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux/mount.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/syscalls/linux/mount.cc')
-rw-r--r--test/syscalls/linux/mount.cc40
1 files changed, 37 insertions, 3 deletions
diff --git a/test/syscalls/linux/mount.cc b/test/syscalls/linux/mount.cc
index 15b645fb7..3c7311782 100644
--- a/test/syscalls/linux/mount.cc
+++ b/test/syscalls/linux/mount.cc
@@ -26,6 +26,7 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
+#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "test/util/capability_util.h"
@@ -44,6 +45,10 @@ namespace testing {
namespace {
+using ::testing::AnyOf;
+using ::testing::Contains;
+using ::testing::Pair;
+
TEST(MountTest, MountBadFilesystem) {
SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_SYS_ADMIN)));
@@ -63,9 +68,7 @@ TEST(MountTest, MountInvalidTarget) {
TEST(MountTest, MountPermDenied) {
// Clear CAP_SYS_ADMIN.
- if (ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_SYS_ADMIN))) {
- EXPECT_NO_ERRNO(SetCapability(CAP_SYS_ADMIN, false));
- }
+ AutoCapability cap(CAP_SYS_ADMIN, false);
// Linux expects a valid target before checking capability.
auto const dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir());
@@ -345,6 +348,37 @@ TEST(MountTest, RenameRemoveMountPoint) {
ASSERT_THAT(rmdir(dir.path().c_str()), SyscallFailsWithErrno(EBUSY));
}
+TEST(MountTest, MountInfo) {
+ SKIP_IF(IsRunningWithVFS1());
+ SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_SYS_ADMIN)));
+
+ auto const dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir());
+ auto const mount = ASSERT_NO_ERRNO_AND_VALUE(
+ Mount("", dir.path(), "tmpfs", MS_NOEXEC, "mode=0123", 0));
+ const std::vector<ProcMountsEntry> mounts =
+ ASSERT_NO_ERRNO_AND_VALUE(ProcSelfMountsEntries());
+ for (const auto& e : mounts) {
+ if (e.mount_point == dir.path()) {
+ EXPECT_EQ(e.fstype, "tmpfs");
+ auto mopts = ParseMountOptions(e.mount_opts);
+ EXPECT_THAT(mopts, AnyOf(Contains(Pair("mode", "0123")),
+ Contains(Pair("mode", "123"))));
+ }
+ }
+
+ const std::vector<ProcMountInfoEntry> mountinfo =
+ ASSERT_NO_ERRNO_AND_VALUE(ProcSelfMountInfoEntries());
+
+ for (auto const& e : mountinfo) {
+ if (e.mount_point == dir.path()) {
+ EXPECT_EQ(e.fstype, "tmpfs");
+ auto mopts = ParseMountOptions(e.super_opts);
+ EXPECT_THAT(mopts, AnyOf(Contains(Pair("mode", "0123")),
+ Contains(Pair("mode", "123"))));
+ }
+ }
+}
+
} // namespace
} // namespace testing