| # 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/dist/resource.gni") | |
| import("//build/fidl/fidl.gni") | |
| fidl("test.fuzzer") { | |
| visibility = [ "../*" ] | |
| testonly = true | |
| sources = [ "test.fuzzer.fidl" ] | |
| public_deps = [ "//zircon/vdso/zx" ] | |
| enable_hlcpp = true | |
| } | |
| # 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(https://fxbug.dev/42165131): 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_unittest_fuzzer" | |
| visibility = [ "//src/sys/fuzzing/*" ] | |
| testonly = true | |
| sources = [ | |
| "fuzzer.cc", | |
| "fuzzer.h", | |
| ] | |
| deps = [ | |
| ":test.fuzzer_hlcpp", | |
| "//sdk/lib/sys/cpp", | |
| "//sdk/lib/syslog/cpp", | |
| "//src/sys/fuzzing/common/testing", | |
| "//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", | |
| ] | |
| deps = [ | |
| ":test.fuzzer_hlcpp", | |
| "//sdk/lib/sys/cpp", | |
| "//sdk/lib/syslog/cpp", | |
| "//sdk/testing/fidl:test_support", | |
| "//src/lib/fxl", | |
| "//src/sys/fuzzing/common", | |
| "//zircon/system/ulib/sync", | |
| ] | |
| } | |
| resource("data") { | |
| sources = [ | |
| "data/cert_fuzzer.stderr", | |
| "data/test_fuzzer.stderr", | |
| ] | |
| outputs = [ "data/{{source_file_part}}" ] | |
| } |