blob: 2950167aa102c84801c899ba059ffc749741133f [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 Guterman6963dc082021-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
16}
17
jcivellif4462a352017-01-10 04:45:5918if (is_android) {
19 import("//build/config/android/config.gni")
James Cook209256f2018-12-07 18:40:5020 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5921 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4422 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3223} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0624 import("//build/config/chromecast_build.gni")
Chong Gu26908f4e2021-01-29 03:13:0725 import("//build/config/coverage/coverage.gni")
Kevin Marshall55fd8522019-10-04 22:47:0126 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4227 import("//build/config/fuchsia/package.gni")
Chong Gu26908f4e2021-01-29 03:13:0728 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Yuta Hijikatac2975452020-12-16 15:59:3929} else if (is_chromeos_ash) {
Ben Pastene4c35c572018-04-30 23:21:4830 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3231 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2832 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3233} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3634 import("//build/config/ios/ios_sdk.gni")
35 import("//build/config/ios/ios_test_runner_wrapper.gni")
36 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3237} else {
Dirk Pranke31e346e2020-07-15 00:54:0638 import("//build/config/sanitizers/sanitizers.gni")
39 import("//build/util/generate_wrapper.gni")
40}
41
qsrfb5251d12015-01-21 15:57:2242# Define a test as an executable (or apk on Android) with the "testonly" flag
43# set.
agrieve62ab00282016-04-05 02:03:4544# Variable:
Dirk Pranke79d065d2020-08-29 03:28:3045# use_xvfb: (optional) whether to run the executable under Xvfb.
agrieve62ab00282016-04-05 02:03:4546# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:5647# use_native_activity: Test implements ANativeActivity_onCreate().
Mirko Bonadei15522bc2020-09-16 20:38:3948# is_xctest: (iOS, optional) whether to build the executable as XCTest.
49# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
50# for build targets.
Haoming Chena9e205c2021-03-25 02:27:1151# override_board: (ash, optional) override the 'cros_board' used in
52# generating the test runner script.
qsrfb5251d12015-01-21 15:57:2253template("test") {
Greg Guterman6963dc082021-04-07 05:20:5954 # Ensures the rts file exists and if not, creates a dummy file
55 if (use_rts) {
56 action("${target_name}__rts_filters") {
57 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:5358 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:5959 args = [ rebase_path(rts_file, root_build_dir) ]
60 outputs = [ rts_file ]
61 }
62 }
63
Andrew Grieve1b290e4a22020-11-24 20:07:0164 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:3965 if (!is_ios) {
66 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
67 "is_xctest can be set only for iOS builds")
68 }
Haoming Chena9e205c2021-03-25 02:27:1169 if (!is_chromeos_ash || cros_board == "") {
70 assert(
71 !defined(invoker.override_board),
72 "override_board can be set only for ChromeOS builds with target board")
73 }
qsrfb5251d12015-01-21 15:57:2274 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3075 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
76
agrieve62ab00282016-04-05 02:03:4577 _use_raw_android_executable = defined(invoker.use_raw_android_executable) &&
78 invoker.use_raw_android_executable
qsrfb5251d12015-01-21 15:57:2279
agrieve67855de2016-03-30 14:46:0180 # output_name is used to allow targets with the same name but in different
81 # packages to still produce unique runner scripts.
82 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2683 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0184 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2685 }
agrieve62ab00282016-04-05 02:03:4586
agrieveb355ad152016-04-19 03:45:2387 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4288 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:5189 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4290 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:5191 ]
agrieve3ac557f02016-04-12 15:52:0092
jbudorickced2a252016-06-09 16:38:5493 assert(_use_raw_android_executable || enable_java_templates)
94
agrieve62ab00282016-04-05 02:03:4595 if (_use_raw_android_executable) {
96 _exec_target = "${target_name}__exec"
97 _dist_target = "${target_name}__dist"
98 _exec_output =
99 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
100
101 executable(_exec_target) {
102 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
103 configs = []
Dirk Pranke19a58732021-03-24 22:26:22104 forward_variables_from(
105 invoker,
106 "*",
107 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
108 "data_deps",
109 "extra_dist_files",
110 ])
agrieve62ab00282016-04-05 02:03:45111
112 # Thanks to the set_defaults() for test(), configs are initialized with
113 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59114 configs -= [
115 "//build/config:shared_library_config",
116 "//build/config/android:hide_all_but_jni",
117 ]
agrieve62ab00282016-04-05 02:03:45118 configs += [ "//build/config:executable_config" ]
119
Dirk Pranke19a58732021-03-24 22:26:22120 if (defined(invoker.data_deps)) {
121 data_deps = invoker.data_deps
122 } else {
123 data_deps = []
124 }
125 if (!defined(data)) {
126 data = []
127 }
128 data += [ "//testing/location_tags.json" ]
129
agrieve62ab00282016-04-05 02:03:45130 # Don't output to the root or else conflict with the group() below.
131 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11132
133 if (use_rts) {
134 data_deps += [ ":${invoker.target_name}__rts_filters" ]
135 }
agrieve62ab00282016-04-05 02:03:45136 }
137
138 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45139 dist_dir = "$root_out_dir/$target_name"
140 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22141 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45142 if (defined(invoker.extra_dist_files)) {
143 extra_files = invoker.extra_dist_files
144 }
Greg Guterman50ed4b42021-04-08 01:15:11145
146 if (use_rts) {
147 if (!defined(data_deps)) {
148 data_deps = []
149 }
150 data_deps += [ ":${invoker.target_name}__rts_filters" ]
151 }
agrieve62ab00282016-04-05 02:03:45152 }
153 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02154 _library_target = "${target_name}__library"
155 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45156 _apk_specific_vars = [
157 "android_manifest",
agrievec6811b422016-06-23 02:25:09158 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27159 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55160 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45161 "enable_multidex",
Benoît Lizéd8b8f742019-11-07 12:50:07162 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02163 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07164 "proguard_configs",
165 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45166 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02167 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45168 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56169 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45170 ]
Siddhartha764226b2018-03-13 02:32:55171
172 # Adds the unwind tables from unstripped binary as an asset file in the
173 # apk, if |add_unwind_tables_in_apk| is specified by the test.
174 if (defined(invoker.add_unwind_tables_in_apk) &&
175 invoker.add_unwind_tables_in_apk) {
176 _unwind_table_asset_name = "${target_name}_unwind_assets"
177 unwind_table_asset(_unwind_table_asset_name) {
Siddhartha764226b2018-03-13 02:32:55178 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22179 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55180 }
181 }
182
agrieve62ab00282016-04-05 02:03:45183 shared_library(_library_target) {
184 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
185 configs = [] # Prevent list overwriting warning.
186 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45187
jbudorickd29ecfa72016-11-18 22:45:42188 forward_variables_from(
189 invoker,
190 "*",
Peter Wen2052bd12020-12-03 20:15:07191 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
192 TESTONLY_AND_VISIBILITY)
193
194 # Native targets do not need to depend on java targets. Filter them out
195 # so that the shared library can be built without needing to wait for
196 # dependent java targets.
197 deps = []
198 if (defined(invoker.deps)) {
199 foreach(_dep, invoker.deps) {
200 _target_label = get_label_info(_dep, "label_no_toolchain")
201 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
202 deps += [ _dep ]
203 }
204 }
205 }
agrieve62ab00282016-04-05 02:03:45206
207 if (!defined(invoker.use_default_launcher) ||
208 invoker.use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37209 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45210 }
211 }
212 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54213 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07214 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45215 apk_name = invoker.target_name
216 if (defined(invoker.output_name)) {
217 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45218 install_script_name = "install_${invoker.output_name}"
219 }
agrieveb355ad152016-04-19 03:45:23220
Daniel Bratellfdda4652019-01-31 15:45:54221 if (defined(invoker.deps)) {
222 deps = invoker.deps
223 } else {
224 deps = []
225 }
226
jcivellif4462a352017-01-10 04:45:59227 # Add the Java classes so that each target does not have to do it.
228 deps += [ "//base/test:test_support_java" ]
229
Siddhartha764226b2018-03-13 02:32:55230 if (defined(_unwind_table_asset_name)) {
231 deps += [ ":${_unwind_table_asset_name}" ]
232 }
Greg Guterman50ed4b42021-04-08 01:15:11233
234 if (use_rts) {
235 data_deps = [ ":${invoker.target_name}__rts_filters" ]
236 }
agrieve62ab00282016-04-05 02:03:45237 }
Andrew Grievee1dc23f2019-10-22 16:26:36238 }
agrieve62ab00282016-04-05 02:03:45239
Andrew Grievee1dc23f2019-10-22 16:26:36240 test_runner_script(_test_runner_target) {
241 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57242
Andrew Grievee1dc23f2019-10-22 16:26:36243 if (_use_raw_android_executable) {
244 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34245 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36246 } else {
247 apk_target = ":$_apk_target"
248 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47249
250 # Dep needed for the test runner .runtime_deps file to pick up data
251 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22252 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45253 }
Andrew Grievee1dc23f2019-10-22 16:26:36254 test_name = _output_name
255 test_suite = _output_name
256 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59257
258 if (use_rts) {
259 data_deps += [ ":${invoker.target_name}__rts_filters" ]
260 }
mikecase56d80d72015-06-03 00:57:26261 }
262
Andrew Grieve7ca6de32019-10-18 03:57:47263 # Create a wrapper script rather than using a group() in order to ensure
264 # "ninja $target_name" always works. If this was a group(), then GN would
265 # not create a top-level alias for it if a target exists in another
266 # directory with the same $target_name.
267 # Also - bots run this script directly for "components_perftests".
268 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01269 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47270 executable = "$root_build_dir/bin/run_$_output_name"
271 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22272 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40273 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47274 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40275 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47276 # Dep needed for the swarming .isolate file to pick up data
277 # deps from the forward_variables_from(invoker, "*") on the library.
278 deps += [
279 ":$_apk_target",
280 ":$_library_target",
281 ]
agrieve62ab00282016-04-05 02:03:45282 }
Dirk Pranke19a58732021-03-24 22:26:22283
284 if (defined(invoker.data_deps)) {
285 data_deps = invoker.data_deps
286 } else {
287 data_deps = []
288 }
289 data = [ "//testing/location_tags.json" ]
Greg Guterman6963dc082021-04-07 05:20:59290
291 if (use_rts) {
292 data_deps += [ ":${invoker.target_name}__rts_filters" ]
293 }
agrieve1a02e582015-10-15 21:35:39294 }
Scott Graham4c4cdc52017-05-29 20:45:03295 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30296 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
297
Scott Graham4c4cdc52017-05-29 20:45:03298 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42299 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42300 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03301
Chong Gu50c83392021-04-06 23:00:27302 manifest_fragments =
303 [ "//build/config/fuchsia/test/minimum_capabilities.test-cmx" ]
Chong Gu26908f4e2021-01-29 03:13:07304
Chong Gu91a1fea2021-03-30 17:24:31305 if (defined(invoker.additional_manifest_fragments)) {
306 manifest_fragments += invoker.additional_manifest_fragments
Chong Guacf19a32021-03-10 01:07:41307 }
Chong Gu26908f4e2021-01-29 03:13:07308 if (use_clang_coverage) {
Chong Gu7ad57c22021-03-11 00:24:38309 manifest_fragments +=
310 [ "//build/config/fuchsia/add_DebugData_service.test-cmx" ]
Chong Gu26908f4e2021-01-29 03:13:07311 }
Chong Gu7ad57c22021-03-11 00:24:38312 combined_manifest = "${target_name}.test-cmx"
313 cmc_merge(combined_manifest) {
314 sources = manifest_fragments
315 output_name = target_name
316 }
317 manifest = "${target_out_dir}/${combined_manifest}"
Chong Gu26908f4e2021-01-29 03:13:07318
Kevin Marshall39b4aa82018-06-23 00:12:15319 fuchsia_package_runner(target_name) {
Dirk Pranked5e9a1b22020-10-28 22:52:59320 is_test_exe = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53321 forward_variables_from(invoker,
322 [
323 "use_test_server",
324 "package_deps",
Andrew Grieve1b290e4a22020-11-24 20:07:01325 "visibility",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53326 ])
Kevin Marshall39b4aa82018-06-23 00:12:15327 runner_script = "//build/fuchsia/test_runner.py"
328 package = ":$_pkg_target"
329 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42330
Dirk Pranke19a58732021-03-24 22:26:22331 data = [ "//testing/location_tags.json" ]
Wezdd593a52020-04-08 17:09:46332 data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59333
334 if (use_rts) {
335 data_deps += [ ":${invoker.target_name}__rts_filters" ]
336 }
Kevin Marshallf35fa5f2018-01-29 19:24:42337 }
338
Wezabe2d752020-02-11 17:12:23339 cr_fuchsia_package(_pkg_target) {
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20340 binary = ":$_exec_target"
341 package_name_override = _output_name
Chong Gu7ad57c22021-03-11 00:24:38342 deps = [ ":$combined_manifest" ]
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20343 }
344
Kevin Marshallf35fa5f2018-01-29 19:24:42345 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01346 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42347 output_name = _exec_target
Greg Guterman50ed4b42021-04-08 01:15:11348
349 if (use_rts) {
350 if (!defined(data_deps)) {
351 data_deps = []
352 }
353 data_deps += [ ":${invoker.target_name}__rts_filters" ]
354 }
Scott Graham4c4cdc52017-05-29 20:45:03355 }
dpranke2a294622015-08-07 05:23:01356 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30357 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46358 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30359
Rohit Raof9b096d2019-09-09 22:26:23360 declare_args() {
361 # Keep the unittest-as-xctest functionality defaulted to off until the
362 # bots are updated to handle it properly.
363 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
364 # supports running unittests with xctest.
365 enable_run_ios_unittests_with_xctest = false
366 }
367
sdefresne012857872016-03-16 10:55:37368 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36369 _wrapper_output_name = "run_${target_name}"
370 ios_test_runner_wrapper(_wrapper_output_name) {
371 forward_variables_from(invoker,
372 [
373 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36374 "deps",
375 "executable_args",
376 "retries",
377 "shards",
378 ])
379
380 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
381
382 if (!defined(executable_args)) {
383 executable_args = []
384 }
385 executable_args += [
386 "--app",
387 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
388 ]
389
390 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22391
392 if (!defined(data)) {
393 data = []
394 }
395 data += [ "//testing/location_tags.json" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36396 }
397
sdefresne012857872016-03-16 10:55:37398 _resources_bundle_data = target_name + "_resources_bundle_data"
399
400 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34401 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22402 sources = [ "//testing/gtest_ios/Default.png" ]
403 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01404 }
405
Mirko Bonadei15522bc2020-09-16 20:38:39406 force_xctest = enable_run_ios_unittests_with_xctest ||
407 (defined(invoker.is_xctest) && invoker.is_xctest)
408
409 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23410 ios_test_target_type = "ios_xctest_test"
411 } else {
412 ios_test_target_type = "ios_app_bundle"
413 }
414
415 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01416 testonly = true
sdefresnea828c282016-05-30 18:04:20417
Mirko Bonadei15522bc2020-09-16 20:38:39418 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23419 xctest_module_target = "//base/test:google_test_runner"
420 }
421
Andrew Grieve1b290e4a22020-11-24 20:07:01422 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13423
424 # Provide sensible defaults in case invoker did not define any of those
425 # required variables.
sdefresne05b97ca2016-06-08 07:19:46426 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13427 info_plist = "//testing/gtest_ios/unittest-Info.plist"
428 }
sdefresne9e147e02016-06-07 00:10:13429
Olivier Robin9689c562020-04-17 14:03:57430 _gtest_bundle_id_suffix = "${target_name}"
431 xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19432
sdefresne9e147e02016-06-07 00:10:13433 if (!defined(extra_substitutions)) {
434 extra_substitutions = []
435 }
Olivier Robin9689c562020-04-17 14:03:57436 extra_substitutions +=
437 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01438
sdefresne047490e2016-07-22 08:49:34439 if (!defined(bundle_deps)) {
440 bundle_deps = []
441 }
442 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36443
444 if (!defined(data_deps)) {
445 data_deps = []
446 }
447
448 # Include the generate_wrapper as part of data_deps
449 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46450 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59451
452 if (use_rts) {
453 data_deps += [ ":${invoker.target_name}__rts_filters" ]
454 }
dpranke2a294622015-08-07 05:23:01455 }
Yuta Hijikatac2975452020-12-16 15:59:39456 } else if (is_chromeos_ash && cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30457 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
458
Ben Pastene16882032018-09-21 01:16:39459 # Building for a cros board (ie: not linux-chromeos).
Benjamin Pastene3bce864e2018-04-14 01:16:32460
Benjamin Pastene3bce864e2018-04-14 01:16:32461 _gen_runner_target = "${target_name}__runner"
462 _runtime_deps_file =
463 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
464 "/" + get_label_info(target_name, "name") + ".runtime_deps"
465
Ben Pastene4ab98652018-12-17 18:33:18466 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32467 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39468 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32469 runtime_deps_file = _runtime_deps_file
Haoming Chena9e205c2021-03-25 02:27:11470
471 if (defined(invoker.override_board)) {
472 override_board = invoker.override_board
473 }
474
Dirk Pranke19a58732021-03-24 22:26:22475 data = [ "//testing/location_tags.json" ]
Greg Guterman6963dc082021-04-07 05:20:59476
477 if (use_rts) {
478 data_deps = [ ":${invoker.target_name}__rts_filters" ]
479 }
Benjamin Pastene3bce864e2018-04-14 01:16:32480 }
481
482 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01483 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
484 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32485 if (!defined(deps)) {
486 deps = []
487 }
488 if (!defined(data)) {
489 data = []
490 }
491
Ben Pastene41041782019-02-16 04:21:58492 # We use a special trigger script for CrOS hardware tests.
493 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
494
Benjamin Pastene3bce864e2018-04-14 01:16:32495 output_name = target_name
496 write_runtime_deps = _runtime_deps_file
497 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37498 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59499
500 if (use_rts) {
501 if (!defined(data_deps)) {
502 data_deps = []
503 }
504 data_deps += [ ":${invoker.target_name}__rts_filters" ]
505 }
Benjamin Pastene3bce864e2018-04-14 01:16:32506 }
Yuke Liaoe703384b2020-07-16 01:05:24507 } else if (chromeos_is_browser_only) {
508 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
509 _executable = target_name
510 _gen_runner_target = "${target_name}__runner"
511
Yuke Liao32af4242020-07-16 21:48:02512 if (defined(invoker.use_xvfb)) {
513 _use_xvfb = invoker.use_xvfb
514 } else {
515 _use_xvfb = false
516 }
517
Yuke Liaod037abc2020-10-06 22:48:22518 # When use_xvfb is set by the invoker, it indicates that running this test
519 # target requires a window, and in lacros build, ash-chrome serves as the
520 # display server. Note that even though the tests themselves do not require
521 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
522 # because ash-chrome is based on x11.
523 _use_ash_chrome = _use_xvfb
524
Yuke Liaoe703384b2020-07-16 01:05:24525 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24526 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02527
Yuke Liao2e4953cf2020-07-26 19:20:19528 data = []
Will Harrisd35e2c92021-04-07 01:42:02529 data_deps = [ "//testing:test_scripts_shared" ]
530
Yuke Liao32af4242020-07-16 21:48:02531 if (_use_xvfb) {
532 executable = "//testing/xvfb.py"
533 } else {
534 executable = "//testing/test_env.py"
535 }
Dirk Pranke19a58732021-03-24 22:26:22536 data += [ "//testing/location_tags.json" ]
Yuke Liao32af4242020-07-16 21:48:02537
Yuke Liaoe703384b2020-07-16 01:05:24538 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02539 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39540 "test",
Yuke Liaoe703384b2020-07-16 01:05:24541 "@WrappedPath(./${_executable})",
542 "--test-launcher-bot-mode",
543 ]
Yuke Liao32af4242020-07-16 21:48:02544
Yuke Liaof540c742020-07-29 16:28:34545 if (_use_ash_chrome) {
Yuke Liao8348aa42020-11-04 19:35:23546 executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ]
Yuke Liao240816d2020-07-22 00:10:39547 }
548
Yuke Liaoe703384b2020-07-16 01:05:24549 if (is_asan) {
550 executable_args += [ "--asan=true" ]
551 }
552 if (is_msan) {
553 executable_args += [ "--msan=true" ]
554 }
555 if (is_tsan) {
556 executable_args += [ "--tsan=true" ]
557 }
558 if (use_cfi_diag) {
559 executable_args += [ "--cfi-diag=true" ]
560 }
561
Yuke Liao2e4953cf2020-07-26 19:20:19562 data += [
Yuke Liao240816d2020-07-22 00:10:39563 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24564 "//.vpython",
565 ]
Greg Guterman6963dc082021-04-07 05:20:59566
567 if (use_rts) {
568 data_deps += [ ":${invoker.target_name}__rts_filters" ]
569 }
Yuke Liaoe703384b2020-07-16 01:05:24570 }
571
572 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01573 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
574 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24575 if (!defined(deps)) {
576 deps = []
577 }
578
Yuke Liaod037abc2020-10-06 22:48:22579 if (!defined(data_deps)) {
580 data_deps = []
581 }
582
Yuke Liaoe703384b2020-07-16 01:05:24583 write_runtime_deps = _runtime_deps_file
584 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22585 if (_use_ash_chrome && also_build_ash_chrome) {
586 data_deps +=
587 [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ]
588 }
Greg Guterman6963dc082021-04-07 05:20:59589
590 if (use_rts) {
591 data_deps += [ ":${invoker.target_name}__rts_filters" ]
592 }
Yuke Liaoe703384b2020-07-16 01:05:24593 }
Dirk Prankedd4ff742020-11-18 19:57:32594 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30595 if (is_mac || is_win) {
596 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
597 }
598
Dirk Prankedd4ff742020-11-18 19:57:32599 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
600 _executable = target_name
601 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06602
Dirk Prankedd4ff742020-11-18 19:57:32603 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
604 _use_xvfb = invoker.use_xvfb
605 } else {
606 _use_xvfb = false
607 }
608
609 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32610 wrapper_script = "$root_build_dir/bin/run_" + _executable
611
612 data = []
Will Harrisd35e2c92021-04-07 01:42:02613 data_deps = [ "//testing:test_scripts_shared" ]
614
Dirk Prankedd4ff742020-11-18 19:57:32615 if (_use_xvfb) {
616 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06617 } else {
Dirk Prankedd4ff742020-11-18 19:57:32618 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06619 }
Dirk Pranke19a58732021-03-24 22:26:22620 data += [ "//testing/location_tags.json" ]
Dirk Pranke31e346e2020-07-15 00:54:06621
Dirk Prankedd4ff742020-11-18 19:57:32622 executable_args = [
623 "@WrappedPath(./${_executable})",
624 "--test-launcher-bot-mode",
625 ]
626 if (is_asan) {
627 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06628 }
Dirk Prankedd4ff742020-11-18 19:57:32629 if (is_msan) {
630 executable_args += [ "--msan=true" ]
631 }
632 if (is_tsan) {
633 executable_args += [ "--tsan=true" ]
634 }
635 if (use_cfi_diag) {
636 executable_args += [ "--cfi-diag=true" ]
637 }
638
639 data += [ "//.vpython" ]
Greg Guterman6963dc082021-04-07 05:20:59640
641 if (use_rts) {
642 data_deps += [ ":${invoker.target_name}__rts_filters" ]
643 }
Dirk Pranke31e346e2020-07-15 00:54:06644 }
645
646 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01647 forward_variables_from(invoker,
648 "*",
649 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
650 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06651 if (!defined(deps)) {
652 deps = []
653 }
654
Dirk Pranke31e346e2020-07-15 00:54:06655 deps += [
656 # Give tests the default manifest on Windows (a no-op elsewhere).
657 "//build/win:default_exe_manifest",
658 ]
659
Dirk Prankedd4ff742020-11-18 19:57:32660 write_runtime_deps = _runtime_deps_file
661 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11662
663 if (use_rts) {
664 if (!defined(data_deps)) {
665 data_deps = []
666 }
667 data_deps += [ ":${invoker.target_name}__rts_filters" ]
668 }
Dirk Prankedd4ff742020-11-18 19:57:32669 }
670 } else {
671 # This is a catch-all clause for NaCl toolchains and other random
672 # configurations that might define tests; test() in these configs
673 # will just define the underlying executables.
674 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
675 "use_xvfb should not be defined for a non-linux configuration")
676 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01677 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
678 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32679 if (!defined(deps)) {
680 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06681 }
Greg Guterman6963dc082021-04-07 05:20:59682
683 if (use_rts) {
684 if (!defined(data_deps)) {
685 data_deps = []
686 }
687 data_deps += [ ":${invoker.target_name}__rts_filters" ]
688 }
Dirk Pranke31e346e2020-07-15 00:54:06689 }
qsrfb5251d12015-01-21 15:57:22690 }
691}
brettwedb6ecc2016-07-14 23:37:03692
Dirk Pranke6188075b2020-10-01 19:31:28693# Defines a type of test that invokes a script to run, rather than
694# invoking an executable.
695#
696# The script must implement the
697# [test executable API](//docs/testing/test_executable_api.md).
698#
699# The template must be passed the `script` parameter, which specifies
700# the path to the script to run. It may optionally be passed a
701# `script_args` parameter, which can be used to include a list of
702# args to be specified by default. The template will produce
703# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
704# for the target to $root_build_dir/${target_name}.runtime_deps, as per
705# the conventions listed in the
706# [test wrapper API](//docs/testing/test_wrapper_api.md).
707template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:59708 if (use_rts) {
709 action("${target_name}__rts_filters") {
710 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53711 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:59712 args = [ rebase_path(rts_file, root_build_dir) ]
713 outputs = [ rts_file ]
714 }
715 }
716
Dirk Pranke6188075b2020-10-01 19:31:28717 generate_wrapper(target_name) {
718 testonly = true
719 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
720
721 executable = "//testing/test_env.py"
722
723 executable_args =
724 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
725 if (defined(invoker.args)) {
726 executable_args += invoker.args
727 }
728
Will Harrisd35e2c92021-04-07 01:42:02729 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:47730
731 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
732 use_vpython3 = false
733 data += [ "//.vpython" ]
734 } else {
735 use_vpython3 = true
736 data += [ "//.vpython3" ]
737 }
738
Dirk Pranke6188075b2020-10-01 19:31:28739 if (defined(invoker.data)) {
740 data += invoker.data
741 }
Dirk Pranke19a58732021-03-24 22:26:22742 data += [ "//testing/location_tags.json" ]
743
Will Harrisd35e2c92021-04-07 01:42:02744 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:28745 if (defined(invoker.data_deps)) {
746 data_deps += invoker.data_deps
747 }
748
749 forward_variables_from(invoker,
750 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01751 TESTONLY_AND_VISIBILITY + [
752 "data",
753 "data_deps",
754 "script",
755 "script_args",
756 ])
757 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28758
759 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:59760
761 if (use_rts) {
762 data_deps += [ ":${invoker.target_name}__rts_filters" ]
763 }
Dirk Pranke6188075b2020-10-01 19:31:28764 }
765}
766
brettwedb6ecc2016-07-14 23:37:03767# Test defaults.
768set_defaults("test") {
769 if (is_android) {
770 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41771 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59772 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03773 } else {
774 configs = default_executable_configs
775 }
776}