summaryrefslogtreecommitdiffstats
path: root/nixos/tests/systemtap.nix
blob: d278cf41c0dab461eb63c60323e0f2887dae195c (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
51
52
53
54
55
56
57
58
{
  system ? builtins.currentSystem,
  config ? { },
  pkgs ? import ../.. { inherit system config; },
}@args:

with pkgs.lib;

let
  stapScript = pkgs.writeText "test.stp" ''
    probe kernel.function("do_sys_poll") {
      println("kernel function probe & println work")
      exit()
    }
  '';

  ## TODO shared infra with ../kernel-generic.nix
  testsForLinuxPackages =
    linuxPackages:
    (import ./make-test-python.nix (
      { pkgs, ... }:
      {
        name = "kernel-${linuxPackages.kernel.version}";
        meta = with pkgs.lib.maintainers; {
          maintainers = [ bendlas ];
        };

        nodes.machine =
          { ... }:
          {
            boot.kernelPackages = linuxPackages;
            programs.systemtap.enable = true;
          };

        testScript = ''
          with subtest("Capture stap ouput"):
              output = machine.succeed("stap ${stapScript} 2>&1")

          with subtest("Ensure that expected output from stap script is there"):
              assert "kernel function probe & println work\n" == output, "kernel function probe & println work\n != " + output
        '';
      }
    ) args);

  ## TODO shared infra with ../kernel-generic.nix
  kernels = {
    inherit (pkgs.linuxKernel.packageAliases) linux_default linux_latest;
  };

in
mapAttrs (_: lP: testsForLinuxPackages lP) kernels
// {
  passthru = {
    inherit testsForLinuxPackages;

    testsForKernel = kernel: testsForLinuxPackages (pkgs.linuxPackagesFor kernel);
  };
}