about summary refs log tree commit diff
path: root/nixos/tests/hibernate.nix
blob: 8251c6e7ef85e9b6b34ca04bb1a8b5ba040c19f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Test whether hibernation from partition works.

import ./make-test-python.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 4444 -k";
    };

    probe = { 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.start()
      machine.wait_for_unit("multi-user.target")
      machine.succeed("mkswap /dev/vdb")
      machine.succeed("swapon -a")
      machine.start_job("listener")
      machine.wait_for_open_port(4444)
      machine.succeed("systemctl hibernate &")
      machine.wait_for_shutdown()
      probe.wait_for_unit("multi-user.target")
      machine.start()
      probe.wait_until_succeeds("echo test | nc machine 4444 -N")
    '';

})