blob: c330f9391c38d699b0ced6c12f7e774d1f3ceab0 [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")
Mirko Bonadei4a0df432020-09-08 19:06:0211import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2412
Greg Guterman6963dc082021-04-07 05:20:5913declare_args() {
14 # For more info about RTS, please see
15 # //docs/testing/regression-test-selection.md
16 use_rts = false
Jamie Madilldd60ee62021-04-13 19:25:5217
18 # Some component repos (e.g. ANGLE) import //testing but do not have "location_tags.json"
19 tests_have_location_tags = true
Greg Guterman6963dc082021-04-07 05:20:5920}
21
jcivellif4462a352017-01-10 04:45:5922if (is_android) {
23 import("//build/config/android/config.gni")
James Cook209256f2018-12-07 18:40:5024 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5925 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4426 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3227} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0628 import("//build/config/chromecast_build.gni")
Chong Gu26908f4e2021-01-29 03:13:0729 import("//build/config/coverage/coverage.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 Gu26908f4e2021-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.
qsrfb5251d12015-01-21 15:57:2255template("test") {
Greg Guterman6963dc082021-04-07 05:20:5956 # Ensures the rts file exists and if not, creates a dummy file
57 if (use_rts) {
58 action("${target_name}__rts_filters") {
59 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:5360 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:5961 args = [ rebase_path(rts_file, root_build_dir) ]
62 outputs = [ rts_file ]
63 }
64 }
65
Andrew Grieve1b290e4a22020-11-24 20:07:0166 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:3967 if (!is_ios) {
68 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
69 "is_xctest can be set only for iOS builds")
70 }
qsrfb5251d12015-01-21 15:57:2271 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3072 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
73
Peter Kotwicz10742f82021-04-15 22:32:5074 _use_default_launcher =
75 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
76 if (!defined(invoker.use_raw_android_executable)) {
77 # Checkouts where build_with_chromium == false often have a custom GN
78 # template wrapper around test() which sets use_default_launcher == false.
79 # Set the _use_raw_android_executable default so that test() targets which
80 # do not use the custom wrapper
81 # (1) Do not cause "gn gen" to fail
82 # (2) Do not need to be moved into if(build_with_chromium) block.
83 _use_raw_android_executable =
84 !build_with_chromium && _use_default_launcher
85 } else {
86 not_needed([ "_use_default_launcher" ])
87 _use_raw_android_executable = invoker.use_raw_android_executable
88 }
qsrfb5251d12015-01-21 15:57:2289
agrieve67855de2016-03-30 14:46:0190 # output_name is used to allow targets with the same name but in different
91 # packages to still produce unique runner scripts.
92 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2693 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0194 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2695 }
agrieve62ab00282016-04-05 02:03:4596
agrieveb355ad152016-04-19 03:45:2397 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4298 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:5199 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42100 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51101 ]
agrieve3ac557f02016-04-12 15:52:00102
jbudorickced2a252016-06-09 16:38:54103 assert(_use_raw_android_executable || enable_java_templates)
104
agrieve62ab00282016-04-05 02:03:45105 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49106 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
107
agrieve62ab00282016-04-05 02:03:45108 _exec_target = "${target_name}__exec"
109 _dist_target = "${target_name}__dist"
110 _exec_output =
111 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
112
113 executable(_exec_target) {
114 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
115 configs = []
Dirk Pranke19a58732021-03-24 22:26:22116 forward_variables_from(
117 invoker,
118 "*",
119 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
120 "data_deps",
121 "extra_dist_files",
122 ])
agrieve62ab00282016-04-05 02:03:45123
124 # Thanks to the set_defaults() for test(), configs are initialized with
125 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59126 configs -= [
127 "//build/config:shared_library_config",
128 "//build/config/android:hide_all_but_jni",
129 ]
agrieve62ab00282016-04-05 02:03:45130 configs += [ "//build/config:executable_config" ]
131
Dirk Pranke19a58732021-03-24 22:26:22132 if (defined(invoker.data_deps)) {
133 data_deps = invoker.data_deps
134 } else {
135 data_deps = []
136 }
137 if (!defined(data)) {
138 data = []
139 }
Jamie Madilldd60ee62021-04-13 19:25:52140 if (tests_have_location_tags) {
141 data += [ "//testing/location_tags.json" ]
142 }
Dirk Pranke19a58732021-03-24 22:26:22143
agrieve62ab00282016-04-05 02:03:45144 # Don't output to the root or else conflict with the group() below.
145 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11146
147 if (use_rts) {
148 data_deps += [ ":${invoker.target_name}__rts_filters" ]
149 }
agrieve62ab00282016-04-05 02:03:45150 }
151
152 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45153 dist_dir = "$root_out_dir/$target_name"
154 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22155 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45156 if (defined(invoker.extra_dist_files)) {
157 extra_files = invoker.extra_dist_files
158 }
Greg Guterman50ed4b42021-04-08 01:15:11159
160 if (use_rts) {
161 if (!defined(data_deps)) {
162 data_deps = []
163 }
164 data_deps += [ ":${invoker.target_name}__rts_filters" ]
165 }
agrieve62ab00282016-04-05 02:03:45166 }
167 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02168 _library_target = "${target_name}__library"
169 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45170 _apk_specific_vars = [
171 "android_manifest",
agrievec6811b422016-06-23 02:25:09172 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27173 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55174 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45175 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50176 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07177 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02178 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07179 "proguard_configs",
180 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45181 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02182 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45183 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56184 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45185 ]
Siddhartha764226b2018-03-13 02:32:55186
187 # Adds the unwind tables from unstripped binary as an asset file in the
188 # apk, if |add_unwind_tables_in_apk| is specified by the test.
189 if (defined(invoker.add_unwind_tables_in_apk) &&
190 invoker.add_unwind_tables_in_apk) {
191 _unwind_table_asset_name = "${target_name}_unwind_assets"
192 unwind_table_asset(_unwind_table_asset_name) {
Siddhartha764226b2018-03-13 02:32:55193 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22194 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55195 }
196 }
197
agrieve62ab00282016-04-05 02:03:45198 shared_library(_library_target) {
199 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
200 configs = [] # Prevent list overwriting warning.
201 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45202
jbudorickd29ecfa72016-11-18 22:45:42203 forward_variables_from(
204 invoker,
205 "*",
Peter Wen2052bd12020-12-03 20:15:07206 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
207 TESTONLY_AND_VISIBILITY)
208
209 # Native targets do not need to depend on java targets. Filter them out
210 # so that the shared library can be built without needing to wait for
211 # dependent java targets.
212 deps = []
213 if (defined(invoker.deps)) {
214 foreach(_dep, invoker.deps) {
215 _target_label = get_label_info(_dep, "label_no_toolchain")
216 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
217 deps += [ _dep ]
218 }
219 }
220 }
agrieve62ab00282016-04-05 02:03:45221
Peter Kotwiczb9957d62021-04-12 21:09:43222 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37223 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45224 }
225 }
226 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54227 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07228 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45229 apk_name = invoker.target_name
230 if (defined(invoker.output_name)) {
231 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45232 install_script_name = "install_${invoker.output_name}"
233 }
agrieveb355ad152016-04-19 03:45:23234
Daniel Bratellfdda4652019-01-31 15:45:54235 if (defined(invoker.deps)) {
236 deps = invoker.deps
237 } else {
238 deps = []
239 }
240
jcivellif4462a352017-01-10 04:45:59241 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43242 if (_use_default_launcher) {
243 deps += [ "//base/test:test_support_java" ]
244 }
jcivellif4462a352017-01-10 04:45:59245
Siddhartha764226b2018-03-13 02:32:55246 if (defined(_unwind_table_asset_name)) {
247 deps += [ ":${_unwind_table_asset_name}" ]
248 }
Greg Guterman50ed4b42021-04-08 01:15:11249
250 if (use_rts) {
251 data_deps = [ ":${invoker.target_name}__rts_filters" ]
252 }
agrieve62ab00282016-04-05 02:03:45253 }
Andrew Grievee1dc23f2019-10-22 16:26:36254 }
agrieve62ab00282016-04-05 02:03:45255
Andrew Grievee1dc23f2019-10-22 16:26:36256 test_runner_script(_test_runner_target) {
257 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57258
Andrew Grievee1dc23f2019-10-22 16:26:36259 if (_use_raw_android_executable) {
260 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34261 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36262 } else {
263 apk_target = ":$_apk_target"
264 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47265
266 # Dep needed for the test runner .runtime_deps file to pick up data
267 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22268 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45269 }
Andrew Grievee1dc23f2019-10-22 16:26:36270 test_name = _output_name
271 test_suite = _output_name
272 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59273
274 if (use_rts) {
275 data_deps += [ ":${invoker.target_name}__rts_filters" ]
276 }
mikecase56d80d72015-06-03 00:57:26277 }
278
Andrew Grieve7ca6de32019-10-18 03:57:47279 # Create a wrapper script rather than using a group() in order to ensure
280 # "ninja $target_name" always works. If this was a group(), then GN would
281 # not create a top-level alias for it if a target exists in another
282 # directory with the same $target_name.
283 # Also - bots run this script directly for "components_perftests".
284 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01285 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47286 executable = "$root_build_dir/bin/run_$_output_name"
287 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22288 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40289 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47290 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40291 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47292 # Dep needed for the swarming .isolate file to pick up data
293 # deps from the forward_variables_from(invoker, "*") on the library.
294 deps += [
295 ":$_apk_target",
296 ":$_library_target",
297 ]
agrieve62ab00282016-04-05 02:03:45298 }
Dirk Pranke19a58732021-03-24 22:26:22299
300 if (defined(invoker.data_deps)) {
301 data_deps = invoker.data_deps
302 } else {
303 data_deps = []
304 }
Jamie Madilldd60ee62021-04-13 19:25:52305 if (tests_have_location_tags) {
306 data = [ "//testing/location_tags.json" ]
307 }
Greg Guterman6963dc082021-04-07 05:20:59308
309 if (use_rts) {
310 data_deps += [ ":${invoker.target_name}__rts_filters" ]
311 }
agrieve1a02e582015-10-15 21:35:39312 }
Scott Graham4c4cdc52017-05-29 20:45:03313 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30314 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
315
Scott Graham4c4cdc52017-05-29 20:45:03316 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42317 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42318 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03319
Chong Gu50c83392021-04-06 23:00:27320 manifest_fragments =
321 [ "//build/config/fuchsia/test/minimum_capabilities.test-cmx" ]
Chong Gu26908f4e2021-01-29 03:13:07322
Chong Gu91a1fea2021-03-30 17:24:31323 if (defined(invoker.additional_manifest_fragments)) {
324 manifest_fragments += invoker.additional_manifest_fragments
Chong Guacf19a32021-03-10 01:07:41325 }
Chong Gu26908f4e2021-01-29 03:13:07326 if (use_clang_coverage) {
Chong Gu7ad57c22021-03-11 00:24:38327 manifest_fragments +=
328 [ "//build/config/fuchsia/add_DebugData_service.test-cmx" ]
Chong Gu26908f4e2021-01-29 03:13:07329 }
Chong Gu7ad57c22021-03-11 00:24:38330 combined_manifest = "${target_name}.test-cmx"
331 cmc_merge(combined_manifest) {
332 sources = manifest_fragments
333 output_name = target_name
334 }
335 manifest = "${target_out_dir}/${combined_manifest}"
Chong Gu26908f4e2021-01-29 03:13:07336
Kevin Marshall39b4aa82018-06-23 00:12:15337 fuchsia_package_runner(target_name) {
Dirk Pranked5e9a1b22020-10-28 22:52:59338 is_test_exe = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53339 forward_variables_from(invoker,
340 [
341 "use_test_server",
342 "package_deps",
Andrew Grieve1b290e4a22020-11-24 20:07:01343 "visibility",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53344 ])
Kevin Marshall39b4aa82018-06-23 00:12:15345 runner_script = "//build/fuchsia/test_runner.py"
346 package = ":$_pkg_target"
347 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42348
Jamie Madilldd60ee62021-04-13 19:25:52349 if (tests_have_location_tags) {
350 data = [ "//testing/location_tags.json" ]
351 }
Wezdd593a52020-04-08 17:09:46352 data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59353
354 if (use_rts) {
355 data_deps += [ ":${invoker.target_name}__rts_filters" ]
356 }
Kevin Marshallf35fa5f2018-01-29 19:24:42357 }
358
Wezabe2d752020-02-11 17:12:23359 cr_fuchsia_package(_pkg_target) {
Wez890b18c2021-04-16 13:20:46360 forward_variables_from(invoker, [ "additional_manifests" ])
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20361 binary = ":$_exec_target"
362 package_name_override = _output_name
Chong Gu7ad57c22021-03-11 00:24:38363 deps = [ ":$combined_manifest" ]
Wez890b18c2021-04-16 13:20:46364
365 # Pass on the test() target's |deps|, in case any of the files listed in
366 # |additional_manifests| are generated by them.
367 if (defined(invoker.deps)) {
368 deps += invoker.deps
369 }
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20370 }
371
Kevin Marshallf35fa5f2018-01-29 19:24:42372 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01373 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42374 output_name = _exec_target
Greg Guterman50ed4b42021-04-08 01:15:11375
376 if (use_rts) {
377 if (!defined(data_deps)) {
378 data_deps = []
379 }
380 data_deps += [ ":${invoker.target_name}__rts_filters" ]
381 }
Scott Graham4c4cdc52017-05-29 20:45:03382 }
dpranke2a294622015-08-07 05:23:01383 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30384 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46385 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30386
Rohit Raof9b096d2019-09-09 22:26:23387 declare_args() {
388 # Keep the unittest-as-xctest functionality defaulted to off until the
389 # bots are updated to handle it properly.
390 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
391 # supports running unittests with xctest.
392 enable_run_ios_unittests_with_xctest = false
393 }
394
sdefresne012857872016-03-16 10:55:37395 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36396 _wrapper_output_name = "run_${target_name}"
397 ios_test_runner_wrapper(_wrapper_output_name) {
398 forward_variables_from(invoker,
399 [
400 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36401 "deps",
402 "executable_args",
403 "retries",
404 "shards",
405 ])
406
407 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
408
409 if (!defined(executable_args)) {
410 executable_args = []
411 }
412 executable_args += [
413 "--app",
414 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
415 ]
416
417 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22418
419 if (!defined(data)) {
420 data = []
421 }
Jamie Madilldd60ee62021-04-13 19:25:52422 if (tests_have_location_tags) {
423 data += [ "//testing/location_tags.json" ]
424 }
Jeff Yoonf7f4eb42020-03-06 18:55:36425 }
426
sdefresne012857872016-03-16 10:55:37427 _resources_bundle_data = target_name + "_resources_bundle_data"
428
429 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34430 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22431 sources = [ "//testing/gtest_ios/Default.png" ]
432 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01433 }
434
Mirko Bonadei15522bc2020-09-16 20:38:39435 force_xctest = enable_run_ios_unittests_with_xctest ||
436 (defined(invoker.is_xctest) && invoker.is_xctest)
437
438 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23439 ios_test_target_type = "ios_xctest_test"
440 } else {
441 ios_test_target_type = "ios_app_bundle"
442 }
443
444 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01445 testonly = true
sdefresnea828c282016-05-30 18:04:20446
Mirko Bonadei15522bc2020-09-16 20:38:39447 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23448 xctest_module_target = "//base/test:google_test_runner"
449 }
450
Andrew Grieve1b290e4a22020-11-24 20:07:01451 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13452
453 # Provide sensible defaults in case invoker did not define any of those
454 # required variables.
sdefresne05b97ca2016-06-08 07:19:46455 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13456 info_plist = "//testing/gtest_ios/unittest-Info.plist"
457 }
sdefresne9e147e02016-06-07 00:10:13458
Olivier Robin9689c562020-04-17 14:03:57459 _gtest_bundle_id_suffix = "${target_name}"
460 xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19461
sdefresne9e147e02016-06-07 00:10:13462 if (!defined(extra_substitutions)) {
463 extra_substitutions = []
464 }
Olivier Robin9689c562020-04-17 14:03:57465 extra_substitutions +=
466 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01467
sdefresne047490e2016-07-22 08:49:34468 if (!defined(bundle_deps)) {
469 bundle_deps = []
470 }
471 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36472
473 if (!defined(data_deps)) {
474 data_deps = []
475 }
476
477 # Include the generate_wrapper as part of data_deps
478 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46479 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59480
481 if (use_rts) {
482 data_deps += [ ":${invoker.target_name}__rts_filters" ]
483 }
dpranke2a294622015-08-07 05:23:01484 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11485 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
486 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30487 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
488
Yuke Liao2a9b2f0e2021-04-16 00:40:11489 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32490
Benjamin Pastene3bce864e2018-04-14 01:16:32491 _gen_runner_target = "${target_name}__runner"
492 _runtime_deps_file =
493 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
494 "/" + get_label_info(target_name, "name") + ".runtime_deps"
495
Ben Pastene4ab98652018-12-17 18:33:18496 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32497 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39498 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32499 runtime_deps_file = _runtime_deps_file
Haoming Chena9e205c2021-03-25 02:27:11500
Yuke Liaoacb74b12021-04-23 23:37:34501 if (is_chromeos_lacros) {
502 # At build time, Lacros tests don't know whether they'll run on VM or
503 # HW, and instead, these flags are specified at runtime when invoking
504 # the generated runner script.
505 skip_generating_board_args = true
506 }
507
Jamie Madilldd60ee62021-04-13 19:25:52508 if (tests_have_location_tags) {
509 data = [ "//testing/location_tags.json" ]
510 }
Greg Guterman6963dc082021-04-07 05:20:59511
512 if (use_rts) {
513 data_deps = [ ":${invoker.target_name}__rts_filters" ]
514 }
Benjamin Pastene3bce864e2018-04-14 01:16:32515 }
516
517 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01518 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
519 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32520 if (!defined(deps)) {
521 deps = []
522 }
523 if (!defined(data)) {
524 data = []
525 }
526
Ben Pastene41041782019-02-16 04:21:58527 # We use a special trigger script for CrOS hardware tests.
528 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
529
Benjamin Pastene3bce864e2018-04-14 01:16:32530 output_name = target_name
531 write_runtime_deps = _runtime_deps_file
532 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37533 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59534
535 if (use_rts) {
536 if (!defined(data_deps)) {
537 data_deps = []
538 }
539 data_deps += [ ":${invoker.target_name}__rts_filters" ]
540 }
Benjamin Pastene3bce864e2018-04-14 01:16:32541 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11542 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24543 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
544 _executable = target_name
545 _gen_runner_target = "${target_name}__runner"
546
Yuke Liao32af4242020-07-16 21:48:02547 if (defined(invoker.use_xvfb)) {
548 _use_xvfb = invoker.use_xvfb
549 } else {
550 _use_xvfb = false
551 }
552
Yuke Liaod037abc2020-10-06 22:48:22553 # When use_xvfb is set by the invoker, it indicates that running this test
554 # target requires a window, and in lacros build, ash-chrome serves as the
555 # display server. Note that even though the tests themselves do not require
556 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
557 # because ash-chrome is based on x11.
558 _use_ash_chrome = _use_xvfb
559
Yuke Liaoe703384b2020-07-16 01:05:24560 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24561 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02562
Yuke Liao2e4953cf2020-07-26 19:20:19563 data = []
Will Harrisd35e2c92021-04-07 01:42:02564 data_deps = [ "//testing:test_scripts_shared" ]
565
Yuke Liao32af4242020-07-16 21:48:02566 if (_use_xvfb) {
567 executable = "//testing/xvfb.py"
568 } else {
569 executable = "//testing/test_env.py"
570 }
Jamie Madilldd60ee62021-04-13 19:25:52571 if (tests_have_location_tags) {
572 data += [ "//testing/location_tags.json" ]
573 }
Yuke Liao32af4242020-07-16 21:48:02574
Yuke Liaoe703384b2020-07-16 01:05:24575 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02576 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39577 "test",
Yuke Liaoe703384b2020-07-16 01:05:24578 "@WrappedPath(./${_executable})",
579 "--test-launcher-bot-mode",
580 ]
Yuke Liao32af4242020-07-16 21:48:02581
Yuke Liaof540c742020-07-29 16:28:34582 if (_use_ash_chrome) {
Yuke Liao8348aa42020-11-04 19:35:23583 executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ]
Yuke Liao240816d2020-07-22 00:10:39584 }
585
Yuke Liaoe703384b2020-07-16 01:05:24586 if (is_asan) {
587 executable_args += [ "--asan=true" ]
588 }
589 if (is_msan) {
590 executable_args += [ "--msan=true" ]
591 }
592 if (is_tsan) {
593 executable_args += [ "--tsan=true" ]
594 }
595 if (use_cfi_diag) {
596 executable_args += [ "--cfi-diag=true" ]
597 }
598
Yuke Liao2e4953cf2020-07-26 19:20:19599 data += [
Yuke Liao240816d2020-07-22 00:10:39600 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24601 "//.vpython",
602 ]
Greg Guterman6963dc082021-04-07 05:20:59603
604 if (use_rts) {
605 data_deps += [ ":${invoker.target_name}__rts_filters" ]
606 }
Yuke Liaoe703384b2020-07-16 01:05:24607 }
608
609 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01610 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
611 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24612 if (!defined(deps)) {
613 deps = []
614 }
615
Yuke Liaod037abc2020-10-06 22:48:22616 if (!defined(data_deps)) {
617 data_deps = []
618 }
619
Yuke Liaoe703384b2020-07-16 01:05:24620 write_runtime_deps = _runtime_deps_file
621 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22622 if (_use_ash_chrome && also_build_ash_chrome) {
623 data_deps +=
624 [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ]
625 }
Greg Guterman6963dc082021-04-07 05:20:59626
627 if (use_rts) {
628 data_deps += [ ":${invoker.target_name}__rts_filters" ]
629 }
Yuke Liaoe703384b2020-07-16 01:05:24630 }
Dirk Prankedd4ff742020-11-18 19:57:32631 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30632 if (is_mac || is_win) {
633 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
634 }
635
Dirk Prankedd4ff742020-11-18 19:57:32636 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
637 _executable = target_name
638 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06639
Dirk Prankedd4ff742020-11-18 19:57:32640 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
641 _use_xvfb = invoker.use_xvfb
642 } else {
643 _use_xvfb = false
644 }
645
646 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32647 wrapper_script = "$root_build_dir/bin/run_" + _executable
648
649 data = []
Will Harrisd35e2c92021-04-07 01:42:02650 data_deps = [ "//testing:test_scripts_shared" ]
651
Dirk Prankedd4ff742020-11-18 19:57:32652 if (_use_xvfb) {
653 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06654 } else {
Dirk Prankedd4ff742020-11-18 19:57:32655 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06656 }
Jamie Madilldd60ee62021-04-13 19:25:52657 if (tests_have_location_tags) {
658 data += [ "//testing/location_tags.json" ]
659 }
Dirk Pranke31e346e2020-07-15 00:54:06660
Dirk Prankedd4ff742020-11-18 19:57:32661 executable_args = [
662 "@WrappedPath(./${_executable})",
663 "--test-launcher-bot-mode",
664 ]
665 if (is_asan) {
666 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06667 }
Dirk Prankedd4ff742020-11-18 19:57:32668 if (is_msan) {
669 executable_args += [ "--msan=true" ]
670 }
671 if (is_tsan) {
672 executable_args += [ "--tsan=true" ]
673 }
674 if (use_cfi_diag) {
675 executable_args += [ "--cfi-diag=true" ]
676 }
677
678 data += [ "//.vpython" ]
Greg Guterman6963dc082021-04-07 05:20:59679
680 if (use_rts) {
681 data_deps += [ ":${invoker.target_name}__rts_filters" ]
682 }
Dirk Pranke31e346e2020-07-15 00:54:06683 }
684
685 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01686 forward_variables_from(invoker,
687 "*",
688 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
689 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06690 if (!defined(deps)) {
691 deps = []
692 }
693
Dirk Pranke31e346e2020-07-15 00:54:06694 deps += [
695 # Give tests the default manifest on Windows (a no-op elsewhere).
696 "//build/win:default_exe_manifest",
697 ]
698
Dirk Prankedd4ff742020-11-18 19:57:32699 write_runtime_deps = _runtime_deps_file
700 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11701
702 if (use_rts) {
703 if (!defined(data_deps)) {
704 data_deps = []
705 }
706 data_deps += [ ":${invoker.target_name}__rts_filters" ]
707 }
Dirk Prankedd4ff742020-11-18 19:57:32708 }
709 } else {
710 # This is a catch-all clause for NaCl toolchains and other random
711 # configurations that might define tests; test() in these configs
712 # will just define the underlying executables.
713 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
714 "use_xvfb should not be defined for a non-linux configuration")
715 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01716 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
717 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32718 if (!defined(deps)) {
719 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06720 }
Greg Guterman6963dc082021-04-07 05:20:59721
722 if (use_rts) {
723 if (!defined(data_deps)) {
724 data_deps = []
725 }
726 data_deps += [ ":${invoker.target_name}__rts_filters" ]
727 }
Dirk Pranke31e346e2020-07-15 00:54:06728 }
qsrfb5251d12015-01-21 15:57:22729 }
730}
brettwedb6ecc2016-07-14 23:37:03731
Dirk Pranke6188075b2020-10-01 19:31:28732# Defines a type of test that invokes a script to run, rather than
733# invoking an executable.
734#
735# The script must implement the
736# [test executable API](//docs/testing/test_executable_api.md).
737#
738# The template must be passed the `script` parameter, which specifies
739# the path to the script to run. It may optionally be passed a
740# `script_args` parameter, which can be used to include a list of
741# args to be specified by default. The template will produce
742# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
743# for the target to $root_build_dir/${target_name}.runtime_deps, as per
744# the conventions listed in the
745# [test wrapper API](//docs/testing/test_wrapper_api.md).
746template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:59747 if (use_rts) {
748 action("${target_name}__rts_filters") {
749 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53750 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:59751 args = [ rebase_path(rts_file, root_build_dir) ]
752 outputs = [ rts_file ]
753 }
754 }
755
Dirk Pranke6188075b2020-10-01 19:31:28756 generate_wrapper(target_name) {
757 testonly = true
758 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
759
760 executable = "//testing/test_env.py"
761
762 executable_args =
763 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
764 if (defined(invoker.args)) {
765 executable_args += invoker.args
766 }
767
Will Harrisd35e2c92021-04-07 01:42:02768 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:47769
770 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
771 use_vpython3 = false
772 data += [ "//.vpython" ]
773 } else {
774 use_vpython3 = true
775 data += [ "//.vpython3" ]
776 }
777
Dirk Pranke6188075b2020-10-01 19:31:28778 if (defined(invoker.data)) {
779 data += invoker.data
780 }
Jamie Madilldd60ee62021-04-13 19:25:52781 if (tests_have_location_tags) {
782 data += [ "//testing/location_tags.json" ]
783 }
Dirk Pranke19a58732021-03-24 22:26:22784
Will Harrisd35e2c92021-04-07 01:42:02785 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:28786 if (defined(invoker.data_deps)) {
787 data_deps += invoker.data_deps
788 }
789
790 forward_variables_from(invoker,
791 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01792 TESTONLY_AND_VISIBILITY + [
793 "data",
794 "data_deps",
795 "script",
796 "script_args",
797 ])
798 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28799
800 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:59801
802 if (use_rts) {
803 data_deps += [ ":${invoker.target_name}__rts_filters" ]
804 }
Dirk Pranke6188075b2020-10-01 19:31:28805 }
806}
807
brettwedb6ecc2016-07-14 23:37:03808# Test defaults.
809set_defaults("test") {
810 if (is_android) {
811 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41812 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59813 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03814 } else {
815 configs = default_executable_configs
816 }
817}