Skip to content

Commit

Permalink
Support "size" and "timeout" on *_fuzz_test
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jun 5, 2022
1 parent 5fbb483 commit a9388dc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ load("//fuzzing:cc_defs.bzl", "cc_fuzz_test")

cc_fuzz_test(
name = "empty_fuzz_test",
size = "small",
srcs = ["empty_fuzz_test.cc"],
)

Expand All @@ -32,6 +33,7 @@ filegroup(
# This target shows how to create a fuzz test target with corpus files.
cc_fuzz_test(
name = "empty_fuzz_test_with_corpus",
timeout = "short",
srcs = ["empty_fuzz_test.cc"],
corpus = [
"corpus_0.txt",
Expand Down
2 changes: 2 additions & 0 deletions examples/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ filegroup(

java_fuzz_test(
name = "EmptyFuzzTest",
size = "small",
srcs = ["com/example/EmptyFuzzTest.java"],
corpus = [
"corpus_0.txt",
Expand All @@ -37,6 +38,7 @@ java_fuzz_test(

java_fuzz_test(
name = "FuzzTest",
timeout = "short",
srcs = ["com/example/FuzzTest.java"],
tags = [
"no-oss-fuzz",
Expand Down
29 changes: 25 additions & 4 deletions fuzzing/private/fuzz_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def fuzzing_decoration(
dicts = None,
instrument_binary = True,
define_regression_test = True,
test_tags = None):
test_size = None,
test_tags = None,
test_timeout = None):
"""Generates the standard targets associated to a fuzz test.
This macro can be used to define custom fuzz test rules in case the default
Expand Down Expand Up @@ -62,7 +64,9 @@ def fuzzing_decoration(
default instrumentation mode does not work for your use case, please
file a Github issue to discuss.
define_regression_test: If true, generate a regression test rule.
test_size: The size of the fuzzing regression test.
test_tags: Tags set on the fuzzing regression test.
test_timeout: The timeout for the fuzzing regression test.
"""

# We tag all non-test targets as "manual" in order to optimize the build
Expand Down Expand Up @@ -122,7 +126,9 @@ def fuzzing_decoration(
fuzzing_regression_test(
name = name,
binary = instrum_binary_name,
size = test_size,
tags = test_tags,
timeout = test_timeout,
)

oss_fuzz_package(
Expand All @@ -138,7 +144,9 @@ def cc_fuzz_test(
corpus = None,
dicts = None,
engine = "@rules_fuzzing//fuzzing:cc_engine",
size = None,
tags = None,
timeout = None,
**binary_kwargs):
"""Defines a C++ fuzz test and a few associated tools and metadata.
Expand All @@ -163,8 +171,11 @@ def cc_fuzz_test(
name: A unique name for this target. Required.
corpus: A list containing corpus files.
dicts: A list containing dictionaries.
engine: A label pointing to the fuzzing engine to use.
tags: Tags set on the fuzzing regression test.
size: The size of the regression test. This does *not* affect fuzzing
itself. Takes the [common size values](https://bazel.build/reference/be/common-definitions#test.size).
tags: Tags set on the regression test.
timeout: The timeout for the regression test. This does *not* affect
fuzzing itself. Takes the [common timeout values](https://docs.bazel.build/versions/main/be/common-definitions.html#test.timeout).
**binary_kwargs: Keyword arguments directly forwarded to the fuzz test
binary rule.
"""
Expand Down Expand Up @@ -194,9 +205,11 @@ def cc_fuzz_test(
engine = engine,
corpus = corpus,
dicts = dicts,
test_size = size,
test_tags = (tags or []) + [
"fuzz-test",
],
test_timeout = timeout,
)

def java_fuzz_test(
Expand All @@ -206,7 +219,9 @@ def java_fuzz_test(
corpus = None,
dicts = None,
engine = "@rules_fuzzing//fuzzing:java_engine",
size = None,
tags = None,
timeout = None,
**binary_kwargs):
"""Defines a Java fuzz test and a few associated tools and metadata.
Expand Down Expand Up @@ -235,7 +250,11 @@ def java_fuzz_test(
corpus: A list containing corpus files.
dicts: A list containing dictionaries.
engine: A label pointing to the fuzzing engine to use.
tags: Tags set on the fuzzing regression test.
size: The size of the regression test. This does *not* affect fuzzing
itself. Takes the [common size values](https://bazel.build/reference/be/common-definitions#test.size).
tags: Tags set on the regression test.
timeout: The timeout for the regression test. This does *not* affect
fuzzing itself. Takes the [common timeout values](https://docs.bazel.build/versions/main/be/common-definitions.html#test.timeout).
**binary_kwargs: Keyword arguments directly forwarded to the fuzz test
binary rule.
"""
Expand Down Expand Up @@ -316,7 +335,9 @@ def java_fuzz_test(
engine = engine,
corpus = corpus,
dicts = dicts,
test_size = size,
test_tags = (tags or []) + [
"fuzz-test",
],
test_timeout = timeout,
)

0 comments on commit a9388dc

Please sign in to comment.