diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-04-14 14:23:38 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-04-14 14:23:38 +0200 |
commit | 36c05d5e5b0025c9c6f62b101478e5e9f6da8d91 (patch) | |
tree | 50c8aad7100545e31850c12d72e780f82a4b3f37 | |
parent | abe218950c779fd1c98034356d3b324d66a0d30a (diff) | |
download | nixlib-36c05d5e5b0025c9c6f62b101478e5e9f6da8d91.tar nixlib-36c05d5e5b0025c9c6f62b101478e5e9f6da8d91.tar.gz nixlib-36c05d5e5b0025c9c6f62b101478e5e9f6da8d91.tar.bz2 nixlib-36c05d5e5b0025c9c6f62b101478e5e9f6da8d91.tar.lz nixlib-36c05d5e5b0025c9c6f62b101478e5e9f6da8d91.tar.xz nixlib-36c05d5e5b0025c9c6f62b101478e5e9f6da8d91.tar.zst nixlib-36c05d5e5b0025c9c6f62b101478e5e9f6da8d91.zip |
Simplify running tests even further
Now you can just say: $ nix-build '<nixos/tests/login.nix>' You can still get the driver script for interactive testing: $ nix-build '<nixos/tests/login.nix>' -A driver $ ./result/bin/nixos-test-driver
-rw-r--r-- | nixos/lib/testing.nix | 94 | ||||
-rw-r--r-- | nixos/release.nix | 2 |
2 files changed, 46 insertions, 50 deletions
diff --git a/nixos/lib/testing.nix b/nixos/lib/testing.nix index 02d865895fbb..8d17958b9d2f 100644 --- a/nixos/lib/testing.nix +++ b/nixos/lib/testing.nix @@ -67,59 +67,55 @@ rec { }; - makeTest = testFun: complete (call testFun); - makeTests = testsFun: lib.mapAttrs (name: complete) (call testsFun); + makeTest = + { testScript, makeCoverageReport ? false, ... } @ t: - apply = makeTest; # compatibility - call = f: f { inherit pkgs system; }; - - complete = { testScript, makeCoverageReport ? false, ... } @ t: t // rec { + let - nodes = buildVirtualNetwork ( - t.nodes or (if t ? machine then { machine = t.machine; } else { })); + nodes = buildVirtualNetwork ( + t.nodes or (if t ? machine then { machine = t.machine; } else { })); - testScript = - # Call the test script with the computed nodes. - if builtins.isFunction t.testScript - then t.testScript { inherit nodes; } - else t.testScript; + testScript' = + # Call the test script with the computed nodes. + if builtins.isFunction testScript + then testScript { inherit nodes; } + else testScript; - vlans = map (m: m.config.virtualisation.vlans) (lib.attrValues nodes); + vlans = map (m: m.config.virtualisation.vlans) (lib.attrValues nodes); - vms = map (m: m.config.system.build.vm) (lib.attrValues nodes); + vms = map (m: m.config.system.build.vm) (lib.attrValues nodes); - # Generate onvenience wrappers for running the test driver - # interactively with the specified network, and for starting the - # VMs from the command line. - driver = runCommand "nixos-test-driver" - { buildInputs = [ makeWrapper]; - inherit testScript; - preferLocalBuild = true; - } - '' - mkdir -p $out/bin - echo "$testScript" > $out/test-script - ln -s ${testDriver}/bin/nixos-test-driver $out/bin/ - vms="$(for i in ${toString vms}; do echo $i/bin/run-*-vm; done)" - wrapProgram $out/bin/nixos-test-driver \ - --add-flags "$vms" \ - --run "testScript=\"\$(cat $out/test-script)\"" \ - --set testScript '"$testScript"' \ - --set VLANS '"${toString vlans}"' - ln -s ${testDriver}/bin/nixos-test-driver $out/bin/nixos-run-vms - wrapProgram $out/bin/nixos-run-vms \ - --add-flags "$vms" \ - --set tests '"startAll; joinAll;"' \ - --set VLANS '"${toString vlans}"' \ - ${lib.optionalString (builtins.length vms == 1) "--set USE_SERIAL 1"} - ''; # " - - test = runTests driver; - - report = releaseTools.gcovReport { coverageRuns = [ test ]; }; - - result = if makeCoverageReport then report else test; - }; + # Generate onvenience wrappers for running the test driver + # interactively with the specified network, and for starting the + # VMs from the command line. + driver = runCommand "nixos-test-driver" + { buildInputs = [ makeWrapper]; + testScript = testScript'; + preferLocalBuild = true; + } + '' + mkdir -p $out/bin + echo "$testScript" > $out/test-script + ln -s ${testDriver}/bin/nixos-test-driver $out/bin/ + vms="$(for i in ${toString vms}; do echo $i/bin/run-*-vm; done)" + wrapProgram $out/bin/nixos-test-driver \ + --add-flags "$vms" \ + --run "testScript=\"\$(cat $out/test-script)\"" \ + --set testScript '"$testScript"' \ + --set VLANS '"${toString vlans}"' + ln -s ${testDriver}/bin/nixos-test-driver $out/bin/nixos-run-vms + wrapProgram $out/bin/nixos-run-vms \ + --add-flags "$vms" \ + --set tests '"startAll; joinAll;"' \ + --set VLANS '"${toString vlans}"' \ + ${lib.optionalString (builtins.length vms == 1) "--set USE_SERIAL 1"} + ''; # " + + test = runTests driver; + + report = releaseTools.gcovReport { coverageRuns = [ test ]; }; + + in (if makeCoverageReport then report else test) // { inherit driver test; }; runInMachine = @@ -149,7 +145,7 @@ rec { exit $? ''; - testscript = '' + testScript = '' startAll; $client->waitForUnit("multi-user.target"); ${preBuild} @@ -162,7 +158,7 @@ rec { ${coreutils}/bin/mkdir $out ${coreutils}/bin/mkdir -p vm-state-client/xchg export > vm-state-client/xchg/saved-env - export tests='${testscript}' + export tests='${testScript}' ${testDriver}/bin/nixos-test-driver ${vm.config.system.build.vm}/bin/run-*-vm ''; # */ diff --git a/nixos/release.nix b/nixos/release.nix index 7465488ae167..45c37570c1ba 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -14,7 +14,7 @@ let forAllSystems = pkgs.lib.genAttrs systems; - callTest = fn: args: forAllSystems (system: (import fn ({ inherit system; } // args)).result); + callTest = fn: args: forAllSystems (system: import fn ({ inherit system; } // args)); pkgs = import nixpkgs { system = "x86_64-linux"; }; |