From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by sourceware.org (Postfix) with ESMTPS id 5B194385B835 for ; Thu, 9 Apr 2020 21:46:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5B194385B835 Received: by mail-qk1-x744.google.com with SMTP id z15so338247qki.7 for ; Thu, 09 Apr 2020 14:46:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:autocrypt:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=eCPCcfvoCba0GY0TVvIPf4cZYUJONKvsMQ29CQjV570=; b=K5Vl/zAb8t6GMbU/gDurUoC3yKXJNhz0GxKhkV4/ijB4qvoNBRom4XZvKFP0i9wuWL U9ztyGTtAZbGCfm1qoN4dvvBL+QQTpamAT9WkDtMy/0D0nLbAD2CtdDdt4Ge+ZI8OKsp 0BsJ+fxY9AOARE+N3G9T1IWBSuRWj/3QykWQx2/Xzuc1VUlKfBxrWj32cyEfyqtoZMtS 7DhHhT4WuGtoZq96ytG+PA3675+dgUqUlx0+t+BUZrtAacGi1h5c8LofIH04RpAgoicR 7MFpBr1D+vxd9lYj0lXVND9rGzyyx90llszhyw4Gx7dOkDA5exKgkU3zYs+MuhP+KuO7 XXcQ== X-Gm-Message-State: AGi0PuZZja39FXVmTZR0o1EiuPH/hCAWmy6/lplu/KD8vpa7Aw5Aks99 dWN/E97G38rUemBdZu2eZ2/utg/FEdJLRg== X-Google-Smtp-Source: APiQypJmInof80vMnLCkswAaTzfQlTFPSa/Ts1BNRp15yokqMuW2kGQJuktoB0Upqx3xH+TOeP0xeQ== X-Received: by 2002:a37:af86:: with SMTP id y128mr1024956qke.429.1586468766134; Thu, 09 Apr 2020 14:46:06 -0700 (PDT) Received: from [192.168.1.4] ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id f7sm120897qkh.25.2020.04.09.14.46.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Apr 2020 14:46:05 -0700 (PDT) Subject: Re: [PATCH v3 2/2] linux: Add wait4 test case To: libc-alpha@sourceware.org References: <20200409201154.3365671-1-alistair.francis@wdc.com> <20200409201154.3365671-2-alistair.francis@wdc.com> From: Adhemerval Zanella Autocrypt: addr=adhemerval.zanella@linaro.org; prefer-encrypt=mutual; keydata= xsFNBFcVGkoBEADiQU2x/cBBmAVf5C2d1xgz6zCnlCefbqaflUBw4hB/bEME40QsrVzWZ5Nq 8kxkEczZzAOKkkvv4pRVLlLn/zDtFXhlcvQRJ3yFMGqzBjofucOrmdYkOGo0uCaoJKPT186L NWp53SACXguFJpnw4ODI64ziInzXQs/rUJqrFoVIlrPDmNv/LUv1OVPKz20ETjgfpg8MNwG6 iMizMefCl+RbtXbIEZ3TE/IaDT/jcOirjv96lBKrc/pAL0h/O71Kwbbp43fimW80GhjiaN2y WGByepnkAVP7FyNarhdDpJhoDmUk9yfwNuIuESaCQtfd3vgKKuo6grcKZ8bHy7IXX1XJj2X/ BgRVhVgMHAnDPFIkXtP+SiarkUaLjGzCz7XkUn4XAGDskBNfbizFqYUQCaL2FdbW3DeZqNIa nSzKAZK7Dm9+0VVSRZXP89w71Y7JUV56xL/PlOE+YKKFdEw+gQjQi0e+DZILAtFjJLoCrkEX w4LluMhYX/X8XP6/C3xW0yOZhvHYyn72sV4yJ1uyc/qz3OY32CRy+bwPzAMAkhdwcORA3JPb kPTlimhQqVgvca8m+MQ/JFZ6D+K7QPyvEv7bQ7M+IzFmTkOCwCJ3xqOD6GjX3aphk8Sr0dq3 4Awlf5xFDAG8dn8Uuutb7naGBd/fEv6t8dfkNyzj6yvc4jpVxwARAQABzUlBZGhlbWVydmFs IFphbmVsbGEgTmV0dG8gKExpbmFybyBWUE4gS2V5KSA8YWRoZW1lcnZhbC56YW5lbGx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aoX8HAcn4sZzt2pfUB9vQMTBJ2d4+m/qO6+ cFTAceXmIoFsN8+gFN3i8Is3u12u8xGudcBPvpoy4OoG Message-ID: <7458cd02-4e84-a16b-5302-8a593cf20c88@linaro.org> Date: Thu, 9 Apr 2020 18:46:02 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200409201154.3365671-2-alistair.francis@wdc.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-25.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Apr 2020 21:46:09 -0000 On 09/04/2020 17:11, Alistair Francis via Libc-alpha wrote: > Add a simple test that checks if the wait4 syscall works without an > rusage argument. This test would have caught the bugs introduced in > commit 600f00b "linux: Use long time_t for wait4/getrusage". > --- > sysdeps/unix/sysv/linux/Makefile | 2 +- > sysdeps/unix/sysv/linux/tst-wait4.c | 51 +++++++++++++++++++++++++++++ > 2 files changed, 52 insertions(+), 1 deletion(-) > create mode 100644 sysdeps/unix/sysv/linux/tst-wait4.c > > diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile > index 60dc5cf9e5..d5fdb4369a 100644 > --- a/sysdeps/unix/sysv/linux/Makefile > +++ b/sysdeps/unix/sysv/linux/Makefile > @@ -98,7 +98,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ > tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \ > test-errno-linux tst-memfd_create tst-mlock2 tst-pkey \ > tst-rlimit-infinity tst-ofdlocks tst-gettid tst-gettid-kill \ > - tst-tgkill > + tst-tgkill tst-wait4 > tests-internal += tst-ofdlocks-compat tst-sigcontext-get_pc wait4 is exported as gnu extension, so there is no need to make the test linux specific. > > CFLAGS-tst-sigcontext-get_pc.c = -fasynchronous-unwind-tables > diff --git a/sysdeps/unix/sysv/linux/tst-wait4.c b/sysdeps/unix/sysv/linux/tst-wait4.c > new file mode 100644 > index 0000000000..44287797a7 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/tst-wait4.c > @@ -0,0 +1,51 @@ > +/* Smoke test for the wait4 system call. > + Copyright (C) 2019-2020 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* Check that wait4 works with no rusage arg. */ > +static void > +test_wait4_no_usage (void) > +{ > + pid_t child = fork (); > + > + if (child == 0) > + { > + pause (); > + exit (0); > + } > + > + wait4 (child, &(int){0}, WNOHANG, NULL); > + kill (child, SIGKILL); > +} > + > +static int > +do_test (void) > +{ > + test_wait4_no_usage(); > + > + return 0; > +} > + > +#include > Below it is a more comprehensible tests based on tst-waitid. It should trigger the issue and add some more coverage to wait4 call: -- /* Tests for wait4. Copyright (C) 2020 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void test_child (void) { /* First thing, we stop ourselves. */ raise (SIGSTOP); /* Hey, we got continued! */ while (1) pause (); } #ifndef WEXITED # define WEXITED 0 # define WCONTINUED 0 # define WSTOPPED WUNTRACED #endif /* Set with only SIGCHLD on do_test_waitid. */ static sigset_t chldset; #ifdef SA_SIGINFO static void sigchld (int signo, siginfo_t *info, void *ctx) { } #endif static void check_sigchld (int code, int status, pid_t pid) { #ifdef SA_SIGINFO siginfo_t siginfo; TEST_COMPARE (sigwaitinfo (&chldset, &siginfo), SIGCHLD); TEST_COMPARE (siginfo.si_signo, SIGCHLD); TEST_COMPARE (siginfo.si_code, code); TEST_COMPARE (siginfo.si_status, status); TEST_COMPARE (siginfo.si_pid, pid); #endif } static int do_test_wait4 (pid_t pid) { /* Adding process_state_tracing_stop ('t') allows the test to work under trace programs such as ptrace. */ enum support_process_state stop_state = support_process_state_stopped | support_process_state_tracing_stop; support_process_state_wait (pid, stop_state); check_sigchld (CLD_STOPPED, SIGSTOP, pid); pid_t ret; int wstatus; struct rusage rusage; ret = wait4 (pid, &wstatus, WUNTRACED|WCONTINUED|WNOHANG, NULL); if (ret == -1 && errno == ENOTSUP) FAIL_RET ("waitid WNOHANG on stopped: %m"); TEST_COMPARE (ret, pid); TEST_VERIFY (WIFSTOPPED (wstatus)); /* Issue again but with struct rusage input. */ ret = wait4 (pid, &wstatus, WUNTRACED|WCONTINUED|WNOHANG, &rusage); /* With WNOHANG and WUNTRACED, if the children has not changes its state since previous call the expected result it 0. */ TEST_COMPARE (ret, 0); /* Some sanity tests to check if 'wtatus' and 'rusage' possible input values. */ ret = wait4 (pid, NULL, WUNTRACED|WCONTINUED|WNOHANG, &rusage); TEST_COMPARE (ret, 0); ret = wait4 (pid, NULL, WUNTRACED|WCONTINUED|WNOHANG, NULL); TEST_COMPARE (ret, 0); if (kill (pid, SIGCONT) != 0) FAIL_RET ("kill (%d, SIGCONT): %m\n", pid); /* Wait for the child to have continued. */ support_process_state_wait (pid, support_process_state_sleeping); #if WCONTINUED != 0 check_sigchld (CLD_CONTINUED, SIGCONT, pid); ret = wait4 (pid, &wstatus, WCONTINUED|WNOHANG, NULL); TEST_COMPARE (ret, pid); TEST_VERIFY (WIFCONTINUED (wstatus)); /* Issue again but with struct rusage input. */ ret = wait4 (pid, &wstatus, WUNTRACED|WCONTINUED|WNOHANG, &rusage); /* With WNOHANG and WUNTRACED, if the children has not changes its state since previous call the expected result it 0. */ TEST_COMPARE (ret, 0); /* Now stop him again and test waitpid with WCONTINUED. */ if (kill (pid, SIGSTOP) != 0) FAIL_RET ("kill (%d, SIGSTOP): %m\n", pid); /* Wait the child stop. The waitid call below will block until it has stopped, but if we are real quick and enter the waitid system call before the SIGCHLD has been generated, then it will be discarded and never delivered. */ support_process_state_wait (pid, stop_state); ret = wait4 (pid, &wstatus, WUNTRACED|WNOHANG, &rusage); TEST_COMPARE (ret, pid); check_sigchld (CLD_STOPPED, SIGSTOP, pid); if (kill (pid, SIGCONT) != 0) FAIL_RET ("kill (%d, SIGCONT): %m\n", pid); /* Wait for the child to have continued. */ support_process_state_wait (pid, support_process_state_sleeping); check_sigchld (CLD_CONTINUED, SIGCONT, pid); ret = wait4 (pid, &wstatus, WCONTINUED|WNOHANG, NULL); TEST_COMPARE (ret, pid); TEST_VERIFY (WIFCONTINUED (wstatus)); #endif /* Die, child, die! */ if (kill (pid, SIGKILL) != 0) FAIL_RET ("kill (%d, SIGKILL): %m\n", pid); support_process_state_wait (pid, support_process_state_zombie); ret = wait4 (pid, &wstatus, 0, &rusage); TEST_COMPARE (ret, pid); TEST_VERIFY (WIFSIGNALED (wstatus)); TEST_VERIFY (WTERMSIG (wstatus) == SIGKILL); check_sigchld (CLD_KILLED, SIGKILL, pid); return 0; } static int do_test (void) { #ifdef SA_SIGINFO { struct sigaction sa; sa.sa_flags = SA_SIGINFO | SA_RESTART; sa.sa_sigaction = sigchld; sigemptyset (&sa.sa_mask); xsigaction (SIGCHLD, &sa, NULL); } #endif sigemptyset (&chldset); sigaddset (&chldset, SIGCHLD); /* The SIGCHLD shall has blocked at the time of the call to sigwait; otherwise, the behavior is undefined. */ sigprocmask (SIG_BLOCK, &chldset, NULL); pid_t pid = xfork (); if (pid == 0) { test_child (); _exit (127); } do_test_wait4 (pid); xsignal (SIGCHLD, SIG_IGN); kill (pid, SIGKILL); /* Make sure it's dead if we bailed early. */ return 0; } #include