1 # Test whether hibernation from partition works.
3 { system ? builtins.currentSystem
5 , pkgs ? import ../.. { inherit system config; }
6 , systemdStage1 ? false
9 with import ../lib/testing-python.nix { inherit system pkgs; };
15 machine = { config, lib, pkgs, ... }: {
17 ./common/auto-format-root-device.nix
20 systemd.services.backdoor.conflicts = [ "sleep.target" ];
21 powerManagement.resumeCommands = "systemctl --no-block restart backdoor.service";
23 virtualisation.emptyDiskImages = [ (2 * config.virtualisation.memorySize) ];
24 virtualisation.useNixStoreImage = true;
26 swapDevices = lib.mkOverride 0 [ { device = "/dev/vdc"; options = [ "x-systemd.makefs" ]; } ];
27 boot.initrd.systemd.enable = systemdStage1;
28 virtualisation.useEFIBoot = true;
33 # Drop in file that checks if we un-hibernated properly (and not booted fresh)
34 machine.wait_for_unit("default.target")
37 "mount -t ramfs -o size=1m ramfs /run/test",
38 "echo not persisted to disk > /run/test/suspended",
42 machine.execute("systemctl hibernate >&2 &", check_return=False)
43 machine.wait_for_shutdown()
45 # Restore machine from hibernation, validate our ramfs file is there.
47 machine.succeed("grep 'not persisted to disk' /run/test/suspended")
49 # Ensure we don't restore from hibernation when booting again
51 machine.wait_for_unit("default.target")
52 machine.fail("grep 'not persisted to disk' /run/test/suspended")