Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/sys Add new test wait6_stopgo_loop in t_wait



details:   https://anonhg.NetBSD.org/src/rev/de095fd31919
branches:  trunk
changeset: 348755:de095fd31919
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sat Nov 05 21:49:28 2016 +0000

description:
Add new test wait6_stopgo_loop in t_wait

This test verifies that it is possible to emit multiple times SIGSTOP and
SIGCONT for a child.

Add checks that status does not return more than one valid state from the
following list: STOPPED, CONTINUED, EXITED and SIGNALED. This check fails
for WIFCONTINUED()==true as it currently and wrongly returns true for
WIFSTOPPED().

This verification is added to wait6_stopgo_loop and wait6_stop_and_go and
marked as expected failure and linked with PR standards/51603.

Remove trailing whitespace.

Sponsored by <The NetBSD Foundation>

diffstat:

 tests/lib/libc/sys/t_wait.c |  109 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 97 insertions(+), 12 deletions(-)

diffs (197 lines):

diff -r b751ccc9afd5 -r de095fd31919 tests/lib/libc/sys/t_wait.c
--- a/tests/lib/libc/sys/t_wait.c       Sat Nov 05 21:11:30 2016 +0000
+++ b/tests/lib/libc/sys/t_wait.c       Sat Nov 05 21:49:28 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_wait.c,v 1.4 2016/04/27 21:14:24 christos Exp $ */
+/* $NetBSD: t_wait.c,v 1.5 2016/11/05 21:49:28 kamil Exp $ */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_wait.c,v 1.4 2016/04/27 21:14:24 christos Exp $");
+__RCSID("$NetBSD: t_wait.c,v 1.5 2016/11/05 21:49:28 kamil Exp $");
 
 #include <sys/wait.h>
 #include <sys/resource.h>
@@ -92,12 +92,12 @@
 
        switch (pid = fork()) {
        case -1:
-               ATF_REQUIRE(pid > 0); 
+               ATF_REQUIRE(pid > 0);
        case 0:
                exit(0x5a5a5a5a);
                /*NOTREACHED*/
        default:
-               ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); 
+               ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
                ATF_REQUIRE(WIFEXITED(st) && WEXITSTATUS(st) == 0x5a);
                ATF_REQUIRE(si.si_status = 0x5a5a5a5a);
                ATF_REQUIRE(si.si_pid == pid);
@@ -128,10 +128,10 @@
                sleep(100);
                /*FALLTHROUGH*/
        case -1:
-               ATF_REQUIRE(pid > 0); 
+               ATF_REQUIRE(pid > 0);
        default:
                ATF_REQUIRE(kill(pid, SIGTERM) == 0);
-               ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); 
+               ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
                ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGTERM);
                ATF_REQUIRE(si.si_status == SIGTERM);
                ATF_REQUIRE(si.si_pid == pid);
@@ -164,9 +164,9 @@
                *(char *)8 = 0;
                /*FALLTHROUGH*/
        case -1:
-               ATF_REQUIRE(pid > 0); 
+               ATF_REQUIRE(pid > 0);
        default:
-               ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); 
+               ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
                ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGSEGV
                    && WCOREDUMP(st));
                ATF_REQUIRE(si.si_status == SIGSEGV);
@@ -194,17 +194,26 @@
        pid_t pid;
        static const struct rlimit rl = { 0, 0 };
 
+       /*
+        * WIFCONTINUED()==true always implies WIFSTOPPED()==true in the
+        * current implementation
+        */
+       atf_tc_expect_fail("PR standards/51603");
+
        ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0);
        switch (pid = fork()) {
        case 0:
                sleep(100);
                /*FALLTHROUGH*/
        case -1:
-               ATF_REQUIRE(pid > 0); 
+               ATF_REQUIRE(pid > 0);
        default:
                ATF_REQUIRE(kill(pid, SIGSTOP) == 0);
-               ATF_REQUIRE(wait6(P_PID, pid, &st, WSTOPPED, &wru, &si) == pid); 
+               ATF_REQUIRE(wait6(P_PID, pid, &st, WSTOPPED, &wru, &si) == pid);
+               ATF_REQUIRE(!WIFEXITED(st));
+               ATF_REQUIRE(!WIFSIGNALED(st));
                ATF_REQUIRE(WIFSTOPPED(st) && WSTOPSIG(st) == SIGSTOP);
+               ATF_REQUIRE(!WIFCONTINUED(st));
                ATF_REQUIRE(si.si_status == SIGSTOP);
                ATF_REQUIRE(si.si_pid == pid);
                ATF_REQUIRE(si.si_uid == getuid());
@@ -213,8 +222,11 @@
                    (uintmax_t)si.si_utime);
 
                ATF_REQUIRE(kill(pid, SIGCONT) == 0);
