blob: 3331a416171aa87c1bb0cd418e1df4fe46c8485b [file] [log] [blame]
Avi Drissmandfd880852022-09-15 20:11:091# Copyright 2015 The Chromium Authors
qsrc6c612c2015-01-13 22:07:482# 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")
Chong Gu26908f4e2021-01-29 03:13:0746 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Greg Thompson76d83b42022-09-15 14:30:3547 import("//third_party/fuchsia-sdk/sdk/build/component.gni")
48 import("//third_party/fuchsia-sdk/sdk/build/package.gni")
Nico Weberd73c90382022-03-30 20:37:5049} else if (is_chromeos && is_chromeos_device) {
Ben Pastene4c35c572018-04-30 23:21:4850 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3251 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2852 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3253} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3654 import("//build/config/ios/ios_sdk.gni")
55 import("//build/config/ios/ios_test_runner_wrapper.gni")
56 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3257} else {
Dirk Pranke31e346e2020-07-15 00:54:0658 import("//build/config/sanitizers/sanitizers.gni")
59 import("//build/util/generate_wrapper.gni")
60}
61
danakjebb9cc4d2022-03-04 21:30:1162template("mixed_test") {
63 assert(defined(invoker.target_type) && invoker.target_type != "")
64 target("mixed_${invoker.target_type}", target_name) {
65 forward_variables_from(invoker,
66 "*",
67 TESTONLY_AND_VISIBILITY + [ "target_type" ])
68 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
69 if (!defined(rs_configs)) {
70 rs_configs = []
71 }
72 rs_configs += [ "//build/rust:test" ]
73
danakjaa85aad2022-03-10 18:45:1074 # The crate_root is generated and should not be specified.
75 assert(!defined(rs_crate_root))
76 rs_generate_crate_root = true
77
danakjebb9cc4d2022-03-04 21:30:1178 # We could automatically add `rs_deps += [ "//testing/rust_gtest_interop" ]`
79 # if `rs_sources` is non-empty. But we don't automatically provide
80 # //testing/gtest either so it would be asymmetric and could break in that
81 # case. So, we act instead as if //testing/rust_gtest_interop is part of the
82 # //testing/gtest dependency. If you add one, and have `rs_sources` listed,
83 # you get both.
84 _gtest_is_in_deps = false
85 if (defined(rs_sources) && rs_sources != [] && defined(deps) &&
86 deps != []) {
87 foreach(dep, deps) {
88 if (dep == "//testing/gtest") {
89 _gtest_is_in_deps = true
90 }
91 }
92 }
93 if (_gtest_is_in_deps) {
94 if (!defined(rs_deps)) {
95 rs_deps = []
96 }
97 rs_deps += [ "//testing/rust_gtest_interop" ]
98 }
99 }
100}
101
qsrfb5251d12015-01-21 15:57:22102# Define a test as an executable (or apk on Android) with the "testonly" flag
103# set.
agrieve62ab00282016-04-05 02:03:45104# Variable:
Dirk Pranke79d065d2020-08-29 03:28:30105# use_xvfb: (optional) whether to run the executable under Xvfb.
danakj02dddc42022-02-11 23:24:30106# use_raw_android_executable: Use mixed_executable() rather than
107# android_apk().
ynovikov389d9e442016-05-27 02:34:56108# use_native_activity: Test implements ANativeActivity_onCreate().
Greg Thompson26516592021-12-16 08:34:45109# use_cfv2: (Fuchsia, optional): build the test as a framework v2 component;
110# see https://fuchsia.dev/fuchsia-src/concepts/components/v2 for details.
Greg Thompson9765eeb42022-04-05 12:30:35111# The default value is true; set it to false explicitly to omit a .cm
112# manifest from the package.
113# use_cfv1: (Fuchsia, optional): build the test as a framework v1 component.
Greg Thompsonb5c4ff52022-09-21 10:40:31114# The default value is false; set it to true explicitly to include a .cmx
Greg Thompson9765eeb42022-04-05 12:30:35115# manifest from the package.
Greg Thompson318cd692022-03-28 08:12:06116# test_runner_shard: (Fuchsia, optional): for CFv2 tests, use the given test
117# runner shard rather than the default shard for the ELF runner. This is
118# useful, for example, to use the elf_test_ambient_exec_runner for tests
119# that require job_policy_ambient_mark_vmo_exec.
Mirko Bonadei15522bc2020-09-16 20:38:39120# is_xctest: (iOS, optional) whether to build the executable as XCTest.
121# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
122# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:43123# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
124# network requests during the test.
qsrfb5251d12015-01-21 15:57:22125template("test") {
Greg Guterman6963dc082021-04-07 05:20:59126 # Ensures the rts file exists and if not, creates a dummy file
127 if (use_rts) {
128 action("${target_name}__rts_filters") {
129 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53130 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:05131 inverted_rts_file =
132 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
133 args = [
134 rebase_path(rts_file, root_build_dir),
135 rebase_path(inverted_rts_file, root_build_dir),
136 ]
137 outputs = [
138 rts_file,
139 inverted_rts_file,
140 ]
Greg Guterman6963dc082021-04-07 05:20:59141 }
142 }
143
Andrew Grieve1b290e4a22020-11-24 20:07:01144 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:39145 if (!is_ios) {
146 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
147 "is_xctest can be set only for iOS builds")
148 }
Stefano Duo4128b6b2021-08-02 21:24:43149 if (!is_android) {
150 assert(!defined(invoker.allow_cleartext_traffic),
151 "allow_cleartext_traffic can be set only for Android tests")
152 }
153
qsrfb5251d12015-01-21 15:57:22154 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:30155 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
156
Peter Kotwicz10742f82021-04-15 22:32:50157 _use_default_launcher =
158 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
159 if (!defined(invoker.use_raw_android_executable)) {
160 # Checkouts where build_with_chromium == false often have a custom GN
161 # template wrapper around test() which sets use_default_launcher == false.
162 # Set the _use_raw_android_executable default so that test() targets which
163 # do not use the custom wrapper
164 # (1) Do not cause "gn gen" to fail
165 # (2) Do not need to be moved into if(build_with_chromium) block.
166 _use_raw_android_executable =
167 !build_with_chromium && _use_default_launcher
168 } else {
169 not_needed([ "_use_default_launcher" ])
170 _use_raw_android_executable = invoker.use_raw_android_executable
171 }
qsrfb5251d12015-01-21 15:57:22172
agrieve67855de2016-03-30 14:46:01173 # output_name is used to allow targets with the same name but in different
174 # packages to still produce unique runner scripts.
175 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26176 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01177 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26178 }
agrieve62ab00282016-04-05 02:03:45179
agrieveb355ad152016-04-19 03:45:23180 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42181 _wrapper_script_vars = [
Jamie Madill73b9af332022-08-03 19:27:47182 "android_test_runner_script",
agrievee41ae190d2016-04-25 14:12:51183 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42184 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51185 ]
agrieve3ac557f02016-04-12 15:52:00186
jbudorickced2a252016-06-09 16:38:54187 assert(_use_raw_android_executable || enable_java_templates)
188
agrieve62ab00282016-04-05 02:03:45189 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49190 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
191
agrieve62ab00282016-04-05 02:03:45192 _exec_target = "${target_name}__exec"
193 _dist_target = "${target_name}__dist"
194 _exec_output =
195 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
196
danakjebb9cc4d2022-03-04 21:30:11197 mixed_test(_exec_target) {
198 target_type = "executable"
199
danakje94f40d2022-02-16 18:13:53200 # Configs will always be defined since we set_defaults in
201 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45202 configs = []
Dirk Pranke19a58732021-03-24 22:26:22203 forward_variables_from(
204 invoker,
205 "*",
206 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
207 "data_deps",
208 "extra_dist_files",
209 ])
agrieve62ab00282016-04-05 02:03:45210
211 # Thanks to the set_defaults() for test(), configs are initialized with
212 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59213 configs -= [
214 "//build/config:shared_library_config",
215 "//build/config/android:hide_all_but_jni",
216 ]
agrieve62ab00282016-04-05 02:03:45217 configs += [ "//build/config:executable_config" ]
218
Dirk Pranke19a58732021-03-24 22:26:22219 if (defined(invoker.data_deps)) {
220 data_deps = invoker.data_deps
221 } else {
222 data_deps = []
223 }
224 if (!defined(data)) {
225 data = []
226 }
Jamie Madilldd60ee62021-04-13 19:25:52227 if (tests_have_location_tags) {
228 data += [ "//testing/location_tags.json" ]
229 }
Dirk Pranke19a58732021-03-24 22:26:22230
agrieve62ab00282016-04-05 02:03:45231 # Don't output to the root or else conflict with the group() below.
232 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11233
234 if (use_rts) {
235 data_deps += [ ":${invoker.target_name}__rts_filters" ]
236 }
agrieve62ab00282016-04-05 02:03:45237 }
238
239 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45240 dist_dir = "$root_out_dir/$target_name"
241 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22242 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45243 if (defined(invoker.extra_dist_files)) {
244 extra_files = invoker.extra_dist_files
245 }
Greg Guterman50ed4b42021-04-08 01:15:11246
247 if (use_rts) {
248 if (!defined(data_deps)) {
249 data_deps = []
250 }
251 data_deps += [ ":${invoker.target_name}__rts_filters" ]
252 }
agrieve62ab00282016-04-05 02:03:45253 }
254 } else {
Arthur Sonzogni54424e92022-09-23 13:30:45255 _library_target = "${target_name}__library"
danakj98e073722022-02-24 21:01:49256 _library_crate_name = "${target_name}_library"
Arthur Sonzogni54424e92022-09-23 13:30:45257 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45258 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43259 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45260 "android_manifest",
agrievec6811b422016-06-23 02:25:09261 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27262 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55263 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45264 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50265 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07266 "product_config_java_packages",
Andrew Grieve43f24fd02022-04-06 23:04:04267 "loadable_modules",
268 "loadable_module_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02269 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07270 "proguard_configs",
271 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45272 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02273 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45274 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56275 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45276 ]
Siddhartha764226b2018-03-13 02:32:55277
Arthur Sonzogni54424e92022-09-23 13:30:45278 _add_unwind_tables_in_apk = defined(invoker.add_unwind_tables_in_apk) &&
279 invoker.add_unwind_tables_in_apk
Andrew Grieved5fdf2af2022-08-23 07:47:55280
Siddhartha764226b2018-03-13 02:32:55281 # Adds the unwind tables from unstripped binary as an asset file in the
282 # apk, if |add_unwind_tables_in_apk| is specified by the test.
Andrew Grieved5fdf2af2022-08-23 07:47:55283 if (_add_unwind_tables_in_apk) {
Arthur Sonzogni54424e92022-09-23 13:30:45284 if (use_android_unwinder_v2) {
285 _unwind_table_asset_v2_name = "${target_name}_v2_unwind_assets"
286 unwind_table_asset_v2(_unwind_table_asset_v2_name) {
287 library_target = _library_target
288 deps = [ ":$_library_target" ]
289 }
290 }
291
Andrew Grievee9655412022-09-22 18:15:09292 # TODO(crbug.com/1315603): Remove generation of v1 unwind asset when
293 # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroidV2`.
Arthur Sonzogni54424e92022-09-23 13:30:45294 _unwind_table_asset_name = "${target_name}_unwind_assets"
295 unwind_table_asset(_unwind_table_asset_name) {
296 library_target = _library_target
297 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55298 }
299 }
300
Arthur Sonzogni54424e92022-09-23 13:30:45301 mixed_test(_library_target) {
danakjebb9cc4d2022-03-04 21:30:11302 target_type = "shared_library"
303
danakj98e073722022-02-24 21:01:49304 # Configs will always be defined since we set_defaults in
305 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45306 configs = [] # Prevent list overwriting warning.
307 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45308
Andrew Grieved5fdf2af2022-08-23 07:47:55309 if (_add_unwind_tables_in_apk) {
310 # Remove -gz if present, as dump_syms does not support it.
311 # Add and then remove because "-=" removes all, but errors if none are found.
312 configs += [ "//build/config:compress_debug_sections" ]
313 configs -= [ "//build/config:compress_debug_sections" ]
314 }
315
danakjebb9cc4d2022-03-04 21:30:11316 # Use a crate name that avoids creating a warning due to double
317 # underscore (ie. `__`).
danakj98e073722022-02-24 21:01:49318 rs_crate_name = _library_crate_name
danakj98e073722022-02-24 21:01:49319
jbudorickd29ecfa72016-11-18 22:45:42320 forward_variables_from(
321 invoker,
322 "*",
Andrew Grieved5fdf2af2022-08-23 07:47:55323 [
324 "configs",
325 "deps",
326 ] + _apk_specific_vars + _wrapper_script_vars +
Peter Wen2052bd12020-12-03 20:15:07327 TESTONLY_AND_VISIBILITY)
328
329 # Native targets do not need to depend on java targets. Filter them out
330 # so that the shared library can be built without needing to wait for
331 # dependent java targets.
332 deps = []
333 if (defined(invoker.deps)) {
Andrew Grieve841ed072022-08-23 16:42:33334 deps = filter_exclude(invoker.deps, java_target_patterns)
Peter Wen2052bd12020-12-03 20:15:07335 }
agrieve62ab00282016-04-05 02:03:45336
Peter Kotwiczb9957d62021-04-12 21:09:43337 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37338 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45339 }
340 }
Arthur Sonzogni54424e92022-09-23 13:30:45341 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54342 forward_variables_from(invoker, _apk_specific_vars)
Arthur Sonzogni54424e92022-09-23 13:30:45343 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45344 apk_name = invoker.target_name
345 if (defined(invoker.output_name)) {
346 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45347 install_script_name = "install_${invoker.output_name}"
348 }
agrieveb355ad152016-04-19 03:45:23349
Daniel Bratellfdda4652019-01-31 15:45:54350 if (defined(invoker.deps)) {
351 deps = invoker.deps
352 } else {
353 deps = []
354 }
Andrew Grieve43f24fd02022-04-06 23:04:04355 if (defined(loadable_module_deps)) {
356 deps += loadable_module_deps
357 }
Daniel Bratellfdda4652019-01-31 15:45:54358
jcivellif4462a352017-01-10 04:45:59359 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43360 if (_use_default_launcher) {
361 deps += [ "//base/test:test_support_java" ]
362 }
jcivellif4462a352017-01-10 04:45:59363
Siddhartha764226b2018-03-13 02:32:55364 if (defined(_unwind_table_asset_name)) {
365 deps += [ ":${_unwind_table_asset_name}" ]
366 }
Greg Guterman50ed4b42021-04-08 01:15:11367
Arthur Sonzogni54424e92022-09-23 13:30:45368 if (defined(_unwind_table_asset_v2_name)) {
369 deps += [ ":${_unwind_table_asset_v2_name}" ]
370 }
371
Greg Guterman50ed4b42021-04-08 01:15:11372 if (use_rts) {
373 data_deps = [ ":${invoker.target_name}__rts_filters" ]
374 }
agrieve62ab00282016-04-05 02:03:45375 }
Andrew Grievee1dc23f2019-10-22 16:26:36376 }
agrieve62ab00282016-04-05 02:03:45377
Andrew Grievee1dc23f2019-10-22 16:26:36378 test_runner_script(_test_runner_target) {
379 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57380
Andrew Grievee1dc23f2019-10-22 16:26:36381 if (_use_raw_android_executable) {
382 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34383 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36384 } else {
Arthur Sonzogni54424e92022-09-23 13:30:45385 apk_target = ":$_apk_target"
Andrew Grievee1dc23f2019-10-22 16:26:36386 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47387
388 # Dep needed for the test runner .runtime_deps file to pick up data
389 # deps from the forward_variables_from(invoker, "*") on the library.
Arthur Sonzogni54424e92022-09-23 13:30:45390 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45391 }
Andrew Grievee1dc23f2019-10-22 16:26:36392 test_name = _output_name
393 test_suite = _output_name
394 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59395
396 if (use_rts) {
397 data_deps += [ ":${invoker.target_name}__rts_filters" ]
398 }
mikecase56d80d72015-06-03 00:57:26399 }
400
Andrew Grieve7ca6de32019-10-18 03:57:47401 # Create a wrapper script rather than using a group() in order to ensure
402 # "ninja $target_name" always works. If this was a group(), then GN would
403 # not create a top-level alias for it if a target exists in another
404 # directory with the same $target_name.
405 # Also - bots run this script directly for "components_perftests".
406 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01407 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47408 executable = "$root_build_dir/bin/run_$_output_name"
409 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22410 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40411 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47412 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40413 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47414 # Dep needed for the swarming .isolate file to pick up data
415 # deps from the forward_variables_from(invoker, "*") on the library.
416 deps += [
Arthur Sonzogni54424e92022-09-23 13:30:45417 ":$_apk_target",
418 ":$_library_target",
Andrew Grieve7ca6de32019-10-18 03:57:47419 ]
agrieve62ab00282016-04-05 02:03:45420 }
Dirk Pranke19a58732021-03-24 22:26:22421
422 if (defined(invoker.data_deps)) {
423 data_deps = invoker.data_deps
424 } else {
425 data_deps = []
426 }
Kevin Marshall23529362022-02-23 16:50:36427
428 data_deps += [ "//testing:test_scripts_shared" ]
429
Jamie Madilldd60ee62021-04-13 19:25:52430 if (tests_have_location_tags) {
431 data = [ "//testing/location_tags.json" ]
432 }
Greg Guterman6963dc082021-04-07 05:20:59433
434 if (use_rts) {
435 data_deps += [ ":${invoker.target_name}__rts_filters" ]
436 }
agrieve1a02e582015-10-15 21:35:39437 }
Scott Graham4c4cdc52017-05-29 20:45:03438 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30439 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
440
Greg Thompsonb5c4ff52022-09-21 10:40:31441 _use_cfv1 = defined(invoker.use_cfv1) && invoker.use_cfv1 # opt-in
442 _use_cfv2 = !defined(invoker.use_cfv2) || invoker.use_cfv2 # opt-out
443
Greg Thompson9765eeb42022-04-05 12:30:35444 # It's meaningless to omit both types of manifest from the package.
Greg Thompsonb5c4ff52022-09-21 10:40:31445 assert(_use_cfv1 || _use_cfv2)
Greg Thompson9765eeb42022-04-05 12:30:35446
Scott Graham4c4cdc52017-05-29 20:45:03447 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42448 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42449 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb42022-04-05 12:30:35450 _program_name = get_label_info(":${_exec_target}", "name")
451 _test_component_targets = []
Scott Graham4c4cdc52017-05-29 20:45:03452
Greg Thompson9765eeb42022-04-05 12:30:35453 # Generate a CFv2 manifest unless the target opts-out via `use_cfv2=false`.
Greg Thompsonb5c4ff52022-09-21 10:40:31454 if (_use_cfv2) {
Greg Thompson26516592021-12-16 08:34:45455 # Generate a CML fragment that provides the program name.
456 _test_program_fragment_target = "${target_name}_program-fragment"
457 _test_program_fragment =
458 "${target_out_dir}/${target_name}_program.test-cml"
Greg Thompson26516592021-12-16 08:34:45459 generated_file(_test_program_fragment_target) {
Kevin Marshall2ec60032022-05-09 17:38:28460 contents = {
461 program = {
462 binary = _program_name
463 }
464 }
Greg Thompson26516592021-12-16 08:34:45465 outputs = [ _test_program_fragment ]
Kevin Marshall2ec60032022-05-09 17:38:28466 output_conversion = "json"
Greg Thompson26516592021-12-16 08:34:45467 }
468
Greg Thompson318cd692022-03-28 08:12:06469 _test_runner_shard =
470 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
471 if (defined(invoker.test_runner_shard)) {
472 _test_runner_shard = invoker.test_runner_shard
473 }
474
Greg Thompson26516592021-12-16 08:34:45475 # Collate the complete set of elements to include in the test component's
476 # manifest.
477 _manifest_fragments = [
Greg Thompson6cdcdb32022-01-31 11:12:44478 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
Greg Thompsonf31d7d22022-01-26 09:17:45479 "//build/config/fuchsia/test/minimum.shard.test-cml",
Greg Thompson26516592021-12-16 08:34:45480 _test_program_fragment,
Greg Thompson318cd692022-03-28 08:12:06481 _test_runner_shard,
Greg Thompson26516592021-12-16 08:34:45482 ]
483
484 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
485 _merged_manifest_name = "${_output_name}.cml"
Greg Thompson9765eeb42022-04-05 12:30:35486
487 if (defined(invoker.additional_manifest_fragments)) {
488 _manifest_fragments +=
489 filter_include(invoker.additional_manifest_fragments,
490 [
491 "*.cml",
492 "*.test-cml",
493 ])
494 }
495
496 # Generate the test component manifest from the specified elements.
497 _test_component_manifest_target = "${target_name}_component-manifest"
498 cmc_merge(_test_component_manifest_target) {
499 sources = _manifest_fragments
500 output_name = "${_merged_manifest_name}"
501 deps = [ ":${_test_program_fragment_target}" ]
502 }
503
504 # Define the test component, dependent on the generated manifest, and the
505 # test executable target.
506 _test_component_target = "${target_name}_component"
507 fuchsia_component(_test_component_target) {
508 deps = [ ":$_test_component_manifest_target" ]
509 data_deps = [ ":$_exec_target" ]
510 manifest = _test_component_manifest
511 visibility = [ ":*" ]
512 }
513
514 _test_component_targets += [ ":${_test_component_target}" ]
515 }
516
Greg Thompsonb5c4ff52022-09-21 10:40:31517 # Generate a CFv1 manifest if the target opts-in via `use_cfv1=true`.
518 if (_use_cfv1) {
Greg Thompson26516592021-12-16 08:34:45519 # Generate a CMX fragment that provides the program name.
Greg Thompson9765eeb42022-04-05 12:30:35520 _test_program_fragment_target_v1 = "${target_name}_program-fragment_v1"
521 _test_program_fragment_v1 =
Greg Thompson26516592021-12-16 08:34:45522 "${target_out_dir}/${target_name}_program.test-cmx"
Greg Thompson9765eeb42022-04-05 12:30:35523 generated_file(_test_program_fragment_target_v1) {
Greg Thompson26516592021-12-16 08:34:45524 contents = "{ \"program\": { \"binary\": \"${_program_name}\"}}"
Greg Thompson9765eeb42022-04-05 12:30:35525 outputs = [ _test_program_fragment_v1 ]
Greg Thompson26516592021-12-16 08:34:45526 }
527
528 # Collate the complete set of elements to include in the test component's
529 # manifest.
Greg Thompson9765eeb42022-04-05 12:30:35530 _manifest_fragments_v1 = [
Greg Thompson26516592021-12-16 08:34:45531 "//build/config/fuchsia/test/minimum_capabilities.test-cmx",
Greg Thompson9765eeb42022-04-05 12:30:35532 _test_program_fragment_v1,
Greg Thompson26516592021-12-16 08:34:45533 ]
534
Greg Thompson9765eeb42022-04-05 12:30:35535 _test_component_manifest_v1 = "${target_out_dir}/${target_name}.cmx"
536 _merged_manifest_name_v1 = "${_output_name}.cmx"
Chong Gu26908f4e2021-01-29 03:13:07537
Greg Thompson9765eeb42022-04-05 12:30:35538 if (defined(invoker.additional_manifest_fragments)) {
539 _manifest_fragments_v1 +=
540 filter_include(invoker.additional_manifest_fragments,
541 [
542 "*.cmx",
543 "*.test-cmx",
544 ])
545 }
Chong Gu28bf7e72021-05-26 01:36:19546
Greg Thompson9765eeb42022-04-05 12:30:35547 # Generate the test component manifest from the specified elements.
548 _test_component_manifest_target_v1 =
549 "${target_name}_component-manifest_v1"
550 cmc_merge(_test_component_manifest_target_v1) {
551 sources = _manifest_fragments_v1
552 output_name = "${_merged_manifest_name_v1}"
553 deps = [ ":${_test_program_fragment_target_v1}" ]
554 }
Chong Gu26908f4e2021-01-29 03:13:07555
Greg Thompson9765eeb42022-04-05 12:30:35556 # Define the test component, dependent on the generated manifest, and the
557 # test executable target.
558 _test_component_target_v1 = "${target_name}_component_v1"
559 fuchsia_component(_test_component_target_v1) {
560 deps = [ ":$_test_component_manifest_target_v1" ]
561 data_deps = [ ":$_exec_target" ]
562 manifest = _test_component_manifest_v1
563 visibility = [ ":*" ]
564 }
565
566 _test_component_targets += [ ":${_test_component_target_v1}" ]
Wez6879f8a2021-09-07 20:27:02567 }
568
569 # Define components for each entry in |additional_manifests|, if any. Since
570 # manifests may themselves depend-on the outputs of |deps|, these components
571 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02572 if (defined(invoker.additional_manifests)) {
573 foreach(filename, invoker.additional_manifests) {
574 _additional_component_target =
575 target_name + "_" + get_path_info(filename, "name")
576 _test_component_targets += [ ":${_additional_component_target}" ]
577 fuchsia_component(_additional_component_target) {
578 forward_variables_from(invoker, [ "testonly" ])
579 data_deps = [ ":$_exec_target" ]
580 visibility = [ ":*" ]
581 manifest = filename
582
583 # Depend on |invoker.deps|, in case it includes a dependency that
584 # creates this additional component's manifest.
585 if (defined(invoker.deps)) {
586 deps = invoker.deps
587 }
588 }
589 }
590 }
591
592 # Define the package target that will bundle the test and additional
593 # components and their data.
594 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21595 forward_variables_from(invoker,
596 [
597 "excluded_files",
598 "excluded_dirs",
599 ])
Wez6879f8a2021-09-07 20:27:02600 package_name = _output_name
601 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21602
603 if (!defined(excluded_dirs)) {
604 excluded_dirs = []
605 }
Sarah Pham80972efc2022-05-31 17:40:15606 if (devtools_root_location != "") {
607 excluded_dirs += [ devtools_root_location ]
608 }
Wez6879f8a2021-09-07 20:27:02609 }
610
611 # |target_name| refers to the package-runner rule, so that building
612 # "base_unittests" will build not only the executable, component, and
613 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25614 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53615 forward_variables_from(invoker,
616 [
Kevin Marshall5fadadd2021-10-16 00:08:25617 "data",
618 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53619 "package_deps",
Greg Thompson26516592021-12-16 08:34:45620 "use_cfv2",
Kevin Marshall5fadadd2021-10-16 00:08:25621 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53622 ])
Kevin Marshall5fadadd2021-10-16 00:08:25623
Chong Guc6bfdf62021-10-20 23:37:00624 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15625 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25626 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42627
Kevin Marshall5fadadd2021-10-16 00:08:25628 if (!defined(deps)) {
629 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52630 }
Kevin Marshall5fadadd2021-10-16 00:08:25631 if (defined(invoker.deps)) {
632 deps += invoker.deps
633 }
Greg Guterman6963dc082021-04-07 05:20:59634
Kevin Marshall5fadadd2021-10-16 00:08:25635 if (!defined(data)) {
636 data = []
637 }
638 if (tests_have_location_tags) {
639 data += [ "//testing/location_tags.json" ]
640 }
641
642 if (!defined(data_deps)) {
643 data_deps = []
644 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28645
Kevin Marshall23529362022-02-23 16:50:36646 data_deps += [ "//testing:test_scripts_shared" ]
647
Greg Guterman6963dc082021-04-07 05:20:59648 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25649 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59650 }
Kevin Marshallf35fa5f2018-01-29 19:24:42651 }
652
danakjebb9cc4d2022-03-04 21:30:11653 mixed_test(_exec_target) {
654 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01655 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42656 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03657 }
dpranke2a294622015-08-07 05:23:01658 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30659 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46660 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30661
Rohit Raof9b096d2019-09-09 22:26:23662 declare_args() {
663 # Keep the unittest-as-xctest functionality defaulted to off until the
664 # bots are updated to handle it properly.
665 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
666 # supports running unittests with xctest.
667 enable_run_ios_unittests_with_xctest = false
668 }
669
sdefresne012857872016-03-16 10:55:37670 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27671 _output_name = target_name
672 if (defined(invoker.output_name)) {
673 _output_name = invoker.output_name
674 }
675
Jeff Yoonf7f4eb42020-03-06 18:55:36676 _wrapper_output_name = "run_${target_name}"
677 ios_test_runner_wrapper(_wrapper_output_name) {
678 forward_variables_from(invoker,
679 [
680 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36681 "deps",
682 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27683 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36684 "retries",
685 "shards",
686 ])
687
688 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
689
690 if (!defined(executable_args)) {
691 executable_args = []
692 }
693 executable_args += [
694 "--app",
695 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
696 ]
697
698 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22699
700 if (!defined(data)) {
701 data = []
702 }
Jamie Madilldd60ee62021-04-13 19:25:52703 if (tests_have_location_tags) {
704 data += [ "//testing/location_tags.json" ]
705 }
Jeff Yoonf7f4eb42020-03-06 18:55:36706 }
707
sdefresne012857872016-03-16 10:55:37708 _resources_bundle_data = target_name + "_resources_bundle_data"
709
710 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34711 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22712 sources = [ "//testing/gtest_ios/Default.png" ]
713 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01714 }
715
Mirko Bonadei15522bc2020-09-16 20:38:39716 force_xctest = enable_run_ios_unittests_with_xctest ||
717 (defined(invoker.is_xctest) && invoker.is_xctest)
718
719 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23720 ios_test_target_type = "ios_xctest_test"
721 } else {
722 ios_test_target_type = "ios_app_bundle"
723 }
724
725 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01726 testonly = true
sdefresnea828c282016-05-30 18:04:20727
Mirko Bonadei15522bc2020-09-16 20:38:39728 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23729 xctest_module_target = "//base/test:google_test_runner"
730 }
731
Andrew Grieve1b290e4a22020-11-24 20:07:01732 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13733
734 # Provide sensible defaults in case invoker did not define any of those
735 # required variables.
sdefresne05b97ca2016-06-08 07:19:46736 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13737 info_plist = "//testing/gtest_ios/unittest-Info.plist"
738 }
sdefresne9e147e02016-06-07 00:10:13739
Sylvain Defresne3c5a1312021-09-23 17:08:09740 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13741 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50742 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09743 } else {
Ali Juma75be0fe2022-01-24 19:39:29744 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27745 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09746 }
dpranke2a294622015-08-07 05:23:01747
sdefresne047490e2016-07-22 08:49:34748 if (!defined(bundle_deps)) {
749 bundle_deps = []
750 }
751 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36752
753 if (!defined(data_deps)) {
754 data_deps = []
755 }
756
Kevin Marshall23529362022-02-23 16:50:36757 data_deps += [ "//testing:test_scripts_shared" ]
758
Jeff Yoonf7f4eb42020-03-06 18:55:36759 # Include the generate_wrapper as part of data_deps
760 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46761 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59762
763 if (use_rts) {
764 data_deps += [ ":${invoker.target_name}__rts_filters" ]
765 }
dpranke2a294622015-08-07 05:23:01766 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11767 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
768 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30769 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
770
Yuke Liao2a9b2f0e2021-04-16 00:40:11771 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32772
Benjamin Pastene3bce864e2018-04-14 01:16:32773 _gen_runner_target = "${target_name}__runner"
774 _runtime_deps_file =
775 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
776 "/" + get_label_info(target_name, "name") + ".runtime_deps"
777
Xinan Lin6be01252021-06-25 23:07:36778 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
779 if (is_skylab) {
Struan Shrimptonf61293f62022-04-11 19:33:40780 generate_skylab_deps(_gen_runner_target) {
Xinan Lin6be01252021-06-25 23:07:36781 generated_script = _generated_script
782 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34783 }
Xinan Lin6be01252021-06-25 23:07:36784 } else {
785 generate_runner_script(_gen_runner_target) {
786 generated_script = _generated_script
787 test_exe = invoker.target_name
788 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34789
Xinan Lin6be01252021-06-25 23:07:36790 if (is_chromeos_lacros) {
791 # At build time, Lacros tests don't know whether they'll run on VM or
792 # HW, and instead, these flags are specified at runtime when invoking
793 # the generated runner script.
794 skip_generating_board_args = true
795 }
Greg Guterman6963dc082021-04-07 05:20:59796
Xinan Lin6be01252021-06-25 23:07:36797 if (tests_have_location_tags) {
798 data = [ "//testing/location_tags.json" ]
799 }
800
801 if (use_rts) {
802 data_deps = [ ":${invoker.target_name}__rts_filters" ]
803 }
Greg Guterman6963dc082021-04-07 05:20:59804 }
Benjamin Pastene3bce864e2018-04-14 01:16:32805 }
806
danakjebb9cc4d2022-03-04 21:30:11807 mixed_test(target_name) {
808 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01809 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
810 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32811 if (!defined(deps)) {
812 deps = []
813 }
814 if (!defined(data)) {
815 data = []
816 }
817
Ben Pastene41041782019-02-16 04:21:58818 # We use a special trigger script for CrOS hardware tests.
819 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
820
Benjamin Pastene3bce864e2018-04-14 01:16:32821 output_name = target_name
822 write_runtime_deps = _runtime_deps_file
823 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37824 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59825
Kevin Marshall23529362022-02-23 16:50:36826 if (!defined(data_deps)) {
827 data_deps = []
828 }
829
830 data_deps += [ "//testing:test_scripts_shared" ]
831
Greg Guterman6963dc082021-04-07 05:20:59832 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59833 data_deps += [ ":${invoker.target_name}__rts_filters" ]
834 }
Benjamin Pastene3bce864e2018-04-14 01:16:32835 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11836 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24837 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
838 _executable = target_name
839 _gen_runner_target = "${target_name}__runner"
840
Yuke Liao32af4242020-07-16 21:48:02841 if (defined(invoker.use_xvfb)) {
842 _use_xvfb = invoker.use_xvfb
843 } else {
844 _use_xvfb = false
845 }
846
Yuke Liaod037abc2020-10-06 22:48:22847 # When use_xvfb is set by the invoker, it indicates that running this test
848 # target requires a window, and in lacros build, ash-chrome serves as the
849 # display server. Note that even though the tests themselves do not require
850 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
851 # because ash-chrome is based on x11.
852 _use_ash_chrome = _use_xvfb
853
Yuke Liaoe703384b2020-07-16 01:05:24854 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24855 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02856
Yuke Liao2e4953cf2020-07-26 19:20:19857 data = []
Will Harrisd35e2c92021-04-07 01:42:02858 data_deps = [ "//testing:test_scripts_shared" ]
859
Yuke Liao32af4242020-07-16 21:48:02860 if (_use_xvfb) {
861 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22862 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02863 } else {
864 executable = "//testing/test_env.py"
865 }
Jamie Madilldd60ee62021-04-13 19:25:52866 if (tests_have_location_tags) {
867 data += [ "//testing/location_tags.json" ]
868 }
Yuke Liao32af4242020-07-16 21:48:02869
Yuke Liaoe703384b2020-07-16 01:05:24870 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02871 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39872 "test",
Yuke Liaoe703384b2020-07-16 01:05:24873 "@WrappedPath(./${_executable})",
874 "--test-launcher-bot-mode",
875 ]
Yuke Liao32af4242020-07-16 21:48:02876
Yuke Liaof540c742020-07-29 16:28:34877 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37878 executable_args += [ "--ash-chrome-path" ]
879
880 # Can't use --ash-chrome-path=path because WrappedPath
881 # won't be expanded for that usage.
882 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39883 }
884
Yuke Liaoe703384b2020-07-16 01:05:24885 if (is_asan) {
886 executable_args += [ "--asan=true" ]
887 }
888 if (is_msan) {
889 executable_args += [ "--msan=true" ]
890 }
891 if (is_tsan) {
892 executable_args += [ "--tsan=true" ]
893 }
894 if (use_cfi_diag) {
895 executable_args += [ "--cfi-diag=true" ]
896 }
897
Takuto Ikuta38ebd0e2022-01-19 17:56:22898 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59899
900 if (use_rts) {
901 data_deps += [ ":${invoker.target_name}__rts_filters" ]
902 }
Yuke Liaoe703384b2020-07-16 01:05:24903 }
904
danakjebb9cc4d2022-03-04 21:30:11905 mixed_test(target_name) {
906 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01907 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
908 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24909 if (!defined(deps)) {
910 deps = []
911 }
912
Yuke Liaod037abc2020-10-06 22:48:22913 if (!defined(data_deps)) {
914 data_deps = []
915 }
916
Kevin Marshall23529362022-02-23 16:50:36917 data_deps += [ "//testing:test_scripts_shared" ]
918
Yuke Liaoe703384b2020-07-16 01:05:24919 write_runtime_deps = _runtime_deps_file
920 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22921 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56922 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22923 }
Greg Guterman6963dc082021-04-07 05:20:59924
925 if (use_rts) {
926 data_deps += [ ":${invoker.target_name}__rts_filters" ]
927 }
Yuke Liaoe703384b2020-07-16 01:05:24928 }
Dirk Prankedd4ff742020-11-18 19:57:32929 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30930 if (is_mac || is_win) {
931 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
932 }
933
Dirk Prankedd4ff742020-11-18 19:57:32934 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
935 _executable = target_name
936 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06937
Dirk Prankedd4ff742020-11-18 19:57:32938 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
939 _use_xvfb = invoker.use_xvfb
940 } else {
941 _use_xvfb = false
942 }
943
944 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32945 wrapper_script = "$root_build_dir/bin/run_" + _executable
946
947 data = []
Will Harrisd35e2c92021-04-07 01:42:02948 data_deps = [ "//testing:test_scripts_shared" ]
949
Dirk Prankedd4ff742020-11-18 19:57:32950 if (_use_xvfb) {
951 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06952 } else {
Dirk Prankedd4ff742020-11-18 19:57:32953 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06954 }
Jamie Madilldd60ee62021-04-13 19:25:52955 if (tests_have_location_tags) {
956 data += [ "//testing/location_tags.json" ]
957 }
Dirk Pranke31e346e2020-07-15 00:54:06958
Dirk Prankedd4ff742020-11-18 19:57:32959 executable_args = [
960 "@WrappedPath(./${_executable})",
961 "--test-launcher-bot-mode",
962 ]
963 if (is_asan) {
964 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06965 }
Dirk Prankedd4ff742020-11-18 19:57:32966 if (is_msan) {
967 executable_args += [ "--msan=true" ]
968 }
969 if (is_tsan) {
970 executable_args += [ "--tsan=true" ]
971 }
972 if (use_cfi_diag) {
973 executable_args += [ "--cfi-diag=true" ]
974 }
975
Greg Guterman6963dc082021-04-07 05:20:59976 if (use_rts) {
977 data_deps += [ ":${invoker.target_name}__rts_filters" ]
978 }
Dirk Pranke31e346e2020-07-15 00:54:06979 }
980
danakjebb9cc4d2022-03-04 21:30:11981 mixed_test(target_name) {
982 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01983 forward_variables_from(invoker,
984 "*",
985 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
986 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06987 if (!defined(deps)) {
988 deps = []
989 }
990
Dirk Pranke31e346e2020-07-15 00:54:06991 deps += [
992 # Give tests the default manifest on Windows (a no-op elsewhere).
993 "//build/win:default_exe_manifest",
994 ]
995
Dirk Prankedd4ff742020-11-18 19:57:32996 write_runtime_deps = _runtime_deps_file
997 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11998
Kevin Marshall23529362022-02-23 16:50:36999 if (!defined(data_deps)) {
1000 data_deps = []
1001 }
1002
1003 data_deps += [ "//testing:test_scripts_shared" ]
1004
Greg Guterman50ed4b42021-04-08 01:15:111005 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:111006 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1007 }
Dirk Prankedd4ff742020-11-18 19:57:321008 }
1009 } else {
1010 # This is a catch-all clause for NaCl toolchains and other random
1011 # configurations that might define tests; test() in these configs
1012 # will just define the underlying executables.
1013 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
1014 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:111015 mixed_test(target_name) {
1016 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011017 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1018 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:321019 if (!defined(deps)) {
1020 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061021 }
Greg Guterman6963dc082021-04-07 05:20:591022
Kevin Marshall23529362022-02-23 16:50:361023 if (!defined(data_deps)) {
1024 data_deps = []
1025 }
1026
1027 data_deps += [ "//testing:test_scripts_shared" ]
1028
Greg Guterman6963dc082021-04-07 05:20:591029 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:591030 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1031 }
Dirk Pranke31e346e2020-07-15 00:54:061032 }
qsrfb5251d12015-01-21 15:57:221033 }
1034}
brettwedb6ecc2016-07-14 23:37:031035
Dirk Pranke6188075b2020-10-01 19:31:281036# Defines a type of test that invokes a script to run, rather than
1037# invoking an executable.
1038#
1039# The script must implement the
1040# [test executable API](//docs/testing/test_executable_api.md).
1041#
1042# The template must be passed the `script` parameter, which specifies
1043# the path to the script to run. It may optionally be passed a
1044# `script_args` parameter, which can be used to include a list of
1045# args to be specified by default. The template will produce
1046# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
1047# for the target to $root_build_dir/${target_name}.runtime_deps, as per
1048# the conventions listed in the
1049# [test wrapper API](//docs/testing/test_wrapper_api.md).
1050template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:591051 if (use_rts) {
1052 action("${target_name}__rts_filters") {
1053 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:531054 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:051055 inverted_rts_file =
1056 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
1057 args = [
1058 rebase_path(rts_file, root_build_dir),
1059 rebase_path(inverted_rts_file, root_build_dir),
1060 ]
1061 outputs = [
1062 rts_file,
1063 inverted_rts_file,
1064 ]
Greg Guterman6963dc082021-04-07 05:20:591065 }
1066 }
1067
Dirk Pranke6188075b2020-10-01 19:31:281068 generate_wrapper(target_name) {
1069 testonly = true
1070 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1071
1072 executable = "//testing/test_env.py"
1073
1074 executable_args =
1075 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1076 if (defined(invoker.args)) {
1077 executable_args += invoker.args
1078 }
1079
Will Harrisd35e2c92021-04-07 01:42:021080 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471081
Dirk Pranke6188075b2020-10-01 19:31:281082 if (defined(invoker.data)) {
1083 data += invoker.data
1084 }
Jamie Madilldd60ee62021-04-13 19:25:521085 if (tests_have_location_tags) {
1086 data += [ "//testing/location_tags.json" ]
1087 }
Dirk Pranke19a58732021-03-24 22:26:221088
Will Harrisd35e2c92021-04-07 01:42:021089 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281090 if (defined(invoker.data_deps)) {
1091 data_deps += invoker.data_deps
1092 }
1093
1094 forward_variables_from(invoker,
1095 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:011096 TESTONLY_AND_VISIBILITY + [
1097 "data",
1098 "data_deps",
1099 "script",
1100 "script_args",
1101 ])
1102 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281103
1104 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591105
1106 if (use_rts) {
1107 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1108 }
Dirk Pranke6188075b2020-10-01 19:31:281109 }
1110}
1111
brettwedb6ecc2016-07-14 23:37:031112# Test defaults.
1113set_defaults("test") {
1114 if (is_android) {
1115 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411116 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591117 configs += [ "//build/config/android:hide_all_but_jni" ]
Andrew Grieved5fdf2af2022-08-23 07:47:551118
1119 # Compress sections to stay under 4gb hard limit on 32-bit current_cpu.
1120 # https://crbug.com/1354616
1121 if (symbol_level == 2 && !use_debug_fission &&
1122 (current_cpu == "arm" || current_cpu == "x86")) {
1123 configs += [ "//build/config:compress_debug_sections" ]
1124 }
brettwedb6ecc2016-07-14 23:37:031125 } else {
1126 configs = default_executable_configs
1127 }
1128}