From patchwork Mon Aug 27 09:30:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 962403 X-Patchwork-Delegate: petr.vorel@gmail.com 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.com 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 41zRTl0nFrz9s2P for ; Mon, 27 Aug 2018 19:31:20 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D26EB3E78D1 for ; Mon, 27 Aug 2018 11:31:17 +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 [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id 6B8F93E7254 for ; Mon, 27 Aug 2018 11:31:10 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id E10DC1000BE2 for ; Mon, 27 Aug 2018 11:31:09 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C7E9FAEB0 for ; Mon, 27 Aug 2018 09:31:08 +0000 (UTC) From: Richard Palethorpe To: ltp@lists.linux.it Date: Mon, 27 Aug 2018 11:30:50 +0200 Message-Id: <20180827093053.24658-1-rpalethorpe@suse.com> X-Mailer: git-send-email 2.18.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Cc: pvorel@suse.com, Richard Palethorpe Subject: [LTP] [PATCH v2 1/4] Convert nanosleep02 to newlib 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" Also add extra check that nanosleep exited with the expected return value and errno for the user's information. Signed-off-by: Richard Palethorpe Reviewed-by: Petr Vorel --- V2: Removed the falls through attribute for case statements and replace it with a comment .../kernel/syscalls/nanosleep/nanosleep02.c | 123 ++++++------------ 1 file changed, 40 insertions(+), 83 deletions(-) diff --git a/testcases/kernel/syscalls/nanosleep/nanosleep02.c b/testcases/kernel/syscalls/nanosleep/nanosleep02.c index 42c825190..2abe38a95 100644 --- a/testcases/kernel/syscalls/nanosleep/nanosleep02.c +++ b/testcases/kernel/syscalls/nanosleep/nanosleep02.c @@ -26,24 +26,10 @@ */ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include "test.h" -#include "safe_macros.h" - -char *TCID = "nanosleep02"; -int TST_TOTAL = 1; - -static void do_child(void); -static void setup(void); -static void sig_handler(); +#include "tst_test.h" +#include "tst_timer.h" +#include "tst_safe_macros.h" /* * Define here the "rem" precision in microseconds, @@ -57,50 +43,6 @@ static void sig_handler(); */ #define USEC_PRECISION 250000 /* Error margin allowed in usec */ -int main(int ac, char **av) -{ - int lc; - pid_t cpid; - - tst_parse_opts(ac, av, NULL, NULL); - -#ifdef UCLINUX - maybe_run_child(&do_child, ""); -#endif - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - if ((cpid = FORK_OR_VFORK()) == -1) { - tst_brkm(TBROK, NULL, - "fork() failed to create child process"); - } - - if (cpid == 0) { -#ifdef UCLINUX - if (self_exec(av[0], "")) { - tst_brkm(TBROK, NULL, "self_exec failed"); - } -#else - do_child(); -#endif - } - - /* wait for child to time slot for execution */ - sleep(1); - - /* Now send signal to child */ - SAFE_KILL(NULL, cpid, SIGINT); - - tst_record_childstatus(NULL, cpid); - } - - tst_exit(); -} - static void do_child(void) { struct timespec timereq = {.tv_sec = 5, .tv_nsec = 9999}; @@ -110,42 +52,57 @@ static void do_child(void) TEST(nanosleep(&timereq, &timerem)); tst_timer_stop(); - if (tst_timespec_lt(timereq, tst_timer_elapsed())) { - tst_resm(TFAIL, "nanosleep() slept more than timereq"); - return; - } + if (!TST_RET) + tst_brk(TBROK, "nanosleep was not interrupted"); + if (TST_ERR != EINTR) + tst_brk(TBROK | TTERRNO, "nanosleep() failed"); + + if (tst_timespec_lt(timereq, tst_timer_elapsed())) + tst_brk(TFAIL, "nanosleep() slept more than timereq"); exp_rem = tst_timespec_diff(timereq, tst_timer_elapsed()); if (tst_timespec_abs_diff_us(timerem, exp_rem) > USEC_PRECISION) { - tst_resm(TFAIL, - "nanosleep() remaining time %llius, expected %llius, diff %llius", - tst_timespec_to_us(timerem), tst_timespec_to_us(exp_rem), - tst_timespec_abs_diff_us(timerem, exp_rem)); + tst_res(TFAIL, + "nanosleep() remaining time %llius, expected %llius, diff %llius", + tst_timespec_to_us(timerem), tst_timespec_to_us(exp_rem), + tst_timespec_abs_diff_us(timerem, exp_rem)); } else { - tst_resm(TPASS, - "nanosleep() slept for %llius, remaining time difference %llius", - tst_timer_elapsed_us(), - tst_timespec_abs_diff_us(timerem, exp_rem)); + tst_res(TPASS, + "nanosleep() slept for %llius, remaining time difference %llius", + tst_timer_elapsed_us(), + tst_timespec_abs_diff_us(timerem, exp_rem)); } - - tst_exit(); } -static void setup(void) +void run(void) { - tst_sig(FORK, DEF_HANDLER, NULL); + pid_t cpid; - tst_timer_check(CLOCK_MONOTONIC); + cpid = SAFE_FORK(); + if (cpid == 0) { + do_child(); + } else { + sleep(1); - TEST_PAUSE; + SAFE_KILL(cpid, SIGINT); - if (signal(SIGINT, sig_handler) == SIG_ERR) { - tst_brkm(TBROK, NULL, - "signal() fails to setup signal handler"); + tst_reap_children(); } } -static void sig_handler(void) +static void sig_handler(int si LTP_ATTRIBUTE_UNUSED) +{ +} + +static void setup(void) { + tst_timer_check(CLOCK_MONOTONIC); + SAFE_SIGNAL(SIGINT, sig_handler); } + +static struct tst_test test = { + .forks_child = 1, + .setup = setup, + .test_all = run, +};