2020-04-24 23:36:52 +00:00
|
|
|
# Test whether hibernation from partition works.
|
|
|
|
|
2021-04-26 19:14:03 +00:00
|
|
|
{ system ? builtins.currentSystem
|
|
|
|
, config ? {}
|
|
|
|
, pkgs ? import ../.. { inherit system config; }
|
2022-04-15 01:41:22 +00:00
|
|
|
, systemdStage1 ? false
|
2021-04-26 19:14:03 +00:00
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-04-26 19:14:03 +00:00
|
|
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
makeTest {
|
2021-04-26 19:14:03 +00:00
|
|
|
name = "hibernate";
|
|
|
|
|
|
|
|
nodes = {
|
2023-05-24 13:37:59 +00:00
|
|
|
machine = { config, lib, pkgs, ... }: {
|
2021-04-26 19:14:03 +00:00
|
|
|
imports = [
|
2023-07-15 17:15:38 +00:00
|
|
|
./common/auto-format-root-device.nix
|
2021-04-26 19:14:03 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
systemd.services.backdoor.conflicts = [ "sleep.target" ];
|
|
|
|
powerManagement.resumeCommands = "systemctl --no-block restart backdoor.service";
|
2021-04-26 19:14:03 +00:00
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
virtualisation.emptyDiskImages = [ (2 * config.virtualisation.memorySize) ];
|
|
|
|
virtualisation.useNixStoreImage = true;
|
|
|
|
|
|
|
|
swapDevices = lib.mkOverride 0 [ { device = "/dev/vdc"; options = [ "x-systemd.makefs" ]; } ];
|
|
|
|
boot.initrd.systemd.enable = systemdStage1;
|
2024-04-21 15:54:59 +00:00
|
|
|
virtualisation.useEFIBoot = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
testScript = ''
|
|
|
|
# Drop in file that checks if we un-hibernated properly (and not booted fresh)
|
|
|
|
machine.wait_for_unit("default.target")
|
|
|
|
machine.succeed(
|
|
|
|
"mkdir /run/test",
|
|
|
|
"mount -t ramfs -o size=1m ramfs /run/test",
|
|
|
|
"echo not persisted to disk > /run/test/suspended",
|
|
|
|
)
|
|
|
|
|
|
|
|
# Hibernate machine
|
|
|
|
machine.execute("systemctl hibernate >&2 &", check_return=False)
|
|
|
|
machine.wait_for_shutdown()
|
|
|
|
|
|
|
|
# Restore machine from hibernation, validate our ramfs file is there.
|
|
|
|
machine.start()
|
|
|
|
machine.succeed("grep 'not persisted to disk' /run/test/suspended")
|
|
|
|
|
|
|
|
# Ensure we don't restore from hibernation when booting again
|
|
|
|
machine.crash()
|
|
|
|
machine.wait_for_unit("default.target")
|
|
|
|
machine.fail("grep 'not persisted to disk' /run/test/suspended")
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-04-26 19:14:03 +00:00
|
|
|
}
|