nixos/tests: add hibernation test

+43
+1
nixos/release.nix
··· 231 231 tests.gnome3 = callTest tests/gnome3.nix {}; 232 232 tests.gnome3-gdm = callTest tests/gnome3-gdm.nix {}; 233 233 tests.grsecurity = callTest tests/grsecurity.nix {}; 234 + tests.hibernate = callTest tests/hibernate.nix {}; 234 235 tests.i3wm = callTest tests/i3wm.nix {}; 235 236 tests.installer = callSubTests tests/installer.nix {}; 236 237 tests.influxdb = callTest tests/influxdb.nix {};
+42
nixos/tests/hibernate.nix
··· 1 + # Test whether hibernation from partition works. 2 + 3 + import ./make-test.nix (pkgs: { 4 + name = "hibernate"; 5 + 6 + nodes = { 7 + machine = { config, lib, pkgs, ... }: with lib; { 8 + virtualisation.emptyDiskImages = [ config.virtualisation.memorySize ]; 9 + 10 + systemd.services.backdoor.conflicts = [ "sleep.target" ]; 11 + 12 + swapDevices = mkOverride 0 [ { device = "/dev/vdb"; } ]; 13 + 14 + networking.firewall.allowedTCPPorts = [ 4444 ]; 15 + 16 + systemd.services.listener.serviceConfig.ExecStart = "${pkgs.netcat}/bin/nc -l -p 4444"; 17 + }; 18 + 19 + probe = { config, lib, pkgs, ...}: { 20 + environment.systemPackages = [ pkgs.netcat ]; 21 + }; 22 + }; 23 + 24 + # 9P doesn't support reconnection to virtio transport after a hibernation. 25 + # Therefore, machine just hangs on any Nix store access. 26 + # To work around it we run a daemon which listens to a TCP connection and 27 + # try to connect to it as a test. 28 + 29 + testScript = 30 + '' 31 + $machine->waitForUnit("multi-user.target"); 32 + $machine->succeed("mkswap /dev/vdb"); 33 + $machine->succeed("swapon -a"); 34 + $machine->startJob("listener"); 35 + $machine->succeed("systemctl hibernate &"); 36 + $machine->waitForShutdown; 37 + $machine->start; 38 + $probe->waitForUnit("network.target"); 39 + $probe->waitUntilSucceeds("echo test | nc -c machine 4444"); 40 + ''; 41 + 42 + })