| # 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 |
| } |
| |
| library_fuzzer(fuzzer_target) { |
| output_name = fuzzer_name |
| forward_variables_from(invoker, |
| "*", |
| [ |
| "configs", |
| "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", |
| ] |
| } |
| } |
| |
| set_defaults("fuchsia_library_fuzzer") { |
| configs = default_executable_configs |
| } |