[PATCH v3] add -Y test for waitid, skip if /proc is not mounted

SuHsueyu anolasc13 at gmail.com
Fri Apr 1 12:17:58 UTC 2022


GSoC micro project. Thanks for comment, this patch pass waitid-Y test in
my environment.

---
add -Y test for waitid, skip if /proc is not mounted

add -Y test for waitid v1

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            |  3 ++
 tests/waitid.c              | 66 +++++++++++++++++++++++++++++--------
 5 files changed, 59 insertions(+), 13 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..900874bb4
--- /dev/null
+++ b/tests/waitid-Y.c
@@ -0,0 +1,3 @@
+#define MY_COMM "<waitid-Y>"
+#define SKIP_IF_PROC_IS_UNAVAILABLE skip_if_unavailable("/proc/")
+#include "waitid.c"
diff --git a/tests/waitid.c b/tests/waitid.c
index a14899530..6eb997a93 100644
--- a/tests/waitid.c
+++ b/tests/waitid.c
@@ -18,6 +18,13 @@
 #include "kernel_rusage.h"
 #include "scno.h"
 
+#ifndef MY_COMM
+# define MY_COMM ""
+#endif
+#ifndef SKIP_IF_PROC_IS_UNAVAILABLE
+# define SKIP_IF_PROC_IS_UNAVAILABLE
+#endif
+
 static const char *
 sprint_rusage(const kernel_rusage_t *const ru)
 {
@@ -117,6 +124,28 @@ sprint_siginfo(const siginfo_t *const si, const char *const status_text)
 	return buf;
 }
 
+static const char*
+sprint_siginfo_comm(const siginfo_t* const si, const char* const status_text)
+{
+	static char buf[1024];
+	snprintf(buf, sizeof(buf),
+		"{si_signo=SIGCHLD"
+		", si_code=%s"
+		", 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),
+		zero_extend_signed_to_ull(si->si_stime));
+	return buf;
+}
+
 static unsigned long
 poison(unsigned int v)
 {
@@ -143,6 +172,8 @@ do_waitid(const unsigned int idtype,
 int
 main(void)
 {
+	SKIP_IF_PROC_IS_UNAVAILABLE;
+
 	tprintf("%s", "");
 
 	int fds[2];
@@ -165,23 +196,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 +226,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 +248,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_comm(sinfo, "SIGSTOP"),
+		sprint_rusage(rusage));
 
 	if (kill(pid, SIGCONT))
 		perror_msg_and_fail("kill(SIGCONT)");
@@ -224,8 +258,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_comm(sinfo, "SIGCONT"),
+		sprint_rusage(rusage));
 #endif /* WCONTINUED */
 
 	assert(write(1, "", 1) == 1);
@@ -233,8 +268,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