grpc_fuzzer.bzl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. Includes fuzzer rules.
  16. """
  17. load("//bazel:grpc_build_system.bzl", "grpc_cc_test")
  18. load("@rules_proto//proto:defs.bzl", "proto_library")
  19. load("@rules_cc//cc:defs.bzl", "cc_proto_library")
  20. def grpc_fuzzer(name, corpus, srcs = [], deps = [], data = [], size = "large", **kwargs):
  21. """Instantiates a fuzzer test.
  22. Args:
  23. name: The name of the test.
  24. corpus: The corpus for the test.
  25. srcs: The source files for the test.
  26. deps: The dependencies of the test.
  27. data: The data dependencies of the test.
  28. size: The size of the test.
  29. **kwargs: Other arguments to supply to the test.
  30. """
  31. CORPUS_DIR = native.package_name() + "/" + corpus
  32. grpc_cc_test(
  33. name = name,
  34. srcs = srcs,
  35. deps = deps + select({
  36. "//:grpc_build_fuzzers": [],
  37. "//conditions:default": ["//test/core/util:fuzzer_corpus_test"],
  38. }),
  39. data = data + native.glob([corpus + "/**"]),
  40. external_deps = [
  41. "gtest",
  42. ],
  43. size = size,
  44. args = select({
  45. "//:grpc_build_fuzzers": [CORPUS_DIR],
  46. "//conditions:default": ["--directory=" + CORPUS_DIR],
  47. }),
  48. **kwargs
  49. )
  50. def grpc_proto_fuzzer(name, corpus, proto, srcs = [], deps = [], data = [], size = "large", **kwargs):
  51. """Instantiates a protobuf mutator fuzzer test.
  52. Args:
  53. name: The name of the test.
  54. corpus: The corpus for the test.
  55. proto: The proto for the test.
  56. srcs: The source files for the test.
  57. deps: The dependencies of the test.
  58. data: The data dependencies of the test.
  59. size: The size of the test.
  60. **kwargs: Other arguments to supply to the test.
  61. """
  62. PROTO_LIBRARY = "_%s_proto" % name
  63. CC_PROTO_LIBRARY = "_%s_cc_proto" % name
  64. CORPUS_DIR = native.package_name() + "/" + corpus
  65. proto_library(
  66. name = PROTO_LIBRARY,
  67. srcs = [proto],
  68. )
  69. cc_proto_library(
  70. name = CC_PROTO_LIBRARY,
  71. deps = [PROTO_LIBRARY],
  72. )
  73. grpc_cc_test(
  74. name = name,
  75. srcs = srcs,
  76. deps = deps + [
  77. "@com_google_libprotobuf_mutator//:libprotobuf_mutator",
  78. CC_PROTO_LIBRARY,
  79. ] + select({
  80. "//:grpc_build_fuzzers": [],
  81. "//conditions:default": ["//test/core/util:fuzzer_corpus_test"],
  82. }),
  83. data = data + native.glob([corpus + "/**"]),
  84. external_deps = [
  85. "gtest",
  86. ],
  87. size = size,
  88. args = select({
  89. "//:grpc_build_fuzzers": [CORPUS_DIR],
  90. "//conditions:default": ["--directory=" + CORPUS_DIR],
  91. }),
  92. **kwargs
  93. )