bazelbuild / rules_fuzzing

Bazel Starlark extensions for defining fuzz tests in Bazel projects
Apache License 2.0
81 stars 19 forks source link

How do you run a cc_fuzz_test() against a specific input? #214

Open haberman opened 1 year ago

haberman commented 1 year ago

Expected Behavior

I can run the fuzz test against a known input, as described here: https://google.github.io/oss-fuzz/advanced-topics/reproducing/#fuzz-target-bugs

Actual Behavior

When I run the fuzz test, I get the following output:

mkdir: cannot create directory ‘/corpus’: Permission denied
mkdir: cannot create directory ‘/artifacts’: Permission denied
bazel-bin/upb/fuzz/file_descriptor_parsenew_fuzzer: line 12: /usr/local/google/home/haberman/code/upb/../rules_fuzzing/fuzzing/engines/libfuzzer_launcher.sh: No such file or directory

Steps to Reproduce the Problem

$ git clone https://github.com/protocolbuffers/upb.git
$ cd upb
$ bazel build -c opt --config=asan-libfuzzer upb/fuzz:file_descriptor_parsenew_fuzzer
$ bazel-bin/upb/fuzz/file_descriptor_parsenew_fuzzer /dev/null
mkdir: cannot create directory ‘/corpus’: Permission denied
mkdir: cannot create directory ‘/artifacts’: Permission denied
bazel-bin/upb/fuzz/file_descriptor_parsenew_fuzzer: line 12: /usr/local/google/home/haberman/code/upb/../rules_fuzzing/fuzzing/engines/libfuzzer_launcher.sh: No such file or directory

Specifications

cc @ericsalo

fmeum commented 1 year ago

Either of the following should work:

bazel run -c opt --config=asan-libfuzzer upb/fuzz:file_descriptor_parsenew_fuzzer_run -- --regression=true --corpus_dir= /some/file
bazel run -c opt --config=asan-libfuzzer upb/fuzz:file_descriptor_parsenew_fuzzer_bin /some/file

The *_run target is a Python launcher that accepts engine-agnostic arguments, *_bin gives you the raw libFuzzer binary.

haberman commented 1 year ago

Can documentation be added to the user guide for this?