From patchwork Thu Jul 18 08:39:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1133627 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=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.cz Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45q6yT0vWDz9s8m for ; Thu, 18 Jul 2019 18:40:01 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2EAE23C1D02 for ; Thu, 18 Jul 2019 10:39:58 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 0E9183C1C93 for ; Thu, 18 Jul 2019 10:39:55 +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-3.smtp.seeweb.it (Postfix) with ESMTPS id 42BD81A01447 for ; Thu, 18 Jul 2019 10:39:54 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 665F2AE12; Thu, 18 Jul 2019 08:39:54 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 18 Jul 2019 10:39:42 +0200 Message-Id: <20190718083943.7687-1-pvorel@suse.cz> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH 1/2] shell: Use $LTP_TIMEOUT_MUL also in retry functions X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" in TST_RETRY_FN_EXP_BACKOFF() and thus in TST_RETRY_FUNC() in new shell API. This function should also address possibility of slow machine. Because using on 2 places moved the default definition to the beginning of the script. + use $((...)) instead of expr. + move expression using $3 after check whether we have enough parameters + document LTP_TIMEOUT_MUL environment variable in wiki. Signed-off-by: Petr Vorel --- Hi, I can squash these 2 commits. General question about Test Writing Guidelines in wiki [1]: 1) we have separate section for C and shell API, which is probably a good choice, but we're trying to sync them. That leads to things like retry function documented under chapter for shell API (2.3). + That page is too long and without table of contents (not easy to navigate in it; I tried to add TOC, but without success). Maybe adding TOC or split the page to 3: 1) general info 2) C API 3) shell API would help. WDYT? Kind regards, Petr [1] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines [2] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#retry-a-function-in-limited-time doc/test-writing-guidelines.txt | 2 ++ testcases/lib/tst_test.sh | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index 869e6ed35..782e14f32 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -1881,6 +1881,8 @@ simply by setting right '$TST_NEEDS_FOO'. the test (see below). | 'TST_NEEDS_MODULE' | Test module name needed for the test (see below). | 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test. +| 'LTP_TIMEOUT_MUL' | Multiply timeout (> 1 is useful for slow machines to + avoid unexpected timeout). |============================================================================= Checking for presence of commands diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh index 31b3a3951..60d765424 100644 --- a/testcases/lib/tst_test.sh +++ b/testcases/lib/tst_test.sh @@ -17,6 +17,8 @@ export TST_ITERATIONS=1 export TST_TMPDIR_RHOST=0 export TST_LIB_LOADED=1 +export LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1} + . tst_ansi_color.sh . tst_security.sh @@ -164,12 +166,13 @@ TST_RETRY_FN_EXP_BACKOFF() { local tst_fun="$1" local tst_exp=$2 - local tst_sec=$(expr $3 \* 1000000) local tst_delay=1 + local tst_sec if [ $# -ne 3 ]; then tst_brk TBROK "TST_RETRY_FN_EXP_BACKOFF expects 3 parameters" fi + tst_sec=$(($3 * LTP_TIMEOUT_MUL * 1000000)) if ! tst_is_int "$tst_sec"; then tst_brk TBROK "TST_RETRY_FN_EXP_BACKOFF: tst_sec must be integer ('$tst_sec')" @@ -185,7 +188,7 @@ TST_RETRY_FN_EXP_BACKOFF() tst_sleep ${tst_delay}us tst_delay=$((tst_delay*2)) else - tst_brk TBROK "\"$tst_fun\" timed out" + tst_brk TBROK "\"$tst_fun\" timed out! If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1" fi done @@ -374,8 +377,6 @@ _tst_rescmp() _tst_setup_timer() { - LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1} - local sec=$((300 * LTP_TIMEOUT_MUL)) local h=$((sec / 3600)) local m=$((sec / 60 % 60)) From patchwork Thu Jul 18 08:39:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1133628 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.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45q6yc3px9z9s8m for ; Thu, 18 Jul 2019 18:40:08 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id AAAFA3C1D46 for ; Thu, 18 Jul 2019 10:40:05 +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 73FBC3C1CE5 for ; Thu, 18 Jul 2019 10:39:58 +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-2.smtp.seeweb.it (Postfix) with ESMTPS id E6BAE6011D2 for ; Thu, 18 Jul 2019 10:39:57 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 03AE6ACB8; Thu, 18 Jul 2019 08:39:57 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 18 Jul 2019 10:39:43 +0200 Message-Id: <20190718083943.7687-2-pvorel@suse.cz> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718083943.7687-1-pvorel@suse.cz> References: <20190718083943.7687-1-pvorel@suse.cz> MIME-Version: 1.0 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_NONE,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 2/2] c: Use $LTP_TIMEOUT_MUL also in retry functions X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" in TST_RETRY_FN_EXP_BACKOFF() and thus in TST_RETRY_FUNC() in new C API. This sync C API with shell API (added in previous commit). + mention LTP_TIMEOUT_MUL use in wiki. + use SPDX, add copyright Signed-off-by: Petr Vorel --- doc/test-writing-guidelines.txt | 2 ++ include/tst_common.h | 26 +++++++++++--------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index 782e14f32..3548d6043 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -2064,6 +2064,8 @@ Sometimes LTP test needs retrying a function for many times to get success. This achievement makes that possible via keeping it retrying if the return value of the function is NOT as we expected. After exceeding a limited time, test will break from the retries immediately. +NOTE: both 'TST_RETRY_FUNC()' and 'TST_RETRY_FN_EXP_BACKOFF()' use 'LTP_TIMEOUT_MUL' +environment variable. [source,c] ------------------------------------------------------------------------------- diff --git a/include/tst_common.h b/include/tst_common.h index c21505450..454a166e8 100644 --- a/include/tst_common.h +++ b/include/tst_common.h @@ -1,21 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* + * Copyright (c) Linux Test Project, 2017-2019 * Copyright (c) 2016 Cyril Hrubis * Copyright (c) 2013 Stanislav Kholmanskikh * Copyright (c) 2010 Ngie Cooper * Copyright (c) 2008 Mike Frysinger - * - * 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 . */ #ifndef TST_COMMON_H__ @@ -51,15 +40,22 @@ #define TST_RETRY_FN_EXP_BACKOFF(FUNC, ERET, MAX_DELAY) \ ({ int tst_delay_ = 1; \ + float m = 1; \ + char *mul = getenv("LTP_TIMEOUT_MUL"); \ + if (mul) { \ + m = atof(mul); \ + if (m < 1) \ + tst_brk(TBROK, "Invalid timeout multiplier '%s'", mul); \ + } \ for (;;) { \ typeof(FUNC) tst_ret_ = FUNC; \ if (tst_ret_ == ERET) \ break; \ - if (tst_delay_ < MAX_DELAY * 1000000) { \ + if (tst_delay_ < MAX_DELAY * m * 1000000) { \ usleep(tst_delay_); \ tst_delay_ *= 2; \ } else { \ - tst_brk(TBROK, #FUNC" timed out"); \ + tst_brk(TBROK, #FUNC" timed out! If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1"); \ } \ } \ ERET; \