Skip to content

Commit

Permalink
Add coverage support for fuzzing_regression_test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyudg committed Jul 30, 2021
1 parent b2b3efd commit 0c28221
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,15 @@ build:asan-jazzer --@rules_fuzzing//fuzzing:cc_engine_instrumentation=jazzer
build:asan-jazzer --@rules_fuzzing//fuzzing:cc_engine_sanitizer=asan
# Workaround for https://github.com/bazelbuild/bazel/issues/11128
build:asan-jazzer --//fuzzing:cc_engine_sanitizer=asan

# Coverage with Replay (C/C++ only)
coverage --//fuzzing:cc_engine=//fuzzing/engines:replay
coverage --@rules_fuzzing//fuzzing:cc_engine_instrumentation=none
coverage --@rules_fuzzing//fuzzing:cc_engine_sanitizer=none
coverage --instrument_test_targets
coverage --action_env=BAZEL_USE_LLVM_NATIVE_COVERAGE=1
coverage --action_env=GCOV=llvm-profdata-10
coverage --action_env=BAZEL_LLVM_COV=llvm-cov-10
coverage --combined_report=lcov
coverage --experimental_use_llvm_covmap
coverage --experimental_generate_llvm_lcov
22 changes: 22 additions & 0 deletions .github/workflows/bazel_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ jobs:
bazel test --verbose_failures --test_output=all \
--build_tag_filters=fuzz-test --config=${{ matrix.config }} \
//examples:all
coverage:
name: Coverage gathering (C++)
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
target: ["//examples:empty_fuzz_test", "//examples:re2_fuzz_test"]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install -yq \
clang-10 \
libunwind-dev \
libblocksruntime-dev
- name: Gather coverage
run: |
bazel coverage ${{ matrix.target }}
- name: Check coverage gathered is non-empty
run: |
[[ -s bazel-out/_coverage/_coverage_report.dat ]]
fuzzer_run_tests_java:
name: Brief fuzz test runs (Java)
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions fuzzing/private/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ def _fuzzing_binary_impl(ctx):
engine_info = ctx.attr.engine[FuzzingEngineInfo],
options_file = ctx.file.options,
),
coverage_common.instrumented_files_info(
ctx,
dependency_attributes = ["binary"],
),
]

_common_fuzzing_binary_attrs = {
Expand Down
12 changes: 10 additions & 2 deletions fuzzing/private/regression.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ exec '{engine_launcher}'
runfiles = runfiles.merge(binary_info.engine_info.launcher_runfiles)
return [DefaultInfo(executable = script, runfiles = runfiles)]

fuzzing_regression_test = rule(
fuzzing_regression_test_script = rule(
implementation = _fuzzing_regression_test_impl,
doc = """
Executes a fuzz test on its seed corpus.
Expand All @@ -62,5 +62,13 @@ Executes a fuzz test on its seed corpus.
mandatory = True,
),
},
test = True,
)

def fuzzing_regression_test(name, binary, tags):
script_name = name + "_regression_test"
fuzzing_regression_test_script(name = script_name, binary = binary, tags = tags, testonly = True)
native.sh_test(
name = name,
srcs = [script_name],
data = [binary],
)

0 comments on commit 0c28221

Please sign in to comment.