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""" 16Includes fuzzer rules. 17""" 18 19load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_proto_library") 20 21def grpc_fuzzer(name, corpus, owner = "grpc", 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 owner: The owning team of the test (for auto-bug-filing). 34 **kwargs: Other arguments to supply to the test. 35 """ 36 CORPUS_DIR = native.package_name() + "/" + corpus 37 grpc_cc_test( 38 name = name, 39 srcs = srcs, 40 tags = tags + ["grpc-fuzzer", "no-cache"], 41 deps = deps + select({ 42 "//:grpc_build_fuzzers": [], 43 "//conditions:default": ["//test/core/util:fuzzer_corpus_test"], 44 }), 45 data = data + native.glob([corpus + "/**"]), 46 external_deps = external_deps + [ 47 "gtest", 48 ], 49 size = size, 50 args = select({ 51 "//:grpc_build_fuzzers": [CORPUS_DIR, "-runs=20000", "-max_total_time=300"], 52 "//conditions:default": ["--directory=" + CORPUS_DIR], 53 }), 54 **kwargs 55 ) 56 57def grpc_proto_fuzzer(name, corpus, proto, owner = "grpc", proto_deps = [], external_deps = [], srcs = [], tags = [], deps = [], data = [], size = "large", **kwargs): 58 """Instantiates a protobuf mutator fuzzer test. 59 60 Args: 61 name: The name of the test. 62 corpus: The corpus for the test. 63 proto: The proto for the test. If empty, it assumes the proto dependency 64 is already included in the target deps. Otherwise it creates a 65 new grpc_proto_library with name "_{name}_proto" and makes the 66 fuzz target depend on it. 67 proto_deps: Deps for proto. Only used if proto is not empty. 68 external_deps: External deps. 69 srcs: The source files for the test. 70 deps: The dependencies of the test. 71 data: The data dependencies of the test. 72 size: The size of the test. 73 tags: The tags for the test. 74 owner: The owning team of the test (for auto-bug-filing). 75 **kwargs: Other arguments to supply to the test. 76 """ 77 CORPUS_DIR = native.package_name() + "/" + corpus 78 deps = deps + ["@com_google_libprotobuf_mutator//:libprotobuf_mutator"] 79 80 if "gtest" not in external_deps: 81 external_deps = external_deps + ["gtest"] 82 83 if proto != None: 84 PROTO_LIBRARY = "_%s_proto" % name 85 grpc_proto_library( 86 name = PROTO_LIBRARY, 87 srcs = [proto], 88 deps = proto_deps, 89 has_services = False, 90 ) 91 deps = deps + [PROTO_LIBRARY] 92 93 grpc_cc_test( 94 name = name, 95 srcs = srcs, 96 tags = tags + ["grpc-fuzzer", "no-cache"], 97 deps = deps + select({ 98 "//:grpc_build_fuzzers": [], 99 "//conditions:default": ["//test/core/util:fuzzer_corpus_test"], 100 }), 101 data = data + native.glob([corpus + "/**"]), 102 external_deps = external_deps, 103 size = size, 104 args = select({ 105 "//:grpc_build_fuzzers": [CORPUS_DIR, "-runs=20000", "-max_total_time=300"], 106 "//conditions:default": ["--directory=" + CORPUS_DIR], 107 }), 108 **kwargs 109 ) 110