From 43ce847e2b5c728018ac3219e29a14a36d6d25d5 Mon Sep 17 00:00:00 2001 From: nixbitcoin Date: Thu, 16 Jul 2020 14:48:41 +0000 Subject: [PATCH] tests: allow running integration tests with different configurations --- test/run-tests.sh | 43 +++++++++-- test/scenarios/default.py | 77 +++++++++++++++++++ test/scenarios/lib.py | 34 ++++++++ .../withnetns.py} | 35 --------- test/test.nix | 12 ++- 5 files changed, 158 insertions(+), 43 deletions(-) create mode 100644 test/scenarios/default.py create mode 100644 test/scenarios/lib.py rename test/{test-script.py => scenarios/withnetns.py} (85%) diff --git a/test/run-tests.sh b/test/run-tests.sh index 5d59d35..def34be 100755 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -5,19 +5,52 @@ # # Usage: # Run test -# ./run-tests.sh +# ./run-tests.sh --scenario # # Run test and save result to avoid garbage collection -# ./run-tests.sh build --out-link /tmp/nix-bitcoin-test +# ./run-tests.sh --scenario build --out-link /tmp/nix-bitcoin-test # # Run interactive test debugging -# ./run-tests.sh debug +# ./run-tests.sh --scenario debug # # This starts the testing VM and drops you into a Python REPL where you can # manually execute the tests from ./test-script.py set -eo pipefail +die() { + printf '%s\n' "$1" >&2 + exit 1 +} + +# Initialize all the option variables. +# This ensures we are not contaminated by variables from the environment. +scenario= + +while :; do + case $1 in + --scenario) + if [ "$2" ]; then + scenario=$2 + shift + else + die 'ERROR: "--scenario" requires a non-empty option argument.' + fi + ;; + -?*) + printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2 + ;; + *) + break + esac + + shift +done + +if [[ -z $scenario ]]; then + die 'ERROR: "--scenario" is required' +fi + numCPUs=${numCPUs:-$(nproc)} # Min. 800 MiB needed to avoid 'out of memory' errors memoryMiB=${memoryMiB:-2048} @@ -32,7 +65,7 @@ run() { export TMPDIR=$(mktemp -d /tmp/nix-bitcoin-test.XXX) trap "rm -rf $TMPDIR" EXIT - nix-build --out-link $TMPDIR/driver "$scriptDir/test.nix" -A driver + nix-build --out-link $TMPDIR/driver -E "import \"$scriptDir/test.nix\" { scenario = \"$scenario\"; }" -A driver # Variable 'tests' contains the Python code that is executed by the driver on startup if [[ $1 == --interactive ]]; then @@ -95,7 +128,7 @@ exprForCI() { vmTestNixExpr() { cat <