blob: 359b4c0bc52fcd5342cbca04f1a3af846ce75eb6 [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
David Dorwin621c5072022-03-30 00:32:5326# On Fuchsia, the test executable has a suffix and is a dependency of the
27# common |target_name| target. For `visibility`, the executable must be
28# specified. Cross-platform targets that include `test` targets in their
29# visibility lists, add `${exec_target_suffix}` immediately after the test
30# target name. This is not necessary when the target is a `source_set`.
31if (is_fuchsia) {
32 exec_target_suffix = "__exec"
33} else {
34 exec_target_suffix = ""
35}
36
jcivellif4462a352017-01-10 04:45:5937if (is_android) {
38 import("//build/config/android/config.gni")
Charlie Hud98dc692021-12-08 01:01:0239 import("//build/config/android/create_unwind_table.gni")
James Cook209256f2018-12-07 18:40:5040 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5941 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4442 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3243} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0644 import("//build/config/chromecast_build.gni")
Kevin Marshall55fd8522019-10-04 22:47:0145 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4246 import("//build/config/fuchsia/package.gni")
Chong Gu26908f4e2021-01-29 03:13:0747 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Nico Weberd73c90382022-03-30 20:37:5048} else if (is_chromeos && is_chromeos_device) {
Ben Pastene4c35c572018-04-30 23:21:4849 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3250 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2851 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3252} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3653 import("//build/config/ios/ios_sdk.gni")
54 import("//build/config/ios/ios_test_runner_wrapper.gni")
55 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3256} else {
Dirk Pranke31e346e2020-07-15 00:54:0657 import("//build/config/sanitizers/sanitizers.gni")
58 import("//build/util/generate_wrapper.gni")
59}
60
danakjebb9cc4d2022-03-04 21:30:1161template("mixed_test") {
62 assert(defined(invoker.target_type) && invoker.target_type != "")
63 target("mixed_${invoker.target_type}", target_name) {
64 forward_variables_from(invoker,
65 "*",
66 TESTONLY_AND_VISIBILITY + [ "target_type" ])
67 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
68 if (!defined(rs_configs)) {
69 rs_configs = []
70 }
71 rs_configs += [ "//build/rust:test" ]
72
danakjaa85aad2022-03-10 18:45:1073 # The crate_root is generated and should not be specified.
74 assert(!defined(rs_crate_root))
75 rs_generate_crate_root = true
76
danakjebb9cc4d2022-03-04 21:30:1177 # We could automatically add `rs_deps += [ "//testing/rust_gtest_interop" ]`
78 # if `rs_sources` is non-empty. But we don't automatically provide
79 # //testing/gtest either so it would be asymmetric and could break in that
80 # case. So, we act instead as if //testing/rust_gtest_interop is part of the
81 # //testing/gtest dependency. If you add one, and have `rs_sources` listed,
82 # you get both.
83 _gtest_is_in_deps = false
84 if (defined(rs_sources) && rs_sources != [] && defined(deps) &&
85 deps != []) {
86 foreach(dep, deps) {
87 if (dep == "//testing/gtest") {
88 _gtest_is_in_deps = true
89 }
90 }
91 }
92 if (_gtest_is_in_deps) {
93 if (!defined(rs_deps)) {
94 rs_deps = []
95 }
96 rs_deps += [ "//testing/rust_gtest_interop" ]
97 }
98 }
99}
100
qsrfb5251d12015-01-21 15:57:22101# Define a test as an executable (or apk on Android) with the "testonly" flag
102# set.
agrieve62ab00282016-04-05 02:03:45103# Variable:
Dirk Pranke79d065d2020-08-29 03:28:30104# use_xvfb: (optional) whether to run the executable under Xvfb.
danakj02dddc42022-02-11 23:24:30105# use_raw_android_executable: Use mixed_executable() rather than
106# android_apk().
ynovikov389d9e442016-05-27 02:34:56107# use_native_activity: Test implements ANativeActivity_onCreate().
Greg Thompson26516592021-12-16 08:34:45108# use_cfv2: (Fuchsia, optional): build the test as a framework v2 component;
109# see https://fuchsia.dev/fuchsia-src/concepts/components/v2 for details.
Greg Thompson9765eeb42022-04-05 12:30:35110# The default value is true; set it to false explicitly to omit a .cm
111# manifest from the package.
112# use_cfv1: (Fuchsia, optional): build the test as a framework v1 component.
113# The default value is true; set it to false explicitly to omit a .cmx
114# manifest from the package.
Greg Thompson318cd692022-03-28 08:12:06115# test_runner_shard: (Fuchsia, optional): for CFv2 tests, use the given test
116# runner shard rather than the default shard for the ELF runner. This is
117# useful, for example, to use the elf_test_ambient_exec_runner for tests
118# that require job_policy_ambient_mark_vmo_exec.
Mirko Bonadei15522bc2020-09-16 20:38:39119# is_xctest: (iOS, optional) whether to build the executable as XCTest.
120# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
121# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:43122# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
123# network requests during the test.
qsrfb5251d12015-01-21 15:57:22124template("test") {
Greg Guterman6963dc082021-04-07 05:20:59125 # Ensures the rts file exists and if not, creates a dummy file
126 if (use_rts) {
127 action("${target_name}__rts_filters") {
128 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53129 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:59130 args = [ rebase_path(rts_file, root_build_dir) ]
131 outputs = [ rts_file ]
132 }
133 }
134
Andrew Grieve1b290e4a22020-11-24 20:07:01135 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:39136 if (!is_ios) {
137 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
138 "is_xctest can be set only for iOS builds")
139 }
Stefano Duo4128b6b2021-08-02 21:24:43140 if (!is_android) {
141 assert(!defined(invoker.allow_cleartext_traffic),
142 "allow_cleartext_traffic can be set only for Android tests")
143 }
144
qsrfb5251d12015-01-21 15:57:22145 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:30146 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
147
Peter Kotwicz10742f82021-04-15 22:32:50148 _use_default_launcher =
149 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
150 if (!defined(invoker.use_raw_android_executable)) {
151 # Checkouts where build_with_chromium == false often have a custom GN
152 # template wrapper around test() which sets use_default_launcher == false.
153 # Set the _use_raw_android_executable default so that test() targets which
154 # do not use the custom wrapper
155 # (1) Do not cause "gn gen" to fail
156 # (2) Do not need to be moved into if(build_with_chromium) block.
157 _use_raw_android_executable =
158 !build_with_chromium && _use_default_launcher
159 } else {
160 not_needed([ "_use_default_launcher" ])
161 _use_raw_android_executable = invoker.use_raw_android_executable
162 }
qsrfb5251d12015-01-21 15:57:22163
agrieve67855de2016-03-30 14:46:01164 # output_name is used to allow targets with the same name but in different
165 # packages to still produce unique runner scripts.
166 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26167 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01168 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26169 }
agrieve62ab00282016-04-05 02:03:45170
agrieveb355ad152016-04-19 03:45:23171 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42172 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:51173 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42174 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51175 ]
agrieve3ac557f02016-04-12 15:52:00176
jbudorickced2a252016-06-09 16:38:54177 assert(_use_raw_android_executable || enable_java_templates)
178
agrieve62ab00282016-04-05 02:03:45179 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49180 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
181
agrieve62ab00282016-04-05 02:03:45182 _exec_target = "${target_name}__exec"
183 _dist_target = "${target_name}__dist"
184 _exec_output =
185 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
186
danakjebb9cc4d2022-03-04 21:30:11187 mixed_test(_exec_target) {
188 target_type = "executable"
189
danakje94f40d2022-02-16 18:13:53190 # Configs will always be defined since we set_defaults in
191 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45192 configs = []
Dirk Pranke19a58732021-03-24 22:26:22193 forward_variables_from(
194 invoker,
195 "*",
196 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
197 "data_deps",
198 "extra_dist_files",
199 ])
agrieve62ab00282016-04-05 02:03:45200
201 # Thanks to the set_defaults() for test(), configs are initialized with
202 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59203 configs -= [
204 "//build/config:shared_library_config",
205 "//build/config/android:hide_all_but_jni",
206 ]
agrieve62ab00282016-04-05 02:03:45207 configs += [ "//build/config:executable_config" ]
208
Dirk Pranke19a58732021-03-24 22:26:22209 if (defined(invoker.data_deps)) {
210 data_deps = invoker.data_deps
211 } else {
212 data_deps = []
213 }
214 if (!defined(data)) {
215 data = []
216 }
Jamie Madilldd60ee62021-04-13 19:25:52217 if (tests_have_location_tags) {
218 data += [ "//testing/location_tags.json" ]
219 }
Dirk Pranke19a58732021-03-24 22:26:22220
agrieve62ab00282016-04-05 02:03:45221 # Don't output to the root or else conflict with the group() below.
222 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11223
224 if (use_rts) {
225 data_deps += [ ":${invoker.target_name}__rts_filters" ]
226 }
agrieve62ab00282016-04-05 02:03:45227 }
228
229 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45230 dist_dir = "$root_out_dir/$target_name"
231 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22232 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45233 if (defined(invoker.extra_dist_files)) {
234 extra_files = invoker.extra_dist_files
235 }
Greg Guterman50ed4b42021-04-08 01:15:11236
237 if (use_rts) {
238 if (!defined(data_deps)) {
239 data_deps = []
240 }
241 data_deps += [ ":${invoker.target_name}__rts_filters" ]
242 }
agrieve62ab00282016-04-05 02:03:45243 }
244 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02245 _library_target = "${target_name}__library"
danakj98e073722022-02-24 21:01:49246 _library_crate_name = "${target_name}_library"
Andrew Grievec61b8dff2019-10-21 16:32:02247 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45248 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43249 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45250 "android_manifest",
agrievec6811b422016-06-23 02:25:09251 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27252 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55253 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45254 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50255 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07256 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02257 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07258 "proguard_configs",
259 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45260 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02261 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45262 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56263 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45264 ]
Siddhartha764226b2018-03-13 02:32:55265
266 # Adds the unwind tables from unstripped binary as an asset file in the
267 # apk, if |add_unwind_tables_in_apk| is specified by the test.
268 if (defined(invoker.add_unwind_tables_in_apk) &&
269 invoker.add_unwind_tables_in_apk) {
270 _unwind_table_asset_name = "${target_name}_unwind_assets"
Charlie Hud98dc692021-12-08 01:01:02271 if (use_android_unwinder_v2) {
272 unwind_table_asset_v2(_unwind_table_asset_name) {
273 library_target = _library_target
274 deps = [ ":$_library_target" ]
275 }
276 } else {
277 unwind_table_asset(_unwind_table_asset_name) {
278 library_target = _library_target
279 deps = [ ":$_library_target" ]
280 }
Siddhartha764226b2018-03-13 02:32:55281 }
282 }
283
danakjebb9cc4d2022-03-04 21:30:11284 mixed_test(_library_target) {
285 target_type = "shared_library"
286
danakj98e073722022-02-24 21:01:49287 # Configs will always be defined since we set_defaults in
288 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45289 configs = [] # Prevent list overwriting warning.
290 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45291
danakjebb9cc4d2022-03-04 21:30:11292 # Use a crate name that avoids creating a warning due to double
293 # underscore (ie. `__`).
danakj98e073722022-02-24 21:01:49294 rs_crate_name = _library_crate_name
danakj98e073722022-02-24 21:01:49295
jbudorickd29ecfa72016-11-18 22:45:42296 forward_variables_from(
297 invoker,
298 "*",
Peter Wen2052bd12020-12-03 20:15:07299 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
300 TESTONLY_AND_VISIBILITY)
301
302 # Native targets do not need to depend on java targets. Filter them out
303 # so that the shared library can be built without needing to wait for
304 # dependent java targets.
305 deps = []
306 if (defined(invoker.deps)) {
307 foreach(_dep, invoker.deps) {
308 _target_label = get_label_info(_dep, "label_no_toolchain")
309 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
310 deps += [ _dep ]
311 }
312 }
313 }
agrieve62ab00282016-04-05 02:03:45314
Peter Kotwiczb9957d62021-04-12 21:09:43315 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37316 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45317 }
318 }
319 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54320 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07321 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45322 apk_name = invoker.target_name
323 if (defined(invoker.output_name)) {
324 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45325 install_script_name = "install_${invoker.output_name}"
326 }
agrieveb355ad152016-04-19 03:45:23327
Daniel Bratellfdda4652019-01-31 15:45:54328 if (defined(invoker.deps)) {
329 deps = invoker.deps
330 } else {
331 deps = []
332 }
333
jcivellif4462a352017-01-10 04:45:59334 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43335 if (_use_default_launcher) {
336 deps += [ "//base/test:test_support_java" ]
337 }
jcivellif4462a352017-01-10 04:45:59338
Siddhartha764226b2018-03-13 02:32:55339 if (defined(_unwind_table_asset_name)) {
340 deps += [ ":${_unwind_table_asset_name}" ]
341 }
Greg Guterman50ed4b42021-04-08 01:15:11342
343 if (use_rts) {
344 data_deps = [ ":${invoker.target_name}__rts_filters" ]
345 }
agrieve62ab00282016-04-05 02:03:45346 }
Andrew Grievee1dc23f2019-10-22 16:26:36347 }
agrieve62ab00282016-04-05 02:03:45348
Andrew Grievee1dc23f2019-10-22 16:26:36349 test_runner_script(_test_runner_target) {
350 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57351
Andrew Grievee1dc23f2019-10-22 16:26:36352 if (_use_raw_android_executable) {
353 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34354 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36355 } else {
356 apk_target = ":$_apk_target"
357 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47358
359 # Dep needed for the test runner .runtime_deps file to pick up data
360 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22361 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45362 }
Andrew Grievee1dc23f2019-10-22 16:26:36363 test_name = _output_name
364 test_suite = _output_name
365 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59366
367 if (use_rts) {
368 data_deps += [ ":${invoker.target_name}__rts_filters" ]
369 }
mikecase56d80d72015-06-03 00:57:26370 }
371
Andrew Grieve7ca6de32019-10-18 03:57:47372 # Create a wrapper script rather than using a group() in order to ensure
373 # "ninja $target_name" always works. If this was a group(), then GN would
374 # not create a top-level alias for it if a target exists in another
375 # directory with the same $target_name.
376 # Also - bots run this script directly for "components_perftests".
377 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01378 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47379 executable = "$root_build_dir/bin/run_$_output_name"
380 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22381 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40382 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47383 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40384 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47385 # Dep needed for the swarming .isolate file to pick up data
386 # deps from the forward_variables_from(invoker, "*") on the library.
387 deps += [
388 ":$_apk_target",
389 ":$_library_target",
390 ]
agrieve62ab00282016-04-05 02:03:45391 }
Dirk Pranke19a58732021-03-24 22:26:22392
393 if (defined(invoker.data_deps)) {
394 data_deps = invoker.data_deps
395 } else {
396 data_deps = []
397 }
Kevin Marshall23529362022-02-23 16:50:36398
399 data_deps += [ "//testing:test_scripts_shared" ]
400
Jamie Madilldd60ee62021-04-13 19:25:52401 if (tests_have_location_tags) {
402 data = [ "//testing/location_tags.json" ]
403 }
Greg Guterman6963dc082021-04-07 05:20:59404
405 if (use_rts) {
406 data_deps += [ ":${invoker.target_name}__rts_filters" ]
407 }
agrieve1a02e582015-10-15 21:35:39408 }
Scott Graham4c4cdc52017-05-29 20:45:03409 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30410 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
411
Greg Thompson9765eeb42022-04-05 12:30:35412 # It's meaningless to omit both types of manifest from the package.
413 assert(!defined(invoker.use_cfv2) || invoker.use_cfv2 ||
414 !defined(invoker.use_cfv1) || invoker.use_cfv1)
415
Scott Graham4c4cdc52017-05-29 20:45:03416 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42417 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42418 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb42022-04-05 12:30:35419 _program_name = get_label_info(":${_exec_target}", "name")
420 _test_component_targets = []
Scott Graham4c4cdc52017-05-29 20:45:03421
Greg Thompson9765eeb42022-04-05 12:30:35422 # Generate a CFv2 manifest unless the target opts-out via `use_cfv2=false`.
Greg Thompson5e4f41f2022-02-09 16:35:14423 if (!defined(invoker.use_cfv2) || invoker.use_cfv2) {
Greg Thompson26516592021-12-16 08:34:45424 # Generate a CML fragment that provides the program name.
425 _test_program_fragment_target = "${target_name}_program-fragment"
426 _test_program_fragment =
427 "${target_out_dir}/${target_name}_program.test-cml"
Greg Thompson26516592021-12-16 08:34:45428 generated_file(_test_program_fragment_target) {
429 contents = "{ program: { binary: \"${_program_name}\",},}"
430 outputs = [ _test_program_fragment ]
431 }
432
Greg Thompson318cd692022-03-28 08:12:06433 _test_runner_shard =
434 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
435 if (defined(invoker.test_runner_shard)) {
436 _test_runner_shard = invoker.test_runner_shard
437 }
438
Greg Thompson26516592021-12-16 08:34:45439 # Collate the complete set of elements to include in the test component's
440 # manifest.
441 _manifest_fragments = [
Greg Thompson6cdcdb32022-01-31 11:12:44442 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
Greg Thompsonf31d7d22022-01-26 09:17:45443 "//build/config/fuchsia/test/minimum.shard.test-cml",
Greg Thompson26516592021-12-16 08:34:45444 _test_program_fragment,
Greg Thompson318cd692022-03-28 08:12:06445 _test_runner_shard,
Greg Thompson26516592021-12-16 08:34:45446 ]
447
448 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
449 _merged_manifest_name = "${_output_name}.cml"
Greg Thompson9765eeb42022-04-05 12:30:35450
451 if (defined(invoker.additional_manifest_fragments)) {
452 _manifest_fragments +=
453 filter_include(invoker.additional_manifest_fragments,
454 [
455 "*.cml",
456 "*.test-cml",
457 ])
458 }
459
460 # Generate the test component manifest from the specified elements.
461 _test_component_manifest_target = "${target_name}_component-manifest"
462 cmc_merge(_test_component_manifest_target) {
463 sources = _manifest_fragments
464 output_name = "${_merged_manifest_name}"
465 deps = [ ":${_test_program_fragment_target}" ]
466 }
467
468 # Define the test component, dependent on the generated manifest, and the
469 # test executable target.
470 _test_component_target = "${target_name}_component"
471 fuchsia_component(_test_component_target) {
472 deps = [ ":$_test_component_manifest_target" ]
473 data_deps = [ ":$_exec_target" ]
474 manifest = _test_component_manifest
475 visibility = [ ":*" ]
476 }
477
478 _test_component_targets += [ ":${_test_component_target}" ]
479 }
480
481 # Generate a CFv1 manifest unless the target opts-out via `use_cfv1=false`.
482 if (!defined(invoker.use_cfv1) || invoker.use_cfv1) {
Greg Thompson26516592021-12-16 08:34:45483 # Generate a CMX fragment that provides the program name.
Greg Thompson9765eeb42022-04-05 12:30:35484 _test_program_fragment_target_v1 = "${target_name}_program-fragment_v1"
485 _test_program_fragment_v1 =
Greg Thompson26516592021-12-16 08:34:45486 "${target_out_dir}/${target_name}_program.test-cmx"
Greg Thompson9765eeb42022-04-05 12:30:35487 generated_file(_test_program_fragment_target_v1) {
Greg Thompson26516592021-12-16 08:34:45488 contents = "{ \"program\": { \"binary\": \"${_program_name}\"}}"
Greg Thompson9765eeb42022-04-05 12:30:35489 outputs = [ _test_program_fragment_v1 ]
Greg Thompson26516592021-12-16 08:34:45490 }
491
492 # Collate the complete set of elements to include in the test component's
493 # manifest.
Greg Thompson9765eeb42022-04-05 12:30:35494 _manifest_fragments_v1 = [
Greg Thompson26516592021-12-16 08:34:45495 "//build/config/fuchsia/test/minimum_capabilities.test-cmx",
Greg Thompson9765eeb42022-04-05 12:30:35496 _test_program_fragment_v1,
Greg Thompson26516592021-12-16 08:34:45497 ]
498
Greg Thompson9765eeb42022-04-05 12:30:35499 _test_component_manifest_v1 = "${target_out_dir}/${target_name}.cmx"
500 _merged_manifest_name_v1 = "${_output_name}.cmx"
Chong Gu26908f4e2021-01-29 03:13:07501
Greg Thompson9765eeb42022-04-05 12:30:35502 if (defined(invoker.additional_manifest_fragments)) {
503 _manifest_fragments_v1 +=
504 filter_include(invoker.additional_manifest_fragments,
505 [
506 "*.cmx",
507 "*.test-cmx",
508 ])
509 }
Chong Gu28bf7e72021-05-26 01:36:19510
Greg Thompson9765eeb42022-04-05 12:30:35511 # Generate the test component manifest from the specified elements.
512 _test_component_manifest_target_v1 =
513 "${target_name}_component-manifest_v1"
514 cmc_merge(_test_component_manifest_target_v1) {
515 sources = _manifest_fragments_v1
516 output_name = "${_merged_manifest_name_v1}"
517 deps = [ ":${_test_program_fragment_target_v1}" ]
518 }
Chong Gu26908f4e2021-01-29 03:13:07519
Greg Thompson9765eeb42022-04-05 12:30:35520 # Define the test component, dependent on the generated manifest, and the
521 # test executable target.
522 _test_component_target_v1 = "${target_name}_component_v1"
523 fuchsia_component(_test_component_target_v1) {
524 deps = [ ":$_test_component_manifest_target_v1" ]
525 data_deps = [ ":$_exec_target" ]
526 manifest = _test_component_manifest_v1
527 visibility = [ ":*" ]
528 }
529
530 _test_component_targets += [ ":${_test_component_target_v1}" ]
Wez6879f8a2021-09-07 20:27:02531 }
532
533 # Define components for each entry in |additional_manifests|, if any. Since
534 # manifests may themselves depend-on the outputs of |deps|, these components
535 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02536 if (defined(invoker.additional_manifests)) {
537 foreach(filename, invoker.additional_manifests) {
538 _additional_component_target =
539 target_name + "_" + get_path_info(filename, "name")
540 _test_component_targets += [ ":${_additional_component_target}" ]
541 fuchsia_component(_additional_component_target) {
542 forward_variables_from(invoker, [ "testonly" ])
543 data_deps = [ ":$_exec_target" ]
544 visibility = [ ":*" ]
545 manifest = filename
546
547 # Depend on |invoker.deps|, in case it includes a dependency that
548 # creates this additional component's manifest.
549 if (defined(invoker.deps)) {
550 deps = invoker.deps
551 }
552 }
553 }
554 }
555
556 # Define the package target that will bundle the test and additional
557 # components and their data.
558 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21559 forward_variables_from(invoker,
560 [
561 "excluded_files",
562 "excluded_dirs",
563 ])
Wez6879f8a2021-09-07 20:27:02564 package_name = _output_name
565 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21566
567 if (!defined(excluded_dirs)) {
568 excluded_dirs = []
569 }
570 excluded_dirs += [ devtools_root_location ]
Wez6879f8a2021-09-07 20:27:02571 }
572
573 # |target_name| refers to the package-runner rule, so that building
574 # "base_unittests" will build not only the executable, component, and
575 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25576 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53577 forward_variables_from(invoker,
578 [
Kevin Marshall5fadadd2021-10-16 00:08:25579 "data",
580 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53581 "package_deps",
Greg Thompson26516592021-12-16 08:34:45582 "use_cfv2",
Kevin Marshall5fadadd2021-10-16 00:08:25583 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53584 ])
Kevin Marshall5fadadd2021-10-16 00:08:25585
Chong Guc6bfdf62021-10-20 23:37:00586 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15587 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25588 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42589
Kevin Marshall5fadadd2021-10-16 00:08:25590 if (!defined(deps)) {
591 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52592 }
Kevin Marshall5fadadd2021-10-16 00:08:25593 if (defined(invoker.deps)) {
594 deps += invoker.deps
595 }
Greg Guterman6963dc082021-04-07 05:20:59596
Kevin Marshall5fadadd2021-10-16 00:08:25597 if (!defined(data)) {
598 data = []
599 }
600 if (tests_have_location_tags) {
601 data += [ "//testing/location_tags.json" ]
602 }
603
604 if (!defined(data_deps)) {
605 data_deps = []
606 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28607
Kevin Marshall23529362022-02-23 16:50:36608 data_deps += [ "//testing:test_scripts_shared" ]
609
Benjamin Lerman5e3cb3362022-01-25 16:46:28610 # TODO(crbug.com/1199334): Because perfetto unit test is defined outside
611 # of chromium, the dependency to the filter file is added here.
612 data_deps += [ "//testing/buildbot/filters:perfetto_unittests_filters" ]
Chong Gu258e22c2021-10-20 18:39:50613
Greg Guterman6963dc082021-04-07 05:20:59614 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25615 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59616 }
Kevin Marshallf35fa5f2018-01-29 19:24:42617 }
618
danakjebb9cc4d2022-03-04 21:30:11619 mixed_test(_exec_target) {
620 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01621 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42622 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03623 }
dpranke2a294622015-08-07 05:23:01624 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30625 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46626 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30627
Rohit Raof9b096d2019-09-09 22:26:23628 declare_args() {
629 # Keep the unittest-as-xctest functionality defaulted to off until the
630 # bots are updated to handle it properly.
631 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
632 # supports running unittests with xctest.
633 enable_run_ios_unittests_with_xctest = false
634 }
635
sdefresne012857872016-03-16 10:55:37636 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27637 _output_name = target_name
638 if (defined(invoker.output_name)) {
639 _output_name = invoker.output_name
640 }
641
Jeff Yoonf7f4eb42020-03-06 18:55:36642 _wrapper_output_name = "run_${target_name}"
643 ios_test_runner_wrapper(_wrapper_output_name) {
644 forward_variables_from(invoker,
645 [
646 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36647 "deps",
648 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27649 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36650 "retries",
651 "shards",
652 ])
653
654 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
655
656 if (!defined(executable_args)) {
657 executable_args = []
658 }
659 executable_args += [
660 "--app",
661 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
662 ]
663
664 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22665
666 if (!defined(data)) {
667 data = []
668 }
Jamie Madilldd60ee62021-04-13 19:25:52669 if (tests_have_location_tags) {
670 data += [ "//testing/location_tags.json" ]
671 }
Jeff Yoonf7f4eb42020-03-06 18:55:36672 }
673
sdefresne012857872016-03-16 10:55:37674 _resources_bundle_data = target_name + "_resources_bundle_data"
675
676 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34677 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22678 sources = [ "//testing/gtest_ios/Default.png" ]
679 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01680 }
681
Mirko Bonadei15522bc2020-09-16 20:38:39682 force_xctest = enable_run_ios_unittests_with_xctest ||
683 (defined(invoker.is_xctest) && invoker.is_xctest)
684
685 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23686 ios_test_target_type = "ios_xctest_test"
687 } else {
688 ios_test_target_type = "ios_app_bundle"
689 }
690
691 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01692 testonly = true
sdefresnea828c282016-05-30 18:04:20693
Mirko Bonadei15522bc2020-09-16 20:38:39694 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23695 xctest_module_target = "//base/test:google_test_runner"
696 }
697
Andrew Grieve1b290e4a22020-11-24 20:07:01698 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13699
700 # Provide sensible defaults in case invoker did not define any of those
701 # required variables.
sdefresne05b97ca2016-06-08 07:19:46702 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13703 info_plist = "//testing/gtest_ios/unittest-Info.plist"
704 }
sdefresne9e147e02016-06-07 00:10:13705
Sylvain Defresne3c5a1312021-09-23 17:08:09706 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13707 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50708 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09709 } else {
Ali Juma75be0fe2022-01-24 19:39:29710 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27711 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09712 }
dpranke2a294622015-08-07 05:23:01713
sdefresne047490e2016-07-22 08:49:34714 if (!defined(bundle_deps)) {
715 bundle_deps = []
716 }
717 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36718
719 if (!defined(data_deps)) {
720 data_deps = []
721 }
722
Kevin Marshall23529362022-02-23 16:50:36723 data_deps += [ "//testing:test_scripts_shared" ]
724
Jeff Yoonf7f4eb42020-03-06 18:55:36725 # Include the generate_wrapper as part of data_deps
726 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46727 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59728
729 if (use_rts) {
730 data_deps += [ ":${invoker.target_name}__rts_filters" ]
731 }
dpranke2a294622015-08-07 05:23:01732 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11733 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
734 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30735 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
736
Yuke Liao2a9b2f0e2021-04-16 00:40:11737 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32738
Benjamin Pastene3bce864e2018-04-14 01:16:32739 _gen_runner_target = "${target_name}__runner"
740 _runtime_deps_file =
741 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
742 "/" + get_label_info(target_name, "name") + ".runtime_deps"
743
Xinan Lin6be01252021-06-25 23:07:36744 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
745 if (is_skylab) {
Xinan Lined50edd2022-03-18 17:04:49746 generate_skylab_runner_script(_gen_runner_target) {
Xinan Lin6be01252021-06-25 23:07:36747 generated_script = _generated_script
748 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34749 }
Xinan Lin6be01252021-06-25 23:07:36750 } else {
751 generate_runner_script(_gen_runner_target) {
752 generated_script = _generated_script
753 test_exe = invoker.target_name
754 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34755
Xinan Lin6be01252021-06-25 23:07:36756 if (is_chromeos_lacros) {
757 # At build time, Lacros tests don't know whether they'll run on VM or
758 # HW, and instead, these flags are specified at runtime when invoking
759 # the generated runner script.
760 skip_generating_board_args = true
761 }
Greg Guterman6963dc082021-04-07 05:20:59762
Xinan Lin6be01252021-06-25 23:07:36763 if (tests_have_location_tags) {
764 data = [ "//testing/location_tags.json" ]
765 }
766
767 if (use_rts) {
768 data_deps = [ ":${invoker.target_name}__rts_filters" ]
769 }
Greg Guterman6963dc082021-04-07 05:20:59770 }
Benjamin Pastene3bce864e2018-04-14 01:16:32771 }
772
danakjebb9cc4d2022-03-04 21:30:11773 mixed_test(target_name) {
774 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01775 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
776 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32777 if (!defined(deps)) {
778 deps = []
779 }
780 if (!defined(data)) {
781 data = []
782 }
783
Ben Pastene41041782019-02-16 04:21:58784 # We use a special trigger script for CrOS hardware tests.
785 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
786
Benjamin Pastene3bce864e2018-04-14 01:16:32787 output_name = target_name
788 write_runtime_deps = _runtime_deps_file
789 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37790 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59791
Kevin Marshall23529362022-02-23 16:50:36792 if (!defined(data_deps)) {
793 data_deps = []
794 }
795
796 data_deps += [ "//testing:test_scripts_shared" ]
797
Greg Guterman6963dc082021-04-07 05:20:59798 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59799 data_deps += [ ":${invoker.target_name}__rts_filters" ]
800 }
Benjamin Pastene3bce864e2018-04-14 01:16:32801 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11802 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24803 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
804 _executable = target_name
805 _gen_runner_target = "${target_name}__runner"
806
Yuke Liao32af4242020-07-16 21:48:02807 if (defined(invoker.use_xvfb)) {
808 _use_xvfb = invoker.use_xvfb
809 } else {
810 _use_xvfb = false
811 }
812
Yuke Liaod037abc2020-10-06 22:48:22813 # When use_xvfb is set by the invoker, it indicates that running this test
814 # target requires a window, and in lacros build, ash-chrome serves as the
815 # display server. Note that even though the tests themselves do not require
816 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
817 # because ash-chrome is based on x11.
818 _use_ash_chrome = _use_xvfb
819
Yuke Liaoe703384b2020-07-16 01:05:24820 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24821 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02822
Yuke Liao2e4953cf2020-07-26 19:20:19823 data = []
Will Harrisd35e2c92021-04-07 01:42:02824 data_deps = [ "//testing:test_scripts_shared" ]
825
Yuke Liao32af4242020-07-16 21:48:02826 if (_use_xvfb) {
827 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22828 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02829 } else {
830 executable = "//testing/test_env.py"
831 }
Jamie Madilldd60ee62021-04-13 19:25:52832 if (tests_have_location_tags) {
833 data += [ "//testing/location_tags.json" ]
834 }
Yuke Liao32af4242020-07-16 21:48:02835
Yuke Liaoe703384b2020-07-16 01:05:24836 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02837 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39838 "test",
Yuke Liaoe703384b2020-07-16 01:05:24839 "@WrappedPath(./${_executable})",
840 "--test-launcher-bot-mode",
841 ]
Yuke Liao32af4242020-07-16 21:48:02842
Yuke Liaof540c742020-07-29 16:28:34843 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37844 executable_args += [ "--ash-chrome-path" ]
845
846 # Can't use --ash-chrome-path=path because WrappedPath
847 # won't be expanded for that usage.
848 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39849 }
850
Yuke Liaoe703384b2020-07-16 01:05:24851 if (is_asan) {
852 executable_args += [ "--asan=true" ]
853 }
854 if (is_msan) {
855 executable_args += [ "--msan=true" ]
856 }
857 if (is_tsan) {
858 executable_args += [ "--tsan=true" ]
859 }
860 if (use_cfi_diag) {
861 executable_args += [ "--cfi-diag=true" ]
862 }
863
Takuto Ikuta38ebd0e2022-01-19 17:56:22864 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59865
866 if (use_rts) {
867 data_deps += [ ":${invoker.target_name}__rts_filters" ]
868 }
Yuke Liaoe703384b2020-07-16 01:05:24869 }
870
danakjebb9cc4d2022-03-04 21:30:11871 mixed_test(target_name) {
872 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01873 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
874 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24875 if (!defined(deps)) {
876 deps = []
877 }
878
Yuke Liaod037abc2020-10-06 22:48:22879 if (!defined(data_deps)) {
880 data_deps = []
881 }
882
Kevin Marshall23529362022-02-23 16:50:36883 data_deps += [ "//testing:test_scripts_shared" ]
884
Yuke Liaoe703384b2020-07-16 01:05:24885 write_runtime_deps = _runtime_deps_file
886 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22887 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56888 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22889 }
Greg Guterman6963dc082021-04-07 05:20:59890
891 if (use_rts) {
892 data_deps += [ ":${invoker.target_name}__rts_filters" ]
893 }
Yuke Liaoe703384b2020-07-16 01:05:24894 }
Dirk Prankedd4ff742020-11-18 19:57:32895 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30896 if (is_mac || is_win) {
897 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
898 }
899
Dirk Prankedd4ff742020-11-18 19:57:32900 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
901 _executable = target_name
902 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06903
Dirk Prankedd4ff742020-11-18 19:57:32904 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
905 _use_xvfb = invoker.use_xvfb
906 } else {
907 _use_xvfb = false
908 }
909
910 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32911 wrapper_script = "$root_build_dir/bin/run_" + _executable
912
913 data = []
Will Harrisd35e2c92021-04-07 01:42:02914 data_deps = [ "//testing:test_scripts_shared" ]
915
Dirk Prankedd4ff742020-11-18 19:57:32916 if (_use_xvfb) {
917 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06918 } else {
Dirk Prankedd4ff742020-11-18 19:57:32919 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06920 }
Jamie Madilldd60ee62021-04-13 19:25:52921 if (tests_have_location_tags) {
922 data += [ "//testing/location_tags.json" ]
923 }
Dirk Pranke31e346e2020-07-15 00:54:06924
Dirk Prankedd4ff742020-11-18 19:57:32925 executable_args = [
926 "@WrappedPath(./${_executable})",
927 "--test-launcher-bot-mode",
928 ]
929 if (is_asan) {
930 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06931 }
Dirk Prankedd4ff742020-11-18 19:57:32932 if (is_msan) {
933 executable_args += [ "--msan=true" ]
934 }
935 if (is_tsan) {
936 executable_args += [ "--tsan=true" ]
937 }
938 if (use_cfi_diag) {
939 executable_args += [ "--cfi-diag=true" ]
940 }
941
942 data += [ "//.vpython" ]
Greg Guterman6963dc082021-04-07 05:20:59943
944 if (use_rts) {
945 data_deps += [ ":${invoker.target_name}__rts_filters" ]
946 }
Dirk Pranke31e346e2020-07-15 00:54:06947 }
948
danakjebb9cc4d2022-03-04 21:30:11949 mixed_test(target_name) {
950 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01951 forward_variables_from(invoker,
952 "*",
953 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
954 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06955 if (!defined(deps)) {
956 deps = []
957 }
958
Dirk Pranke31e346e2020-07-15 00:54:06959 deps += [
960 # Give tests the default manifest on Windows (a no-op elsewhere).
961 "//build/win:default_exe_manifest",
962 ]
963
Dirk Prankedd4ff742020-11-18 19:57:32964 write_runtime_deps = _runtime_deps_file
965 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11966
Kevin Marshall23529362022-02-23 16:50:36967 if (!defined(data_deps)) {
968 data_deps = []
969 }
970
971 data_deps += [ "//testing:test_scripts_shared" ]
972
Greg Guterman50ed4b42021-04-08 01:15:11973 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:11974 data_deps += [ ":${invoker.target_name}__rts_filters" ]
975 }
Dirk Prankedd4ff742020-11-18 19:57:32976 }
977 } else {
978 # This is a catch-all clause for NaCl toolchains and other random
979 # configurations that might define tests; test() in these configs
980 # will just define the underlying executables.
981 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
982 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:11983 mixed_test(target_name) {
984 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01985 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
986 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32987 if (!defined(deps)) {
988 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06989 }
Greg Guterman6963dc082021-04-07 05:20:59990
Kevin Marshall23529362022-02-23 16:50:36991 if (!defined(data_deps)) {
992 data_deps = []
993 }
994
995 data_deps += [ "//testing:test_scripts_shared" ]
996
Greg Guterman6963dc082021-04-07 05:20:59997 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59998 data_deps += [ ":${invoker.target_name}__rts_filters" ]
999 }
Dirk Pranke31e346e2020-07-15 00:54:061000 }
qsrfb5251d12015-01-21 15:57:221001 }
1002}
brettwedb6ecc2016-07-14 23:37:031003
Dirk Pranke6188075b2020-10-01 19:31:281004# Defines a type of test that invokes a script to run, rather than
1005# invoking an executable.
1006#
1007# The script must implement the
1008# [test executable API](//docs/testing/test_executable_api.md).
1009#
1010# The template must be passed the `script` parameter, which specifies
1011# the path to the script to run. It may optionally be passed a
1012# `script_args` parameter, which can be used to include a list of
1013# args to be specified by default. The template will produce
1014# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
1015# for the target to $root_build_dir/${target_name}.runtime_deps, as per
1016# the conventions listed in the
1017# [test wrapper API](//docs/testing/test_wrapper_api.md).
1018template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:591019 if (use_rts) {
1020 action("${target_name}__rts_filters") {
1021 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:531022 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:591023 args = [ rebase_path(rts_file, root_build_dir) ]
1024 outputs = [ rts_file ]
1025 }
1026 }
1027
Dirk Pranke6188075b2020-10-01 19:31:281028 generate_wrapper(target_name) {
1029 testonly = true
1030 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1031
1032 executable = "//testing/test_env.py"
1033
1034 executable_args =
1035 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1036 if (defined(invoker.args)) {
1037 executable_args += invoker.args
1038 }
1039
Will Harrisd35e2c92021-04-07 01:42:021040 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471041
Dirk Pranke6188075b2020-10-01 19:31:281042 if (defined(invoker.data)) {
1043 data += invoker.data
1044 }
Jamie Madilldd60ee62021-04-13 19:25:521045 if (tests_have_location_tags) {
1046 data += [ "//testing/location_tags.json" ]
1047 }
Dirk Pranke19a58732021-03-24 22:26:221048
Will Harrisd35e2c92021-04-07 01:42:021049 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281050 if (defined(invoker.data_deps)) {
1051 data_deps += invoker.data_deps
1052 }
1053
1054 forward_variables_from(invoker,
1055 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:011056 TESTONLY_AND_VISIBILITY + [
1057 "data",
1058 "data_deps",
1059 "script",
1060 "script_args",
1061 ])
1062 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281063
1064 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591065
1066 if (use_rts) {
1067 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1068 }
Dirk Pranke6188075b2020-10-01 19:31:281069 }
1070}
1071
brettwedb6ecc2016-07-14 23:37:031072# Test defaults.
1073set_defaults("test") {
1074 if (is_android) {
1075 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411076 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591077 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:031078 } else {
1079 configs = default_executable_configs
Leonard Grey077a28302021-12-16 14:14:261080 if (is_mac) {
1081 # TODO(lgrey): Maybe restore this.
1082 # Don't strip tests for visibility into test crashes/hangs.
1083 # https://bugs.chromium.org/p/chromium/issues/detail?id=1244047#c49
1084 configs -= [ "//build/config/mac:strip_all" ]
1085 }
brettwedb6ecc2016-07-14 23:37:031086 }
1087}