nixpkgs-suyu/nixos/tests/tracee.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.7 KiB
Nix
Raw Normal View History

import ./make-test-python.nix ({ pkgs, ... }: {
name = "tracee-integration";
meta.maintainers = pkgs.tracee.meta.maintainers;
nodes = {
machine = { config, pkgs, ... }: {
# EventFilters/trace_only_events_from_new_containers and
# Test_EventFilters/trace_only_events_from_"dockerd"_binary_and_contain_it's_pid
# require docker/dockerd
virtualisation.docker.enable = true;
environment.systemPackages = with pkgs; [
# required by Test_EventFilters/trace_events_from_ls_and_which_binary_in_separate_scopes
which
# build the go integration tests as a binary
(tracee.overrideAttrs (oa: {
pname = oa.pname + "-integration";
postPatch = oa.postPatch or "" + ''
# prepare tester.sh (which will be embedded in the test binary)
patchShebangs tests/integration/tester.sh
# fix the test to look at nixos paths for running programs
substituteInPlace tests/integration/integration_test.go \
--replace "bin=/usr/bin/" "comm=" \
--replace "binary=/usr/bin/" "comm=" \
--replace "/usr/bin/dockerd" "dockerd" \
--replace "/usr/bin" "/run/current-system/sw/bin"
'';
nativeBuildInputs = oa.nativeBuildInputs or [ ] ++ [ makeWrapper ];
buildPhase = ''
runHook preBuild
# just build the static lib we need for the go test binary
make $makeFlags ''${enableParallelBuilding:+-j$NIX_BUILD_CORES} bpf-core ./dist/btfhub
# then compile the tests to be ran later
CGO_LDFLAGS="$(pkg-config --libs libbpf)" go test -tags core,ebpf,integration -p 1 -c -o $GOPATH/tracee-integration ./tests/integration/...
runHook postBuild
'';
doCheck = false;
outputs = [ "out" ];
installPhase = ''
mkdir -p $out/bin
mv $GOPATH/tracee-integration $out/bin/
'';
doInstallCheck = false;
meta = oa.meta // {
outputsToInstall = [];
};
}))
];
};
};
testScript = ''
machine.wait_for_unit("docker.service")
with subtest("run integration tests"):
# EventFilters/trace_only_events_from_new_containers also requires a container called "alpine"
machine.succeed('tar c -C ${pkgs.pkgsStatic.busybox} . | docker import - alpine --change "ENTRYPOINT [\"sleep\"]"')
# Test_EventFilters/trace_event_set_in_a_specific_scope expects to be in a dir that includes "integration"
print(machine.succeed(
'mkdir /tmp/integration',
'cd /tmp/integration && tracee-integration -test.v'
))
'';
})