2015-03-05 14:21:27 +00:00
|
|
|
# Test whether hibernation from partition works.
|
|
|
|
|
2021-04-23 01:01:15 +00:00
|
|
|
{ system ? builtins.currentSystem
|
|
|
|
, config ? {}
|
|
|
|
, pkgs ? import ../.. { inherit system config; }
|
2022-04-13 11:48:20 +00:00
|
|
|
, systemdStage1 ? false
|
2021-04-23 01:01:15 +00:00
|
|
|
}:
|
2015-03-05 14:21:27 +00:00
|
|
|
|
2021-04-23 01:01:15 +00:00
|
|
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
2015-03-05 14:21:27 +00:00
|
|
|
|
2023-07-29 18:21:28 +00:00
|
|
|
makeTest {
|
2021-04-23 01:01:15 +00:00
|
|
|
name = "hibernate";
|
|
|
|
|
|
|
|
nodes = {
|
2023-04-30 01:17:05 +00:00
|
|
|
machine = { config, lib, pkgs, ... }: {
|
2021-04-23 01:01:15 +00:00
|
|
|
imports = [
|
nixos/qemu-vm: use persistent block device names
This change removes the bespoke logic around identifying block devices.
Instead of trying to find the right device by iterating over
`qemu.drives` and guessing the right partition number (e.g.
/dev/vda{1,2}), devices are now identified by persistent names provided
by udev in /dev/disk/by-*.
Before this change, the root device was formatted on demand in the
initrd. However, this makes it impossible to use filesystem identifiers
to identify devices. Now, the formatting step is performed before the VM
is started. Because some tests, however, rely on this behaviour, a
utility function to replace this behaviour in added in
/nixos/tests/common/auto-format-root-device.nix.
Devices that contain neither a partition table nor a filesystem are
identified by their hardware serial number which is injecetd via QEMU
(and is thus persistent and predictable). PCI paths are not a reliably
way to identify devices because their availability and numbering depends
on the QEMU machine type.
This change makes the module more robust against changes in QEMU and the
kernel (non-persistent device naming) and by decoupling abstractions
(i.e. rootDevice, bootPartition, and bootLoaderDevice) enables further
improvement down the line.
2023-06-08 00:34:10 +00:00
|
|
|
./common/auto-format-root-device.nix
|
2021-04-23 01:01:15 +00:00
|
|
|
];
|
2015-03-05 14:21:27 +00:00
|
|
|
|
2023-07-29 18:21:28 +00:00
|
|
|
systemd.services.backdoor.conflicts = [ "sleep.target" ];
|
|
|
|
powerManagement.resumeCommands = "systemctl --no-block restart backdoor.service";
|
2021-04-23 01:01:15 +00:00
|
|
|
|
2023-07-29 18:21:28 +00:00
|
|
|
virtualisation.emptyDiskImages = [ (2 * config.virtualisation.memorySize) ];
|
|
|
|
virtualisation.useNixStoreImage = true;
|
|
|
|
|
|
|
|
swapDevices = lib.mkOverride 0 [ { device = "/dev/vdc"; options = [ "x-systemd.makefs" ]; } ];
|
|
|
|
boot.resumeDevice = "/dev/vdc";
|
|
|
|
boot.initrd.systemd.enable = systemdStage1;
|
2015-03-05 14:21:27 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-07-29 18:21:28 +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")
|
|
|
|
'';
|
2015-03-05 14:21:27 +00:00
|
|
|
|
2021-04-23 01:01:15 +00:00
|
|
|
}
|