[RFC,v3,2/5] tst_test.sh: Introduce TST_NO_DEFAULT_RUN
diff mbox series

Message ID 20180403154717.22491-3-pvorel@suse.cz
State Superseded
Delegated to: Cyril Hrubis
Headers show
Series
  • Rewriting network tests into new shell API
Related show

Commit Message

Petr Vorel April 3, 2018, 3:47 p.m. UTC
TST_NO_DEFAULT_RUN is somehow similar to TST_NO_DEFAULT_MAIN. It's meant
to be used for libraries and tools using tst_test.sh. It helps to use
part of test framework functionality without wanting to run test.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/tst_test.sh | 100 +++++++++++++++++++++++-----------------------
 1 file changed, 51 insertions(+), 49 deletions(-)

Comments

Cyril Hrubis April 4, 2018, 1:08 p.m. UTC | #1
Hi!
> TST_NO_DEFAULT_RUN is somehow similar to TST_NO_DEFAULT_MAIN. It's meant
> to be used for libraries and tools using tst_test.sh. It helps to use
> part of test framework functionality without wanting to run test.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/tst_test.sh | 100 +++++++++++++++++++++++-----------------------
>  1 file changed, 51 insertions(+), 49 deletions(-)
> 
> diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
> index 78bd328a2..7cdaa1f7f 100644
> --- a/testcases/lib/tst_test.sh
> +++ b/testcases/lib/tst_test.sh
> @@ -1,6 +1,6 @@
>  #!/bin/sh
>  #
> -# Copyright (c) Linux Test Project, 2014-2017
> +# Copyright (c) Linux Test Project, 2014-2018
>  #
>  # This program is free software; you can redistribute it and/or modify
>  # it under the terms of the GNU General Public License as published by
> @@ -371,67 +371,69 @@ tst_run()
>  	tst_do_exit
>  }
>  
> -if TST_TEST_PATH=$(which $0) 2>/dev/null; then
> -	if ! grep -q tst_run "$TST_TEST_PATH"; then
> -		tst_brk TBROK "Test $0 must call tst_run!"
> +if [ -z "$TST_NO_DEFAULT_RUN" ]; then
> +	if TST_TEST_PATH=$(which $0) 2>/dev/null; then
> +		if ! grep -q tst_run "$TST_TEST_PATH"; then
> +			tst_brk TBROK "Test $0 must call tst_run!"
> +		fi
>  	fi
> -fi
> -
> -if [ -z "$TST_ID" ]; then
> -	filename=$(basename $0)
> -	TST_ID=${filename%%.*}
> -fi
> -export TST_ID="$TST_ID"
> -
> -if [ -z "$TST_TESTFUNC" ]; then
> -	tst_brk TBROK "TST_TESTFUNC is not defined"
> -fi
>  
> -if [ -n "$TST_CNT" ]; then
> -	if ! tst_is_int "$TST_CNT"; then
> -		tst_brk TBROK "TST_CNT must be integer"
> +	if [ -z "$TST_ID" ]; then
> +		filename=$(basename $0)
> +		TST_ID=${filename%%.*}
>  	fi
> +	export TST_ID="$TST_ID"
>  
> -	if [ "$TST_CNT" -le 0 ]; then
> -		tst_brk TBROK "TST_CNT must be > 0"
> +	if [ -z "$TST_TESTFUNC" ]; then
> +		tst_brk TBROK "TST_TESTFUNC is not defined"
>  	fi
> -fi
>  
> -if [ -n "$TST_POS_ARGS" ]; then
> -	if ! tst_is_int "$TST_POS_ARGS"; then
> -		tst_brk TBROK "TST_POS_ARGS must be integer"
> +	if [ -n "$TST_CNT" ]; then
> +		if ! tst_is_int "$TST_CNT"; then
> +			tst_brk TBROK "TST_CNT must be integer"
> +		fi
> +
> +		if [ "$TST_CNT" -le 0 ]; then
> +			tst_brk TBROK "TST_CNT must be > 0"
> +		fi
>  	fi
>  
> -	if [ "$TST_POS_ARGS" -le 0 ]; then
> -		tst_brk TBROK "TST_POS_ARGS must be > 0"
> +	if [ -n "$TST_POS_ARGS" ]; then
> +		if ! tst_is_int "$TST_POS_ARGS"; then
> +			tst_brk TBROK "TST_POS_ARGS must be integer"
> +		fi
> +
> +		if [ "$TST_POS_ARGS" -le 0 ]; then
> +			tst_brk TBROK "TST_POS_ARGS must be > 0"
> +		fi
>  	fi
> -fi
>  
> -if [ -z "$LTPROOT" ]; then
> -	export LTPROOT="$PWD"
> -	export TST_DATAROOT="$LTPROOT/datafiles"
> -else
> -	export TST_DATAROOT="$LTPROOT/testcases/data/$TST_ID"
> -fi
> +	if [ -z "$LTPROOT" ]; then
> +		export LTPROOT="$PWD"
> +		export TST_DATAROOT="$LTPROOT/datafiles"
> +	else
> +		export TST_DATAROOT="$LTPROOT/testcases/data/$TST_ID"
> +	fi

I guess that we may want to initialize the TST_ID, LTPROOT and
TST_DATAROOT regardless, otherwise this looks pretty much
straighforward and okay.
Petr Vorel April 4, 2018, 1:15 p.m. UTC | #2
Hi,

