Skip to content

Commit a003b56

Browse files
committed
latest trial to build pw_fuzz
1 parent ee49ebd commit a003b56

File tree

12 files changed

+204
-1
lines changed

12 files changed

+204
-1
lines changed

.gitmodules

+12
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,15 @@
325325
url = https://github.com/Infineon/optiga-trust-m.git
326326
branch = matter_support
327327
platforms = infineon
328+
[submodule "third_party/abseil-cpp/src"]
329+
path = third_party/abseil-cpp/src
330+
url = https://github.com/abseil/abseil-cpp.git
331+
[submodule "third_party/fuzztest"]
332+
path = third_party/fuzztest
333+
url = https://github.com/google/fuzztest.git
334+
[submodule "third_party/googletest"]
335+
path = third_party/googletest
336+
url = https://github.com/google/googletest
337+
[submodule "third_party/re2/src"]
338+
path = third_party/re2/src
339+
url = https://github.com/google/re2.git

BUILD.gn

+11
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
6161
}
6262
}
6363

64+
if (pw_enable_fuzz_test_targets) {
65+
group("pw_fuzz_tests") {
66+
deps = [
67+
#":pw_module_tests.run($dir_pigweed/targets/host:host_clang_fuzz)",
68+
#"$dir_pigweed:pw_module_tests.run($dir_pigweed/targets/host:host_clang_fuzz)",
69+
# "${chip_root}/build/toolchain/pw_fuzzer:clang_pw_fuzz",
70+
"${chip_root}/src/lib/format/tests:FuzzPayloadDecoderPW(//build/toolchain/pw_fuzzer:clang_pw_fuzz)",
71+
]
72+
}
73+
}
74+
6475
# Matter's in-tree pw_python_package or pw_python_distribution targets.
6576
_matter_python_packages = [
6677
"//examples/chef",

build/chip/fuzz_test.gni

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import("${chip_root}/build/chip/tests.gni")
2020
declare_args() {
2121
enable_fuzz_test_targets = is_clang && chip_build_tests &&
2222
(current_os == "linux" || current_os == "mac")
23+
24+
pw_enable_fuzz_test_targets = false
2325
}
2426

2527
# Define a fuzz target for chip.

build/config/BUILDCONFIG.gn

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ _chip_defaults = {
4747
declare_args() {
4848
# Toolchain to use for host. This is usually set by default.
4949
host_toolchain = ""
50+
51+
is_pw_fuzz = false
5052
}
5153

5254
if (host_toolchain == "") {
@@ -68,6 +70,9 @@ if (_chip_defaults.custom_toolchain != "") {
6870
} else {
6971
_default_toolchain = _chip_defaults.custom_toolchain
7072
}
73+
# } else if (is_pw_fuzz == true) {
74+
# _default_toolchain =
75+
# "${_build_overrides.build_root}/toolchain/pw_fuzzer:clang_pw_fuzz"
7176
} else if (target_os == "all") {
7277
_default_toolchain = "${_pigweed_overrides.dir_pw_toolchain}/default"
7378
} else if (target_os == "linux") {

build/config/compiler/BUILD.gn

+2-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ config("strict_warnings") {
307307
config("warnings_default") {
308308
configs = [
309309
":warnings_common",
310-
":strict_warnings",
310+
311+
# ":strict_warnings",
311312
":disabled_warnings",
312313
]
313314
}

build/toolchain/pw_fuzzer/BUILD.gn

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# TODO: maybe delete this file as it seems useless as of 25/06
16+
import("//build_overrides/build.gni")
17+
import("//build_overrides/pigweed.gni")
18+
19+
import("${build_root}/toolchain/gcc_toolchain.gni")
20+
21+
import("$dir_pigweed/targets/host/target_toolchains.gni")
22+
23+
#import("$dir_pigweed/pw_toolchain/host_clang/toolchains.gni")
24+
25+
gcc_toolchain("clang_pw_fuzz") {
26+
toolchain_args = {
27+
name = "clang_pw_fuzz"
28+
print("gcc_toolchain(clang_pw_fuzz)")
29+
30+
# print("pw_toolchain_host_clang = $pw_toolchain_host_clang")
31+
# forward_variables_from(pw_toolchain_host_clang.fuzz, "*", [ "name" ])
32+
33+
# print(
34+
# "pw_target_toolchain_host.clang_fuzz = ${pw_target_toolchain_host.clang_fuzz}")
35+
forward_variables_from(pw_target_toolchain_host.clang_fuzz, "*", [ "name" ])
36+
37+
#This is needed to have the defaults passed from pw_target_toolchain_host.clang_fuzz,
38+
forward_variables_from(defaults, "*")
39+
40+
#print("defaults = $defaults")
41+
print("pw_toolchain_FUZZING_ENABLED = ${pw_toolchain_FUZZING_ENABLED}")
42+
pw_unit_test_MAIN = "$dir_pw_fuzzer:fuzztest_main"
43+
pw_unit_test_BACKEND = "$dir_pw_fuzzer:gtest"
44+
45+
# below three lines are needed by gcc_toolchain template
46+
current_os = host_os
47+
current_cpu = host_cpu
48+
is_clang = true
49+
50+
# pw_toolchain_FUZZING_ENABLED = true
51+
treat_warnings_as_errors = false
52+
53+
# dir_pw_third_party_abseil_cpp = "$dir_pigweed/third_party/abseil-cpp/src"
54+
# dir_pw_third_party_fuzztest = "$dir_pigweed/third_party/fuzztest"
55+
# dir_pw_third_party_googletest = "$dir_pigweed/third_party/googletest"
56+
# dir_pw_third_party_re2 = "$dir_pigweed/third_party/re2/src"
57+
58+
#dir_pw_third_party_abseil_cpp = "$dir_pw_third_party/abseil-cpp/"
59+
60+
dir_pw_third_party_abseil_cpp = "//third_party/abseil-cpp/src"
61+
dir_pw_third_party_fuzztest = "//third_party/fuzztest"
62+
dir_pw_third_party_googletest = "//third_party/googletest"
63+
dir_pw_third_party_re2 = "//third_party/re2/src"
64+
65+
# use below if above dont work
66+
#dir_pw_third_party_abseil_cpp="//third_party/abseil-cpp"
67+
#dir_pw_third_party_re2 = "//third_party/re2"
68+
}
69+
}

src/lib/format/tests/BUILD.gn

+31
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,34 @@ if (enable_fuzz_test_targets) {
5656
]
5757
}
5858
}
59+
60+
if (pw_enable_fuzz_test_targets) {
61+
# DOCSTAG: [pwfuzzer_examples_fuzztest-gn]
62+
pw_test("FuzzPayloadDecoderPW") {
63+
sources = [ "FuzzPayloadDecoderPW.cpp" ]
64+
65+
# print(" aAAAA: $dir_pw_fuzzer")
66+
deps = [
67+
#":pw_module_tests.run($dir_pigweed/targets/host:host_clang_fuzz)",
68+
"$dir_pw_fuzzer:fuzztest", # <- Added!
69+
70+
# "${chip_root}/build/toolchain/pw_fuzzer:clang_pw_fuzz",
71+
72+
# "${chip_root}:fuzzers",
73+
]
74+
public_deps = [
75+
"${chip_root}/src/controller/data_model:cluster-tlv-metadata",
76+
"${chip_root}/src/lib/core",
77+
"${chip_root}/src/lib/format:flat-tree",
78+
"${chip_root}/src/lib/format:protocol-decoder",
79+
"${chip_root}/src/lib/format:protocol-tlv-metadata",
80+
"${chip_root}/src/lib/support",
81+
"${chip_root}/src/platform/logging:stdio",
82+
]
83+
84+
# this is necessary so it is not disable in third_party/pigweed/repo/pw_unit_test/test.gni
85+
# otherwise it will be built successfully but with FuzzPayloadDecoderPW.DISABLED.ninja and no executable
86+
87+
enable_if = true
88+
}
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
*
3+
* Copyright (c) 2020-2021 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
#include <cstddef>
19+
#include <cstdint>
20+
#include <lib/format/protocol_decoder.h>
21+
#include <lib/support/StringBuilder.h>
22+
23+
#include <tlv/meta/clusters_meta.h>
24+
#include <tlv/meta/protocols_meta.h>
25+
26+
#include <pw_unit_test/framework.h>
27+
#include <pw_fuzzer/fuzztest.h>
28+
29+
namespace {
30+
31+
using namespace chip::Decoders;
32+
using namespace chip::FlatTree;
33+
using namespace chip::TLV;
34+
using namespace chip::TLVMeta;
35+
36+
void RunDecodePW(const std::vector<std::uint8_t>& bytes)
37+
{
38+
const uint8_t* const data{bytes.data()};
39+
const int size{static_cast<int>(bytes.size())};
40+
41+
chip::ByteSpan payload(data, size);
42+
43+
PayloadDecoderInitParams params;
44+
params.SetProtocolDecodeTree(chip::TLVMeta::protocols_meta).SetClusterDecodeTree(chip::TLVMeta::clusters_meta);
45+
46+
47+
// Try some SC variants
48+
params.SetProtocol(chip::Protocols::SecureChannel::Id);
49+
params.SetMessageType(0);
50+
51+
chip::Decoders::PayloadDecoder<64, 128> decoder(params);
52+
53+
decoder.StartDecoding(payload);
54+
55+
printf("Test is running");
56+
57+
PayloadEntry entry;
58+
while (decoder.Next(entry))
59+
{
60+
// Nothing to do ...
61+
}
62+
}
63+
64+
65+
66+
67+
FUZZ_TEST(PayloadDecoder, RunDecodePW);
68+
}

third_party/abseil-cpp/src

Submodule src added at 3ab97e7

third_party/fuzztest

Submodule fuzztest added at 6eb010c

third_party/googletest

Submodule googletest added at 1d17ea1

third_party/re2/src

Submodule src added at 85dd7ad

0 commit comments

Comments
 (0)