Skip to content

Commit

Permalink
Fuzz reuse (#8119)
Browse files Browse the repository at this point in the history
This PR allows the envoy_cc_fuzz_test rule to be used when pulling in envoy. which can be useful when you're writing filters for envoy, and want to reuse the fuzzing architecture envoy has already built. other rules already allow for this (see envoy_cc_test in this same file for example).

Risk Level: Low
Testing:

Testing the Old Rule Still Works

It is possible to test the old rules still work (even without specifying a repository), by simply choosing your favorite fuzz test, and choosing to run bazel test on it. For example: bazel test //test/common/router:header_parser_fuzz_test. Any envoy_cc_fuzz_test rule should do.

Testing New Rules Work

I've done testing inside my own repository, but if you want to create your own test rule you can probably do the following in envoy-filter-example:

Checkout envoy-filter-example, and update the envoy submodule to this pr.
Follow the directions in: test/fuzz/README.md to define a envoy_cc_fuzz_test rule. Make sure to add a line for: repository = "@envoy" which is the new argument being added.
You should be able to run the fuzz test.

Signed-off-by: Cynthia Coan <[email protected]>
  • Loading branch information
securityinsanity authored and htuch committed Sep 3, 2019
1 parent dad0f2e commit 0eab93b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions bazel/envoy_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,15 @@ def _envoy_test_linkopts():
}) + envoy_select_force_libcpp([], ["-lstdc++fs", "-latomic"])

# Envoy C++ fuzz test targets. These are not included in coverage runs.
def envoy_cc_fuzz_test(name, corpus, deps = [], tags = [], **kwargs):
if not (corpus.startswith("//") or corpus.startswith(":")):
def envoy_cc_fuzz_test(
name,
corpus,
repository = "",
size = "medium",
deps = [],
tags = [],
**kwargs):
if not (corpus.startswith("//") or corpus.startswith(":") or corpus.startswith("@")):
corpus_name = name + "_corpus"
corpus = native.glob([corpus + "/**"])
native.filegroup(
Expand All @@ -81,7 +88,11 @@ def envoy_cc_fuzz_test(name, corpus, deps = [], tags = [], **kwargs):
test_lib_name = name + "_lib"
envoy_cc_test_library(
name = test_lib_name,
deps = deps + ["//test/fuzz:fuzz_runner_lib", "//bazel:dynamic_stdlib"],
deps = deps + [
repository + "//test/fuzz:fuzz_runner_lib",
repository + "//bazel:dynamic_stdlib",
],
repository = repository,
**kwargs
)
native.cc_test(
Expand All @@ -93,12 +104,13 @@ def envoy_cc_fuzz_test(name, corpus, deps = [], tags = [], **kwargs):
data = [corpus_name],
# No fuzzing on macOS.
deps = select({
"@envoy//bazel:apple": ["//test:dummy_main"],
"@envoy//bazel:apple": [repository + "//test:dummy_main"],
"//conditions:default": [
":" + test_lib_name,
"//test/fuzz:main",
repository + "//test/fuzz:main",
],
}),
size = size,
tags = tags,
)

Expand Down

0 comments on commit 0eab93b

Please sign in to comment.