blob: 722ce425dab68d7948f3b3f22b480ab077d18156 [file]
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")
import("${build_root}/config/compiler/compiler.gni")
import("${chip_root}/build/chip/tests.gni")
import("${dir_pw_unit_test}/test.gni")
declare_args() {
#Fuzz testing using libfuzzer
enable_fuzz_test_targets =
(is_libfuzzer || oss_fuzz) && is_clang && chip_build_tests &&
(current_os == "linux" || current_os == "mac")
#Fuzz testing using pw_fuzzer and FuzzTest Framework
pw_enable_fuzz_test_targets = false
}
# Define a fuzz target for chip.
#
# Fuzz generally only apply on the following environments:
# - linux and mac host builds when using clang
#
# Sample usage
#
# chip_fuzz_target("fuzz-target-name") {
# sources = [
# "FuzzTarget.cpp", # Fuzz target
# ]
#
# public_deps = [
# "${chip_root}/src/lib/foo", # add dependencies here
# ]
# }
#
#
template("chip_fuzz_target") {
if (enable_fuzz_test_targets) {
executable(target_name) {
forward_variables_from(invoker, "*")
fuzz_configs = []
if (oss_fuzz) {
fuzz_configs += [ "//build/config/compiler:oss_fuzz" ]
} else {
fuzz_configs += [ "//build/config/compiler:libfuzzer_fuzzing" ]
# ASan is the default sanitizer for local libFuzzer builds. MSAN (is_msan) is
# mutually exclusive with ASan and is applied globally via sanitize_default
# (which pulls in the instrumented-sysroot libc++), so only add ASan here when
# not building MSAN.
if (!is_msan) {
fuzz_configs += [ "//build/config/compiler:sanitize_address" ]
}
}
if (defined(public_configs)) {
public_configs += fuzz_configs
} else {
public_configs = fuzz_configs
}
if (!defined(oubput_dir)) {
output_dir = "${root_out_dir}/tests"
}
}
}
}
# Define a fuzz target for Matter using pw_fuzzer and Google FuzzTest Framework.
#
# Google FuzzTest is only supported on Linux and MacOS using Clang:
#
# Sample usage
#
# chip_pw_fuzz_target("fuzz-target-name") {
# test_source = [
# "FuzzTarget.cpp", # Fuzz target
# ]
#
# public_deps = [
# "${chip_root}/src/lib/foo", # add dependencies here
# ]
# }
#
#
template("chip_pw_fuzz_target") {
if (defined(invoker.test_source)) {
_test_output_dir = "${root_out_dir}/tests"
if (defined(invoker.output_dir)) {
_test_output_dir = invoker.output_dir
}
pw_test(target_name) {
forward_variables_from(invoker,
[
"deps",
"public_deps",
"cflags",
"configs",
"remove_configs",
])
if (!defined(configs)) {
configs = []
}
if (use_coverage) {
configs += [ "${build_root}/config/compiler:coverage" ]
}
sources = invoker.test_source
output_dir = _test_output_dir
deps = [ "$dir_pw_fuzzer:fuzztest" ]
# this is necessary so FuzzTest is compiled into an executable in third_party/pigweed/repo/pw_unit_test/test.gni
# otherwise it will be built successfully but with FuzzTarget.DISABLED.ninja and no executable.
enable_if = true
}
}
}