blob: 5a430216e8b5d5783e1bf366b479ddd0ea98a823 [file] [log] [blame]
Aaron Greenf3c3d2b2020-04-02 23:12:31 -07001# Copyright 2020 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7# https://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, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("$dir_pw_docgen/docs.gni")
16import("$dir_pw_fuzzer/fuzzer.gni")
17
18declare_args() {
19 # Sets the sanitizer to pass to clang. Valid values are those for "-fsanitize"
20 # listed in https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html.
21 pw_sanitizer = ""
22}
23
Aaron Green33c67822020-04-06 13:47:38 -070024config("default_config") {
25 include_dirs = [ "public" ]
26}
27
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070028# This is added automatically by the `pw_fuzzer` template.
Aaron Green33c67822020-04-06 13:47:38 -070029config("fuzzing") {
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070030 common_flags = [ "-fsanitize=fuzzer" ]
31 if (pw_sanitizer != "") {
32 common_flags += [ "-fsanitize=$pw_sanitizer" ]
33 }
34 cflags = common_flags
35 ldflags = common_flags
36}
37
Aaron Green33c67822020-04-06 13:47:38 -070038source_set("pw_fuzzer") {
39 public_configs = [ ":default_config" ]
Aaron Green0ce7f412020-04-06 13:39:40 -070040 public = [
41 "public/pw_fuzzer/asan_interface.h",
42 "public/pw_fuzzer/fuzzed_data_provider.h",
43 ]
Aaron Green33c67822020-04-06 13:47:38 -070044 sources = public
45 public_deps = [ "$dir_pw_log" ]
46}
47
48# See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode
49config("fuzzing_build_mode_unsafe_for_production") {
50 defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ]
51}
52
53config("fuzzing_verbose_logging") {
54 defines = [ "FUZZING_VERBOSE_LOGGING" ]
55}
56
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070057pw_doc_group("docs") {
58 inputs = [ "doc_resources/pw_fuzzer_coverage_guided.png" ]
59 sources = [ "docs.rst" ]
60}
61
62# Sample fuzzer
63pw_fuzzer("toy_fuzzer") {
64 sources = [ "examples/toy_fuzzer.cc" ]
65 deps = [ "$dir_pw_string" ]
66}
67
68pw_test_group("tests") {
69 tests = [ ":toy_fuzzer" ]
70}