From 3c9384eebb2cd152cb5e4756f426b4cf36269072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Wed, 21 Feb 2018 14:59:33 +0100 Subject: [PATCH] Allow retaining system test output using an environment variable Instead of exporting an environment variable containing a command line argument (NOCLEAN="-n"), extend run.sh to handle a "boolean" environment variable (SYSTEMTEST_NO_CLEAN) itself. The former method is buggy because the value of NOCLEAN is set in parallel.mk when that file is first created, but it is not subsequently updated upon each test run (because make considers parallel.mk to be up to date). To retain backward compatibility, the "-n" command line argument for run.sh is still supported (and has a higher priority than the relevant environment variable). The SYSTEMTEST_NO_CLEAN environment variable can also be used directly to prevent cleanup when using "make test" instead of runall.sh. Apart from fixing a bug, this simplifies the way runall.sh controls run.sh behavior due to the Makefile being bypassed. Direct processing of environment variables in run.sh is more scalable in the long run, given that the previously utilized technique, even with its implementation fixed, would still require Makefile.in to be modified in two places each time a new flag needed to be passed from runall.sh to run.sh. (cherry picked from commit 3862043879534542a75e40d5e6c0cc09f37f8d6b) --- bin/tests/system/Makefile.in | 4 ++-- bin/tests/system/README | 8 ++++---- bin/tests/system/run.sh | 7 ++++++- bin/tests/system/runall.sh | 9 ++++++--- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/bin/tests/system/Makefile.in b/bin/tests/system/Makefile.in index 1b7ff31dd7..cfd8e16d24 100644 --- a/bin/tests/system/Makefile.in +++ b/bin/tests/system/Makefile.in @@ -92,7 +92,7 @@ parallel.mk: for directory in $(PARALLEL) ; do \ echo "" >> $@ ; \ echo "test-`echo $$directory | tr _ -`:" >> $@ ; \ - echo " @$(SHELL) ./run.sh $$NOCLEAN -r -p $$port $$directory 2>&1 | tee $$directory/test.output" >> $@ ; \ + echo " @$(SHELL) ./run.sh -r -p $$port $$directory 2>&1 | tee $$directory/test.output" >> $@ ; \ port=`expr $$port + 100` ; \ done @@ -100,7 +100,7 @@ parallel.mk: test: parallel.mk subdirs @$(MAKE) -f parallel.mk check - @$(SHELL) ./runsequential.sh $$NOCLEAN -r + @$(SHELL) ./runsequential.sh -r @$(SHELL) ./testsummary.sh check: test diff --git a/bin/tests/system/README b/bin/tests/system/README index 4bf6719d44..3b521fc911 100644 --- a/bin/tests/system/README +++ b/bin/tests/system/README @@ -153,10 +153,10 @@ A run of all the system tests can also be initiated via make: make [-j numproc] test In this case, retention of the output files after a test completes successfully -is specified by setting the environment variable NOCLEAN to "-n" prior to -running make, e.g. +is specified by setting the environment variable SYSTEMTEST_NO_CLEAN to 1 prior +to running make, e.g. - NOCLEAN=-n make [-j numproc] test + SYSTEMTEST_NO_CLEAN=1 make [-j numproc] test @@ -714,7 +714,7 @@ the ports are assigned when the tests are run. This is achieved by having the when "make check" is run, and contains a target for each test of the form: : - @$(SHELL) run.sh $$NOCLEAN -r -p + @$(SHELL) run.sh -r -p The is unique and the values of for each test are separated by at least 100 ports. diff --git a/bin/tests/system/run.sh b/bin/tests/system/run.sh index 60e6395da7..9abdedbba8 100644 --- a/bin/tests/system/run.sh +++ b/bin/tests/system/run.sh @@ -17,9 +17,14 @@ SYSTEMTESTTOP=. . $SYSTEMTESTTOP/conf.sh stopservers=true -clean=true baseport=5300 +if [ ${SYSTEMTEST_NO_CLEAN:-0} -eq 1 ]; then + clean=false +else + clean=true +fi + while getopts "knp:r" flag; do case "$flag" in k) stopservers=false ;; diff --git a/bin/tests/system/runall.sh b/bin/tests/system/runall.sh index 5aa9412454..0ad6739527 100644 --- a/bin/tests/system/runall.sh +++ b/bin/tests/system/runall.sh @@ -27,12 +27,13 @@ SYSTEMTESTTOP=. usage="Usage: ./runall.sh [-n] [numprocesses]" +SYSTEMTEST_NO_CLEAN=0 + # Handle "-n" switch if present. -NOCLEAN="" while getopts "n" flag; do case "$flag" in - n) NOCLEAN="-n" ;; + n) SYSTEMTEST_NO_CLEAN=1 ;; esac done export NOCLEAN @@ -57,6 +58,8 @@ fi # Run the tests. +export SYSTEMTEST_NO_CLEAN + status=0 if [ "$CYGWIN" = "" ]; then # Running on Unix, use "make" to run tests in parallel. @@ -69,7 +72,7 @@ else # used, the tests would be run sequentially anyway.) { for testdir in $SUBDIRS; do - $SHELL run.sh $NOCLEAN $testdir || status=1 + $SHELL run.sh $testdir || status=1 done } 2>&1 | tee "systests.output" fi