-
-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathMakefile.test
More file actions
166 lines (141 loc) · 5.7 KB
/
Copy pathMakefile.test
File metadata and controls
166 lines (141 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Netcap Test Makefile
# Include this from main Makefile or use directly: make -f Makefile.test test-unit
.PHONY: test test-unit test-integration test-regression test-e2e test-bench test-fuzz test-all
.PHONY: test-coverage test-coverage-html test-race
.PHONY: test-golden-update test-golden-verify
.PHONY: fixtures-download fixtures-generate test-databases-generate
.PHONY: test-hyperscan
# Test targets
test: test-unit
test-all: test-unit test-integration test-regression
# Unit tests (fast, isolated, with mocks)
test-unit:
@echo "Running unit tests..."
go test -short -race -coverprofile=coverage.out ./...
# Integration tests (with real files and fixtures)
test-integration:
@echo "Running integration tests..."
go test -v -tags=integration ./tests/integration/...
# Regression tests (golden file comparisons)
test-regression:
@echo "Running regression tests..."
go test -v -tags=regression ./tests/regression/...
test-regression-verify:
@echo "Verifying regression test outputs..."
@./scripts/verify-golden-files.sh
# Update golden files (use after verifying changes are correct)
test-golden-update:
@echo "Updating golden files..."
UPDATE_GOLDEN=1 go test -v -tags=regression ./tests/regression/...
@echo "Golden files updated. Please review changes before committing."
# E2E tests (full CLI workflows)
test-e2e:
@echo "Running end-to-end tests..."
go test -v -tags=e2e -timeout=10m ./tests/e2e/...
# Hyperscan / Vectorscan integration tests (requires libhs from
# pkg-config). Builds with the `hyperscan` tag and exercises the
# multi-pattern fast path used by service probe matching.
test-hyperscan:
@echo "Running Hyperscan integration tests (requires libhs / vectorscan)..."
@pkg-config --exists libhs || (echo "libhs not found via pkg-config. Install vectorscan (brew install vectorscan) or hyperscan (apt install libhyperscan-dev)." && exit 1)
CGO_ENABLED=1 go test -v -tags hyperscan \
./internal/hsmatch/... \
./internal/filter/... \
./decoder/stream/service/... \
./decoder/stream/software/... \
./rules/...
# Performance benchmarks
test-bench:
@echo "Running benchmarks..."
go test -bench=. -benchmem -cpuprofile=cpu.prof -memprofile=mem.prof ./tests/benchmarks/...
@echo "Profiles saved: cpu.prof, mem.prof"
# Fuzzing smoke run. Each Fuzz* target is gated behind the `fuzz` build tag
# so it never slows the default unit suite. Go's -fuzz flag only accepts a
# single target per invocation, so we discover and loop over every target.
# Override the per-target budget with FUZZTIME (default 10s).
FUZZTIME ?= 10s
FUZZ_PKGS := ./decoder/packet/... ./decoder/stream/smtp/... ./decoder/stream/pop3/...
test-fuzz:
@echo "Running fuzz smoke (FUZZTIME=$(FUZZTIME) per target)..."
@for pkg in $(FUZZ_PKGS); do \
targets=$$(go test -tags fuzz -list '^Fuzz' $$pkg 2>/dev/null | grep '^Fuzz'); \
for t in $$targets; do \
echo ">> $$pkg $$t"; \
go test -tags fuzz -run '^$$' -fuzz="^$$t$$" -fuzztime=$(FUZZTIME) $$pkg || exit 1; \
done; \
done
@echo "Fuzz smoke complete."
# Coverage reports
test-coverage:
@echo "Generating coverage report..."
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
test-coverage-html:
@echo "Generating HTML coverage report..."
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
# Race detector
test-race:
@echo "Running tests with race detector..."
go test -race ./...
# Memory sanitizer (requires clang)
test-msan:
@echo "Running tests with memory sanitizer..."
CC=clang go test -msan ./...
# Test specific package
test-pkg:
@test -n "$(PKG)" || (echo "Usage: make test-pkg PKG=./collector/" && exit 1)
go test -v -race -cover $(PKG)
# Test with verbose output
test-verbose:
go test -v ./...
# Coverage enforcement (fail if below threshold)
test-coverage-check: test-coverage
@echo "Checking coverage threshold (80%)..."
@go tool cover -func=coverage.out | grep total | awk '{print $$3}' | sed 's/%//' | \
awk '{if ($$1 < 80) {print "Coverage below 80%: " $$1 "%"; exit 1} else {print "Coverage OK: " $$1 "%"}}'
# Test data management
fixtures-download:
@echo "Downloading test fixtures..."
@mkdir -p tests/fixtures/pcaps
@./scripts/download-test-fixtures.sh
fixtures-generate:
@echo "Generating synthetic test fixtures..."
go run ./helpers/pcap_generator.go
test-databases-generate:
@echo "Generating test databases..."
go run ./helpers/generate_test_dbs.go
# Clean test artifacts
test-clean:
@echo "Cleaning test artifacts..."
rm -f coverage.out coverage.html
rm -f cpu.prof mem.prof
rm -rf tests/fixtures/tmp/
find . -name "*.test" -delete
# Help
test-help:
@echo "Netcap Test Targets:"
@echo ""
@echo " test - Run unit tests (default)"
@echo " test-all - Run unit, integration, and regression tests"
@echo " test-unit - Run fast unit tests"
@echo " test-integration - Run integration tests"
@echo " test-regression - Run regression tests"
@echo " test-e2e - Run end-to-end tests"
@echo " test-bench - Run performance benchmarks"
@echo " test-fuzz - Run fuzz smoke over all Fuzz* targets (FUZZTIME=10s)"
@echo ""
@echo " test-coverage - Generate coverage report"
@echo " test-coverage-html - Generate HTML coverage report"
@echo " test-race - Run tests with race detector"
@echo ""
@echo " test-golden-update - Update golden files"
@echo " test-golden-verify - Verify against golden files"
@echo ""
@echo " test-pkg PKG=./collector/ - Test specific package"
@echo " test-verbose - Run tests with verbose output"
@echo ""
@echo " fixtures-download - Download test fixtures"
@echo " fixtures-generate - Generate synthetic fixtures"
@echo " test-clean - Clean test artifacts"