From patchwork Fri Jun 1 07:28:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 923794 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.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40xwth4mnBz9s0W for ; Fri, 1 Jun 2018 17:29:00 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 399B13E7812 for ; Fri, 1 Jun 2018 09:28:58 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 4073E3E7797 for ; Fri, 1 Jun 2018 09:28: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-5.smtp.seeweb.it (Postfix) with ESMTPS id 1E8BF600B92 for ; Fri, 1 Jun 2018 09:28:49 +0200 (CEST) Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 7DB8EAD4A; Fri, 1 Jun 2018 07:28:48 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Fri, 1 Jun 2018 09:28:34 +0200 Message-Id: <20180601072838.13196-2-pvorel@suse.cz> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180601072838.13196-1-pvorel@suse.cz> References: <20180601072838.13196-1-pvorel@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-5.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-5.smtp.seeweb.it Subject: [LTP] [RFC PATCH v6 1/5] tst_test.sh: Hide "private" variables with "_tst_" prefix 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" Variables in tst_run and out of functions are visible to the test. Adding prefix "_tst_" manifest they're private. NOTE: kept $res from tst_run() as it's going to be moved into separate function in new commit. Signed-off-by: Petr Vorel --- testcases/lib/tst_test.sh | 57 +++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh index 779383392..337d33ca4 100644 --- a/testcases/lib/tst_test.sh +++ b/testcases/lib/tst_test.sh @@ -32,7 +32,7 @@ export TST_TMPDIR_RHOST=0 . tst_ansi_color.sh -tst_do_exit() +_tst_do_exit() { local ret=0 @@ -79,7 +79,7 @@ tst_do_exit() exit $ret } -tst_inc_res() +_tst_inc_res() { case "$1" in TPASS) TST_PASS=$((TST_PASS+1));; @@ -100,7 +100,7 @@ tst_res() tst_color_enabled local color=$? - tst_inc_res "$res" + _tst_inc_res "$res" printf "$TST_ID $TST_COUNT " tst_print_colored $res "$res: " @@ -113,7 +113,7 @@ tst_brk() shift tst_res "$res" "$@" - tst_do_exit + _tst_do_exit } ROD_SILENT() @@ -230,14 +230,14 @@ tst_usage() echo "-i n Execute test n times" } -tst_resstr() +_tst_resstr() { echo "$TST_PASS$TST_FAIL$TST_CONF" } -tst_rescmp() +_tst_rescmp() { - local res=$(tst_resstr) + local res=$(_tst_resstr) if [ "$1" = "$res" ]; then tst_brk TBROK "Test didn't report any results" @@ -246,31 +246,30 @@ tst_rescmp() tst_run() { - local tst_i + local _tst_i + local _tst_name if [ -n "$TST_TEST_PATH" ]; then - for tst_i in $(grep TST_ "$TST_TEST_PATH" | sed 's/.*TST_//; s/[="} \t\/:`].*//'); do - case "$tst_i" in + for _tst_i in $(grep TST_ "$TST_TEST_PATH" | sed 's/.*TST_//; s/[="} \t\/:`].*//'); do + case "$_tst_i" in SETUP|CLEANUP|TESTFUNC|ID|CNT|MIN_KVER);; OPTS|USAGE|PARSE_ARGS|POS_ARGS);; NEEDS_ROOT|NEEDS_TMPDIR|NEEDS_DEVICE|DEVICE);; NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);; IPV6);; - *) tst_res TWARN "Reserved variable TST_$tst_i used!";; + *) tst_res TWARN "Reserved variable TST_$_tst_i used!";; esac done fi - local name - OPTIND=1 - while getopts "hi:$TST_OPTS" name $TST_ARGS; do - case $name in + while getopts "hi:$TST_OPTS" _tst_name $TST_ARGS; do + case $_tst_name in 'h') tst_usage; exit 0;; 'i') TST_ITERATIONS=$OPTARG;; '?') tst_usage; exit 2;; - *) $TST_PARSE_ARGS "$name" "$OPTARG";; + *) $TST_PARSE_ARGS "$_tst_name" "$OPTARG";; esac done @@ -350,35 +349,35 @@ tst_run() while [ $TST_ITERATIONS -gt 0 ]; do if [ -n "$TST_CNT" ]; then if type ${TST_TESTFUNC}1 > /dev/null 2>&1; then - for tst_i in $(seq $TST_CNT); do - local res=$(tst_resstr) - $TST_TESTFUNC$tst_i - tst_rescmp "$res" + for _tst_i in $(seq $TST_CNT); do + local _tst_res=$(_tst_resstr) + $TST_TESTFUNC$_tst_i + _tst_rescmp "$_tst_res" TST_COUNT=$((TST_COUNT+1)) done else - for tst_i in $(seq $TST_CNT); do - local res=$(tst_resstr) - $TST_TESTFUNC $tst_i - tst_rescmp "$res" + for _tst_i in $(seq $TST_CNT); do + local _tst_res=$(_tst_resstr) + $TST_TESTFUNC $_tst_i + _tst_rescmp "$_tst_res" TST_COUNT=$((TST_COUNT+1)) done fi else - local res=$(tst_resstr) + local _tst_res=$(_tst_resstr) $TST_TESTFUNC - tst_rescmp "$res" + _tst_rescmp "$_tst_res" TST_COUNT=$((TST_COUNT+1)) fi TST_ITERATIONS=$((TST_ITERATIONS-1)) done - tst_do_exit + _tst_do_exit } if [ -z "$TST_ID" ]; then - filename=$(basename $0) - TST_ID=${filename%%.*} + _tst_filename=$(basename $0) + TST_ID=${_tst_filename%%.*} fi export TST_ID="$TST_ID"