Skip to content

Commit 6f7468c

Browse files
committed
adding template for pw_fuzz_tests
1 parent 2b9ffe6 commit 6f7468c

File tree

5 files changed

+97
-32
lines changed

5 files changed

+97
-32
lines changed

BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
6868
#":pw_module_tests.run($dir_pigweed/targets/host:host_clang_fuzz)",
6969
#"$dir_pigweed:pw_module_tests.run($dir_pigweed/targets/host:host_clang_fuzz)",
7070
# "${chip_root}/build/toolchain/pw_fuzzer:clang_pw_fuzz",
71-
"${chip_root}/src/lib/format/tests:FuzzPayloadDecoderPW(//build/toolchain/pw_fuzzer:clang_pw_fuzz)",
71+
"${chip_root}/src/lib/format/tests:FuzzPayloadDecoderPW(//build/toolchain/pw_fuzzer:chip_pw_fuzztest)",
7272
]
7373
}
7474
}

build/chip/fuzz_test.gni

+54
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
17+
import("//build_overrides/pigweed.gni")
18+
1719
import("${build_root}/config/compiler/compiler.gni")
1820
import("${chip_root}/build/chip/tests.gni")
21+
import("${dir_pw_unit_test}/test.gni")
1922

2023
declare_args() {
2124
enable_fuzz_test_targets = is_clang && chip_build_tests &&
@@ -68,3 +71,54 @@ template("chip_fuzz_target") {
6871
}
6972
}
7073
}
74+
75+
template("chip_pw_fuzz_target") {
76+
not_needed([ "target_name" ])
77+
if (!defined(invoker.sources)) {
78+
sources = []
79+
}
80+
if (!defined(invoker.public_deps)) {
81+
public_deps = []
82+
}
83+
if (!defined(invoker.deps)) {
84+
deps = []
85+
}
86+
87+
if (defined(invoker.test_sources)) {
88+
foreach(_test, invoker.test_sources) {
89+
_test_name = string_replace(_test, ".cpp", "")
90+
91+
_test_output_dir = "${root_out_dir}/fuzz_tests"
92+
if (defined(invoker.output_dir)) {
93+
_test_output_dir = invoker.output_dir
94+
}
95+
96+
pw_test(_test_name) {
97+
forward_variables_from(invoker,
98+
[
99+
"deps",
100+
"public_deps",
101+
"cflags",
102+
"configs",
103+
])
104+
105+
# TODO see what to do with this, I added it to try running FuzzTest with compatibility mode, since this is the mode supported by OSS-fuzz
106+
# defines = [
107+
# "FUZZTEST_COMPATIBILITY_MODE=libfuzzer",
108+
# "MAKE_BUILD_TYPE=RelWithDebug",
109+
# ]
110+
111+
#cflags = [ "-Wno-error=format-nonliteral" ] CAN NOT USE since strict_warning defines the opposite
112+
113+
sources = [ _test ]
114+
output_dir = _test_output_dir
115+
116+
deps += [ "$dir_pw_fuzzer:fuzztest" ]
117+
118+
# this is necessary so it is not disable in third_party/pigweed/repo/pw_unit_test/test.gni
119+
# otherwise it will be built successfully but with FuzzPayloadDecoderPW.DISABLED.ninja and no executable
120+
enable_if = true
121+
}
122+
}
123+
}
124+
}

build/config/compiler/BUILD.gn

+5-11
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ config("strict_warnings") {
239239
"-Wunreachable-code",
240240
"-Wvla",
241241
"-Wformat",
242-
"-Wformat-nonliteral",
242+
243+
#TODO: Remove this workaround to build FuzzTests; Abseil C++ submodule is has an error related to this warning
244+
#"-Wformat-nonliteral",
243245
"-Wformat-security",
244246
]
245247

