blob: c4199b22409b108cf923d882a12fe31c9437b940 [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 {
Andrew Grievee9655412022-09-22 18:15:09255 _library_target_name = "${target_name}__library"
danakj98e073722022-02-24 21:01:49256 _library_crate_name = "${target_name}_library"
Andrew Grievee9655412022-09-22 18:15:09257 _apk_target_name = "${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
Andrew Grievee9655412022-09-22 18:15:09278 _add_unwind_tables_in_apk =
279 defined(invoker.add_unwind_tables_in_apk) &&
280 invoker.add_unwind_tables_in_apk && target_cpu == "arm"
Andrew Grieved5fdf2af2022-08-23 07:47:55281
Siddhartha764226b2018-03-13 02:32:55282 # Adds the unwind tables from unstripped binary as an asset file in the
283 # apk, if |add_unwind_tables_in_apk| is specified by the test.
Andrew Grieved5fdf2af2022-08-23 07:47:55284 if (_add_unwind_tables_in_apk) {
Andrew Grievee9655412022-09-22 18:15:09285 # TODO(crbug.com/1315603): Remove generation of v1 unwind asset when
286 # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroidV2`.
287 _unwind_table_name = "${_library_target_name}_unwind_v1"
288 unwind_table_v1(_unwind_table_name) {
289 library_target = ":$_library_target_name"
290 }
291
Dan Stahr3be6e202022-09-22 15:46:35292 if (use_android_unwinder_v2) {
Andrew Grievee9655412022-09-22 18:15:09293 _unwind_table_v2_name = "${_library_target_name}_unwind_v2"
294 unwind_table_v2(_unwind_table_v2_name) {
295 library_target = ":$_library_target_name"
Dan Stahr3be6e202022-09-22 15:46:35296 }
297 }
298
Andrew Grievee9655412022-09-22 18:15:09299 _unwind_table_asset_name = "${target_name}__unwind_assets"
300 android_assets(_unwind_table_asset_name) {
301 sources = [ "$target_out_dir/$_unwind_table_name/$unwind_table_asset_v1_filename" ]
302 disable_compression = true
303 deps = [ ":$_unwind_table_name" ]
304 if (use_android_unwinder_v2) {
305 sources += [ "$target_out_dir/$_unwind_table_v2_name/$unwind_table_asset_v2_filename" ]
306 deps += [ ":$_unwind_table_v2_name" ]
307 }
Siddhartha764226b2018-03-13 02:32:55308 }
309 }
310
Andrew Grievee9655412022-09-22 18:15:09311 mixed_test(_library_target_name) {
danakjebb9cc4d2022-03-04 21:30:11312 target_type = "shared_library"
313
danakj98e073722022-02-24 21:01:49314 # Configs will always be defined since we set_defaults in
315 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45316 configs = [] # Prevent list overwriting warning.
317 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45318
Andrew Grieved5fdf2af2022-08-23 07:47:55319 if (_add_unwind_tables_in_apk) {
320 # Remove -gz if present, as dump_syms does not support it.
321 # Add and then remove because "-=" removes all, but errors if none are found.
322 configs += [ "//build/config:compress_debug_sections" ]
323 configs -= [ "//build/config:compress_debug_sections" ]
324 }
325
danakjebb9cc4d2022-03-04 21:30:11326 # Use a crate name that avoids creating a warning due to double
327 # underscore (ie. `__`).
danakj98e073722022-02-24 21:01:49328 rs_crate_name = _library_crate_name
danakj98e073722022-02-24 21:01:49329
jbudorickd29ecfa72016-11-18 22:45:42330 forward_variables_from(
331 invoker,
332 "*",
Andrew Grieved5fdf2af2022-08-23 07:47:55333 [
334 "configs",
335 "deps",
336 ] + _apk_specific_vars + _wrapper_script_vars +
Peter Wen2052bd12020-12-03 20:15:07337 TESTONLY_AND_VISIBILITY)
338
339 # Native targets do not need to depend on java targets. Filter them out
340 # so that the shared library can be built without needing to wait for
341 # dependent java targets.
342 deps = []
343 if (defined(invoker.deps)) {
Andrew Grieve841ed072022-08-23 16:42:33344 deps = filter_exclude(invoker.deps, java_target_patterns)
Peter Wen2052bd12020-12-03 20:15:07345 }
agrieve62ab00282016-04-05 02:03:45346
Peter Kotwiczb9957d62021-04-12 21:09:43347 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37348 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45349 }
350 }
Andrew Grievee9655412022-09-22 18:15:09351 unittest_apk(_apk_target_name) {
Daniel Bratellfdda4652019-01-31 15:45:54352 forward_variables_from(invoker, _apk_specific_vars)
Andrew Grievee9655412022-09-22 18:15:09353 shared_library = ":$_library_target_name"
agrieve62ab00282016-04-05 02:03:45354 apk_name = invoker.target_name
355 if (defined(invoker.output_name)) {
356 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45357 install_script_name = "install_${invoker.output_name}"
358 }
agrieveb355ad152016-04-19 03:45:23359
Daniel Bratellfdda4652019-01-31 15:45:54360 if (defined(invoker.deps)) {
361 deps = invoker.deps
362 } else {
363 deps = []
364 }
Andrew Grieve43f24fd02022-04-06 23:04:04365 if (defined(loadable_module_deps)) {
366 deps += loadable_module_deps
367 }
Daniel Bratellfdda4652019-01-31 15:45:54368
jcivellif4462a352017-01-10 04:45:59369 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43370 if (_use_default_launcher) {
371 deps += [ "//base/test:test_support_java" ]
372 }
jcivellif4462a352017-01-10 04:45:59373
Siddhartha764226b2018-03-13 02:32:55374 if (defined(_unwind_table_asset_name)) {
375 deps += [ ":${_unwind_table_asset_name}" ]
376 }
Greg Guterman50ed4b42021-04-08 01:15:11377
378 if (use_rts) {
379 data_deps = [ ":${invoker.target_name}__rts_filters" ]
380 }
agrieve62ab00282016-04-05 02:03:45381 }
Andrew Grievee1dc23f2019-10-22 16:26:36382 }
agrieve62ab00282016-04-05 02:03:45383
Andrew Grievee1dc23f2019-10-22 16:26:36384 test_runner_script(_test_runner_target) {
385 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57386
Andrew Grievee1dc23f2019-10-22 16:26:36387 if (_use_raw_android_executable) {
388 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34389 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36390 } else {
Andrew Grievee9655412022-09-22 18:15:09391 apk_target = ":$_apk_target_name"
Andrew Grievee1dc23f2019-10-22 16:26:36392 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47393
394 # Dep needed for the test runner .runtime_deps file to pick up data
395 # deps from the forward_variables_from(invoker, "*") on the library.
Andrew Grievee9655412022-09-22 18:15:09396 data_deps = [ ":$_library_target_name" ]
agrieve62ab00282016-04-05 02:03:45397 }
Andrew Grievee1dc23f2019-10-22 16:26:36398 test_name = _output_name
399 test_suite = _output_name
400 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59401
402 if (use_rts) {
403 data_deps += [ ":${invoker.target_name}__rts_filters" ]
404 }
mikecase56d80d72015-06-03 00:57:26405 }
406
Andrew Grieve7ca6de32019-10-18 03:57:47407 # Create a wrapper script rather than using a group() in order to ensure
408 # "ninja $target_name" always works. If this was a group(), then GN would
409 # not create a top-level alias for it if a target exists in another
410 # directory with the same $target_name.
411 # Also - bots run this script directly for "components_perftests".
412 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01413 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47414 executable = "$root_build_dir/bin/run_$_output_name"
415 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22416 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40417 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47418 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40419 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47420 # Dep needed for the swarming .isolate file to pick up data
421 # deps from the forward_variables_from(invoker, "*") on the library.
422 deps += [
Andrew Grievee9655412022-09-22 18:15:09423 ":$_apk_target_name",
424 ":$_library_target_name",
Andrew Grieve7ca6de32019-10-18 03:57:47425 ]
agrieve62ab00282016-04-05 02:03:45426 }
Dirk Pranke19a58732021-03-24 22:26:22427
428 if (defined(invoker.data_deps)) {
429 data_deps = invoker.data_deps
430 } else {
431 data_deps = []
432 }
Kevin Marshall23529362022-02-23 16:50:36433
434 data_deps += [ "//testing:test_scripts_shared" ]
435
Jamie Madilldd60ee62021-04-13 19:25:52436 if (tests_have_location_tags) {
437 data = [ "//testing/location_tags.json" ]
438 }
Greg Guterman6963dc082021-04-07 05:20:59439
440 if (use_rts) {
441 data_deps += [ ":${invoker.target_name}__rts_filters" ]
442 }
agrieve1a02e582015-10-15 21:35:39443 }
Scott Graham4c4cdc52017-05-29 20:45:03444 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30445 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
446
Greg Thompsonb5c4ff52022-09-21 10:40:31447 _use_cfv1 = defined(invoker.use_cfv1) && invoker.use_cfv1 # opt-in
448 _use_cfv2 = !defined(invoker.use_cfv2) || invoker.use_cfv2 # opt-out
449
Greg Thompson9765eeb42022-04-05 12:30:35450 # It's meaningless to omit both types of manifest from the package.
Greg Thompsonb5c4ff52022-09-21 10:40:31451 assert(_use_cfv1 || _use_cfv2)
Greg Thompson9765eeb42022-04-05 12:30:35452
Scott Graham4c4cdc52017-05-29 20:45:03453 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42454 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42455 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb42022-04-05 12:30:35456 _program_name = get_label_info(":${_exec_target}", "name")
457 _test_component_targets = []
Scott Graham4c4cdc52017-05-29 20:45:03458
Greg Thompson9765eeb42022-04-05 12:30:35459 # Generate a CFv2 manifest unless the target opts-out via `use_cfv2=false`.
Greg Thompsonb5c4ff52022-09-21 10:40:31460 if (_use_cfv2) {
Greg Thompson26516592021-12-16 08:34:45461 # Generate a CML fragment that provides the program name.
462 _test_program_fragment_target = "${target_name}_program-fragment"
463 _test_program_fragment =
464 "${target_out_dir}/${target_name}_program.test-cml"
Greg Thompson26516592021-12-16 08:34:45465 generated_file(_test_program_fragment_target) {
Kevin Marshall2ec60032022-05-09 17:38:28466 contents = {
467 program = {
468 binary = _program_name
469 }
470 }
Greg Thompson26516592021-12-16 08:34:45471 outputs = [ _test_program_fragment ]
Kevin Marshall2ec60032022-05-09 17:38:28472 output_conversion = "json"
Greg Thompson26516592021-12-16 08:34:45473 }
474
Greg Thompson318cd692022-03-28 08:12:06475 _test_runner_shard =
476 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
477 if (defined(invoker.test_runner_shard)) {
478 _test_runner_shard = invoker.test_runner_shard
479 }
480
Greg Thompson26516592021-12-16 08:34:45481 # Collate the complete set of elements to include in the test component's
482 # manifest.
483 _manifest_fragments = [
Greg Thompson6cdcdb32022-01-31 11:12:44484 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
Greg Thompsonf31d7d22022-01-26 09:17:45485 "//build/config/fuchsia/test/minimum.shard.test-cml",
Greg Thompson26516592021-12-16 08:34:45486 _test_program_fragment,
Greg Thompson318cd692022-03-28 08:12:06487 _test_runner_shard,
Greg Thompson26516592021-12-16 08:34:45488 ]
489
490 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
491 _merged_manifest_name = "${_output_name}.cml"
Greg Thompson9765eeb42022-04-05 12:30:35492
493 if (defined(invoker.additional_manifest_fragments)) {
494 _manifest_fragments +=
495 filter_include(invoker.additional_manifest_fragments,
496 [
497 "*.cml",
498 "*.test-cml",
499 ])
500 }
501
502 # Generate the test component manifest from the specified elements.
503 _test_component_manifest_target = "${target_name}_component-manifest"
504 cmc_merge(_test_component_manifest_target) {
505 sources = _manifest_fragments
506 output_name = "${_merged_manifest_name}"
507 deps = [ ":${_test_program_fragment_target}" ]
508 }
509
510 # Define the test component, dependent on the generated manifest, and the
511 # test executable target.
512 _test_component_target = "${target_name}_component"
513 fuchsia_component(_test_component_target) {
514 deps = [ ":$_test_component_manifest_target" ]
515 data_deps = [ ":$_exec_target" ]
516 manifest = _test_component_manifest
517 visibility = [ ":*" ]
518 }
519
520 _test_component_targets += [ ":${_test_component_target}" ]
521 }
522
Greg Thompsonb5c4ff52022-09-21 10:40:31523 # Generate a CFv1 manifest if the target opts-in via `use_cfv1=true`.
524 if (_use_cfv1) {
Greg Thompson26516592021-12-16 08:34:45525 # Generate a CMX fragment that provides the program name.
Greg Thompson9765eeb42022-04-05 12:30:35526 _test_program_fragment_target_v1 = "${target_name}_program-fragment_v1"
527 _test_program_fragment_v1 =
Greg Thompson26516592021-12-16 08:34:45528 "${target_out_dir}/${target_name}_program.test-cmx"
Greg Thompson9765eeb42022-04-05 12:30:35529 generated_file(_test_program_fragment_target_v1) {
Greg Thompson26516592021-12-16 08:34:45530 contents = "{ \"program\": { \"binary\": \"${_program_name}\"}}"
Greg Thompson9765eeb42022-04-05 12:30:35531 outputs = [ _test_program_fragment_v1 ]
Greg Thompson26516592021-12-16 08:34:45532 }
533
534 # Collate the complete set of elements to include in the test component's
535 # manifest.
Greg Thompson9765eeb42022-04-05 12:30:35536 _manifest_fragments_v1 = [
Greg Thompson26516592021-12-16 08:34:45537 "//build/config/fuchsia/test/minimum_capabilities.test-cmx",
Greg Thompson9765eeb42022-04-05 12:30:35538 _test_program_fragment_v1,
Greg Thompson26516592021-12-16 08:34:45539 ]
540
Greg Thompson9765eeb42022-04-05 12:30:35541 _test_component_manifest_v1 = "${target_out_dir}/${target_name}.cmx"
542 _merged_manifest_name_v1 = "${_output_name}.cmx"
Chong Gu26908f4e2021-01-29 03:13:07543
Greg Thompson9765eeb42022-04-05 12:30:35544 if (defined(invoker.additional_manifest_fragments)) {
545 _manifest_fragments_v1 +=
546 filter_include(invoker.additional_manifest_fragments,
547 [
548 "*.cmx",
549 "*.test-cmx",
550 ])
551 }
Chong Gu28bf7e72021-05-26 01:36:19552
Greg Thompson9765eeb42022-04-05 12:30:35553 # Generate the test component manifest from the specified elements.
554 _test_component_manifest_target_v1 =
555 "${target_name}_component-manifest_v1"
556 cmc_merge(_test_component_manifest_target_v1) {
557 sources = _manifest_fragments_v1
558 output_name = "${_merged_manifest_name_v1}"
559 deps = [ ":${_test_program_fragment_target_v1}" ]
560 }
Chong Gu26908f4e2021-01-29 03:13:07561
Greg Thompson9765eeb42022-04-05 12:30:35562 # Define the test component, dependent on the generated manifest, and the
563 # test executable target.
564 _test_component_target_v1 = "${target_name}_component_v1"
565 fuchsia_component(_test_component_target_v1) {
566 deps = [ ":$_test_component_manifest_target_v1" ]
567 data_deps = [ ":$_exec_target" ]
568 manifest = _test_component_manifest_v1
569 visibility = [ ":*" ]
570 }
571
572 _test_component_targets += [ ":${_test_component_target_v1}" ]
Wez6879f8a2021-09-07 20:27:02573 }
574
575 # Define components for each entry in |additional_manifests|, if any. Since
576 # manifests may themselves depend-on the outputs of |deps|, these components
577 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02578 if (defined(invoker.additional_manifests)) {
579 foreach(filename, invoker.additional_manifests) {
580 _additional_component_target =
581 target_name + "_" + get_path_info(filename, "name")
582 _test_component_targets += [ ":${_additional_component_target}" ]
583 fuchsia_component(_additional_component_target) {
584 forward_variables_from(invoker, [ "testonly" ])
585 data_deps = [ ":$_exec_target" ]
586 visibility = [ ":*" ]
587 manifest = filename
588
589 # Depend on |invoker.deps|, in case it includes a dependency that
590 # creates this additional component's manifest.
591 if (defined(invoker.deps)) {
592 deps = invoker.deps
593 }
594 }
595 }
596 }
597
598 # Define the package target that will bundle the test and additional
599 # components and their data.
600 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21601 forward_variables_from(invoker,
602 [
603 "excluded_files",
604 "excluded_dirs",
605 ])
Wez6879f8a2021-09-07 20:27:02606 package_name = _output_name
607 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21608
609 if (!defined(excluded_dirs)) {
610 excluded_dirs = []
611 }
Sarah Pham80972efc2022-05-31 17:40:15612 if (devtools_root_location != "") {
613 excluded_dirs += [ devtools_root_location ]
614 }
Wez6879f8a2021-09-07 20:27:02615 }
616
617 # |target_name| refers to the package-runner rule, so that building
618 # "base_unittests" will build not only the executable, component, and
619 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25620 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53621 forward_variables_from(invoker,
622 [
Kevin Marshall5fadadd2021-10-16 00:08:25623 "data",
624 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53625 "package_deps",
Greg Thompson26516592021-12-16 08:34:45626 "use_cfv2",
Kevin Marshall5fadadd2021-10-16 00:08:25627 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53628 ])
Kevin Marshall5fadadd2021-10-16 00:08:25629
Chong Guc6bfdf62021-10-20 23:37:00630 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15631 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25632 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42633
Kevin Marshall5fadadd2021-10-16 00:08:25634 if (!defined(deps)) {
635 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52636 }
Kevin Marshall5fadadd2021-10-16 00:08:25637 if (defined(invoker.deps)) {
638 deps += invoker.deps
639 }
Greg Guterman6963dc082021-04-07 05:20:59640
Kevin Marshall5fadadd2021-10-16 00:08:25641 if (!defined(data)) {
642 data = []
643 }
644 if (tests_have_location_tags) {
645 data += [ "//testing/location_tags.json" ]
646 }
647
648 if (!defined(data_deps)) {
649 data_deps = []
650 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28651
Kevin Marshall23529362022-02-23 16:50:36652 data_deps += [ "//testing:test_scripts_shared" ]
653
Greg Guterman6963dc082021-04-07 05:20:59654 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25655 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59656 }
Kevin Marshallf35fa5f2018-01-29 19:24:42657 }
658
danakjebb9cc4d2022-03-04 21:30:11659 mixed_test(_exec_target) {
660 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01661 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42662 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03663 }
dpranke2a294622015-08-07 05:23:01664 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30665 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46666 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30667
Rohit Raof9b096d2019-09-09 22:26:23668 declare_args() {
669 # Keep the unittest-as-xctest functionality defaulted to off until the
670 # bots are updated to handle it properly.
671 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
672 # supports running unittests with xctest.
673 enable_run_ios_unittests_with_xctest = false
674 }
675
sdefresne012857872016-03-16 10:55:37676 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27677 _output_name = target_name
678 if (defined(invoker.output_name)) {
679 _output_name = invoker.output_name
680 }
681
Jeff Yoonf7f4eb42020-03-06 18:55:36682 _wrapper_output_name = "run_${target_name}"
683 ios_test_runner_wrapper(_wrapper_output_name) {
684 forward_variables_from(invoker,
685 [
686 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36687 "deps",
688 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27689 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36690 "retries",
691 "shards",
692 ])
693
694 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
695
696 if (!defined(executable_args)) {
697 executable_args = []
698 }
699 executable_args += [
700 "--app",
701 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
702 ]
703
704 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22705
706 if (!defined(data)) {
707 data = []
708 }
Jamie Madilldd60ee62021-04-13 19:25:52709 if (tests_have_location_tags) {
710 data += [ "//testing/location_tags.json" ]
711 }
Jeff Yoonf7f4eb42020-03-06 18:55:36712 }
713
sdefresne012857872016-03-16 10:55:37714 _resources_bundle_data = target_name + "_resources_bundle_data"
715
716 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34717 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22718 sources = [ "//testing/gtest_ios/Default.png" ]
719 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01720 }
721
Mirko Bonadei15522bc2020-09-16 20:38:39722 force_xctest = enable_run_ios_unittests_with_xctest ||
723 (defined(invoker.is_xctest) && invoker.is_xctest)
724
725 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23726 ios_test_target_type = "ios_xctest_test"
727 } else {
728 ios_test_target_type = "ios_app_bundle"
729 }
730
731 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01732 testonly = true
sdefresnea828c282016-05-30 18:04:20733
Mirko Bonadei15522bc2020-09-16 20:38:39734 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23735 xctest_module_target = "//base/test:google_test_runner"
736 }
737
Andrew Grieve1b290e4a22020-11-24 20:07:01738 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13739
740 # Provide sensible defaults in case invoker did not define any of those
741 # required variables.
sdefresne05b97ca2016-06-08 07:19:46742 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13743 info_plist = "//testing/gtest_ios/unittest-Info.plist"
744 }
sdefresne9e147e02016-06-07 00:10:13745
Sylvain Defresne3c5a1312021-09-23 17:08:09746 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13747 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50748 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09749 } else {
Ali Juma75be0fe2022-01-24 19:39:29750 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27751 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09752 }
dpranke2a294622015-08-07 05:23:01753
sdefresne047490e2016-07-22 08:49:34754 if (!defined(bundle_deps)) {
755 bundle_deps = []
756 }
757 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36758
759 if (!defined(data_deps)) {
760 data_deps = []
761 }
762
Kevin Marshall23529362022-02-23 16:50:36763 data_deps += [ "//testing:test_scripts_shared" ]
764
Jeff Yoonf7f4eb42020-03-06 18:55:36765 # Include the generate_wrapper as part of data_deps
766 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46767 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59768
769 if (use_rts) {
770 data_deps += [ ":${invoker.target_name}__rts_filters" ]
771 }
dpranke2a294622015-08-07 05:23:01772 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11773 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
774 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30775 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
776
Yuke Liao2a9b2f0e2021-04-16 00:40:11777 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32778
Benjamin Pastene3bce864e2018-04-14 01:16:32779 _gen_runner_target = "${target_name}__runner"
780 _runtime_deps_file =
781 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
782 "/" + get_label_info(target_name, "name") + ".runtime_deps"
783
Xinan Lin6be01252021-06-25 23:07:36784 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
785 if (is_skylab) {
Struan Shrimptonf61293f62022-04-11 19:33:40786 generate_skylab_deps(_gen_runner_target) {
Xinan Lin6be01252021-06-25 23:07:36787 generated_script = _generated_script
788 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34789 }
Xinan Lin6be01252021-06-25 23:07:36790 } else {
791 generate_runner_script(_gen_runner_target) {
792 generated_script = _generated_script
793 test_exe = invoker.target_name
794 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34795
Xinan Lin6be01252021-06-25 23:07:36796 if (is_chromeos_lacros) {
797 # At build time, Lacros tests don't know whether they'll run on VM or
798 # HW, and instead, these flags are specified at runtime when invoking
799 # the generated runner script.
800 skip_generating_board_args = true
801 }
Greg Guterman6963dc082021-04-07 05:20:59802
Xinan Lin6be01252021-06-25 23:07:36803 if (tests_have_location_tags) {
804 data = [ "//testing/location_tags.json" ]
805 }
806
807 if (use_rts) {
808 data_deps = [ ":${invoker.target_name}__rts_filters" ]
809 }
Greg Guterman6963dc082021-04-07 05:20:59810 }
Benjamin Pastene3bce864e2018-04-14 01:16:32811 }
812
danakjebb9cc4d2022-03-04 21:30:11813 mixed_test(target_name) {
814 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01815 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
816 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32817 if (!defined(deps)) {
818 deps = []
819 }
820 if (!defined(data)) {
821 data = []
822 }
823
Ben Pastene41041782019-02-16 04:21:58824 # We use a special trigger script for CrOS hardware tests.
825 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
826
Benjamin Pastene3bce864e2018-04-14 01:16:32827 output_name = target_name
828 write_runtime_deps = _runtime_deps_file
829 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37830 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59831
Kevin Marshall23529362022-02-23 16:50:36832 if (!defined(data_deps)) {
833 data_deps = []
834 }
835
836 data_deps += [ "//testing:test_scripts_shared" ]
837
Greg Guterman6963dc082021-04-07 05:20:59838 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59839 data_deps += [ ":${invoker.target_name}__rts_filters" ]
840 }
Benjamin Pastene3bce864e2018-04-14 01:16:32841 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11842 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24843 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
844 _executable = target_name
845 _gen_runner_target = "${target_name}__runner"
846
Yuke Liao32af4242020-07-16 21:48:02847 if (defined(invoker.use_xvfb)) {
848 _use_xvfb = invoker.use_xvfb
849 } else {
850 _use_xvfb = false
851 }
852
Yuke Liaod037abc2020-10-06 22:48:22853 # When use_xvfb is set by the invoker, it indicates that running this test
854 # target requires a window, and in lacros build, ash-chrome serves as the
855 # display server. Note that even though the tests themselves do not require
856 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
857 # because ash-chrome is based on x11.
858 _use_ash_chrome = _use_xvfb
859
Yuke Liaoe703384b2020-07-16 01:05:24860 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24861 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02862
Yuke Liao2e4953cf2020-07-26 19:20:19863 data = []
Will Harrisd35e2c92021-04-07 01:42:02864 data_deps = [ "//testing:test_scripts_shared" ]
865
Yuke Liao32af4242020-07-16 21:48:02866 if (_use_xvfb) {
867 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22868 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02869 } else {
870 executable = "//testing/test_env.py"
871 }
Jamie Madilldd60ee62021-04-13 19:25:52872 if (tests_have_location_tags) {
873 data += [ "//testing/location_tags.json" ]
874 }
Yuke Liao32af4242020-07-16 21:48:02875
Yuke Liaoe703384b2020-07-16 01:05:24876 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02877 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39878 "test",
Yuke Liaoe703384b2020-07-16 01:05:24879 "@WrappedPath(./${_executable})",
880 "--test-launcher-bot-mode",
881 ]
Yuke Liao32af4242020-07-16 21:48:02882
Yuke Liaof540c742020-07-29 16:28:34883 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37884 executable_args += [ "--ash-chrome-path" ]
885
886 # Can't use --ash-chrome-path=path because WrappedPath
887 # won't be expanded for that usage.
888 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39889 }
890
Yuke Liaoe703384b2020-07-16 01:05:24891 if (is_asan) {
892 executable_args += [ "--asan=true" ]
893 }
894 if (is_msan) {
895 executable_args += [ "--msan=true" ]
896 }
897 if (is_tsan) {
898 executable_args += [ "--tsan=true" ]
899 }
900 if (use_cfi_diag) {
901 executable_args += [ "--cfi-diag=true" ]
902 }
903
Takuto Ikuta38ebd0e2022-01-19 17:56:22904 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59905
906 if (use_rts) {
907 data_deps += [ ":${invoker.target_name}__rts_filters" ]
908 }
Yuke Liaoe703384b2020-07-16 01:05:24909 }
910
danakjebb9cc4d2022-03-04 21:30:11911 mixed_test(target_name) {
912 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01913 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
914 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24915 if (!defined(deps)) {
916 deps = []
917 }
918
Yuke Liaod037abc2020-10-06 22:48:22919 if (!defined(data_deps)) {
920 data_deps = []
921 }
922
Kevin Marshall23529362022-02-23 16:50:36923 data_deps += [ "//testing:test_scripts_shared" ]
924
Yuke Liaoe703384b2020-07-16 01:05:24925 write_runtime_deps = _runtime_deps_file
926 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22927 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56928 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22929 }
Greg Guterman6963dc082021-04-07 05:20:59930
931 if (use_rts) {
932 data_deps += [ ":${invoker.target_name}__rts_filters" ]
933 }
Yuke Liaoe703384b2020-07-16 01:05:24934 }
Dirk Prankedd4ff742020-11-18 19:57:32935 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30936 if (is_mac || is_win) {
937 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
938 }
939
Dirk Prankedd4ff742020-11-18 19:57:32940 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
941 _executable = target_name
942 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06943
Dirk Prankedd4ff742020-11-18 19:57:32944 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
945 _use_xvfb = invoker.use_xvfb
946 } else {
947 _use_xvfb = false
948 }
949
950 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32951 wrapper_script = "$root_build_dir/bin/run_" + _executable
952
953 data = []
Will Harrisd35e2c92021-04-07 01:42:02954 data_deps = [ "//testing:test_scripts_shared" ]
955
Dirk Prankedd4ff742020-11-18 19:57:32956 if (_use_xvfb) {
957 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06958 } else {
Dirk Prankedd4ff742020-11-18 19:57:32959 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06960 }
Jamie Madilldd60ee62021-04-13 19:25:52961 if (tests_have_location_tags) {
962 data += [ "//testing/location_tags.json" ]
963 }
Dirk Pranke31e346e2020-07-15 00:54:06964
Dirk Prankedd4ff742020-11-18 19:57:32965 executable_args = [
966 "@WrappedPath(./${_executable})",
967 "--test-launcher-bot-mode",
968 ]
969 if (is_asan) {
970 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06971 }
Dirk Prankedd4ff742020-11-18 19:57:32972 if (is_msan) {
973 executable_args += [ "--msan=true" ]
974 }
975 if (is_tsan) {
976 executable_args += [ "--tsan=true" ]
977 }
978 if (use_cfi_diag) {
979 executable_args += [ "--cfi-diag=true" ]
980 }
981
Greg Guterman6963dc082021-04-07 05:20:59982 if (use_rts) {
983 data_deps += [ ":${invoker.target_name}__rts_filters" ]
984 }
Dirk Pranke31e346e2020-07-15 00:54:06985 }
986
danakjebb9cc4d2022-03-04 21:30:11987 mixed_test(target_name) {
988 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01989 forward_variables_from(invoker,
990 "*",
991 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
992 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06993 if (!defined(deps)) {
994 deps = []
995 }
996
Dirk Pranke31e346e2020-07-15 00:54:06997 deps += [
998 # Give tests the default manifest on Windows (a no-op elsewhere).
999 "//build/win:default_exe_manifest",
1000 ]
1001
Dirk Prankedd4ff742020-11-18 19:57:321002 write_runtime_deps = _runtime_deps_file
1003 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:111004
Kevin Marshall23529362022-02-23 16:50:361005 if (!defined(data_deps)) {
1006 data_deps = []
1007 }
1008
1009 data_deps += [ "//testing:test_scripts_shared" ]
1010
Greg Guterman50ed4b42021-04-08 01:15:111011 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:111012 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1013 }
Dirk Prankedd4ff742020-11-18 19:57:321014 }
1015 } else {
1016 # This is a catch-all clause for NaCl toolchains and other random
1017 # configurations that might define tests; test() in these configs
1018 # will just define the underlying executables.
1019 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
1020 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:111021 mixed_test(target_name) {
1022 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011023 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1024 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:321025 if (!defined(deps)) {
1026 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061027 }
Greg Guterman6963dc082021-04-07 05:20:591028
Kevin Marshall23529362022-02-23 16:50:361029 if (!defined(data_deps)) {
1030 data_deps = []
1031 }
1032
1033 data_deps += [ "//testing:test_scripts_shared" ]
1034
Greg Guterman6963dc082021-04-07 05:20:591035 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:591036 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1037 }
Dirk Pranke31e346e2020-07-15 00:54:061038 }
qsrfb5251d12015-01-21 15:57:221039 }
1040}
brettwedb6ecc2016-07-14 23:37:031041
Dirk Pranke6188075b2020-10-01 19:31:281042# Defines a type of test that invokes a script to run, rather than
1043# invoking an executable.
1044#
1045# The script must implement the
1046# [test executable API](//docs/testing/test_executable_api.md).
1047#
1048# The template must be passed the `script` parameter, which specifies
1049# the path to the script to run. It may optionally be passed a
1050# `script_args` parameter, which can be used to include a list of
1051# args to be specified by default. The template will produce
1052# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
1053# for the target to $root_build_dir/${target_name}.runtime_deps, as per
1054# the conventions listed in the
1055# [test wrapper API](//docs/testing/test_wrapper_api.md).
1056template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:591057 if (use_rts) {
1058 action("${target_name}__rts_filters") {
1059 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:531060 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:051061 inverted_rts_file =
1062 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
1063 args = [
1064 rebase_path(rts_file, root_build_dir),
1065 rebase_path(inverted_rts_file, root_build_dir),
1066 ]
1067 outputs = [
1068 rts_file,
1069 inverted_rts_file,
1070 ]
Greg Guterman6963dc082021-04-07 05:20:591071 }
1072 }
1073
Dirk Pranke6188075b2020-10-01 19:31:281074 generate_wrapper(target_name) {
1075 testonly = true
1076 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1077
1078 executable = "//testing/test_env.py"
1079
1080 executable_args =
1081 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1082 if (defined(invoker.args)) {
1083 executable_args += invoker.args
1084 }
1085
Will Harrisd35e2c92021-04-07 01:42:021086 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471087
Dirk Pranke6188075b2020-10-01 19:31:281088 if (defined(invoker.data)) {
1089 data += invoker.data
1090 }
Jamie Madilldd60ee62021-04-13 19:25:521091 if (tests_have_location_tags) {
1092 data += [ "//testing/location_tags.json" ]
1093 }
Dirk Pranke19a58732021-03-24 22:26:221094
Will Harrisd35e2c92021-04-07 01:42:021095 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281096 if (defined(invoker.data_deps)) {
1097 data_deps += invoker.data_deps
1098 }
1099
1100 forward_variables_from(invoker,
1101 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:011102 TESTONLY_AND_VISIBILITY + [
1103 "data",
1104 "data_deps",
1105 "script",
1106 "script_args",
1107 ])
1108 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281109
1110 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591111
1112 if (use_rts) {
1113 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1114 }
Dirk Pranke6188075b2020-10-01 19:31:281115 }
1116}
1117
brettwedb6ecc2016-07-14 23:37:031118# Test defaults.
1119set_defaults("test") {
1120 if (is_android) {
1121 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411122 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591123 configs += [ "//build/config/android:hide_all_but_jni" ]
Andrew Grieved5fdf2af2022-08-23 07:47:551124
1125 # Compress sections to stay under 4gb hard limit on 32-bit current_cpu.
1126 # https://crbug.com/1354616
1127 if (symbol_level == 2 && !use_debug_fission &&
1128 (current_cpu == "arm" || current_cpu == "x86")) {
1129 configs += [ "//build/config:compress_debug_sections" ]
1130 }
brettwedb6ecc2016-07-14 23:37:031131 } else {
1132 configs = default_executable_configs
1133 }
1134}