tests: define tests via flake
Advantages: - Pure test evaluations - The test framework can now be used by flakes that extend nix-bitcoin - Most features of `run-tests.sh` are now accessible via `nix build`/`nix run`. We keep `run-tests.sh` for advanced features like `scenarioOverridesFile` and adhoc scenarios. Other changes: - `run-tests.sh` now builds aggregate VM tests like `basic` or `buildable` by creating all VMs in a single evaluation. This speeds up the tests and eases debugging by separating the eval and build steps. - Use the new `nix` CLI which has improved build output logging by prefixing output lines with the origin drv name.
This commit is contained in:
parent
90e942e5ae
commit
edbaeb9813
12 changed files with 451 additions and 277 deletions
50
test/lib/run-vm.sh
Normal file
50
test/lib/run-vm.sh
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# This script uses the following env vars:
|
||||
# NIX_BITCOIN_VM_ENABLE_NETWORK
|
||||
# NIX_BITCOIN_VM_DATADIR
|
||||
# QEMU_OPTS
|
||||
# QEMU_NET_OPTS
|
||||
|
||||
if [[ ${NIX_BITCOIN_VM_DATADIR:-} ]]; then
|
||||
dataDir=$NIX_BITCOIN_VM_DATADIR
|
||||
else
|
||||
dataDir=$(mktemp -d /tmp/nix-bitcoin-vm.XXX)
|
||||
trap 'rm -rf "$dataDir"' EXIT
|
||||
fi
|
||||
|
||||
testDriver=$1
|
||||
shift
|
||||
|
||||
# Variable 'tests' contains the Python code that is executed by the driver on startup
|
||||
if [[ ${1:-} == --debug ]]; then
|
||||
shift
|
||||
echo "Running interactive testing environment"
|
||||
# Start REPL.
|
||||
# Use `code.interact` for the REPL instead of the builtin test driver REPL
|
||||
# because it supports low featured terminals like Emacs' shell-mode.
|
||||
tests='
|
||||
is_interactive = True
|
||||
exec(open(os.environ["testScript"]).read())
|
||||
if "machine" in vars(): machine.start()
|
||||
import code
|
||||
code.interact(local=globals())
|
||||
'
|
||||
echo
|
||||
echo "Starting VM, data dir: $dataDir"
|
||||
else
|
||||
tests='exec(open(os.environ["testScript"]).read())'
|
||||
fi
|
||||
|
||||
if [[ ! ${NIX_BITCOIN_VM_ENABLE_NETWORK:-} ]]; then
|
||||
QEMU_NET_OPTS='restrict=on'
|
||||
fi
|
||||
|
||||
# The VM creates a VDE control socket in $PWD
|
||||
env --chdir "$dataDir" -i \
|
||||
USE_TMPDIR=1 \
|
||||
TMPDIR="$dataDir" \
|
||||
QEMU_OPTS="-nographic ${QEMU_OPTS:-}" \
|
||||
QEMU_NET_OPTS="${QEMU_NET_OPTS:-}" \
|
||||
"$testDriver/bin/nixos-test-driver" <(echo "$tests") "$@"
|
||||
Loading…
Add table
Add a link
Reference in a new issue