@@ -308,8 +310,7 @@ config("strict_warnings") {
308310
config("warnings_default") {
309311
configs = [
310312
":warnings_common",
311-
312-
# ":strict_warnings",
313+
":strict_warnings",
313314
":disabled_warnings",
314315
]
315316
}
@@ -369,18 +370,11 @@ config("runtime_default") {
369370
}
370371
if (current_os == "linux" || current_os == "tizen" || current_os == "webos") {
371372
libs = [
373+
"atomic",
372374
"dl",
373375
"pthread",
374376
"rt",
375377
]
376-
377-
#TODO: see what to do with this workaround
378-
# work around because when building pw_fuzzer, the downstreamed pw_fuzzer toolchain makes us use --sysroot flag in the clang++ invocation; the sysroot flag points to the "clang_sysroot" subdirectory of the CIPD environemnt,
379-
# the clang_sysroot folder is populated from CIPD (fuchsia/third_party/sysroot/linux) which does not include the libatomic library and makes the FuzzTest linking fail
380-
# FYI, using the sysroot flag is only activated when pw_toolchain_OSS_FUZZ_ENABLED=false
381-
if (is_pw_fuzz == false) {
382-
libs += [ "atomic" ]
383-
}
384378
}
385379

386380
cflags = []

build/toolchain/pw_fuzzer/BUILD.gn

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import("$dir_pigweed/targets/host/target_toolchains.gni")
2222

2323
#import("$dir_pigweed/pw_toolchain/host_clang/toolchains.gni")
2424

25-
gcc_toolchain("clang_pw_fuzz") {
25+
gcc_toolchain("chip_pw_fuzztest") {
2626
toolchain_args = {
27-
name = "clang_pw_fuzz"
28-
print("gcc_toolchain(clang_pw_fuzz)")
27+
name = "chip_pw_fuzztest"
28+
print("gcc_toolchain(chip_pw_fuzztest)")
2929

3030
# print("pw_toolchain_host_clang = $pw_toolchain_host_clang")
3131
# forward_variables_from(pw_toolchain_host_clang.fuzz, "*", [ "name" ])
@@ -37,7 +37,8 @@ gcc_toolchain("clang_pw_fuzz") {
3737
#This is needed to have the defaults passed from pw_target_toolchain_host.clang_fuzz,
3838
forward_variables_from(defaults, "*")
3939

40-
#print("defaults = $defaults")
40+
print("defaults = $defaults")
41+
4142
print("pw_toolchain_FUZZING_ENABLED = ${pw_toolchain_FUZZING_ENABLED}")
4243
pw_unit_test_MAIN = "$dir_pw_fuzzer:fuzztest_main"
4344
pw_unit_test_BACKEND = "$dir_pw_fuzzer:gtest"

src/lib/format/tests/BUILD.gn

+32-16
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,41 @@ if (enable_fuzz_test_targets) {
5858
}
5959
}
6060

61-
if (pw_enable_fuzz_test_targets) {
62-
# DOCSTAG: [pwfuzzer_examples_fuzztest-gn]
63-
pw_test("FuzzPayloadDecoderPW") {
64-
sources = [ "FuzzPayloadDecoderPW.cpp" ]
61+
# if (pw_enable_fuzz_test_targets) {
62+
# # DOCSTAG: [pwfuzzer_examples_fuzztest-gn]
63+
# pw_test("FuzzPayloadDecoderPW") {
64+
# sources = [ "FuzzPayloadDecoderPW.cpp" ]
6565

66-
# print(" aAAAA: $dir_pw_fuzzer")
67-
deps = [
68-
#":pw_module_tests.run($dir_pigweed/targets/host:host_clang_fuzz)",
69-
"$dir_pw_fuzzer:fuzztest", # <- Added!
66+
# # print(" aAAAA: $dir_pw_fuzzer")
67+
# deps = [
68+
# #":pw_module_tests.run($dir_pigweed/targets/host:host_clang_fuzz)",
69+
# "$dir_pw_fuzzer:fuzztest", # <- Added!
7070

71-
# "${chip_root}/build/toolchain/pw_fuzzer:clang_pw_fuzz",
71+
# # "${chip_root}/build/toolchain/pw_fuzzer:clang_pw_fuzz",
72+
73+
# # "${chip_root}:fuzzers",
74+
# ]
75+
# public_deps = [
76+
# "${chip_root}/src/controller/data_model:cluster-tlv-metadata",
77+
# "${chip_root}/src/lib/core",
78+
# "${chip_root}/src/lib/format:flat-tree",
79+
# "${chip_root}/src/lib/format:protocol-decoder",
80+
# "${chip_root}/src/lib/format:protocol-tlv-metadata",
81+
# "${chip_root}/src/lib/support",
82+
# "${chip_root}/src/platform/logging:stdio",
83+
# ]
84+
85+
# # this is necessary so it is not disable in third_party/pigweed/repo/pw_unit_test/test.gni
86+
# # otherwise it will be built successfully but with FuzzPayloadDecoderPW.DISABLED.ninja and no executable
87+
88+
# enable_if = true
89+
# }
90+
# }
91+
92+
if (pw_enable_fuzz_test_targets) {
93+
chip_pw_fuzz_target("FuzzPayloadDecoder") {
94+
test_sources = [ "FuzzPayloadDecoderPW.cpp" ]
7295

73-
# "${chip_root}:fuzzers",
74-
]
7596
public_deps = [
7697
"${chip_root}/src/controller/data_model:cluster-tlv-metadata",
7798
"${chip_root}/src/lib/core",
@@ -81,10 +102,5 @@ if (pw_enable_fuzz_test_targets) {
81102
"${chip_root}/src/lib/support",
82103
"${chip_root}/src/platform/logging:stdio",
83104
]
84-
85-
# this is necessary so it is not disable in third_party/pigweed/repo/pw_unit_test/test.gni
86-
# otherwise it will be built successfully but with FuzzPayloadDecoderPW.DISABLED.ninja and no executable
87-
88-
enable_if = true
89105
}
90106
}

0 commit comments

Comments
 (0)