From 7406a34312b7ea70a0c5b49f97dbfb48edcbcc08 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 14 Mar 2019 11:19:18 +0800 Subject: [PATCH] run KC705 tests in hacked fixed-output derivation Unlike the previous RunCommand hack, this integrates with Hydra build monitoring. --- extended-tests.py | 34 ---------------------------------- main.nix | 47 ++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 43 deletions(-) delete mode 100644 extended-tests.py diff --git a/extended-tests.py b/extended-tests.py deleted file mode 100644 index 10d039e..0000000 --- a/extended-tests.py +++ /dev/null @@ -1,34 +0,0 @@ -import json -import sys -import time -import subprocess -import os - -import artiq - - -with open(sys.argv[1], "r") as hydra_json_file: - hydra_json = json.load(hydra_json_file) - -drv = hydra_json["drvPath"] -assert drv.startswith("/nix/store/") -drv = drv[len("/nix/store/"):] -hydra_log = "/var/lib/hydra/build-logs/" + drv[:2] + "/" + drv[2:] - -with open(hydra_log, "w") as log: - def run(*args, **kwargs): - subprocess.run(args, stdout=log, stderr=log, **kwargs).check_returncode() - - run("artiq_flash", "-t", "kc705", "-V", "nist_clock") - - time.sleep(15) - - # ping: socket: Operation not permitted - #run("ping", "kc705-1", "-c10", "-w30") - - env = { - "ARTIQ_ROOT": artiq.__path__[0] + "/examples/kc705_nist_clock", - "ARTIQ_LOW_LATENCY": "1" - } - env.update(os.environ) - run("python", "-m", "unittest", "discover", "-v", "artiq.test.coredevice", env=env) diff --git a/main.nix b/main.nix index 57ae732..a02919c 100644 --- a/main.nix +++ b/main.nix @@ -17,23 +17,52 @@ let EOF echo \"5e.`cut -c1-8 <<< $REV`\" > $out/pkgs/artiq-version.nix ''; + generateTestOkHash = pkgs.runCommand "generate-test-ok-hash" { buildInputs = [ pkgs.nix ]; } + '' + TMPDIR=`mktemp -d` + cp ${generatedNix}/pkgs/artiq-version.nix $TMPDIR/passed + HASH=`nix-hash --type sha256 --base32 $TMPDIR` + echo \"$HASH\" > $out + ''; artiqpkgs = import "${generatedNix}/default.nix" { inherit pkgs; }; artiqVersion = import "${generatedNix}/pkgs/artiq-version.nix"; jobs = builtins.mapAttrs (key: value: pkgs.lib.hydraJob value) artiqpkgs; in jobs // { - generated-nix = pkgs.lib.hydraJob generatedNix; + generated-nix = pkgs.lib.hydraJob generatedNix; # used by sinara-systems channel = pkgs.releaseTools.channel rec { name = "main"; src = generatedNix; constituents = builtins.attrValues jobs; }; - extended-tests = pkgs.runCommand "extended-tests" { - propagatedBuildInputs = [ - (pkgs.python3.withPackages(ps: [ artiqpkgs.artiq artiqpkgs.artiq-board-kc705-nist_clock ])) - artiqpkgs.binutils-or1k - artiqpkgs.openocd - pkgs.iputils - ]; - } "cp ${./extended-tests.py} $out;"; + + # HACK: Abuse fixed-output derivations to escape the sandbox and run the hardware + # unit tests, all integrated in the Hydra interface. + # One major downside of this hack is the tests are only run when generateTestOkHash + # changes, i.e. when the ARTIQ version changes (and not the dependencies). + # Impure derivations, when they land in Nix/Hydra, should improve the situation. + kc705-tests = pkgs.stdenv.mkDerivation { + name = "extended-tests"; + outputHashAlgo = "sha256"; + outputHashMode = "recursive"; + outputHash = import generateTestOkHash; + buildInputs = [ + (pkgs.python3.withPackages(ps: [ artiqpkgs.artiq artiqpkgs.artiq-board-kc705-nist_clock ])) + artiqpkgs.binutils-or1k + pkgs.iputils + ]; + phases = [ "buildPhase" ]; + buildPhase = + '' + artiq_flash -t kc705 -H rpi + sleep 15 + # ping: socket: Operation not permitted + #ping kc705-1 -c10 -w30 + export ARTIQ_ROOT=`python -c "import artiq; print(artiq.__path__[0])"`/examples/kc705_nist_clock", + export ARTIQ_LOW_LATENCY=1 + python -m unittest discover -v artiq.test.coredevice + mkdir $out + cp ${generatedNix}/pkgs/artiq-version.nix $out/passed + ''; + }; }