From 36c05d5e5b0025c9c6f62b101478e5e9f6da8d91 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 14 Apr 2014 14:23:38 +0200 Subject: [PATCH] Simplify running tests even further Now you can just say: $ nix-build '' You can still get the driver script for interactive testing: $ nix-build '' -A driver $ ./result/bin/nixos-test-driver --- nixos/lib/testing.nix | 88 +++++++++++++++++++++---------------------- nixos/release.nix | 2 +- 2 files changed, 43 insertions(+), 47 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; }; + let - complete = { testScript, makeCoverageReport ? false, ... } @ t: t // rec { + 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 testScript + then testScript { inherit nodes; } + else testScript; - testScript = - # Call the test script with the computed nodes. - if builtins.isFunction t.testScript - then t.testScript { inherit nodes; } - else t.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]; + 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"} + ''; # " - # 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; - test = runTests driver; + report = releaseTools.gcovReport { coverageRuns = [ test ]; }; - report = releaseTools.gcovReport { coverageRuns = [ test ]; }; - - result = if makeCoverageReport then report else 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"; };