2019-04-08 23:41:05 +08:00
|
|
|
{ pkgs ? import <nixpkgs> {},
|
|
|
|
diskImage ? "/opt/windows/c.img",
|
|
|
|
qemuMem ? "2G",
|
2019-04-14 08:00:37 +08:00
|
|
|
testTimeout ? 180,
|
2019-04-13 21:50:58 +08:00
|
|
|
artiqPkg ? import ../conda-artiq.nix { inherit pkgs; },
|
2019-04-15 07:12:48 +08:00
|
|
|
testCommand ? "python -m unittest discover -v artiq.test",
|
2019-04-08 23:41:05 +08:00
|
|
|
}:
|
|
|
|
|
|
|
|
with pkgs;
|
|
|
|
|
|
|
|
let
|
2019-04-15 07:12:48 +08:00
|
|
|
escape = builtins.replaceStrings [ "\\" ] [ "\\\\" ];
|
2019-04-14 05:33:31 +08:00
|
|
|
qemu = import ./qemu.nix {
|
|
|
|
inherit pkgs qemuMem;
|
|
|
|
diskImage = "c.img";
|
|
|
|
};
|
2019-04-15 07:12:48 +08:00
|
|
|
# Double-escape because we produce a script from a shell heredoc
|
|
|
|
ssh = cmd: qemu.ssh (escape cmd);
|
2019-04-14 05:33:31 +08:00
|
|
|
scp = qemu.scp;
|
2019-04-18 14:51:18 +08:00
|
|
|
condaEnv = "artiq-env";
|
2019-04-15 07:12:48 +08:00
|
|
|
in
|
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "windows-test-runner";
|
|
|
|
src = ./.;
|
|
|
|
|
2019-04-18 15:08:17 +08:00
|
|
|
propagatedBuildInputs = qemu.inputs;
|
2019-04-15 07:12:48 +08:00
|
|
|
dontBuild = true;
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
cat > $out/bin/run.sh << EOF
|
|
|
|
# +1 day from last modification of the disk image
|
|
|
|
CLOCK=$(date -Is -d @$(expr $(stat -c %Y ${diskImage}) + 86400))
|
|
|
|
${qemu.runQemu true [
|
|
|
|
"-boot" "order=c"
|
|
|
|
"-snapshot"
|
|
|
|
"-drive" "file=${diskImage},index=0,media=disk,cache=unsafe"
|
2019-04-18 14:51:18 +08:00
|
|
|
"-rtc" "base=\\$CLOCK"
|
2019-04-15 07:12:48 +08:00
|
|
|
"-display" "none"
|
|
|
|
]} &
|
|
|
|
|
|
|
|
echo "Wait for Windows to boot"
|
|
|
|
sleep 10
|
|
|
|
${ssh "ver"}
|
|
|
|
for pkg in ${artiqPkg}/noarch/artiq*.tar.bz2 ; do
|
2019-04-18 14:51:18 +08:00
|
|
|
${scp "\\$pkg" "artiq.tar.bz2"}
|
2019-04-15 07:12:48 +08:00
|
|
|
${ssh "anaconda\\scripts\\activate ${condaEnv} && conda install artiq.tar.bz2"}
|
|
|
|
done
|
|
|
|
|
|
|
|
# Allow tests to run for 2 minutes
|
|
|
|
${ssh "shutdown -s -t ${toString testTimeout}"}
|
|
|
|
|
|
|
|
${ssh "anaconda\\scripts\\activate ${condaEnv} && ${testCommand}"}
|
|
|
|
|
|
|
|
# Abort timeouted shutdown
|
|
|
|
${ssh "shutdown -a"}
|
|
|
|
# Power off immediately
|
|
|
|
${ssh "shutdown -p -f"}
|
|
|
|
EOF
|
|
|
|
chmod a+x $out/bin/run.sh
|
|
|
|
'';
|
2019-04-14 07:54:36 +08:00
|
|
|
}
|