| 1 |
# Copyright 2016 gRPC authors. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
""" |
| 16 |
Includes fuzzer rules. |
| 17 |
""" |
| 18 |
|
| 19 |
load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_proto_library") |
| 20 |
|
| 21 |
def grpc_fuzzer(name, corpus, srcs = [], tags = [], external_deps = [], deps = [], data = [], size = "large", **kwargs): |
| 22 |
"""Instantiates a fuzzer test. |
| 23 |
|
| 24 |
Args: |
| 25 |
name: The name of the test. |
| 26 |
corpus: The corpus for the test. |
| 27 |
srcs: The source files for the test. |
| 28 |
external_deps: External deps. |
| 29 |
deps: The dependencies of the test. |
| 30 |
data: The data dependencies of the test. |
| 31 |
size: The size of the test. |
| 32 |
tags: The tags for the test. |
| 33 |
**kwargs: Other arguments to supply to the test. |
| 34 |
""" |
| 35 |
CORPUS_DIR = native.package_name() + "/" + corpus |
| 36 |
grpc_cc_test( |
| 37 |
name = name, |
| 38 |
srcs = srcs, |
| 39 |
tags = tags + ["grpc-fuzzer", "no-cache"], |
| 40 |
deps = deps + select({ |
| 41 |
"//:grpc_build_fuzzers": [], |
| 42 |
"//conditions:default": ["//test/core/util:fuzzer_corpus_test"], |
| 43 |
}), |
| 44 |
data = data + native.glob([corpus + "/**"]), |
| 45 |
external_deps = external_deps + [ |
| 46 |
"gtest", |
| 47 |
], |
| 48 |
size = size, |
| 49 |
args = select({ |
| 50 |
"//:grpc_build_fuzzers": [CORPUS_DIR, "-runs=20000", "-max_total_time=300"], |
| 51 |
"//conditions:default": ["--directory=" + CORPUS_DIR], |
| 52 |
}), |
| 53 |
**kwargs |
| 54 |
) |
| 55 |
|
| 56 |
def grpc_proto_fuzzer(name, corpus, proto, proto_deps = [], external_deps = [], srcs = [], tags = [], deps = [], data = [], size = "large", **kwargs): |
| 57 |
"""Instantiates a protobuf mutator fuzzer test. |
| 58 |
|
| 59 |
Args: |
| 60 |
name: The name of the test. |
| 61 |
corpus: The corpus for the test. |
| 62 |
proto: The proto for the test. |
| 63 |
proto_deps: Deps for proto. |
| 64 |
external_deps: External deps. |
| 65 |
srcs: The source files for the test. |
| 66 |
deps: The dependencies of the test. |
| 67 |
data: The data dependencies of the test. |
| 68 |
size: The size of the test. |
| 69 |
tags: The tags for the test. |
| 70 |
**kwargs: Other arguments to supply to the test. |
| 71 |
""" |
| 72 |
PROTO_LIBRARY = "_%s_proto" % name |
| 73 |
CORPUS_DIR = native.package_name() + "/" + corpus |
| 74 |
|
| 75 |
grpc_proto_library( |
| 76 |
name = PROTO_LIBRARY, |
| 77 |
srcs = [proto], |
| 78 |
deps = proto_deps, |
| 79 |
has_services = False, |
| 80 |
) |
| 81 |
|
| 82 |
grpc_cc_test( |
| 83 |
name = name, |
| 84 |
srcs = srcs, |
| 85 |
tags = tags + ["grpc-fuzzer", "no-cache"], |
| 86 |
deps = deps + [ |
| 87 |
"@com_google_libprotobuf_mutator//:libprotobuf_mutator", |
| 88 |
PROTO_LIBRARY, |
| 89 |
] + select({ |
| 90 |
"//:grpc_build_fuzzers": [], |
| 91 |
"//conditions:default": ["//test/core/util:fuzzer_corpus_test"], |
| 92 |
}), |
| 93 |
data = data + native.glob([corpus + "/**"]), |
| 94 |
external_deps = external_deps + [ |
| 95 |
"gtest", |
| 96 |
], |
| 97 |
size = size, |
| 98 |
args = select({ |
| 99 |
"//:grpc_build_fuzzers": [CORPUS_DIR, "-runs=20000", "-max_total_time=300"], |
| 100 |
"//conditions:default": ["--directory=" + CORPUS_DIR], |
| 101 |
}), |
| 102 |
**kwargs |
| 103 |
) |