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, +};