@@ -6,8 +6,6 @@ open source projects.
66The long running fuzzing execution is configured in the [ oss-fuzz repository] .
77Shorter executions are done on a per-PR basis, configured as a [ github workflow] .
88
9- For fuzzers to be called, they must be compiled within [ oss_fuzz_build.sh] ( ./oss_fuzz_build.sh ) .
10-
119### Testing locally
1210
1311Build fuzzers:
@@ -19,12 +17,12 @@ All fuzzers will be built into `./build/fuzz/out`.
1917
2018Smoke test fuzzers:
2119
20+ All the fuzzers will be built and executed once, to ensure they are fully functional.
21+
2222``` bash
2323make fuzz-smoketest
2424```
2525
26- The smoke test runs each fuzzer once to ensure they are fully functional.
27-
2826Run fuzzer locally:
2927``` bash
3028./build/fuzz/out/fuzz_conditions_match
@@ -39,6 +37,27 @@ Run fuzzer inside a container:
3937 /out/fuzz_conditions_match
4038```
4139
40+ ### Caveats of creating oss-fuzz compatible tests
41+
42+ #### Segregate fuzz tests
43+
44+ OSS-Fuzz does not properly support mixed ` *_test.go ` files, in which there is a combination
45+ of fuzz and non-fuzz tests. To mitigate this problem, ensure your fuzz tests are not in the
46+ same file as other Go tests. As a pattern, call your fuzz test files ` *_fuzz_test.go ` .
47+
48+ #### Build tags to avoid conflicts when running Go tests
49+
50+ Due to the issue above, code duplication will occur when creating fuzz tests that rely on
51+ helper functions that are shared with other tests. To avoid build issues, add a conditional
52+ build tag at the top of the ` *_fuzz_test.go ` file:
53+ ``` go
54+ // go:build gofuzz_libfuzzer
55+ // +build gofuzz_libfuzzer
56+ ```
57+
58+ The build tag above is set at [ go-118-fuzz-build] .
59+ At this point in time we can't pass on specific tags from [ compile_native_go_fuzzer] .
60+
4261### Running oss-fuzz locally
4362
4463The ` make fuzz-smoketest ` is meant to be an easy way to reproduce errors that may occur
@@ -59,3 +78,5 @@ For latest info on testing oss-fuzz locally, refer to the [upstream guide].
5978[ oss-fuzz repository ] : https://github.com/google/oss-fuzz/tree/master/projects/fluxcd
6079[ github workflow ] : .github/workflows/cifuzz.yaml
6180[ upstream guide ] : https://google.github.io/oss-fuzz/getting-started/new-project-guide/#testing-locally
81+ [ go-118-fuzz-build ] : https://github.com/AdamKorcz/go-118-fuzz-build/blob/b2031950a318d4f2dcf3ec3e128f904d5cf84623/main.go#L40
82+ [ compile_native_go_fuzzer ] : https://github.com/google/oss-fuzz/blob/c2d827cb78529fdc757c9b0b4fea0f1238a54814/infra/base-images/base-builder/compile_native_go_fuzzer#L32
0 commit comments