at master 1.8 kB view raw
1# Test whether hibernation from partition works. 2 3{ 4 system ? builtins.currentSystem, 5 config ? { }, 6 pkgs ? import ../.. { inherit system config; }, 7 systemdStage1 ? false, 8}: 9 10with import ../lib/testing-python.nix { inherit system pkgs; }; 11 12makeTest { 13 name = "hibernate"; 14 15 nodes = { 16 machine = 17 { 18 config, 19 lib, 20 pkgs, 21 ... 22 }: 23 { 24 imports = [ 25 ./common/auto-format-root-device.nix 26 ]; 27 28 systemd.services.backdoor.conflicts = [ "sleep.target" ]; 29 powerManagement.resumeCommands = "systemctl --no-block restart backdoor.service"; 30 31 virtualisation.emptyDiskImages = [ (2 * config.virtualisation.memorySize) ]; 32 virtualisation.useNixStoreImage = true; 33 34 swapDevices = lib.mkOverride 0 [ 35 { 36 device = "/dev/vdc"; 37 options = [ "x-systemd.makefs" ]; 38 } 39 ]; 40 boot.initrd.systemd.enable = systemdStage1; 41 virtualisation.useEFIBoot = true; 42 }; 43 }; 44 45 testScript = '' 46 # Drop in file that checks if we un-hibernated properly (and not booted fresh) 47 machine.wait_for_unit("default.target") 48 machine.succeed( 49 "mkdir /run/test", 50 "mount -t ramfs -o size=1m ramfs /run/test", 51 "echo not persisted to disk > /run/test/suspended", 52 ) 53 54 # Hibernate machine 55 machine.execute("systemctl hibernate >&2 &", check_return=False) 56 machine.wait_for_shutdown() 57 58 # Restore machine from hibernation, validate our ramfs file is there. 59 machine.start() 60 machine.succeed("grep 'not persisted to disk' /run/test/suspended") 61 62 # Ensure we don't restore from hibernation when booting again 63 machine.crash() 64 machine.wait_for_unit("default.target") 65 machine.fail("grep 'not persisted to disk' /run/test/suspended") 66 ''; 67 68}