From patchwork Tue Aug 28 14:40:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Stancek X-Patchwork-Id: 962982 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=fail (p=none dis=none) header.from=redhat.com 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 420BHv6S71z9s1x for ; Wed, 29 Aug 2018 00:40:27 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B96473E7647 for ; Tue, 28 Aug 2018 16:40:24 +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 [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id 01D1B3E605D for ; Tue, 28 Aug 2018 16:40:17 +0200 (CEST) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 3365460129C for ; Tue, 28 Aug 2018 16:40:16 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1BD7B813F709; Tue, 28 Aug 2018 14:40:15 +0000 (UTC) Received: from dustball.brq.redhat.com (unknown [10.43.17.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FAF2112D17B; Tue, 28 Aug 2018 14:40:14 +0000 (UTC) From: Jan Stancek To: ltp@lists.linux.it, liwan@redhat.com, chrubis@suse.cz, rpalethorpe@suse.com Date: Tue, 28 Aug 2018 16:40:06 +0200 Message-Id: <5730db8dee0c566014c99bc0d264326fe1c923cc.1535466715.git.jstancek@redhat.com> In-Reply-To: <920f7a911d8b32c3c2e673a9c608ded2526a616d.1535466715.git.jstancek@redhat.com> References: <920f7a911d8b32c3c2e673a9c608ded2526a616d.1535466715.git.jstancek@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 28 Aug 2018 14:40:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 28 Aug 2018 14:40:15 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jstancek@redhat.com' RCPT:'' X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS 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] [PATCH RFC v3 2/3] lib: introduce tst_timeout_remaining() 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" Which returns number of seconds remaining till timeout. Signed-off-by: Jan Stancek --- include/tst_test.h | 1 + lib/newlib_tests/test18 | Bin 0 -> 384032 bytes lib/newlib_tests/test18.c | 32 ++++++++++++++++++++++++++++++++ lib/tst_test.c | 21 +++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100755 lib/newlib_tests/test18 create mode 100644 lib/newlib_tests/test18.c diff --git a/include/tst_test.h b/include/tst_test.h index 98dacf3873ab..c0c9a7c7b995 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -217,6 +217,7 @@ const char *tst_strsig(int sig); */ const char *tst_strstatus(int status); +unsigned int tst_timeout_remaining(void); void tst_set_timeout(int timeout); #ifndef TST_NO_DEFAULT_MAIN diff --git a/lib/newlib_tests/test18 b/lib/newlib_tests/test18 new file mode 100755 index 000000000000..01dc1d7976fe Binary files /dev/null and b/lib/newlib_tests/test18 differ diff --git a/lib/newlib_tests/test18.c b/lib/newlib_tests/test18.c new file mode 100644 index 000000000000..aba007d3689c --- /dev/null +++ b/lib/newlib_tests/test18.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018, Linux Test Project + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "tst_test.h" + +static void run(void) +{ + unsigned int remaining = tst_timeout_remaining(); + if (remaining >= 200) + tst_res(TPASS, "Timeout remaining: %d", remaining); + else + tst_res(TFAIL, "Timeout remaining: %d", remaining); +} + +static struct tst_test test = { + .test_all = run, +}; diff --git a/lib/tst_test.c b/lib/tst_test.c index 2f3d357d2fcc..75619fabffa4 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -47,6 +47,8 @@ static int iterations = 1; static float duration = -1; static pid_t main_pid, lib_pid; static int mntpoint_mounted; +static clockid_t tst_clock; +static struct timespec tst_start_time; struct results { int passed; @@ -758,6 +760,7 @@ static void do_setup(int argc, char *argv[]) if (tst_test->sample) tst_test = tst_timer_test_setup(tst_test); + tst_clock = tst_timer_find_clock(); parse_opts(argc, argv); @@ -992,6 +995,21 @@ static void sigint_handler(int sig LTP_ATTRIBUTE_UNUSED) } } +unsigned int tst_timeout_remaining(void) +{ + static struct timespec now; + unsigned int elapsed; + + if (tst_clock_gettime(tst_clock, &now)) + tst_res(TWARN | TERRNO, "tst_clock_gettime() failed"); + + elapsed = tst_timespec_diff_ms(now, tst_start_time) / 1000; + if (results->timeout > elapsed) + return results->timeout - elapsed; + + return 0; +} + void tst_set_timeout(int timeout) { char *mul = getenv("LTP_TIMEOUT_MUL"); @@ -1012,6 +1030,9 @@ void tst_set_timeout(int timeout) results->timeout = results->timeout * m + 0.5; } + if (tst_clock_gettime(tst_clock, &tst_start_time)) + tst_res(TWARN | TERRNO, "tst_clock_gettime() failed"); + tst_res(TINFO, "Timeout per run is %uh %02um %02us", results->timeout/3600, (results->timeout%3600)/60, results->timeout % 60);