[PATCH] add -Y test for waitid
SuHsueyu
anolasc13 at gmail.com
Wed Mar 16 09:00:30 UTC 2022
GSoC microproject. Thank you for your comments. I squash three patches that I submmited earlier.
add -Y test for waitid
tests: add test for P_PGID in waitid
---
tests/Makefile.am | 1 +
tests/gen_tests.in | 1 +
tests/pure_executables.list | 1 +
tests/waitid-Y.c | 2 ++
tests/waitid.c | 42 ++++++++++++++++++++++++-------------
5 files changed, 33 insertions(+), 14 deletions(-)
create mode 100644 tests/waitid-Y.c
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index b98a733a0..a4b61fb61 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -1049,6 +1049,7 @@ vmsplice -ewrite=1
wait4 -esignal=none
wait4-v -v -e signal=none -e trace=wait4
waitid -esignal=none
+waitid-Y -Y -e signal=none -e trace=waitid
waitid-v -v -e signal=none -e trace=waitid
waitpid -a28
xattr -a22 -e trace=getxattr,fgetxattr,lgetxattr,setxattr,fsetxattr,lsetxattr,listxattr,flistxattr,llistxattr,removexattr,fremovexattr,lremovexattr
diff --git a/tests/waitid-Y.c b/tests/waitid-Y.c
new file mode 100644
index 000000000..74d7dcff8
--- /dev/null
+++ b/tests/waitid-Y.c
@@ -0,0 +1,2 @@
+#define MY_COMM "<waitid-Y>"
+#include "waitid.c"
diff --git a/tests/waitid.c b/tests/waitid.c
index a14899530..6e425f485 100644
--- a/tests/waitid.c
+++ b/tests/waitid.c
@@ -18,6 +18,10 @@
#include "kernel_rusage.h"
#include "scno.h"
+#ifndef MY_COMM
+# define MY_COMM ""
+#endif
+
static const char *
sprint_rusage(const kernel_rusage_t *const ru)
{
@@ -103,13 +107,14 @@ sprint_siginfo(const siginfo_t *const si, const char *const status_text)
snprintf(buf, sizeof(buf),
"{si_signo=SIGCHLD"
", si_code=%s"
- ", si_pid=%d"
+ ", si_pid=%d%s"
", si_uid=%d"
", si_status=%s"
", si_utime=%llu"
", si_stime=%llu}",
si_code_2_name(si->si_code),
si->si_pid,
+ MY_COMM,
si->si_uid,
status_text,
zero_extend_signed_to_ull(si->si_utime),
@@ -165,23 +170,24 @@ main(void)
if (do_waitid(P_PID, pid, 0, WNOHANG|WEXITED, 0))
perror_msg_and_fail("waitid #1");
- tprintf("waitid(P_PID, %d, NULL, WNOHANG|WEXITED, NULL) = 0\n", pid);
+ tprintf("waitid(P_PID, %d%s, NULL, WNOHANG|WEXITED, NULL) = 0\n",
+ pid, MY_COMM);
TAIL_ALLOC_OBJECT_CONST_PTR(siginfo_t, sinfo);
memset(sinfo, 0, sizeof(*sinfo));
TAIL_ALLOC_OBJECT_CONST_PTR(kernel_rusage_t, rusage);
if (do_waitid(P_PID, pid, sinfo, WNOHANG|WEXITED|WSTOPPED, rusage))
perror_msg_and_fail("waitid #2");
- tprintf("waitid(P_PID, %d, {}, WNOHANG|WEXITED|WSTOPPED, %s) = 0\n",
- pid, sprint_rusage(rusage));
+ tprintf("waitid(P_PID, %d%s, {}, WNOHANG|WEXITED|WSTOPPED, %s) = 0\n",
+ pid, MY_COMM, sprint_rusage(rusage));
assert(write(1, "", 1) == 1);
(void) close(1);
if (do_waitid(P_PID, pid, sinfo, WEXITED, rusage))
perror_msg_and_fail("waitid #3");
- tprintf("waitid(P_PID, %d, %s, WEXITED, %s) = 0\n",
- pid, sprint_siginfo(sinfo, "42"), sprint_rusage(rusage));
+ tprintf("waitid(P_PID, %d%s, %s, WEXITED, %s) = 0\n",
+ pid, MY_COMM, sprint_siginfo(sinfo, "42"), sprint_rusage(rusage));
pid = fork();
if (pid < 0)
@@ -194,8 +200,9 @@ main(void)
if (do_waitid(P_PID, pid, sinfo, WEXITED, rusage))
perror_msg_and_fail("waitid #4");
- tprintf("waitid(P_PID, %d, %s, WEXITED, %s) = 0\n",
- pid, sprint_siginfo(sinfo, "SIGUSR1"), sprint_rusage(rusage));
+ tprintf("waitid(P_PID, %d%s, %s, WEXITED, %s) = 0\n",
+ pid, MY_COMM, sprint_siginfo(sinfo, "SIGUSR1"),
+ sprint_rusage(rusage));
if (pipe(fds))
perror_msg_and_fail("pipe");
@@ -215,8 +222,9 @@ main(void)
if (do_waitid(P_PID, pid, sinfo, WSTOPPED, rusage))
perror_msg_and_fail("waitid #5");
- tprintf("waitid(P_PID, %d, %s, WSTOPPED, %s) = 0\n",
- pid, sprint_siginfo(sinfo, "SIGSTOP"), sprint_rusage(rusage));
+ tprintf("waitid(P_PID, %d%s, %s, WSTOPPED, %s) = 0\n",
+ pid, MY_COMM, sprint_siginfo(sinfo, "SIGSTOP"),
+ sprint_rusage(rusage));
if (kill(pid, SIGCONT))
perror_msg_and_fail("kill(SIGCONT)");
@@ -224,8 +232,9 @@ main(void)
#if defined WCONTINUED
if (do_waitid(P_PID, pid, sinfo, WCONTINUED, rusage))
perror_msg_and_fail("waitid #6");
- tprintf("waitid(P_PID, %d, %s, WCONTINUED, %s) = 0\n",
- pid, sprint_siginfo(sinfo, "SIGCONT"), sprint_rusage(rusage));
+ tprintf("waitid(P_PID, %d%s, %s, WCONTINUED, %s) = 0\n",
+ pid, MY_COMM, sprint_siginfo(sinfo, "SIGCONT"),
+ sprint_rusage(rusage));
#endif /* WCONTINUED */
assert(write(1, "", 1) == 1);
@@ -233,8 +242,13 @@ main(void)
if (do_waitid(P_PID, pid, sinfo, WEXITED, rusage))
perror_msg_and_fail("waitid #7");
- tprintf("waitid(P_PID, %d, %s, WEXITED, %s) = 0\n",
- pid, sprint_siginfo(sinfo, "0"), sprint_rusage(rusage));
+ tprintf("waitid(P_PID, %d%s, %s, WEXITED, %s) = 0\n",
+ pid, MY_COMM, sprint_siginfo(sinfo, "0"), sprint_rusage(rusage));
+
+ pid_t pgid = getpgid(pid);
+ long pgrc = do_waitid(P_PGID, pgid, sinfo, WEXITED, rusage);
+ tprintf("waitid(P_PGID, %d, %p, WEXITED, %p)"
+ " = %ld %s (%m)\n", pgid, sinfo, rusage, pgrc, errno2name());
long rc = do_waitid(P_ALL, -1, sinfo, WEXITED|WSTOPPED, rusage);
tprintf("waitid(P_ALL, -1, %p, WEXITED|WSTOPPED, %p)"
--
2.25.1
More information about the Strace-devel
mailing list