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