at 23.11-pre 2.6 kB view raw
1import ./make-test-python.nix ({ pkgs, ... }: { 2 name = "tracee-integration"; 3 meta.maintainers = pkgs.tracee.meta.maintainers; 4 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; 11 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 21 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 34 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; 46 })) 47 ]; 48 }; 49 }; 50 51 testScript = '' 52 machine.wait_for_unit("docker.service") 53 54 with subtest("run integration tests"): 55 # EventFilters/trace_only_events_from_new_containers also requires a container called "alpine" 56 machine.succeed('tar c -C ${pkgs.pkgsStatic.busybox} . | docker import - alpine --change "ENTRYPOINT [\"sleep\"]"') 57 58 # Test_EventFilters/trace_event_set_in_a_specific_scope expects to be in a dir that includes "integration" 59 print(machine.succeed( 60 'mkdir /tmp/integration', 61 'cd /tmp/integration && tracee-integration -test.v' 62 )) 63 ''; 64})