@@ -33,7 +33,11 @@ REPOSITORY_ROOT := $(shell git rev-parse --show-toplevel)
33
33
BUILD_DIR := $(REPOSITORY_ROOT ) /build
34
34
35
35
# Other dependency versions
36
- ENVTEST_BIN_VERSION ?= 1.19.2
36
+ ENVTEST_BIN_VERSION ?= 1.24.0
37
+
38
+ # FUZZ_TIME defines the max amount of time, in Go Duration,
39
+ # each fuzzer should run for.
40
+ FUZZ_TIME ?= 1m
37
41
38
42
# Caches libgit2 versions per tag, "forcing" rebuild only when needed.
39
43
LIBGIT2_PATH := $(BUILD_DIR ) /libgit2/$(LIBGIT2_TAG )
@@ -134,7 +138,6 @@ tidy: ## Run go mod tidy
134
138
fmt : # # Run go fmt against code
135
139
go fmt ./...
136
140
cd api; go fmt ./...
137
- cd tests/fuzz; go fmt .
138
141
139
142
vet : $(LIBGIT2 ) # # Run go vet against code
140
143
go vet ./...
@@ -206,9 +209,9 @@ ifneq ($(shell grep -o 'LIBGIT2_IMG ?= \w.*' Makefile | cut -d ' ' -f 3):$(shell
206
209
exit 1; \
207
210
}
208
211
endif
209
- ifneq ($(shell grep -o 'LIBGIT2_TAG ?= \w.* ' Makefile | cut -d ' ' -f 3) , $(shell grep -o "LIBGIT2_TAG=.* " tests/fuzz/oss_fuzz_build .sh | sed 's;LIBGIT2_TAG="$${LIBGIT2_TAG :-;;g' | sed 's;}";;g'))
212
+ ifneq ($(shell grep -o 'LIBGIT2_TAG ?= \w.* ' Makefile | cut -d ' ' -f 3) , $(shell grep -o "LIBGIT2_TAG=.* " tests/fuzz/oss_fuzz_prebuild .sh | sed 's;LIBGIT2_TAG="$${LIBGIT2_TAG :-;;g' | sed 's;}";;g'))
210
213
@{ \
211
- echo " LIBGIT2_TAG must match in both Makefile and tests/fuzz/oss_fuzz_build .sh" ; \
214
+ echo " LIBGIT2_TAG must match in both Makefile and tests/fuzz/oss_fuzz_prebuild .sh" ; \
212
215
exit 1; \
213
216
}
214
217
endif
@@ -232,26 +235,32 @@ rm -rf $$TMP_DIR ;\
232
235
}
233
236
endef
234
237
235
- # Build fuzzers
238
+ # Build fuzzers used by oss-fuzz.
236
239
fuzz-build : $(LIBGIT2 )
237
- rm -rf $(BUILD_DIR ) /fuzz/
238
- mkdir -p $(BUILD_DIR ) /fuzz/out/
240
+ rm -rf $(shell pwd) /build /fuzz/
241
+ mkdir -p $(shell pwd) /build /fuzz/out/
239
242
240
- docker build . --pull -- tag local-fuzzing:latest -f tests/fuzz/Dockerfile.builder
243
+ docker build . --tag local-fuzzing:latest -f tests/fuzz/Dockerfile.builder
241
244
docker run --rm \
242
245
-e FUZZING_LANGUAGE=go -e SANITIZER=address \
243
246
-e CIFUZZ_DEBUG='True' -e OSS_FUZZ_PROJECT_NAME=fluxcd \
244
- -v "$(BUILD_DIR) /fuzz/out":/out \
247
+ -v "$(shell pwd)/build /fuzz/out":/out \
245
248
local-fuzzing:latest
246
249
250
+ # Run each fuzzer once to ensure they will work when executed by oss-fuzz.
247
251
fuzz-smoketest : fuzz-build
248
252
docker run --rm \
249
- -v " $( BUILD_DIR) /fuzz/out" :/out \
250
- -v " $( shell go env GOMODCACHE) :/root/go/pkg/mod" \
253
+ -v " $( shell pwd) /build/fuzz/out" :/out \
251
254
-v " $( shell pwd) /tests/fuzz/oss_fuzz_run.sh" :/runner.sh \
252
255
local-fuzzing:latest \
253
256
bash -c " /runner.sh"
254
257
258
+ # Run fuzz tests for the duration set in FUZZ_TIME.
259
+ fuzz-native :
260
+ KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS ) \
261
+ FUZZ_TIME=$(FUZZ_TIME ) \
262
+ ./tests/fuzz/native_go_run.sh
263
+
255
264
# Creates an env file that can be used to load all source-controller's dependencies
256
265
# this is handy when you want to run adhoc debug sessions on tests or start the
257
266
# controller in a new debug session.
0 commit comments