From 823b5e480e40a47e3e01471094af681cd6abd33c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 25 Jan 2019 06:42:26 -0500 Subject: [PATCH] Tests: add script for running multiple Python-module tests - This is a driver script for running testmodule.py multiple times with different global- and job-configurations. - Usage: testpythonrun.sh - Run the script from the build-directory. It uses files from the tests/ (source) subdirectory to drive the test runs. --- src/modules/testpythonrun.sh | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/modules/testpythonrun.sh diff --git a/src/modules/testpythonrun.sh b/src/modules/testpythonrun.sh new file mode 100644 index 000000000..be2b7800b --- /dev/null +++ b/src/modules/testpythonrun.sh @@ -0,0 +1,55 @@ +#! /bin/sh + +### Command-line validation +# +# +SRCDIR=$( dirname "$0" ) +test -d "$SRCDIR" || { echo "! Can't find source directory." ; exit 1 ; } + +MODULE="$1" +test -n "$MODULE" || { echo "! Usage: $0 " ; exit 1 ; } + +### Run-time validation +# +# .. switch SRCDIR to the module that has been found +BINDIR="$SRCDIR" # Keep original SRCDIR +SRCDIR="$SRCDIR/$MODULE" +XSRCDIR="src/modules/$MODULE" # In builddir +TESTDIR="$SRCDIR/tests" + +test -x "$BINDIR/testmodule.py" || { echo "! No support script $BINDIR/testmodule.py" ; exit 1 ; } +test -d "$SRCDIR" || { echo "! Source $SRCDIR is not a directory." ; exit 1 ; } +test -f "$TESTDIR/1.global" || { echo "! Source $SRCDIR has no tests." ; exit 1 ; } + +test -f "libcalamares.so" || { echo "! Run the tests from the build-directory." ; exit 1 ; } +test -d "$XSRCDIR" || { echo "! No module directory $XSRCDIR in build-dir." ; exit 1 ; } + +### Python setup +# +# +export PYTHONPATH=".:$PYTHONPATH" +PYTHON=$( which python3 2> /dev/null ) +if test -z "$PYTHON" ; then + PYTHON=$( which python 2> /dev/null ) +fi +test -x "$PYTHON" || { echo "! No suitable Python executable found." ; exit 1 ; } + +### Test-execution +# +# +C=0 +while true ; do + # Might use shell arithmetic, but need other shebang then + C=$( expr "$C" + 1 ) + + G_CFG="$TESTDIR/$C.global" + J_CFG="$TESTDIR/$C.job" + + test -f "$G_CFG" || break + if test -f "$J_CFG" ; then + $PYTHON "$BINDIR/testmodule.py" "$XSRCDIR" "$G_CFG" "$J_CFG" + else + $PYTHON "$BINDIR/testmodule.py" "$XSRCDIR" "$G_CFG" + fi +done +