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 # ============================================================================== | 5 # ============================================================================== |
6 # TEST SETUP | 6 # TEST SETUP |
7 # ============================================================================== | 7 # ============================================================================== |
8 | 8 |
| 9 template("_gen_isolate") { |
| 10 testonly = true |
| 11 _runtime_deps_file = "$target_gen_dir/$target_name.runtime_deps" |
| 12 group("${target_name}__write_deps") { |
| 13 forward_variables_from(invoker, |
| 14 [ |
| 15 "data", |
| 16 "data_deps", |
| 17 "deps", |
| 18 "public_deps", |
| 19 ]) |
| 20 write_runtime_deps = _runtime_deps_file |
| 21 } |
| 22 |
| 23 action(target_name) { |
| 24 script = "//testing/generate_isolate.py" |
| 25 inputs = [ |
| 26 _runtime_deps_file, |
| 27 ] |
| 28 outputs = [ |
| 29 invoker.output, |
| 30 ] |
| 31 args = [ |
| 32 "--output-directory=.", |
| 33 "--out-file", |
| 34 rebase_path(invoker.output, root_build_dir), |
| 35 "--runtime-deps-file", |
| 36 rebase_path(_runtime_deps_file, root_build_dir), |
| 37 ] |
| 38 if (is_android) { |
| 39 args += [ "--apply-android-filters" ] |
| 40 } |
| 41 if (defined(invoker.apply_device_filters) && invoker.apply_device_filters) { |
| 42 args += [ "--apply-device-filters" ] |
| 43 } |
| 44 _assert_no_odd_data = |
| 45 defined(invoker.assert_no_odd_data) && invoker.assert_no_odd_data |
| 46 if (_assert_no_odd_data) { |
| 47 args += [ "--assert-no-odd-data" ] |
| 48 } |
| 49 if (defined(invoker.command)) { |
| 50 _isolate_dir = get_path_info(invoker.output, "dir") |
| 51 args += [ |
| 52 "--command", |
| 53 rebase_path(invoker.command, _isolate_dir), |
| 54 ] |
| 55 } |
| 56 deps = [ |
| 57 ":${invoker.target_name}__write_deps", |
| 58 ] |
| 59 } |
| 60 } |
| 61 |
9 # Define a test as an executable (or apk on Android) with the "testonly" flag | 62 # Define a test as an executable (or apk on Android) with the "testonly" flag |
10 # set. | 63 # set. |
11 # Variable: | 64 # Variable: |
12 # use_raw_android_executable: Use executable() rather than android_apk(). | 65 # use_raw_android_executable: Use executable() rather than android_apk(). |
| 66 # use_native_activity: Test implements ANativeActivity_onCreate(). |
13 template("test") { | 67 template("test") { |
14 if (is_android) { | 68 if (is_android) { |
15 import("//build/config/android/config.gni") | 69 import("//build/config/android/config.gni") |
16 import("//build/config/android/rules.gni") | 70 import("//build/config/android/rules.gni") |
| 71 import("//build/config/sanitizers/sanitizers.gni") |
17 | 72 |
18 _use_raw_android_executable = defined(invoker.use_raw_android_executable) && | 73 _use_raw_android_executable = defined(invoker.use_raw_android_executable) && |
19 invoker.use_raw_android_executable | 74 invoker.use_raw_android_executable |
20 | 75 |
21 # output_name is used to allow targets with the same name but in different | 76 # output_name is used to allow targets with the same name but in different |
22 # packages to still produce unique runner scripts. | 77 # packages to still produce unique runner scripts. |
23 _output_name = invoker.target_name | 78 _output_name = invoker.target_name |
24 if (defined(invoker.output_name)) { | 79 if (defined(invoker.output_name)) { |
25 _output_name = invoker.output_name | 80 _output_name = invoker.output_name |
26 } | 81 } |
27 | 82 |
| 83 _test_runner_target = "${_output_name}__test_runner_script" |
| 84 _wrapper_script_vars = [ "shard_timeout" ] |
| 85 _gen_isolate_vars = [ |
| 86 "allow_odd_runtime_deps", |
| 87 "ignore_all_data_deps", |
| 88 ] |
| 89 _generate_device_isolate = |
| 90 !defined(invoker.ignore_all_data_deps) || !invoker.ignore_all_data_deps |
| 91 |
| 92 if (_generate_device_isolate) { |
| 93 _allow_odd_runtime_deps = defined(invoker.allow_odd_runtime_deps) && |
| 94 invoker.allow_odd_runtime_deps |
| 95 |
| 96 # The device isolate is needed at runtime, so it cannot go in |
| 97 # target_gen_dir, as builder/tester configurations do not include it. |
| 98 _target_dir_name = get_label_info(":$target_name", "dir") |
| 99 _device_isolate_path = "$root_out_dir/gen.runtime/$_target_dir_name/$targe
t_name.device.isolate" |
| 100 _gen_isolate_target_name = "${target_name}__isolate" |
| 101 _gen_isolate(_gen_isolate_target_name) { |
| 102 forward_variables_from(invoker, |
| 103 [ |
| 104 "data", |
| 105 "data_deps", |
| 106 "deps", |
| 107 "public_deps", |
| 108 ]) |
| 109 assert_no_odd_data = !_allow_odd_runtime_deps |
| 110 output = _device_isolate_path |
| 111 apply_device_filters = true |
| 112 } |
| 113 } |
| 114 |
| 115 assert(_use_raw_android_executable || enable_java_templates) |
| 116 |
28 if (_use_raw_android_executable) { | 117 if (_use_raw_android_executable) { |
29 _exec_target = "${target_name}__exec" | 118 _exec_target = "${target_name}__exec" |
30 _dist_target = "${target_name}__dist" | 119 _dist_target = "${target_name}__dist" |
31 _exec_output = | 120 _exec_output = |
32 "$target_out_dir/${invoker.target_name}/${invoker.target_name}" | 121 "$target_out_dir/${invoker.target_name}/${invoker.target_name}" |
33 | 122 |
34 executable(_exec_target) { | 123 executable(_exec_target) { |
35 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn
. | 124 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn
. |
36 configs = [] | 125 configs = [] |
37 data_deps = [] | 126 data_deps = [] |
38 forward_variables_from(invoker, "*", [ "extra_dist_files" ]) | 127 forward_variables_from( |
| 128 invoker, |
| 129 "*", |
| 130 _wrapper_script_vars + _gen_isolate_vars + [ "extra_dist_files" ]) |
39 testonly = true | 131 testonly = true |
40 | 132 |
41 # Thanks to the set_defaults() for test(), configs are initialized with | 133 # Thanks to the set_defaults() for test(), configs are initialized with |
42 # the default shared_library configs rather than executable configs. | 134 # the default shared_library configs rather than executable configs. |
43 configs -= [ | 135 configs -= [ |
44 "//build/config:shared_library_config", | 136 "//build/config:shared_library_config", |
45 "//build/config/android:hide_native_jni_exports", | 137 "//build/config/android:hide_native_jni_exports", |
46 ] | 138 ] |
47 configs += [ "//build/config:executable_config" ] | 139 configs += [ "//build/config:executable_config" ] |
48 | 140 |
(...skipping 14 matching lines...) Expand all Loading... |
63 if (defined(invoker.extra_dist_files)) { | 155 if (defined(invoker.extra_dist_files)) { |
64 extra_files = invoker.extra_dist_files | 156 extra_files = invoker.extra_dist_files |
65 } | 157 } |
66 } | 158 } |
67 } else { | 159 } else { |
68 _library_target = "_${target_name}__library" | 160 _library_target = "_${target_name}__library" |
69 _apk_target = "${target_name}_apk" | 161 _apk_target = "${target_name}_apk" |
70 _apk_specific_vars = [ | 162 _apk_specific_vars = [ |
71 "android_manifest", | 163 "android_manifest", |
72 "enable_multidex", | 164 "enable_multidex", |
| 165 "proguard_configs", |
| 166 "proguard_enabled", |
73 "use_default_launcher", | 167 "use_default_launcher", |
74 "write_asset_list", | 168 "write_asset_list", |
| 169 "use_native_activity", |
75 ] | 170 ] |
76 shared_library(_library_target) { | 171 shared_library(_library_target) { |
77 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn
. | 172 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn
. |
78 configs = [] # Prevent list overwriting warning. | 173 configs = [] # Prevent list overwriting warning. |
79 configs = invoker.configs | 174 configs = invoker.configs |
80 testonly = true | 175 testonly = true |
81 | 176 |
82 deps = [] | 177 deps = [] |
83 forward_variables_from(invoker, | 178 forward_variables_from(invoker, |
84 "*", | 179 "*", |
85 _apk_specific_vars + [ | 180 _apk_specific_vars + _wrapper_script_vars + |
86 "isolate_file", | 181 _gen_isolate_vars + [ "visibility" ]) |
87 "visibility", | |
88 ]) | |
89 | 182 |
90 if (!defined(invoker.use_default_launcher) || | 183 if (!defined(invoker.use_default_launcher) || |
91 invoker.use_default_launcher) { | 184 invoker.use_default_launcher) { |
92 deps += [ "//testing/android/native_test:native_test_native_code" ] | 185 deps += [ "//testing/android/native_test:native_test_native_code" ] |
93 } | 186 } |
94 } | 187 } |
95 unittest_apk(_apk_target) { | 188 unittest_apk(_apk_target) { |
96 forward_variables_from(invoker, _apk_specific_vars + [ "deps" ]) | 189 forward_variables_from(invoker, _apk_specific_vars + [ "deps" ]) |
97 unittests_dep = ":$_library_target" | 190 unittests_dep = ":$_library_target" |
98 apk_name = invoker.target_name | 191 apk_name = invoker.target_name |
99 if (defined(invoker.output_name)) { | 192 if (defined(invoker.output_name)) { |
100 apk_name = invoker.output_name | 193 apk_name = invoker.output_name |
101 unittests_binary = "lib${apk_name}.so" | 194 unittests_binary = "lib${apk_name}.so" |
102 install_script_name = "install_${invoker.output_name}" | 195 install_script_name = "install_${invoker.output_name}" |
103 } | 196 } |
104 deps += [ ":$_library_target" ] | 197 deps += [ ":$_library_target" ] |
| 198 |
| 199 # TODO(agrieve): Remove this data_dep once bots don't build the _apk |
| 200 # target (post-GYP). |
| 201 # It's a bit backwards for the apk to depend on the runner script, since |
| 202 # the apk is conceptually a runtime_dep of the script. However, it is |
| 203 # currently necessary because the bots build this _apk target directly |
| 204 # rather than the group() below. |
| 205 data_deps = [ |
| 206 ":$_test_runner_target", |
| 207 ] |
105 } | 208 } |
106 | 209 |
107 # Incremental test targets work only for .apks. | 210 # Incremental test targets work only for .apks. |
108 _incremental_test_runner_target = | 211 _incremental_test_runner_target = |
109 "${_output_name}_incremental__test_runner_script" | 212 "${_output_name}_incremental__test_runner_script" |
110 test_runner_script(_incremental_test_runner_target) { | 213 test_runner_script(_incremental_test_runner_target) { |
111 forward_variables_from(invoker, [ "isolate_file" ]) | 214 forward_variables_from(invoker, _wrapper_script_vars) |
| 215 if (_generate_device_isolate) { |
| 216 isolate_file = _device_isolate_path |
| 217 deps = [ |
| 218 ":$_gen_isolate_target_name", |
| 219 ] |
| 220 } |
112 apk_target = ":$_apk_target" | 221 apk_target = ":$_apk_target" |
113 test_name = "${_output_name}_incremental" | 222 test_name = "${_output_name}_incremental" |
114 test_type = "gtest" | 223 test_type = "gtest" |
115 test_suite = _output_name | 224 test_suite = _output_name |
116 incremental_install = true | 225 incremental_install = true |
117 } | 226 } |
118 group("${target_name}_incremental") { | 227 group("${target_name}_incremental") { |
119 testonly = true | 228 testonly = true |
120 datadeps = [ | 229 datadeps = [ |
121 ":$_incremental_test_runner_target", | 230 ":$_incremental_test_runner_target", |
122 ] | 231 ] |
123 deps = [ | 232 deps = [ |
124 ":${_apk_target}_incremental", | 233 ":${_apk_target}_incremental", |
125 ] | 234 ] |
126 } | 235 } |
127 } | 236 } |
128 | 237 |
129 _test_runner_target = "${_output_name}__test_runner_script" | 238 _test_runner_target = "${_output_name}__test_runner_script" |
130 test_runner_script(_test_runner_target) { | 239 test_runner_script(_test_runner_target) { |
131 forward_variables_from(invoker, [ "isolate_file" ]) | 240 forward_variables_from(invoker, _wrapper_script_vars) |
| 241 if (_generate_device_isolate) { |
| 242 isolate_file = _device_isolate_path |
| 243 deps = [ |
| 244 ":$_gen_isolate_target_name", |
| 245 ] |
| 246 } |
| 247 |
132 if (_use_raw_android_executable) { | 248 if (_use_raw_android_executable) { |
133 executable_dist_dir = "$root_out_dir/$_dist_target" | 249 executable_dist_dir = "$root_out_dir/$_dist_target" |
134 } else { | 250 } else { |
135 apk_target = ":$_apk_target" | 251 apk_target = ":$_apk_target" |
136 } | 252 } |
137 test_name = _output_name | 253 test_name = _output_name |
138 test_type = "gtest" | 254 test_type = "gtest" |
139 test_suite = _output_name | 255 test_suite = _output_name |
140 } | 256 } |
141 | 257 |
142 group(target_name) { | 258 group(target_name) { |
143 testonly = true | 259 testonly = true |
144 deps = [ | 260 deps = [ |
145 ":$_test_runner_target", | 261 ":$_test_runner_target", |
146 ] | 262 ] |
147 if (_use_raw_android_executable) { | 263 if (_use_raw_android_executable) { |
148 deps += [ ":$_dist_target" ] | 264 deps += [ ":$_dist_target" ] |
149 } else { | 265 } else { |
150 deps += [ ":$_apk_target" ] | 266 deps += [ ":$_apk_target" ] |
151 } | 267 } |
152 } | 268 } |
153 | 269 |
154 # TODO(GYP): Delete this after we've converted everything to GN. | 270 # TODO(GYP_GONE): Delete this after we've converted everything to GN. |
155 # The _run targets exist only for compatibility w/ GYP. | 271 # The _run targets exist only for compatibility w/ GYP. |
156 group("${target_name}_apk_run") { | 272 group("${target_name}_apk_run") { |
157 testonly = true | 273 testonly = true |
158 deps = [ | 274 deps = [ |
159 ":${invoker.target_name}", | 275 ":${invoker.target_name}", |
160 ] | 276 ] |
161 } | 277 } |
162 } else if (is_ios) { | 278 } else if (is_ios) { |
163 import("//build/config/ios/rules.gni") | 279 import("//build/config/ios/rules.gni") |
164 | 280 |
165 _test_target = target_name | 281 _test_target = target_name |
166 _resources_bundle_data = target_name + "_resources_bundle_data" | 282 _resources_bundle_data = target_name + "_resources_bundle_data" |
167 | 283 |
168 bundle_data(_resources_bundle_data) { | 284 bundle_data(_resources_bundle_data) { |
169 visibility = [ | 285 visibility = [ |
170 ":${_test_target}", | 286 ":${_test_target}", |
171 ":${_test_target}_generate_executable", | 287 ":${_test_target}_generate_executable", |
172 ] | 288 ] |
173 sources = [ | 289 sources = [ |
174 "//testing/gtest_ios/Default.png", | 290 "//testing/gtest_ios/Default.png", |
175 ] | 291 ] |
176 outputs = [ | 292 outputs = [ |
177 "{{bundle_resources_dir}}/{{source_file_part}}", | 293 "{{bundle_resources_dir}}/{{source_file_part}}", |
178 ] | 294 ] |
179 } | 295 } |
180 | 296 |
181 app(_test_target) { | 297 ios_app_bundle(_test_target) { |
182 # TODO(GYP): Make this configurable and only provide a default | |
183 # that can be overridden. | |
184 info_plist = "//testing/gtest_ios/unittest-Info.plist" | |
185 app_name = target_name | |
186 entitlements_path = "//testing/gtest_ios" | |
187 code_signing_identity = "" | |
188 testonly = true | 298 testonly = true |
189 extra_substitutions = [ "BUNDLE_ID_TEST_NAME=$app_name" ] | |
190 | 299 |
191 # See above call. | 300 # See above call. |
192 set_sources_assignment_filter([]) | 301 set_sources_assignment_filter([]) |
| 302 forward_variables_from(invoker, "*", [ "testonly" ]) |
193 | 303 |
194 forward_variables_from(invoker, "*") | 304 # Provide sensible defaults in case invoker did not define any of those |
| 305 # required variables. |
| 306 if (!defined(info_plist) && !defined(info_plist_target)) { |
| 307 info_plist = "//testing/gtest_ios/unittest-Info.plist" |
| 308 } |
| 309 if (!defined(entitlements_path)) { |
| 310 entitlements_path = "//testing/gtest_ios" |
| 311 } |
| 312 if (!defined(code_signing_identity)) { |
| 313 code_signing_identity = "" |
| 314 } |
| 315 |
| 316 # TODO(crbug.com/603102): remove this once gyp support is dropped and all |
| 317 # application uses the target name as value for BUNDLE_ID_TEST_NAME. |
| 318 if (defined(invoker.app_name)) { |
| 319 app_name = invoker.app_name |
| 320 } else { |
| 321 app_name = target_name |
| 322 } |
| 323 |
| 324 if (!defined(extra_substitutions)) { |
| 325 extra_substitutions = [] |
| 326 } |
| 327 extra_substitutions += [ "BUNDLE_ID_TEST_NAME=$app_name" ] |
195 | 328 |
196 if (!defined(deps)) { | 329 if (!defined(deps)) { |
197 deps = [] | 330 deps = [] |
198 } | 331 } |
199 deps += [ | 332 deps += [ |
200 ":$_resources_bundle_data", | 333 ":$_resources_bundle_data", |
201 | 334 |
202 # All shared libraries must have the sanitizer deps to properly link in | 335 # All shared libraries must have the sanitizer deps to properly link in |
203 # asan mode (this target will be empty in other cases). | 336 # asan mode (this target will be empty in other cases). |
204 "//build/config/sanitizers:deps", | 337 "//build/config/sanitizers:deps", |
205 ] | 338 ] |
206 } | 339 } |
207 } else { | 340 } else { |
208 executable(target_name) { | 341 executable(target_name) { |
209 deps = [] | 342 deps = [] |
210 forward_variables_from(invoker, "*") | 343 forward_variables_from(invoker, "*") |
211 | 344 |
212 testonly = true | 345 testonly = true |
213 deps += [ | 346 deps += [ |
214 # All shared libraries must have the sanitizer deps to properly link in | 347 # All shared libraries must have the sanitizer deps to properly link in |
215 # asan mode (this target will be empty in other cases). | 348 # asan mode (this target will be empty in other cases). |
216 "//build/config/sanitizers:deps", | 349 "//build/config/sanitizers:deps", |
217 | 350 |
218 # Give tests the default manifest on Windows (a no-op elsewhere). | 351 # Give tests the default manifest on Windows (a no-op elsewhere). |
219 "//build/win:default_exe_manifest", | 352 "//build/win:default_exe_manifest", |
220 ] | 353 ] |
221 } | 354 } |
222 | 355 |
223 # TODO(GYP): Delete this after we've converted everything to GN. | 356 # TODO(GYP_GONE): Delete this after we've converted everything to GN. |
224 # The _run targets exist only for compatibility with GYP. | 357 # The _run targets exist only for compatibility with GYP. |
225 group("${target_name}_run") { | 358 group("${target_name}_run") { |
226 testonly = true | 359 testonly = true |
227 deps = [ | 360 deps = [ |
228 ":${invoker.target_name}", | 361 ":${invoker.target_name}", |
229 ] | 362 ] |
230 } | 363 } |
| 364 |
| 365 if (defined(invoker.output_name) && target_name != invoker.output_name) { |
| 366 group("${invoker.output_name}_run") { |
| 367 testonly = true |
| 368 deps = [ |
| 369 ":${invoker.target_name}", |
| 370 ] |
| 371 } |
| 372 } |
231 } | 373 } |
232 } | 374 } |
OLD | NEW |