-               ATF_REQUIRE(wait6(P_PID, pid, &st, WCONTINUED, &wru, &si) == pid); 
+               ATF_REQUIRE(wait6(P_PID, pid, &st, WCONTINUED, &wru, &si) == pid);
+               ATF_REQUIRE(!WIFEXITED(st));
+               ATF_REQUIRE(!WIFSIGNALED(st));
                ATF_REQUIRE(WIFCONTINUED(st));
+               ATF_REQUIRE(!WIFSTOPPED(st));
                ATF_REQUIRE(si.si_status == SIGCONT);
                ATF_REQUIRE(si.si_pid == pid);
                ATF_REQUIRE(si.si_uid == getuid());
@@ -223,8 +235,11 @@
                    (uintmax_t)si.si_utime);
 
                ATF_REQUIRE(kill(pid, SIGQUIT) == 0);
-               ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); 
+               ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
+               ATF_REQUIRE(!WIFEXITED(st));
                ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGQUIT);
+               ATF_REQUIRE(!WIFSTOPPED(st));
+               ATF_REQUIRE(!WIFCONTINUED(st));
                ATF_REQUIRE(si.si_status == SIGQUIT);
                ATF_REQUIRE(si.si_pid == pid);
                ATF_REQUIRE(si.si_uid == getuid());
@@ -235,6 +250,75 @@
        }
 }
 
+ATF_TC(wait6_stopgo_loop);
+ATF_TC_HEAD(wait6_stopgo_loop, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Test that wait6(2) handled stopped/continued process loop");
+}
+
+ATF_TC_BODY(wait6_stopgo_loop, tc)
+{
+       siginfo_t si;
+       struct wrusage wru;
+       int st;
+       pid_t pid;
+       static const struct rlimit rl = { 0, 0 };
+       size_t N = 100;
+
+       /*
+        * WIFCONTINUED()==true always implies WIFSTOPPED()==true in the
+        * current implementation
+        */
+       atf_tc_expect_fail("PR standards/51603");
+
+       ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0);
+       switch (pid = fork()) {
+       case 0:
+               sleep(100);
+               /*FALLTHROUGH*/
+       case -1:
+               ATF_REQUIRE(pid > 0);
+       }
+
+       printf("Before loop of SIGSTOP/SIGCONT sequence %zu times\n", N);
+       while (N --> 0) {
+               ATF_REQUIRE(kill(pid, SIGSTOP) == 0);
+               ATF_REQUIRE(wait6(P_PID, pid, &st, WSTOPPED, &wru, &si) == pid);
+               ATF_REQUIRE(!WIFEXITED(st));
+               ATF_REQUIRE(!WIFSIGNALED(st));
+               ATF_REQUIRE(WIFSTOPPED(st) && WSTOPSIG(st) == SIGSTOP);
+               ATF_REQUIRE(!WIFCONTINUED(st));
+               ATF_REQUIRE(si.si_status == SIGSTOP);
+               ATF_REQUIRE(si.si_pid == pid);
+               ATF_REQUIRE(si.si_uid == getuid());
+               ATF_REQUIRE(si.si_code == CLD_STOPPED);
+
+               ATF_REQUIRE(kill(pid, SIGCONT) == 0);
+               ATF_REQUIRE(wait6(P_PID, pid, &st, WCONTINUED, &wru, &si) == pid);
+               ATF_REQUIRE(!WIFEXITED(st));
+               ATF_REQUIRE(!WIFSIGNALED(st));
+               ATF_REQUIRE(WIFCONTINUED(st));
+               ATF_REQUIRE(!WIFSTOPPED(st));
+               ATF_REQUIRE(si.si_status == SIGCONT);
+               ATF_REQUIRE(si.si_pid == pid);
+               ATF_REQUIRE(si.si_uid == getuid());
+               ATF_REQUIRE(si.si_code == CLD_CONTINUED);
+       }
+       ATF_REQUIRE(kill(pid, SIGQUIT) == 0);
+       ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
+       ATF_REQUIRE(!WIFEXITED(st));
+       ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGQUIT);
+       ATF_REQUIRE(!WIFSTOPPED(st));
+       ATF_REQUIRE(!WIFCONTINUED(st));
+       ATF_REQUIRE(si.si_status == SIGQUIT);
+       ATF_REQUIRE(si.si_pid == pid);
+       ATF_REQUIRE(si.si_uid == getuid());
+       ATF_REQUIRE(si.si_code == CLD_KILLED);
+       printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
+           (uintmax_t)si.si_utime);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -244,6 +328,7 @@
        ATF_TP_ADD_TC(tp, wait6_terminated);
        ATF_TP_ADD_TC(tp, wait6_coredumped);
        ATF_TP_ADD_TC(tp, wait6_stop_and_go);
+       ATF_TP_ADD_TC(tp, wait6_stopgo_loop);
 
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index