Release NixOS 23.11
[NixPkgs.git] / nixos / tests / tracee.nix
blob3dadc0f9fdb338530720ce9e5e3cd361ea98b1e2
1 import ./make-test-python.nix ({ pkgs, ... }: {
2   name = "tracee-integration";
3   meta.maintainers = pkgs.tracee.meta.maintainers;
5   nodes = {
6     machine = { config, pkgs, ... }: {
7       # EventFilters/trace_only_events_from_new_containers and
8       # Test_EventFilters/trace_only_events_from_"dockerd"_binary_and_contain_it's_pid
9       # require docker/dockerd
10       virtualisation.docker.enable = true;
12       environment.systemPackages = with pkgs; [
13         # required by Test_EventFilters/trace_events_from_ls_and_which_binary_in_separate_scopes
14         which
15         # build the go integration tests as a binary
16         (tracee.overrideAttrs (oa: {
17           pname = oa.pname + "-integration";
18           postPatch = oa.postPatch or "" + ''
19             # prepare tester.sh (which will be embedded in the test binary)
20             patchShebangs tests/integration/tester.sh
22             # fix the test to look at nixos paths for running programs
23             substituteInPlace tests/integration/integration_test.go \
24               --replace "bin=/usr/bin/" "comm=" \
25               --replace "binary=/usr/bin/" "comm=" \
26               --replace "/usr/bin/dockerd" "dockerd" \
27               --replace "/usr/bin" "/run/current-system/sw/bin"
28           '';
29           nativeBuildInputs = oa.nativeBuildInputs or [ ] ++ [ makeWrapper ];
30           buildPhase = ''
31             runHook preBuild
32             # just build the static lib we need for the go test binary
33             make $makeFlags ''${enableParallelBuilding:+-j$NIX_BUILD_CORES} bpf-core ./dist/btfhub
35             # then compile the tests to be ran later
36             CGO_LDFLAGS="$(pkg-config --libs libbpf)" go test -tags core,ebpf,integration -p 1 -c -o $GOPATH/tracee-integration ./tests/integration/...
37             runHook postBuild
38           '';
39           doCheck = false;
40           outputs = [ "out" ];
41           installPhase = ''
42             mkdir -p $out/bin
43             mv $GOPATH/tracee-integration $out/bin/
44           '';
45           doInstallCheck = false;
47           meta = oa.meta // {
48             outputsToInstall = [];
49           };
50         }))
51       ];
52     };
53   };
55   testScript = ''
56     machine.wait_for_unit("docker.service")
58     with subtest("run integration tests"):
59       # EventFilters/trace_only_events_from_new_containers also requires a container called "alpine"
60       machine.succeed('tar c -C ${pkgs.pkgsStatic.busybox} . | docker import - alpine --change "ENTRYPOINT [\"sleep\"]"')
62       # Test_EventFilters/trace_event_set_in_a_specific_scope expects to be in a dir that includes "integration"
63       print(machine.succeed(
64         'mkdir /tmp/integration',
65         'cd /tmp/integration && tracee-integration -test.v'
66       ))
67   '';