public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] test: Add rudimentary support to run selected tests only
@ 2022-10-07  0:47 Stefano Brivio
  2022-10-07  6:11 ` David Gibson
  0 siblings, 1 reply; 3+ messages in thread
From: Stefano Brivio @ 2022-10-07  0:47 UTC (permalink / raw)
  To: passt-dev

[-- Attachment #1: Type: text/plain, Size: 3396 bytes --]

To keep this simple, only support tests that have corresponding setup
and teardown functions implied by their path. For example:

  ./run passt/ndp

will trigger the 'passt' setup and teardown functions.

This is not really elegant, but it looks robust, and while David is
considering proper alternatives, it should be quite useful.

Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
---
 test/README.md | 16 ++++++++++++++++
 test/lib/term  |  2 +-
 test/run       | 37 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/test/README.md b/test/README.md
index 72a4986..09ad05d 100644
--- a/test/README.md
+++ b/test/README.md
@@ -85,6 +85,22 @@ variable settings: DEBUG=1 enables debugging messages, TRACE=1 enables tracing
 
     PCAP=1 TRACE=1 ./run
 
+## Running selected tests
+
+Rudimentary support to run a list of selected tests, without support for
+dependencies, is available. Tests need to have a setup function corresponding to
+their path. For example:
+
+    ./run passt/ndp passt/dhcp pasta/ndp
+
+will call the 'passt' setup function (from lib/setup), run the two corresponding
+tests, call the 'passt' teardown function, the 'pasta' setup, run the pasta/ndp
+test, and finally tear down the 'pasta' setup.
+
+Note that requirements on steps implemented by related tests are not handled.
+For example, if the 'passt/tcp' needs guest connectivity set up by the
+'passt/ndp' and 'passt/dhcp' tests, those need to be listed explicitly.
+
 ## Continuous integration
 
 Issuing:
diff --git a/test/lib/term b/test/lib/term
index eade2cd..1b42df8 100755
--- a/test/lib/term
+++ b/test/lib/term
@@ -650,7 +650,7 @@ run_term() {
 		asciinema rec --overwrite "${STATEBASE}/demo.uncut" -c "$TMUX /bin/sh -c './run_demo from_term'"
 		video_postprocess "${STATEBASE}/demo.uncut"
 	else
-		$TMUX /bin/sh -c './run from_term'
+		$TMUX /bin/sh -c "./run from_term ${*}"
 	fi
 }
 
diff --git a/test/run b/test/run
index 4bb9cd8..1ae270e 100755
--- a/test/run
+++ b/test/run
@@ -127,6 +127,37 @@ run() {
 	return 0
 }
 
+# run_selected() - Run list of tests, with setup/teardown based on test path
+# $@:	List of tests
+run_selected() {
+	mkfifo $STATEBASE/log_pipe
+
+	term
+	VALGRIND=1
+
+	__setup=
+	for __test; do
+		if [ "${__test%%/*}" != "${__setup}" ]; then
+			[ -n "${__setup}" ] && teardown "${__setup}"
+			__setup="${__test%%/*}"
+			setup "${__setup}"
+		fi
+
+		test "${__test}"
+	done
+	teardown "${__setup}"
+
+	log "PASS: ${STATUS_PASS}, FAIL: ${STATUS_FAIL}"
+
+	pause_continue \
+		"Press any key to keep test session open"	\
+		"Closing in "					\
+		"Interrupted, press any key to quit"		\
+		9
+
+	return 0
+}
+
 # demo() - Simpler path for demo purposes
 demo() {
 	mkfifo $STATEBASE/log_pipe
@@ -160,11 +191,15 @@ demo() {
 [ "$(basename "${0}")" = "run_demo" ] && DEMO=1
 
 if [ "${1}" = "from_term" ]; then
+	shift
+
 	exec > ${LOGDIR}/script.log 2>&1
 	[ ${DEBUG} -eq 1 ] && set -x
 	cd ..
 	if [ ${DEMO} -eq 1 ]; then
 		demo
+	elif [ -n "${1}" ]; then
+		run_selected ${*}
 	else
 		run
 	fi
@@ -176,7 +211,7 @@ else
 	:> "${LOGFILE}"
 	STATEBASE="$(mktemp -d --tmpdir passt-tests-XXXXXX)"
 	trap "cleanup" EXIT
-	run_term
+	run_term ${*}
 fi
 
 [ ${DEMO} -eq 1 ] && exit 0
-- 
@@ -127,6 +127,37 @@ run() {
 	return 0
 }
 
+# run_selected() - Run list of tests, with setup/teardown based on test path
+# $@:	List of tests
+run_selected() {
+	mkfifo $STATEBASE/log_pipe
+
+	term
+	VALGRIND=1
+
+	__setup=
+	for __test; do
+		if [ "${__test%%/*}" != "${__setup}" ]; then
+			[ -n "${__setup}" ] && teardown "${__setup}"
+			__setup="${__test%%/*}"
+			setup "${__setup}"
+		fi
+
+		test "${__test}"
+	done
+	teardown "${__setup}"
+
+	log "PASS: ${STATUS_PASS}, FAIL: ${STATUS_FAIL}"
+
+	pause_continue \
+		"Press any key to keep test session open"	\
+		"Closing in "					\
+		"Interrupted, press any key to quit"		\
+		9
+
+	return 0
+}
+
 # demo() - Simpler path for demo purposes
 demo() {
 	mkfifo $STATEBASE/log_pipe
@@ -160,11 +191,15 @@ demo() {
 [ "$(basename "${0}")" = "run_demo" ] && DEMO=1
 
 if [ "${1}" = "from_term" ]; then
+	shift
+
 	exec > ${LOGDIR}/script.log 2>&1
 	[ ${DEBUG} -eq 1 ] && set -x
 	cd ..
 	if [ ${DEMO} -eq 1 ]; then
 		demo
+	elif [ -n "${1}" ]; then
+		run_selected ${*}
 	else
 		run
 	fi
@@ -176,7 +211,7 @@ else
 	:> "${LOGFILE}"
 	STATEBASE="$(mktemp -d --tmpdir passt-tests-XXXXXX)"
 	trap "cleanup" EXIT
-	run_term
+	run_term ${*}
 fi
 
 [ ${DEMO} -eq 1 ] && exit 0
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] test: Add rudimentary support to run selected tests only
  2022-10-07  0:47 [PATCH] test: Add rudimentary support to run selected tests only Stefano Brivio
@ 2022-10-07  6:11 ` David Gibson
  2022-10-07  7:37   ` Stefano Brivio
  0 siblings, 1 reply; 3+ messages in thread
From: David Gibson @ 2022-10-07  6:11 UTC (permalink / raw)
  To: passt-dev

[-- Attachment #1: Type: text/plain, Size: 4395 bytes --]

On Fri, Oct 07, 2022 at 02:47:32AM +0200, Stefano Brivio wrote:
> To keep this simple, only support tests that have corresponding setup
> and teardown functions implied by their path. For example:
> 
>   ./run passt/ndp
> 
> will trigger the 'passt' setup and teardown functions.
> 
> This is not really elegant, but it looks robust, and while David is
> considering proper alternatives, it should be quite useful.
> 
> Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>

I'm not sure I'd go so far as to call it "robust".  AFAICT it will
break for cases where the setup function isn't named after the test
dir (e.g. for perf/* which need the passt_in_ns setup).  And, of
course, it's still the user's responsibility to handle inter-test
dependencies (dhcp needs ndp to run first , tcp & udp need dhcp to run
first , etc.)

But still, it's pretty simple and looks useful despite those
limitations so,

Reviewed-by: David Gibson <david(a)gibson.dropbear.id.au>


> ---
>  test/README.md | 16 ++++++++++++++++
>  test/lib/term  |  2 +-
>  test/run       | 37 ++++++++++++++++++++++++++++++++++++-
>  3 files changed, 53 insertions(+), 2 deletions(-)
> 
> diff --git a/test/README.md b/test/README.md
> index 72a4986..09ad05d 100644
> --- a/test/README.md
> +++ b/test/README.md
> @@ -85,6 +85,22 @@ variable settings: DEBUG=1 enables debugging messages, TRACE=1 enables tracing
>  
>      PCAP=1 TRACE=1 ./run
>  
> +## Running selected tests
> +
> +Rudimentary support to run a list of selected tests, without support for
> +dependencies, is available. Tests need to have a setup function corresponding to
> +their path. For example:
> +
> +    ./run passt/ndp passt/dhcp pasta/ndp
> +
> +will call the 'passt' setup function (from lib/setup), run the two corresponding
> +tests, call the 'passt' teardown function, the 'pasta' setup, run the pasta/ndp
> +test, and finally tear down the 'pasta' setup.
> +
> +Note that requirements on steps implemented by related tests are not handled.
> +For example, if the 'passt/tcp' needs guest connectivity set up by the
> +'passt/ndp' and 'passt/dhcp' tests, those need to be listed explicitly.
> +
>  ## Continuous integration
>  
>  Issuing:
> diff --git a/test/lib/term b/test/lib/term
> index eade2cd..1b42df8 100755
> --- a/test/lib/term
> +++ b/test/lib/term
> @@ -650,7 +650,7 @@ run_term() {
>  		asciinema rec --overwrite "${STATEBASE}/demo.uncut" -c "$TMUX /bin/sh -c './run_demo from_term'"
>  		video_postprocess "${STATEBASE}/demo.uncut"
>  	else
> -		$TMUX /bin/sh -c './run from_term'
> +		$TMUX /bin/sh -c "./run from_term ${*}"
>  	fi
>  }
>  
> diff --git a/test/run b/test/run
> index 4bb9cd8..1ae270e 100755
> --- a/test/run
> +++ b/test/run
> @@ -127,6 +127,37 @@ run() {
>  	return 0
>  }
>  
> +# run_selected() - Run list of tests, with setup/teardown based on test path
> +# $@:	List of tests
> +run_selected() {
> +	mkfifo $STATEBASE/log_pipe
> +
> +	term
> +	VALGRIND=1
> +
> +	__setup=
> +	for __test; do
> +		if [ "${__test%%/*}" != "${__setup}" ]; then
> +			[ -n "${__setup}" ] && teardown "${__setup}"
> +			__setup="${__test%%/*}"
> +			setup "${__setup}"
> +		fi
> +
> +		test "${__test}"
> +	done
> +	teardown "${__setup}"
> +
> +	log "PASS: ${STATUS_PASS}, FAIL: ${STATUS_FAIL}"
> +
> +	pause_continue \
> +		"Press any key to keep test session open"	\
> +		"Closing in "					\
> +		"Interrupted, press any key to quit"		\
> +		9
> +
> +	return 0
> +}
> +
>  # demo() - Simpler path for demo purposes
>  demo() {
>  	mkfifo $STATEBASE/log_pipe
> @@ -160,11 +191,15 @@ demo() {
>  [ "$(basename "${0}")" = "run_demo" ] && DEMO=1
>  
>  if [ "${1}" = "from_term" ]; then
> +	shift
> +
>  	exec > ${LOGDIR}/script.log 2>&1
>  	[ ${DEBUG} -eq 1 ] && set -x
>  	cd ..
>  	if [ ${DEMO} -eq 1 ]; then
>  		demo
> +	elif [ -n "${1}" ]; then
> +		run_selected ${*}
>  	else
>  		run
>  	fi
> @@ -176,7 +211,7 @@ else
>  	:> "${LOGFILE}"
>  	STATEBASE="$(mktemp -d --tmpdir passt-tests-XXXXXX)"
>  	trap "cleanup" EXIT
> -	run_term
> +	run_term ${*}
>  fi
>  
>  [ ${DEMO} -eq 1 ] && exit 0

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] test: Add rudimentary support to run selected tests only
  2022-10-07  6:11 ` David Gibson
