2022-10-02 10:43:54 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }: {
|
|
|
|
name = "tracee-integration";
|
|
|
|
nodes = {
|
|
|
|
machine = { config, pkgs, ... }: {
|
2023-02-01 15:27:41 +00:00
|
|
|
# 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;
|
2022-10-02 10:43:54 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [
|
2023-02-01 15:27:41 +00:00
|
|
|
# required by Test_EventFilters/trace_events_from_ls_and_which_binary_in_separate_scopes
|
|
|
|
pkgs.which
|
2022-10-02 10:43:54 +00:00
|
|
|
# build the go integration tests as a binary
|
|
|
|
(pkgs.tracee.overrideAttrs (oa: {
|
|
|
|
pname = oa.pname + "-integration";
|
2023-01-30 15:22:50 +00:00
|
|
|
postPatch = oa.postPatch or "" + ''
|
2023-02-01 15:27:41 +00:00
|
|
|
# prepare tester.sh (which will be embedded in the test binary)
|
2023-01-30 15:22:50 +00:00
|
|
|
patchShebangs tests/integration/tester.sh
|
2023-02-01 15:27:41 +00:00
|
|
|
|
2023-01-30 15:22:50 +00:00
|
|
|
# fix the test to look at nixos paths for running programs
|
|
|
|
substituteInPlace tests/integration/integration_test.go \
|
2023-02-01 15:27:41 +00:00
|
|
|
--replace "bin=/usr/bin/" "comm=" \
|
|
|
|
--replace "/usr/bin/dockerd" "dockerd" \
|
|
|
|
--replace "/usr/bin" "/run/current-system/sw/bin"
|
2023-01-30 15:22:50 +00:00
|
|
|
'';
|
|
|
|
nativeBuildInputs = oa.nativeBuildInputs or [ ] ++ [ pkgs.makeWrapper ];
|
2022-10-02 10:43:54 +00:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
# just build the static lib we need for the go test binary
|
2023-01-19 13:07:45 +00:00
|
|
|
make $makeFlags ''${enableParallelBuilding:+-j$NIX_BUILD_CORES} bpf-core ./dist/btfhub
|
2022-10-26 11:11:44 +00:00
|
|
|
|
2022-10-02 10:43:54 +00:00
|
|
|
# then compile the tests to be ran later
|
2022-10-26 11:11:44 +00:00
|
|
|
CGO_LDFLAGS="$(pkg-config --libs libbpf)" go test -tags core,ebpf,integration -p 1 -c -o $GOPATH/tracee-integration ./tests/integration/...
|
2022-10-02 10:43:54 +00:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
doCheck = false;
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
2023-01-30 15:22:50 +00:00
|
|
|
mv $GOPATH/tracee-integration $out/bin/
|
2022-10-02 10:43:54 +00:00
|
|
|
'';
|
|
|
|
doInstallCheck = false;
|
|
|
|
}))
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2023-02-01 15:27:41 +00:00
|
|
|
machine.wait_for_unit("docker.service")
|
|
|
|
|
2022-10-02 10:43:54 +00:00
|
|
|
with subtest("run integration tests"):
|
|
|
|
# EventFilters/trace_only_events_from_new_containers also requires a container called "alpine"
|
2023-02-01 15:27:41 +00:00
|
|
|
machine.succeed('tar c -C ${pkgs.pkgsStatic.busybox} . | docker import - alpine --change "ENTRYPOINT [\"sleep\"]"')
|
2022-10-02 10:43:54 +00:00
|
|
|
|
2023-02-01 15:27:41 +00:00
|
|
|
# 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'
|
|
|
|
))
|
2022-10-02 10:43:54 +00:00
|
|
|
'';
|
|
|
|
})
|