ci: use run-tests.sh

This commit is contained in:
Erik Arvstedt 2020-12-11 13:26:10 +01:00
parent a82f0f5f48
commit 9977fa69af
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
3 changed files with 37 additions and 39 deletions

View File

@ -1,12 +0,0 @@
let
pkgs = import <nixpkgs> {};
nbPkgs = import ../pkgs { inherit pkgs; };
ciPkgs = with nbPkgs; [
electrs
elementsd
hwi
joinmarket
lightning-loop
];
in
pkgs.writeText "ci-pkgs" (pkgs.lib.concatMapStringsSep "\n" toString ciPkgs)

View File

@ -21,9 +21,9 @@ fi
echo "$NIX_PATH ($(nix eval --raw nixpkgs.lib.version))" echo "$NIX_PATH ($(nix eval --raw nixpkgs.lib.version))"
if [[ $scenario ]]; then if [[ $scenario ]]; then
buildExpr=$(../test/run-tests.sh --scenario $scenario exprForCI) testArgs="--scenario $scenario"
else else
buildExpr="import ./build.nix" testArgs=pkgsUnstable
fi fi
"${BASH_SOURCE[0]%/*}/build-to-cachix.sh" -E "$buildExpr" "${BASH_SOURCE[0]%/*}/../test/run-tests.sh" --ci $testArgs

View File

@ -44,6 +44,7 @@ scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd)
scenario= scenario=
outLinkPrefix= outLinkPrefix=
ciBuild=
while :; do while :; do
case $1 in case $1 in
--scenario|-s) --scenario|-s)
@ -66,6 +67,10 @@ while :; do
exit 1 exit 1
fi fi
;; ;;
--ci)
shift
ciBuild=1
;;
*) *)
break break
esac esac
@ -135,12 +140,16 @@ container() {
doBuild() { doBuild() {
name=$1 name=$1
shift shift
if [[ $outLinkPrefix ]]; then if [[ $ciBuild ]]; then
outLink="--out-link $outLinkPrefix-$name" "$scriptDir/../ci/build-to-cachix.sh" "$@"
else else
outLink=--no-out-link if [[ $outLinkPrefix ]]; then
outLink="--out-link $outLinkPrefix-$name"
else
outLink=--no-out-link
fi
nix-build $outLink "$@"
fi fi
nix-build $outLink "$@"
} }
# Run the test by building the test derivation # Run the test by building the test derivation
@ -148,27 +157,28 @@ buildTest() {
vmTestNixExpr | doBuild $scenario $outLinkArg "$@" - vmTestNixExpr | doBuild $scenario $outLinkArg "$@" -
} }
# On continuous integration nodes there are few other processes running alongside the
# test, so use more memory here for maximum performance.
exprForCI() {
memoryMiB=4096
memTotalKiB=$(awk '/MemTotal/ { print $2 }' /proc/meminfo)
memAvailableKiB=$(awk '/MemAvailable/ { print $2 }' /proc/meminfo)
# Round down to nearest multiple of 50 MiB for improved test build caching
((memAvailableMiB = memAvailableKiB / (1024 * 50) * 50))
((memAvailableMiB < memoryMiB)) && memoryMiB=$memAvailableMiB
>&2 echo "VM stats: CPUs: $numCPUs, memory: $memoryMiB MiB"
>&2 echo "Host memory total: $((memTotalKiB / 1024)) MiB, available: $memAvailableMiB MiB"
# VMX is usually not available on CI nodes due to recursive virtualisation.
# Explicitly disable VMX, otherwise QEMU 4.20 fails with message
# "error: failed to set MSR 0x48b to 0x159ff00000000"
vmTestNixExpr "-cpu host,-vmx"
}
vmTestNixExpr() { vmTestNixExpr() {
extraQEMUOpts="$1" extraQEMUOpts=
cat <<EOF
if [[ $ciBuild ]]; then
# On continuous integration nodes there are few other processes running alongside the
# test, so use more memory here for maximum performance.
memoryMiB=4096
memTotalKiB=$(awk '/MemTotal/ { print $2 }' /proc/meminfo)
memAvailableKiB=$(awk '/MemAvailable/ { print $2 }' /proc/meminfo)
# Round down to nearest multiple of 50 MiB for improved test build caching
((memAvailableMiB = memAvailableKiB / (1024 * 50) * 50))
((memAvailableMiB < memoryMiB)) && memoryMiB=$memAvailableMiB
>&2 echo "VM stats: CPUs: $numCPUs, memory: $memoryMiB MiB"
>&2 echo "Host memory total: $((memTotalKiB / 1024)) MiB, available: $memAvailableMiB MiB"
# VMX is usually not available on CI nodes due to recursive virtualisation.
# Explicitly disable VMX, otherwise QEMU 4.20 fails with message
# "error: failed to set MSR 0x48b to 0x159ff00000000"
extraQEMUOpts="-cpu host,-vmx"
fi
cat <<EOF
((import "$scriptDir/tests.nix" { scenario = "$scenario"; }).vm {}).overrideAttrs (old: rec { ((import "$scriptDir/tests.nix" { scenario = "$scenario"; }).vm {}).overrideAttrs (old: rec {
buildCommand = '' buildCommand = ''
export QEMU_OPTS="-smp $numCPUs -m $memoryMiB $extraQEMUOpts" export QEMU_OPTS="-smp $numCPUs -m $memoryMiB $extraQEMUOpts"