[LTP] [RFC PATCH v2 1/2] tst_test.sh: Add TST_TEST_DATA and TST_TEST_DATA_IFS

Petr Vorel pvorel@suse.cz
Tue May 22 21:37:58 CEST 2018


Hi Cyril,

> > @@ -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
Changed in v3 in the way you suggested.
I thought there is a reason not to introduce any function as it'd be exported.
In v3 I added not only tst_run_tests(), but also tst_run_test() helper.

Thanks for your review.


Kind regards,
Petr


More information about the ltp mailing list