commit | 714854659c044c96c08c054657fb7fcacb863995 | [log] [tgz] |
---|---|---|
author | Stefan Bucur <281483+stefanbucur@users.noreply.github.com> | Fri Oct 23 15:18:51 2020 -0400 |
committer | GitHub <noreply@github.com> | Fri Oct 23 15:18:51 2020 -0400 |
tree | 28736da931e11404eda90873007f7bb27e69a855 | |
parent | 704d600fd2e5f8b0ee27f0eea15e0df1d6490f4a [diff] |
Formatting nit: Remove empty comment lines. (#70) They occur at the beginning of each file and add up to the vertical space.
This repository contains Bazel Starlark extensions for defining fuzz tests in Bazel projects.
This is not an officially supported Google product.
To import the fuzzing rules in your project, you first need to add the snippet below to your WORKSPACE
file:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "rules_fuzzing", sha256 = "8901c2438fb94b55b160e82dd14a8fc3c208f948497822946319c60939c34c4f", strip_prefix = "bazel-rules-fuzzing-bc4b3afc59a56cec8c61f964efa93fa81e3eb6a8", urls = ["https://github.com/googleinterns/bazel-rules-fuzzing/archive/bc4b3afc59a56cec8c61f964efa93fa81e3eb6a8.zip"], ) load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies") rules_fuzzing_dependencies() load("@rules_fuzzing//fuzzing:dependency_imports.bzl", "fuzzing_dependency_imports") fuzzing_dependency_imports() load("@fuzzing_py_deps//:requirements.bzl", fuzzing_py_install = "pip_install") fuzzing_py_install()
Our project is under active development, to use the latest feature, change the urls
and sha256
value above to the latest commit.
Tiny example:
Assume that you have a fuzz_test.cc
file to do the fuzzing test and corpus files corpus_1.txt
and corpus_dir/*
.
You can create a fuzz test target in the BUILD
like below:
load("@rules_fuzzing//fuzzing:cc_deps.bzl", "cc_fuzz_test") cc_fuzz_test( name = "fuzz_test", srcs = ["fuzz_test.cc"], corpus = ["corpus_1.txt"] + glob(["corpus_dir/**"], )
If your .bazelrc
in the project root directory has config libfuzzer
:
build:libfuzzer --action_env=CC=clang build:libfuzzer --action_env=CXX=clang++ build:libfuzzer --linkopt=-fsanitize=fuzzer build:libfuzzer --copt=-fsanitize=fuzzer build:libfuzzer --@rules_fuzzing//fuzzing:engine=libfuzzer
you then can run the fuzz test above using command
bazel run fuzz_test_run --config=libfuzzer
You can also control the fuzzing test running time by passing --timeout_secs
like
bazel run fuzz_test_run --config=libfuzzer -- --timeout_secs=20
If you only want to run the regression test on the corpus, set --regression
:
bazel run fuzz_test_run --config=libfuzzer -- --regression=True
Feel free to copy the config setting in .bazelrc to yours.
See the examples directory for more examples.