Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "size" and "timeout" on *_fuzz_test #204

Merged
merged 1 commit into from
Jun 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 25 additions & 3 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 @@ -164,7 +172,11 @@ def cc_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 @@ -194,9 +206,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 +220,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 +251,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 +336,9 @@ def java_fuzz_test(
engine = engine,
corpus = corpus,
dicts = dicts,
test_size = size,
test_tags = (tags or []) + [
"fuzz-test",
],
test_timeout = timeout,
)