Make it easier to run the tests

You can now run a test in the nixos/tests directory directly using
nix-build, e.g.

  $ nix-build '<nixos/tests/login.nix>' -A test

This gets rid of having to add the test to nixos/tests/default.nix.
(Of course, you still need to add it to nixos/release.nix if you want
Hydra to run the test.)
This commit is contained in:
Eelco Dolstra 2014-04-14 14:02:44 +02:00
parent 753639e548
commit abe218950c
37 changed files with 132 additions and 175 deletions

View File

@ -73,7 +73,7 @@ rec {
apply = makeTest; # compatibility apply = makeTest; # compatibility
call = f: f { inherit pkgs system; }; call = f: f { inherit pkgs system; };
complete = { testScript, ... } @ t: t // rec { complete = { testScript, makeCoverageReport ? false, ... } @ t: t // rec {
nodes = buildVirtualNetwork ( nodes = buildVirtualNetwork (
t.nodes or (if t ? machine then { machine = t.machine; } else { })); t.nodes or (if t ? machine then { machine = t.machine; } else { }));
@ -117,6 +117,8 @@ rec {
test = runTests driver; test = runTests driver;
report = releaseTools.gcovReport { coverageRuns = [ test ]; }; report = releaseTools.gcovReport { coverageRuns = [ test ]; };
result = if makeCoverageReport then report else test;
}; };

View File

