1# Test whether hibernation from partition works.
2
3import ./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 4444 -k";
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->waitForOpenPort(4444);
36 $machine->succeed("systemctl hibernate &");
37 $machine->waitForShutdown;
38 $machine->start;
39 $probe->waitForUnit("network.target");
40 $probe->waitUntilSucceeds("echo test | nc machine 4444");
41 '';
42
43})