summaryrefslogtreecommitdiffstats
path: root/nixos/tests/systemd-analyze.nix
blob: dbe20e82627f46ec6fccd3f69ee945e815443aa4 (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
40
41
42
43
44
45
46
47
48
49
50
{
  latestKernel,
  lib,
  ...
}:

{
  name = "systemd-analyze";
  meta.maintainers = with lib.maintainers; [ raskin ];

  _module.args.latestKernel = lib.mkDefault false;

  nodes.machine =
    { pkgs, lib, ... }:
    {
      boot.kernelPackages = lib.mkIf latestKernel pkgs.linuxPackages_latest;
    };

  testScript = ''
    machine.wait_for_unit("multi-user.target")

    # We create a special output directory to copy it as a whole
    with subtest("Prepare output dir"):
        machine.succeed("mkdir systemd-analyze")


    # Save the output into a file with given name inside the common
    # output directory
    def run_systemd_analyze(args, name):
        tgt_dir = "systemd-analyze"
        machine.succeed(
            "systemd-analyze {} > {}/{} 2> {}/{}.err".format(
                " ".join(args), tgt_dir, name, tgt_dir, name
            )
        )


    with subtest("Print statistics"):
        run_systemd_analyze(["blame"], "blame.txt")
        run_systemd_analyze(["critical-chain"], "critical-chain.txt")
        run_systemd_analyze(["dot"], "dependencies.dot")
        run_systemd_analyze(["plot"], "systemd-analyze.svg")

    # We copy the main graph into the $out (toplevel), and we also copy
    # the entire output directory with additional data
    with subtest("Copying the resulting data into $out"):
        machine.copy_from_machine("systemd-analyze/", "")
        machine.copy_from_machine("systemd-analyze/systemd-analyze.svg", "")
  '';
}