2019-04-18 21:54:06 +08:00
|
|
|
{ pkgs ? import <nixpkgs> {},
|
|
|
|
diskImage ? "/opt/windows/c.img",
|
|
|
|
qemuMem ? "2G",
|
2019-04-19 00:41:28 +08:00
|
|
|
testTimeout ? 600,
|
2019-04-18 21:54:06 +08:00
|
|
|
artiqPkg ? import ../conda-artiq.nix { inherit pkgs; },
|
|
|
|
testCommand ? "python -m unittest discover -v artiq.test",
|
|
|
|
}:
|
|
|
|
|
|
|
|
with pkgs;
|
|
|
|
|
|
|
|
let
|
|
|
|
escape = builtins.replaceStrings [ "\\" ] [ "\\\\" ];
|
|
|
|
qemu = import ./qemu.nix {
|
|
|
|
inherit pkgs qemuMem;
|
|
|
|
diskImage = "c.img";
|
|
|
|
};
|
|
|
|
# Double-escape because we produce a script from a shell heredoc
|
|
|
|
ssh = cmd: qemu.ssh (escape cmd);
|
|
|
|
scp = qemu.scp;
|
|
|
|
condaEnv = "artiq-env";
|
2019-04-18 23:34:09 +08:00
|
|
|
tcpPorts = [ 1380 1381 1382 1383 ];
|
|
|
|
forwardedPorts =
|
|
|
|
map (port: {
|
|
|
|
listenAddr = "192.168.1.50";
|
|
|
|
targetAddr = "192.168.1.50";
|
|
|
|
inherit port;
|
|
|
|
}) tcpPorts;
|
2019-04-18 21:54:06 +08:00
|
|
|
in
|
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "windows-test-runner";
|
|
|
|
src = ./.;
|
|
|
|
|
|
|
|
propagatedBuildInputs = qemu.inputs;
|
|
|
|
dontBuild = true;
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
cat > $out/bin/run.sh << EOF
|
2019-04-23 00:59:58 +08:00
|
|
|
#!/usr/bin/env bash
|
2019-04-19 00:13:55 +08:00
|
|
|
set -e -m
|
|
|
|
|
2019-04-18 21:54:06 +08:00
|
|
|
# +1 day from last modification of the disk image
|
|
|
|
CLOCK=$(date -Is -d @$(expr $(stat -c %Y ${diskImage}) + 86400))
|
2019-04-18 23:34:09 +08:00
|
|
|
${qemu.runQemu true forwardedPorts [
|
2019-04-18 21:54:06 +08:00
|
|
|
"-boot" "order=c"
|
|
|
|
"-snapshot"
|
|
|
|
"-drive" "file=${diskImage},index=0,media=disk,cache=unsafe"
|
|
|
|
"-rtc" "base=\\$CLOCK"
|
|
|
|
"-display" "none"
|
|
|
|
]} &
|
|
|
|
|
|
|
|
echo "Wait for Windows to boot"
|
|
|
|
sleep 10
|
2019-04-18 23:40:25 +08:00
|
|
|
export HOME=`mktemp -d`
|
2019-04-18 21:54:06 +08:00
|
|
|
${ssh "ver"}
|
|
|
|
for pkg in ${artiqPkg}/noarch/artiq*.tar.bz2 ; do
|
|
|
|
${scp "\\$pkg" "artiq.tar.bz2"}
|
|
|
|
${ssh "anaconda\\scripts\\activate ${condaEnv} && conda install artiq.tar.bz2"}
|
|
|
|
done
|
|
|
|
|
2019-04-22 06:08:36 +08:00
|
|
|
# Schedule a timed shutdown against hanging test runs
|
2019-04-18 21:54:06 +08:00
|
|
|
${ssh "shutdown -s -t ${toString testTimeout}"}
|
|
|
|
|
2019-04-20 07:17:39 +08:00
|
|
|
FAIL=n
|
2019-04-20 07:50:55 +08:00
|
|
|
( ${ssh "anaconda\\scripts\\activate ${condaEnv} && ${testCommand}"} ) || FAIL=y
|
2019-04-18 21:54:06 +08:00
|
|
|
|
|
|
|
# Abort timeouted shutdown
|
|
|
|
${ssh "shutdown -a"}
|
|
|
|
# Power off immediately
|
|
|
|
${ssh "shutdown -p -f"}
|
2019-04-19 00:13:55 +08:00
|
|
|
wait
|
|
|
|
|
2019-04-22 07:14:17 +08:00
|
|
|
if [ "\$FAIL" = "y" ]; then
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
2019-04-18 21:54:06 +08:00
|
|
|
EOF
|
|
|
|
chmod a+x $out/bin/run.sh
|
|
|
|
'';
|
|
|
|
}
|