| # Copyright 2021 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/config/current_target_tuple.gni") |
| import("//build/fidl/fidl.gni") |
| |
| fidl("test.fuzzer") { |
| visibility = [ "../*" ] |
| testonly = true |
| sources = [ "test.fuzzer.fidl" ] |
| public_deps = [ "//sdk/fidl/fuchsia.mem" ] |
| } |
| |
| # This config allows linking against libFuzzer regardless of the toolchain variant, which is useful |
| # for testing. |
| config("libfuzzer") { |
| # Use the runtimes.json file generated by the toolchain build to locate libFuzzer, and link it |
| # directly into the test fuzzer without involving clang's driver or adding any instrumentation. |
| clang_lib_dir = "//prebuilt/third_party/clang/$host_platform/lib" |
| runtime_json = read_file("$clang_lib_dir/runtime.json", "json") |
| libfuzzer = "" |
| foreach(variant, runtime_json) { |
| # TODO(fxbug.dev/84352): This is a workaround until "-fsanitize=fuzzer" is added to |
| # runtime.json. It assumes libclang_rt.asan.so and libclang_rt.fuzzer.a are co-located. |
| if (libfuzzer == "" && variant["cflags"] == [ "-fsanitize=address" ]) { |
| targets = [] |
| targets = variant["target"] |
| if (targets + [ current_target_tuple ] - [ current_target_tuple ] != |
| targets) { |
| runtimes = variant["runtime"] |
| runtime = runtimes[0] |
| staticlib = string_replace(runtime["dist"], "asan.so", "fuzzer.a") |
| libfuzzer = "$clang_lib_dir/$staticlib" |
| } |
| } |
| } |
| libs = [ libfuzzer ] |
| } |
| |
| executable("fuzzer") { |
| output_name = "libfuzzer_test_fuzzer" |
| visibility = [ "//src/sys/fuzzing/*" ] |
| testonly = true |
| sources = [ |
| "fuzzer.cc", |
| "fuzzer.h", |
| ] |
| public_deps = [ |
| ":test.fuzzer", |
| "//src/sys/fuzzing/common/testing", |
| ] |
| deps = [ |
| "//sdk/lib/sys/cpp", |
| "//sdk/lib/syslog/cpp", |
| "//src/sys/fuzzing/common/testing:sanitizer", |
| "//zircon/system/ulib/zx", |
| ] |
| configs += [ ":libfuzzer" ] |
| exclude_toolchain_tags = [ "instrumented" ] |
| } |
| |
| executable("relay") { |
| output_name = "libfuzzer_test_relay" |
| visibility = [ "//src/sys/fuzzing/*" ] |
| testonly = true |
| sources = [ |
| "relay-main.cc", |
| "relay.cc", |
| "relay.h", |
| ] |
| public_deps = [ |
| ":test.fuzzer", |
| "//sdk/lib/fidl/cpp", |
| "//sdk/lib/syslog/cpp", |
| "//sdk/testing/fidl:test_support", |
| "//src/lib/fxl", |
| "//src/sys/fuzzing/common", |
| "//zircon/system/ulib/sync", |
| ] |
| deps = [ "//sdk/lib/sys/cpp" ] |
| } |
| |
| executable("echo") { |
| output_name = "libfuzzer_test_echo" |
| visibility = [ "//src/sys/fuzzing/*" ] |
| testonly = true |
| sources = [ "echo.cc" ] |
| } |