Merge #348: run-tests: add 'vm' command
3cce822c64
run-tests: add 'vm' command (Erik Arvstedt) Pull request description: ACKs for top commit: nixbitcoin: ACK3cce822c64
Tree-SHA512: 1b7cdc0bc3b73634fdc6abd6817417fd49853be076cf71cc54487e5db9e97e67832eef5ecbb8e899e30a91a60ff333e022e51cc664df7364417240f05096eb16
This commit is contained in:
commit
9e7d9ee475
|
@ -45,9 +45,14 @@ the host system.
|
||||||
git clone https://github.com/fort-nix/nix-bitcoin
|
git clone https://github.com/fort-nix/nix-bitcoin
|
||||||
cd nix-bitcoin/test
|
cd nix-bitcoin/test
|
||||||
|
|
||||||
|
# Run a node in a VM. No tests are executed.
|
||||||
|
./run-tests.sh vm
|
||||||
|
systemctl status bitcoind
|
||||||
|
|
||||||
# Run a Python test shell inside a VM node
|
# Run a Python test shell inside a VM node
|
||||||
./run-tests.sh debug
|
./run-tests.sh debug
|
||||||
print(succeed("systemctl status bitcoind"))
|
print(succeed("systemctl status bitcoind"))
|
||||||
|
run_test("bitcoind")
|
||||||
|
|
||||||
# Run a node in a container. Requires systemd and root privileges.
|
# Run a node in a container. Requires systemd and root privileges.
|
||||||
./run-tests.sh container
|
./run-tests.sh container
|
||||||
|
|
|
@ -61,5 +61,23 @@ name: testConfig:
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# This allows running a test scenario in a regular NixOS VM.
|
||||||
|
# No tests are executed.
|
||||||
|
vmWithoutTests = (pkgs.nixos {
|
||||||
|
imports = [
|
||||||
|
testConfig
|
||||||
|
"${toString pkgs.path}/nixos/modules/virtualisation/qemu-vm.nix"
|
||||||
|
];
|
||||||
|
virtualisation.graphics = false;
|
||||||
|
services.mingetty.autologinUser = "root";
|
||||||
|
|
||||||
|
# Provide a shortcut for instant poweroff from within the machine
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
(lowPrio (writeScriptBin "q" ''
|
||||||
|
echo o >/proc/sysrq-trigger
|
||||||
|
''))
|
||||||
|
];
|
||||||
|
}).vm;
|
||||||
|
|
||||||
config = testConfig;
|
config = testConfig;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,14 @@
|
||||||
# For now, creating NixOS containers requires root permissions.
|
# For now, creating NixOS containers requires root permissions.
|
||||||
# See ./lib/make-container.sh for a complete documentation.
|
# See ./lib/make-container.sh for a complete documentation.
|
||||||
#
|
#
|
||||||
|
# Run a test scenario in a regular NixOS VM.
|
||||||
|
# No tests are executed, the machine's serial console is attached to your terminal.
|
||||||
|
# ./run-tests.sh [--scenario <scenario>] vm
|
||||||
|
#
|
||||||
|
# This is useful for directly exploring a test configuration without the
|
||||||
|
# intermediate Python REPL layer.
|
||||||
|
# Run command 'q' inside the machine for instant poweroff.
|
||||||
|
#
|
||||||
# Run tests from a snapshot copy of the source files
|
# Run tests from a snapshot copy of the source files
|
||||||
# ./run-tests.sh --copy-src|-c ...
|
# ./run-tests.sh --copy-src|-c ...
|
||||||
#
|
#
|
||||||
|
@ -170,6 +178,24 @@ container() {
|
||||||
"$scriptDir/lib/make-container.sh" "$@"
|
"$scriptDir/lib/make-container.sh" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Run a regular NixOS VM
|
||||||
|
vm() {
|
||||||
|
export TMPDIR=$(mktemp -d /tmp/nix-bitcoin-vm.XXX)
|
||||||
|
runAtExit+="rm -rf $TMPDIR;"
|
||||||
|
|
||||||
|
nix-build --out-link $TMPDIR/vm -E "((import \"$scriptDir/tests.nix\" {}).getTest \"$scenario\").vmWithoutTests"
|
||||||
|
|
||||||
|
echo "VM stats: CPUs: $numCPUs, memory: $memoryMiB MiB"
|
||||||
|
extraNetOpts=
|
||||||
|
[[ $NB_TEST_ENABLE_NETWORK ]] || extraNetOpts='restrict=on'
|
||||||
|
|
||||||
|
USE_TMPDIR=1 \
|
||||||
|
NIX_DISK_IMAGE=$TMPDIR/img.qcow2 \
|
||||||
|
QEMU_OPTS="-smp $numCPUs -m $memoryMiB -nographic $QEMU_OPTS" \
|
||||||
|
QEMU_NET_OPTS="$extraNetOpts $QEMU_NET_OPTS" \
|
||||||
|
$TMPDIR/vm/bin/run-*-vm
|
||||||
|
}
|
||||||
|
|
||||||
doBuild() {
|
doBuild() {
|
||||||
name=$1
|
name=$1
|
||||||
shift
|
shift
|
||||||
|
|
Loading…
Reference in New Issue
Block a user