[PATCH v2 5/5] tests: add a test case for -YY option

Masatake YAMATO yamato at redhat.com
Tue Aug 24 19:26:43 UTC 2021


From: <yamato at redhat.com>

From: Masatake YAMATO <yamato at redhat.com>

* tests/strace-YY-0123456789.c: New file defining YY_OPTION.
* tests/strace-Y-0123456789.c: Include "scno.h".
(do_default_action) Compare values returned from getppid() if
YY_OPTION is defined.
Call `pidfd_open' to compare arguments and retvals.
* tests/gen_tests.in (strace-YY-0123456789): New test.
* tests/Makefile.am (CHECK_PROGRAMS): Add strace-YY-0123456789.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 tests/.gitignore             |  1 +
 tests/Makefile.am            |  1 +
 tests/gen_tests.in           |  1 +
 tests/strace-Y-0123456789.c  | 42 +++++++++++++++++++++++++++++++-----
 tests/strace-YY-0123456789.c |  2 ++
 5 files changed, 42 insertions(+), 5 deletions(-)
 create mode 100644 tests/strace-YY-0123456789.c

diff --git a/tests/.gitignore b/tests/.gitignore
index 00d8b044b..d80d39e8d 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -883,6 +883,7 @@ strace-n
 strace-x
 strace-xx
 strace-Y-0123456789
+strace-YY-0123456789
 swap
 sxetmask
 symlink
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 83fc867f1..8ebe7bf55 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -323,6 +323,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
 	status-none-threads \
 	status-unfinished-threads \
 	strace-Y-0123456789 \
+	strace-YY-0123456789 \
 	syslog-success \
 	tgkill--pidns-translation \
 	threads-execve \
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index 55d20b9d4..76df025fa 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -856,6 +856,7 @@ strace-n	-e trace=listen -n -qq -a 12
 strace-x	-e trace=chdir -x -a 12
 strace-xx	-e trace=chdir -xx -a 18
 strace-Y-0123456789	-e trace=getppid -e signal='!SIGCHLD' -q -f -Y -a 18
+strace-YY-0123456789    -e trace=getppid,pidfd_open -e signal='!SIGCHLD' -q -f -yy -YY -a 18
 swap	-a23 -e trace=swapon,swapoff
 sxetmask	-a11 -e trace=sgetmask,ssetmask
 symlink	-a34
diff --git a/tests/strace-Y-0123456789.c b/tests/strace-Y-0123456789.c
index 6640336ef..02d2bcdf8 100644
--- a/tests/strace-Y-0123456789.c
+++ b/tests/strace-Y-0123456789.c
@@ -1,5 +1,5 @@
 /*
- * Test strace's -Y option
+ * Test strace's -Y and -YY option
  * Copyright (c) 2021 The strace developers.
  * All rights reserved.
  *
@@ -12,6 +12,7 @@
  * Even if linux returns a longer name, strace should
  * not crash. */
 
+#include "scno.h"
 #include "tests.h"
 
 #include <stdio.h>
@@ -33,7 +34,20 @@ do_default_action(void)
 	char comm[sizeof(NEW_NAME)];
 	prctl(PR_GET_NAME, comm);
 
-	printf("%-5d<%s> getppid() = %d\n", pid, comm, ppid);
+	char ocomm[sizeof(NEW_NAME)];
+	strcpy(ocomm, comm);
+
+	printf("%-5d<%s> getppid() = %d"
+#ifdef YY_OPTION
+	       "<strace>"
+#endif
+	       "\n", pid, comm, ppid);
+
+#ifdef YY_OPTION
+	int pfd = syscall(__NR_pidfd_open, ppid, 0, 0, 0, 0, 0);
+	printf("%-5d<%s> pidfd_open(%d<strace>, 0) = %d<pid:%d<strace>>\n",
+	       pid, comm, ppid, pfd, ppid);
+#endif
 
 	fflush(stdout);
 
@@ -44,12 +58,24 @@ do_default_action(void)
 		pid = getpid();
 		ppid = getppid();
 		prctl(PR_GET_NAME, comm);
-		printf("%-5d<%s> getppid() = %d\n", pid, comm, ppid);
+		printf("%-5d<%s> getppid() = %d"
+#ifdef YY_OPTION
+		       "<%s>\n", pid, comm, ppid, ocomm
+#else
+		       "\n",     pid, comm, ppid
+#endif
+			);
 		strcpy(comm, NEW_NAME);
 		prctl(PR_SET_NAME, comm);
 		prctl(PR_GET_NAME, comm);
 		ppid = getppid();
-		printf("%-5d<%s> getppid() = %d\n", pid, comm, ppid);
+		printf("%-5d<%s> getppid() = %d"
+#ifdef YY_OPTION
+		       "<%s>\n", pid, comm, ppid, ocomm
+#else
+			"\n",    pid, comm, ppid
+#endif
+			);
 		fflush(stdout);
 
 		char * self_argv[] = { (char *)"unused", (char *)"execve", NULL };
@@ -63,7 +89,13 @@ do_default_action(void)
 		printf("%-5d<exe> +++ exited with 0 +++\n", child);
 
 		ppid = getppid();
-		printf("%-5d<%s> getppid() = %d\n", pid, comm, ppid);
+		printf("%-5d<%s> getppid() = %d"
+#ifdef YY_OPTION
+		       "<strace>\n"
+#else
+		       "\n"
+#endif
+		       , pid, comm, ppid);
 		printf("%-5d<%s> +++ exited with 0 +++\n", pid, comm);
 		return WEXITSTATUS(status);
 	}
diff --git a/tests/strace-YY-0123456789.c b/tests/strace-YY-0123456789.c
new file mode 100644
index 000000000..999b32630
--- /dev/null
+++ b/tests/strace-YY-0123456789.c
@@ -0,0 +1,2 @@
+#define YY_OPTION
+#include "strace-Y-0123456789.c"
-- 
2.31.1



More information about the Strace-devel mailing list