[go: nahoru, domu]

blob: 3c3e2116d068161510621bee1ffad62d3130d6e9 [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 Liaoe703384b2020-07-16 01:05:249import("//build/config/chromeos/ui_mode.gni")
Mirko Bonadei4a0df432020-09-08 19:06:0210import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2411
Greg Guterman6963dc02021-04-07 05:20:5912declare_args() {
13 # For more info about RTS, please see
14 # //docs/testing/regression-test-selection.md
15 use_rts = false
Jamie Madilldd60ee62021-04-13 19:25:5216
17 # Some component repos (e.g. ANGLE) import //testing but do not have "location_tags.json"
18 tests_have_location_tags = true
Greg Guterman6963dc02021-04-07 05:20:5919}
20
jcivellif4462a352017-01-10 04:45:5921if (is_android) {
22 import("//build/config/android/config.gni")
James Cook209256f2018-12-07 18:40:5023 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5924 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4425 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3226} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0627 import("//build/config/chromecast_build.gni")
Chong Gu26908f42021-01-29 03:13:0728 import("//build/config/coverage/coverage.gni")
Kevin Marshall55fd8522019-10-04 22:47:0129 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4230 import("//build/config/fuchsia/package.gni")
Chong Gu26908f42021-01-29 03:13:0731 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Yuta Hijikatac2975452020-12-16 15:59:3932} else if (is_chromeos_ash) {
Ben Pastene4c35c572018-04-30 23:21:4833 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3234 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2835 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3236} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3637 import("//build/config/ios/ios_sdk.gni")
38 import("//build/config/ios/ios_test_runner_wrapper.gni")
39 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3240} else {
Dirk Pranke31e346e2020-07-15 00:54:0641 import("//build/config/sanitizers/sanitizers.gni")
42 import("//build/util/generate_wrapper.gni")
43}
44
qsrfb5251d12015-01-21 15:57:2245# Define a test as an executable (or apk on Android) with the "testonly" flag
46# set.
agrieve62ab00282016-04-05 02:03:4547# Variable:
Dirk Pranke79d065d2020-08-29 03:28:3048# use_xvfb: (optional) whether to run the executable under Xvfb.
agrieve62ab00282016-04-05 02:03:4549# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:5650# use_native_activity: Test implements ANativeActivity_onCreate().
Mirko Bonadei15522bc2020-09-16 20:38:3951# is_xctest: (iOS, optional) whether to build the executable as XCTest.
52# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
53# for build targets.
Haoming Chena9e205c2021-03-25 02:27:1154# override_board: (ash, optional) override the 'cros_board' used in
55# generating the test runner script.
qsrfb5251d12015-01-21 15:57:2256template("test") {
Greg Guterman6963dc02021-04-07 05:20:5957 # Ensures the rts file exists and if not, creates a dummy file
58 if (use_rts) {
59 action("${target_name}__rts_filters") {
60 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:5361 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc02021-04-07 05:20:5962 args = [ rebase_path(rts_file, root_build_dir) ]
63 outputs = [ rts_file ]
64 }
65 }
66
Andrew Grieve1b290e4a22020-11-24 20:07:0167 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:3968 if (!is_ios) {
69 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
70 "is_xctest can be set only for iOS builds")
71 }
Haoming Chena9e205c2021-03-25 02:27:1172 if (!is_chromeos_ash || cros_board == "") {
73 assert(
74 !defined(invoker.override_board),
75 "override_board can be set only for ChromeOS builds with target board")
76 }
qsrfb5251d12015-01-21 15:57:2277 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3078 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
79
agrieve62ab00282016-04-05 02:03:4580 _use_raw_android_executable = defined(invoker.use_raw_android_executable) &&
81 invoker.use_raw_android_executable
qsrfb5251d12015-01-21 15:57:2282
agrieve67855de2016-03-30 14:46:0183 # output_name is used to allow targets with the same name but in different
84 # packages to still produce unique runner scripts.
85 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2686 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0187 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2688 }
agrieve62ab00282016-04-05 02:03:4589
agrieveb355ad152016-04-19 03:45:2390 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4291 _wrapper_script_vars = [
agrievee41ae1902016-04-25 14:12:5192 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4293 "shard_timeout",
agrievee41ae1902016-04-25 14:12:5194 ]
agrieve3ac557f02016-04-12 15:52:0095
jbudorickced2a252016-06-09 16:38:5496 assert(_use_raw_android_executable || enable_java_templates)
97
agrieve62ab00282016-04-05 02:03:4598 if (_use_raw_android_executable) {
99 _exec_target = "${target_name}__exec"
100 _dist_target = "${target_name}__dist"
101 _exec_output =
102 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
103
104 executable(_exec_target) {
105 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
106 configs = []
Dirk Pranke19a58732021-03-24 22:26:22107 forward_variables_from(
108 invoker,
109 "*",
110 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
111 "data_deps",
112 "extra_dist_files",
113 ])
agrieve62ab00282016-04-05 02:03:45114
115 # Thanks to the set_defaults() for test(), configs are initialized with
116 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59117 configs -= [
118 "//build/config:shared_library_config",
119 "//build/config/android:hide_all_but_jni",
120 ]
agrieve62ab00282016-04-05 02:03:45121 configs += [ "//build/config:executable_config" ]
122
Dirk Pranke19a58732021-03-24 22:26:22123 if (defined(invoker.data_deps)) {
124 data_deps = invoker.data_deps
125 } else {
126 data_deps = []
127 }
128 if (!defined(data)) {
129 data = []
130 }
Jamie Madilldd60ee62021-04-13 19:25:52131 if (tests_have_location_tags) {
132 data += [ "//testing/location_tags.json" ]
133 }
Dirk Pranke19a58732021-03-24 22:26:22134
agrieve62ab00282016-04-05 02:03:45135 # Don't output to the root or else conflict with the group() below.
136 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11137
138 if (use_rts) {
139 data_deps += [ ":${invoker.target_name}__rts_filters" ]
140 }
agrieve62ab00282016-04-05 02:03:45141 }
142
143 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45144 dist_dir = "$root_out_dir/$target_name"
145 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22146 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45147 if (defined(invoker.extra_dist_files)) {
148 extra_files = invoker.extra_dist_files
149 }
Greg Guterman50ed4b42021-04-08 01:15:11150
151 if (use_rts) {
152 if (!defined(data_deps)) {
153 data_deps = []
154 }
155 data_deps += [ ":${invoker.target_name}__rts_filters" ]
156 }
agrieve62ab00282016-04-05 02:03:45157 }
158 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02159 _library_target = "${target_name}__library"
160 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45161 _apk_specific_vars = [
162 "android_manifest",
agrievec6811b422016-06-23 02:25:09163 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27164 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55165 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45166 "enable_multidex",
Benoît Lizéd8b8f742019-11-07 12:50:07167 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02168 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07169 "proguard_configs",
170 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45171 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02172 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45173 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56174 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45175 ]
Siddhartha764226b2018-03-13 02:32:55176
Peter Kotwiczb9957d62021-04-12 21:09:43177 _use_default_launcher =
178 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
179
Siddhartha764226b2018-03-13 02:32:55180 # Adds the unwind tables from unstripped binary as an asset file in the
181 # apk, if |add_unwind_tables_in_apk| is specified by the test.
182 if (defined(invoker.add_unwind_tables_in_apk) &&
183 invoker.add_unwind_tables_in_apk) {
184 _unwind_table_asset_name = "${target_name}_unwind_assets"
185 unwind_table_asset(_unwind_table_asset_name) {
Siddhartha764226b2018-03-13 02:32:55186 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22187 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55188 }
189 }
190
agrieve62ab00282016-04-05 02:03:45191 shared_library(_library_target) {
192 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
193 configs = [] # Prevent list overwriting warning.
194 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45195
jbudorickd29ecfa72016-11-18 22:45:42196 forward_variables_from(
197 invoker,
198 "*",
Peter Wen2052bd12020-12-03 20:15:07199 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
200 TESTONLY_AND_VISIBILITY)
201
202 # Native targets do not need to depend on java targets. Filter them out
203 # so that the shared library can be built without needing to wait for
204 # dependent java targets.
205 deps = []
206 if (defined(invoker.deps)) {
207 foreach(_dep, invoker.deps) {
208 _target_label = get_label_info(_dep, "label_no_toolchain")
209 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
210 deps += [ _dep ]
211 }
212 }
213 }
agrieve62ab00282016-04-05 02:03:45214
Peter Kotwiczb9957d62021-04-12 21:09:43215 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37216 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45217 }
218 }
219 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54220 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07221 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45222 apk_name = invoker.target_name
223 if (defined(invoker.output_name)) {
224 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45225 install_script_name = "install_${invoker.output_name}"
226 }
agrieveb355ad152016-04-19 03:45:23227
Daniel Bratellfdda4652019-01-31 15:45:54228 if (defined(invoker.deps)) {
229 deps = invoker.deps
230 } else {
231 deps = []
232 }
233
jcivellif4462a352017-01-10 04:45:59234 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43235 if (_use_default_launcher) {
236 deps += [ "//base/test:test_support_java" ]
237 }
jcivellif4462a352017-01-10 04:45:59238
Siddhartha764226b2018-03-13 02:32:55239 if (defined(_unwind_table_asset_name)) {
240 deps += [ ":${_unwind_table_asset_name}" ]
241 }
Greg Guterman50ed4b42021-04-08 01:15:11242
243 if (use_rts) {
244 data_deps = [ ":${invoker.target_name}__rts_filters" ]
245 }
agrieve62ab00282016-04-05 02:03:45246 }
Andrew Grievee1dc23f2019-10-22 16:26:36247 }
agrieve62ab00282016-04-05 02:03:45248
Andrew Grievee1dc23f2019-10-22 16:26:36249 test_runner_script(_test_runner_target) {
250 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce844392016-12-15 19:57:57251
Andrew Grievee1dc23f2019-10-22 16:26:36252 if (_use_raw_android_executable) {
253 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34254 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36255 } else {
256 apk_target = ":$_apk_target"
257 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47258
259 # Dep needed for the test runner .runtime_deps file to pick up data
260 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22261 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45262 }
Andrew Grievee1dc23f2019-10-22 16:26:36263 test_name = _output_name
264 test_suite = _output_name
265 test_type = "gtest"
Greg Guterman6963dc02021-04-07 05:20:59266
267 if (use_rts) {
268 data_deps += [ ":${invoker.target_name}__rts_filters" ]
269 }
mikecase56d80d72015-06-03 00:57:26270 }
271
Andrew Grieve7ca6de32019-10-18 03:57:47272 # Create a wrapper script rather than using a group() in order to ensure
273 # "ninja $target_name" always works. If this was a group(), then GN would
274 # not create a top-level alias for it if a target exists in another
275 # directory with the same $target_name.
276 # Also - bots run this script directly for "components_perftests".
277 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01278 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47279 executable = "$root_build_dir/bin/run_$_output_name"
280 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22281 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40282 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47283 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40284 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47285 # Dep needed for the swarming .isolate file to pick up data
286 # deps from the forward_variables_from(invoker, "*") on the library.
287 deps += [
288 ":$_apk_target",
289 ":$_library_target",
290 ]
agrieve62ab00282016-04-05 02:03:45291 }
Dirk Pranke19a58732021-03-24 22:26:22292
293 if (defined(invoker.data_deps)) {
294 data_deps = invoker.data_deps
295 } else {
296 data_deps = []
297 }
Jamie Madilldd60ee62021-04-13 19:25:52298 if (tests_have_location_tags) {
299 data = [ "//testing/location_tags.json" ]
300 }
Greg Guterman6963dc02021-04-07 05:20:59301
302 if (use_rts) {
303 data_deps += [ ":${invoker.target_name}__rts_filters" ]
304 }
agrieve1a02e582015-10-15 21:35:39305 }
Scott Graham4c4cdc52017-05-29 20:45:03306 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30307 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
308
Scott Graham4c4cdc52017-05-29 20:45:03309 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42310 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42311 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03312
Chong Gu50c83392021-04-06 23:00:27313 manifest_fragments =
314 [ "//build/config/fuchsia/test/minimum_capabilities.test-cmx" ]
Chong Gu26908f42021-01-29 03:13:07315
Chong Gu91a1fea2021-03-30 17:24:31316 if (defined(invoker.additional_manifest_fragments)) {
317 manifest_fragments += invoker.additional_manifest_fragments
Chong Guacf19a32021-03-10 01:07:41318 }
Chong Gu26908f42021-01-29 03:13:07319 if (use_clang_coverage) {
Chong Gu7ad57c22021-03-11 00:24:38320 manifest_fragments +=
321 [ "//build/config/fuchsia/add_DebugData_service.test-cmx" ]
Chong Gu26908f42021-01-29 03:13:07322 }
Chong Gu7ad57c22021-03-11 00:24:38323 combined_manifest = "${target_name}.test-cmx"
324 cmc_merge(combined_manifest) {
325 sources = manifest_fragments
326 output_name = target_name
327 }
328 manifest = "${target_out_dir}/${combined_manifest}"
Chong Gu26908f42021-01-29 03:13:07329
Kevin Marshall39b4aa82018-06-23 00:12:15330 fuchsia_package_runner(target_name) {
Dirk Pranked5e9a1b22020-10-28 22:52:59331 is_test_exe = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53332 forward_variables_from(invoker,
333 [
334 "use_test_server",
335 "package_deps",
Andrew Grieve1b290e4a22020-11-24 20:07:01336 "visibility",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53337 ])
Kevin Marshall39b4aa82018-06-23 00:12:15338 runner_script = "//build/fuchsia/test_runner.py"
339 package = ":$_pkg_target"
340 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42341
Jamie Madilldd60ee62021-04-13 19:25:52342 if (tests_have_location_tags) {
343 data = [ "//testing/location_tags.json" ]
344 }
Wezdd593a52020-04-08 17:09:46345 data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Greg Guterman6963dc02021-04-07 05:20:59346
347 if (use_rts) {
348 data_deps += [ ":${invoker.target_name}__rts_filters" ]
349 }
Kevin Marshallf35fa5f2018-01-29 19:24:42350 }
351
Wezabe2d752020-02-11 17:12:23352 cr_fuchsia_package(_pkg_target) {
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20353 binary = ":$_exec_target"
354 package_name_override = _output_name
Chong Gu7ad57c22021-03-11 00:24:38355 deps = [ ":$combined_manifest" ]
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20356 }
357
Kevin Marshallf35fa5f2018-01-29 19:24:42358 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01359 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42360 output_name = _exec_target
Greg Guterman50ed4b42021-04-08 01:15:11361
362 if (use_rts) {
363 if (!defined(data_deps)) {
364 data_deps = []
365 }
366 data_deps += [ ":${invoker.target_name}__rts_filters" ]
367 }
Scott Graham4c4cdc52017-05-29 20:45:03368 }
dpranke2a294622015-08-07 05:23:01369 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30370 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46371 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30372
Rohit Raof9b096d2019-09-09 22:26:23373 declare_args() {
374 # Keep the unittest-as-xctest functionality defaulted to off until the
375 # bots are updated to handle it properly.
376 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
377 # supports running unittests with xctest.
378 enable_run_ios_unittests_with_xctest = false
379 }
380
sdefresne012857872016-03-16 10:55:37381 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36382 _wrapper_output_name = "run_${target_name}"
383 ios_test_runner_wrapper(_wrapper_output_name) {
384 forward_variables_from(invoker,
385 [
386 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36387 "deps",
388 "executable_args",
389 "retries",
390 "shards",
391 ])
392
393 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
394
395 if (!defined(executable_args)) {
396 executable_args = []
397 }
398 executable_args += [
399 "--app",
400 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
401 ]
402
403 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22404
405 if (!defined(data)) {
406 data = []
407 }
Jamie Madilldd60ee62021-04-13 19:25:52408 if (tests_have_location_tags) {
409 data += [ "//testing/location_tags.json" ]
410 }
Jeff Yoonf7f4eb42020-03-06 18:55:36411 }
412
sdefresne012857872016-03-16 10:55:37413 _resources_bundle_data = target_name + "_resources_bundle_data"
414
415 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34416 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22417 sources = [ "//testing/gtest_ios/Default.png" ]
418 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01419 }
420
Mirko Bonadei15522bc2020-09-16 20:38:39421 force_xctest = enable_run_ios_unittests_with_xctest ||
422 (defined(invoker.is_xctest) && invoker.is_xctest)
423
424 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23425 ios_test_target_type = "ios_xctest_test"
426 } else {
427 ios_test_target_type = "ios_app_bundle"
428 }
429
430 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01431 testonly = true
sdefresnea828c282016-05-30 18:04:20432
Mirko Bonadei15522bc2020-09-16 20:38:39433 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23434 xctest_module_target = "//base/test:google_test_runner"
435 }
436
Andrew Grieve1b290e4a22020-11-24 20:07:01437 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13438
439 # Provide sensible defaults in case invoker did not define any of those
440 # required variables.
sdefresne05b97ca2016-06-08 07:19:46441 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13442 info_plist = "//testing/gtest_ios/unittest-Info.plist"
443 }
sdefresne9e147e02016-06-07 00:10:13444
Olivier Robin9689c562020-04-17 14:03:57445 _gtest_bundle_id_suffix = "${target_name}"
446 xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19447
sdefresne9e147e02016-06-07 00:10:13448 if (!defined(extra_substitutions)) {
449 extra_substitutions = []
450 }
Olivier Robin9689c562020-04-17 14:03:57451 extra_substitutions +=
452 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01453
sdefresne047490e2016-07-22 08:49:34454 if (!defined(bundle_deps)) {
455 bundle_deps = []
456 }
457 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36458
459 if (!defined(data_deps)) {
460 data_deps = []
461 }
462
463 # Include the generate_wrapper as part of data_deps
464 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46465 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc02021-04-07 05:20:59466
467 if (use_rts) {
468 data_deps += [ ":${invoker.target_name}__rts_filters" ]
469 }
dpranke2a294622015-08-07 05:23:01470 }
Yuta Hijikatac2975452020-12-16 15:59:39471 } else if (is_chromeos_ash && cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30472 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
473
Ben Pastene16882032018-09-21 01:16:39474 # Building for a cros board (ie: not linux-chromeos).
Benjamin Pastene3bce864e2018-04-14 01:16:32475
Benjamin Pastene3bce864e2018-04-14 01:16:32476 _gen_runner_target = "${target_name}__runner"
477 _runtime_deps_file =
478 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
479 "/" + get_label_info(target_name, "name") + ".runtime_deps"
480
Ben Pastene4ab98652018-12-17 18:33:18481 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32482 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39483 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32484 runtime_deps_file = _runtime_deps_file
Haoming Chena9e205c2021-03-25 02:27:11485
486 if (defined(invoker.override_board)) {
487 override_board = invoker.override_board
488 }
489
Jamie Madilldd60ee62021-04-13 19:25:52490 if (tests_have_location_tags) {
491 data = [ "//testing/location_tags.json" ]
492 }
Greg Guterman6963dc02021-04-07 05:20:59493
494 if (use_rts) {
495 data_deps = [ ":${invoker.target_name}__rts_filters" ]
496 }
Benjamin Pastene3bce864e2018-04-14 01:16:32497 }
498
499 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01500 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
501 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32502 if (!defined(deps)) {
503 deps = []
504 }
505 if (!defined(data)) {
506 data = []
507 }
508
Ben Pastene41041782019-02-16 04:21:58509 # We use a special trigger script for CrOS hardware tests.
510 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
511
Benjamin Pastene3bce864e2018-04-14 01:16:32512 output_name = target_name
513 write_runtime_deps = _runtime_deps_file
514 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37515 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc02021-04-07 05:20:59516
517 if (use_rts) {
518 if (!defined(data_deps)) {
519 data_deps = []
520 }
521 data_deps += [ ":${invoker.target_name}__rts_filters" ]
522 }
Benjamin Pastene3bce864e2018-04-14 01:16:32523 }
Yuke Liaoe703384b2020-07-16 01:05:24524 } else if (chromeos_is_browser_only) {
525 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
526 _executable = target_name
527 _gen_runner_target = "${target_name}__runner"
528
Yuke Liao32af4242020-07-16 21:48:02529 if (defined(invoker.use_xvfb)) {
530 _use_xvfb = invoker.use_xvfb
531 } else {
532 _use_xvfb = false
533 }
534
Yuke Liaod037abc2020-10-06 22:48:22535 # When use_xvfb is set by the invoker, it indicates that running this test
536 # target requires a window, and in lacros build, ash-chrome serves as the
537 # display server. Note that even though the tests themselves do not require
538 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
539 # because ash-chrome is based on x11.
540 _use_ash_chrome = _use_xvfb
541
Yuke Liaoe703384b2020-07-16 01:05:24542 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24543 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02544
Yuke Liao2e4953cf2020-07-26 19:20:19545 data = []
Will Harrisd35e2c92021-04-07 01:42:02546 data_deps = [ "//testing:test_scripts_shared" ]
547
Yuke Liao32af4242020-07-16 21:48:02548 if (_use_xvfb) {
549 executable = "//testing/xvfb.py"
550 } else {
551 executable = "//testing/test_env.py"
552 }
Jamie Madilldd60ee62021-04-13 19:25:52553 if (tests_have_location_tags) {
554 data += [ "//testing/location_tags.json" ]
555 }
Yuke Liao32af4242020-07-16 21:48:02556
Yuke Liaoe703384b2020-07-16 01:05:24557 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02558 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39559 "test",
Yuke Liaoe703384b2020-07-16 01:05:24560 "@WrappedPath(./${_executable})",
561 "--test-launcher-bot-mode",
562 ]
Yuke Liao32af4242020-07-16 21:48:02563
Yuke Liaof540c742020-07-29 16:28:34564 if (_use_ash_chrome) {
Yuke Liao8348aa42020-11-04 19:35:23565 executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ]
Yuke Liao240816d2020-07-22 00:10:39566 }
567
Yuke Liaoe703384b2020-07-16 01:05:24568 if (is_asan) {
569 executable_args += [ "--asan=true" ]
570 }
571 if (is_msan) {
572 executable_args += [ "--msan=true" ]
573 }
574 if (is_tsan) {
575 executable_args += [ "--tsan=true" ]
576 }
577 if (use_cfi_diag) {
578 executable_args += [ "--cfi-diag=true" ]
579 }
580
Yuke Liao2e4953cf2020-07-26 19:20:19581 data += [
Yuke Liao240816d2020-07-22 00:10:39582 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24583 "//.vpython",
584 ]
Greg Guterman6963dc02021-04-07 05:20:59585
586 if (use_rts) {
587 data_deps += [ ":${invoker.target_name}__rts_filters" ]
588 }
Yuke Liaoe703384b2020-07-16 01:05:24589 }
590
591 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01592 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
593 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24594 if (!defined(deps)) {
595 deps = []
596 }
597
Yuke Liaod037abc2020-10-06 22:48:22598 if (!defined(data_deps)) {
599 data_deps = []
600 }
601
Yuke Liaoe703384b2020-07-16 01:05:24602 write_runtime_deps = _runtime_deps_file
603 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22604 if (_use_ash_chrome && also_build_ash_chrome) {
605 data_deps +=
606 [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ]
607 }
Greg Guterman6963dc02021-04-07 05:20:59608
609 if (use_rts) {
610 data_deps += [ ":${invoker.target_name}__rts_filters" ]
611 }
Yuke Liaoe703384b2020-07-16 01:05:24612 }
Dirk Prankedd4ff742020-11-18 19:57:32613 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30614 if (is_mac || is_win) {
615 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
616 }
617
Dirk Prankedd4ff742020-11-18 19:57:32618 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
619 _executable = target_name
620 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06621
Dirk Prankedd4ff742020-11-18 19:57:32622 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
623 _use_xvfb = invoker.use_xvfb
624 } else {
625 _use_xvfb = false
626 }
627
628 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32629 wrapper_script = "$root_build_dir/bin/run_" + _executable
630
631 data = []
Will Harrisd35e2c92021-04-07 01:42:02632 data_deps = [ "//testing:test_scripts_shared" ]
633
Dirk Prankedd4ff742020-11-18 19:57:32634 if (_use_xvfb) {
635 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06636 } else {
Dirk Prankedd4ff742020-11-18 19:57:32637 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06638 }
Jamie Madilldd60ee62021-04-13 19:25:52639 if (tests_have_location_tags) {
640 data += [ "//testing/location_tags.json" ]
641 }
Dirk Pranke31e346e2020-07-15 00:54:06642
Dirk Prankedd4ff742020-11-18 19:57:32643 executable_args = [
644 "@WrappedPath(./${_executable})",
645 "--test-launcher-bot-mode",
646 ]
647 if (is_asan) {
648 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06649 }
Dirk Prankedd4ff742020-11-18 19:57:32650 if (is_msan) {
651 executable_args += [ "--msan=true" ]
652 }
653 if (is_tsan) {
654 executable_args += [ "--tsan=true" ]
655 }
656 if (use_cfi_diag) {
657 executable_args += [ "--cfi-diag=true" ]
658 }
659
660 data += [ "//.vpython" ]
Greg Guterman6963dc02021-04-07 05:20:59661
662 if (use_rts) {
663 data_deps += [ ":${invoker.target_name}__rts_filters" ]
664 }
Dirk Pranke31e346e2020-07-15 00:54:06665 }
666
667 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01668 forward_variables_from(invoker,
669 "*",
670 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
671 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06672 if (!defined(deps)) {
673 deps = []
674 }
675
Dirk Pranke31e346e2020-07-15 00:54:06676 deps += [
677 # Give tests the default manifest on Windows (a no-op elsewhere).
678 "//build/win:default_exe_manifest",
679 ]
680
Dirk Prankedd4ff742020-11-18 19:57:32681 write_runtime_deps = _runtime_deps_file
682 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11683
684 if (use_rts) {
685 if (!defined(data_deps)) {
686 data_deps = []
687 }
688 data_deps += [ ":${invoker.target_name}__rts_filters" ]
689 }
Dirk Prankedd4ff742020-11-18 19:57:32690 }
691 } else {
692 # This is a catch-all clause for NaCl toolchains and other random
693 # configurations that might define tests; test() in these configs
694 # will just define the underlying executables.
695 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
696 "use_xvfb should not be defined for a non-linux configuration")
697 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01698 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
699 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32700 if (!defined(deps)) {
701 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06702 }
Greg Guterman6963dc02021-04-07 05:20:59703
704 if (use_rts) {
705 if (!defined(data_deps)) {
706 data_deps = []
707 }
708 data_deps += [ ":${invoker.target_name}__rts_filters" ]
709 }
Dirk Pranke31e346e2020-07-15 00:54:06710 }
qsrfb5251d12015-01-21 15:57:22711 }
712}
brettwedb6ecc2016-07-14 23:37:03713
Dirk Pranke6188075b2020-10-01 19:31:28714# Defines a type of test that invokes a script to run, rather than
715# invoking an executable.
716#
717# The script must implement the
718# [test executable API](//docs/testing/test_executable_api.md).
719#
720# The template must be passed the `script` parameter, which specifies
721# the path to the script to run. It may optionally be passed a
722# `script_args` parameter, which can be used to include a list of
723# args to be specified by default. The template will produce
724# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
725# for the target to $root_build_dir/${target_name}.runtime_deps, as per
726# the conventions listed in the
727# [test wrapper API](//docs/testing/test_wrapper_api.md).
728template("script_test") {
Greg Guterman6963dc02021-04-07 05:20:59729 if (use_rts) {
730 action("${target_name}__rts_filters") {
731 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53732 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc02021-04-07 05:20:59733 args = [ rebase_path(rts_file, root_build_dir) ]
734 outputs = [ rts_file ]
735 }
736 }
737
Dirk Pranke6188075b2020-10-01 19:31:28738 generate_wrapper(target_name) {
739 testonly = true
740 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
741
742 executable = "//testing/test_env.py"
743
744 executable_args =
745 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
746 if (defined(invoker.args)) {
747 executable_args += invoker.args
748 }
749
Will Harrisd35e2c92021-04-07 01:42:02750 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:47751
752 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
753 use_vpython3 = false
754 data += [ "//.vpython" ]
755 } else {
756 use_vpython3 = true
757 data += [ "//.vpython3" ]
758 }
759
Dirk Pranke6188075b2020-10-01 19:31:28760 if (defined(invoker.data)) {
761 data += invoker.data
762 }
Jamie Madilldd60ee62021-04-13 19:25:52763 if (tests_have_location_tags) {
764 data += [ "//testing/location_tags.json" ]
765 }
Dirk Pranke19a58732021-03-24 22:26:22766
Will Harrisd35e2c92021-04-07 01:42:02767 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:28768 if (defined(invoker.data_deps)) {
769 data_deps += invoker.data_deps
770 }
771
772 forward_variables_from(invoker,
773 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01774 TESTONLY_AND_VISIBILITY + [
775 "data",
776 "data_deps",
777 "script",
778 "script_args",
779 ])
780 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28781
782 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc02021-04-07 05:20:59783
784 if (use_rts) {
785 data_deps += [ ":${invoker.target_name}__rts_filters" ]
786 }
Dirk Pranke6188075b2020-10-01 19:31:28787 }
788}
789
brettwedb6ecc2016-07-14 23:37:03790# Test defaults.
791set_defaults("test") {
792 if (is_android) {
793 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41794 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59795 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03796 } else {
797 configs = default_executable_configs
798 }
799}