blob: cd37d02dcf10fc2925b5bc6fe5b3e0b7d1586bcf [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")
danakj482580a2022-11-18 18:00:5914import("//build/rust/rust_static_library.gni")
Mirko Bonadei4a0df432020-09-08 19:06:0215import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2416
Greg Guterman6963dc082021-04-07 05:20:5917declare_args() {
Dirk Prankeb404c3b2021-06-14 19:57:5018 # Some component repos (e.g. ANGLE) import //testing but do not have
19 # "location_tags.json", and so we don't want to try and upload the tags
20 # for their tests.
21 # And, some build configs may simply turn off generation altogether.
22 tests_have_location_tags = generate_location_tags
Greg Guterman6963dc082021-04-07 05:20:5923}
24
David Dorwin621c5072022-03-30 00:32:5325# On Fuchsia, the test executable has a suffix and is a dependency of the
26# common |target_name| target. For `visibility`, the executable must be
27# specified. Cross-platform targets that include `test` targets in their
28# visibility lists, add `${exec_target_suffix}` immediately after the test
29# target name. This is not necessary when the target is a `source_set`.
30if (is_fuchsia) {
31 exec_target_suffix = "__exec"
32} else {
33 exec_target_suffix = ""
34}
35
jcivellif4462a352017-01-10 04:45:5936if (is_android) {
37 import("//build/config/android/config.gni")
Charlie Hud98dc692021-12-08 01:01:0238 import("//build/config/android/create_unwind_table.gni")
James Cook209256f2018-12-07 18:40:5039 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5940 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4441 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3242} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0643 import("//build/config/chromecast_build.gni")
Kevin Marshall55fd8522019-10-04 22:47:0144 import("//build/config/fuchsia/generate_runner_scripts.gni")
Chong Gu26908f4e2021-01-29 03:13:0745 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Greg Thompson76d83b42022-09-15 14:30:3546 import("//third_party/fuchsia-sdk/sdk/build/component.gni")
47 import("//third_party/fuchsia-sdk/sdk/build/package.gni")
Nico Weberd73c90382022-03-30 20:37:5048} else if (is_chromeos && is_chromeos_device) {
Ben Pastene4c35c572018-04-30 23:21:4849 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3250 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2851 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3252} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3653 import("//build/config/ios/ios_sdk.gni")
54 import("//build/config/ios/ios_test_runner_wrapper.gni")
55 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3256} else {
Dirk Pranke31e346e2020-07-15 00:54:0657 import("//build/config/sanitizers/sanitizers.gni")
58 import("//build/util/generate_wrapper.gni")
59}
60
danakj482580a2022-11-18 18:00:5961# This template generates the test target (of type `target_type`) but also
62# generates a rust library that includes all .rs files found in sources and
63# depends on that from the test target.
danakjebb9cc4d2022-03-04 21:30:1164template("mixed_test") {
65 assert(defined(invoker.target_type) && invoker.target_type != "")
danakjebb9cc4d2022-03-04 21:30:1166
danakj482580a2022-11-18 18:00:5967 _rs_vars = [
68 "sources", # We split this list into two.
69 "crate_name", # Android test template overrides the crate name.
70 ]
danakjaa85aad2022-03-10 18:45:1071
danakj482580a2022-11-18 18:00:5972 if (defined(invoker.sources)) {
73 _rs_sources = filter_include(invoker.sources, [ "*.rs" ])
74 _cc_sources = filter_exclude(invoker.sources, [ "*.rs" ])
75 } else {
76 _rs_sources = []
77 _cc_sources = []
78 }
79
80 if (_rs_sources != []) {
81 _rust_target_name = "${target_name}_rust_objects"
82
83 # We could automatically add `deps += [ "//testing/rust_gtest_interop" ]`
danakjebb9cc4d2022-03-04 21:30:1184 # if `rs_sources` is non-empty. But we don't automatically provide
85 # //testing/gtest either so it would be asymmetric and could break in that
danakj482580a2022-11-18 18:00:5986 # case. So, we act instead as if //testing/rust_gtest_interop is part of
87 # the //testing/gtest dependency. If you add one, and have `rs_sources`
88 # listed, you get both.
danakjebb9cc4d2022-03-04 21:30:1189 _gtest_is_in_deps = false
danakj482580a2022-11-18 18:00:5990 if (defined(invoker.deps) && invoker.deps != []) {
91 foreach(dep, invoker.deps) {
danakjc1f000c2022-11-18 19:31:0692 if (get_label_info(dep, "label_no_toolchain") ==
93 "//testing/gtest:gtest") {
danakjebb9cc4d2022-03-04 21:30:1194 _gtest_is_in_deps = true
95 }
96 }
97 }
danakj482580a2022-11-18 18:00:5998
99 # TODO(danakj): This could be a rust_source_set perhaps, the point being
100 # that we need to link in all the .o object files inside the library,
101 # instead of dropping unreachable ones during linking (which would drop the
102 # tests). Alternatively we could use a special name suffix or other similar
103 # trick perhaps to ensure that all object files are linked in here.
104 rust_static_library(_rust_target_name) {
105 forward_variables_from(invoker,
106 TESTONLY_AND_VISIBILITY + [
107 "crate_name",
108 "deps",
109 "public_deps",
110 ])
111 configs += [ "//build/rust:test" ]
112 generate_crate_root = true
113 sources = _rs_sources
114 if (_gtest_is_in_deps) {
115 deps += [ "//testing/rust_gtest_interop" ]
danakjebb9cc4d2022-03-04 21:30:11116 }
danakj482580a2022-11-18 18:00:59117 }
118 } else {
119 not_needed(invoker, _rs_vars)
120 }
121
122 target(invoker.target_type, target_name) {
123 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY + _rs_vars)
124 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
125 sources = _cc_sources
126 if (!defined(deps)) {
127 deps = []
128 }
129 if (_rs_sources != []) {
130 deps += [ ":${_rust_target_name}" ]
danakjebb9cc4d2022-03-04 21:30:11131 }
132 }
133}
134
qsrfb5251d12015-01-21 15:57:22135# Define a test as an executable (or apk on Android) with the "testonly" flag
136# set.
agrieve62ab00282016-04-05 02:03:45137# Variable:
Dirk Pranke79d065d2020-08-29 03:28:30138# use_xvfb: (optional) whether to run the executable under Xvfb.
danakj482580a2022-11-18 18:00:59139# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:56140# use_native_activity: Test implements ANativeActivity_onCreate().
Greg Thompson318cd692022-03-28 08:12:06141# test_runner_shard: (Fuchsia, optional): for CFv2 tests, use the given test
Greg Thompsonfd269652022-10-28 12:06:55142# runner shard rather than the default shard for the ELF runner when
143# assembling the test component. This is useful, for example, to use the
144# elf_test_ambient_exec_runner for tests that require
145# job_policy_ambient_mark_vmo_exec.
146# fuchsia_package_deps: (Fuchsia, optional) List of fuchsia_component()
147# targets that this test package contains.
Chong Guc2f17c32022-11-15 23:14:45148# # TODO(crbug/1280705): remove when all tests are migrated to CFv2.
149# fuchsia_legacy_script_required: (Fuchsia, optional) Whether the old test
150# scripts are required to run the test target.
Mirko Bonadei15522bc2020-09-16 20:38:39151# is_xctest: (iOS, optional) whether to build the executable as XCTest.
152# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
153# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:43154# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
155# network requests during the test.
qsrfb5251d12015-01-21 15:57:22156template("test") {
Greg Guterman6963dc082021-04-07 05:20:59157 # Ensures the rts file exists and if not, creates a dummy file
158 if (use_rts) {
159 action("${target_name}__rts_filters") {
160 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53161 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:05162 inverted_rts_file =
163 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
164 args = [
165 rebase_path(rts_file, root_build_dir),
166 rebase_path(inverted_rts_file, root_build_dir),
167 ]
168 outputs = [
169 rts_file,
170 inverted_rts_file,
171 ]
Greg Guterman6963dc082021-04-07 05:20:59172 }
173 }
174
Andrew Grieve1b290e4a22020-11-24 20:07:01175 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:39176 if (!is_ios) {
177 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
178 "is_xctest can be set only for iOS builds")
179 }
Stefano Duo4128b6b2021-08-02 21:24:43180 if (!is_android) {
181 assert(!defined(invoker.allow_cleartext_traffic),
182 "allow_cleartext_traffic can be set only for Android tests")
183 }
184
qsrfb5251d12015-01-21 15:57:22185 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:30186 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
187
Peter Kotwicz10742f82021-04-15 22:32:50188 _use_default_launcher =
189 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
190 if (!defined(invoker.use_raw_android_executable)) {
191 # Checkouts where build_with_chromium == false often have a custom GN
192 # template wrapper around test() which sets use_default_launcher == false.
193 # Set the _use_raw_android_executable default so that test() targets which
194 # do not use the custom wrapper
195 # (1) Do not cause "gn gen" to fail
196 # (2) Do not need to be moved into if(build_with_chromium) block.
197 _use_raw_android_executable =
198 !build_with_chromium && _use_default_launcher
199 } else {
200 not_needed([ "_use_default_launcher" ])
201 _use_raw_android_executable = invoker.use_raw_android_executable
202 }
qsrfb5251d12015-01-21 15:57:22203
agrieve67855de2016-03-30 14:46:01204 # output_name is used to allow targets with the same name but in different
205 # packages to still produce unique runner scripts.
206 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26207 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01208 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26209 }
agrieve62ab00282016-04-05 02:03:45210
agrieveb355ad152016-04-19 03:45:23211 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42212 _wrapper_script_vars = [
Jamie Madill73b9af332022-08-03 19:27:47213 "android_test_runner_script",
agrievee41ae190d2016-04-25 14:12:51214 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42215 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51216 ]
agrieve3ac557f02016-04-12 15:52:00217
jbudorickced2a252016-06-09 16:38:54218 assert(_use_raw_android_executable || enable_java_templates)
219
agrieve62ab00282016-04-05 02:03:45220 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49221 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
222
agrieve62ab00282016-04-05 02:03:45223 _exec_target = "${target_name}__exec"
224 _dist_target = "${target_name}__dist"
225 _exec_output =
226 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
227
danakjebb9cc4d2022-03-04 21:30:11228 mixed_test(_exec_target) {
229 target_type = "executable"
230
danakje94f40d2022-02-16 18:13:53231 # Configs will always be defined since we set_defaults in
232 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45233 configs = []
Dirk Pranke19a58732021-03-24 22:26:22234 forward_variables_from(
235 invoker,
236 "*",
237 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
238 "data_deps",
239 "extra_dist_files",
240 ])
agrieve62ab00282016-04-05 02:03:45241
242 # Thanks to the set_defaults() for test(), configs are initialized with
243 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59244 configs -= [
245 "//build/config:shared_library_config",
246 "//build/config/android:hide_all_but_jni",
247 ]
agrieve62ab00282016-04-05 02:03:45248 configs += [ "//build/config:executable_config" ]
249
Dirk Pranke19a58732021-03-24 22:26:22250 if (defined(invoker.data_deps)) {
251 data_deps = invoker.data_deps
252 } else {
253 data_deps = []
254 }
255 if (!defined(data)) {
256 data = []
257 }
Jamie Madilldd60ee62021-04-13 19:25:52258 if (tests_have_location_tags) {
259 data += [ "//testing/location_tags.json" ]
260 }
Dirk Pranke19a58732021-03-24 22:26:22261
agrieve62ab00282016-04-05 02:03:45262 # Don't output to the root or else conflict with the group() below.
263 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11264
265 if (use_rts) {
266 data_deps += [ ":${invoker.target_name}__rts_filters" ]
267 }
agrieve62ab00282016-04-05 02:03:45268 }
269
270 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45271 dist_dir = "$root_out_dir/$target_name"
272 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22273 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45274 if (defined(invoker.extra_dist_files)) {
275 extra_files = invoker.extra_dist_files
276 }
Greg Guterman50ed4b42021-04-08 01:15:11277
278 if (use_rts) {
279 if (!defined(data_deps)) {
280 data_deps = []
281 }
282 data_deps += [ ":${invoker.target_name}__rts_filters" ]
283 }
agrieve62ab00282016-04-05 02:03:45284 }
285 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38286 _library_target_name = "${target_name}__library"
danakj98e073722022-02-24 21:01:49287 _library_crate_name = "${target_name}_library"
Andrew Grieveee8aa44d2022-09-23 17:14:38288 _apk_target_name = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45289 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43290 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45291 "android_manifest",
agrievec6811b422016-06-23 02:25:09292 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27293 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55294 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45295 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50296 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07297 "product_config_java_packages",
Andrew Grieve43f24fd02022-04-06 23:04:04298 "loadable_modules",
299 "loadable_module_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02300 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07301 "proguard_configs",
302 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45303 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02304 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45305 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56306 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45307 ]
Siddhartha764226b2018-03-13 02:32:55308
Andrew Grieveee8aa44d2022-09-23 17:14:38309 _add_unwind_tables_in_apk =
310 defined(invoker.add_unwind_tables_in_apk) &&
311 invoker.add_unwind_tables_in_apk && target_cpu == "arm"
Andrew Grieved5fdf2af2022-08-23 07:47:55312
Siddhartha764226b2018-03-13 02:32:55313 # Adds the unwind tables from unstripped binary as an asset file in the
314 # apk, if |add_unwind_tables_in_apk| is specified by the test.
Andrew Grieved5fdf2af2022-08-23 07:47:55315 if (_add_unwind_tables_in_apk) {
Andrew Grieveee8aa44d2022-09-23 17:14:38316 # TODO(crbug.com/1315603): Remove generation of v1 unwind asset when
317 # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroidV2`.
318 _unwind_table_name = "${_library_target_name}_unwind_v1"
319 unwind_table_v1(_unwind_table_name) {
320 library_target = ":$_library_target_name"
321 }
322
Arthur Sonzogni54424e92022-09-23 13:30:45323 if (use_android_unwinder_v2) {
Andrew Grieveee8aa44d2022-09-23 17:14:38324 _unwind_table_v2_name = "${_library_target_name}_unwind_v2"
325 unwind_table_v2(_unwind_table_v2_name) {
326 library_target = ":$_library_target_name"
Arthur Sonzogni54424e92022-09-23 13:30:45327 }
328 }
329
Andrew Grieveee8aa44d2022-09-23 17:14:38330 _unwind_table_asset_name = "${target_name}__unwind_assets"
331 android_assets(_unwind_table_asset_name) {
332 sources = [ "$target_out_dir/$_unwind_table_name/$unwind_table_asset_v1_filename" ]
333 disable_compression = true
334 deps = [ ":$_unwind_table_name" ]
335 if (use_android_unwinder_v2) {
336 sources += [ "$target_out_dir/$_unwind_table_v2_name/$unwind_table_asset_v2_filename" ]
337 deps += [ ":$_unwind_table_v2_name" ]
338 }
Siddhartha764226b2018-03-13 02:32:55339 }
340 }
341
Andrew Grieveee8aa44d2022-09-23 17:14:38342 mixed_test(_library_target_name) {
danakjebb9cc4d2022-03-04 21:30:11343 target_type = "shared_library"
344
danakj98e073722022-02-24 21:01:49345 # Configs will always be defined since we set_defaults in
346 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45347 configs = [] # Prevent list overwriting warning.
348 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45349
Andrew Grieved5fdf2af2022-08-23 07:47:55350 if (_add_unwind_tables_in_apk) {
351 # Remove -gz if present, as dump_syms does not support it.
352 # Add and then remove because "-=" removes all, but errors if none are found.
353 configs += [ "//build/config:compress_debug_sections" ]
354 configs -= [ "//build/config:compress_debug_sections" ]
355 }
356
jbudorickd29ecfa72016-11-18 22:45:42357 forward_variables_from(
358 invoker,
359 "*",
Andrew Grieved5fdf2af2022-08-23 07:47:55360 [
361 "configs",
362 "deps",
363 ] + _apk_specific_vars + _wrapper_script_vars +
Peter Wen2052bd12020-12-03 20:15:07364 TESTONLY_AND_VISIBILITY)
365
danakj482580a2022-11-18 18:00:59366 # Use a crate name that avoids creating a warning due to double
367 # underscore (ie. `__`).
368 crate_name = _library_crate_name
369
Peter Wen2052bd12020-12-03 20:15:07370 # Native targets do not need to depend on java targets. Filter them out
371 # so that the shared library can be built without needing to wait for
372 # dependent java targets.
373 deps = []
374 if (defined(invoker.deps)) {
Andrew Grieve841ed072022-08-23 16:42:33375 deps = filter_exclude(invoker.deps, java_target_patterns)
Peter Wen2052bd12020-12-03 20:15:07376 }
agrieve62ab00282016-04-05 02:03:45377
Peter Kotwiczb9957d62021-04-12 21:09:43378 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37379 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45380 }
381 }
Andrew Grieveee8aa44d2022-09-23 17:14:38382 unittest_apk(_apk_target_name) {
Daniel Bratellfdda4652019-01-31 15:45:54383 forward_variables_from(invoker, _apk_specific_vars)
Andrew Grieveee8aa44d2022-09-23 17:14:38384 shared_library = ":$_library_target_name"
agrieve62ab00282016-04-05 02:03:45385 apk_name = invoker.target_name
386 if (defined(invoker.output_name)) {
387 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45388 install_script_name = "install_${invoker.output_name}"
389 }
agrieveb355ad152016-04-19 03:45:23390
Daniel Bratellfdda4652019-01-31 15:45:54391 if (defined(invoker.deps)) {
392 deps = invoker.deps
393 } else {
394 deps = []
395 }
Andrew Grieve43f24fd02022-04-06 23:04:04396 if (defined(loadable_module_deps)) {
397 deps += loadable_module_deps
398 }
Daniel Bratellfdda4652019-01-31 15:45:54399
jcivellif4462a352017-01-10 04:45:59400 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43401 if (_use_default_launcher) {
402 deps += [ "//base/test:test_support_java" ]
403 }
jcivellif4462a352017-01-10 04:45:59404
Siddhartha764226b2018-03-13 02:32:55405 if (defined(_unwind_table_asset_name)) {
406 deps += [ ":${_unwind_table_asset_name}" ]
407 }
Greg Guterman50ed4b42021-04-08 01:15:11408
409 if (use_rts) {
410 data_deps = [ ":${invoker.target_name}__rts_filters" ]
411 }
agrieve62ab00282016-04-05 02:03:45412 }
Andrew Grievee1dc23f2019-10-22 16:26:36413 }
agrieve62ab00282016-04-05 02:03:45414
Andrew Grievee1dc23f2019-10-22 16:26:36415 test_runner_script(_test_runner_target) {
416 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57417
Andrew Grievee1dc23f2019-10-22 16:26:36418 if (_use_raw_android_executable) {
419 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34420 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36421 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38422 apk_target = ":$_apk_target_name"
Andrew Grievee1dc23f2019-10-22 16:26:36423 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47424
425 # Dep needed for the test runner .runtime_deps file to pick up data
426 # deps from the forward_variables_from(invoker, "*") on the library.
Andrew Grieveee8aa44d2022-09-23 17:14:38427 data_deps = [ ":$_library_target_name" ]
agrieve62ab00282016-04-05 02:03:45428 }
Andrew Grievee1dc23f2019-10-22 16:26:36429 test_name = _output_name
430 test_suite = _output_name
431 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59432
433 if (use_rts) {
434 data_deps += [ ":${invoker.target_name}__rts_filters" ]
435 }
mikecase56d80d72015-06-03 00:57:26436 }
437
Andrew Grieve7ca6de32019-10-18 03:57:47438 # Create a wrapper script rather than using a group() in order to ensure
439 # "ninja $target_name" always works. If this was a group(), then GN would
440 # not create a top-level alias for it if a target exists in another
441 # directory with the same $target_name.
442 # Also - bots run this script directly for "components_perftests".
443 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01444 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47445 executable = "$root_build_dir/bin/run_$_output_name"
446 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22447 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40448 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47449 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40450 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47451 # Dep needed for the swarming .isolate file to pick up data
452 # deps from the forward_variables_from(invoker, "*") on the library.
453 deps += [
Andrew Grieveee8aa44d2022-09-23 17:14:38454 ":$_apk_target_name",
455 ":$_library_target_name",
Andrew Grieve7ca6de32019-10-18 03:57:47456 ]
agrieve62ab00282016-04-05 02:03:45457 }
Dirk Pranke19a58732021-03-24 22:26:22458
459 if (defined(invoker.data_deps)) {
460 data_deps = invoker.data_deps
461 } else {
462 data_deps = []
463 }
Kevin Marshall23529362022-02-23 16:50:36464
465 data_deps += [ "//testing:test_scripts_shared" ]
466
Jamie Madilldd60ee62021-04-13 19:25:52467 if (tests_have_location_tags) {
468 data = [ "//testing/location_tags.json" ]
469 }
Greg Guterman6963dc082021-04-07 05:20:59470
471 if (use_rts) {
472 data_deps += [ ":${invoker.target_name}__rts_filters" ]
473 }
agrieve1a02e582015-10-15 21:35:39474 }
Scott Graham4c4cdc52017-05-29 20:45:03475 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30476 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
477
Scott Graham4c4cdc52017-05-29 20:45:03478 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42479 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42480 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb42022-04-05 12:30:35481 _program_name = get_label_info(":${_exec_target}", "name")
Scott Graham4c4cdc52017-05-29 20:45:03482
Greg Thompson2f1e3762022-10-17 19:53:44483 # Generate a CML fragment that provides the program name.
484 _test_program_fragment_target = "${target_name}_program-fragment"
485 _test_program_fragment = "${target_out_dir}/${target_name}_program.test-cml"
486 generated_file(_test_program_fragment_target) {
487 contents = {
488 program = {
489 binary = _program_name
Kevin Marshall2ec60032022-05-09 17:38:28490 }
Greg Thompson26516592021-12-16 08:34:45491 }
Greg Thompson2f1e3762022-10-17 19:53:44492 outputs = [ _test_program_fragment ]
493 output_conversion = "json"
Greg Thompson9765eeb42022-04-05 12:30:35494 }
495
Chong Guc2f17c32022-11-15 23:14:45496 use_v2_script = use_v2_script_default
Chong Gu3c6fe122022-11-16 08:15:19497 if (target_cpu == "x64") {
498 use_v2_script = false
499 }
Chong Guc2f17c32022-11-15 23:14:45500 if (defined(invoker.fuchsia_legacy_script_required) &&
501 invoker.fuchsia_legacy_script_required) {
502 use_v2_script = false
503 }
504
Greg Thompson2f1e3762022-10-17 19:53:44505 _test_runner_shard =
506 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
507 if (defined(invoker.test_runner_shard)) {
508 _test_runner_shard = invoker.test_runner_shard
Wez6879f8a2021-09-07 20:27:02509 }
510
Greg Thompson2f1e3762022-10-17 19:53:44511 # Collate the complete set of elements to include in the test component's
512 # manifest.
513 _manifest_fragments = [
514 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
515 "//build/config/fuchsia/test/minimum.shard.test-cml",
516 _test_program_fragment,
517 _test_runner_shard,
518 ]
519
520 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
521 _merged_manifest_name = "${_output_name}.cml"
522
523 if (defined(invoker.additional_manifest_fragments)) {
524 _manifest_fragments += invoker.additional_manifest_fragments
525 }
526
527 # Generate the test component manifest from the specified elements.
528 _test_component_manifest_target = "${target_name}_component-manifest"
529 cmc_merge(_test_component_manifest_target) {
530 sources = _manifest_fragments
531 output_name = "${_merged_manifest_name}"
532 deps = [ ":${_test_program_fragment_target}" ]
533 }
534
535 # Define the test component, dependent on the generated manifest, and the
536 # test executable target.
537 _test_component_target = "${target_name}_component"
538 fuchsia_component(_test_component_target) {
539 deps = [ ":$_test_component_manifest_target" ]
540 data_deps = [ ":$_exec_target" ]
541 manifest = _test_component_manifest
542 visibility = [ ":*" ]
543 }
544
545 _test_component_targets = [ ":${_test_component_target}" ]
546
Wez6879f8a2021-09-07 20:27:02547 # Define components for each entry in |additional_manifests|, if any. Since
548 # manifests may themselves depend-on the outputs of |deps|, these components
549 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02550 if (defined(invoker.additional_manifests)) {
551 foreach(filename, invoker.additional_manifests) {
552 _additional_component_target =
553 target_name + "_" + get_path_info(filename, "name")
554 _test_component_targets += [ ":${_additional_component_target}" ]
555 fuchsia_component(_additional_component_target) {
556 forward_variables_from(invoker, [ "testonly" ])
557 data_deps = [ ":$_exec_target" ]
558 visibility = [ ":*" ]
559 manifest = filename
560
561 # Depend on |invoker.deps|, in case it includes a dependency that
562 # creates this additional component's manifest.
563 if (defined(invoker.deps)) {
564 deps = invoker.deps
565 }
566 }
567 }
568 }
569
570 # Define the package target that will bundle the test and additional
571 # components and their data.
572 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21573 forward_variables_from(invoker,
574 [
575 "excluded_files",
576 "excluded_dirs",
577 ])
Wez6879f8a2021-09-07 20:27:02578 package_name = _output_name
579 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21580
Greg Thompsonfd269652022-10-28 12:06:55581 if (defined(invoker.fuchsia_package_deps)) {
582 deps += invoker.fuchsia_package_deps
583 }
Kevin Marshall36c602c2021-11-04 16:16:21584 if (!defined(excluded_dirs)) {
585 excluded_dirs = []
586 }
Sarah Pham80972efc2022-05-31 17:40:15587 if (devtools_root_location != "") {
588 excluded_dirs += [ devtools_root_location ]
589 }
Wez6879f8a2021-09-07 20:27:02590 }
591
592 # |target_name| refers to the package-runner rule, so that building
593 # "base_unittests" will build not only the executable, component, and
594 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25595 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53596 forward_variables_from(invoker,
597 [
Kevin Marshall5fadadd2021-10-16 00:08:25598 "data",
599 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53600 "package_deps",
Kevin Marshall5fadadd2021-10-16 00:08:25601 "use_test_server",
Chong Guc2f17c32022-11-15 23:14:45602 "use_v2_script",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53603 ])
Kevin Marshall5fadadd2021-10-16 00:08:25604
Chong Guc6bfdf62021-10-20 23:37:00605 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15606 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25607 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42608
Kevin Marshall5fadadd2021-10-16 00:08:25609 if (!defined(deps)) {
610 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52611 }
Kevin Marshall5fadadd2021-10-16 00:08:25612 if (defined(invoker.deps)) {
613 deps += invoker.deps
614 }
Greg Guterman6963dc082021-04-07 05:20:59615
Kevin Marshall5fadadd2021-10-16 00:08:25616 if (!defined(data)) {
617 data = []
618 }
619 if (tests_have_location_tags) {
620 data += [ "//testing/location_tags.json" ]
621 }
622
623 if (!defined(data_deps)) {
624 data_deps = []
625 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28626
Kevin Marshall23529362022-02-23 16:50:36627 data_deps += [ "//testing:test_scripts_shared" ]
628
Greg Guterman6963dc082021-04-07 05:20:59629 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25630 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59631 }
Kevin Marshallf35fa5f2018-01-29 19:24:42632 }
633
danakjebb9cc4d2022-03-04 21:30:11634 mixed_test(_exec_target) {
635 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01636 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42637 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03638 }
dpranke2a294622015-08-07 05:23:01639 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30640 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46641 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30642
Rohit Raof9b096d2019-09-09 22:26:23643 declare_args() {
644 # Keep the unittest-as-xctest functionality defaulted to off until the
645 # bots are updated to handle it properly.
646 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
647 # supports running unittests with xctest.
648 enable_run_ios_unittests_with_xctest = false
649 }
650
sdefresne012857872016-03-16 10:55:37651 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27652 _output_name = target_name
653 if (defined(invoker.output_name)) {
654 _output_name = invoker.output_name
655 }
656
Jeff Yoonf7f4eb42020-03-06 18:55:36657 _wrapper_output_name = "run_${target_name}"
658 ios_test_runner_wrapper(_wrapper_output_name) {
659 forward_variables_from(invoker,
660 [
661 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36662 "deps",
663 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27664 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36665 "retries",
666 "shards",
667 ])
668
669 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
670
671 if (!defined(executable_args)) {
672 executable_args = []
673 }
674 executable_args += [
675 "--app",
676 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
677 ]
678
679 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22680
681 if (!defined(data)) {
682 data = []
683 }
Jamie Madilldd60ee62021-04-13 19:25:52684 if (tests_have_location_tags) {
685 data += [ "//testing/location_tags.json" ]
686 }
Jeff Yoonf7f4eb42020-03-06 18:55:36687 }
688
sdefresne012857872016-03-16 10:55:37689 _resources_bundle_data = target_name + "_resources_bundle_data"
690
691 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34692 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22693 sources = [ "//testing/gtest_ios/Default.png" ]
694 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01695 }
696
Mirko Bonadei15522bc2020-09-16 20:38:39697 force_xctest = enable_run_ios_unittests_with_xctest ||
698 (defined(invoker.is_xctest) && invoker.is_xctest)
699
danakjfae603fc602022-11-18 18:40:22700 mixed_test(_test_target) {
701 if (force_xctest) {
702 target_type = "ios_xctest_test"
703 } else {
704 target_type = "ios_app_bundle"
705 }
dpranke2a294622015-08-07 05:23:01706 testonly = true
sdefresnea828c282016-05-30 18:04:20707
Mirko Bonadei15522bc2020-09-16 20:38:39708 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23709 xctest_module_target = "//base/test:google_test_runner"
710 }
711
Andrew Grieve1b290e4a22020-11-24 20:07:01712 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13713
714 # Provide sensible defaults in case invoker did not define any of those
715 # required variables.
sdefresne05b97ca2016-06-08 07:19:46716 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13717 info_plist = "//testing/gtest_ios/unittest-Info.plist"
718 }
sdefresne9e147e02016-06-07 00:10:13719
Sylvain Defresne3c5a1312021-09-23 17:08:09720 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13721 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50722 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09723 } else {
Ali Juma75be0fe2022-01-24 19:39:29724 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27725 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09726 }
dpranke2a294622015-08-07 05:23:01727
sdefresne047490e2016-07-22 08:49:34728 if (!defined(bundle_deps)) {
729 bundle_deps = []
730 }
731 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36732
733 if (!defined(data_deps)) {
734 data_deps = []
735 }
736
Kevin Marshall23529362022-02-23 16:50:36737 data_deps += [ "//testing:test_scripts_shared" ]
738
Jeff Yoonf7f4eb42020-03-06 18:55:36739 # Include the generate_wrapper as part of data_deps
740 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46741 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59742
743 if (use_rts) {
744 data_deps += [ ":${invoker.target_name}__rts_filters" ]
745 }
dpranke2a294622015-08-07 05:23:01746 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11747 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
748 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30749 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
750
Yuke Liao2a9b2f0e2021-04-16 00:40:11751 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32752
Benjamin Pastene3bce864e2018-04-14 01:16:32753 _gen_runner_target = "${target_name}__runner"
754 _runtime_deps_file =
755 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
756 "/" + get_label_info(target_name, "name") + ".runtime_deps"
757
Xinan Lin6be01252021-06-25 23:07:36758 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
759 if (is_skylab) {
Struan Shrimptonf61293f62022-04-11 19:33:40760 generate_skylab_deps(_gen_runner_target) {
Xinan Lin6be01252021-06-25 23:07:36761 generated_script = _generated_script
762 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34763 }
Xinan Lin6be01252021-06-25 23:07:36764 } else {
765 generate_runner_script(_gen_runner_target) {
766 generated_script = _generated_script
767 test_exe = invoker.target_name
768 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34769
Xinan Lin6be01252021-06-25 23:07:36770 if (is_chromeos_lacros) {
771 # At build time, Lacros tests don't know whether they'll run on VM or
772 # HW, and instead, these flags are specified at runtime when invoking
773 # the generated runner script.
774 skip_generating_board_args = true
775 }
Greg Guterman6963dc082021-04-07 05:20:59776
Xinan Lin6be01252021-06-25 23:07:36777 if (tests_have_location_tags) {
778 data = [ "//testing/location_tags.json" ]
779 }
780
781 if (use_rts) {
782 data_deps = [ ":${invoker.target_name}__rts_filters" ]
783 }
Greg Guterman6963dc082021-04-07 05:20:59784 }
Benjamin Pastene3bce864e2018-04-14 01:16:32785 }
786
danakjebb9cc4d2022-03-04 21:30:11787 mixed_test(target_name) {
788 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01789 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
790 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32791 if (!defined(deps)) {
792 deps = []
793 }
794 if (!defined(data)) {
795 data = []
796 }
797
Ben Pastene41041782019-02-16 04:21:58798 # We use a special trigger script for CrOS hardware tests.
799 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
800
Benjamin Pastene3bce864e2018-04-14 01:16:32801 output_name = target_name
802 write_runtime_deps = _runtime_deps_file
803 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37804 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59805
Kevin Marshall23529362022-02-23 16:50:36806 if (!defined(data_deps)) {
807 data_deps = []
808 }
809
810 data_deps += [ "//testing:test_scripts_shared" ]
811
Greg Guterman6963dc082021-04-07 05:20:59812 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59813 data_deps += [ ":${invoker.target_name}__rts_filters" ]
814 }
Benjamin Pastene3bce864e2018-04-14 01:16:32815 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11816 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24817 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
818 _executable = target_name
819 _gen_runner_target = "${target_name}__runner"
820
Yuke Liao32af4242020-07-16 21:48:02821 if (defined(invoker.use_xvfb)) {
822 _use_xvfb = invoker.use_xvfb
823 } else {
824 _use_xvfb = false
825 }
826
Yuke Liaod037abc2020-10-06 22:48:22827 # When use_xvfb is set by the invoker, it indicates that running this test
828 # target requires a window, and in lacros build, ash-chrome serves as the
829 # display server. Note that even though the tests themselves do not require
830 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
831 # because ash-chrome is based on x11.
832 _use_ash_chrome = _use_xvfb
833
Yuke Liaoe703384b2020-07-16 01:05:24834 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24835 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02836
Yuke Liao2e4953cf2020-07-26 19:20:19837 data = []
Will Harrisd35e2c92021-04-07 01:42:02838 data_deps = [ "//testing:test_scripts_shared" ]
839
Yuke Liao32af4242020-07-16 21:48:02840 if (_use_xvfb) {
841 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22842 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02843 } else {
844 executable = "//testing/test_env.py"
845 }
Jamie Madilldd60ee62021-04-13 19:25:52846 if (tests_have_location_tags) {
847 data += [ "//testing/location_tags.json" ]
848 }
Yuke Liao32af4242020-07-16 21:48:02849
Yuke Liaoe703384b2020-07-16 01:05:24850 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02851 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39852 "test",
Yuke Liaoe703384b2020-07-16 01:05:24853 "@WrappedPath(./${_executable})",
854 "--test-launcher-bot-mode",
855 ]
Yuke Liao32af4242020-07-16 21:48:02856
Yuke Liaof540c742020-07-29 16:28:34857 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37858 executable_args += [ "--ash-chrome-path" ]
859
860 # Can't use --ash-chrome-path=path because WrappedPath
861 # won't be expanded for that usage.
862 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39863 }
864
Yuke Liaoe703384b2020-07-16 01:05:24865 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:00866 executable_args += [ "--asan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24867 }
868 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:00869 executable_args += [ "--msan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24870 }
871 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:00872 executable_args += [ "--tsan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24873 }
874 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:00875 executable_args += [ "--cfi-diag=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24876 }
877
Takuto Ikuta38ebd0e2022-01-19 17:56:22878 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59879
880 if (use_rts) {
881 data_deps += [ ":${invoker.target_name}__rts_filters" ]
882 }
Yuke Liaoe703384b2020-07-16 01:05:24883 }
884
danakjebb9cc4d2022-03-04 21:30:11885 mixed_test(target_name) {
886 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01887 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
888 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24889 if (!defined(deps)) {
890 deps = []
891 }
892
Yuke Liaod037abc2020-10-06 22:48:22893 if (!defined(data_deps)) {
894 data_deps = []
895 }
896
Kevin Marshall23529362022-02-23 16:50:36897 data_deps += [ "//testing:test_scripts_shared" ]
898
Yuke Liaoe703384b2020-07-16 01:05:24899 write_runtime_deps = _runtime_deps_file
900 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22901 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56902 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22903 }
Greg Guterman6963dc082021-04-07 05:20:59904
905 if (use_rts) {
906 data_deps += [ ":${invoker.target_name}__rts_filters" ]
907 }
Yuke Liaoe703384b2020-07-16 01:05:24908 }
Dirk Prankedd4ff742020-11-18 19:57:32909 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30910 if (is_mac || is_win) {
911 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
912 }
913
Dirk Prankedd4ff742020-11-18 19:57:32914 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
915 _executable = target_name
916 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06917
Dirk Prankedd4ff742020-11-18 19:57:32918 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
919 _use_xvfb = invoker.use_xvfb
920 } else {
921 _use_xvfb = false
922 }
923
924 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32925 wrapper_script = "$root_build_dir/bin/run_" + _executable
926
927 data = []
Will Harrisd35e2c92021-04-07 01:42:02928 data_deps = [ "//testing:test_scripts_shared" ]
929
Dirk Prankedd4ff742020-11-18 19:57:32930 if (_use_xvfb) {
931 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06932 } else {
Dirk Prankedd4ff742020-11-18 19:57:32933 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06934 }
Jamie Madilldd60ee62021-04-13 19:25:52935 if (tests_have_location_tags) {
936 data += [ "//testing/location_tags.json" ]
937 }
Dirk Pranke31e346e2020-07-15 00:54:06938
Dirk Prankedd4ff742020-11-18 19:57:32939 executable_args = [
940 "@WrappedPath(./${_executable})",
941 "--test-launcher-bot-mode",
942 ]
943 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:00944 executable_args += [ "--asan=1" ]
Dirk Pranke31e346e2020-07-15 00:54:06945 }
Dirk Prankedd4ff742020-11-18 19:57:32946 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:00947 executable_args += [ "--msan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:32948 }
949 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:00950 executable_args += [ "--tsan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:32951 }
952 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:00953 executable_args += [ "--cfi-diag=1" ]
Dirk Prankedd4ff742020-11-18 19:57:32954 }
955
Greg Guterman6963dc082021-04-07 05:20:59956 if (use_rts) {
957 data_deps += [ ":${invoker.target_name}__rts_filters" ]
958 }
Dirk Pranke31e346e2020-07-15 00:54:06959 }
960
danakjebb9cc4d2022-03-04 21:30:11961 mixed_test(target_name) {
962 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01963 forward_variables_from(invoker,
964 "*",
965 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
966 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06967 if (!defined(deps)) {
968 deps = []
969 }
970
Dirk Pranke31e346e2020-07-15 00:54:06971 deps += [
972 # Give tests the default manifest on Windows (a no-op elsewhere).
973 "//build/win:default_exe_manifest",
974 ]
975
Dirk Prankedd4ff742020-11-18 19:57:32976 write_runtime_deps = _runtime_deps_file
977 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11978
Kevin Marshall23529362022-02-23 16:50:36979 if (!defined(data_deps)) {
980 data_deps = []
981 }
982
983 data_deps += [ "//testing:test_scripts_shared" ]
984
Greg Guterman50ed4b42021-04-08 01:15:11985 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:11986 data_deps += [ ":${invoker.target_name}__rts_filters" ]
987 }
Dirk Prankedd4ff742020-11-18 19:57:32988 }
989 } else {
990 # This is a catch-all clause for NaCl toolchains and other random
991 # configurations that might define tests; test() in these configs
992 # will just define the underlying executables.
993 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
994 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:11995 mixed_test(target_name) {
996 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01997 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
998 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32999 if (!defined(deps)) {
1000 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061001 }
Greg Guterman6963dc082021-04-07 05:20:591002
Kevin Marshall23529362022-02-23 16:50:361003 if (!defined(data_deps)) {
1004 data_deps = []
1005 }
1006
1007 data_deps += [ "//testing:test_scripts_shared" ]
1008
Greg Guterman6963dc082021-04-07 05:20:591009 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:591010 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1011 }
Dirk Pranke31e346e2020-07-15 00:54:061012 }
qsrfb5251d12015-01-21 15:57:221013 }
1014}
brettwedb6ecc2016-07-14 23:37:031015
Dirk Pranke6188075b2020-10-01 19:31:281016# Defines a type of test that invokes a script to run, rather than
1017# invoking an executable.
1018#
1019# The script must implement the
1020# [test executable API](//docs/testing/test_executable_api.md).
1021#
1022# The template must be passed the `script` parameter, which specifies
1023# the path to the script to run. It may optionally be passed a
1024# `script_args` parameter, which can be used to include a list of
1025# args to be specified by default. The template will produce
1026# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
1027# for the target to $root_build_dir/${target_name}.runtime_deps, as per
1028# the conventions listed in the
1029# [test wrapper API](//docs/testing/test_wrapper_api.md).
1030template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:591031 if (use_rts) {
1032 action("${target_name}__rts_filters") {
1033 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:531034 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:051035 inverted_rts_file =
1036 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
1037 args = [
1038 rebase_path(rts_file, root_build_dir),
1039 rebase_path(inverted_rts_file, root_build_dir),
1040 ]
1041 outputs = [
1042 rts_file,
1043 inverted_rts_file,
1044 ]
Greg Guterman6963dc082021-04-07 05:20:591045 }
1046 }
1047
Dirk Pranke6188075b2020-10-01 19:31:281048 generate_wrapper(target_name) {
1049 testonly = true
1050 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1051
1052 executable = "//testing/test_env.py"
1053
1054 executable_args =
1055 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1056 if (defined(invoker.args)) {
1057 executable_args += invoker.args
1058 }
1059
Will Harrisd35e2c92021-04-07 01:42:021060 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471061
Dirk Pranke6188075b2020-10-01 19:31:281062 if (defined(invoker.data)) {
1063 data += invoker.data
1064 }
Jamie Madilldd60ee62021-04-13 19:25:521065 if (tests_have_location_tags) {
1066 data += [ "//testing/location_tags.json" ]
1067 }
Dirk Pranke19a58732021-03-24 22:26:221068
Will Harrisd35e2c92021-04-07 01:42:021069 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281070 if (defined(invoker.data_deps)) {
1071 data_deps += invoker.data_deps
1072 }
1073
1074 forward_variables_from(invoker,
1075 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:011076 TESTONLY_AND_VISIBILITY + [
1077 "data",
1078 "data_deps",
1079 "script",
1080 "script_args",
1081 ])
1082 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281083
1084 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591085
1086 if (use_rts) {
1087 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1088 }
Dirk Pranke6188075b2020-10-01 19:31:281089 }
1090}
1091
brettwedb6ecc2016-07-14 23:37:031092# Test defaults.
1093set_defaults("test") {
1094 if (is_android) {
1095 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411096 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591097 configs += [ "//build/config/android:hide_all_but_jni" ]
Andrew Grieved5fdf2af2022-08-23 07:47:551098
1099 # Compress sections to stay under 4gb hard limit on 32-bit current_cpu.
1100 # https://crbug.com/1354616
1101 if (symbol_level == 2 && !use_debug_fission &&
1102 (current_cpu == "arm" || current_cpu == "x86")) {
1103 configs += [ "//build/config:compress_debug_sections" ]
1104 }
brettwedb6ecc2016-07-14 23:37:031105 } else {
1106 configs = default_executable_configs
1107 }
1108}