Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 1 | # 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 | |
| 15 | import("$dir_pw_docgen/docs.gni") |
| 16 | import("$dir_pw_fuzzer/fuzzer.gni") |
| 17 | |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 18 | config("default_config") { |
| 19 | include_dirs = [ "public" ] |
| 20 | } |
| 21 | |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 22 | # This is added automatically by the `pw_fuzzer` template. |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 23 | config("fuzzing") { |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 24 | common_flags = [ "-fsanitize=fuzzer" ] |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 25 | cflags = common_flags |
| 26 | ldflags = common_flags |
| 27 | } |
| 28 | |
Aaron Green | b3ae1dc | 2020-04-13 11:37:05 -0700 | [diff] [blame^] | 29 | config("sanitize_address") { |
| 30 | cflags = [ "-fsanitize=address" ] |
| 31 | ldflags = cflags |
| 32 | } |
| 33 | |
| 34 | config("sanitize_memory") { |
| 35 | cflags = [ "-fsanitize=memory" ] |
| 36 | ldflags = cflags |
| 37 | } |
| 38 | |
| 39 | config("sanitize_undefined") { |
| 40 | cflags = [ "-fsanitize=undefined" ] |
| 41 | ldflags = cflags |
| 42 | } |
| 43 | |
| 44 | # OSS-Fuzz needs to be able to specify its own compilers and add flags. |
| 45 | config("oss_fuzz") { |
| 46 | # OSS-Fuzz doesn't always link with -fsanitize=fuzzer, sometimes it uses |
| 47 | #-fsanitize=fuzzer-no-link and provides the fuzzing engine explicitly to be |
| 48 | # passed to the linker. |
| 49 | ldflags = [ getenv("LIB_FUZZING_ENGINE") ] |
| 50 | } |
| 51 | |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 52 | source_set("pw_fuzzer") { |
| 53 | public_configs = [ ":default_config" ] |
Aaron Green | 0ce7f41 | 2020-04-06 13:39:40 -0700 | [diff] [blame] | 54 | public = [ |
| 55 | "public/pw_fuzzer/asan_interface.h", |
| 56 | "public/pw_fuzzer/fuzzed_data_provider.h", |
| 57 | ] |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 58 | sources = public |
| 59 | public_deps = [ "$dir_pw_log" ] |
| 60 | } |
| 61 | |
| 62 | # See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode |
| 63 | config("fuzzing_build_mode_unsafe_for_production") { |
| 64 | defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ] |
| 65 | } |
| 66 | |
| 67 | config("fuzzing_verbose_logging") { |
| 68 | defines = [ "FUZZING_VERBOSE_LOGGING" ] |
| 69 | } |
| 70 | |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 71 | pw_doc_group("docs") { |
| 72 | inputs = [ "doc_resources/pw_fuzzer_coverage_guided.png" ] |
| 73 | sources = [ "docs.rst" ] |
| 74 | } |
| 75 | |
| 76 | # Sample fuzzer |
| 77 | pw_fuzzer("toy_fuzzer") { |
| 78 | sources = [ "examples/toy_fuzzer.cc" ] |
| 79 | deps = [ "$dir_pw_string" ] |
| 80 | } |
| 81 | |
| 82 | pw_test_group("tests") { |
| 83 | tests = [ ":toy_fuzzer" ] |
| 84 | } |