@ -14,6 +14,8 @@ let
forAllSystems = pkgs.lib.genAttrs systems; forAllSystems = pkgs.lib.genAttrs systems;
callTest = fn: args: forAllSystems (system: (import fn ({ inherit system; } // args)).result);
pkgs = import nixpkgs { system = "x86_64-linux"; }; pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib; lib = pkgs.lib;
@ -207,14 +209,42 @@ in rec {
*/ */
# Run the tests in ./tests/default.nix for each platform. You can # Run the tests for each platform. You can run a test by doing
# run a test by doing e.g. "nix-build -A tests.login.x86_64-linux". # e.g. nix-build -A tests.login.x86_64-linux, or equivalently,
tests = # nix-build tests/login.nix -A result.
with lib; tests.avahi = callTest tests/avahi.nix {};
let tests.bittorrent = callTest tests/bittorrent.nix {};
testsFor = system: tests.containers = callTest tests/containers.nix {};
mapAttrsRecursiveCond (x: !x ? test) tests.firefox = callTest tests/firefox.nix {};
(n: v: listToAttrs [(nameValuePair system (if v.makeCoverageReport or false then v.report else v.test))]) tests.firewall = callTest tests/firewall.nix {};
(import ./tests { inherit nixpkgs system; }); tests.gnome3 = callTest tests/gnome3.nix {};
in fold recursiveUpdate {} (map testsFor systems); tests.installer.grub1 = forAllSystems (system: (import tests/installer.nix { inherit system; }).grub1.test);
tests.installer.lvm = forAllSystems (system: (import tests/installer.nix { inherit system; }).lvm.test);
tests.installer.rebuildCD = forAllSystems (system: (import tests/installer.nix { inherit system; }).rebuildCD.test);
tests.installer.separateBoot = forAllSystems (system: (import tests/installer.nix { inherit system; }).separateBoot.test);
tests.installer.simple = forAllSystems (system: (import tests/installer.nix { inherit system; }).simple.test);
tests.ipv6 = callTest tests/ipv6.nix {};
tests.jenkins = callTest tests/jenkins.nix {};
tests.kde4 = callTest tests/kde4.nix {};
tests.latestKernel.login = callTest tests/login.nix { latestKernel = true; };
tests.login = callTest tests/login.nix {};
tests.logstash = callTest tests/logstash.nix {};
tests.misc = callTest tests/misc.nix {};
tests.mumble = callTest tests/mumble.nix {};
tests.munin = callTest tests/munin.nix {};
tests.mysql = callTest tests/mysql.nix {};
tests.mysqlReplication = callTest tests/mysql-replication.nix {};
tests.nat = callTest tests/nat.nix {};
tests.nfs3 = callTest tests/nfs.nix { version = 3; };
tests.openssh = callTest tests/openssh.nix {};
tests.printing = callTest tests/printing.nix {};
tests.proxy = callTest tests/proxy.nix {};
tests.quake3 = callTest tests/quake3.nix {};
tests.rabbitmq = callTest tests/rabbitmq.nix {};
tests.runInMachine = callTest tests/run-in-machine.nix {};
tests.simple = callTest tests/simple.nix {};
tests.tomcat = callTest tests/tomcat.nix {};
tests.udisks = callTest tests/udisks.nix {};
tests.xfce = callTest tests/xfce.nix {};
} }

View File

@ -1,8 +1,7 @@
{ pkgs, ... }: # Test whether `avahi-daemon' and `libnss-mdns' work as expected.
with pkgs; import ./make-test.nix {
{
nodes = { nodes = {
one = one =
{ config, pkgs, ... }: { { config, pkgs, ... }: {
@ -17,7 +16,6 @@ with pkgs;
}; };
}; };
# Test whether `avahi-daemon' and `libnss-mdns' work as expected.
testScript = testScript =
'' startAll; '' startAll;

View File

@ -6,7 +6,7 @@
# which only works if the first client successfully uses the UPnP-IGD # which only works if the first client successfully uses the UPnP-IGD
# protocol to poke a hole in the NAT. # protocol to poke a hole in the NAT.
{ pkgs, ... }: import ./make-test.nix ({ pkgs, ... }:
let let
@ -108,4 +108,4 @@ in
$client2->succeed("cmp /tmp/test.tar.bz2 ${file}"); $client2->succeed("cmp /tmp/test.tar.bz2 ${file}");
''; '';
} })

View File

@ -1,8 +1,6 @@
# Test for NixOS' container support. # Test for NixOS' container support.
{ pkgs, ... }: import ./make-test.nix {
{
machine = machine =
{ config, pkgs, ... }: { config, pkgs, ... }:

View File

@ -1,46 +0,0 @@
{ nixpkgs ? <nixpkgs>
, system ? builtins.currentSystem
, minimal ? false
}:
with import ../lib/testing.nix { inherit system minimal; };
{
avahi = makeTest (import ./avahi.nix);
bittorrent = makeTest (import ./bittorrent.nix);
containers = makeTest (import ./containers.nix);
firefox = makeTest (import ./firefox.nix);
firewall = makeTest (import ./firewall.nix);
installer = makeTests (import ./installer.nix);
efi-installer = makeTests (import ./efi-installer.nix);
gnome3 = makeTest (import ./gnome3.nix);
ipv6 = makeTest (import ./ipv6.nix);
jenkins = makeTest (import ./jenkins.nix);
kde4 = makeTest (import ./kde4.nix);
#kexec = makeTest (import ./kexec.nix);
login = makeTest (import ./login.nix {});
logstash = makeTest (import ./logstash.nix);
latestKernel.login = makeTest (import ./login.nix ({ config, pkgs, ... }: { boot.kernelPackages = pkgs.linuxPackages_latest; }));
misc = makeTest (import ./misc.nix);
#mpich = makeTest (import ./mpich.nix);
mysql = makeTest (import ./mysql.nix);
mysql_replication = makeTest (import ./mysql-replication.nix);
munin = makeTest (import ./munin.nix);
mumble = makeTest (import ./mumble.nix);
nat = makeTest (import ./nat.nix);
nfs3 = makeTest (import ./nfs.nix { version = 3; });
#nfs4 = makeTest (import ./nfs.nix { version = 4; });
openssh = makeTest (import ./openssh.nix);
#partition = makeTest (import ./partition.nix);
printing = makeTest (import ./printing.nix);
proxy = makeTest (import ./proxy.nix);
quake3 = makeTest (import ./quake3.nix);
rabbitmq = makeTest (import ./rabbitmq.nix);
simple = makeTest (import ./simple.nix);
#subversion = makeTest (import ./subversion.nix);
tomcat = makeTest (import ./tomcat.nix);
udisks = makeTest (import ./udisks.nix);
#trac = makeTest (import ./trac.nix);
xfce = makeTest (import ./xfce.nix);
runInMachine.test = import ./run-in-machine.nix { inherit system; };
}

View File

@ -1,6 +1,4 @@
{ pkgs, ... }: import ./make-test.nix ({ pkgs, ... }: {
{
machine = machine =
{ config, pkgs, ... }: { config, pkgs, ... }:
@ -18,4 +16,4 @@
$machine->screenshot("screen"); $machine->screenshot("screen");
''; '';
} })

View File

@ -1,8 +1,6 @@
# Test the firewall module. # Test the firewall module.
{ pkgs, ... }: import ./make-test.nix {
{
nodes = nodes =
{ walled = { walled =

View File

@ -1,6 +1,4 @@
{ pkgs, ... }: import ./make-test.nix {
{
machine = machine =
{ config, pkgs, ... }: { config, pkgs, ... }:

View File

@ -1,7 +1,8 @@
{ pkgs, system, ... }: { system ? builtins.currentSystem }:
with pkgs.lib; with import ../lib/testing.nix { inherit system; };
with import ../lib/qemu-flags.nix; with import ../lib/qemu-flags.nix;
with pkgs.lib;
let let
@ -99,7 +100,7 @@ let
my $machine = createMachine({ hda => "harddisk", my $machine = createMachine({ hda => "harddisk",
hdaInterface => "${iface}", hdaInterface => "${iface}",
cdrom => glob("${iso}/iso/*.iso"), cdrom => glob("${iso}/iso/*.iso"),
qemuFlags => '${optionalString testChannel (toString (qemuNICFlags 1 1 2))} ${optionalString (pkgs.stdenv.system == "x86_64-linux") "-cpu kvm64"}'}); qemuFlags => '${optionalString testChannel (toString (qemuNICFlags 1 1 2))} ${optionalString (iso.system == "x86_64-linux") "-cpu kvm64"}'});
$machine->start; $machine->start;
${optionalString testChannel '' ${optionalString testChannel ''
@ -190,13 +191,15 @@ let
''; '';
makeTest = { createPartitions, fileSystems, testChannel ? false, grubVersion ? 2, grubDevice ? "/dev/vda" }: makeInstallerTest =
{ inherit iso; { createPartitions, fileSystems, testChannel ? false, grubVersion ? 2, grubDevice ? "/dev/vda" }:
makeTest ({ ... }: {
inherit iso;
nodes = if testChannel then { inherit webserver; } else { }; nodes = if testChannel then { inherit webserver; } else { };
testScript = testScriptFun { testScript = testScriptFun {
inherit createPartitions fileSystems testChannel grubVersion grubDevice; inherit createPartitions fileSystems testChannel grubVersion grubDevice;
}; };
}; });
in { in {
@ -206,7 +209,7 @@ in {
# The (almost) simplest partitioning scheme: a swap partition and # The (almost) simplest partitioning scheme: a swap partition and
# one big filesystem partition. # one big filesystem partition.
simple = makeTest simple = makeInstallerTest
{ createPartitions = { createPartitions =
'' ''
$machine->succeed( $machine->succeed(
@ -225,7 +228,7 @@ in {
}; };
# Same as the previous, but now with a separate /boot partition. # Same as the previous, but now with a separate /boot partition.
separateBoot = makeTest separateBoot = makeInstallerTest
{ createPartitions = { createPartitions =
'' ''
$machine->succeed( $machine->succeed(
@ -248,7 +251,7 @@ in {
# Create two physical LVM partitions combined into one volume group # Create two physical LVM partitions combined into one volume group
# that contains the logical swap and root partitions. # that contains the logical swap and root partitions.
lvm = makeTest lvm = makeInstallerTest
{ createPartitions = { createPartitions =
'' ''
$machine->succeed( $machine->succeed(
@ -271,8 +274,7 @@ in {
fileSystems = rootFS; fileSystems = rootFS;
}; };
/* swraid = makeInstallerTest
swraid = makeTest
{ createPartitions = { createPartitions =
'' ''
$machine->succeed( $machine->succeed(
@ -304,10 +306,9 @@ in {
''; '';
fileSystems = rootFS + bootFS; fileSystems = rootFS + bootFS;
}; };
*/
# Test a basic install using GRUB 1. # Test a basic install using GRUB 1.
grub1 = makeTest grub1 = makeInstallerTest
{ createPartitions = { createPartitions =
'' ''
$machine->succeed( $machine->succeed(
@ -328,7 +329,7 @@ in {
}; };
# Rebuild the CD configuration with a little modification. # Rebuild the CD configuration with a little modification.
rebuildCD = rebuildCD = makeTest ({ ... }:
{ inherit iso; { inherit iso;
nodes = { }; nodes = { };
testScript = testScript =
@ -352,5 +353,5 @@ in {
$machine->shutdown; $machine->shutdown;
''; '';
}; });
} }

View File

@ -1,9 +1,7 @@
# Test of IPv6 functionality in NixOS, including whether router # Test of IPv6 functionality in NixOS, including whether router
# solicication/advertisement using radvd works. # solicication/advertisement using radvd works.
{ pkgs, ... }: import ./make-test.nix {
{
nodes = nodes =
{ client = { config, pkgs, ... }: { }; { client = { config, pkgs, ... }: { };

View File

@ -2,9 +2,9 @@
# 1. jenkins service starts on master node # 1. jenkins service starts on master node
# 2. jenkins user can be extended on both master and slave # 2. jenkins user can be extended on both master and slave
# 3. jenkins service not started on slave node # 3. jenkins service not started on slave node
{ pkgs, ... }:
{ import ./make-test.nix {
nodes = { nodes = {
master = master =

View File

@ -1,6 +1,4 @@
{ pkgs, ... }: import ./make-test.nix ({ pkgs, ... }: {
{
machine = machine =
{ config, pkgs, ... }: { config, pkgs, ... }:
@ -64,4 +62,4 @@
$machine->screenshot("screen"); $machine->screenshot("screen");
''; '';
} })

View File

@ -1,8 +1,6 @@
# Test whether fast reboots via kexec work. # Test whether fast reboots via kexec work.
{ pkgs, ... }: import ./make-test.nix {
{
machine = { config, pkgs, ... }: machine = { config, pkgs, ... }:
{ virtualisation.vlans = [ ]; }; { virtualisation.vlans = [ ]; };

View File

@ -1,8 +1,11 @@
config: { pkgs, ... }: import ./make-test.nix ({ pkgs, latestKernel ? false, ... }:
{ {
machine = config; machine =
{ config, pkgs, lib, ... }:
{ boot.kernelPackages = lib.mkIf latestKernel pkgs.linuxPackages_latest;
};
testScript = testScript =
'' ''
@ -58,4 +61,4 @@ config: { pkgs, ... }:
}; };
''; '';
} })

View File

@ -1,9 +1,8 @@
{ pkgs, ... }: # This test runs logstash and checks if messages flows and
# elasticsearch is started.
# This test runs logstash and checks if messages flows and elasticsearch is import ./make-test.nix {
# started
{
nodes = { nodes = {
one = one =
{ config, pkgs, ... }: { config, pkgs, ... }:
@ -28,10 +27,10 @@
}; };
}; };
}; };
testScript = '' testScript = ''
startAll; startAll;
$one->waitForUnit("logstash.service"); $one->waitForUnit("logstash.service");
$one->waitUntilSucceeds("journalctl -n 20 _SYSTEMD_UNIT=logstash.service | grep flowers"); $one->waitUntilSucceeds("journalctl -n 20 _SYSTEMD_UNIT=logstash.service | grep flowers");
$one->fail("journalctl -n 20 _SYSTEMD_UNIT=logstash.service | grep dragons"); $one->fail("journalctl -n 20 _SYSTEMD_UNIT=logstash.service | grep dragons");

View File

@ -1,8 +1,6 @@
# Miscellaneous small tests that don't warrant their own VM run. # Miscellaneous small tests that don't warrant their own VM run.
{ pkgs, ... }: import ./make-test.nix {
{
machine = machine =
{ config, pkgs, ... }: { config, pkgs, ... }:

View File

@ -1,10 +1,6 @@
# Simple example to showcase distributed tests using NixOS VMs. # Simple example to showcase distributed tests using NixOS VMs.
{ pkgs, ... }: import ./make-test.nix {
with pkgs;
{
nodes = { nodes = {
master = master =
{ config, pkgs, ... }: { { config, pkgs, ... }: {

View File

@ -1,4 +1,4 @@
{ pkgs, ... }: import ./make-test.nix (
let let
client = { config, pkgs, ... }: { client = { config, pkgs, ... }: {
@ -52,4 +52,4 @@ in
$client1->screenshot("screen1"); $client1->screenshot("screen1");
$client2->screenshot("screen2"); $client2->screenshot("screen2");
''; '';
} })

View File

@ -1,13 +1,12 @@
{ pkgs, ... }:
# This test runs basic munin setup with node and cron job running on the same # This test runs basic munin setup with node and cron job running on the same
# machine. # machine.
{ import ./make-test.nix {
nodes = {
nodes = {
one = one =
{ config, pkgs, ... }: { config, pkgs, ... }:
{ {
services = { services = {
munin-node.enable = true; munin-node.enable = true;
munin-cron = { munin-cron = {
@ -20,10 +19,10 @@
}; };
}; };
}; };
testScript = '' testScript = ''
startAll; startAll;
$one->waitForUnit("munin-node.service"); $one->waitForUnit("munin-node.service");
$one->waitForFile("/var/lib/munin/one/one-uptime-uptime-g.rrd"); $one->waitForFile("/var/lib/munin/one/one-uptime-uptime-g.rrd");
$one->waitForFile("/var/www/munin/one/index.html"); $one->waitForFile("/var/www/munin/one/index.html");

View File

@ -1,9 +1,10 @@
{ pkgs, ... }: import ./make-test.nix (
let let
replicateUser = "replicate"; replicateUser = "replicate";
replicatePassword = "secret"; replicatePassword = "secret";
in in
{ {
nodes = { nodes = {
master = master =
@ -58,4 +59,4 @@ in
$slave2->sleep(100); # Hopefully this is long enough!! $slave2->sleep(100); # Hopefully this is long enough!!
$slave2->succeed("echo 'use testdb; select * from tests' | mysql -u root -N | grep 4"); $slave2->succeed("echo 'use testdb; select * from tests' | mysql -u root -N | grep 4");
''; '';
} })

View File

@ -1,6 +1,5 @@
{ pkgs, ... }: import ./make-test.nix {
{
nodes = { nodes = {
master = master =
{ pkgs, config, ... }: { pkgs, config, ... }:

View File

@ -4,9 +4,7 @@
# router connected to both that performs Network Address Translation # router connected to both that performs Network Address Translation
# for the client. # for the client.
{ pkgs, ... }: import ./make-test.nix {
{
nodes = nodes =
{ client = { client =

View File

@ -1,6 +1,4 @@
{ version }: import ./make-test.nix ({ version, ... }:
{ pkgs, ... }:
let let
@ -84,4 +82,4 @@ in
die "shutdown took too long ($duration seconds)" if $duration > 30; die "shutdown took too long ($duration seconds)" if $duration > 30;
''; '';
} })

View File

@ -1,6 +1,5 @@
{ pkgs, ... }: import ./make-test.nix ({ pkgs, ... }: {
{
nodes = { nodes = {
server = server =
@ -35,4 +34,4 @@
$client->succeed("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no server 'echo hello world' >&2"); $client->succeed("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no server 'echo hello world' >&2");
$client->succeed("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no server 'ulimit -l' | grep 1024"); $client->succeed("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no server 'ulimit -l' | grep 1024");
''; '';
} })

View File

@ -1,4 +1,4 @@
{ pkgs, system, ... }: import ./make-test.nix ({ pkgs, ... }:
with pkgs.lib; with pkgs.lib;
@ -224,4 +224,4 @@ in {
ensureMountPoint("/mnt/boot"); ensureMountPoint("/mnt/boot");
}; };
''; '';
} })

View File

@ -1,8 +1,6 @@
# Test printing via CUPS. # Test printing via CUPS.
{ pkgs, ... }: import ./make-test.nix ({pkgs, ... }: {
{
nodes = { nodes = {
@ -88,4 +86,4 @@
} }
''; '';
} })

View File

@ -1,4 +1,4 @@
{ pkgs, ... }: import ./make-test.nix (
let let
@ -90,4 +90,4 @@ in
$client->succeed("curl --fail http://proxy/"); $client->succeed("curl --fail http://proxy/");
''; '';
} })

View File

@ -1,4 +1,4 @@
{ pkgs, ... }: import ./make-test.nix (
let let
@ -79,4 +79,4 @@ rec {
$server->stopJob("quake3-server"); $server->stopJob("quake3-server");
''; '';
} })

View File

@ -1,8 +1,7 @@
{ pkgs, ... }: # This test runs rabbitmq and checks if rabbitmq is up and running.
# This test runs rabbitmq and checks if rabbitmq is up and running import ./make-test.nix ({ pkgs, ... }: {
{
nodes = { nodes = {
one = { config, pkgs, ... }: { one = { config, pkgs, ... }: {
services.rabbitmq.enable = true; services.rabbitmq.enable = true;
@ -11,8 +10,8 @@
testScript = '' testScript = ''
startAll; startAll;
$one->waitForUnit("rabbitmq.service"); $one->waitForUnit("rabbitmq.service");
$one->waitUntilSucceeds("su -s ${pkgs.stdenv.shell} rabbitmq -c \"rabbitmqctl status\""); $one->waitUntilSucceeds("su -s ${pkgs.stdenv.shell} rabbitmq -c \"rabbitmqctl status\"");
''; '';
} })

View File

@ -2,7 +2,9 @@
with import ../lib/testing.nix { inherit system; }; with import ../lib/testing.nix { inherit system; };
runInMachine { {
drv = pkgs.patchelf; test = runInMachine {
machine = { config, pkgs, ... }: { services.sshd.enable = true; }; drv = pkgs.hello;
machine = { config, pkgs, ... }: { /* services.sshd.enable = true; */ };
};
} }

View File

@ -1,11 +1,11 @@
{ pkgs, ... }: import ./make-test.nix {
{
machine = { config, pkgs, ... }: { }; machine = { config, pkgs, ... }: { };
testScript = testScript =
'' ''
startAll; startAll;
$machine->waitForUnit("multi-user.target");
$machine->shutdown; $machine->shutdown;
''; '';
} }

View File

@ -1,4 +1,4 @@
{ pkgs, ... }: import ./make-test.nix (
let let
@ -114,4 +114,4 @@ in
$webserver->stopJob("httpd"); $webserver->stopJob("httpd");
''; '';
} })

View File

@ -1,6 +1,5 @@
{ pkgs, ... }: import ./make-test.nix {
{
nodes = { nodes = {
server = server =
{ pkgs, config, ... }: { pkgs, config, ... }:
@ -25,4 +24,5 @@
$client->succeed("curl --fail http://server/examples/servlets/servlet/HelloWorldExample"); $client->succeed("curl --fail http://server/examples/servlets/servlet/HelloWorldExample");
$client->succeed("curl --fail http://server/examples/jsp/jsp2/simpletag/hello.jsp"); $client->succeed("curl --fail http://server/examples/jsp/jsp2/simpletag/hello.jsp");
''; '';
} }

View File

@ -1,6 +1,5 @@
{ pkgs, ... }: import ./make-test.nix ({ pkgs, ... }: {
{
nodes = { nodes = {
storage = storage =
{ config, pkgs, ... }: { config, pkgs, ... }:
@ -68,4 +67,4 @@
$client->screenshot("screen"); $client->screenshot("screen");
''; '';
} })

View File

@ -1,4 +1,4 @@
{ pkgs, ... }: import ./make-test.nix ({ pkgs, ... }:
let let
@ -53,4 +53,4 @@ in
$machine->fail("[ -e /dev/sda ]"); $machine->fail("[ -e /dev/sda ]");
''; '';
} })

View File

@ -1,6 +1,4 @@
{ pkgs, ... }: import ./make-test.nix {
{
machine = machine =
{ config, pkgs, ... }: { config, pkgs, ... }: