Files
carbon-lang/bazel/fuzzing/rules.bzl
T
Chandler Carruth 6aae31b65b Merge LLVM and Bazel infra from the toolchain repository. (#207)
The Bazel bits are collected into a directory and given less confusing
names (I hope). Other than names, everything is a direct copy from the
toolchain repository without any edits.

A few files needed to be merged in:
- `.gitignore`
- `.pre-commit-config.yaml`

Subsequent commits will add relevant C++ infrastructure and then the
source code itself.
2020-12-04 19:26:07 -08:00

52 lines
1.6 KiB
Python

# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""Rules for building fuzz tests."""
load("@rules_cc//cc:defs.bzl", "cc_test")
def cc_fuzz_test(
name,
corpus = None,
args = [],
data = [],
features = [],
tags = [],
**kwargs):
"""Macro for C++ fuzzing test.
Args:
name: The main fuzz test rule name.
corpus: List of files to use as a fuzzing corpus.
args: Will have the locations of the corpus files added and passed down
to the fuzz test.
data: Will have the corpus added and passed down to the fuzz test.
features: Will have the "fuzzer" feature added and passed down to the
fuzz test.
tags: Will have "fuzz_test" added and passed down to the fuzz test.
**kwargs: Remaining arguments passed down to the fuzz test.
"""
# Add relevant tag and feature if necessary.
if "fuzz_test" not in tags:
tags = tags + ["fuzz_test"]
if "fuzzer" not in features:
features = features + ["fuzzer"]
# Append the corpus files to the test arguments. When run on a list of
# files rather than a directory, libFuzzer-based fuzzers will perform a
# regression test against the corpus.
if corpus:
data = data + corpus
args = args + ["$(location %s)" % file for file in corpus]
cc_test(
name = name,
args = args,
data = data,
features = features,
tags = tags,
**kwargs
)