summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2020-09-29 15:47:25 -0700
committergVisor bot <gvisor-bot@google.com>2020-09-29 15:49:27 -0700
commit4a428b13b20baf055e7e70ecb51a87299f0c6d8e (patch)
tree25635079890a2b92abdae4f74b5af99190450e86 /test
parent7fbb45e8ed82c118338c38fb71e7ff50addaa653 (diff)
Add /proc/[pid]/cwd
PiperOrigin-RevId: 334478850
Diffstat (limited to 'test')
-rw-r--r--test/syscalls/linux/proc.cc18
1 files changed, 16 insertions, 2 deletions
diff --git a/test/syscalls/linux/proc.cc b/test/syscalls/linux/proc.cc
index 6e3c536c0..e8fcc4439 100644
--- a/test/syscalls/linux/proc.cc
+++ b/test/syscalls/linux/proc.cc
@@ -780,8 +780,12 @@ TEST(ProcSelfFdInfo, Flags) {
}
TEST(ProcSelfExe, Absolute) {
- auto exe = ASSERT_NO_ERRNO_AND_VALUE(
- ReadLink(absl::StrCat("/proc/", getpid(), "/exe")));
+ auto exe = ASSERT_NO_ERRNO_AND_VALUE(ReadLink("/proc/self/exe"));
+ EXPECT_EQ(exe[0], '/');
+}
+
+TEST(ProcSelfCwd, Absolute) {
+ auto exe = ASSERT_NO_ERRNO_AND_VALUE(ReadLink("/proc/self/cwd"));
EXPECT_EQ(exe[0], '/');
}
@@ -1473,6 +1477,16 @@ TEST(ProcPidExe, Subprocess) {
EXPECT_EQ(actual, expected_absolute_path);
}
+// /proc/PID/cwd points to the correct directory.
+TEST(ProcPidCwd, Subprocess) {
+ auto want = ASSERT_NO_ERRNO_AND_VALUE(GetCWD());
+
+ char got[PATH_MAX + 1] = {};
+ ASSERT_THAT(ReadlinkWhileRunning("cwd", got, sizeof(got)),
+ SyscallSucceedsWithValue(Gt(0)));
+ EXPECT_EQ(got, want);
+}
+
// Test whether /proc/PID/ files can be read for a running process.
TEST(ProcPidFile, SubprocessRunning) {
char buf[1];