From cff52180c4103fafbedc6b79fbc0269ced108240 Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Thu, 9 May 2019 13:22:41 +0200 Subject: [PATCH] autotest: don't source the configuration file in every test script Most of our bash test scripts source autotest_common.sh to be able to use some autotest-specific functions like timing_enter(). The same test scripts allow specifying custom command line parameters without actually realizing that those parameters can be potentially picked up by autotest_common.sh as well. For example, if particular nvmf tests are run in "isolation" mode by being executed with the first param set to "iso", and there is a file named "iso" in the current dir, that file will be sourced. This could be bad. In this patch we stop sourcing or even processing $1 in autotest_common.sh. Instead, the test configuration will be sourced just once from autobuild.sh, autopackage.sh and autotest.sh. If the user wants to run particular test scripts manually, he should source an SPDK test configuration by himself - manually as well. In most cases he won't even have two, as only a few test scripts depend on SPDK_* variables. Note that we still have to setup the default values for SPDK_* variables in autotest_common.sh because some of our test scripts actually depend on them: > if [ $SPDK_TEST_RBD -eq 1 ]; then ... Because it lacks any type of quotes around SPDK_TEST_RBD, it will print the following message when that variable is unset: > /bin/bash: line 0: [: -eq: unary operator expected It doesn't trigger any error ($? == 0), but can be still a bit misleading in the script output. Change-Id: I350045d8582d66fe1ed7697d4bcbba324cb541ad Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/453876 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- autobuild.sh | 8 ++++++++ autopackage.sh | 8 ++++++++ autotest.sh | 5 +++-- test/common/autotest_common.sh | 6 ------ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/autobuild.sh b/autobuild.sh index becb9c972..ba9c10895 100755 --- a/autobuild.sh +++ b/autobuild.sh @@ -2,6 +2,14 @@ set -e +# If the configuration of tests is not provided, no tests will be carried out. +if [[ ! -f $1 ]]; then + echo "ERROR: SPDK test configuration not specified" + exit 1 +fi + +source "$1" + rootdir=$(readlink -f $(dirname $0)) source "$rootdir/test/common/autotest_common.sh" diff --git a/autopackage.sh b/autopackage.sh index 7851fb852..ce114af4b 100755 --- a/autopackage.sh +++ b/autopackage.sh @@ -2,6 +2,14 @@ set -xe +# If the configuration of tests is not provided, no tests will be carried out. +if [[ ! -f $1 ]]; then + echo "ERROR: SPDK test configuration not specified" + exit 1 +fi + +source "$1" + rootdir=$(readlink -f $(dirname $0)) source "$rootdir/test/common/autotest_common.sh" diff --git a/autotest.sh b/autotest.sh index 949639c52..9309e9a33 100755 --- a/autotest.sh +++ b/autotest.sh @@ -4,11 +4,12 @@ rootdir=$(readlink -f $(dirname $0)) # In autotest_common.sh all tests are disabled by default. # If the configuration of tests is not provided, no tests will be carried out. -if [[ -z $1 ]]; then - echo "SPDK test configuration not specified" +if [[ ! -f $1 ]]; then + echo "ERROR: SPDK test configuration not specified" exit 1 fi +source "$1" source "$rootdir/test/common/autotest_common.sh" source "$rootdir/test/nvmf/common.sh" diff --git a/test/common/autotest_common.sh b/test/common/autotest_common.sh index 7ab8cb7ff..d860669e8 100644 --- a/test/common/autotest_common.sh +++ b/test/common/autotest_common.sh @@ -59,12 +59,6 @@ export RUN_NIGHTLY : ${RUN_NIGHTLY_FAILING:=0} export RUN_NIGHTLY_FAILING -if [[ ! -z $1 ]]; then - if [ -f $1 ]; then - source $1 - fi -fi - # Set defaults for missing test config options : ${SPDK_BUILD_DOC=0}; export SPDK_BUILD_DOC : ${SPDK_BUILD_SHARED_OBJECT=0}; export SPDK_BUILD_SHARED_OBJECT