blob: a4eed345958f464fab99710a5060cccfd77dc951 [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
Peter Kotwiczb9957d62021-04-12 21:09:43172 _use_default_launcher =
173 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
174
Siddhartha764226b2018-03-13 02:32:55175 # Adds the unwind tables from unstripped binary as an asset file in the
176 # apk, if |add_unwind_tables_in_apk| is specified by the test.
177 if (defined(invoker.add_unwind_tables_in_apk) &&
178 invoker.add_unwind_tables_in_apk) {
179 _unwind_table_asset_name = "${target_name}_unwind_assets"
180 unwind_table_asset(_unwind_table_asset_name) {
Siddhartha764226b2018-03-13 02:32:55181 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22182 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55183 }
184 }
185
agrieve62ab00282016-04-05 02:03:45186 shared_library(_library_target) {
187 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
188 configs = [] # Prevent list overwriting warning.
189 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45190
jbudorickd29ecfa72016-11-18 22:45:42191 forward_variables_from(
192 invoker,
193 "*",
Peter Wen2052bd12020-12-03 20:15:07194 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
195 TESTONLY_AND_VISIBILITY)
196
197 # Native targets do not need to depend on java targets. Filter them out
198 # so that the shared library can be built without needing to wait for
199 # dependent java targets.
200 deps = []
201 if (defined(invoker.deps)) {
202 foreach(_dep, invoker.deps) {
203 _target_label = get_label_info(_dep, "label_no_toolchain")
204 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
205 deps += [ _dep ]
206 }
207 }
208 }
agrieve62ab00282016-04-05 02:03:45209
Peter Kotwiczb9957d62021-04-12 21:09:43210 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37211 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45212 }
213 }
214 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54215 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07216 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45217 apk_name = invoker.target_name
218 if (defined(invoker.output_name)) {
219 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45220 install_script_name = "install_${invoker.output_name}"
221 }
agrieveb355ad152016-04-19 03:45:23222
Daniel Bratellfdda4652019-01-31 15:45:54223 if (defined(invoker.deps)) {
224 deps = invoker.deps
225 } else {
226 deps = []
227 }
228
jcivellif4462a352017-01-10 04:45:59229 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43230 if (_use_default_launcher) {
231 deps += [ "//base/test:test_support_java" ]
232 }
jcivellif4462a352017-01-10 04:45:59233
Siddhartha764226b2018-03-13 02:32:55234 if (defined(_unwind_table_asset_name)) {
235 deps += [ ":${_unwind_table_asset_name}" ]
236 }
Greg Guterman50ed4b42021-04-08 01:15:11237
238 if (use_rts) {
239 data_deps = [ ":${invoker.target_name}__rts_filters" ]
240 }
agrieve62ab00282016-04-05 02:03:45241 }
Andrew Grievee1dc23f2019-10-22 16:26:36242 }
agrieve62ab00282016-04-05 02:03:45243
Andrew Grievee1dc23f2019-10-22 16:26:36244 test_runner_script(_test_runner_target) {
245 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57246
Andrew Grievee1dc23f2019-10-22 16:26:36247 if (_use_raw_android_executable) {
248 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34249 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36250 } else {
251 apk_target = ":$_apk_target"
252 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47253
254 # Dep needed for the test runner .runtime_deps file to pick up data
255 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22256 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45257 }
Andrew Grievee1dc23f2019-10-22 16:26:36258 test_name = _output_name
259 test_suite = _output_name
260 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59261
262 if (use_rts) {
263 data_deps += [ ":${invoker.target_name}__rts_filters" ]
264 }
mikecase56d80d72015-06-03 00:57:26265 }
266
Andrew Grieve7ca6de32019-10-18 03:57:47267 # Create a wrapper script rather than using a group() in order to ensure
268 # "ninja $target_name" always works. If this was a group(), then GN would
269 # not create a top-level alias for it if a target exists in another
270 # directory with the same $target_name.
271 # Also - bots run this script directly for "components_perftests".
272 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01273 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47274 executable = "$root_build_dir/bin/run_$_output_name"
275 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22276 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40277 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47278 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40279 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47280 # Dep needed for the swarming .isolate file to pick up data
281 # deps from the forward_variables_from(invoker, "*") on the library.
282 deps += [
283 ":$_apk_target",
284 ":$_library_target",
285 ]
agrieve62ab00282016-04-05 02:03:45286 }
Dirk Pranke19a58732021-03-24 22:26:22287
288 if (defined(invoker.data_deps)) {
289 data_deps = invoker.data_deps
290 } else {
291 data_deps = []
292 }
293 data = [ "//testing/location_tags.json" ]
Greg Guterman6963dc082021-04-07 05:20:59294
295 if (use_rts) {
296 data_deps += [ ":${invoker.target_name}__rts_filters" ]
297 }
agrieve1a02e582015-10-15 21:35:39298 }
Scott Graham4c4cdc52017-05-29 20:45:03299 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30300 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
301
Scott Graham4c4cdc52017-05-29 20:45:03302 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42303 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42304 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03305
Chong Gu50c83392021-04-06 23:00:27306 manifest_fragments =
307 [ "//build/config/fuchsia/test/minimum_capabilities.test-cmx" ]
Chong Gu26908f4e2021-01-29 03:13:07308
Chong Gu91a1fea2021-03-30 17:24:31309 if (defined(invoker.additional_manifest_fragments)) {
310 manifest_fragments += invoker.additional_manifest_fragments
Chong Guacf19a32021-03-10 01:07:41311 }
Chong Gu26908f4e2021-01-29 03:13:07312 if (use_clang_coverage) {
Chong Gu7ad57c22021-03-11 00:24:38313 manifest_fragments +=
314 [ "//build/config/fuchsia/add_DebugData_service.test-cmx" ]
Chong Gu26908f4e2021-01-29 03:13:07315 }
Chong Gu7ad57c22021-03-11 00:24:38316 combined_manifest = "${target_name}.test-cmx"
317 cmc_merge(combined_manifest) {
318 sources = manifest_fragments
319 output_name = target_name
320 }
321 manifest = "${target_out_dir}/${combined_manifest}"
Chong Gu26908f4e2021-01-29 03:13:07322
Kevin Marshall39b4aa82018-06-23 00:12:15323 fuchsia_package_runner(target_name) {
Dirk Pranked5e9a1b22020-10-28 22:52:59324 is_test_exe = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53325 forward_variables_from(invoker,
326 [
327 "use_test_server",
328 "package_deps",
Andrew Grieve1b290e4a22020-11-24 20:07:01329 "visibility",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53330 ])
Kevin Marshall39b4aa82018-06-23 00:12:15331 runner_script = "//build/fuchsia/test_runner.py"
332 package = ":$_pkg_target"
333 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42334
Dirk Pranke19a58732021-03-24 22:26:22335 data = [ "//testing/location_tags.json" ]
Wezdd593a52020-04-08 17:09:46336 data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59337
338 if (use_rts) {
339 data_deps += [ ":${invoker.target_name}__rts_filters" ]
340 }
Kevin Marshallf35fa5f2018-01-29 19:24:42341 }
342
Wezabe2d752020-02-11 17:12:23343 cr_fuchsia_package(_pkg_target) {
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20344 binary = ":$_exec_target"
345 package_name_override = _output_name
Chong Gu7ad57c22021-03-11 00:24:38346 deps = [ ":$combined_manifest" ]
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20347 }
348
Kevin Marshallf35fa5f2018-01-29 19:24:42349 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01350 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42351 output_name = _exec_target
Greg Guterman50ed4b42021-04-08 01:15:11352
353 if (use_rts) {
354 if (!defined(data_deps)) {
355 data_deps = []
356 }
357 data_deps += [ ":${invoker.target_name}__rts_filters" ]
358 }
Scott Graham4c4cdc52017-05-29 20:45:03359 }
dpranke2a294622015-08-07 05:23:01360 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30361 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46362 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30363
Rohit Raof9b096d2019-09-09 22:26:23364 declare_args() {
365 # Keep the unittest-as-xctest functionality defaulted to off until the
366 # bots are updated to handle it properly.
367 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
368 # supports running unittests with xctest.
369 enable_run_ios_unittests_with_xctest = false
370 }
371
sdefresne012857872016-03-16 10:55:37372 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36373 _wrapper_output_name = "run_${target_name}"
374 ios_test_runner_wrapper(_wrapper_output_name) {
375 forward_variables_from(invoker,
376 [
377 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36378 "deps",
379 "executable_args",
380 "retries",
381 "shards",
382 ])
383
384 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
385
386 if (!defined(executable_args)) {
387 executable_args = []
388 }
389 executable_args += [
390 "--app",
391 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
392 ]
393
394 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22395
396 if (!defined(data)) {
397 data = []
398 }
399 data += [ "//testing/location_tags.json" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36400 }
401
sdefresne012857872016-03-16 10:55:37402 _resources_bundle_data = target_name + "_resources_bundle_data"
403
404 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34405 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22406 sources = [ "//testing/gtest_ios/Default.png" ]
407 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01408 }
409
Mirko Bonadei15522bc2020-09-16 20:38:39410 force_xctest = enable_run_ios_unittests_with_xctest ||
411 (defined(invoker.is_xctest) && invoker.is_xctest)
412
413 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23414 ios_test_target_type = "ios_xctest_test"
415 } else {
416 ios_test_target_type = "ios_app_bundle"
417 }
418
419 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01420 testonly = true
sdefresnea828c282016-05-30 18:04:20421
Mirko Bonadei15522bc2020-09-16 20:38:39422 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23423 xctest_module_target = "//base/test:google_test_runner"
424 }
425
Andrew Grieve1b290e4a22020-11-24 20:07:01426 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13427
428 # Provide sensible defaults in case invoker did not define any of those
429 # required variables.
sdefresne05b97ca2016-06-08 07:19:46430 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13431 info_plist = "//testing/gtest_ios/unittest-Info.plist"
432 }
sdefresne9e147e02016-06-07 00:10:13433
Olivier Robin9689c562020-04-17 14:03:57434 _gtest_bundle_id_suffix = "${target_name}"
435 xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19436
sdefresne9e147e02016-06-07 00:10:13437 if (!defined(extra_substitutions)) {
438 extra_substitutions = []
439 }
Olivier Robin9689c562020-04-17 14:03:57440 extra_substitutions +=
441 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01442
sdefresne047490e2016-07-22 08:49:34443 if (!defined(bundle_deps)) {
444 bundle_deps = []
445 }
446 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36447
448 if (!defined(data_deps)) {
449 data_deps = []
450 }
451
452 # Include the generate_wrapper as part of data_deps
453 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46454 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59455
456 if (use_rts) {
457 data_deps += [ ":${invoker.target_name}__rts_filters" ]
458 }
dpranke2a294622015-08-07 05:23:01459 }
Yuta Hijikatac2975452020-12-16 15:59:39460 } else if (is_chromeos_ash && cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30461 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
462
Ben Pastene16882032018-09-21 01:16:39463 # Building for a cros board (ie: not linux-chromeos).
Benjamin Pastene3bce864e2018-04-14 01:16:32464
Benjamin Pastene3bce864e2018-04-14 01:16:32465 _gen_runner_target = "${target_name}__runner"
466 _runtime_deps_file =
467 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
468 "/" + get_label_info(target_name, "name") + ".runtime_deps"
469
Ben Pastene4ab98652018-12-17 18:33:18470 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32471 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39472 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32473 runtime_deps_file = _runtime_deps_file
Haoming Chena9e205c2021-03-25 02:27:11474
475 if (defined(invoker.override_board)) {
476 override_board = invoker.override_board
477 }
478
Dirk Pranke19a58732021-03-24 22:26:22479 data = [ "//testing/location_tags.json" ]
Greg Guterman6963dc082021-04-07 05:20:59480
481 if (use_rts) {
482 data_deps = [ ":${invoker.target_name}__rts_filters" ]
483 }
Benjamin Pastene3bce864e2018-04-14 01:16:32484 }
485
486 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01487 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
488 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32489 if (!defined(deps)) {
490 deps = []
491 }
492 if (!defined(data)) {
493 data = []
494 }
495
Ben Pastene41041782019-02-16 04:21:58496 # We use a special trigger script for CrOS hardware tests.
497 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
498
Benjamin Pastene3bce864e2018-04-14 01:16:32499 output_name = target_name
500 write_runtime_deps = _runtime_deps_file
501 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37502 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59503
504 if (use_rts) {
505 if (!defined(data_deps)) {
506 data_deps = []
507 }
508 data_deps += [ ":${invoker.target_name}__rts_filters" ]
509 }
Benjamin Pastene3bce864e2018-04-14 01:16:32510 }
Yuke Liaoe703384b2020-07-16 01:05:24511 } else if (chromeos_is_browser_only) {
512 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
513 _executable = target_name
514 _gen_runner_target = "${target_name}__runner"
515
Yuke Liao32af4242020-07-16 21:48:02516 if (defined(invoker.use_xvfb)) {
517 _use_xvfb = invoker.use_xvfb
518 } else {
519 _use_xvfb = false
520 }
521
Yuke Liaod037abc2020-10-06 22:48:22522 # When use_xvfb is set by the invoker, it indicates that running this test
523 # target requires a window, and in lacros build, ash-chrome serves as the
524 # display server. Note that even though the tests themselves do not require
525 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
526 # because ash-chrome is based on x11.
527 _use_ash_chrome = _use_xvfb
528
Yuke Liaoe703384b2020-07-16 01:05:24529 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24530 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02531
Yuke Liao2e4953cf2020-07-26 19:20:19532 data = []
Will Harrisd35e2c92021-04-07 01:42:02533 data_deps = [ "//testing:test_scripts_shared" ]
534
Yuke Liao32af4242020-07-16 21:48:02535 if (_use_xvfb) {
536 executable = "//testing/xvfb.py"
537 } else {
538 executable = "//testing/test_env.py"
539 }
Dirk Pranke19a58732021-03-24 22:26:22540 data += [ "//testing/location_tags.json" ]
Yuke Liao32af4242020-07-16 21:48:02541
Yuke Liaoe703384b2020-07-16 01:05:24542 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02543 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39544 "test",
Yuke Liaoe703384b2020-07-16 01:05:24545 "@WrappedPath(./${_executable})",
546 "--test-launcher-bot-mode",
547 ]
Yuke Liao32af4242020-07-16 21:48:02548
Yuke Liaof540c742020-07-29 16:28:34549 if (_use_ash_chrome) {
Yuke Liao8348aa42020-11-04 19:35:23550 executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ]
Yuke Liao240816d2020-07-22 00:10:39551 }
552
Yuke Liaoe703384b2020-07-16 01:05:24553 if (is_asan) {
554 executable_args += [ "--asan=true" ]
555 }
556 if (is_msan) {
557 executable_args += [ "--msan=true" ]
558 }
559 if (is_tsan) {
560 executable_args += [ "--tsan=true" ]
561 }
562 if (use_cfi_diag) {
563 executable_args += [ "--cfi-diag=true" ]
564 }
565
Yuke Liao2e4953cf2020-07-26 19:20:19566 data += [
Yuke Liao240816d2020-07-22 00:10:39567 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24568 "//.vpython",
569 ]
Greg Guterman6963dc082021-04-07 05:20:59570
571 if (use_rts) {
572 data_deps += [ ":${invoker.target_name}__rts_filters" ]
573 }
Yuke Liaoe703384b2020-07-16 01:05:24574 }
575
576 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01577 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
578 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24579 if (!defined(deps)) {
580 deps = []
581 }
582
Yuke Liaod037abc2020-10-06 22:48:22583 if (!defined(data_deps)) {
584 data_deps = []
585 }
586
Yuke Liaoe703384b2020-07-16 01:05:24587 write_runtime_deps = _runtime_deps_file
588 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22589 if (_use_ash_chrome && also_build_ash_chrome) {
590 data_deps +=
591 [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ]
592 }
Greg Guterman6963dc082021-04-07 05:20:59593
594 if (use_rts) {
595 data_deps += [ ":${invoker.target_name}__rts_filters" ]
596 }
Yuke Liaoe703384b2020-07-16 01:05:24597 }
Dirk Prankedd4ff742020-11-18 19:57:32598 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30599 if (is_mac || is_win) {
600 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
601 }
602
Dirk Prankedd4ff742020-11-18 19:57:32603 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
604 _executable = target_name
605 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06606
Dirk Prankedd4ff742020-11-18 19:57:32607 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
608 _use_xvfb = invoker.use_xvfb
609 } else {
610 _use_xvfb = false
611 }
612
613 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32614 wrapper_script = "$root_build_dir/bin/run_" + _executable
615
616 data = []
Will Harrisd35e2c92021-04-07 01:42:02617 data_deps = [ "//testing:test_scripts_shared" ]
618
Dirk Prankedd4ff742020-11-18 19:57:32619 if (_use_xvfb) {
620 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06621 } else {
Dirk Prankedd4ff742020-11-18 19:57:32622 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06623 }
Dirk Pranke19a58732021-03-24 22:26:22624 data += [ "//testing/location_tags.json" ]
Dirk Pranke31e346e2020-07-15 00:54:06625
Dirk Prankedd4ff742020-11-18 19:57:32626 executable_args = [
627 "@WrappedPath(./${_executable})",
628 "--test-launcher-bot-mode",
629 ]
630 if (is_asan) {
631 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06632 }
Dirk Prankedd4ff742020-11-18 19:57:32633 if (is_msan) {
634 executable_args += [ "--msan=true" ]
635 }
636 if (is_tsan) {
637 executable_args += [ "--tsan=true" ]
638 }
639 if (use_cfi_diag) {
640 executable_args += [ "--cfi-diag=true" ]
641 }
642
643 data += [ "//.vpython" ]
Greg Guterman6963dc082021-04-07 05:20:59644
645 if (use_rts) {
646 data_deps += [ ":${invoker.target_name}__rts_filters" ]
647 }
Dirk Pranke31e346e2020-07-15 00:54:06648 }
649
650 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01651 forward_variables_from(invoker,
652 "*",
653 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
654 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06655 if (!defined(deps)) {
656 deps = []
657 }
658
Dirk Pranke31e346e2020-07-15 00:54:06659 deps += [
660 # Give tests the default manifest on Windows (a no-op elsewhere).
661 "//build/win:default_exe_manifest",
662 ]
663
Dirk Prankedd4ff742020-11-18 19:57:32664 write_runtime_deps = _runtime_deps_file
665 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11666
667 if (use_rts) {
668 if (!defined(data_deps)) {
669 data_deps = []
670 }
671 data_deps += [ ":${invoker.target_name}__rts_filters" ]
672 }
Dirk Prankedd4ff742020-11-18 19:57:32673 }
674 } else {
675 # This is a catch-all clause for NaCl toolchains and other random
676 # configurations that might define tests; test() in these configs
677 # will just define the underlying executables.
678 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
679 "use_xvfb should not be defined for a non-linux configuration")
680 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01681 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
682 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32683 if (!defined(deps)) {
684 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06685 }
Greg Guterman6963dc082021-04-07 05:20:59686
687 if (use_rts) {
688 if (!defined(data_deps)) {
689 data_deps = []
690 }
691 data_deps += [ ":${invoker.target_name}__rts_filters" ]
692 }
Dirk Pranke31e346e2020-07-15 00:54:06693 }
qsrfb5251d12015-01-21 15:57:22694 }
695}
brettwedb6ecc2016-07-14 23:37:03696
Dirk Pranke6188075b2020-10-01 19:31:28697# Defines a type of test that invokes a script to run, rather than
698# invoking an executable.
699#
700# The script must implement the
701# [test executable API](//docs/testing/test_executable_api.md).
702#
703# The template must be passed the `script` parameter, which specifies
704# the path to the script to run. It may optionally be passed a
705# `script_args` parameter, which can be used to include a list of
706# args to be specified by default. The template will produce
707# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
708# for the target to $root_build_dir/${target_name}.runtime_deps, as per
709# the conventions listed in the
710# [test wrapper API](//docs/testing/test_wrapper_api.md).
711template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:59712 if (use_rts) {
713 action("${target_name}__rts_filters") {
714 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53715 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:59716 args = [ rebase_path(rts_file, root_build_dir) ]
717 outputs = [ rts_file ]
718 }
719 }
720
Dirk Pranke6188075b2020-10-01 19:31:28721 generate_wrapper(target_name) {
722 testonly = true
723 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
724
725 executable = "//testing/test_env.py"
726
727 executable_args =
728 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
729 if (defined(invoker.args)) {
730 executable_args += invoker.args
731 }
732
Will Harrisd35e2c92021-04-07 01:42:02733 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:47734
735 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
736 use_vpython3 = false
737 data += [ "//.vpython" ]
738 } else {
739 use_vpython3 = true
740 data += [ "//.vpython3" ]
741 }
742
Dirk Pranke6188075b2020-10-01 19:31:28743 if (defined(invoker.data)) {
744 data += invoker.data
745 }
Dirk Pranke19a58732021-03-24 22:26:22746 data += [ "//testing/location_tags.json" ]
747
Will Harrisd35e2c92021-04-07 01:42:02748 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:28749 if (defined(invoker.data_deps)) {
750 data_deps += invoker.data_deps
751 }
752
753 forward_variables_from(invoker,
754 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01755 TESTONLY_AND_VISIBILITY + [
756 "data",
757 "data_deps",
758 "script",
759 "script_args",
760 ])
761 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28762
763 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:59764
765 if (use_rts) {
766 data_deps += [ ":${invoker.target_name}__rts_filters" ]
767 }
Dirk Pranke6188075b2020-10-01 19:31:28768 }
769}
770
brettwedb6ecc2016-07-14 23:37:03771# Test defaults.
772set_defaults("test") {
773 if (is_android) {
774 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41775 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59776 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03777 } else {
778 configs = default_executable_configs
779 }
780}