2019-04-08 23:41:05 +08:00
|
|
|
{ pkgs ? import <nixpkgs> {},
|
|
|
|
diskImage ? "/opt/windows/c.img",
|
|
|
|
qemuMem ? "2G",
|
2019-04-09 00:12:44 +08:00
|
|
|
testTimeout ? 120,
|
2019-04-13 21:50:58 +08:00
|
|
|
artiqPkg ? import ../conda-artiq.nix { inherit pkgs; },
|
2019-04-08 23:41:05 +08:00
|
|
|
}:
|
|
|
|
|
|
|
|
with pkgs;
|
|
|
|
|
|
|
|
let
|
|
|
|
qemu = qemu_kvm;
|
|
|
|
runQemu = extraArgs:
|
|
|
|
let
|
|
|
|
args = [
|
|
|
|
"-enable-kvm"
|
|
|
|
"-m" qemuMem
|
|
|
|
"-display" "none"
|
|
|
|
"-bios" "${OVMF.fd}/FV/OVMF.fd"
|
2019-04-10 03:01:33 +08:00
|
|
|
"-netdev" "user,id=n1,restrict=on,hostfwd=tcp::2022-:22" "-device" "e1000,netdev=n1"
|
2019-04-08 23:41:05 +08:00
|
|
|
];
|
|
|
|
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}\""
|
2019-04-11 21:26:44 +08:00
|
|
|
${sshpass}/bin/sshpass -p${sshPassword} -- \
|
|
|
|
${openssh}/bin/ssh -np 2022 ${sshOpts} \
|
2019-04-08 23:41:05 +08:00
|
|
|
${sshUser}@localhost \
|
|
|
|
"${cmd}"
|
|
|
|
'';
|
|
|
|
scp = src: target: ''
|
|
|
|
echo "Copy ${src} to ${target}"
|
2019-04-11 21:26:44 +08:00
|
|
|
${sshpass}/bin/sshpass -p${sshPassword} -- \
|
|
|
|
${openssh}/bin/scp -P 2022 ${sshOpts} \
|
2019-04-08 23:41:05 +08:00
|
|
|
"${src}" "${sshUser}@localhost:${target}"
|
|
|
|
'';
|
2019-04-11 22:22:17 +08:00
|
|
|
condaEnv = "artiq-env";
|
2019-04-10 02:41:46 +08:00
|
|
|
installCondaPkg = pkg: ''
|
|
|
|
F="$(basename ${pkg})"
|
|
|
|
${scp pkg "$F"}
|
2019-04-11 22:22:17 +08:00
|
|
|
${ssh "miniconda\\Scripts\\conda install -y -n ${condaEnv} $F"}
|
2019-04-10 02:41:46 +08:00
|
|
|
${ssh "del $F"}
|
2019-04-08 23:41:05 +08:00
|
|
|
'';
|
2019-04-13 21:50:58 +08:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "windows-test-conda-artiq";
|
|
|
|
src = ./.;
|
|
|
|
dontBuild = true;
|
|
|
|
installPhase = ''
|
|
|
|
mkdir $out
|
|
|
|
'';
|
|
|
|
doCheck = true;
|
|
|
|
checkInputs = [ qemu sshpass openssh ];
|
|
|
|
checkPhase = ''
|
|
|
|
# +1 day from last modification of the disk image
|
|
|
|
CLOCK=$(date -Is -d @$(expr $(stat -c %Y ${diskImage}) + 86400))
|
|
|
|
${runQemu [
|
|
|
|
"-boot" "order=c"
|
|
|
|
"-snapshot"
|
|
|
|
"-drive" "file=${diskImage},index=0,media=disk,cache=unsafe"
|
|
|
|
"-rtc" "base=$CLOCK"
|
|
|
|
]} &
|
2019-04-10 03:01:51 +08:00
|
|
|
|
2019-04-13 21:50:58 +08:00
|
|
|
echo "Wait for Windows to boot"
|
|
|
|
sleep 10
|
|
|
|
${ssh "ver"}
|
|
|
|
for pkg in ${artiqPkg}/noarch/*.tar.bz2 ; do
|
|
|
|
${installCondaPkg "$pkg"}
|
|
|
|
done
|
2019-04-10 03:01:51 +08:00
|
|
|
|
2019-04-13 21:50:58 +08:00
|
|
|
# Allow tests to run for 2 minutes
|
|
|
|
${ssh "shutdown -s -t ${toString testTimeout}"}
|
2019-04-10 03:01:51 +08:00
|
|
|
|
2019-04-13 21:50:58 +08:00
|
|
|
${ssh "miniconda\\scripts\\activate ${condaEnv} && miniconda\\envs\\${condaEnv}\\python -m unittest discover -v artiq.test"}
|
2019-04-10 03:01:51 +08:00
|
|
|
|
2019-04-13 21:50:58 +08:00
|
|
|
# Abort timeouted shutdown
|
|
|
|
${ssh "shutdown -a"}
|
|
|
|
# Power off immediately
|
|
|
|
${ssh "shutdown -p -f"}
|
|
|
|
'';
|
|
|
|
}
|