]> granicus.if.org Git - strace/commitdiff
tests: enhance test coverage of SIGCHLD siginfo_t
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 10 Jun 2016 09:22:12 +0000 (09:22 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 10 Jun 2016 09:56:53 +0000 (09:56 +0000)
* tests/siginfo.c: New file.
* tests/siginfo.test: New test.
* tests/wait.c: Remove.
* tests/wait.expected: Remove.
* tests/wait.test: Remove.
* tests/.gitignore: Add siginfo, remove wait.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(DECODER_TESTS): Add siginfo.test, remove wait.test.
(EXTRA_DIST): Remove wait.expected.

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

index 65f3c06080658ee7e3e3e27d628ddc55df3e199f..67d0d66e2bea876a7b90243ef2d4524c89083aff 100644 (file)
@@ -230,6 +230,7 @@ setuid32
 shmxt
 sigaction
 sigaltstack
+siginfo
 signalfd
 sigreturn
 sleep
@@ -275,7 +276,6 @@ utimes
 vfork-f
 vhangup
 vmsplice
-wait
 wait4
 wait4-v
 waitid
index 48e44011c23bbf040baf19bb8260bafdd0119af2..7a029b63112a77d9def3f4ffc2209a4ad469c9a5 100644 (file)
@@ -283,6 +283,7 @@ check_PROGRAMS = \
        shmxt \
        sigaction \
        sigaltstack \
+       siginfo \
        signalfd \
        sigreturn \
        sleep \
@@ -328,7 +329,6 @@ check_PROGRAMS = \
        vfork-f \
        vhangup \
        vmsplice \
-       wait \
        wait4 \
        wait4-v \
        waitid \
@@ -587,6 +587,7 @@ DECODER_TESTS = \
        shmxt.test \
        sigaction.test \
        sigaltstack.test \
+       siginfo.test \
        signalfd.test \
        sigreturn.test \
        splice.test \
@@ -629,7 +630,6 @@ DECODER_TESTS = \
        utimes.test \
        vhangup.test \
        vmsplice.test \
-       wait.test \
        wait4.test \
        wait4-v.test \
        waitid.test \
@@ -723,7 +723,6 @@ EXTRA_DIST = init.sh run.sh match.awk \
             sun_path.expected \
             uio.expected \
             umovestr.expected \
-            wait.expected \
             xchownx.c \
             xgetrlimit.c \
             xselect.c \
diff --git a/tests/siginfo.c b/tests/siginfo.c
new file mode 100644 (file)
index 0000000..48cfaf3
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * Check SIGCHLD siginfo_t decoding.
+ *
+ * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h"
+#include <assert.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+static siginfo_t sinfo;
+
+static void
+handler(int no, siginfo_t *si, void *uc)
+{
+       memcpy(&sinfo, si, sizeof(sinfo));
+}
+
+int
+main(void)
+{
+       tprintf("%s", "");
+
+       int fds[2];
+       if (pipe(fds))
+               perror_msg_and_fail("pipe");
+
+       pid_t pid = fork();
+       if (pid < 0)
+               perror_msg_and_fail("fork");
+
+       if (!pid) {
+               char c;
+               (void) close(1);
+               assert(read(0, &c, sizeof(c)) == 1);
+               return 42;
+       }
+
+       (void) close(0);
+
+       struct sigaction sa = {
+               .sa_sigaction = handler,
+               .sa_flags = SA_SIGINFO
+       };
+       assert(sigaction(SIGCHLD, &sa, NULL) == 0);
+
+       sigset_t block_mask, unblock_mask;
+       assert(sigprocmask(SIG_SETMASK, NULL, &block_mask) == 0);
+       sigaddset(&block_mask, SIGCHLD);
+       assert(sigprocmask(SIG_SETMASK, &block_mask, NULL) == 0);
+
+       unblock_mask = block_mask;
+       sigdelset(&unblock_mask, SIGCHLD);
+
+       assert(write(1, "", 1) == 1);
+       (void) close(1);
+
+       sigsuspend(&unblock_mask);
+       tprintf("--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED"
+               ", si_pid=%d, si_uid=%u, si_status=%d"
+               ", si_utime=%llu, si_stime=%llu} ---\n",
+               sinfo.si_pid, sinfo.si_uid, sinfo.si_status,
+               widen_to_ull(sinfo.si_utime), widen_to_ull(sinfo.si_stime));
+
+       int s;
+       assert(wait(&s) == pid);
+       assert(WIFEXITED(s) && WEXITSTATUS(s) == 42);
+
+       if (pipe(fds))
+               perror_msg_and_fail("pipe");
+       pid = fork();
+       if (pid < 0)
+               perror_msg_and_fail("fork");
+
+       if (!pid) {
+               (void) close(1);
+               char c;
+               assert(read(0, &c, sizeof(c)) == 1);
+               (void) raise(SIGUSR1);
+               return 1;
+       }
+
+       (void) close(0);
+
+       assert(write(1, "", 1) == 1);
+       (void) close(1);
+
+       sigsuspend(&unblock_mask);
+       tprintf("--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED"
+               ", si_pid=%d, si_uid=%u, si_status=SIGUSR1"
+               ", si_utime=%llu, si_stime=%llu} ---\n",
+               sinfo.si_pid, sinfo.si_uid,
+               widen_to_ull(sinfo.si_utime), widen_to_ull(sinfo.si_stime));
+
+       assert(wait(&s) == pid);
+       assert(WIFSIGNALED(s) && WTERMSIG(s) == SIGUSR1);
+
+       if (pipe(fds))
+               perror_msg_and_fail("pipe");
+       pid = fork();
+       if (pid < 0)
+               perror_msg_and_fail("fork");
+
+       if (!pid) {
+               (void) close(1);
+               raise(SIGSTOP);
+               char c;
+               assert(read(0, &c, sizeof(c)) == 1);
+               return 0;
+       }
+
+       (void) close(0);
+
+       sigsuspend(&unblock_mask);
+       tprintf("--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_STOPPED"
+               ", si_pid=%d, si_uid=%u, si_status=SIGSTOP"
+               ", si_utime=%llu, si_stime=%llu} ---\n",
+               sinfo.si_pid, sinfo.si_uid,
+               widen_to_ull(sinfo.si_utime), widen_to_ull(sinfo.si_stime));
+
+       assert(kill(pid, SIGCONT) == 0);
+
+       sigsuspend(&unblock_mask);
+       tprintf("--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_CONTINUED"
+               ", si_pid=%d, si_uid=%u, si_status=SIGCONT"
+               ", si_utime=%llu, si_stime=%llu} ---\n",
+               sinfo.si_pid, sinfo.si_uid,
+               widen_to_ull(sinfo.si_utime), widen_to_ull(sinfo.si_stime));
+
+       assert(write(1, "", 1) == 1);
+       (void) close(1);
+
+       sigsuspend(&unblock_mask);
+       tprintf("--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED"
+               ", si_pid=%d, si_uid=%u, si_status=0"
+               ", si_utime=%llu, si_stime=%llu} ---\n",
+               sinfo.si_pid, sinfo.si_uid,
+               widen_to_ull(sinfo.si_utime), widen_to_ull(sinfo.si_stime));
+
+       assert(wait(&s) == pid && s == 0);
+
+       tprintf("%s\n", "+++ exited with 0 +++");
+       return 0;
+}
diff --git a/tests/siginfo.test b/tests/siginfo.test
new file mode 100755 (executable)
index 0000000..725f714
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Check SIGCHLD siginfo_t decoding.
+
+. "${srcdir=.}/init.sh"
+run_strace_match_diff -e trace=none
diff --git a/tests/wait.c b/tests/wait.c
deleted file mode 100644 (file)
index b01b2be..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "tests.h"
-#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);
-       if (pipe(fds))
-               perror_msg_and_fail("pipe");
-
-       pid = fork();
-       if (pid < 0)
-               perror_msg_and_fail("fork");
-
-       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();
-       if (pid < 0)
-               perror_msg_and_fail("fork");
-
-       if (!pid) {
-               (void) raise(SIGUSR1);
-               return 1;
-       }
-       assert(wait4(pid, &s, __WALL, NULL) == pid);
-       assert(WIFSIGNALED(s) && WTERMSIG(s) == SIGUSR1);
-
-       pid = fork();
-       if (pid < 0)
-               perror_msg_and_fail("fork");
-
-       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
deleted file mode 100644 (file)
index 53140cb..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-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
deleted file mode 100755 (executable)
index 9d1705f..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh
-
-# Check wait4 and waitid syscalls decoding.
-
-. "${srcdir=.}/init.sh"
-
-run_prog
-run_strace -v -e wait4,waitid $args
-match_grep
-
-exit 0