From d7917b4b5bbeac0e8a05a74a37acf9a1d52dc5cd Mon Sep 17 00:00:00 2001 From: Stephan Maka Date: Thu, 18 Apr 2019 15:54:06 +0200 Subject: [PATCH] windows tests: rename default.nix to run-test.nix default.nix will now run the tests outside of hydra. --- artiq/windows/README.md | 4 +-- artiq/windows/default.nix | 56 ++++++---------------------------- artiq/windows/run-test.nix | 62 ++++++++++++++++++++++++++++++++++++++ main.nix | 2 +- 4 files changed, 75 insertions(+), 49 deletions(-) create mode 100644 artiq/windows/run-test.nix diff --git a/artiq/windows/README.md b/artiq/windows/README.md index 70ca743..147ac49 100644 --- a/artiq/windows/README.md +++ b/artiq/windows/README.md @@ -12,8 +12,8 @@ Then press **return** to automatically complete the installation via SSH. The vi Move the image `c.img` to one of Nix' `extra-sandbox-paths` (`nix.sandboxPaths` on NixOS). -# Running the tests +# Running the tests manually ```shell -nix-build --arg diskImage "\"…/c.img\"" +nix-build --pure --arg diskImage "\"…/c.img\"" -I artiqSrc=…/artiq ``` diff --git a/artiq/windows/default.nix b/artiq/windows/default.nix index 266b5af..52b3e7d 100644 --- a/artiq/windows/default.nix +++ b/artiq/windows/default.nix @@ -2,61 +2,25 @@ diskImage ? "/opt/windows/c.img", qemuMem ? "2G", testTimeout ? 180, - 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"; + windowsRunner = overrides: + import ./run-test.nix { + inherit pkgs diskImage qemuMem testTimeout; + }; in stdenv.mkDerivation { - name = "windows-test-runner"; + name = "windows-test"; src = ./.; - propagatedBuildInputs = qemu.inputs; - 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" - "-rtc" "base=\\$CLOCK" - "-display" "none" - ]} & - - echo "Wait for Windows to boot" - sleep 10 - ${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 - - # 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 + phases = [ "installPhase" "checkPhase" ]; + installPhase = "touch $out"; + doCheck = true; + checkPhase = '' + ${windowsRunner { testCommand = "set ARTIQ_ROOT=%cd%\\anaconda\\envs\\artiq-env\\Lib\\site-packages\\artiq\\examples\\kc705_nist_clock&&set ARTIQ_LOW_LATENCY=1&&python -m unittest discover -v artiq.test"; }}/bin/run.sh ''; } diff --git a/artiq/windows/run-test.nix b/artiq/windows/run-test.nix new file mode 100644 index 0000000..266b5af --- /dev/null +++ b/artiq/windows/run-test.nix @@ -0,0 +1,62 @@ +{ pkgs ? import {}, + diskImage ? "/opt/windows/c.img", + qemuMem ? "2G", + testTimeout ? 180, + 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"; +in + +stdenv.mkDerivation { + name = "windows-test-runner"; + src = ./.; + + propagatedBuildInputs = qemu.inputs; + 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" + "-rtc" "base=\\$CLOCK" + "-display" "none" + ]} & + + echo "Wait for Windows to boot" + sleep 10 + ${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 + + # 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 + ''; +} diff --git a/main.nix b/main.nix index 41e3119..14516b1 100644 --- a/main.nix +++ b/main.nix @@ -31,7 +31,7 @@ let artiqpkgs = import "${generatedNix}/default.nix" { inherit pkgs; }; artiqVersion = import "${generatedNix}/pkgs/artiq-version.nix"; windowsRunner = overrides: - import "${generatedNix}/windows" ({ + import "${generatedNix}/windows/run-test.nix" ({ inherit pkgs; artiqPkg = artiqpkgs.conda-artiq; } // overrides);