From: Dmitry V. Levin Date: Wed, 15 Jul 2015 01:50:27 +0000 (+0000) Subject: tests: add wait.test X-Git-Tag: v4.11~235 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cde9ef71838f5f9906d5ee846461973f0e68ee1b;p=strace tests: add wait.test * tests/wait.c: New file. * tests/wait.expected: Likewise. * tests/wait.test: New test. * tests/Makefile.am (check_PROGRAMS): Add wait. (TESTS): Add wait.test. (EXTRA_DIST): Add wait.expected. * tests/.gitignore: Add wait. --- diff --git a/tests/.gitignore b/tests/.gitignore index ef0d5738..b48e870c 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -53,6 +53,7 @@ umovestr2 unix-pair-send-recv utime utimensat +wait xattr xet_robust_list *.log diff --git a/tests/Makefile.am b/tests/Makefile.am index 316cc409..bb8e9bc8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -66,6 +66,7 @@ check_PROGRAMS = \ unix-pair-send-recv \ utime \ utimensat \ + wait \ xattr \ xet_robust_list \ # end of check_PROGRAMS @@ -139,6 +140,7 @@ TESTS = \ uio.test \ utime.test \ utimensat.test \ + wait.test \ xattr.test \ xet_robust_list.test \ count.test \ @@ -191,6 +193,7 @@ EXTRA_DIST = init.sh run.sh match.awk \ umovestr.expected \ unix-yy-accept.awk \ unix-yy-connect.awk \ + wait.expected \ xattr.expected \ $(TESTS) diff --git a/tests/wait.c b/tests/wait.c new file mode 100644 index 00000000..6f27d9c7 --- /dev/null +++ b/tests/wait.c @@ -0,0 +1,67 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include +#include + +int +main(void) +{ + int fds[2]; + int s; + pid_t pid; + struct rusage rusage = {}; + siginfo_t info = {}; + + (void) close(0); + (void) close(1); + assert(!pipe(fds) && fds[0] == 0 && fds[1] == 1); + + pid = fork(); + assert(pid >= 0); + if (!pid) { + char c; + (void) close(1); + assert(read(0, &c, sizeof(c)) == 1); + return 42; + } + + (void) close(0); + assert(wait4(pid, &s, WNOHANG | __WALL, NULL) == 0); + assert(waitid(P_PID, pid, &info, WNOHANG | WEXITED) == 0); + + assert(write(1, "", 1) == 1); + (void) close(1); + assert(wait4(pid, &s, 0, &rusage) == pid); + assert(WIFEXITED(s) && WEXITSTATUS(s) == 42); + + pid = fork(); + assert(pid >= 0); + if (!pid) { + (void) raise(SIGUSR1); + return 77; + } + assert(wait4(pid, &s, __WALL, NULL) == pid); + assert(WIFSIGNALED(s) && WTERMSIG(s) == SIGUSR1); + + pid = fork(); + assert(pid >= 0); + if (!pid) { + raise(SIGSTOP); + return 0; + } + assert(wait4(pid, &s, WUNTRACED, NULL) == pid); + assert(WIFSTOPPED(s) && WSTOPSIG(s) == SIGSTOP); + + assert(kill(pid, SIGCONT) == 0); + assert(waitid(P_PID, pid, &info, WEXITED | WSTOPPED) == 0); + assert(info.si_code == CLD_EXITED && info.si_status == 0); + + assert(wait4(-1, &s, WNOHANG | WUNTRACED | __WALL, &rusage) == -1); + + return 0; +} diff --git a/tests/wait.expected b/tests/wait.expected new file mode 100644 index 00000000..53140cb0 --- /dev/null +++ b/tests/wait.expected @@ -0,0 +1,11 @@ +wait4\([[:digit:]]+, 0x[[:xdigit:]]+, WNOHANG\|__WALL, NULL\) += 0 +waitid\(P_PID, [[:digit:]]+, \{\}, WNOHANG\|WEXITED, NULL\) += 0 +wait4\([[:digit:]]+, \[\{WIFEXITED\(s\) && WEXITSTATUS\(s\) == 42\}\], 0, \{ru_utime=\{[[:digit:]], [[:digit:]]+\}, ru_stime=\{[[:digit:]], [[:digit:]]+\}, ru_maxrss=[[:digit:]]+, ru_ixrss=0, ru_idrss=0, ru_isrss=0, ru_minflt=[[:digit:]]+, ru_majflt=[[:digit:]]+, ru_nswap=0, ru_inblock=[[:digit:]]+, ru_oublock=[[:digit:]]+, ru_msgsnd=0, ru_msgrcv=0, ru_nsignals=0, ru_nvcsw=[[:digit:]]+, ru_nivcsw=[[:digit:]]+\}\) += [[:digit:]]+ +--- SIGCHLD \{si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=[[:digit:]]+, si_uid=[[:digit:]]+, si_status=42, si_utime=[[:digit:]], si_stime=[[:digit:]]} --- +wait4\([[:digit:]]+, \[\{WIFSIGNALED\(s\) && WTERMSIG\(s\) == SIGUSR1\}\], __WALL, NULL\) += [[:digit:]]+ +--- SIGCHLD \{si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=[[:digit:]]+, si_uid=[[:digit:]]+, si_status=SIGUSR1, si_utime=[[:digit:]], si_stime=[[:digit:]]\} --- +wait4\([[:digit:]]+, \[\{WIFSTOPPED\(s\) && WSTOPSIG\(s\) == SIGSTOP\}\], WSTOPPED, NULL\) += [[:digit:]]+ +--- SIGCHLD \{si_signo=SIGCHLD, si_code=CLD_STOPPED, si_pid=[[:digit:]]+, si_uid=[[:digit:]]+, si_status=SIGSTOP, si_utime=[[:digit:]], si_stime=[[:digit:]]\} --- +--- SIGCHLD \{si_signo=SIGCHLD, si_code=CLD_CONTINUED, si_pid=[[:digit:]]+, si_uid=[[:digit:]]+, si_status=SIGCONT, si_utime=[[:digit:]], si_stime=[[:digit:]]\} --- +waitid\(P_PID, [[:digit:]]+, \{si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=[[:digit:]]+, si_uid=[[:digit:]]+, si_status=0, si_utime=[[:digit:]], si_stime=[[:digit:]]\}, WEXITED\|WSTOPPED, NULL\) += 0 +wait4\(-1, 0x[[:xdigit:]]+, WNOHANG\|WSTOPPED\|__WALL, 0x[[:xdigit:]]+\) += -1 ECHILD .* diff --git a/tests/wait.test b/tests/wait.test new file mode 100755 index 00000000..9d1705f8 --- /dev/null +++ b/tests/wait.test @@ -0,0 +1,11 @@ +#!/bin/sh + +# Check wait4 and waitid syscalls decoding. + +. "${srcdir=.}/init.sh" + +run_prog +run_strace -v -e wait4,waitid $args +match_grep + +exit 0