@@ -33,7 +33,11 @@ REPOSITORY_ROOT := $(shell git rev-parse --show-toplevel)
3333BUILD_DIR := $(REPOSITORY_ROOT ) /build
3434
3535# 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
3741
3842# Caches libgit2 versions per tag, "forcing" rebuild only when needed.
3943LIBGIT2_PATH := $(BUILD_DIR ) /libgit2/$(LIBGIT2_TAG )
@@ -134,7 +138,6 @@ tidy: ## Run go mod tidy
134138fmt : # # Run go fmt against code
135139 go fmt ./...
136140 cd api; go fmt ./...
137- cd tests/fuzz; go fmt .
138141
139142vet : $(LIBGIT2 ) # # Run go vet against code
140143 go vet ./...
@@ -206,9 +209,9 @@ ifneq ($(shell grep -o 'LIBGIT2_IMG ?= \w.*' Makefile | cut -d ' ' -f 3):$(shell
206209 exit 1; \
207210 }
208211endif
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'))
210213 @{ \
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" ; \
212215 exit 1; \
213216 }
214217endif
@@ -232,26 +235,32 @@ rm -rf $$TMP_DIR ;\
232235}
233236endef
234237
235- # Build fuzzers
238+ # Build fuzzers used by oss-fuzz.
236239fuzz-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/
239242
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
241244 docker run --rm \
242245 -e FUZZING_LANGUAGE=go -e SANITIZER=address \
243246 -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 \
245248 local-fuzzing:latest
246249
250+ # Run each fuzzer once to ensure they will work when executed by oss-fuzz.
247251fuzz-smoketest : fuzz-build
248252 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 \
251254 -v " $( shell pwd) /tests/fuzz/oss_fuzz_run.sh" :/runner.sh \
252255 local-fuzzing:latest \
253256 bash -c " /runner.sh"
254257
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+
255264# Creates an env file that can be used to load all source-controller's dependencies
256265# this is handy when you want to run adhoc debug sessions on tests or start the
257266# controller in a new debug session.
0 commit comments