linuxPackages.systemtap: 4.8 -> 5.0a, add nixos tests (#276840)

* nixos/tests/systemtap: init smoke test

* linuxPackages.systemtap: use --sysroot instead of -r

* nixos/tests/systemtap: rule out warnings

* linuxPackages.systemtap: smaller sysroot

* nixos/tests/systemtap: test on a few more kernels

* linuxPackages.systemtap: provide debuginfo for tracing kernel.function

* linuxPackages.systemtap: test kernel.function probe

* linuxPackages.systemtap: 4.8 -> 5.0a
This commit is contained in:
Herwig Hochleitner 2024-01-09 19:38:02 +01:00 committed by GitHub
parent 4b73ceed19
commit ae34cddb51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 3 deletions

View File

@ -861,6 +861,7 @@ in {
systemd-misc = handleTest ./systemd-misc.nix {};
systemd-userdbd = handleTest ./systemd-userdbd.nix {};
systemd-homed = handleTest ./systemd-homed.nix {};
systemtap = handleTest ./systemtap.nix {};
tandoor-recipes = handleTest ./tandoor-recipes.nix {};
tang = handleTest ./tang.nix {};
taskserver = handleTest ./taskserver.nix {};

50
nixos/tests/systemtap.nix Normal file
View File

@ -0,0 +1,50 @@
{ 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);
};
}

View File

@ -6,8 +6,8 @@ let
## fetchgit info
url = "git://sourceware.org/git/systemtap.git";
rev = "release-${version}";
sha256 = "sha256-UiUMoqdfkk6mzaPGctpQW3dvOWKhNBNuScJ5BpCykVg=";
version = "4.8";
sha256 = "sha256-2L7+k/tgI6trkstDTY4xxfFzmNDlxbCHDRKAFaERQeM=";
version = "5.0a";
inherit (kernel) stdenv;
@ -22,6 +22,14 @@ let
env.NIX_CFLAGS_COMPILE = toString [ "-Wno-error=deprecated-declarations" ]; # Needed with GCC 12
};
## symlink farm for --sysroot flag
sysroot = runCommand "systemtap-sysroot-${kernel.version}" { } ''
mkdir -p $out/boot $out/usr/lib/debug
ln -s ${kernel.dev}/vmlinux ${kernel.dev}/lib $out
ln -s ${kernel.dev}/vmlinux $out/usr/lib/debug
ln -s ${kernel}/System.map $out/boot/System.map-${kernel.version}
'';
pypkgs = with python3.pkgs; makePythonPath [ pyparsing ];
in runCommand "systemtap-${kernel.version}-${version}" {
@ -40,7 +48,7 @@ in runCommand "systemtap-${kernel.version}-${version}" {
done
rm $out/bin/stap $out/bin/dtrace
makeWrapper $stapBuild/bin/stap $out/bin/stap \
--add-flags "-r ${kernel.dev}" \
--add-flags "--sysroot ${sysroot}" \
--prefix PATH : ${lib.makeBinPath [ stdenv.cc.cc stdenv.cc.bintools elfutils gnumake ]}
makeWrapper $stapBuild/bin/dtrace $out/bin/dtrace \
--prefix PYTHONPATH : ${pypkgs}