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