summaryrefslogtreecommitdiffstats
path: root/nixos/tests/systemd-pstore.nix
blob: 7b9fc2f5142ac68b0c51c7ebd70c61a19bc4541d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{
  name = "systemd-pstore";

  nodes.machine = {
    virtualisation.useEFIBoot = true;
    boot.initrd.systemd.enable = true;
    testing.initrdBackdoor = true;
  };

  testScript = ''
    machine.switch_root()
    with subtest("pstore API fs is mounted"):
      machine.succeed("stat /sys/fs/pstore")

    with subtest("systemd-pstore.service doesn't run because nothing crashed"):
      output = machine.execute("systemctl status systemd-pstore.service", check_return=False)[1]
      t.assertIn("condition unmet", output)
      machine.fail("stat /var/lib/systemd/pstore/*/*/dmesg.txt")

    with subtest("systemd-pstore.service saves dmesg.txt files"):
      machine.execute("echo c > /proc/sysrq-trigger", check_return=False, check_output=False)
      machine.wait_for_shutdown()
      machine.switch_root()
      machine.wait_for_unit("systemd-pstore.service")
      machine.succeed("stat /var/lib/systemd/pstore/*/*/dmesg.txt")

    with subtest("crashes in initrd can be recovered too"):
      machine.succeed(
        "rm -r /var/lib/systemd/pstore/*",
        "sync",
      )
      machine.shutdown()
      machine.execute("echo c > /proc/sysrq-trigger", check_return=False, check_output=False)
      machine.wait_for_shutdown()
      machine.switch_root()
      machine.wait_for_unit("systemd-pstore.service")
      machine.succeed("stat /var/lib/systemd/pstore/*/*/dmesg.txt")
  '';
}