blob: 1729cd0842f17406fa1c097f318060c3286fca5f [file] [edit]
# Copyright 2022 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/fuzzing/internal/library_fuzzer.gni")
# Creates a fuzzer binary.
#
# When built in a fuzzer toolchain variant, this template produces a fuzzer that uses libfuzzer as
# its fuzzing engine, and that is linked directly against one or more target libraries in the same
# process. The fuzzer generates and tests inputs in a loop, automatically discovering code paths and
# finding bugs.
#
# When built with a non-fuzzer toolchain variant, it produces a "fuzzer test" that exercises the
# same code as above with a set of fixed inputs. This is useful for ensuring the fuzzer code is
# buildable and, if inputs that previously caused are added to the fixed set, acting as a regression
# test.
#
# Parameters are the same as `executable` except that:
# $testonly cannot be set
# $variant_selector_target_type cannot be set
#
template("fuchsia_library_fuzzer") {
# Include the fuzzer executable.
fuzzer_target = "${target_name}_bin"
fuzzer_name = target_name
if (defined(invoker.output_name)) {
fuzzer_name = invoker.output_name
}
# 'expect_includes_deps': A list option that defines which include paths should
# be incorporated into the fuzzer manifest. This ensures that specific headers
# are included during fuzzer generation, particularly from dependencies that
# are necessary for proper compilation and testing.
expect_includes_deps = []
if (defined(invoker.expect_includes_deps)) {
expect_includes_deps = invoker.expect_includes_deps
} else {
expect_includes_deps = [ "//src/sys/fuzzing/libfuzzer:libfuzzer_includes" ]
}
library_fuzzer(fuzzer_target) {
output_name = fuzzer_name
forward_variables_from(invoker,
"*",
[
"configs",
"expect_includes_deps",
"output_name",
"target_type",
"visibility",
])
target_configs = invoker.configs
}
# Assemble the group.
group(target_name) {
testonly = true
forward_variables_from(invoker, [ "visibility" ])
deps = [
":$fuzzer_target",
"//src/sys/fuzzing/libfuzzer:engine-bin",
] + expect_includes_deps
}
}
set_defaults("fuchsia_library_fuzzer") {
configs = default_executable_configs
}