rules.bzl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. """Rules for building fuzz tests."""
  5. load("@rules_cc//cc:defs.bzl", "cc_test")
  6. def cc_fuzz_test(
  7. name,
  8. corpus = None,
  9. args = [],
  10. data = [],
  11. features = [],
  12. tags = [],
  13. **kwargs):
  14. """Macro for C++ fuzzing test.
  15. Args:
  16. name: The main fuzz test rule name.
  17. corpus: List of files to use as a fuzzing corpus.
  18. args: Will have the locations of the corpus files added and passed down
  19. to the fuzz test.
  20. data: Will have the corpus added and passed down to the fuzz test.
  21. features: Will have the "fuzzer" feature added and passed down to the
  22. fuzz test.
  23. tags: Will have "fuzz_test" added and passed down to the fuzz test.
  24. **kwargs: Remaining arguments passed down to the fuzz test.
  25. """
  26. # Add relevant tag and feature if necessary.
  27. if "fuzz_test" not in tags:
  28. tags = tags + ["fuzz_test"]
  29. if "fuzzer" not in features:
  30. features = features + ["fuzzer"]
  31. # Append the corpus files to the test arguments. When run on a list of
  32. # files rather than a directory, libFuzzer-based fuzzers will perform a
  33. # regression test against the corpus.
  34. if corpus:
  35. data = data + corpus
  36. args = args + ["$(location %s)" % file for file in corpus]
  37. cc_test(
  38. name = name,
  39. args = args,
  40. data = data,
  41. features = features,
  42. tags = tags,
  43. **kwargs
  44. )