@ 2022-10-07  7:37   ` Stefano Brivio
  0 siblings, 0 replies; 3+ messages in thread
From: Stefano Brivio @ 2022-10-07  7:37 UTC (permalink / raw)
  To: passt-dev

[-- Attachment #1: Type: text/plain, Size: 1027 bytes --]

On Fri, 7 Oct 2022 17:11:56 +1100
David Gibson <david(a)gibson.dropbear.id.au> wrote:

> On Fri, Oct 07, 2022 at 02:47:32AM +0200, Stefano Brivio wrote:
> > To keep this simple, only support tests that have corresponding setup
> > and teardown functions implied by their path. For example:
> > 
> >   ./run passt/ndp
> > 
> > will trigger the 'passt' setup and teardown functions.
> > 
> > This is not really elegant, but it looks robust, and while David is
> > considering proper alternatives, it should be quite useful.
> > 
> > Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>  
> 
> I'm not sure I'd go so far as to call it "robust".  AFAICT it will
> break for cases where the setup function isn't named after the test
> dir (e.g. for perf/* which need the passt_in_ns setup).  And, of
> course, it's still the user's responsibility to handle inter-test
> dependencies (dhcp needs ndp to run first , tcp & udp need dhcp to run
> first , etc.)

Right, well, but I mentioned both facts in the README... ;)

-- 
Stefano


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-07  7:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-07  0:47 [PATCH] test: Add rudimentary support to run selected tests only Stefano Brivio
2022-10-07  6:11 ` David Gibson
2022-10-07  7:37   ` Stefano Brivio

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).