blob: ce98b40655c5ab70dc27e374f44b14d17c985356 [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.
# 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") {
"FIDL fuzzer service provider must set protocol: the fully-qualified name of the protocol to be fuzzed.")
"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}"
if (defined(invoker.deps)) {
fuzzer_deps = invoker.deps
} else {
fuzzer_deps = []
fuzzer_deps += [
fuzzer(target_name) {
deps = fuzzer_deps