nixos/tests: add hibernation test

This commit is contained in:
Nikolay Amiantov 2015-03-05 17:21:27 +03:00
parent 399db54e35
commit 9cc70b419c
2 changed files with 43 additions and 0 deletions

View file

@ -231,6 +231,7 @@ in rec {
tests.gnome3 = callTest tests/gnome3.nix {};
tests.gnome3-gdm = callTest tests/gnome3-gdm.nix {};
tests.grsecurity = callTest tests/grsecurity.nix {};
tests.hibernate = callTest tests/hibernate.nix {};
tests.i3wm = callTest tests/i3wm.nix {};
tests.installer = callSubTests tests/installer.nix {};
tests.influxdb = callTest tests/influxdb.nix {};

42
nixos/tests/hibernate.nix Normal file
View file

@ -0,0 +1,42 @@
# Test whether hibernation from partition works.
import ./make-test.nix (pkgs: {
name = "hibernate";
nodes = {
machine = { config, lib, pkgs, ... }: with lib; {
virtualisation.emptyDiskImages = [ config.virtualisation.memorySize ];
systemd.services.backdoor.conflicts = [ "sleep.target" ];
swapDevices = mkOverride 0 [ { device = "/dev/vdb"; } ];
networking.firewall.allowedTCPPorts = [ 4444 ];
systemd.services.listener.serviceConfig.ExecStart = "${pkgs.netcat}/bin/nc -l -p 4444";
};
probe = { config, lib, pkgs, ...}: {
environment.systemPackages = [ pkgs.netcat ];
};
};
# 9P doesn't support reconnection to virtio transport after a hibernation.
# Therefore, machine just hangs on any Nix store access.
# To work around it we run a daemon which listens to a TCP connection and
# try to connect to it as a test.
testScript =
''
$machine->waitForUnit("multi-user.target");
$machine->succeed("mkswap /dev/vdb");
$machine->succeed("swapon -a");
$machine->startJob("listener");
$machine->succeed("systemctl hibernate &");
$machine->waitForShutdown;
$machine->start;
$probe->waitForUnit("network.target");
$probe->waitUntilSucceeds("echo test | nc -c machine 4444");
'';
})