From patchwork Fri Aug 10 08:36:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 956140 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.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 41mz570q19z9s5b for ; Fri, 10 Aug 2018 18:37:14 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CF3003E711B for ; Fri, 10 Aug 2018 10:37:10 +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 [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 836563E6099 for ; Fri, 10 Aug 2018 10:37:08 +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-7.smtp.seeweb.it (Postfix) with ESMTPS id 78401200DC4 for ; Fri, 10 Aug 2018 10:37:07 +0200 (CEST) Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 7635CADBD; Fri, 10 Aug 2018 08:37:06 +0000 (UTC) From: Richard Palethorpe To: ltp@lists.linux.it Date: Fri, 10 Aug 2018 10:36:53 +0200 Message-Id: <20180810083654.28938-2-rpalethorpe@suse.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180810083654.28938-1-rpalethorpe@suse.com> References: <20180810083654.28938-1-rpalethorpe@suse.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-7.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-7.smtp.seeweb.it Cc: Richard Palethorpe Subject: [LTP] [PATCH 1/2] tst_timer: Add tst_timer_state_ms function 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" Allow the user to discover the current timer state with a single function. Useful for using a timer in a loop where we do not know if the timer has already been started. Signed-off-by: Richard Palethorpe --- include/tst_timer.h | 7 +++++++ lib/tst_timer.c | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/tst_timer.h b/include/tst_timer.h index 0fd7ed6cf..a6df53e82 100644 --- a/include/tst_timer.h +++ b/include/tst_timer.h @@ -34,6 +34,11 @@ #include #include +#define TST_TIMER_NONE 0 +#define TST_TIMER_STARTED 1 +#define TST_TIMER_STOPPED (1 << 1) +#define TST_TIMER_EXPIRED (1 << 2) + /* * Converts timespec to microseconds. */ @@ -259,6 +264,8 @@ void tst_timer_start(clockid_t clk_id); */ int tst_timer_expired_ms(long long ms); +int tst_timer_state_ms(long long ms); + /* * Marks timer end time. */ diff --git a/lib/tst_timer.c b/lib/tst_timer.c index 53ff36777..80dc8cf1f 100644 --- a/lib/tst_timer.c +++ b/lib/tst_timer.c @@ -87,6 +87,17 @@ int tst_timer_expired_ms(long long ms) return tst_timespec_diff_ms(cur_time, start_time) >= ms; } +int tst_timer_state_ms(long long ms) +{ + int status = TST_TIMER_NONE; + + status |= (start_time.tv_sec | start_time.tv_nsec) > 0; + status |= ((stop_time.tv_sec | stop_time.tv_nsec) > 0) << 1; + status |= tst_timer_expired_ms(ms) << 2; + + return status; +} + void tst_timer_stop(void) { if (tst_clock_gettime(clock_id, &stop_time)) From patchwork Fri Aug 10 08:36:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 956141 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.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 41mz5919JYz9s5b for ; Fri, 10 Aug 2018 18:37:17 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 6F7383E710C for ; Fri, 10 Aug 2018 10:37:14 +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 [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 90F5E3E60A8 for ; Fri, 10 Aug 2018 10:37:08 +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-7.smtp.seeweb.it (Postfix) with ESMTPS id 785CE200DDB for ; Fri, 10 Aug 2018 10:37:07 +0200 (CEST) Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 79347AE5C; Fri, 10 Aug 2018 08:37:06 +0000 (UTC) From: Richard Palethorpe To: ltp@lists.linux.it Date: Fri, 10 Aug 2018 10:36:54 +0200 Message-Id: <20180810083654.28938-3-rpalethorpe@suse.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180810083654.28938-1-rpalethorpe@suse.com> References: <20180810083654.28938-1-rpalethorpe@suse.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-7.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-7.smtp.seeweb.it Cc: Richard Palethorpe Subject: [LTP] [PATCH 2/2] fzsync: Limit execution time to prevent test timeouts 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 the tst_timer library to check how long the main test loop has been running for and break the loop if it exceeds 60 seconds. This prevents an overall test timeout which is reported as a failure. Signed-off-by: Richard Palethorpe --- include/tst_fuzzy_sync.h | 43 +++++++++++++------ lib/newlib_tests/test16.c | 3 +- testcases/cve/cve-2014-0196.c | 3 +- testcases/cve/cve-2016-7117.c | 3 +- testcases/cve/cve-2017-2671.c | 3 +- testcases/kernel/syscalls/inotify/inotify09.c | 3 +- 6 files changed, 40 insertions(+), 18 deletions(-) diff --git a/include/tst_fuzzy_sync.h b/include/tst_fuzzy_sync.h index bcc625e24..0d561edf6 100644 --- a/include/tst_fuzzy_sync.h +++ b/include/tst_fuzzy_sync.h @@ -42,6 +42,7 @@ #include #include #include "tst_atomic.h" +#include "tst_timer.h" #ifndef CLOCK_MONOTONIC_RAW # define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC @@ -280,6 +281,17 @@ static inline int tst_fzsync_wait_b(struct tst_fzsync_pair *pair) return tst_fzsync_pair_wait(pair, &pair->b_cntr, &pair->a_cntr); } +/** + * tst_fzsync_pair_exit - Signal that the other thread should exit + * + * Causes tst_fzsync_pair_wait() and tst_fzsync_pair_wait_update() to return + * 0. + */ +static inline void tst_fzsync_pair_exit(struct tst_fzsync_pair *pair) +{ + tst_atomic_store(1, &pair->exit); +} + /** * tst_fzsync_pair_wait_update_{a,b} - Wait and then recalculate * @@ -301,10 +313,26 @@ static inline int tst_fzsync_wait_b(struct tst_fzsync_pair *pair) static inline int tst_fzsync_wait_update_a(struct tst_fzsync_pair *pair) { static int loop_index; + int timer_state = tst_timer_state_ms(60000); + int exit = 0; + + if (!(timer_state & TST_TIMER_STARTED)) { + tst_timer_start(CLOCK_MONOTONIC_RAW); + } else if (timer_state & TST_TIMER_EXPIRED) { + tst_res(TINFO, + "Exceeded fuzzy sync time limit, requesting exit"); + exit = 1; + } tst_fzsync_pair_wait(pair, &pair->a_cntr, &pair->b_cntr); - loop_index++; - tst_fzsync_pair_update(loop_index, pair); + + if (exit) { + tst_fzsync_pair_exit(pair); + } else { + loop_index++; + tst_fzsync_pair_update(loop_index, pair); + } + return tst_fzsync_pair_wait(pair, &pair->a_cntr, &pair->b_cntr); } @@ -313,14 +341,3 @@ static inline int tst_fzsync_wait_update_b(struct tst_fzsync_pair *pair) tst_fzsync_pair_wait(pair, &pair->b_cntr, &pair->a_cntr); return tst_fzsync_pair_wait(pair, &pair->b_cntr, &pair->a_cntr); } - -/** - * tst_fzsync_pair_exit - Signal that the other thread should exit - * - * Causes tst_fzsync_pair_wait() and tst_fzsync_pair_wait_update() to return - * 0. - */ -static inline void tst_fzsync_pair_exit(struct tst_fzsync_pair *pair) -{ - tst_atomic_store(1, &pair->exit); -} diff --git a/lib/newlib_tests/test16.c b/lib/newlib_tests/test16.c index d80bd5369..bb3d86e2d 100644 --- a/lib/newlib_tests/test16.c +++ b/lib/newlib_tests/test16.c @@ -65,7 +65,8 @@ static void run(void) unsigned int i, j, fail = 0; for (i = 0; i < LOOPS; i++) { - tst_fzsync_wait_update_a(&pair); + if (!tst_fzsync_wait_update_a(&pair)) + break; tst_fzsync_delay_a(&pair); seq[seq_n] = 'A'; seq_n = i * 2 + 1; diff --git a/testcases/cve/cve-2014-0196.c b/testcases/cve/cve-2014-0196.c index d18108897..8d15909b7 100644 --- a/testcases/cve/cve-2014-0196.c +++ b/testcases/cve/cve-2014-0196.c @@ -118,7 +118,8 @@ static void run(void) t.c_lflag |= ECHO; tcsetattr(master_fd, TCSANOW, &t); - tst_fzsync_wait_update_a(&fzsync_pair); + if (!tst_fzsync_wait_update_a(&fzsync_pair)) + break; tst_fzsync_delay_a(&fzsync_pair); tst_fzsync_time_a(&fzsync_pair); diff --git a/testcases/cve/cve-2016-7117.c b/testcases/cve/cve-2016-7117.c index 3cb7efcdf..d68f62ecc 100644 --- a/testcases/cve/cve-2016-7117.c +++ b/testcases/cve/cve-2016-7117.c @@ -140,7 +140,8 @@ static void run(void) if (socketpair(AF_LOCAL, SOCK_DGRAM, 0, (int *)socket_fds)) tst_brk(TBROK | TERRNO, "Socket creation failed"); - tst_fzsync_wait_update_a(&fzsync_pair); + if (!tst_fzsync_wait_update_a(&fzsync_pair)) + break; tst_fzsync_delay_a(&fzsync_pair); stat = tst_syscall(__NR_recvmmsg, diff --git a/testcases/cve/cve-2017-2671.c b/testcases/cve/cve-2017-2671.c index b0471bfff..21dd2a754 100644 --- a/testcases/cve/cve-2017-2671.c +++ b/testcases/cve/cve-2017-2671.c @@ -115,7 +115,8 @@ static void run(void) SAFE_CONNECT(sockfd, (struct sockaddr *)&iaddr, sizeof(iaddr)); - tst_fzsync_wait_update_a(&fzsync_pair); + if (!tst_fzsync_wait_update_a(&fzsync_pair)) + break; tst_fzsync_delay_a(&fzsync_pair); connect(sockfd, (struct sockaddr *)&uaddr, sizeof(uaddr)); tst_fzsync_time_a(&fzsync_pair); diff --git a/testcases/kernel/syscalls/inotify/inotify09.c b/testcases/kernel/syscalls/inotify/inotify09.c index 475411311..52df38f24 100644 --- a/testcases/kernel/syscalls/inotify/inotify09.c +++ b/testcases/kernel/syscalls/inotify/inotify09.c @@ -102,7 +102,8 @@ static void verify_inotify(void) if (wd < 0) tst_brk(TBROK | TERRNO, "inotify_add_watch() failed."); - tst_fzsync_wait_update_a(&fzsync_pair); + if (!tst_fzsync_wait_update_a(&fzsync_pair)) + break; tst_fzsync_delay_a(&fzsync_pair); wd = myinotify_rm_watch(inotify_fd, wd);