From patchwork Thu Apr 5 14:50:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895418 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40H5QC25hwz9s0y for ; Fri, 6 Apr 2018 00:52:03 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C71F03E76C4 for ; Thu, 5 Apr 2018 16:52:00 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id E22C23E605F for ; Thu, 5 Apr 2018 16:51:52 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 322282A255B for ; Thu, 5 Apr 2018 16:51:50 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 888ADAED5 for ; Thu, 5 Apr 2018 14:51:50 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 16:50:10 +0200 Message-Id: <20180405145015.7633-2-chrubis@suse.cz> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180405145015.7633-1-chrubis@suse.cz> References: <20180405145015.7633-1-chrubis@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_PASS,T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [RFC PATCH 1/6] exit02: Rewrite to new library X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" We get rid of the ridiculous sleep(2) in the test as a side effect. Signed-off-by: Cyril Hrubis --- testcases/kernel/syscalls/exit/exit02.c | 249 ++++++++------------------------ 1 file changed, 60 insertions(+), 189 deletions(-) diff --git a/testcases/kernel/syscalls/exit/exit02.c b/testcases/kernel/syscalls/exit/exit02.c index 7858c894d..8143870e8 100644 --- a/testcases/kernel/syscalls/exit/exit02.c +++ b/testcases/kernel/syscalls/exit/exit02.c @@ -1,212 +1,83 @@ /* + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2018 Cyril Hrubis * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program 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 General Public License for more details. * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ - /* - * NAME - * exit02.c - * - * DESCRIPTION - * Check that exit flushes output file buffers and closes files upon - * exitting - * - * ALGORITHM - * Fork a process that creates a file and writes a few bytes, and - * calls exit WITHOUT calling close(). The parent then reads the - * file. If everything that was written is present in the file, then - * the test passes. - * - * USAGE - * exit02 - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * None + * Fork a process that creates a file and writes a few bytes, and + * calls exit WITHOUT calling close(). The parent then reads the + * file. If everything that was written is present in the file, then + * the test passes. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "test.h" - -void cleanup(void); -void setup(void); - -char *TCID = "exit02"; -int TST_TOTAL = 1; - -#define READ 0 -#define WRITE 1 -#define MODE 0666 - -char filen[40]; - -int main(int ac, char **av) + +#include +#include "tst_test.h" + +#define FNAME "test_file" + +static void child_write(void) { - int pid, npid, sig, nsig, exno, nexno, status; - int filed; - char wbuf[BUFSIZ], rbuf[BUFSIZ]; - int len, rlen; - int rval = 0; - int lc; - - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); - - setup(); /* global setup for test */ - - /* - * The following loop checks looping state if -i option given - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - /* - * reset tst_count in case we are looping. - */ - tst_count = 0; - - strcpy(wbuf, "abcd"); - len = strlen(wbuf); - - exno = sig = 0; - - if ((pid = FORK_OR_VFORK()) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "fork() failed"); - - if (pid == 0) { /* child */ - sleep(1); - if ((filed = creat(filen, MODE)) == -1) { - tst_resm(TINFO, "creat error: unable to" - "open output file"); - exit(2); - } - if (write(filed, wbuf, len) != len) { - tst_resm(TINFO, "write error"); - exit(2); - } - exit(exno); - } else { /* parent */ - npid = wait(&status); - - if (npid != pid) { - tst_resm(TFAIL, "wait error: " - "unexpected pid returned"); - rval = 1; - } - - nsig = status % 256; - - /* - * to check if the core dump bit has been - * set, bit # 7 - */ - if (nsig >= 128) - nsig = nsig - 128; - - /* - * nsig is the signal number returned by - * wait - */ - if (nsig != sig) { - tst_resm(TFAIL, "wait error: unexpected " - "signal returned %d", nsig); - rval = 1; - } - - /* - * nexno is the exit number returned by wait - */ - nexno = status / 256; - if (nexno != exno) { - tst_resm(TFAIL, "wait error: unexpected exit " - "number %d", nexno); - rval = 1; - } - - sleep(2); /* let child's exit close opened file */ - - filed = open(filen, O_RDONLY, READ); - if (filed == -1) { - tst_resm(TFAIL, "open error: " - "unable to open input file"); - rval = 1; - } else { - rlen = read(filed, rbuf, len); - if (len != rlen) { - tst_resm(TFAIL, "exit error: file " - "buffer was not flushed"); - rval = 1; - } else if (strncmp(rbuf, wbuf, len) != 0) { - tst_resm(TFAIL, "exit error: file " - "buffer was not flushed"); - rval = 1; - } - } - close(filed); - unlink(filen); - } - if (!rval) { - tst_resm(TPASS, "exit() test PASSED"); - } - } - cleanup(); - tst_exit(); + int fd; + + fd = SAFE_CREAT(FNAME, 0666); + SAFE_WRITE(1, fd, FNAME, sizeof(FNAME)); + exit(0); } -/* - * setup() - perform all ONE TIME setup for this test - */ -void setup(void) +static void check_file(void) { + int fd, len; + char buf[256]; - tst_sig(FORK, DEF_HANDLER, cleanup); + fd = SAFE_OPEN(FNAME, O_RDONLY); + len = SAFE_READ(0, fd, buf, sizeof(buf)); - umask(0); + if (len != sizeof(FNAME)) { + tst_res(TFAIL, "Wrong length %i expected %zu", len, sizeof(buf)); + return; + } - TEST_PAUSE; + if (memcmp(buf, FNAME, sizeof(FNAME))) { + tst_res(TFAIL, "Wrong data read back"); + return; + } - tst_tmpdir(); + SAFE_CLOSE(fd); - sprintf(filen, "tfile_%d", getpid()); + tst_res(TPASS, "File written by child read back correctly"); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at completion or - * premature exit. - */ -void cleanup(void) +static void run(void) { + int pid; - /* - * Remove tmp dir and all files in it - */ - tst_rmdir(); + pid = SAFE_FORK(); + if (!pid) + child_write(); - /* - * exit with return code appropriate for results - */ + tst_reap_children(); + check_file(); + + SAFE_UNLINK(FNAME); } + +static struct tst_test test = { + .needs_tmpdir = 1, + .forks_child = 1, + .test_all = run, +}; From patchwork Thu Apr 5 14:50:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895417 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40H5Q72WV5z9s0y for ; Fri, 6 Apr 2018 00:51:59 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C76E13E77BD for ; Thu, 5 Apr 2018 16:51:56 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id A90693E605F for ; Thu, 5 Apr 2018 16:51:52 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 411B5200975 for ; Thu, 5 Apr 2018 16:51:51 +0200 (CEST) Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E41A2AF1F for ; Thu, 5 Apr 2018 14:51:50 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 16:50:11 +0200 Message-Id: <20180405145015.7633-3-chrubis@suse.cz> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180405145015.7633-1-chrubis@suse.cz> References: <20180405145015.7633-1-chrubis@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_PASS,T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [RFC PATCH 2/6] syscalls/pipe11: Rewrite to new library. X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" + Check that the buffer read in the child is correct as well + We got rid of sleep(5) as a side effect Signed-off-by: Cyril Hrubis --- testcases/kernel/syscalls/pipe/pipe11.c | 289 +++++++++----------------------- 1 file changed, 77 insertions(+), 212 deletions(-) diff --git a/testcases/kernel/syscalls/pipe/pipe11.c b/testcases/kernel/syscalls/pipe/pipe11.c index e3b274128..6964f164d 100644 --- a/testcases/kernel/syscalls/pipe/pipe11.c +++ b/testcases/kernel/syscalls/pipe/pipe11.c @@ -1,246 +1,111 @@ /* + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2018 Cyril Hrubis * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program 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 General Public License for more details. * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* - * NAME - * pipe11.c - * - * DESCRIPTION - * Check if many children can read what is written to a pipe by the - * parent. + * Check if many children can read what is written to a pipe by the parent. * * ALGORITHM - * 1. Open a pipe and write to it - * 2. Fork a large number of children - * 3. Have the children read the pipe and check how many characters - * each got - * - * USAGE: - * pipe11 [-c n] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * None + * For a different nchilds number: + * 1. Open a pipe and write nchilds * (PIPE_BUF/nchilds) bytes into it + * 2. Fork nchilds children + * 3. Each child reads PIPE_BUF/nchilds characters and checks that the + * bytes read are correct */ -#include -#include -#include -#include -#include -#include "test.h" - -char *TCID = "pipe11"; -int TST_TOTAL = 1; - -void do_child(void); -void do_child_uclinux(void); -void setup(void); -void cleanup(void); - -#define NUMCHILD 50 -#define NCPERCHILD 50 -char rawchars[] = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"; -int kidid; -int numchild; /* no of children to fork */ -int ncperchild; /* no of chars child should read */ -int szcharbuf; /* size of char buf */ -int pipewrcnt; /* chars written to pipe */ -char *wrbuf, *rdbuf; -int fd[2]; /* fds for pipe read/write */ - -ssize_t do_read(int fd, void *buf, size_t count) -{ - ssize_t n; - - do { - n = read(fd, buf, count); - } while (n < 0 && errno == EINTR); +#include +#include "tst_test.h" - return n; -} +static int fd[2]; +static unsigned char buf[PIPE_BUF]; +static size_t read_per_child; -int main(int ac, char **av) +void do_child(void) { - int lc; - - int i; - int fork_ret, status; - int written; /* no of chars read and written */ - - tst_parse_opts(ac, av, NULL, NULL); -#ifdef UCLINUX - maybe_run_child(&do_child_uclinux, "ddddd", &fd[0], &fd[1], &kidid, - &ncperchild, &szcharbuf); -#endif - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - /* reset tst_count in case we are looping */ - tst_count = 0; + size_t nread; + unsigned char rbuf[read_per_child]; + unsigned int i; - TEST(pipe(fd)); + SAFE_CLOSE(fd[1]); - if (TEST_RETURN != 0) { - tst_resm(TFAIL, "pipe creation failed"); - continue; - } - - written = write(fd[1], wrbuf, szcharbuf); - if (written != szcharbuf) { - tst_brkm(TBROK, cleanup, "write to pipe failed"); - } - -refork: - ++kidid; - fork_ret = FORK_OR_VFORK(); - - if (fork_ret < 0) { - tst_brkm(TBROK, cleanup, "fork() failed"); - } - - if ((fork_ret != 0) && (fork_ret != -1) && (kidid < numchild)) { - goto refork; - } + nread = SAFE_READ(0, fd[0], rbuf, sizeof(rbuf)); - if (fork_ret == 0) { /* child */ -#ifdef UCLINUX - if (self_exec(av[0], "ddddd", fd[0], fd[1], kidid, - ncperchild, szcharbuf) < 0) { - tst_brkm(TBROK, cleanup, "self_exec failed"); - } -#else - do_child(); -#endif - } + if (nread != read_per_child) { + tst_res(TFAIL, "Invalid read size child %i size %zu", + getpid(), nread); + return; + } - /* parent */ - sleep(5); - tst_resm(TINFO, "There are %d children to wait for", kidid); - for (i = 1; i <= kidid; ++i) { - wait(&status); - if (status == 0) { - tst_resm(TPASS, "child %d exited successfully", - i); - } else { - tst_resm(TFAIL, "child %d exited with bad " - "status", i); - } + for (i = 0; i < read_per_child; i++) { + if (rbuf[i] != (i % 256)) { + tst_res(TFAIL, + "Invalid byte read child %i byte %i have %i expected %i", + getpid(), i, rbuf[i], i % 256); + return; } } - cleanup(); - - tst_exit(); -} - -/* - * do_child() - */ -void do_child(void) -{ - int nread; - if (close(fd[1])) { - tst_resm(TINFO, "child %d " "could not close pipe", kidid); - exit(0); - } - nread = do_read(fd[0], rdbuf, ncperchild); - if (nread == ncperchild) { - tst_resm(TINFO, "child %d " "got %d chars", kidid, nread); - exit(0); - } else { - tst_resm(TFAIL, "child %d did not receive expected no of " - "characters, got %d characters", kidid, nread); - exit(1); - } + tst_res(TPASS, "Child %i read pipe buffer correctly", getpid()); } -/* - * do_child_uclinux() - as above, but mallocs rdbuf first - */ -void do_child_uclinux(void) -{ - if ((rdbuf = malloc(szcharbuf)) == NULL) { - tst_brkm(TBROK, cleanup, "malloc of rdbuf failed"); - } - - do_child(); -} +static unsigned int childs[] = { + 1, + 2, + 3, + 4, + 10, + 50 +}; -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) +static void run(unsigned int tcase) { - int i; - unsigned int j; + pid_t pid; + unsigned int nchilds = childs[tcase]; + read_per_child = PIPE_BUF/nchilds; + unsigned int i, j; - tst_sig(FORK, DEF_HANDLER, cleanup); + tst_res(TINFO, "Reading %zu per each of %u children", + read_per_child, nchilds); - TEST_PAUSE; - - numchild = NUMCHILD; - ncperchild = NCPERCHILD; + for (i = 0; i < nchilds; i++) { + for (j = 0; j < read_per_child; j++) { + buf[i * read_per_child + j] = j % 256; + } + } - kidid = 0; + SAFE_PIPE(fd); - /* allocate read and write buffers */ - szcharbuf = numchild * ncperchild; + SAFE_WRITE(1, fd[1], buf, read_per_child * nchilds); - /* make sure pipe write doesn't block */ - if (szcharbuf == PIPE_BUF) { - /* adjust number of characters per child */ - ncperchild = szcharbuf / numchild; - } + for (i = 0; i < nchilds; i++) { + pid = SAFE_FORK(); - if ((wrbuf = malloc(szcharbuf)) == NULL) { - tst_brkm(TBROK, cleanup, "malloc failed"); - } - - if ((rdbuf = malloc(szcharbuf)) == NULL) { - tst_brkm(TBROK, cleanup, "malloc of rdbuf failed"); + if (!pid) { + do_child(); + exit(0); + } } - /* initialize wrbuf */ - j = 0; - for (i = 0; i < szcharbuf;) { - wrbuf[i++] = rawchars[j++]; - if (j >= sizeof(rawchars)) - j = 0; - } + tst_reap_children(); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - -} +static struct tst_test test = { + .forks_child = 1, + .test = run, + .tcnt = ARRAY_SIZE(childs), +}; From patchwork Thu Apr 5 14:50:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895420 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40H5QN1kMjz9s0y for ; Fri, 6 Apr 2018 00:52:12 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BE5173E7311 for ; Thu, 5 Apr 2018 16:52:09 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id 22D3E3E76AD for ; Thu, 5 Apr 2018 16:51:53 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id B44F920006D for ; Thu, 5 Apr 2018 16:51:52 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6531BAF61 for ; Thu, 5 Apr 2018 14:51:52 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 16:50:12 +0200 Message-Id: <20180405145015.7633-4-chrubis@suse.cz> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180405145015.7633-1-chrubis@suse.cz> References: <20180405145015.7633-1-chrubis@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_PASS,T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [RFC PATCH 3/6] syscalls/alarm05: Rewrite to the new library. X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" + Speed up the test a bit, we save 6 seconds yay! Signed-off-by: Cyril Hrubis --- testcases/kernel/syscalls/alarm/alarm05.c | 216 +++++++----------------------- 1 file changed, 45 insertions(+), 171 deletions(-) diff --git a/testcases/kernel/syscalls/alarm/alarm05.c b/testcases/kernel/syscalls/alarm/alarm05.c index 1e93d2554..acb43c9a8 100644 --- a/testcases/kernel/syscalls/alarm/alarm05.c +++ b/testcases/kernel/syscalls/alarm/alarm05.c @@ -1,203 +1,77 @@ /* + * Copyright (c) International Business Machines Corp., 2001,2005 + * 07/2001 Ported by Wayne Boyer + * 06/2005 Test for alarm cleanup by Amos Waterland * - * Copyright (c) International Business Machines Corp., 2001,2005 + * Copyright (c) 2018 Cyril Hrubis * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program 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 General Public License for more details. + * This program 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 General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* - * Test Name: alarm05 - * * Test Description: - * Check the functionality of the Alarm system call when the time input - * parameter is non zero. - * - * Expected Result: * The return value of the alarm system call should be equal to the * amount previously remaining in the alarm clock. * A SIGALRM signal should be received after the specified amount of * time has elapsed. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * - * Usage: - * alarm05 [-c n] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 06/2005 Test for alarm cleanup by Amos Waterland - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS: - * None. */ -#include -#include -#include -#include -#include -#include - -#include "test.h" +#include "tst_test.h" -char *TCID = "alarm05"; -int TST_TOTAL = 1; -int alarms_received = 0; /* flag to indicate SIGALRM received or not */ +static volatile int alarms_fired = 0; -void setup(); /* Main setup function of test */ -void cleanup(); /* cleanup function for the test */ -void sigproc(int sig); /* signal catching function */ - -int main(int ac, char **av) +static void run(void) { - int lc; - int time_sec1 = 10; /* time for which 1st alarm is set */ - int time_sec2 = 5; /* time for which 2st alarm is set */ - int ret_val1, ret_val2; /* return values for alarm() calls */ - int ret_val3; - int sleep_time1 = 3; /* waiting time for the signal */ - int sleep_time2 = 6; /* waiting time for the signal */ - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { + unsigned int ret; - tst_count = 0; + alarms_fired = 0; - /* - * Reset alarms_received for every iteration, since it has - * old values from previous iterations (if any) and not - * a value of zero - */ - alarms_received = 0; + ret = alarm(10); + if (ret) + tst_res(TFAIL, "alarm() returned non-zero"); + else + tst_res(TPASS, "alarm() returned zero"); - /* - * Call First alarm() with non-zero time parameter - * 'time_sec1' to send SIGALRM to the calling process. - */ - TEST(alarm(time_sec1)); - ret_val1 = TEST_RETURN; + sleep(1); - /* Wait for signal SIGALARM */ - sleep(sleep_time1); + ret = alarm(1); + if (ret == 9) + tst_res(TPASS, "alarm() returned remainder correctly"); + else + tst_res(TFAIL, "alarm() returned wrong remained %u", ret); - /* - * Call Second alarm() with non-zero time parameter - * 'time_sec2' to send SIGALRM to the calling process. - */ - TEST(alarm(time_sec2)); - ret_val2 = TEST_RETURN; + sleep(2); - /* Wait for signal SIGALRM */ - sleep(sleep_time2); - - /* - * Check whether the second alarm() call returned - * the amount of time previously remaining in the - * alarm clock of the calling process, and - * sigproc() executed when SIGALRM received by the - * process, the variable alarms_received is set. - */ - if ((alarms_received == 1) && - (ret_val2 == (time_sec1 - sleep_time1))) { - - /* - * Make sure the system cleaned up the alarm - * after it delivered it. - */ - TEST(alarm(0)); - ret_val3 = TEST_RETURN; - - if (ret_val3 != 0) - tst_resm(TFAIL, "System did not " - "clean up delivered " "alarm"); - else { - tst_resm(TPASS, "Functionality of " - "alarm(%u) successful", - time_sec2); - } - } else { - tst_resm(TFAIL, "alarm(%u) fails, returned %d, " - "alarms_received:%d", - time_sec2, ret_val2, alarms_received); - } - } - - cleanup(); - tst_exit(); + if (alarms_fired == 1) + tst_res(TPASS, "alarm handler fired once"); + else + tst_res(TFAIL, "alarm handler filred %u times", alarms_fired); } -/* - * setup() - performs all ONE TIME setup for this test. - * Setup the signal handler to catch SIGALRM. - */ -void setup(void) +static void sighandler(int sig) { - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* Set the signal catching function */ - if (signal(SIGALRM, sigproc) == SIG_ERR) { - tst_brkm(TFAIL, cleanup, - "signal() fails to catch SIGALARM, errno=%d", errno); - } + if (sig == SIGALRM) + alarms_fired++; } -/* - * sigproc(int) - This function defines the action that has to be taken - * when the SIGALRM signal is caught. - * It also sets the variable which is used to check whether the - * alarm system call was successful. - */ -void sigproc(int sig) +static void setup(void) { - alarms_received++; + SAFE_SIGNAL(SIGALRM, sighandler); } -/* - * void - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ -} +static struct tst_test test = { + .test_all = run, + .setup = setup, +}; From patchwork Thu Apr 5 14:50:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40H5QY55KSz9s0y for ; Fri, 6 Apr 2018 00:52:21 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 009C63E792C for ; Thu, 5 Apr 2018 16:52:16 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) by picard.linux.it (Postfix) with ESMTP id 0D0943E7809 for ; Thu, 5 Apr 2018 16:52:02 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 266241A01163 for ; Thu, 5 Apr 2018 16:51:52 +0200 (CEST) Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B7CABAF31 for ; Thu, 5 Apr 2018 14:51:51 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 16:50:13 +0200 Message-Id: <20180405145015.7633-5-chrubis@suse.cz> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180405145015.7633-1-chrubis@suse.cz> References: <20180405145015.7633-1-chrubis@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_PASS,T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [RFC PATCH 4/6] syscalls/alarm01: Remove X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" The test was simply wrong alarm() does not return a failure at all. Signed-off-by: Cyril Hrubis --- runtest/ltplite | 1 - runtest/quickhit | 2 - runtest/stress.part3 | 1 - runtest/syscalls | 1 - testcases/kernel/syscalls/.gitignore | 1 - testcases/kernel/syscalls/alarm/alarm01.c | 176 ------------------------------ 6 files changed, 182 deletions(-) delete mode 100644 testcases/kernel/syscalls/alarm/alarm01.c diff --git a/runtest/ltplite b/runtest/ltplite index 15dc0c20f..001325d65 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -71,7 +71,6 @@ acct01 acct01 adjtimex01 adjtimex01 adjtimex02 adjtimex02 -alarm01 alarm01 alarm02 alarm02 alarm03 alarm03 alarm05 alarm05 diff --git a/runtest/quickhit b/runtest/quickhit index 99e7c4779..2a1056971 100644 --- a/runtest/quickhit +++ b/runtest/quickhit @@ -3,8 +3,6 @@ access01 access01 # Basic test for access(2) using F_OK, R_OK, W_OK and X_OK arguments. access03 access03 # EFAULT error testing for access(2) -alarm01 alarm01 -# Basic test for alarm(2) alarm02 alarm02 # Boundary Value Test for alarm(2) # TEST CASES diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 2a7747ce3..0d5951454 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -13,7 +13,6 @@ acct01 acct01 adjtimex01 adjtimex01 adjtimex02 adjtimex02 -alarm01 alarm01 alarm02 alarm02 alarm03 alarm03 alarm05 alarm05 diff --git a/runtest/syscalls b/runtest/syscalls index 76ab082be..71cfd2d6f 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -19,7 +19,6 @@ add_key04 add_key04 adjtimex01 adjtimex01 adjtimex02 adjtimex02 -alarm01 alarm01 alarm02 alarm02 alarm03 alarm03 alarm05 alarm05 diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index eea606e61..cd80cfc8f 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -12,7 +12,6 @@ /add_key/add_key04 /adjtimex/adjtimex01 /adjtimex/adjtimex02 -/alarm/alarm01 /alarm/alarm02 /alarm/alarm03 /alarm/alarm05 diff --git a/testcases/kernel/syscalls/alarm/alarm01.c b/testcases/kernel/syscalls/alarm/alarm01.c deleted file mode 100644 index f17207b0a..000000000 --- a/testcases/kernel/syscalls/alarm/alarm01.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, - * Mountain View, CA 94043, or: - * - * http://www.sgi.com - * - * For further information regarding this notice, see: - * - * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ - */ -/* $Id: alarm01.c,v 1.6 2009/08/28 10:57:29 vapier Exp $ */ -/********************************************************** - * - * OS Test - Silicon Graphics, Inc. - * - * TEST IDENTIFIER : alarm01 - * - * EXECUTED BY : anyone - * - * TEST TITLE : Basic test for alarm(2) - * - * PARENT DOCUMENT : usctpl01 - * - * TEST CASE TOTAL : 1 - * - * WALL CLOCK TIME : 1 - * - * CPU TYPES : ALL - * - * AUTHOR : William Roske - * - * CO-PILOT : Dave Fenner - * - * DATE STARTED : 03/30/92 - * - * INITIAL RELEASE : UNICOS 7.0 - * - * TEST CASES - * - * 1.) alarm(2) returns...(See Description) - * - * INPUT SPECIFICATIONS - * The standard options for system call tests are accepted. - * (See the parse_opts(3) man page). - * - * OUTPUT SPECIFICATIONS - *$ - * DURATION - * Terminates - with frequency and infinite modes. - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * RESOURCES - * None - * - * ENVIRONMENTAL NEEDS - * The libcuts.a and libsys.a libraries must be included in - * the compilation of this test. - * - * SPECIAL PROCEDURAL REQUIREMENTS - * None - * - * INTERCASE DEPENDENCIES - * None - * - * DETAILED DESCRIPTION - * This is a Phase I test for the alarm(2) system call. It is intended - * to provide a limited exposure of the system call, for now. It - * should/will be extended when full functional tests are written for - * alarm(2). - * - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, Issue a PASS message. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * - * - *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ - -#include -#include -#include -#include "test.h" - -void setup(); -void cleanup(); - -char *TCID = "alarm01"; -int TST_TOTAL = 1; - -int main(int ac, char **av) -{ - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Call alarm(2) - */ - TEST(alarm(1)); - - /* check return code */ - if (TEST_RETURN == -1) - tst_resm(TFAIL | TTERRNO, "alarm(1) failed"); - else { - tst_resm(TPASS, "alarm(1) returned %ld", - TEST_RETURN); - } - - } - - cleanup(); - tst_exit(); -} - -void setup(void) -{ - void trapper(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - signal(SIGALRM, trapper); - - TEST_PAUSE; -} - -/*************************************************************** - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - ***************************************************************/ -void cleanup(void) -{ -} - -void trapper(int sig) -{ - signal(SIGALRM, trapper); -} From patchwork Thu Apr 5 14:50:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895419 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40H5QH36cTz9s27 for ; Fri, 6 Apr 2018 00:52:07 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D5EAA3E7804 for ; Thu, 5 Apr 2018 16:52:04 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id DC2ED3E730A for ; Thu, 5 Apr 2018 16:51:52 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 772B31001BDC for ; Thu, 5 Apr 2018 16:51:52 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 16EC5AE81 for ; Thu, 5 Apr 2018 14:51:52 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 16:50:14 +0200 Message-Id: <20180405145015.7633-6-chrubis@suse.cz> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180405145015.7633-1-chrubis@suse.cz> References: <20180405145015.7633-1-chrubis@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_PASS,T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [RFC PATCH 5/6] syscalls/waitpid01: Rewrite to the new library. X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" + use raise(SIGALRM) instead of wasting time with alarm(2) Signed-off-by: Cyril Hrubis --- testcases/kernel/syscalls/waitpid/waitpid01.c | 172 ++++++++------------------ 1 file changed, 52 insertions(+), 120 deletions(-) diff --git a/testcases/kernel/syscalls/waitpid/waitpid01.c b/testcases/kernel/syscalls/waitpid/waitpid01.c index e05e783ef..efbc26e5a 100644 --- a/testcases/kernel/syscalls/waitpid/waitpid01.c +++ b/testcases/kernel/syscalls/waitpid/waitpid01.c @@ -1,142 +1,74 @@ /* + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 John George + * Copyright (c) 2018 Cyril Hrubis * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program 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 General Public License for more details. * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* - * NAME - * waitpid01.c - * - * DESCRIPTION - * Check that when a child kills itself by generating an alarm - * exception, the waiting parent is correctly notified. - * - * ALGORITHM - * Fork a child that sets an alarm. When the alarm goes off, causing - * the death of the child, the parent checks that SIG_ALRM was returned - * - * USAGE: - * waitpid01 [-c n] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * History - * 07/2001 John George - * -Ported + * Check that when a child kills itself by SIGALRM the waiting parent is + * correctly notified. * - * Restrictions - * None + * Fork a child that raises(SIGALRM), the parent checks that SIGALRM was + * returned. */ - -#include -#include +#include #include -#include -#include "test.h" - -static void setup(void); -static void cleanup(void); - -char *TCID = "waitpid01"; -int TST_TOTAL = 1; +#include "tst_test.h" -int main(int argc, char **argv) +static void run(void) { - int lc; - - int pid, npid, sig, nsig; - int exno, nexno, status; - - tst_parse_opts(argc, argv, NULL, NULL); + pid_t pid, rpid; + int status; - setup(); - - /* check for looping state if -i option is given */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset tst_count in case we are looping */ - tst_count = 0; - - exno = 1; - sig = 14; + pid = SAFE_FORK(); + if (!pid) { + raise(SIGALRM); + exit(0); + } - pid = FORK_OR_VFORK(); - if (pid < 0) { - tst_brkm(TFAIL, cleanup, "Fork Failed"); - } else if (pid == 0) { - alarm(2); - pause(); - exit(exno); - } else { - errno = 0; - while (((npid = waitpid(pid, &status, 0)) != -1) || - (errno == EINTR)) { - if (errno == EINTR) - continue; + rpid = waitpid(pid, &status, 0); + if (rpid < 0) + tst_brk(TBROK | TERRNO, "waitpid() failed"); - if (npid != pid) { - tst_resm(TFAIL, "waitpid error: " - "unexpected pid returned"); - } else { - tst_resm(TPASS, - "recieved expected pid"); - } + if (rpid != pid) { + tst_res(TFAIL, "waitpid() returned wrong pid %i, expected %i", + rpid, pid); + } else { + tst_res(TPASS, "waitpid() returned correct pid %i", pid); + } - nsig = WTERMSIG(status); + if (!WIFSIGNALED(status)) { + tst_res(TFAIL, "WIFSIGNALED() not set in status (%s)", + tst_strstatus(status)); + return; + } - /* - * nsig is the signal number returned by - * waitpid - */ - if (nsig != sig) { - tst_resm(TFAIL, "waitpid error: " - "unexpected signal " - "returned"); - } else { - tst_resm(TPASS, "recieved expected " - "signal"); - } + tst_res(TPASS, "WIFSIGNALED() set in status"); - /* - * nexno is the exit number returned by - * waitpid - */ - nexno = WEXITSTATUS(status); - if (nexno != 0) { - tst_resm(TFAIL, "signal error: " - "unexpected exit number " - "returned"); - } - } - } + if (WTERMSIG(status) != SIGALRM) { + tst_res(TFAIL, "WTERMSIG() != SIGALRM but %s", + tst_strsig(WTERMSIG(status))); + return; } - cleanup(); - tst_exit(); + tst_res(TPASS, "WTERMSIG() == SIGALRM"); } -static void setup(void) -{ - TEST_PAUSE; -} - -static void cleanup(void) -{ - tst_sig(FORK, DEF_HANDLER, cleanup); -} +static struct tst_test test = { + .forks_child = 1, + .test_all = run, +}; From patchwork Thu Apr 5 14:50:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895421 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40H5QS1CDnz9s0y for ; Fri, 6 Apr 2018 00:52:15 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id ADA153E7844 for ; Thu, 5 Apr 2018 16:52:12 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id 24DAC3E76AE for ; Thu, 5 Apr 2018 16:51:53 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id BDFB26021B2 for ; Thu, 5 Apr 2018 16:51:52 +0200 (CEST) Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6D4CBAF63 for ; Thu, 5 Apr 2018 14:51:52 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 16:50:15 +0200 Message-Id: <20180405145015.7633-7-chrubis@suse.cz> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180405145015.7633-1-chrubis@suse.cz> References: <20180405145015.7633-1-chrubis@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_PASS,T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Subject: [LTP] [RFC PATCH 6/6] syscalls/wait401: Rewrite to the new library X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" + Get rid of the sleep(1) in the process Signed-off-by: Cyril Hrubis --- testcases/kernel/syscalls/wait4/wait401.c | 122 +++++++++++------------------- 1 file changed, 45 insertions(+), 77 deletions(-) diff --git a/testcases/kernel/syscalls/wait4/wait401.c b/testcases/kernel/syscalls/wait4/wait401.c index 26a5c7002..eb5f41f42 100644 --- a/testcases/kernel/syscalls/wait4/wait401.c +++ b/testcases/kernel/syscalls/wait4/wait401.c @@ -1,106 +1,74 @@ /* + * Copyright (c) International Business Machines Corp., 2001 + * Copyright (c) 2012-2018 Cyril Hrubis * - * Copyright (c) International Business Machines Corp., 2001 - * Copyright (c) 2012 Cyril Hrubis + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program 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 General Public License for more details. * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* - * wait401 - check that a call to wait4() correctly waits for a child - * process to exit + * wait401 - check that a call to wait4() correctly waits for a child + * process to exit */ -#include "test.h" - +#include #include #define _USE_BSD #include #include #include +#include "tst_test.h" -char *TCID = "wait401"; -int TST_TOTAL = 1; - -static void cleanup(void); -static void setup(void); - -int main(int ac, char **av) +static void run(void) { - int lc; pid_t pid; int status = 1; struct rusage rusage; - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - - pid = FORK_OR_VFORK(); - - switch (pid) { - case -1: - tst_brkm(TBROK, cleanup, "fork() failed"); - break; - case 0: - sleep(1); - exit(0); - break; - default: - TEST(wait4(pid, &status, 0, &rusage)); - break; - } + pid = SAFE_FORK(); + if (!pid) + exit(0); - if (TEST_RETURN == -1) { - tst_brkm(TFAIL, cleanup, "%s call failed - errno = %d " - ": %s", TCID, TEST_ERRNO, - strerror(TEST_ERRNO)); - } - - if (WIFEXITED(status) == 0) { - tst_brkm(TFAIL, cleanup, - "%s call succeeded but " - "WIFEXITED() did not return expected value " - "- %d", TCID, WIFEXITED(status)); - } else if (TEST_RETURN != pid) { - tst_resm(TFAIL, "%s did not return the " - "expected value (%d), actual: %ld", - TCID, pid, TEST_RETURN); - } else { + TEST(wait4(pid, &status, 0, &rusage)); + if (TEST_RETURN == -1) { + tst_res(TFAIL | TERRNO, "wait4() failed"); + return; + } - tst_resm(TPASS, - "Received child pid as expected."); - } + if (TEST_RETURN != pid) { + tst_res(TFAIL, "waitpid() returned wrong pid %li, expected %i", + TEST_RETURN, pid); + } else { + tst_res(TPASS, "waitpid() returned correct pid %i", pid); + } - tst_resm(TPASS, "%s call succeeded", TCID); + if (!WIFEXITED(status)) { + tst_res(TFAIL, "WIFEXITED() not set in status (%s)", + tst_strstatus(status)); + return; } - cleanup(); - tst_exit(); -} + tst_res(TPASS, "WIFEXITED() is set in status"); -static void setup(void) -{ - tst_sig(FORK, DEF_HANDLER, cleanup); + if (WEXITSTATUS(status)) + tst_res(TFAIL, "WEXITSTATUS() != 0 but %i", WEXITSTATUS(status)); + else + tst_res(TPASS, "WEXITSTATUS() == 0"); - TEST_PAUSE; } -static void cleanup(void) -{ -} +static struct tst_test test = { + .forks_child = 1, + .test_all = run, +};