mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
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
This commit is contained in:
parent
abe218950c
commit
36c05d5e5b
2 changed files with 43 additions and 47 deletions
|
@ -67,59 +67,55 @@ rec {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
makeTest = testFun: complete (call testFun);
|
makeTest =
|
||||||
makeTests = testsFun: lib.mapAttrs (name: complete) (call testsFun);
|
{ testScript, makeCoverageReport ? false, ... } @ t:
|
||||||
|
|
||||||
apply = makeTest; # compatibility
|
let
|
||||||
call = f: f { inherit pkgs system; };
|
|
||||||
|
|
||||||
complete = { testScript, makeCoverageReport ? false, ... } @ t: t // rec {
|
nodes = buildVirtualNetwork (
|
||||||
|
t.nodes or (if t ? machine then { machine = t.machine; } else { }));
|
||||||
|
|
||||||
nodes = buildVirtualNetwork (
|
testScript' =
|
||||||
t.nodes or (if t ? machine then { machine = t.machine; } else { }));
|
# Call the test script with the computed nodes.
|
||||||
|
if builtins.isFunction testScript
|
||||||
|
then testScript { inherit nodes; }
|
||||||
|
else testScript;
|
||||||
|
|
||||||
testScript =
|
vlans = map (m: m.config.virtualisation.vlans) (lib.attrValues nodes);
|
||||||
# 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);
|
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
|
test = runTests 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 ]; };
|
||||||
|
|
||||||
report = releaseTools.gcovReport { coverageRuns = [ test ]; };
|
in (if makeCoverageReport then report else test) // { inherit driver test; };
|
||||||
|
|
||||||
result = if makeCoverageReport then report else test;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
runInMachine =
|
runInMachine =
|
||||||
|
@ -149,7 +145,7 @@ rec {
|
||||||
exit $?
|
exit $?
|
||||||
'';
|
'';
|
||||||
|
|
||||||
testscript = ''
|
testScript = ''
|
||||||
startAll;
|
startAll;
|
||||||
$client->waitForUnit("multi-user.target");
|
$client->waitForUnit("multi-user.target");
|
||||||
${preBuild}
|
${preBuild}
|
||||||
|
@ -162,7 +158,7 @@ rec {
|
||||||
${coreutils}/bin/mkdir $out
|
${coreutils}/bin/mkdir $out
|
||||||
${coreutils}/bin/mkdir -p vm-state-client/xchg
|
${coreutils}/bin/mkdir -p vm-state-client/xchg
|
||||||
export > vm-state-client/xchg/saved-env
|
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
|
${testDriver}/bin/nixos-test-driver ${vm.config.system.build.vm}/bin/run-*-vm
|
||||||
''; # */
|
''; # */
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ let
|
||||||
|
|
||||||
forAllSystems = pkgs.lib.genAttrs systems;
|
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"; };
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue