Skip to content

Commit c7c717c

Browse files
recomission integration tests (#2017)
Integration tests were previously skipped and as such unmaintained and were broken over time. This commit fixes the tests by redesigning them to locally run tracee, and making code ready for new integration tests being added. Adds a new test to check container mode filtering.
1 parent fcdb1d6 commit c7c717c

File tree

6 files changed

+306
-223
lines changed

6 files changed

+306
-223
lines changed

.github/actions/build-dependencies/action.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,12 @@ runs:
4141
run: |
4242
go install honnef.co/go/tools/cmd/staticcheck@latest
4343
shell: bash
44+
- name: Install docker
45+
run: |
46+
sudo apt-get install --yes ca-certificates curl gnupg lsb-release
47+
sudo mkdir -p /etc/apt/keyrings
48+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
49+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
50+
sudo apt-get --yes update
51+
sudo apt-get install --yes docker-ce docker-ce-cli containerd.io
52+
shell: bash

.github/workflows/pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
opa-version: ${{ env.OPA_VERSION }}
9090
- name: Run Integration Tests
9191
run: |
92-
make test-integration
92+
sudo env "PATH=$PATH" make test-integration
9393
VERIFY-SIGNATURES:
9494
name: Verify Signatures
9595
needs:

Makefile

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ help:
235235
@echo ""
236236
@echo "# test"
237237
@echo ""
238-
@echo " $$ make test-types # run unit tests for types module"
239238
@echo " $$ make test-unit # run unit tests"
239+
@echo " $$ make test-types # run unit tests for types module"
240240
@echo " $$ make test-integration # run integration tests"
241241
@echo " $$ make test-rules # opa test (tracee-rules)"
242242
@echo ""
@@ -556,45 +556,6 @@ clean-tracee-rules:
556556
#
557557
$(CMD_RM) -rf $(OUTPUT_DIR)/tracee-rules
558558

559-
.PHONY: test-unit
560-
test-unit: \
561-
.checkver_$(CMD_GO) \
562-
tracee-ebpf \
563-
test-types
564-
#
565-
$(GO_ENV_EBPF) \
566-
$(CMD_GO) test \
567-
-tags ebpf \
568-
-short \
569-
-race \
570-
-v \
571-
-coverprofile=coverage.txt \
572-
./...
573-
574-
.PHONY: test-types
575-
test-types: \
576-
.checkver_$(CMD_GO)
577-
#
578-
# Note that we must changed the directory here because types is a standalone Go module.
579-
cd ./types && $(CMD_GO) test \
580-
-short \
581-
-race \
582-
-v \
583-
-coverprofile=coverage.txt \
584-
./...
585-
586-
.PHONY: test-integration
587-
test-integration: \
588-
.checkver_$(CMD_GO) \
589-
tracee-ebpf
590-
#
591-
TRC_BIN=$(abspath $(OUTPUT_DIR)/tracee-ebpf) \
592-
$(GO_ENV_EBPF) \
593-
$(CMD_GO) test \
594-
-tags ebpf,integration \
595-
-v \
596-
-run "Test_Events" ./tests/integration/...
597-
598559
#
599560
# rules
600561
#
@@ -637,6 +598,55 @@ clean-rules:
637598
#
638599
$(CMD_RM) -rf $(OUTPUT_DIR)/rules
639600

601+
#
602+
# tests
603+
#
604+
605+
.PHONY: test-unit
606+
test-unit: \
607+
.checkver_$(CMD_GO) \
608+
tracee-ebpf \
609+
test-types
610+
#
611+
$(GO_ENV_EBPF) \
612+
$(CMD_GO) test \
613+
-tags ebpf \
614+
-short \
615+
-race \
616+
-v \
617+
-coverprofile=coverage.txt \
618+
./cmd/... \
619+
./pkg/... \
620+
./signatures/... \
621+
622+
.PHONY: test-types
623+
test-types: \
624+
.checkver_$(CMD_GO)
625+
#
626+
# Note that we must changed the directory here because types is a standalone Go module.
627+
cd ./types && $(CMD_GO) test \
628+
-short \
629+
-race \
630+
-v \
631+
-coverprofile=coverage.txt \
632+
./...
633+
634+
.PHONY: test-integration
635+
test-integration: \
636+
.checkver_$(CMD_GO) \
637+
tracee-ebpf
638+
#
639+
$(GO_ENV_EBPF) \
640+
$(CMD_GO) test \
641+
-tags $(GO_TAGS_EBPF) \
642+
-ldflags="-w \
643+
-extldflags \"$(CGO_EXT_LDFLAGS_EBPF)\" \
644+
-X main.version=\"$(VERSION)\" \
645+
" \
646+
-v \
647+
-p 1 \
648+
./tests/integration/... \
649+
640650
.PHONY: test-rules
641651
test-rules: \
642652
| .check_$(CMD_OPA)

pkg/ebpf/tracee.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ type Tracee struct {
201201
eventsSorter *sorting.EventsChronologicalSorter
202202
eventDerivations events.DerivationTable
203203
kernelSymbols *helpers.KernelSymbolTable
204+
running bool
204205
}
205206

206207
func (t *Tracee) Stats() *metrics.Stats {
@@ -985,6 +986,7 @@ func (t *Tracee) Run(ctx gocontext.Context) error {
985986
go t.handleEvents(ctx)
986987
go t.processFileWrites()
987988
go t.processNetEvents(ctx)
989+
t.running = true
988990
// block until ctx is cancelled elsewhere
989991
<-ctx.Done()
990992
t.eventsPerfMap.Stop()
@@ -1054,6 +1056,11 @@ func (t *Tracee) Close() {
10541056
fmt.Fprintf(os.Stderr, "failed to clean containers module when closing tracee: %s", err)
10551057
}
10561058
}
1059+
t.running = false
1060+
}
1061+
1062+
func (t *Tracee) Running() bool {
1063+
return t.running
10571064
}
10581065

10591066
func computeFileHash(fileName string) (string, error) {

0 commit comments

Comments
 (0)