Skip to content

Commit bb61ddf

Browse files
authored
Support "size" and "timeout" on *_fuzz_test (#204)
1 parent c4ae20c commit bb61ddf

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

examples/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ load("//fuzzing:cc_defs.bzl", "cc_fuzz_test")
2121

2222
cc_fuzz_test(
2323
name = "empty_fuzz_test",
24+
size = "small",
2425
srcs = ["empty_fuzz_test.cc"],
2526
)
2627

@@ -32,6 +33,7 @@ filegroup(
3233
# This target shows how to create a fuzz test target with corpus files.
3334
cc_fuzz_test(
3435
name = "empty_fuzz_test_with_corpus",
36+
timeout = "short",
3537
srcs = ["empty_fuzz_test.cc"],
3638
corpus = [
3739
"corpus_0.txt",

examples/java/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ filegroup(
2929

3030
java_fuzz_test(
3131
name = "EmptyFuzzTest",
32+
size = "small",
3233
srcs = ["com/example/EmptyFuzzTest.java"],
3334
corpus = [
3435
"corpus_0.txt",
@@ -37,6 +38,7 @@ java_fuzz_test(
3738

3839
java_fuzz_test(
3940
name = "FuzzTest",
41+
timeout = "short",
4042
srcs = ["com/example/FuzzTest.java"],
4143
tags = [
4244
"no-oss-fuzz",

fuzzing/private/fuzz_test.bzl

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def fuzzing_decoration(
3232
dicts = None,
3333
instrument_binary = True,
3434
define_regression_test = True,
35-
test_tags = None):
35+
test_size = None,
36+
test_tags = None,
37+
test_timeout = None):
3638
"""Generates the standard targets associated to a fuzz test.
3739
3840
This macro can be used to define custom fuzz test rules in case the default
@@ -62,7 +64,9 @@ def fuzzing_decoration(
6264
default instrumentation mode does not work for your use case, please
6365
file a Github issue to discuss.
6466
define_regression_test: If true, generate a regression test rule.
67+
test_size: The size of the fuzzing regression test.
6568
test_tags: Tags set on the fuzzing regression test.
69+
test_timeout: The timeout for the fuzzing regression test.
6670
"""
6771

6872
# We tag all non-test targets as "manual" in order to optimize the build
@@ -122,7 +126,9 @@ def fuzzing_decoration(
122126
fuzzing_regression_test(
123127
name = name,
124128
binary = instrum_binary_name,
129+
size = test_size,
125130
tags = test_tags,
131+
timeout = test_timeout,
126132
)
127133

128134
oss_fuzz_package(
@@ -138,7 +144,9 @@ def cc_fuzz_test(
138144
corpus = None,
139145
dicts = None,
140146
engine = "@rules_fuzzing//fuzzing:cc_engine",
147+
size = None,
141148
tags = None,
149+
timeout = None,
142150
**binary_kwargs):
143151
"""Defines a C++ fuzz test and a few associated tools and metadata.
144152
@@ -164,7 +172,11 @@ def cc_fuzz_test(
164172
corpus: A list containing corpus files.
165173
dicts: A list containing dictionaries.
166174
engine: A label pointing to the fuzzing engine to use.
167-
tags: Tags set on the fuzzing regression test.
175+
size: The size of the regression test. This does *not* affect fuzzing
176+
itself. Takes the [common size values](https://bazel.build/reference/be/common-definitions#test.size).
177+
tags: Tags set on the regression test.
178+
timeout: The timeout for the regression test. This does *not* affect
179+
fuzzing itself. Takes the [common timeout values](https://docs.bazel.build/versions/main/be/common-definitions.html#test.timeout).
168180
**binary_kwargs: Keyword arguments directly forwarded to the fuzz test
169181
binary rule.
170182
"""
@@ -194,9 +206,11 @@ def cc_fuzz_test(
194206
engine = engine,
195207
corpus = corpus,
196208
dicts = dicts,
209+
test_size = size,
197210
test_tags = (tags or []) + [
198211
"fuzz-test",
199212
],
213+
test_timeout = timeout,
200214
)
201215

202216
def java_fuzz_test(
@@ -206,7 +220,9 @@ def java_fuzz_test(
206220
corpus = None,
207221
dicts = None,
208222
engine = "@rules_fuzzing//fuzzing:java_engine",
223+
size = None,
209224
tags = None,
225+
timeout = None,
210226
**binary_kwargs):
211227
"""Defines a Java fuzz test and a few associated tools and metadata.
212228
@@ -235,7 +251,11 @@ def java_fuzz_test(
235251
corpus: A list containing corpus files.
236252
dicts: A list containing dictionaries.
237253
engine: A label pointing to the fuzzing engine to use.
238-
tags: Tags set on the fuzzing regression test.
254+
size: The size of the regression test. This does *not* affect fuzzing
255+
itself. Takes the [common size values](https://bazel.build/reference/be/common-definitions#test.size).
256+
tags: Tags set on the regression test.
257+
timeout: The timeout for the regression test. This does *not* affect
258+
fuzzing itself. Takes the [common timeout values](https://docs.bazel.build/versions/main/be/common-definitions.html#test.timeout).
239259
**binary_kwargs: Keyword arguments directly forwarded to the fuzz test
240260
binary rule.
241261
"""
@@ -316,7 +336,9 @@ def java_fuzz_test(
316336
engine = engine,
317337
corpus = corpus,
318338
dicts = dicts,
339+
test_size = size,
319340
test_tags = (tags or []) + [
320341
"fuzz-test",
321342
],
343+
test_timeout = timeout,
322344
)

0 commit comments

Comments
 (0)