From 577966e11d7b8e9570e1bf8b505ceb81f088ca1d Mon Sep 17 00:00:00 2001 From: Stephan Maka Date: Mon, 8 Apr 2019 17:41:05 +0200 Subject: [PATCH] add windows image test runner --- artiq/windows/README.md | 11 +++++++ artiq/windows/default.nix | 69 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 artiq/windows/default.nix diff --git a/artiq/windows/README.md b/artiq/windows/README.md index 1159f07..70ca743 100644 --- a/artiq/windows/README.md +++ b/artiq/windows/README.md @@ -6,3 +6,14 @@ result/bin/networked-installer.sh ``` Follow the instructions. + +Then press **return** to automatically complete the installation via SSH. The virtual machine will be shut down when the process is complete. + +Move the image `c.img` to one of Nix' `extra-sandbox-paths` (`nix.sandboxPaths` on NixOS). + + +# Running the tests + +```shell +nix-build --arg diskImage "\"…/c.img\"" +``` diff --git a/artiq/windows/default.nix b/artiq/windows/default.nix new file mode 100644 index 0000000..d1a8b1b --- /dev/null +++ b/artiq/windows/default.nix @@ -0,0 +1,69 @@ +{ pkgs ? import {}, + diskImage ? "/opt/windows/c.img", + qemuMem ? "2G", + artiqPkg ? (pkgs.fetchurl { + url = "https://nixbld.m-labs.hk/build/2316/download/1/artiq-5e.b8e2b82a-0.tar.bz2"; + sha256 = "0gisv3a17rnwavsifpz4cfnqvlssv37pysi2qx41k67rmcpqcs98"; + }), +}: + +with pkgs; + +let + qemu = qemu_kvm; + runQemu = extraArgs: + let + args = [ + "-enable-kvm" + "-m" qemuMem + "-display" "none" + "-bios" "${OVMF.fd}/FV/OVMF.fd" + "-netdev" "user,id=n1,hostfwd=tcp::2022-:22" "-device" "e1000,netdev=n1" + ]; + argStr = builtins.concatStringsSep " " (args ++ extraArgs); + in "qemu-system-x86_64 ${argStr}"; + sshUser = "user"; + sshPassword = "user"; + sshOpts = "-o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=$TMPDIR/known_hosts"; + ssh = cmd: '' + echo "ssh windows \"${cmd}\"" + sshpass -p${sshPassword} -- \ + ssh -np 2022 ${sshOpts} \ + ${sshUser}@localhost \ + "${cmd}" + ''; + scp = src: target: '' + echo "Copy ${src} to ${target}" + sshpass -p${sshPassword} -- \ + scp -P 2022 ${sshOpts} \ + "${src}" "${sshUser}@localhost:${target}" + ''; + installCondaPkgs = condaPkgs: + builtins.concatStringsSep "\n" (map (pkg: '' + F="$(basename ${pkg})" + ${scp pkg "$F"} + ${ssh "miniconda\\Scripts\\conda install $F"} + ${ssh "del $F"} + '') condaPkgs); +in +stdenv.mkDerivation { + name = "windows-test"; + src = ./.; + buildInputs = [ qemu sshpass openssh ]; + buildPhase = '' + ${runQemu [ + "-boot" "order=c" + "-snapshot" + "-drive" "file=${diskImage},index=0,media=disk,cache=unsafe" + ]} & + echo "Wait for Windows to boot" + sleep 10 + ${ssh "ver"} + ${installCondaPkgs [artiqPkg]} + ${ssh "miniconda\\scripts\\activate && miniconda\\python -m unittest discover -v artiq.test"} + ${ssh "shutdown /p /f"} + ''; + installPhase = '' + echo Done + ''; +}