> > -if [ -z "$LTPROOT" ]; then
> > -	export LTPROOT="$PWD"
> > -	export TST_DATAROOT="$LTPROOT/datafiles"
> > -else
> > -	export TST_DATAROOT="$LTPROOT/testcases/data/$TST_ID"
> > -fi
> > +	if [ -z "$LTPROOT" ]; then
> > +		export LTPROOT="$PWD"
> > +		export TST_DATAROOT="$LTPROOT/datafiles"
> > +	else
> > +		export TST_DATAROOT="$LTPROOT/testcases/data/$TST_ID"
> > +	fi

> I guess that we may want to initialize the TST_ID, LTPROOT and
> TST_DATAROOT regardless, otherwise this looks pretty much
> straighforward and okay.
Thanks for feedback, Cyril!
I'll change it in v4.


Kind regards,
Petr

Patch
diff mbox series

diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 78bd328a2..7cdaa1f7f 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -1,6 +1,6 @@ 
 #!/bin/sh
 #
-# Copyright (c) Linux Test Project, 2014-2017
+# Copyright (c) Linux Test Project, 2014-2018
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -371,67 +371,69 @@  tst_run()
 	tst_do_exit
 }
 
-if TST_TEST_PATH=$(which $0) 2>/dev/null; then
-	if ! grep -q tst_run "$TST_TEST_PATH"; then
-		tst_brk TBROK "Test $0 must call tst_run!"
+if [ -z "$TST_NO_DEFAULT_RUN" ]; then
+	if TST_TEST_PATH=$(which $0) 2>/dev/null; then
+		if ! grep -q tst_run "$TST_TEST_PATH"; then
+			tst_brk TBROK "Test $0 must call tst_run!"
+		fi
 	fi
-fi
-
-if [ -z "$TST_ID" ]; then
-	filename=$(basename $0)
-	TST_ID=${filename%%.*}
-fi
-export TST_ID="$TST_ID"
-
-if [ -z "$TST_TESTFUNC" ]; then
-	tst_brk TBROK "TST_TESTFUNC is not defined"
-fi
 
-if [ -n "$TST_CNT" ]; then
-	if ! tst_is_int "$TST_CNT"; then
-		tst_brk TBROK "TST_CNT must be integer"
+	if [ -z "$TST_ID" ]; then
+		filename=$(basename $0)
+		TST_ID=${filename%%.*}
 	fi
+	export TST_ID="$TST_ID"
 
-	if [ "$TST_CNT" -le 0 ]; then
-		tst_brk TBROK "TST_CNT must be > 0"
+	if [ -z "$TST_TESTFUNC" ]; then
+		tst_brk TBROK "TST_TESTFUNC is not defined"
 	fi
-fi
 
-if [ -n "$TST_POS_ARGS" ]; then
-	if ! tst_is_int "$TST_POS_ARGS"; then
-		tst_brk TBROK "TST_POS_ARGS must be integer"
+	if [ -n "$TST_CNT" ]; then
+		if ! tst_is_int "$TST_CNT"; then
+			tst_brk TBROK "TST_CNT must be integer"
+		fi
+
+		if [ "$TST_CNT" -le 0 ]; then
+			tst_brk TBROK "TST_CNT must be > 0"
+		fi
 	fi
 
-	if [ "$TST_POS_ARGS" -le 0 ]; then
-		tst_brk TBROK "TST_POS_ARGS must be > 0"
+	if [ -n "$TST_POS_ARGS" ]; then
+		if ! tst_is_int "$TST_POS_ARGS"; then
+			tst_brk TBROK "TST_POS_ARGS must be integer"
+		fi
+
+		if [ "$TST_POS_ARGS" -le 0 ]; then
+			tst_brk TBROK "TST_POS_ARGS must be > 0"
+		fi
 	fi
-fi
 
-if [ -z "$LTPROOT" ]; then
-	export LTPROOT="$PWD"
-	export TST_DATAROOT="$LTPROOT/datafiles"
-else
-	export TST_DATAROOT="$LTPROOT/testcases/data/$TST_ID"
-fi
+	if [ -z "$LTPROOT" ]; then
+		export LTPROOT="$PWD"
+		export TST_DATAROOT="$LTPROOT/datafiles"
+	else
+		export TST_DATAROOT="$LTPROOT/testcases/data/$TST_ID"
+	fi
 
-TST_ARGS="$@"
+	TST_ARGS="$@"
 
-while getopts ":hi:$TST_OPTS" tst_name; do
-	case $tst_name in
-	'h') TST_PRINT_HELP=1;;
-	*);;
-	esac
-done
+	while getopts ":hi:$TST_OPTS" tst_name; do
+		case $tst_name in
+		'h') TST_PRINT_HELP=1;;
+		*);;
+		esac
+	done
 
-shift $((OPTIND - 1))
+	shift $((OPTIND - 1))
 
-if [ -n "$TST_POS_ARGS" ]; then
-	if [ -z "$TST_PRINT_HELP" -a $# -ne "$TST_POS_ARGS" ]; then
-		tst_brk TBROK "Invalid number of positional paramters:"\
-			      "have ($@) $#, expected ${TST_POS_ARGS}"
-	fi
-else
-	if [ -z "$TST_PRINT_HELP" -a $# -ne 0 ]; then
-		tst_brk TBROK "Unexpected positional arguments '$@'"
+	if [ -n "$TST_POS_ARGS" ]; then
+		if [ -z "$TST_PRINT_HELP" -a $# -ne "$TST_POS_ARGS" ]; then
+			tst_brk TBROK "Invalid number of positional paramters:"\
+					  "have ($@) $#, expected ${TST_POS_ARGS}"
+		fi
+	else
+		if [ -z "$TST_PRINT_HELP" -a $# -ne 0 ]; then
+			tst_brk TBROK "Unexpected positional arguments '$@'"
+		fi
 	fi
 fi