Chromium Code Reviews| 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 if (defined(invoker.dict)) { |
|
aizatsky
2016/02/16 18:25:05
use forward_variables_from (see below).
mmoroz
2016/02/17 10:36:48
Done.
Didn't know that, thanks!
| |
| 96 dict = invoker.dict | |
| 97 } | |
| 98 if (defined(invoker.params)) { | |
| 99 params = invoker.params | |
| 100 } | |
| 82 } | 101 } |
| 83 | 102 |
| 84 test_deps += [ | 103 test_deps += [ ":$launcher_name" ] |
| 85 ":$launcher_name", | 104 if (defined(invoker.dict)) { |
| 86 ":" + fuzzer_name + "_dict_copy", | 105 test_deps += [ ":" + fuzzer_name + "_dict_copy" ] |
| 87 ] | 106 } |
| 88 test_data += [ | 107 |
| 89 invoker.dict, | 108 if (defined(invoker.dict)) { |
| 90 ":$launcher_name", | 109 test_data += [ invoker.dict ] |
| 91 ] | 110 } |
| 111 test_data += [ ":$launcher_name" ] | |
| 92 } | 112 } |
| 93 | 113 |
| 94 test(target_name) { | 114 test(target_name) { |
| 95 forward_variables_from(invoker, | 115 forward_variables_from(invoker, |
| 96 [ | 116 [ |
| 97 "sources", | 117 "sources", |
| 98 "include_dirs", | 118 "include_dirs", |
| 99 ]) | 119 ]) |
| 100 deps = test_deps | 120 deps = test_deps |
| 101 data = test_data | 121 data = test_data |
| 102 | 122 |
| 103 if (defined(invoker.additional_configs)) { | 123 if (defined(invoker.additional_configs)) { |
| 104 configs += invoker.additional_configs | 124 configs += invoker.additional_configs |
| 105 } | 125 } |
| 106 } | 126 } |
| 107 } else { | 127 } else { |
| 108 # noop on unsupported platforms. | 128 # noop on unsupported platforms. |
| 109 # mark attributes as used. | 129 # mark attributes as used. |
| 110 assert(invoker.sources == [] || invoker.sources != []) | 130 assert(invoker.sources == [] || invoker.sources != []) |
| 111 if (defined(invoker.additional_configs)) { | 131 if (defined(invoker.additional_configs)) { |
| 112 assert( | 132 assert( |
| 113 invoker.additional_configs == [] || invoker.additional_configs != []) | 133 invoker.additional_configs == [] || invoker.additional_configs != []) |
| 114 } | 134 } |
| 115 if (defined(invoker.deps)) { | 135 if (defined(invoker.deps)) { |
| 116 assert(invoker.deps == [] || invoker.deps != []) | 136 assert(invoker.deps == [] || invoker.deps != []) |
| 117 } | 137 } |
| 118 if (defined(invoker.dict)) { | 138 if (defined(invoker.dict)) { |
| 119 assert(invoker.dict == [] || invoker.dict != []) | 139 assert(invoker.dict == [] || invoker.dict != []) |
| 120 } | 140 } |
| 141 if (defined(invoker.params)) { | |
| 142 assert(invoker.params == [] || invoker.params != []) | |
| 143 } | |
| 121 | 144 |
| 122 group(target_name) { | 145 group(target_name) { |
| 123 } | 146 } |
| 124 } | 147 } |
| 125 } | 148 } |
| OLD | NEW |