Linux Test Project
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [RFC PATCH v2 1/2] tst_test.sh: Add TST_TEST_DATA and TST_TEST_DATA_IFS
Date: Tue, 22 May 2018 12:42:20 +0200	[thread overview]
Message-ID: <20180522104220.GA27975@rei> (raw)
In-Reply-To: <20180516161820.3077-2-pvorel@suse.cz>

Hi!
>  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,18 +352,30 @@ tst_run()
>  			if type test1 > /dev/null 2>&1; then
>  				for tst_i in $(seq $TST_CNT); do
>  					local res=$(tst_resstr)
> -					$TST_TESTFUNC$tst_i
> +					$TST_TESTFUNC$tst_i $tst_i $TST_TEST_DATA
>  					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_TESTFUNC $tst_i $TST_TEST_DATA
>  					tst_rescmp "$res"
>  					TST_COUNT=$((TST_COUNT+1))
>  				done
>  			fi

So in this implementation we cannot use IFS to separate the arguments,
without that it's kind of useless as we can pass anything in global
variable anyway...

> +		elif [ -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
> +				local res=$(tst_resstr)
> +				$TST_TESTFUNC $tst_i "$tst_data"
> +				tst_rescmp "$res"
> +				TST_COUNT=$((TST_COUNT+1))
> +				tst_i=$((tst_i+1))
> +			done
>  		else
>  			local res=$(tst_resstr)
>  			$TST_TESTFUNC
> @@ -400,6 +412,8 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
>  		tst_brk TBROK "TST_TESTFUNC is not defined"
>  	fi

Uff, the maze of if conditions is getting out of hand a bit.

Why dont we move innter part of the while [ $TST_ITERATION -gt 0 ] loop
to a separate tst_run_tests() function and add the ability to pass data
in $1 there. Then we can do something as:

	while [ $TST_INTERATION -gt 0 ]; then
	      if [ -n $TST_TEST_DATA ]; then
	          for tst_data in ...; do
		      tst_run_tests "$tst_data"
		  done
	      else
	           tst_run_tests
	      fi
	done


> +	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"
> -- 
> 2.16.3
> 

-- 
Cyril Hrubis
chrubis@suse.cz

  parent reply	other threads:[~2018-05-22 10:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-16 16:18 [LTP] [RFC PATCH v2 0/2] Shell: Add TST_TEST_DATA and TST_TEST_DATA_IFS Petr Vorel
2018-05-16 16:18 ` [LTP] [RFC PATCH v2 1/2] tst_test.sh: " Petr Vorel
2018-05-16 16:22   ` Petr Vorel
2018-05-22 10:42   ` Cyril Hrubis [this message]
2018-05-22 19:37     ` Petr Vorel
2018-05-16 16:18 ` [LTP] [RFC PATCH v2 2/2] net/{stress, virt}: Use " Petr Vorel
2018-05-16 16:20   ` Petr Vorel
2018-05-17 14:10   ` Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180522104220.GA27975@rei \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox