OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # Defines fuzzer_test. | 5 # Defines fuzzer_test. |
6 # | 6 # |
7 import("//build/config/features.gni") | 7 import("//build/config/features.gni") |
8 import("//build/config/sanitizers/sanitizers.gni") | 8 import("//build/config/sanitizers/sanitizers.gni") |
9 import("//testing/test.gni") | 9 import("//testing/test.gni") |
10 | 10 |
11 # visible for testing only. | 11 # visible for testing only. |
12 template("fuzzer_test_launcher") { | 12 template("fuzzer_test_launcher") { |
13 assert(defined(invoker.fuzzer_name), "need fuzzer_name in $target_name.") | 13 assert(defined(invoker.fuzzer_name), "need fuzzer_name in $target_name.") |
14 assert(defined(invoker.dict), "need dict in $target_name.") | 14 assert(defined(invoker.dict) || defined(invoker.params), |
| 15 "need dict or params in $target_name.") |
15 | 16 |
16 generated_script = "$root_build_dir/$target_name" | 17 generated_script = "$root_build_dir/$target_name" |
17 | 18 |
18 action(target_name) { | 19 action(target_name) { |
19 script = "//testing/libfuzzer/gen_fuzzer_runner.py" | 20 script = "//testing/libfuzzer/gen_fuzzer_runner.py" |
20 args = [ | 21 args = [ |
21 "--fuzzer", | 22 "--fuzzer", |
22 invoker.fuzzer_name, | 23 invoker.fuzzer_name, |
23 "--launcher", | 24 "--launcher", |
24 rebase_path(generated_script, root_build_dir), | 25 rebase_path(generated_script, root_build_dir), |
25 "--dict", | |
26 rebase_path("$root_build_dir/" + invoker.dict, root_build_dir), | |
27 ] | 26 ] |
| 27 if (defined(invoker.dict)) { |
| 28 args += [ |
| 29 "--dict", |
| 30 rebase_path("$root_build_dir/" + invoker.dict, root_build_dir), |
| 31 ] |
| 32 } |
| 33 if (defined(invoker.params)) { |
| 34 args += [ |
| 35 "--params", |
| 36 "\"" + invoker.params + "\"", |
| 37 ] |
| 38 } |
28 outputs = [ | 39 outputs = [ |
29 generated_script, | 40 generated_script, |
30 ] | 41 ] |
31 } | 42 } |
32 } | 43 } |
33 | 44 |
34 # fuzzer_test is used to define individual libfuzzer tests. | 45 # fuzzer_test is used to define individual libfuzzer tests. |
35 # | 46 # |
36 # Supported attributes: | 47 # Supported attributes: |
37 # - (required) sources - fuzzer test source files | 48 # - (required) sources - fuzzer test source files |
38 # - data - test data files. | 49 # - data - test data files. |
39 # - deps - test dependencies | 50 # - deps - test dependencies |
40 # - additional_configs - additional configs to be used for compilation | 51 # - additional_configs - additional configs to be used for compilation |
41 # - dict - a dictionary file for the fuzzer. | 52 # - dict - a dictionary file for the fuzzer. |
| 53 # - params - custom parameters for the fuzzer (e.g. some -max_len or -timeout). |
42 # | 54 # |
43 # If use_libfuzzer gn flag is defined, then proper fuzzer would be build. | 55 # If use_libfuzzer gn flag is defined, then proper fuzzer would be build. |
44 # Without use_libfuzzer a unit-test style binary would be built on linux | 56 # Without use_libfuzzer a unit-test style binary would be built on linux |
45 # and the whole target is a no-op otherwise. | 57 # and the whole target is a no-op otherwise. |
46 # | 58 # |
47 # The template wraps test() target with appropriate dependencies. | 59 # The template wraps test() target with appropriate dependencies. |
48 # If any test run-time options are present (dict), then a launcher | 60 # If any test run-time options are present (dict or params), then a launcher |
49 # file would be generated with <fuzzer_name>.sh name in root output | 61 # file would be generated with <fuzzer_name>.sh name in root output |
50 # dir (next to test). | 62 # dir (next to test). |
51 template("fuzzer_test") { | 63 template("fuzzer_test") { |
52 if (!disable_libfuzzer && (use_libfuzzer || use_drfuzz || is_linux)) { | 64 if (!disable_libfuzzer && (use_libfuzzer || use_drfuzz || is_linux)) { |
53 assert(defined(invoker.sources), "Need sources in $target_name.") | 65 assert(defined(invoker.sources), "Need sources in $target_name.") |
54 | 66 |
55 test_deps = [ "//testing/libfuzzer:libfuzzer_main" ] | 67 test_deps = [ "//testing/libfuzzer:libfuzzer_main" ] |
56 | 68 |
57 if (defined(invoker.deps)) { | 69 if (defined(invoker.deps)) { |
58 test_deps += invoker.deps | 70 test_deps += invoker.deps |
59 } | 71 } |
60 | 72 |
61 test_data = [] | 73 test_data = [] |
62 if (defined(invoker.data)) { | 74 if (defined(invoker.data)) { |
63 test_data += invoker.data | 75 test_data += invoker.data |
64 } | 76 } |
65 | 77 |
66 if (defined(invoker.dict)) { | 78 if (defined(invoker.dict) || defined(invoker.params)) { |
67 fuzzer_name = target_name | 79 fuzzer_name = target_name |
68 launcher_name = target_name + ".sh" | 80 launcher_name = target_name + ".sh" |
69 | 81 |
70 # Copy dictionary to output | 82 if (defined(invoker.dict)) { |
71 copy(target_name + "_dict_copy") { | 83 # Copy dictionary to output |
72 sources = [ | 84 copy(target_name + "_dict_copy") { |
73 invoker.dict, | 85 sources = [ |
74 ] | 86 invoker.dict, |
75 outputs = [ | 87 ] |
76 "$root_build_dir/" + invoker.dict, | 88 outputs = [ |
77 ] | 89 "$root_build_dir/" + invoker.dict, |
| 90 ] |
| 91 } |
78 } | 92 } |
79 | 93 |
80 fuzzer_test_launcher(launcher_name) { | 94 fuzzer_test_launcher(launcher_name) { |
81 dict = invoker.dict | 95 forward_variables_from(invoker, |
| 96 [ |
| 97 "dict", |
| 98 "params", |
| 99 ]) |
82 } | 100 } |
83 | 101 |
84 test_deps += [ | 102 test_deps += [ ":$launcher_name" ] |
85 ":$launcher_name", | 103 if (defined(invoker.dict)) { |
86 ":" + fuzzer_name + "_dict_copy", | 104 test_deps += [ ":" + fuzzer_name + "_dict_copy" ] |
87 ] | 105 } |
88 test_data += [ | 106 |
89 invoker.dict, | 107 if (defined(invoker.dict)) { |
90 ":$launcher_name", | 108 test_data += [ invoker.dict ] |
91 ] | 109 } |
| 110 test_data += [ ":$launcher_name" ] |
92 } | 111 } |
93 | 112 |
94 test(target_name) { | 113 test(target_name) { |
95 forward_variables_from(invoker, | 114 forward_variables_from(invoker, |
96 [ | 115 [ |
97 "sources", | 116 "sources", |
98 "include_dirs", | 117 "include_dirs", |
99 ]) | 118 ]) |
100 deps = test_deps | 119 deps = test_deps |
101 data = test_data | 120 data = test_data |
102 | 121 |
103 if (defined(invoker.additional_configs)) { | 122 if (defined(invoker.additional_configs)) { |
104 configs += invoker.additional_configs | 123 configs += invoker.additional_configs |
105 } | 124 } |
106 } | 125 } |
107 } else { | 126 } else { |
108 # noop on unsupported platforms. | 127 # noop on unsupported platforms. |
109 # mark attributes as used. | 128 # mark attributes as used. |
110 assert(invoker.sources == [] || invoker.sources != []) | 129 assert(invoker.sources == [] || invoker.sources != []) |
111 if (defined(invoker.additional_configs)) { | 130 if (defined(invoker.additional_configs)) { |
112 assert( | 131 assert( |
113 invoker.additional_configs == [] || invoker.additional_configs != []) | 132 invoker.additional_configs == [] || invoker.additional_configs != []) |
114 } | 133 } |
115 if (defined(invoker.deps)) { | 134 if (defined(invoker.deps)) { |
116 assert(invoker.deps == [] || invoker.deps != []) | 135 assert(invoker.deps == [] || invoker.deps != []) |
117 } | 136 } |
118 if (defined(invoker.dict)) { | 137 if (defined(invoker.dict)) { |
119 assert(invoker.dict == [] || invoker.dict != []) | 138 assert(invoker.dict == [] || invoker.dict != []) |
120 } | 139 } |
| 140 if (defined(invoker.params)) { |
| 141 assert(invoker.params == [] || invoker.params != []) |
| 142 } |
121 | 143 |
122 group(target_name) { | 144 group(target_name) { |
123 } | 145 } |
124 } | 146 } |
125 } | 147 } |
OLD | NEW |