From patchwork Thu May 24 15:21:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 919938 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.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40sClp50jzz9ry1 for ; Fri, 25 May 2018 01:21:42 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B2B1B3E6FD4 for ; Thu, 24 May 2018 17:21:39 +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 [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id 155053E6FBC for ; Thu, 24 May 2018 17:21:37 +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-2.smtp.seeweb.it (Postfix) with ESMTPS id 76D65604C6D for ; Thu, 24 May 2018 17:21:36 +0200 (CEST) Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C963AAAC3 for ; Thu, 24 May 2018 15:21:35 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 24 May 2018 17:21:26 +0200 Message-Id: <20180524152129.1067-1-pvorel@suse.cz> X-Mailer: git-send-email 2.16.3 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_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] [RFC PATCH v4 1/4] lib/tst_test.sh: Fix test name function detection for TST_CNT 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" Reported-by: Cyril Hrubis Signed-off-by: Petr Vorel --- testcases/lib/tst_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh index 464c4c41e..779383392 100644 --- a/testcases/lib/tst_test.sh +++ b/testcases/lib/tst_test.sh @@ -349,7 +349,7 @@ tst_run() #TODO check that test reports some results for each test function call while [ $TST_ITERATIONS -gt 0 ]; do if [ -n "$TST_CNT" ]; then - if type test1 > /dev/null 2>&1; 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 From patchwork Thu May 24 15:21:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 919939 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.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40sClt0pMGz9ry1 for ; Fri, 25 May 2018 01:21:46 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 605663E6FC7 for ; Thu, 24 May 2018 17:21:43 +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 [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 258B53E6FBE for ; Thu, 24 May 2018 17:21:38 +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-4.smtp.seeweb.it (Postfix) with ESMTPS id 8BFC51182543 for ; Thu, 24 May 2018 17:21:37 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 30124AD5E for ; Thu, 24 May 2018 15:21:37 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 24 May 2018 17:21:27 +0200 Message-Id: <20180524152129.1067-2-pvorel@suse.cz> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180524152129.1067-1-pvorel@suse.cz> References: <20180524152129.1067-1-pvorel@suse.cz> 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 Subject: [LTP] [RFC PATCH v4 2/4] lib/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 | 56 +++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh index 779383392..a5f0ab288 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,31 @@ tst_rescmp() tst_run() { - local tst_i + local _tst_i 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 + local _tst_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 +350,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 res=$(_tst_resstr) + $TST_TESTFUNC$_tst_i + _tst_rescmp "$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 res=$(_tst_resstr) + $TST_TESTFUNC $_tst_i + _tst_rescmp "$res" TST_COUNT=$((TST_COUNT+1)) done fi else - local res=$(tst_resstr) + local res=$(_tst_resstr) $TST_TESTFUNC - tst_rescmp "$res" + _tst_rescmp "$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" From patchwork Thu May 24 15:21:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 919940 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.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40sClw6Kczz9ry1 for ; Fri, 25 May 2018 01:21:48 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 28CAB3E7042 for ; Thu, 24 May 2018 17:21:46 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id ED6993E6FBC for ; Thu, 24 May 2018 17:21:38 +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-6.smtp.seeweb.it (Postfix) with ESMTPS id 843DA1415358 for ; Thu, 24 May 2018 17:21:38 +0200 (CEST) Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 18FFCAAC3 for ; Thu, 24 May 2018 15:21:38 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 24 May 2018 17:21:28 +0200 Message-Id: <20180524152129.1067-3-pvorel@suse.cz> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180524152129.1067-1-pvorel@suse.cz> References: <20180524152129.1067-1-pvorel@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-6.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-6.smtp.seeweb.it Subject: [LTP] [RFC PATCH v4 3/4] lib/tst_test.sh: Warn about using "private" variable or 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" Signed-off-by: Petr Vorel --- testcases/lib/tst_test.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh index a5f0ab288..cdcd33ced 100644 --- a/testcases/lib/tst_test.sh +++ b/testcases/lib/tst_test.sh @@ -259,6 +259,10 @@ tst_run() *) tst_res TWARN "Reserved variable TST_$_tst_i used!";; esac done + + for _tst_i in $(grep _tst_ "$TST_TEST_PATH" | sed 's/.*_tst_//; s/[="} \t\/:`].*//'); do + tst_res TWARN "Private variable or function _tst_$_tst_i used!" + done fi local _tst_name From patchwork Thu May 24 15:21:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 919941 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.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40sClz5VHHz9ry1 for ; Fri, 25 May 2018 01:21:51 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0E8F93E7059 for ; Thu, 24 May 2018 17:21:49 +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 9FD123E6FD7 for ; Thu, 24 May 2018 17:21:40 +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-2.smtp.seeweb.it (Postfix) with ESMTPS id A4E91604836 for ; Thu, 24 May 2018 17:21:39 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1A462AAC3 for ; Thu, 24 May 2018 15:21:39 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 24 May 2018 17:21:29 +0200 Message-Id: <20180524152129.1067-4-pvorel@suse.cz> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180524152129.1067-1-pvorel@suse.cz> References: <20180524152129.1067-1-pvorel@suse.cz> 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_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] [RFC PATCH v4 4/4] tst_test.sh: Add TST_TEST_DATA and TST_TEST_DATA_IFS 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" This is specific only for shell. Each run of tst_run gets passed sequence number of a test being run as '$1' and corresponding part of data from TST_TEST_DATA as '$2'. Also create internal functions _tst_run_tests() and _tst_run_test() to reduce duplicity. Signed-off-by: Petr Vorel --- doc/test-writing-guidelines.txt | 75 +++++++++++++++++++++++++++++++++++++---- testcases/lib/tst_test.sh | 61 +++++++++++++++++++++------------ 2 files changed, 107 insertions(+), 29 deletions(-) diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index fb7dcb591..1f6b05279 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -1442,12 +1442,12 @@ TST_CNT=2 test1() { - tst_res TPASS "Test 1 passed" + tst_res TPASS "Test $1 passed" } test2() { - tst_res TPASS "Test 2 passed" + tst_res TPASS "Test $1 passed" } tst_run @@ -1455,7 +1455,8 @@ tst_run If '$TST_CNT' is set, the test library looks if there are functions named '$\{TST_TESTFUNC\}1', ..., '$\{TST_TESTFUNC\}$\{TST_CNT\}' and if these are -found they are executed one by one. +found they are executed one by one. The test number is passed to it in the '$1'. + [source,sh] ------------------------------------------------------------------------------- @@ -1471,8 +1472,8 @@ TST_CNT=2 do_test() { case $1 in - 1) tst_res TPASS "Test 1 passed";; - 2) tst_res TPASS "Test 2 passed";; + 1) tst_res TPASS "Test $1 passed";; + 2) tst_res TPASS "Test $1 passed";; esac } @@ -1483,6 +1484,66 @@ Otherwise, if '$TST_CNT' is set but there is no '$\{TST_TESTFUNC\}1', etc., the '$TST_TESTFUNC' is executed '$TST_CNT' times and the test number is passed to it in the '$1'. +[source,sh] +------------------------------------------------------------------------------- +#!/bin/sh +# +# Example test with tests in a single function, using $TST_TEST_DATA and +# $TST_TEST_DATA_IFS +# + +TST_TESTFUNC=do_test +TST_TEST_DATA="foo:bar:d dd" +TST_TEST_DATA_IFS=":" +. tst_test.sh + +do_test() +{ + tst_res TPASS "Test $1 passed with data '$2'" +} + +tst_run +# output: +# test 1 TPASS: Test 1 passed with data 'foo' +# test 2 TPASS: Test 2 passed with data 'bar' +# test 3 TPASS: Test 3 passed with data 'd dd' + +------------------------------------------------------------------------------- + +It's possible to pass data for function with '$TST_TEST_DATA'. Optional +'$TST_TEST_DATA_IFS' is used for splitting, default value is space. + +[source,sh] +------------------------------------------------------------------------------- +#!/bin/sh +# +# Example test with tests in a single function, using $TST_TEST_DATA and $TST_CNT +# + +TST_TESTFUNC=do_test +TST_CNT=2 +TST_TEST_DATA="foo bar" +. tst_test.sh + +do_test() +{ + case $1 in + 1) tst_res TPASS "Test $1 passed with data '$2'";; + 2) tst_res TPASS "Test $1 passed with data '$2'";; + esac +} + +tst_run +# output: +# test 1 TPASS: Test 1 passed with data 'foo' +# test 2 TPASS: Test 2 passed with data 'bar' + +------------------------------------------------------------------------------- +When '$TST_TEST_DATA' is used with '$TST_CNT', it's passed as whole string in +'$2' ($1 is for the test number), '$TST_TEST_DATA_IFS' for splitting is not +specified, therefore using space as the default value. Similar it would be +using these variables with separate functions. + 2.3.2 Library variables ^^^^^^^^^^^^^^^^^^^^^^^ @@ -1587,8 +1648,8 @@ these can be listed with passing help '-h' option to any test. The function that prints the usage is passed in '$TST_USAGE', the help for the options implemented in the library is appended when usage is printed. -Lastly the fucntion '$PARSE_ARGS' is called with the option name in '$1' and, -if option has argument, its value in '$2'. +Lastly the fucntion '$PARSE_ARGS' is called with the option name in the '$1' +and, if option has argument, its value in the '$2'. [source,sh] ------------------------------------------------------------------------------- diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh index cdcd33ced..34b2188ac 100644 --- a/testcases/lib/tst_test.sh +++ b/testcases/lib/tst_test.sh @@ -246,7 +246,7 @@ _tst_rescmp() tst_run() { - local _tst_i + local _tst_i _tst_data if [ -n "$TST_TEST_PATH" ]; then for _tst_i in $(grep TST_ "$TST_TEST_PATH" | sed 's/.*TST_//; s/[="} \t\/:`].*//'); do @@ -255,7 +255,7 @@ tst_run() OPTS|USAGE|PARSE_ARGS|POS_ARGS);; NEEDS_ROOT|NEEDS_TMPDIR|NEEDS_DEVICE|DEVICE);; NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);; - IPV6);; + IPV6|TEST_DATA|TEST_DATA_IFS);; *) tst_res TWARN "Reserved variable TST_$_tst_i used!";; esac done @@ -352,27 +352,17 @@ tst_run() #TODO check that test reports some results for each test function call 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" - 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" - TST_COUNT=$((TST_COUNT+1)) - done - fi + if [ -n "$TST_TEST_DATA" ]; then + _tst_i=1 + tst_check_cmds cut + while true; do + tst_data="$(echo "$TST_TEST_DATA" | cut -d"$TST_TEST_DATA_IFS" -f$_tst_i)" + [ -z "$tst_data" ] && break + _tst_run_tests "$tst_data" + _tst_i=$((_tst_i+1)) + done else - local res=$(_tst_resstr) - $TST_TESTFUNC - _tst_rescmp "$res" - TST_COUNT=$((TST_COUNT+1)) + _tst_run_tests fi TST_ITERATIONS=$((TST_ITERATIONS-1)) done @@ -380,6 +370,31 @@ tst_run() _tst_do_exit } +_tst_run_tests() +{ + local data="$1" + local i + + for i in $(seq ${TST_CNT:-1}); do + if type ${TST_TESTFUNC}1 > /dev/null 2>&1; then + _tst_run_test "$TST_TESTFUNC$i" $i "$data" + else + _tst_run_test "$TST_TESTFUNC" $i "$data" + fi + done +} + +_tst_run_test() +{ + local res=$(_tst_resstr) + local fnc="$1" + shift + + $fnc "$@" + _tst_rescmp "$res" + TST_COUNT=$((TST_COUNT+1)) +} + if [ -z "$TST_ID" ]; then _tst_filename=$(basename $0) TST_ID=${_tst_filename%%.*} @@ -404,6 +419,8 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then tst_brk TBROK "TST_TESTFUNC is not defined" fi + TST_TEST_DATA_IFS="${TST_TEST_DATA_IFS:- }" + if [ -n "$TST_CNT" ]; then if ! tst_is_int "$TST_CNT"; then tst_brk TBROK "TST_CNT must be integer"