blob: 762879115842522f1744f3718d67ba952e9175ff [file] [log] [blame]
# Copyright 2020 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/cpp/fidl_cpp.gni")
import("//build/fuzzing/fuchsia_library_fuzzer.gni")
# Defines service provider for a generated FIDL fuzzer
#
# The fidl() template supports a list of `fuzzers` that contain a `protocol`
# string and optional list of `methods`. Each of the fidl()'s `fuzzers`
# generates a library target of the form:
#
# [fidl() target name]_libfuzzer_[protocol]_[method1 name]_[method2 name]...
#
# The target contains the core fuzzer logic, but relies on symbols that must be
# defined by the FIDL service implementer for providing an instance of the
# service to fuzz.
#
# This template is a helper for tying together the above-mentioned target and
# the sources and/or deps necessary to provide the above-mentioned symbols.
#
# NOTE: The `protocol` and `methods` passed to this template must _exactly_
# match one of the `fuzzers` defined on the corresponding fidl() rule.
#
# Parameters
#
# fidl (required)
# [label] The `fidl()` label that includes the protocol to be fuzzed.
#
# protocol (required)
# [fully-qualified FIDL protocol name] The fully-qualified name of the FIDL
# protocol to be fuzzed.
#
# methods (optional)
# [list of strings] The names of the methods to be fuzzed, as they appear in
# the FIDL file. These are translated into defines that enable fuzzing code
# for the appropriate methods. Defaults to special define value for fuzzing
# all methods of the specified protocol.
#
# Other parameters are precisely those of an `executable`, with their usual GN
# meanings; these parameters are forwarded to the generated fuzzer() template.
template("fidl_protocol_fuzzer") {
if (is_fuchsia) {
assert(
defined(invoker.protocol),
"FIDL fuzzer service provider must set protocol: the fully-qualified name of the protocol to be fuzzed.")
assert(
defined(invoker.fidl),
"FIDL fuzzer service provider must set fidl: the fidl() target defining the corresponding fuzzer.")
protocol_suffix = string_replace(invoker.protocol, ".", "_")
if (defined(invoker.methods)) {
foreach(method, invoker.methods) {
protocol_suffix = "${protocol_suffix}_${method}"
}
}
fuchsia_library_fuzzer(target_name) {
deps = []
forward_variables_from(invoker,
"*",
[
"protocol",
"fidl",
"methods",
])
deps += [
"${invoker.fidl}_libfuzzer_${protocol_suffix}",
"//sdk/lib/fidl/cpp/fuzzing",
]
}
}
}