@@ -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 )
@@ -206,9 +210,9 @@ ifneq ($(shell grep -o 'LIBGIT2_IMG ?= \w.*' Makefile | cut -d ' ' -f 3):$(shell
206
210
exit 1; \
207
211
}
208
212
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'))
213
+ 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
214
@{ \
211
- echo " LIBGIT2_TAG must match in both Makefile and tests/fuzz/oss_fuzz_build .sh" ; \
215
+ echo " LIBGIT2_TAG must match in both Makefile and tests/fuzz/oss_fuzz_prebuild .sh" ; \
212
216
exit 1; \
213
217
}
214
218
endif
@@ -232,26 +236,32 @@ rm -rf $$TMP_DIR ;\
232
236
}
233
237
endef
234
238
235
- # Build fuzzers
239
+ # Build fuzzers used by oss-fuzz.
236
240
fuzz-build : $(LIBGIT2 )
237
- rm -rf $(BUILD_DIR ) /fuzz/
238
- mkdir -p $(BUILD_DIR ) /fuzz/out/
241
+ rm -rf $(shell pwd) /build /fuzz/
242
+ mkdir -p $(shell pwd) /build /fuzz/out/
239
243
240
- docker build . --pull -- tag local-fuzzing:latest -f tests/fuzz/Dockerfile.builder
244
+ docker build . --tag local-fuzzing:latest -f tests/fuzz/Dockerfile.builder
241
245
docker run --rm \
242
246
-e FUZZING_LANGUAGE=go -e SANITIZER=address \
243
247
-e CIFUZZ_DEBUG='True' -e OSS_FUZZ_PROJECT_NAME=fluxcd \
244
- -v "$(BUILD_DIR) /fuzz/out":/out \
248
+ -v "$(shell pwd)/build /fuzz/out":/out \
245
249
local-fuzzing:latest
246
250
251
+ # Run each fuzzer once to ensure they will work when executed by oss-fuzz.
247
252
fuzz-smoketest : fuzz-build
248
253
docker run --rm \
249
- -v " $( BUILD_DIR) /fuzz/out" :/out \
250
- -v " $( shell go env GOMODCACHE) :/root/go/pkg/mod" \
254
+ -v " $( shell pwd) /build/fuzz/out" :/out \
251
255
-v " $( shell pwd) /tests/fuzz/oss_fuzz_run.sh" :/runner.sh \
252
256
local-fuzzing:latest \
253
257
bash -c " /runner.sh"
254
258
259
+ # Run fuzz tests for the duration set in FUZZ_TIME.
260
+ fuzz-native :
261
+ KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS ) \
262
+ FUZZ_TIME=$(FUZZ_TIME ) \
263
+ ./tests/fuzz/native_go_run.sh
264
+
255
265
# Creates an env file that can be used to load all source-controller's dependencies
256
266
# this is handy when you want to run adhoc debug sessions on tests or start the
257
267
# controller in a new debug session.
0 commit comments