]> granicus.if.org Git - strace/commitdiff
tests: add wait.test
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 15 Jul 2015 01:50:27 +0000 (01:50 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 28 Aug 2015 08:46:23 +0000 (08:46 +0000)
* 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.

tests/.gitignore
tests/Makefile.am
tests/wait.c [new file with mode: 0644]
tests/wait.expected [new file with mode: 0644]
tests/wait.test [new file with mode: 0755]

index ef0d5738c49a5784d43f953691c59aabf8239328..b48e870cc01a0c3f4d53180c2861d0139c1b7c77 100644 (file)
@@ -53,6 +53,7 @@ umovestr2
 unix-pair-send-recv
 utime
 utimensat
+wait
 xattr
 xet_robust_list
 *.log
index 316cc409390fb9b956ba5b6df7008a8ad8c3637e..bb8e9bc80c19112ada706fc144866e55e1d22e8f 100644 (file)
@@ -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 (file)
index 0000000..6f27d9c
--- /dev/null
@@ -0,0 +1,67 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <assert.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <sys/resource.h>
+
+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 (file)
index 0000000..53140cb
--- /dev/null
@@ -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 (executable)
index 0000000..9d1705f
--- /dev/null
@@ -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