blob: a7682c6e99873a8f0918d157f2f9b57fcd37eefc [file] [log] [blame]
qsrc6c612c2015-01-13 22:07:481# Copyright 2015 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
qsrfb5251d12015-01-21 15:57:224
5# ==============================================================================
6# TEST SETUP
7# ==============================================================================
8
Yuke Liao2a9b2f0e2021-04-16 00:40:119import("//build/config/chromeos/args.gni")
Yuke Liaoe703384b2020-07-16 01:05:2410import("//build/config/chromeos/ui_mode.gni")
Kevin Marshall36c602c2021-11-04 16:16:2111import("//build/config/devtools.gni")
Dirk Prankeb404c3b2021-06-14 19:57:5012import("//build/config/gclient_args.gni")
Greg Guterman28b3cba2021-05-12 22:21:0313import("//build/config/rts.gni")
danakj02dddc42022-02-11 23:24:3014import("//build/rust/mixed_executable.gni")
danakj98e073722022-02-24 21:01:4915import("//build/rust/mixed_shared_library.gni")
Mirko Bonadei4a0df432020-09-08 19:06:0216import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2417
Greg Guterman6963dc082021-04-07 05:20:5918declare_args() {
Dirk Prankeb404c3b2021-06-14 19:57:5019 # Some component repos (e.g. ANGLE) import //testing but do not have
20 # "location_tags.json", and so we don't want to try and upload the tags
21 # for their tests.
22 # And, some build configs may simply turn off generation altogether.
23 tests_have_location_tags = generate_location_tags
Greg Guterman6963dc082021-04-07 05:20:5924}
25
jcivellif4462a352017-01-10 04:45:5926if (is_android) {
27 import("//build/config/android/config.gni")
Charlie Hud98dc692021-12-08 01:01:0228 import("//build/config/android/create_unwind_table.gni")
James Cook209256f2018-12-07 18:40:5029 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5930 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4431 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3232} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0633 import("//build/config/chromecast_build.gni")
Kevin Marshall55fd8522019-10-04 22:47:0134 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4235 import("//build/config/fuchsia/package.gni")
Chong Gu26908f4e2021-01-29 03:13:0736 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Yuke Liaoe502a742021-04-19 23:15:0237} else if ((is_chromeos_ash || is_chromeos_lacros) && is_chromeos_device) {
Ben Pastene4c35c572018-04-30 23:21:4838 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3239 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2840 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3241} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3642 import("//build/config/ios/ios_sdk.gni")
43 import("//build/config/ios/ios_test_runner_wrapper.gni")
44 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3245} else {
Dirk Pranke31e346e2020-07-15 00:54:0646 import("//build/config/sanitizers/sanitizers.gni")
47 import("//build/util/generate_wrapper.gni")
48}
49
danakjebb9cc4d2022-03-04 21:30:1150template("mixed_test") {
51 assert(defined(invoker.target_type) && invoker.target_type != "")
52 target("mixed_${invoker.target_type}", target_name) {
53 forward_variables_from(invoker,
54 "*",
55 TESTONLY_AND_VISIBILITY + [ "target_type" ])
56 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
57 if (!defined(rs_configs)) {
58 rs_configs = []
59 }
60 rs_configs += [ "//build/rust:test" ]
61
danakjaa85aad2022-03-10 18:45:1062 # The crate_root is generated and should not be specified.
63 assert(!defined(rs_crate_root))
64 rs_generate_crate_root = true
65
danakjebb9cc4d2022-03-04 21:30:1166 # We could automatically add `rs_deps += [ "//testing/rust_gtest_interop" ]`
67 # if `rs_sources` is non-empty. But we don't automatically provide
68 # //testing/gtest either so it would be asymmetric and could break in that
69 # case. So, we act instead as if //testing/rust_gtest_interop is part of the
70 # //testing/gtest dependency. If you add one, and have `rs_sources` listed,
71 # you get both.
72 _gtest_is_in_deps = false
73 if (defined(rs_sources) && rs_sources != [] && defined(deps) &&
74 deps != []) {
75 foreach(dep, deps) {
76 if (dep == "//testing/gtest") {
77 _gtest_is_in_deps = true
78 }
79 }
80 }
81 if (_gtest_is_in_deps) {
82 if (!defined(rs_deps)) {
83 rs_deps = []
84 }
85 rs_deps += [ "//testing/rust_gtest_interop" ]
86 }
87 }
88}
89
qsrfb5251d12015-01-21 15:57:2290# Define a test as an executable (or apk on Android) with the "testonly" flag
91# set.
agrieve62ab00282016-04-05 02:03:4592# Variable:
Dirk Pranke79d065d2020-08-29 03:28:3093# use_xvfb: (optional) whether to run the executable under Xvfb.
danakj02dddc42022-02-11 23:24:3094# use_raw_android_executable: Use mixed_executable() rather than
95# android_apk().
ynovikov389d9e442016-05-27 02:34:5696# use_native_activity: Test implements ANativeActivity_onCreate().
Greg Thompson26516592021-12-16 08:34:4597# use_cfv2: (Fuchsia, optional): build the test as a framework v2 component;
98# see https://fuchsia.dev/fuchsia-src/concepts/components/v2 for details.
Greg Thompson5e4f41f2022-02-09 16:35:1499# The default value is true; set it to false explicitly to build a test as
100# a v1 component.
Mirko Bonadei15522bc2020-09-16 20:38:39101# is_xctest: (iOS, optional) whether to build the executable as XCTest.
102# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
103# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:43104# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
105# network requests during the test.
qsrfb5251d12015-01-21 15:57:22106template("test") {
Greg Guterman6963dc082021-04-07 05:20:59107 # Ensures the rts file exists and if not, creates a dummy file
108 if (use_rts) {
109 action("${target_name}__rts_filters") {
110 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53111 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:59112 args = [ rebase_path(rts_file, root_build_dir) ]
113 outputs = [ rts_file ]
114 }
115 }
116
Andrew Grieve1b290e4a22020-11-24 20:07:01117 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:39118 if (!is_ios) {
119 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
120 "is_xctest can be set only for iOS builds")
121 }
Stefano Duo4128b6b2021-08-02 21:24:43122 if (!is_android) {
123 assert(!defined(invoker.allow_cleartext_traffic),
124 "allow_cleartext_traffic can be set only for Android tests")
125 }
126
qsrfb5251d12015-01-21 15:57:22127 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:30128 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
129
Peter Kotwicz10742f82021-04-15 22:32:50130 _use_default_launcher =
131 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
132 if (!defined(invoker.use_raw_android_executable)) {
133 # Checkouts where build_with_chromium == false often have a custom GN
134 # template wrapper around test() which sets use_default_launcher == false.
135 # Set the _use_raw_android_executable default so that test() targets which
136 # do not use the custom wrapper
137 # (1) Do not cause "gn gen" to fail
138 # (2) Do not need to be moved into if(build_with_chromium) block.
139 _use_raw_android_executable =
140 !build_with_chromium && _use_default_launcher
141 } else {
142 not_needed([ "_use_default_launcher" ])
143 _use_raw_android_executable = invoker.use_raw_android_executable
144 }
qsrfb5251d12015-01-21 15:57:22145
agrieve67855de2016-03-30 14:46:01146 # output_name is used to allow targets with the same name but in different
147 # packages to still produce unique runner scripts.
148 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26149 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01150 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26151 }
agrieve62ab00282016-04-05 02:03:45152
agrieveb355ad152016-04-19 03:45:23153 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42154 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:51155 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42156 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51157 ]
agrieve3ac557f02016-04-12 15:52:00158
jbudorickced2a252016-06-09 16:38:54159 assert(_use_raw_android_executable || enable_java_templates)
160
agrieve62ab00282016-04-05 02:03:45161 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49162 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
163
agrieve62ab00282016-04-05 02:03:45164 _exec_target = "${target_name}__exec"
165 _dist_target = "${target_name}__dist"
166 _exec_output =
167 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
168
danakjebb9cc4d2022-03-04 21:30:11169 mixed_test(_exec_target) {
170 target_type = "executable"
171
danakje94f40d2022-02-16 18:13:53172 # Configs will always be defined since we set_defaults in
173 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45174 configs = []
Dirk Pranke19a58732021-03-24 22:26:22175 forward_variables_from(
176 invoker,
177 "*",
178 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
179 "data_deps",
180 "extra_dist_files",
181 ])
agrieve62ab00282016-04-05 02:03:45182
183 # Thanks to the set_defaults() for test(), configs are initialized with
184 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59185 configs -= [
186 "//build/config:shared_library_config",
187 "//build/config/android:hide_all_but_jni",
188 ]
agrieve62ab00282016-04-05 02:03:45189 configs += [ "//build/config:executable_config" ]
190
Dirk Pranke19a58732021-03-24 22:26:22191 if (defined(invoker.data_deps)) {
192 data_deps = invoker.data_deps
193 } else {
194 data_deps = []
195 }
196 if (!defined(data)) {
197 data = []
198 }
Jamie Madilldd60ee62021-04-13 19:25:52199 if (tests_have_location_tags) {
200 data += [ "//testing/location_tags.json" ]
201 }
Dirk Pranke19a58732021-03-24 22:26:22202
agrieve62ab00282016-04-05 02:03:45203 # Don't output to the root or else conflict with the group() below.
204 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11205
206 if (use_rts) {
207 data_deps += [ ":${invoker.target_name}__rts_filters" ]
208 }
agrieve62ab00282016-04-05 02:03:45209 }
210
211 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45212 dist_dir = "$root_out_dir/$target_name"
213 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22214 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45215 if (defined(invoker.extra_dist_files)) {
216 extra_files = invoker.extra_dist_files
217 }
Greg Guterman50ed4b42021-04-08 01:15:11218
219 if (use_rts) {
220 if (!defined(data_deps)) {
221 data_deps = []
222 }
223 data_deps += [ ":${invoker.target_name}__rts_filters" ]
224 }
agrieve62ab00282016-04-05 02:03:45225 }
226 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02227 _library_target = "${target_name}__library"
danakj98e073722022-02-24 21:01:49228 _library_crate_name = "${target_name}_library"
Andrew Grievec61b8dff2019-10-21 16:32:02229 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45230 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43231 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45232 "android_manifest",
agrievec6811b422016-06-23 02:25:09233 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27234 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55235 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45236 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50237 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07238 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02239 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07240 "proguard_configs",
241 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45242 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02243 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45244 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56245 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45246 ]
Siddhartha764226b2018-03-13 02:32:55247
248 # Adds the unwind tables from unstripped binary as an asset file in the
249 # apk, if |add_unwind_tables_in_apk| is specified by the test.
250 if (defined(invoker.add_unwind_tables_in_apk) &&
251 invoker.add_unwind_tables_in_apk) {
252 _unwind_table_asset_name = "${target_name}_unwind_assets"
Charlie Hud98dc692021-12-08 01:01:02253 if (use_android_unwinder_v2) {
254 unwind_table_asset_v2(_unwind_table_asset_name) {
255 library_target = _library_target
256 deps = [ ":$_library_target" ]
257 }
258 } else {
259 unwind_table_asset(_unwind_table_asset_name) {
260 library_target = _library_target
261 deps = [ ":$_library_target" ]
262 }
Siddhartha764226b2018-03-13 02:32:55263 }
264 }
265
danakjebb9cc4d2022-03-04 21:30:11266 mixed_test(_library_target) {
267 target_type = "shared_library"
268
danakj98e073722022-02-24 21:01:49269 # Configs will always be defined since we set_defaults in
270 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45271 configs = [] # Prevent list overwriting warning.
272 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45273
danakjebb9cc4d2022-03-04 21:30:11274 # Use a crate name that avoids creating a warning due to double
275 # underscore (ie. `__`).
danakj98e073722022-02-24 21:01:49276 rs_crate_name = _library_crate_name
danakj98e073722022-02-24 21:01:49277
jbudorickd29ecfa72016-11-18 22:45:42278 forward_variables_from(
279 invoker,
280 "*",
Peter Wen2052bd12020-12-03 20:15:07281 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
282 TESTONLY_AND_VISIBILITY)
283
284 # Native targets do not need to depend on java targets. Filter them out
285 # so that the shared library can be built without needing to wait for
286 # dependent java targets.
287 deps = []
288 if (defined(invoker.deps)) {
289 foreach(_dep, invoker.deps) {
290 _target_label = get_label_info(_dep, "label_no_toolchain")
291 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
292 deps += [ _dep ]
293 }
294 }
295 }
agrieve62ab00282016-04-05 02:03:45296
Peter Kotwiczb9957d62021-04-12 21:09:43297 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37298 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45299 }
300 }
301 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54302 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07303 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45304 apk_name = invoker.target_name
305 if (defined(invoker.output_name)) {
306 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45307 install_script_name = "install_${invoker.output_name}"
308 }
agrieveb355ad152016-04-19 03:45:23309
Daniel Bratellfdda4652019-01-31 15:45:54310 if (defined(invoker.deps)) {
311 deps = invoker.deps
312 } else {
313 deps = []
314 }
315
jcivellif4462a352017-01-10 04:45:59316 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43317 if (_use_default_launcher) {
318 deps += [ "//base/test:test_support_java" ]
319 }
jcivellif4462a352017-01-10 04:45:59320
Siddhartha764226b2018-03-13 02:32:55321 if (defined(_unwind_table_asset_name)) {
322 deps += [ ":${_unwind_table_asset_name}" ]
323 }
Greg Guterman50ed4b42021-04-08 01:15:11324
325 if (use_rts) {
326 data_deps = [ ":${invoker.target_name}__rts_filters" ]
327 }
agrieve62ab00282016-04-05 02:03:45328 }
Andrew Grievee1dc23f2019-10-22 16:26:36329 }
agrieve62ab00282016-04-05 02:03:45330
Andrew Grievee1dc23f2019-10-22 16:26:36331 test_runner_script(_test_runner_target) {
332 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57333
Andrew Grievee1dc23f2019-10-22 16:26:36334 if (_use_raw_android_executable) {
335 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34336 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36337 } else {
338 apk_target = ":$_apk_target"
339 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47340
341 # Dep needed for the test runner .runtime_deps file to pick up data
342 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22343 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45344 }
Andrew Grievee1dc23f2019-10-22 16:26:36345 test_name = _output_name
346 test_suite = _output_name
347 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59348
349 if (use_rts) {
350 data_deps += [ ":${invoker.target_name}__rts_filters" ]
351 }
mikecase56d80d72015-06-03 00:57:26352 }
353
Andrew Grieve7ca6de32019-10-18 03:57:47354 # Create a wrapper script rather than using a group() in order to ensure
355 # "ninja $target_name" always works. If this was a group(), then GN would
356 # not create a top-level alias for it if a target exists in another
357 # directory with the same $target_name.
358 # Also - bots run this script directly for "components_perftests".
359 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01360 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47361 executable = "$root_build_dir/bin/run_$_output_name"
362 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22363 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40364 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47365 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40366 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47367 # Dep needed for the swarming .isolate file to pick up data
368 # deps from the forward_variables_from(invoker, "*") on the library.
369 deps += [
370 ":$_apk_target",
371 ":$_library_target",
372 ]
agrieve62ab00282016-04-05 02:03:45373 }
Dirk Pranke19a58732021-03-24 22:26:22374
375 if (defined(invoker.data_deps)) {
376 data_deps = invoker.data_deps
377 } else {
378 data_deps = []
379 }
Kevin Marshall23529362022-02-23 16:50:36380
381 data_deps += [ "//testing:test_scripts_shared" ]
382
Jamie Madilldd60ee62021-04-13 19:25:52383 if (tests_have_location_tags) {
384 data = [ "//testing/location_tags.json" ]
385 }
Greg Guterman6963dc082021-04-07 05:20:59386
387 if (use_rts) {
388 data_deps += [ ":${invoker.target_name}__rts_filters" ]
389 }
agrieve1a02e582015-10-15 21:35:39390 }
Scott Graham4c4cdc52017-05-29 20:45:03391 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30392 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
393
Scott Graham4c4cdc52017-05-29 20:45:03394 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42395 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42396 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03397
Greg Thompson5e4f41f2022-02-09 16:35:14398 if (!defined(invoker.use_cfv2) || invoker.use_cfv2) {
Greg Thompson26516592021-12-16 08:34:45399 # Generate a CML fragment that provides the program name.
400 _test_program_fragment_target = "${target_name}_program-fragment"
401 _test_program_fragment =
402 "${target_out_dir}/${target_name}_program.test-cml"
403 _program_name = get_label_info(":${_exec_target}", "name")
404 generated_file(_test_program_fragment_target) {
405 contents = "{ program: { binary: \"${_program_name}\",},}"
406 outputs = [ _test_program_fragment ]
407 }
408
409 # Collate the complete set of elements to include in the test component's
410 # manifest.
411 _manifest_fragments = [
Greg Thompson6cdcdb32022-01-31 11:12:44412 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
Greg Thompson26516592021-12-16 08:34:45413 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml",
Greg Thompsonf31d7d22022-01-26 09:17:45414 "//build/config/fuchsia/test/minimum.shard.test-cml",
Greg Thompson26516592021-12-16 08:34:45415 _test_program_fragment,
416 ]
417
418 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
419 _merged_manifest_name = "${_output_name}.cml"
420 } else {
421 # Generate a CMX fragment that provides the program name.
422 _test_program_fragment_target = "${target_name}_program-fragment"
423 _test_program_fragment =
424 "${target_out_dir}/${target_name}_program.test-cmx"
425 _program_name = get_label_info(":${_exec_target}", "name")
426 generated_file(_test_program_fragment_target) {
427 contents = "{ \"program\": { \"binary\": \"${_program_name}\"}}"
428 outputs = [ _test_program_fragment ]
429 }
430
431 # Collate the complete set of elements to include in the test component's
432 # manifest.
433 _manifest_fragments = [
434 "//build/config/fuchsia/test/minimum_capabilities.test-cmx",
435 _test_program_fragment,
436 ]
437
438 _test_component_manifest = "${target_out_dir}/${target_name}.cmx"
439 _merged_manifest_name = "${_output_name}.cmx"
Wez6879f8a2021-09-07 20:27:02440 }
Chong Gu26908f4e2021-01-29 03:13:07441
Chong Gu91a1fea2021-03-30 17:24:31442 if (defined(invoker.additional_manifest_fragments)) {
Wez6879f8a2021-09-07 20:27:02443 _manifest_fragments += invoker.additional_manifest_fragments
Chong Guacf19a32021-03-10 01:07:41444 }
Chong Gu28bf7e72021-05-26 01:36:19445
Wez6879f8a2021-09-07 20:27:02446 # Generate the test component manifest from the specified elements.
447 _test_component_manifest_target = "${target_name}_component-manifest"
Wez6879f8a2021-09-07 20:27:02448 cmc_merge(_test_component_manifest_target) {
449 sources = _manifest_fragments
Greg Thompson26516592021-12-16 08:34:45450 output_name = "${_merged_manifest_name}"
Wez6879f8a2021-09-07 20:27:02451 deps = [ ":${_test_program_fragment_target}" ]
Chong Gu7ad57c22021-03-11 00:24:38452 }
Chong Gu26908f4e2021-01-29 03:13:07453
Wez6879f8a2021-09-07 20:27:02454 # Define the test component, dependent on the generated manifest, and the
455 # test executable target.
456 _test_component_target = "${target_name}_component"
457 fuchsia_component(_test_component_target) {
458 deps = [ ":$_test_component_manifest_target" ]
459 data_deps = [ ":$_exec_target" ]
460 manifest = _test_component_manifest
461 visibility = [ ":*" ]
462 }
463
464 # Define components for each entry in |additional_manifests|, if any. Since
465 # manifests may themselves depend-on the outputs of |deps|, these components
466 # must each individually depend on |invoker.deps|.
467 _test_component_targets = [ ":${_test_component_target}" ]
468 if (defined(invoker.additional_manifests)) {
469 foreach(filename, invoker.additional_manifests) {
470 _additional_component_target =
471 target_name + "_" + get_path_info(filename, "name")
472 _test_component_targets += [ ":${_additional_component_target}" ]
473 fuchsia_component(_additional_component_target) {
474 forward_variables_from(invoker, [ "testonly" ])
475 data_deps = [ ":$_exec_target" ]
476 visibility = [ ":*" ]
477 manifest = filename
478
479 # Depend on |invoker.deps|, in case it includes a dependency that
480 # creates this additional component's manifest.
481 if (defined(invoker.deps)) {
482 deps = invoker.deps
483 }
484 }
485 }
486 }
487
488 # Define the package target that will bundle the test and additional
489 # components and their data.
490 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21491 forward_variables_from(invoker,
492 [
493 "excluded_files",
494 "excluded_dirs",
495 ])
Wez6879f8a2021-09-07 20:27:02496 package_name = _output_name
497 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21498
499 if (!defined(excluded_dirs)) {
500 excluded_dirs = []
501 }
502 excluded_dirs += [ devtools_root_location ]
Wez6879f8a2021-09-07 20:27:02503 }
504
505 # |target_name| refers to the package-runner rule, so that building
506 # "base_unittests" will build not only the executable, component, and
507 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25508 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53509 forward_variables_from(invoker,
510 [
Kevin Marshall5fadadd2021-10-16 00:08:25511 "data",
512 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53513 "package_deps",
Greg Thompson26516592021-12-16 08:34:45514 "use_cfv2",
Kevin Marshall5fadadd2021-10-16 00:08:25515 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53516 ])
Kevin Marshall5fadadd2021-10-16 00:08:25517
Chong Guc6bfdf62021-10-20 23:37:00518 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15519 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25520 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42521
Kevin Marshall5fadadd2021-10-16 00:08:25522 if (!defined(deps)) {
523 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52524 }
Kevin Marshall5fadadd2021-10-16 00:08:25525 if (defined(invoker.deps)) {
526 deps += invoker.deps
527 }
Greg Guterman6963dc082021-04-07 05:20:59528
Kevin Marshall5fadadd2021-10-16 00:08:25529 if (!defined(data)) {
530 data = []
531 }
532 if (tests_have_location_tags) {
533 data += [ "//testing/location_tags.json" ]
534 }
535
536 if (!defined(data_deps)) {
537 data_deps = []
538 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28539
Kevin Marshall23529362022-02-23 16:50:36540 data_deps += [ "//testing:test_scripts_shared" ]
541
Benjamin Lerman5e3cb3362022-01-25 16:46:28542 # TODO(crbug.com/1199334): Because perfetto unit test is defined outside
543 # of chromium, the dependency to the filter file is added here.
544 data_deps += [ "//testing/buildbot/filters:perfetto_unittests_filters" ]
Chong Gu258e22c2021-10-20 18:39:50545
Greg Guterman6963dc082021-04-07 05:20:59546 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25547 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59548 }
Kevin Marshallf35fa5f2018-01-29 19:24:42549 }
550
danakjebb9cc4d2022-03-04 21:30:11551 mixed_test(_exec_target) {
552 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01553 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42554 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03555 }
dpranke2a294622015-08-07 05:23:01556 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30557 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46558 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30559
Rohit Raof9b096d2019-09-09 22:26:23560 declare_args() {
561 # Keep the unittest-as-xctest functionality defaulted to off until the
562 # bots are updated to handle it properly.
563 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
564 # supports running unittests with xctest.
565 enable_run_ios_unittests_with_xctest = false
566 }
567
sdefresne012857872016-03-16 10:55:37568 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27569 _output_name = target_name
570 if (defined(invoker.output_name)) {
571 _output_name = invoker.output_name
572 }
573
Jeff Yoonf7f4eb42020-03-06 18:55:36574 _wrapper_output_name = "run_${target_name}"
575 ios_test_runner_wrapper(_wrapper_output_name) {
576 forward_variables_from(invoker,
577 [
578 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36579 "deps",
580 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27581 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36582 "retries",
583 "shards",
584 ])
585
586 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
587
588 if (!defined(executable_args)) {
589 executable_args = []
590 }
591 executable_args += [
592 "--app",
593 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
594 ]
595
596 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22597
598 if (!defined(data)) {
599 data = []
600 }
Jamie Madilldd60ee62021-04-13 19:25:52601 if (tests_have_location_tags) {
602 data += [ "//testing/location_tags.json" ]
603 }
Jeff Yoonf7f4eb42020-03-06 18:55:36604 }
605
sdefresne012857872016-03-16 10:55:37606 _resources_bundle_data = target_name + "_resources_bundle_data"
607
608 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34609 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22610 sources = [ "//testing/gtest_ios/Default.png" ]
611 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01612 }
613
Mirko Bonadei15522bc2020-09-16 20:38:39614 force_xctest = enable_run_ios_unittests_with_xctest ||
615 (defined(invoker.is_xctest) && invoker.is_xctest)
616
617 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23618 ios_test_target_type = "ios_xctest_test"
619 } else {
620 ios_test_target_type = "ios_app_bundle"
621 }
622
623 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01624 testonly = true
sdefresnea828c282016-05-30 18:04:20625
Mirko Bonadei15522bc2020-09-16 20:38:39626 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23627 xctest_module_target = "//base/test:google_test_runner"
628 }
629
Andrew Grieve1b290e4a22020-11-24 20:07:01630 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13631
632 # Provide sensible defaults in case invoker did not define any of those
633 # required variables.
sdefresne05b97ca2016-06-08 07:19:46634 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13635 info_plist = "//testing/gtest_ios/unittest-Info.plist"
636 }
sdefresne9e147e02016-06-07 00:10:13637
Sylvain Defresne3c5a1312021-09-23 17:08:09638 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13639 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50640 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09641 } else {
Ali Juma75be0fe2022-01-24 19:39:29642 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27643 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09644 }
dpranke2a294622015-08-07 05:23:01645
sdefresne047490e2016-07-22 08:49:34646 if (!defined(bundle_deps)) {
647 bundle_deps = []
648 }
649 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36650
651 if (!defined(data_deps)) {
652 data_deps = []
653 }
654
Kevin Marshall23529362022-02-23 16:50:36655 data_deps += [ "//testing:test_scripts_shared" ]
656
Jeff Yoonf7f4eb42020-03-06 18:55:36657 # Include the generate_wrapper as part of data_deps
658 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46659 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59660
661 if (use_rts) {
662 data_deps += [ ":${invoker.target_name}__rts_filters" ]
663 }
dpranke2a294622015-08-07 05:23:01664 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11665 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
666 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30667 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
668
Yuke Liao2a9b2f0e2021-04-16 00:40:11669 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32670
Benjamin Pastene3bce864e2018-04-14 01:16:32671 _gen_runner_target = "${target_name}__runner"
672 _runtime_deps_file =
673 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
674 "/" + get_label_info(target_name, "name") + ".runtime_deps"
675
Xinan Lin6be01252021-06-25 23:07:36676 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
677 if (is_skylab) {
678 generate_skylab_runner_script(_gen_runner_target) {
679 generated_script = _generated_script
680 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34681 }
Xinan Lin6be01252021-06-25 23:07:36682 } else {
683 generate_runner_script(_gen_runner_target) {
684 generated_script = _generated_script
685 test_exe = invoker.target_name
686 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34687
Xinan Lin6be01252021-06-25 23:07:36688 if (is_chromeos_lacros) {
689 # At build time, Lacros tests don't know whether they'll run on VM or
690 # HW, and instead, these flags are specified at runtime when invoking
691 # the generated runner script.
692 skip_generating_board_args = true
693 }
Greg Guterman6963dc082021-04-07 05:20:59694
Xinan Lin6be01252021-06-25 23:07:36695 if (tests_have_location_tags) {
696 data = [ "//testing/location_tags.json" ]
697 }
698
699 if (use_rts) {
700 data_deps = [ ":${invoker.target_name}__rts_filters" ]
701 }
Greg Guterman6963dc082021-04-07 05:20:59702 }
Benjamin Pastene3bce864e2018-04-14 01:16:32703 }
704
danakjebb9cc4d2022-03-04 21:30:11705 mixed_test(target_name) {
706 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01707 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
708 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32709 if (!defined(deps)) {
710 deps = []
711 }
712 if (!defined(data)) {
713 data = []
714 }
715
Ben Pastene41041782019-02-16 04:21:58716 # We use a special trigger script for CrOS hardware tests.
717 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
718
Benjamin Pastene3bce864e2018-04-14 01:16:32719 output_name = target_name
720 write_runtime_deps = _runtime_deps_file
721 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37722 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59723
Kevin Marshall23529362022-02-23 16:50:36724 if (!defined(data_deps)) {
725 data_deps = []
726 }
727
728 data_deps += [ "//testing:test_scripts_shared" ]
729
Greg Guterman6963dc082021-04-07 05:20:59730 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59731 data_deps += [ ":${invoker.target_name}__rts_filters" ]
732 }
Benjamin Pastene3bce864e2018-04-14 01:16:32733 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11734 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24735 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
736 _executable = target_name
737 _gen_runner_target = "${target_name}__runner"
738
Yuke Liao32af4242020-07-16 21:48:02739 if (defined(invoker.use_xvfb)) {
740 _use_xvfb = invoker.use_xvfb
741 } else {
742 _use_xvfb = false
743 }
744
Yuke Liaod037abc2020-10-06 22:48:22745 # When use_xvfb is set by the invoker, it indicates that running this test
746 # target requires a window, and in lacros build, ash-chrome serves as the
747 # display server. Note that even though the tests themselves do not require
748 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
749 # because ash-chrome is based on x11.
750 _use_ash_chrome = _use_xvfb
751
Yuke Liaoe703384b2020-07-16 01:05:24752 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24753 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02754
Yuke Liao2e4953cf2020-07-26 19:20:19755 data = []
Will Harrisd35e2c92021-04-07 01:42:02756 data_deps = [ "//testing:test_scripts_shared" ]
757
Yuke Liao32af4242020-07-16 21:48:02758 if (_use_xvfb) {
759 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22760 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02761 } else {
762 executable = "//testing/test_env.py"
763 }
Jamie Madilldd60ee62021-04-13 19:25:52764 if (tests_have_location_tags) {
765 data += [ "//testing/location_tags.json" ]
766 }
Yuke Liao32af4242020-07-16 21:48:02767
Yuke Liaoe703384b2020-07-16 01:05:24768 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02769 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39770 "test",
Yuke Liaoe703384b2020-07-16 01:05:24771 "@WrappedPath(./${_executable})",
772 "--test-launcher-bot-mode",
773 ]
Yuke Liao32af4242020-07-16 21:48:02774
Yuke Liaof540c742020-07-29 16:28:34775 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37776 executable_args += [ "--ash-chrome-path" ]
777
778 # Can't use --ash-chrome-path=path because WrappedPath
779 # won't be expanded for that usage.
780 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39781 }
782
Yuke Liaoe703384b2020-07-16 01:05:24783 if (is_asan) {
784 executable_args += [ "--asan=true" ]
785 }
786 if (is_msan) {
787 executable_args += [ "--msan=true" ]
788 }
789 if (is_tsan) {
790 executable_args += [ "--tsan=true" ]
791 }
792 if (use_cfi_diag) {
793 executable_args += [ "--cfi-diag=true" ]
794 }
795
Takuto Ikuta38ebd0e2022-01-19 17:56:22796 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59797
798 if (use_rts) {
799 data_deps += [ ":${invoker.target_name}__rts_filters" ]
800 }
Yuke Liaoe703384b2020-07-16 01:05:24801 }
802
danakjebb9cc4d2022-03-04 21:30:11803 mixed_test(target_name) {
804 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01805 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
806 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24807 if (!defined(deps)) {
808 deps = []
809 }
810
Yuke Liaod037abc2020-10-06 22:48:22811 if (!defined(data_deps)) {
812 data_deps = []
813 }
814
Kevin Marshall23529362022-02-23 16:50:36815 data_deps += [ "//testing:test_scripts_shared" ]
816
Yuke Liaoe703384b2020-07-16 01:05:24817 write_runtime_deps = _runtime_deps_file
818 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22819 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56820 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22821 }
Greg Guterman6963dc082021-04-07 05:20:59822
823 if (use_rts) {
824 data_deps += [ ":${invoker.target_name}__rts_filters" ]
825 }
Yuke Liaoe703384b2020-07-16 01:05:24826 }
Dirk Prankedd4ff742020-11-18 19:57:32827 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30828 if (is_mac || is_win) {
829 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
830 }
831
Dirk Prankedd4ff742020-11-18 19:57:32832 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
833 _executable = target_name
834 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06835
Dirk Prankedd4ff742020-11-18 19:57:32836 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
837 _use_xvfb = invoker.use_xvfb
838 } else {
839 _use_xvfb = false
840 }
841
842 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32843 wrapper_script = "$root_build_dir/bin/run_" + _executable
844
845 data = []
Will Harrisd35e2c92021-04-07 01:42:02846 data_deps = [ "//testing:test_scripts_shared" ]
847
Dirk Prankedd4ff742020-11-18 19:57:32848 if (_use_xvfb) {
849 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06850 } else {
Dirk Prankedd4ff742020-11-18 19:57:32851 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06852 }
Jamie Madilldd60ee62021-04-13 19:25:52853 if (tests_have_location_tags) {
854 data += [ "//testing/location_tags.json" ]
855 }
Dirk Pranke31e346e2020-07-15 00:54:06856
Dirk Prankedd4ff742020-11-18 19:57:32857 executable_args = [
858 "@WrappedPath(./${_executable})",
859 "--test-launcher-bot-mode",
860 ]
861 if (is_asan) {
862 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06863 }
Dirk Prankedd4ff742020-11-18 19:57:32864 if (is_msan) {
865 executable_args += [ "--msan=true" ]
866 }
867 if (is_tsan) {
868 executable_args += [ "--tsan=true" ]
869 }
870 if (use_cfi_diag) {
871 executable_args += [ "--cfi-diag=true" ]
872 }
873
874 data += [ "//.vpython" ]
Greg Guterman6963dc082021-04-07 05:20:59875
876 if (use_rts) {
877 data_deps += [ ":${invoker.target_name}__rts_filters" ]
878 }
Dirk Pranke31e346e2020-07-15 00:54:06879 }
880
danakjebb9cc4d2022-03-04 21:30:11881 mixed_test(target_name) {
882 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01883 forward_variables_from(invoker,
884 "*",
885 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
886 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06887 if (!defined(deps)) {
888 deps = []
889 }
890
Dirk Pranke31e346e2020-07-15 00:54:06891 deps += [
892 # Give tests the default manifest on Windows (a no-op elsewhere).
893 "//build/win:default_exe_manifest",
894 ]
895
Dirk Prankedd4ff742020-11-18 19:57:32896 write_runtime_deps = _runtime_deps_file
897 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11898
Kevin Marshall23529362022-02-23 16:50:36899 if (!defined(data_deps)) {
900 data_deps = []
901 }
902
903 data_deps += [ "//testing:test_scripts_shared" ]
904
Greg Guterman50ed4b42021-04-08 01:15:11905 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:11906 data_deps += [ ":${invoker.target_name}__rts_filters" ]
907 }
Dirk Prankedd4ff742020-11-18 19:57:32908 }
909 } else {
910 # This is a catch-all clause for NaCl toolchains and other random
911 # configurations that might define tests; test() in these configs
912 # will just define the underlying executables.
913 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
914 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:11915 mixed_test(target_name) {
916 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01917 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
918 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32919 if (!defined(deps)) {
920 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06921 }
Greg Guterman6963dc082021-04-07 05:20:59922
Kevin Marshall23529362022-02-23 16:50:36923 if (!defined(data_deps)) {
924 data_deps = []
925 }
926
927 data_deps += [ "//testing:test_scripts_shared" ]
928
Greg Guterman6963dc082021-04-07 05:20:59929 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59930 data_deps += [ ":${invoker.target_name}__rts_filters" ]
931 }
Dirk Pranke31e346e2020-07-15 00:54:06932 }
qsrfb5251d12015-01-21 15:57:22933 }
934}
brettwedb6ecc2016-07-14 23:37:03935
Dirk Pranke6188075b2020-10-01 19:31:28936# Defines a type of test that invokes a script to run, rather than
937# invoking an executable.
938#
939# The script must implement the
940# [test executable API](//docs/testing/test_executable_api.md).
941#
942# The template must be passed the `script` parameter, which specifies
943# the path to the script to run. It may optionally be passed a
944# `script_args` parameter, which can be used to include a list of
945# args to be specified by default. The template will produce
946# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
947# for the target to $root_build_dir/${target_name}.runtime_deps, as per
948# the conventions listed in the
949# [test wrapper API](//docs/testing/test_wrapper_api.md).
950template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:59951 if (use_rts) {
952 action("${target_name}__rts_filters") {
953 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53954 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:59955 args = [ rebase_path(rts_file, root_build_dir) ]
956 outputs = [ rts_file ]
957 }
958 }
959
Dirk Pranke6188075b2020-10-01 19:31:28960 generate_wrapper(target_name) {
961 testonly = true
962 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
963
964 executable = "//testing/test_env.py"
965
966 executable_args =
967 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
968 if (defined(invoker.args)) {
969 executable_args += invoker.args
970 }
971
Will Harrisd35e2c92021-04-07 01:42:02972 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:47973
974 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
975 use_vpython3 = false
976 data += [ "//.vpython" ]
Dirk Pranke2dd666cd2021-03-03 16:57:47977 }
978
Dirk Pranke6188075b2020-10-01 19:31:28979 if (defined(invoker.data)) {
980 data += invoker.data
981 }
Jamie Madilldd60ee62021-04-13 19:25:52982 if (tests_have_location_tags) {
983 data += [ "//testing/location_tags.json" ]
984 }
Dirk Pranke19a58732021-03-24 22:26:22985
Will Harrisd35e2c92021-04-07 01:42:02986 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:28987 if (defined(invoker.data_deps)) {
988 data_deps += invoker.data_deps
989 }
990
991 forward_variables_from(invoker,
992 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01993 TESTONLY_AND_VISIBILITY + [
994 "data",
995 "data_deps",
996 "script",
997 "script_args",
998 ])
999 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281000
1001 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591002
1003 if (use_rts) {
1004 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1005 }
Dirk Pranke6188075b2020-10-01 19:31:281006 }
1007}
1008
brettwedb6ecc2016-07-14 23:37:031009# Test defaults.
1010set_defaults("test") {
1011 if (is_android) {
1012 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411013 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591014 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:031015 } else {
1016 configs = default_executable_configs
Leonard Grey077a28302021-12-16 14:14:261017 if (is_mac) {
1018 # TODO(lgrey): Maybe restore this.
1019 # Don't strip tests for visibility into test crashes/hangs.
1020 # https://bugs.chromium.org/p/chromium/issues/detail?id=1244047#c49
1021 configs -= [ "//build/config/mac:strip_all" ]
1022 }
brettwedb6ecc2016-07-14 23:37:031023 }
1024}