gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/util/mount_util_test.cc (about)

     1  // Copyright 2018 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  #include "test/util/mount_util.h"
    16  
    17  #include "gmock/gmock.h"
    18  #include "gtest/gtest.h"
    19  #include "test/util/test_util.h"
    20  
    21  namespace gvisor {
    22  namespace testing {
    23  
    24  namespace {
    25  
    26  TEST(ParseMounts, Mounts) {
    27    auto entries = ASSERT_NO_ERRNO_AND_VALUE(ProcSelfMountsEntriesFrom(
    28        R"proc(sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
    29  proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
    30   /mnt tmpfs rw,noexec 0 0
    31  )proc"));
    32    EXPECT_EQ(entries.size(), 3);
    33  }
    34  
    35  TEST(ParseMounts, MountInfo) {
    36    auto entries = ASSERT_NO_ERRNO_AND_VALUE(ProcSelfMountInfoEntriesFrom(
    37        R"proc(22 28 0:20 / /sys rw,relatime shared:7 - sysfs sysfs rw
    38  23 28 0:21 / /proc rw,relatime shared:14 - proc proc rw
    39  2007 8844 0:278 / /mnt rw,noexec - tmpfs  rw,mode=123,uid=268601820,gid=5000
    40  )proc"));
    41    EXPECT_EQ(entries.size(), 3);
    42  
    43    entries = ASSERT_NO_ERRNO_AND_VALUE(ProcSelfMountInfoEntriesFrom(
    44        R"proc(22 28 0:20 / /sys rw,relatime shared:7 master:20 - sysfs sysfs rw
    45  23 28 0:21 / /proc rw,relatime shared:14 master:20 propagate_from:1 - proc proc rw
    46  2007 8844 0:278 / /mnt rw,noexec - tmpfs  rw,mode=123,uid=268601820,gid=5000
    47  )proc"));
    48    EXPECT_EQ(entries.size(), 3);
    49  }
    50  
    51  }  // namespace
    52  
    53  }  // namespace testing
    54  }  // namespace gvisor