[go: nahoru, domu]

blob: b8e4e29ce96d6cd61bfc637528159840841d161c [file] [log] [blame]
qsrc6c612c2015-01-13 22:07:481# Copyright 2015 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
qsrfb5251d12015-01-21 15:57:224
5# ==============================================================================
6# TEST SETUP
7# ==============================================================================
8
Yuke Liao2a9b2f0e2021-04-16 00:40:119import("//build/config/chromeos/args.gni")
Yuke Liaoe703384b2020-07-16 01:05:2410import("//build/config/chromeos/ui_mode.gni")
Dirk Prankeb404c3b2021-06-14 19:57:5011import("//build/config/gclient_args.gni")
Greg Guterman28b3cba2021-05-12 22:21:0312import("//build/config/rts.gni")
Mirko Bonadei4a0df432020-09-08 19:06:0213import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2414
Greg Guterman6963dc02021-04-07 05:20:5915declare_args() {
Dirk Prankeb404c3b2021-06-14 19:57:5016 # Some component repos (e.g. ANGLE) import //testing but do not have
17 # "location_tags.json", and so we don't want to try and upload the tags
18 # for their tests.
19 # And, some build configs may simply turn off generation altogether.
20 tests_have_location_tags = generate_location_tags
Greg Guterman6963dc02021-04-07 05:20:5921}
22
jcivellif4462a352017-01-10 04:45:5923if (is_android) {
24 import("//build/config/android/config.gni")
James Cook209256f2018-12-07 18:40:5025 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5926 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4427 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3228} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0629 import("//build/config/chromecast_build.gni")
Kevin Marshall55fd8522019-10-04 22:47:0130 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4231 import("//build/config/fuchsia/package.gni")
Chong Gu26908f42021-01-29 03:13:0732 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Yuke Liaoe502a742021-04-19 23:15:0233} else if ((is_chromeos_ash || is_chromeos_lacros) && is_chromeos_device) {
Ben Pastene4c35c572018-04-30 23:21:4834 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3235 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2836 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3237} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3638 import("//build/config/ios/ios_sdk.gni")
39 import("//build/config/ios/ios_test_runner_wrapper.gni")
40 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3241} else {
Dirk Pranke31e346e2020-07-15 00:54:0642 import("//build/config/sanitizers/sanitizers.gni")
43 import("//build/util/generate_wrapper.gni")
44}
45
qsrfb5251d12015-01-21 15:57:2246# Define a test as an executable (or apk on Android) with the "testonly" flag
47# set.
agrieve62ab00282016-04-05 02:03:4548# Variable:
Dirk Pranke79d065d2020-08-29 03:28:3049# use_xvfb: (optional) whether to run the executable under Xvfb.
agrieve62ab00282016-04-05 02:03:4550# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:5651# use_native_activity: Test implements ANativeActivity_onCreate().
Mirko Bonadei15522bc2020-09-16 20:38:3952# is_xctest: (iOS, optional) whether to build the executable as XCTest.
53# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
54# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:4355# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
56# network requests during the test.
qsrfb5251d12015-01-21 15:57:2257template("test") {
Greg Guterman6963dc02021-04-07 05:20:5958 # Ensures the rts file exists and if not, creates a dummy file
59 if (use_rts) {
60 action("${target_name}__rts_filters") {
61 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:5362 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc02021-04-07 05:20:5963 args = [ rebase_path(rts_file, root_build_dir) ]
64 outputs = [ rts_file ]
65 }
66 }
67
Andrew Grieve1b290e4a22020-11-24 20:07:0168 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:3969 if (!is_ios) {
70 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
71 "is_xctest can be set only for iOS builds")
72 }
Stefano Duo4128b6b2021-08-02 21:24:4373 if (!is_android) {
74 assert(!defined(invoker.allow_cleartext_traffic),
75 "allow_cleartext_traffic can be set only for Android tests")
76 }
77
qsrfb5251d12015-01-21 15:57:2278 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3079 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
80
Peter Kotwicz10742f82021-04-15 22:32:5081 _use_default_launcher =
82 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
83 if (!defined(invoker.use_raw_android_executable)) {
84 # Checkouts where build_with_chromium == false often have a custom GN
85 # template wrapper around test() which sets use_default_launcher == false.
86 # Set the _use_raw_android_executable default so that test() targets which
87 # do not use the custom wrapper
88 # (1) Do not cause "gn gen" to fail
89 # (2) Do not need to be moved into if(build_with_chromium) block.
90 _use_raw_android_executable =
91 !build_with_chromium && _use_default_launcher
92 } else {
93 not_needed([ "_use_default_launcher" ])
94 _use_raw_android_executable = invoker.use_raw_android_executable
95 }
qsrfb5251d12015-01-21 15:57:2296
agrieve67855de2016-03-30 14:46:0197 # output_name is used to allow targets with the same name but in different
98 # packages to still produce unique runner scripts.
99 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26100 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01101 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26102 }
agrieve62ab00282016-04-05 02:03:45103
agrieveb355ad152016-04-19 03:45:23104 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42105 _wrapper_script_vars = [
agrievee41ae1902016-04-25 14:12:51106 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42107 "shard_timeout",
agrievee41ae1902016-04-25 14:12:51108 ]
agrieve3ac557f02016-04-12 15:52:00109
jbudorickced2a252016-06-09 16:38:54110 assert(_use_raw_android_executable || enable_java_templates)
111
agrieve62ab00282016-04-05 02:03:45112 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49113 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
114
agrieve62ab00282016-04-05 02:03:45115 _exec_target = "${target_name}__exec"
116 _dist_target = "${target_name}__dist"
117 _exec_output =
118 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
119
120 executable(_exec_target) {
121 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
122 configs = []
Dirk Pranke19a58732021-03-24 22:26:22123 forward_variables_from(
124 invoker,
125 "*",
126 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
127 "data_deps",
128 "extra_dist_files",
129 ])
agrieve62ab00282016-04-05 02:03:45130
131 # Thanks to the set_defaults() for test(), configs are initialized with
132 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59133 configs -= [
134 "//build/config:shared_library_config",
135 "//build/config/android:hide_all_but_jni",
136 ]
agrieve62ab00282016-04-05 02:03:45137 configs += [ "//build/config:executable_config" ]
138
Dirk Pranke19a58732021-03-24 22:26:22139 if (defined(invoker.data_deps)) {
140 data_deps = invoker.data_deps
141 } else {
142 data_deps = []
143 }
144 if (!defined(data)) {
145 data = []
146 }
Jamie Madilldd60ee62021-04-13 19:25:52147 if (tests_have_location_tags) {
148 data += [ "//testing/location_tags.json" ]
149 }
Dirk Pranke19a58732021-03-24 22:26:22150
agrieve62ab00282016-04-05 02:03:45151 # Don't output to the root or else conflict with the group() below.
152 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11153
154 if (use_rts) {
155 data_deps += [ ":${invoker.target_name}__rts_filters" ]
156 }
agrieve62ab00282016-04-05 02:03:45157 }
158
159 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45160 dist_dir = "$root_out_dir/$target_name"
161 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22162 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45163 if (defined(invoker.extra_dist_files)) {
164 extra_files = invoker.extra_dist_files
165 }
Greg Guterman50ed4b42021-04-08 01:15:11166
167 if (use_rts) {
168 if (!defined(data_deps)) {
169 data_deps = []
170 }
171 data_deps += [ ":${invoker.target_name}__rts_filters" ]
172 }
agrieve62ab00282016-04-05 02:03:45173 }
174 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02175 _library_target = "${target_name}__library"
176 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45177 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43178 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45179 "android_manifest",
agrievec6811b422016-06-23 02:25:09180 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27181 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55182 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45183 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50184 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07185 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02186 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07187 "proguard_configs",
188 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45189 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02190 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45191 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56192 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45193 ]
Siddhartha764226b2018-03-13 02:32:55194
195 # Adds the unwind tables from unstripped binary as an asset file in the
196 # apk, if |add_unwind_tables_in_apk| is specified by the test.
197 if (defined(invoker.add_unwind_tables_in_apk) &&
198 invoker.add_unwind_tables_in_apk) {
199 _unwind_table_asset_name = "${target_name}_unwind_assets"
200 unwind_table_asset(_unwind_table_asset_name) {
Siddhartha764226b2018-03-13 02:32:55201 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22202 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55203 }
204 }
205
agrieve62ab00282016-04-05 02:03:45206 shared_library(_library_target) {
207 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
208 configs = [] # Prevent list overwriting warning.
209 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45210
jbudorickd29ecfa72016-11-18 22:45:42211 forward_variables_from(
212 invoker,
213 "*",
Peter Wen2052bd12020-12-03 20:15:07214 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
215 TESTONLY_AND_VISIBILITY)
216
217 # Native targets do not need to depend on java targets. Filter them out
218 # so that the shared library can be built without needing to wait for
219 # dependent java targets.
220 deps = []
221 if (defined(invoker.deps)) {
222 foreach(_dep, invoker.deps) {
223 _target_label = get_label_info(_dep, "label_no_toolchain")
224 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
225 deps += [ _dep ]
226 }
227 }
228 }
agrieve62ab00282016-04-05 02:03:45229
Peter Kotwiczb9957d62021-04-12 21:09:43230 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37231 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45232 }
233 }
234 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54235 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07236 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45237 apk_name = invoker.target_name
238 if (defined(invoker.output_name)) {
239 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45240 install_script_name = "install_${invoker.output_name}"
241 }
agrieveb355ad152016-04-19 03:45:23242
Daniel Bratellfdda4652019-01-31 15:45:54243 if (defined(invoker.deps)) {
244 deps = invoker.deps
245 } else {
246 deps = []
247 }
248
jcivellif4462a352017-01-10 04:45:59249 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43250 if (_use_default_launcher) {
251 deps += [ "//base/test:test_support_java" ]
252 }
jcivellif4462a352017-01-10 04:45:59253
Siddhartha764226b2018-03-13 02:32:55254 if (defined(_unwind_table_asset_name)) {
255 deps += [ ":${_unwind_table_asset_name}" ]
256 }
Greg Guterman50ed4b42021-04-08 01:15:11257
258 if (use_rts) {
259 data_deps = [ ":${invoker.target_name}__rts_filters" ]
260 }
agrieve62ab00282016-04-05 02:03:45261 }
Andrew Grievee1dc23f2019-10-22 16:26:36262 }
agrieve62ab00282016-04-05 02:03:45263
Andrew Grievee1dc23f2019-10-22 16:26:36264 test_runner_script(_test_runner_target) {
265 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce844392016-12-15 19:57:57266
Andrew Grievee1dc23f2019-10-22 16:26:36267 if (_use_raw_android_executable) {
268 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34269 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36270 } else {
271 apk_target = ":$_apk_target"
272 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47273
274 # Dep needed for the test runner .runtime_deps file to pick up data
275 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22276 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45277 }
Andrew Grievee1dc23f2019-10-22 16:26:36278 test_name = _output_name
279 test_suite = _output_name
280 test_type = "gtest"
Greg Guterman6963dc02021-04-07 05:20:59281
282 if (use_rts) {
283 data_deps += [ ":${invoker.target_name}__rts_filters" ]
284 }
mikecase56d80d72015-06-03 00:57:26285 }
286
Andrew Grieve7ca6de32019-10-18 03:57:47287 # Create a wrapper script rather than using a group() in order to ensure
288 # "ninja $target_name" always works. If this was a group(), then GN would
289 # not create a top-level alias for it if a target exists in another
290 # directory with the same $target_name.
291 # Also - bots run this script directly for "components_perftests".
292 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01293 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47294 executable = "$root_build_dir/bin/run_$_output_name"
295 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22296 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40297 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47298 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40299 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47300 # Dep needed for the swarming .isolate file to pick up data
301 # deps from the forward_variables_from(invoker, "*") on the library.
302 deps += [
303 ":$_apk_target",
304 ":$_library_target",
305 ]
agrieve62ab00282016-04-05 02:03:45306 }
Dirk Pranke19a58732021-03-24 22:26:22307
308 if (defined(invoker.data_deps)) {
309 data_deps = invoker.data_deps
310 } else {
311 data_deps = []
312 }
Jamie Madilldd60ee62021-04-13 19:25:52313 if (tests_have_location_tags) {
314 data = [ "//testing/location_tags.json" ]
315 }
Greg Guterman6963dc02021-04-07 05:20:59316
317 if (use_rts) {
318 data_deps += [ ":${invoker.target_name}__rts_filters" ]
319 }
agrieve1a02e582015-10-15 21:35:39320 }
Scott Graham4c4cdc52017-05-29 20:45:03321 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30322 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
323
Scott Graham4c4cdc52017-05-29 20:45:03324 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42325 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42326 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03327
Wez6879f8a2021-09-07 20:27:02328 # Generate a CMX fragment that provides the program name.
329 _test_program_fragment_target = "${target_name}_program-fragment"
330 _test_program_fragment = "${target_out_dir}/${target_name}_program.test-cmx"
331 _program_name = get_label_info(":${_exec_target}", "name")
332 generated_file(_test_program_fragment_target) {
333 contents = "{ \"program\": { \"binary\": \"${_program_name}\"}}"
334 outputs = [ _test_program_fragment ]
335 }
Chong Gu26908f42021-01-29 03:13:07336
Wez6879f8a2021-09-07 20:27:02337 # Collate the complete set of elements to include in the test component's
338 # manifest.
339 _manifest_fragments = [
340 "//build/config/fuchsia/test/minimum_capabilities.test-cmx",
341 _test_program_fragment,
342 ]
Chong Gu91a1fea2021-03-30 17:24:31343 if (defined(invoker.additional_manifest_fragments)) {
Wez6879f8a2021-09-07 20:27:02344 _manifest_fragments += invoker.additional_manifest_fragments
Chong Guacf19a32021-03-10 01:07:41345 }
Chong Gu28bf7e72021-05-26 01:36:19346
Wez6879f8a2021-09-07 20:27:02347 # Generate the test component manifest from the specified elements.
348 _test_component_manifest_target = "${target_name}_component-manifest"
349 _test_component_manifest = "${target_out_dir}/${target_name}.cmx"
350 cmc_merge(_test_component_manifest_target) {
351 sources = _manifest_fragments
352 output_name = "${_output_name}.cmx"
353 deps = [ ":${_test_program_fragment_target}" ]
Chong Gu7ad57c22021-03-11 00:24:38354 }
Chong Gu26908f42021-01-29 03:13:07355
Wez6879f8a2021-09-07 20:27:02356 # Define the test component, dependent on the generated manifest, and the
357 # test executable target.
358 _test_component_target = "${target_name}_component"
359 fuchsia_component(_test_component_target) {
360 deps = [ ":$_test_component_manifest_target" ]
361 data_deps = [ ":$_exec_target" ]
362 manifest = _test_component_manifest
363 visibility = [ ":*" ]
364 }
365
366 # Define components for each entry in |additional_manifests|, if any. Since
367 # manifests may themselves depend-on the outputs of |deps|, these components
368 # must each individually depend on |invoker.deps|.
369 _test_component_targets = [ ":${_test_component_target}" ]
370 if (defined(invoker.additional_manifests)) {
371 foreach(filename, invoker.additional_manifests) {
372 _additional_component_target =
373 target_name + "_" + get_path_info(filename, "name")
374 _test_component_targets += [ ":${_additional_component_target}" ]
375 fuchsia_component(_additional_component_target) {
376 forward_variables_from(invoker, [ "testonly" ])
377 data_deps = [ ":$_exec_target" ]
378 visibility = [ ":*" ]
379 manifest = filename
380
381 # Depend on |invoker.deps|, in case it includes a dependency that
382 # creates this additional component's manifest.
383 if (defined(invoker.deps)) {
384 deps = invoker.deps
385 }
386 }
387 }
388 }
389
390 # Define the package target that will bundle the test and additional
391 # components and their data.
392 fuchsia_package(_pkg_target) {
393 forward_variables_from(invoker, [ "excluded_files" ])
394 package_name = _output_name
395 deps = _test_component_targets
396 }
397
398 # |target_name| refers to the package-runner rule, so that building
399 # "base_unittests" will build not only the executable, component, and
400 # package, but also the script required to run them.
Kevin Marshall39b4aa82018-06-23 00:12:15401 fuchsia_package_runner(target_name) {
Dirk Pranked5e9a1b22020-10-28 22:52:59402 is_test_exe = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53403 forward_variables_from(invoker,
404 [
Casey Hillersfb3f40f2021-06-09 21:05:42405 "use_run_test_component",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53406 "use_test_server",
407 "package_deps",
Andrew Grieve1b290e4a22020-11-24 20:07:01408 "visibility",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53409 ])
Kevin Marshall39b4aa82018-06-23 00:12:15410 runner_script = "//build/fuchsia/test_runner.py"
411 package = ":$_pkg_target"
412 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42413
Jamie Madilldd60ee62021-04-13 19:25:52414 if (tests_have_location_tags) {
415 data = [ "//testing/location_tags.json" ]
416 }
Wezdd593a52020-04-08 17:09:46417 data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Greg Guterman6963dc02021-04-07 05:20:59418
419 if (use_rts) {
420 data_deps += [ ":${invoker.target_name}__rts_filters" ]
421 }
Kevin Marshallf35fa5f2018-01-29 19:24:42422 }
423
424 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01425 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42426 output_name = _exec_target
Greg Guterman50ed4b42021-04-08 01:15:11427
428 if (use_rts) {
429 if (!defined(data_deps)) {
430 data_deps = []
431 }
432 data_deps += [ ":${invoker.target_name}__rts_filters" ]
433 }
Scott Graham4c4cdc52017-05-29 20:45:03434 }
dpranke2a294622015-08-07 05:23:01435 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30436 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46437 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30438
Rohit Raof9b096d2019-09-09 22:26:23439 declare_args() {
440 # Keep the unittest-as-xctest functionality defaulted to off until the
441 # bots are updated to handle it properly.
442 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
443 # supports running unittests with xctest.
444 enable_run_ios_unittests_with_xctest = false
445 }
446
sdefresne012857872016-03-16 10:55:37447 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36448 _wrapper_output_name = "run_${target_name}"
449 ios_test_runner_wrapper(_wrapper_output_name) {
450 forward_variables_from(invoker,
451 [
452 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36453 "deps",
454 "executable_args",
455 "retries",
456 "shards",
457 ])
458
459 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
460
461 if (!defined(executable_args)) {
462 executable_args = []
463 }
464 executable_args += [
465 "--app",
466 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
467 ]
468
469 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22470
471 if (!defined(data)) {
472 data = []
473 }
Jamie Madilldd60ee62021-04-13 19:25:52474 if (tests_have_location_tags) {
475 data += [ "//testing/location_tags.json" ]
476 }
Jeff Yoonf7f4eb42020-03-06 18:55:36477 }
478
sdefresne012857872016-03-16 10:55:37479 _resources_bundle_data = target_name + "_resources_bundle_data"
480
481 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34482 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22483 sources = [ "//testing/gtest_ios/Default.png" ]
484 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01485 }
486
Mirko Bonadei15522bc2020-09-16 20:38:39487 force_xctest = enable_run_ios_unittests_with_xctest ||
488 (defined(invoker.is_xctest) && invoker.is_xctest)
489
490 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23491 ios_test_target_type = "ios_xctest_test"
492 } else {
493 ios_test_target_type = "ios_app_bundle"
494 }
495
496 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01497 testonly = true
sdefresnea828c282016-05-30 18:04:20498
Mirko Bonadei15522bc2020-09-16 20:38:39499 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23500 xctest_module_target = "//base/test:google_test_runner"
501 }
502
Andrew Grieve1b290e4a22020-11-24 20:07:01503 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13504
505 # Provide sensible defaults in case invoker did not define any of those
506 # required variables.
sdefresne05b97ca2016-06-08 07:19:46507 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13508 info_plist = "//testing/gtest_ios/unittest-Info.plist"
509 }
sdefresne9e147e02016-06-07 00:10:13510
Sylvain Defresne3c5a1312021-09-23 17:08:09511 if (ios_use_shared_bundle_id_for_test_apps) {
512 _gtest_bundle_id_suffix = "unittests"
513 } else {
514 _gtest_bundle_id_suffix = "${target_name}"
515 }
516 xcode_product_bundle_id =
517 "$ios_app_bundle_id_prefix.gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19518
sdefresne9e147e02016-06-07 00:10:13519 if (!defined(extra_substitutions)) {
520 extra_substitutions = []
521 }
Olivier Robin9689c562020-04-17 14:03:57522 extra_substitutions +=
523 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01524
sdefresne047490e2016-07-22 08:49:34525 if (!defined(bundle_deps)) {
526 bundle_deps = []
527 }
528 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36529
530 if (!defined(data_deps)) {
531 data_deps = []
532 }
533
534 # Include the generate_wrapper as part of data_deps
535 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46536 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc02021-04-07 05:20:59537
538 if (use_rts) {
539 data_deps += [ ":${invoker.target_name}__rts_filters" ]
540 }
dpranke2a294622015-08-07 05:23:01541 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11542 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
543 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30544 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
545
Yuke Liao2a9b2f0e2021-04-16 00:40:11546 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32547
Benjamin Pastene3bce864e2018-04-14 01:16:32548 _gen_runner_target = "${target_name}__runner"
549 _runtime_deps_file =
550 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
551 "/" + get_label_info(target_name, "name") + ".runtime_deps"
552
Xinan Lin6be01252021-06-25 23:07:36553 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
554 if (is_skylab) {
555 generate_skylab_runner_script(_gen_runner_target) {
556 generated_script = _generated_script
557 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34558 }
Xinan Lin6be01252021-06-25 23:07:36559 } else {
560 generate_runner_script(_gen_runner_target) {
561 generated_script = _generated_script
562 test_exe = invoker.target_name
563 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34564
Xinan Lin6be01252021-06-25 23:07:36565 if (is_chromeos_lacros) {
566 # At build time, Lacros tests don't know whether they'll run on VM or
567 # HW, and instead, these flags are specified at runtime when invoking
568 # the generated runner script.
569 skip_generating_board_args = true
570 }
Greg Guterman6963dc02021-04-07 05:20:59571
Xinan Lin6be01252021-06-25 23:07:36572 if (tests_have_location_tags) {
573 data = [ "//testing/location_tags.json" ]
574 }
575
576 if (use_rts) {
577 data_deps = [ ":${invoker.target_name}__rts_filters" ]
578 }
Greg Guterman6963dc02021-04-07 05:20:59579 }
Benjamin Pastene3bce864e2018-04-14 01:16:32580 }
581
582 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01583 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
584 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32585 if (!defined(deps)) {
586 deps = []
587 }
588 if (!defined(data)) {
589 data = []
590 }
591
Ben Pastene41041782019-02-16 04:21:58592 # We use a special trigger script for CrOS hardware tests.
593 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
594
Benjamin Pastene3bce864e2018-04-14 01:16:32595 output_name = target_name
596 write_runtime_deps = _runtime_deps_file
597 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37598 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc02021-04-07 05:20:59599
600 if (use_rts) {
601 if (!defined(data_deps)) {
602 data_deps = []
603 }
604 data_deps += [ ":${invoker.target_name}__rts_filters" ]
605 }
Benjamin Pastene3bce864e2018-04-14 01:16:32606 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11607 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24608 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
609 _executable = target_name
610 _gen_runner_target = "${target_name}__runner"
611
Yuke Liao32af4242020-07-16 21:48:02612 if (defined(invoker.use_xvfb)) {
613 _use_xvfb = invoker.use_xvfb
614 } else {
615 _use_xvfb = false
616 }
617
Yuke Liaod037abc2020-10-06 22:48:22618 # When use_xvfb is set by the invoker, it indicates that running this test
619 # target requires a window, and in lacros build, ash-chrome serves as the
620 # display server. Note that even though the tests themselves do not require
621 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
622 # because ash-chrome is based on x11.
623 _use_ash_chrome = _use_xvfb
624
Yuke Liaoe703384b2020-07-16 01:05:24625 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24626 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02627
Yuke Liao2e4953cf2020-07-26 19:20:19628 data = []
Will Harrisd35e2c92021-04-07 01:42:02629 data_deps = [ "//testing:test_scripts_shared" ]
630
Yuke Liao32af4242020-07-16 21:48:02631 if (_use_xvfb) {
632 executable = "//testing/xvfb.py"
633 } else {
634 executable = "//testing/test_env.py"
635 }
Jamie Madilldd60ee62021-04-13 19:25:52636 if (tests_have_location_tags) {
637 data += [ "//testing/location_tags.json" ]
638 }
Yuke Liao32af4242020-07-16 21:48:02639
Yuke Liaoe703384b2020-07-16 01:05:24640 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02641 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39642 "test",
Yuke Liaoe703384b2020-07-16 01:05:24643 "@WrappedPath(./${_executable})",
644 "--test-launcher-bot-mode",
645 ]
Yuke Liao32af4242020-07-16 21:48:02646
Yuke Liaof540c742020-07-29 16:28:34647 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37648 executable_args += [ "--ash-chrome-path" ]
649
650 # Can't use --ash-chrome-path=path because WrappedPath
651 # won't be expanded for that usage.
652 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39653 }
654
Yuke Liaoe703384b2020-07-16 01:05:24655 if (is_asan) {
656 executable_args += [ "--asan=true" ]
657 }
658 if (is_msan) {
659 executable_args += [ "--msan=true" ]
660 }
661 if (is_tsan) {
662 executable_args += [ "--tsan=true" ]
663 }
664 if (use_cfi_diag) {
665 executable_args += [ "--cfi-diag=true" ]
666 }
667
Yuke Liao2e4953cf2020-07-26 19:20:19668 data += [
Yuke Liao240816d2020-07-22 00:10:39669 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24670 "//.vpython",
671 ]
Greg Guterman6963dc02021-04-07 05:20:59672
673 if (use_rts) {
674 data_deps += [ ":${invoker.target_name}__rts_filters" ]
675 }
Yuke Liaoe703384b2020-07-16 01:05:24676 }
677
678 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01679 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
680 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24681 if (!defined(deps)) {
682 deps = []
683 }
684
Yuke Liaod037abc2020-10-06 22:48:22685 if (!defined(data_deps)) {
686 data_deps = []
687 }
688
Yuke Liaoe703384b2020-07-16 01:05:24689 write_runtime_deps = _runtime_deps_file
690 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22691 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56692 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22693 }
Greg Guterman6963dc02021-04-07 05:20:59694
695 if (use_rts) {
696 data_deps += [ ":${invoker.target_name}__rts_filters" ]
697 }
Yuke Liaoe703384b2020-07-16 01:05:24698 }
Dirk Prankedd4ff742020-11-18 19:57:32699 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30700 if (is_mac || is_win) {
701 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
702 }
703
Dirk Prankedd4ff742020-11-18 19:57:32704 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
705 _executable = target_name
706 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06707
Dirk Prankedd4ff742020-11-18 19:57:32708 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
709 _use_xvfb = invoker.use_xvfb
710 } else {
711 _use_xvfb = false
712 }
713
714 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32715 wrapper_script = "$root_build_dir/bin/run_" + _executable
716
717 data = []
Will Harrisd35e2c92021-04-07 01:42:02718 data_deps = [ "//testing:test_scripts_shared" ]
719
Dirk Prankedd4ff742020-11-18 19:57:32720 if (_use_xvfb) {
721 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06722 } else {
Dirk Prankedd4ff742020-11-18 19:57:32723 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06724 }
Jamie Madilldd60ee62021-04-13 19:25:52725 if (tests_have_location_tags) {
726 data += [ "//testing/location_tags.json" ]
727 }
Dirk Pranke31e346e2020-07-15 00:54:06728
Dirk Prankedd4ff742020-11-18 19:57:32729 executable_args = [
730 "@WrappedPath(./${_executable})",
731 "--test-launcher-bot-mode",
732 ]
733 if (is_asan) {
734 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06735 }
Dirk Prankedd4ff742020-11-18 19:57:32736 if (is_msan) {
737 executable_args += [ "--msan=true" ]
738 }
739 if (is_tsan) {
740 executable_args += [ "--tsan=true" ]
741 }
742 if (use_cfi_diag) {
743 executable_args += [ "--cfi-diag=true" ]
744 }
745
746 data += [ "//.vpython" ]
Greg Guterman6963dc02021-04-07 05:20:59747
748 if (use_rts) {
749 data_deps += [ ":${invoker.target_name}__rts_filters" ]
750 }
Dirk Pranke31e346e2020-07-15 00:54:06751 }
752
753 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01754 forward_variables_from(invoker,
755 "*",
756 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
757 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06758 if (!defined(deps)) {
759 deps = []
760 }
761
Dirk Pranke31e346e2020-07-15 00:54:06762 deps += [
763 # Give tests the default manifest on Windows (a no-op elsewhere).
764 "//build/win:default_exe_manifest",
765 ]
766
Dirk Prankedd4ff742020-11-18 19:57:32767 write_runtime_deps = _runtime_deps_file
768 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11769
770 if (use_rts) {
771 if (!defined(data_deps)) {
772 data_deps = []
773 }
774 data_deps += [ ":${invoker.target_name}__rts_filters" ]
775 }
Dirk Prankedd4ff742020-11-18 19:57:32776 }
777 } else {
778 # This is a catch-all clause for NaCl toolchains and other random
779 # configurations that might define tests; test() in these configs
780 # will just define the underlying executables.
781 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
782 "use_xvfb should not be defined for a non-linux configuration")
783 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01784 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
785 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32786 if (!defined(deps)) {
787 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06788 }
Greg Guterman6963dc02021-04-07 05:20:59789
790 if (use_rts) {
791 if (!defined(data_deps)) {
792 data_deps = []
793 }
794 data_deps += [ ":${invoker.target_name}__rts_filters" ]
795 }
Dirk Pranke31e346e2020-07-15 00:54:06796 }
qsrfb5251d12015-01-21 15:57:22797 }
798}
brettwedb6ecc2016-07-14 23:37:03799
Dirk Pranke6188075b2020-10-01 19:31:28800# Defines a type of test that invokes a script to run, rather than
801# invoking an executable.
802#
803# The script must implement the
804# [test executable API](//docs/testing/test_executable_api.md).
805#
806# The template must be passed the `script` parameter, which specifies
807# the path to the script to run. It may optionally be passed a
808# `script_args` parameter, which can be used to include a list of
809# args to be specified by default. The template will produce
810# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
811# for the target to $root_build_dir/${target_name}.runtime_deps, as per
812# the conventions listed in the
813# [test wrapper API](//docs/testing/test_wrapper_api.md).
814template("script_test") {
Greg Guterman6963dc02021-04-07 05:20:59815 if (use_rts) {
816 action("${target_name}__rts_filters") {
817 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53818 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc02021-04-07 05:20:59819 args = [ rebase_path(rts_file, root_build_dir) ]
820 outputs = [ rts_file ]
821 }
822 }
823
Dirk Pranke6188075b2020-10-01 19:31:28824 generate_wrapper(target_name) {
825 testonly = true
826 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
827
828 executable = "//testing/test_env.py"
829
830 executable_args =
831 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
832 if (defined(invoker.args)) {
833 executable_args += invoker.args
834 }
835
Will Harrisd35e2c92021-04-07 01:42:02836 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:47837
838 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
839 use_vpython3 = false
840 data += [ "//.vpython" ]
841 } else {
842 use_vpython3 = true
843 data += [ "//.vpython3" ]
844 }
845
Dirk Pranke6188075b2020-10-01 19:31:28846 if (defined(invoker.data)) {
847 data += invoker.data
848 }
Jamie Madilldd60ee62021-04-13 19:25:52849 if (tests_have_location_tags) {
850 data += [ "//testing/location_tags.json" ]
851 }
Dirk Pranke19a58732021-03-24 22:26:22852
Will Harrisd35e2c92021-04-07 01:42:02853 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:28854 if (defined(invoker.data_deps)) {
855 data_deps += invoker.data_deps
856 }
857
858 forward_variables_from(invoker,
859 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01860 TESTONLY_AND_VISIBILITY + [
861 "data",
862 "data_deps",
863 "script",
864 "script_args",
865 ])
866 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28867
868 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc02021-04-07 05:20:59869
870 if (use_rts) {
871 data_deps += [ ":${invoker.target_name}__rts_filters" ]
872 }
Dirk Pranke6188075b2020-10-01 19:31:28873 }
874}
875
brettwedb6ecc2016-07-14 23:37:03876# Test defaults.
877set_defaults("test") {
878 if (is_android) {
879 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41880 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59881 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03882 } else {
883 configs = default_executable_configs
884 }
885}