From patchwork Wed May 16 12:39:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 914594 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 40mDXh6lfMz9s33 for ; Wed, 16 May 2018 22:39:48 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7216C1A958F for ; Wed, 16 May 2018 14:39:46 +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 9D5133E7125 for ; Wed, 16 May 2018 14:39:42 +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 D0AAD60208B for ; Wed, 16 May 2018 14:39:40 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 72F37ABF3; Wed, 16 May 2018 12:39:40 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Wed, 16 May 2018 14:39:23 +0200 Message-Id: <20180516123924.11047-2-pvorel@suse.cz> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180516123924.11047-1-pvorel@suse.cz> References: <20180516123924.11047-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 1/2] lib/tst_test.sh: TST_TESTFUNC_DATA and TST_TESTFUNC_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. Signed-off-by: Petr Vorel --- If we accept it, it's a question if pass iteration number as well (and if yes, maybe it should be in $1 and data in $2). Kind regards, Petr --- doc/test-writing-guidelines.txt | 23 +++++++++++++++++++++++ testcases/lib/tst_test.sh | 20 ++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index 8e405a034..2184f6365 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -1485,6 +1485,29 @@ 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 using TST_TESTFUNC_DATA +# + +TST_TESTFUNC=do_test +TST_TESTFUNC_DATA="foo bar" +. tst_test.sh + +do_test() +{ + 1) tst_res TPASS "Test passed with data '$1'";; +} + +tst_run +------------------------------------------------------------------------------- + +It's possible to pass data for function with '$TST_TESTFUNC_DATA'. Optional +'$TST_TESTFUNC_DATA_IFS' variable is supported to set '$IFS' for splitting. +'$TST_TESTFUNC_DATA' cannot be mixed with '$TST_CNT'. + 2.3.2 Library variables ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh index 8d49d34b6..31bf51e10 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 ifs 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|TESTFUNC_DATA|TESTFUNC_DATA_IFS);; *) tst_res TWARN "Reserved variable TST_$tst_i used!";; esac done @@ -364,6 +364,18 @@ tst_run() TST_COUNT=$((TST_COUNT+1)) done fi + elif [ -n "$TST_TESTFUNC_DATA" ]; then + if [ -n "$TST_TESTFUNC_DATA_IFS" ]; then + ifs="$IFS" + IFS="$TST_TESTFUNC_DATA_IFS" + fi + for tst_i in $TST_TESTFUNC_DATA; do + [ -n "$ifs" ] && IFS="$ifs" + local res=$(tst_resstr) + $TST_TESTFUNC $tst_i + tst_rescmp "$res" + TST_COUNT=$((TST_COUNT+1)) + done else local res=$(tst_resstr) $TST_TESTFUNC @@ -400,6 +412,10 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then tst_brk TBROK "TST_TESTFUNC is not defined" fi + if [ -n "$TST_CNT" -a -n "$TST_TESTFUNC_DATA" ]; then + tst_brk TBROK "TST_CNT cannot be mixed with TST_TESTFUNC_DATA" + fi + if [ -n "$TST_CNT" ]; then if ! tst_is_int "$TST_CNT"; then tst_brk TBROK "TST_CNT must be integer"