[PATCH v3 6/6] tests/pidfd_getfd.c: test decoding of targetfd

Ákos Uzonyi uzonyi.akos at gmail.com
Sun May 24 10:41:38 UTC 2020


* tests/pidfd_getfd.c (k_pidfd_getfd): rename argument: pid -> pidfd
(main): test decoding of targetfd
* tests/gen_tests.in: add "-e signal=none" argument to pidfd_getfd tests

Signed-off-by: Uzonyi Ákos <uzonyi.akos at gmail.com>
---
 tests/gen_tests.in  |  6 +++---
 tests/pidfd_getfd.c | 35 ++++++++++++++++++++++++++++++-----
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index 579329ce..4efed03b 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -432,9 +432,9 @@ perf_event_open_unabbrev	-a1 -v -e trace=perf_event_open
 personality-Xabbrev	+personality.test -Xabbrev
 personality-Xraw	+personality.test -a15 -Xraw
 personality-Xverbose	+personality.test -Xverbose
-pidfd_getfd	-a18 -Xverbose </dev/full
-pidfd_getfd-y	--trace=pidfd_getfd -a18 -y </dev/full
-pidfd_getfd-yy	--trace=pidfd_getfd -a18 -yy </dev/full
+pidfd_getfd	-a18 -Xverbose -e signal=none </dev/full
+pidfd_getfd-y	--trace=pidfd_getfd -a18 -e signal=none -y </dev/full
+pidfd_getfd-yy	--trace=pidfd_getfd -a18 -e signal=none -yy </dev/full
 pidfd_open	-a17
 pidfd_open--decode-fd-path	-a17 -e decode-fd=path -e trace=pidfd_open
 pidfd_open--decode-fd-pidfd	-a17 -e decode-fd=pidfd -e trace=pidfd_open
diff --git a/tests/pidfd_getfd.c b/tests/pidfd_getfd.c
index 791e58e3..f2cc9799 100644
--- a/tests/pidfd_getfd.c
+++ b/tests/pidfd_getfd.c
@@ -13,8 +13,12 @@
 
 #ifdef __NR_pidfd_getfd
 
+# include <assert.h>
+# include <signal.h>
 # include <stdio.h>
+# include <stdlib.h>
 # include <unistd.h>
+# include <sys/wait.h>
 
 # ifndef PIDFD_PATH
 #  define PIDFD_PATH ""
@@ -29,12 +33,12 @@
 static const char *errstr;
 
 static long
-k_pidfd_getfd(const unsigned int pid, const unsigned int fd,
+k_pidfd_getfd(const unsigned int pidfd, const unsigned int fd,
 	      const unsigned int flags)
 {
 	const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
 	const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
-	const kernel_ulong_t arg1 = fill | pid;
+	const kernel_ulong_t arg1 = fill | pidfd;
 	const kernel_ulong_t arg2 = fill | fd;
 	const kernel_ulong_t arg3 = fill | flags;
 	const long rc = syscall(__NR_pidfd_getfd,
@@ -54,7 +58,21 @@ main(void)
 	rc = k_pidfd_getfd(0, 0, 0xbadc0ded);
 	printf("pidfd_getfd(0" FD0_PATH ", 0, 0xbadc0ded) = %s\n", errstr);
 
-	int pid = getpid();
+	int child_wait_fds[2];
+	if (pipe(child_wait_fds))
+		perror_msg_and_fail("pipe");
+
+	int dupfd = dup(0);
+	int pid = fork();
+	if (pid == 0) {
+		close(0);
+		close(child_wait_fds[1]);
+		if (read(child_wait_fds[0], &child_wait_fds[1], sizeof(int)))
+			_exit(2);
+		_exit(0);
+	}
+	close(dupfd);
+
 	int pidfd = syscall(__NR_pidfd_open, pid, 0);
 #if PRINT_PIDFD
 	char pidfd_str[sizeof("<pid:>") + 3 * sizeof(int)];
@@ -62,12 +80,19 @@ main(void)
 #else
 	const char *pidfd_str = PIDFD_PATH;
 #endif
-	rc = k_pidfd_getfd(pidfd, 0, 0);
-	printf("pidfd_getfd(%d%s, 0, 0) = %s%s\n",
+	rc = k_pidfd_getfd(pidfd, dupfd, 0);
+	printf("pidfd_getfd(%d%s, %d%s, 0) = %s%s\n",
 	       pidfd, pidfd >= 0 ? pidfd_str : "",
+	       dupfd, FD0_PATH,
 	       errstr, rc >= 0 ? FD0_PATH : "");
 
 	puts("+++ exited with 0 +++");
+
+	close(child_wait_fds[1]);
+	int status;
+	assert(wait(&status) == pid);
+	assert(status == 0);
+
 	return 0;
 }
 
-- 
2.26.2



More information about the Strace-devel mailing list