blob: 2f40bbceb7c168ab7bd805d03bb06fc624b4fe30 [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) {
danakjebb9cc4d2022-03-04 21:30:1192 if (dep == "//testing/gtest") {
93 _gtest_is_in_deps = true
94 }
95 }
96 }
danakj482580a2022-11-18 18:00:5997
98 # TODO(danakj): This could be a rust_source_set perhaps, the point being
99 # that we need to link in all the .o object files inside the library,
100 # instead of dropping unreachable ones during linking (which would drop the
101 # tests). Alternatively we could use a special name suffix or other similar
102 # trick perhaps to ensure that all object files are linked in here.
103 rust_static_library(_rust_target_name) {
104 forward_variables_from(invoker,
105 TESTONLY_AND_VISIBILITY + [
106 "crate_name",
107 "deps",
108 "public_deps",
109 ])
110 configs += [ "//build/rust:test" ]
111 generate_crate_root = true
112 sources = _rs_sources
113 if (_gtest_is_in_deps) {
114 deps += [ "//testing/rust_gtest_interop" ]
danakjebb9cc4d2022-03-04 21:30:11115 }
danakj482580a2022-11-18 18:00:59116 }
117 } else {
118 not_needed(invoker, _rs_vars)
119 }
120
121 target(invoker.target_type, target_name) {
122 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY + _rs_vars)
123 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
124 sources = _cc_sources
125 if (!defined(deps)) {
126 deps = []
127 }
128 if (_rs_sources != []) {
129 deps += [ ":${_rust_target_name}" ]
danakjebb9cc4d2022-03-04 21:30:11130 }
131 }
132}
133
qsrfb5251d12015-01-21 15:57:22134# Define a test as an executable (or apk on Android) with the "testonly" flag
135# set.
agrieve62ab00282016-04-05 02:03:45136# Variable:
Dirk Pranke79d065d2020-08-29 03:28:30137# use_xvfb: (optional) whether to run the executable under Xvfb.
danakj482580a2022-11-18 18:00:59138# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:56139# use_native_activity: Test implements ANativeActivity_onCreate().
Greg Thompson318cd692022-03-28 08:12:06140# test_runner_shard: (Fuchsia, optional): for CFv2 tests, use the given test
Greg Thompsonfd269652022-10-28 12:06:55141# runner shard rather than the default shard for the ELF runner when
142# assembling the test component. This is useful, for example, to use the
143# elf_test_ambient_exec_runner for tests that require
144# job_policy_ambient_mark_vmo_exec.
145# fuchsia_package_deps: (Fuchsia, optional) List of fuchsia_component()
146# targets that this test package contains.
Chong Guc2f17c32022-11-15 23:14:45147# # TODO(crbug/1280705): remove when all tests are migrated to CFv2.
148# fuchsia_legacy_script_required: (Fuchsia, optional) Whether the old test
149# scripts are required to run the test target.
Mirko Bonadei15522bc2020-09-16 20:38:39150# is_xctest: (iOS, optional) whether to build the executable as XCTest.
151# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
152# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:43153# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
154# network requests during the test.
qsrfb5251d12015-01-21 15:57:22155template("test") {
Greg Guterman6963dc082021-04-07 05:20:59156 # Ensures the rts file exists and if not, creates a dummy file
157 if (use_rts) {
158 action("${target_name}__rts_filters") {
159 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53160 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:05161 inverted_rts_file =
162 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
163 args = [
164 rebase_path(rts_file, root_build_dir),
165 rebase_path(inverted_rts_file, root_build_dir),
166 ]
167 outputs = [
168 rts_file,
169 inverted_rts_file,
170 ]
Greg Guterman6963dc082021-04-07 05:20:59171 }
172 }
173
Andrew Grieve1b290e4a22020-11-24 20:07:01174 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:39175 if (!is_ios) {
176 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
177 "is_xctest can be set only for iOS builds")
178 }
Stefano Duo4128b6b2021-08-02 21:24:43179 if (!is_android) {
180 assert(!defined(invoker.allow_cleartext_traffic),
181 "allow_cleartext_traffic can be set only for Android tests")
182 }
183
qsrfb5251d12015-01-21 15:57:22184 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:30185 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
186
Peter Kotwicz10742f82021-04-15 22:32:50187 _use_default_launcher =
188 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
189 if (!defined(invoker.use_raw_android_executable)) {
190 # Checkouts where build_with_chromium == false often have a custom GN
191 # template wrapper around test() which sets use_default_launcher == false.
192 # Set the _use_raw_android_executable default so that test() targets which
193 # do not use the custom wrapper
194 # (1) Do not cause "gn gen" to fail
195 # (2) Do not need to be moved into if(build_with_chromium) block.
196 _use_raw_android_executable =
197 !build_with_chromium && _use_default_launcher
198 } else {
199 not_needed([ "_use_default_launcher" ])
200 _use_raw_android_executable = invoker.use_raw_android_executable
201 }
qsrfb5251d12015-01-21 15:57:22202
agrieve67855de2016-03-30 14:46:01203 # output_name is used to allow targets with the same name but in different
204 # packages to still produce unique runner scripts.
205 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26206 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01207 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26208 }
agrieve62ab00282016-04-05 02:03:45209
agrieveb355ad152016-04-19 03:45:23210 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42211 _wrapper_script_vars = [
Jamie Madill73b9af332022-08-03 19:27:47212 "android_test_runner_script",
agrievee41ae190d2016-04-25 14:12:51213 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42214 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51215 ]
agrieve3ac557f02016-04-12 15:52:00216
jbudorickced2a252016-06-09 16:38:54217 assert(_use_raw_android_executable || enable_java_templates)
218
agrieve62ab00282016-04-05 02:03:45219 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49220 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
221
agrieve62ab00282016-04-05 02:03:45222 _exec_target = "${target_name}__exec"
223 _dist_target = "${target_name}__dist"
224 _exec_output =
225 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
226
danakjebb9cc4d2022-03-04 21:30:11227 mixed_test(_exec_target) {
228 target_type = "executable"
229
danakje94f40d2022-02-16 18:13:53230 # Configs will always be defined since we set_defaults in
231 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45232 configs = []
Dirk Pranke19a58732021-03-24 22:26:22233 forward_variables_from(
234 invoker,
235 "*",
236 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
237 "data_deps",
238 "extra_dist_files",
239 ])
agrieve62ab00282016-04-05 02:03:45240
241 # Thanks to the set_defaults() for test(), configs are initialized with
242 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59243 configs -= [
244 "//build/config:shared_library_config",
245 "//build/config/android:hide_all_but_jni",
246 ]
agrieve62ab00282016-04-05 02:03:45247 configs += [ "//build/config:executable_config" ]
248
Dirk Pranke19a58732021-03-24 22:26:22249 if (defined(invoker.data_deps)) {
250 data_deps = invoker.data_deps
251 } else {
252 data_deps = []
253 }
254 if (!defined(data)) {
255 data = []
256 }
Jamie Madilldd60ee62021-04-13 19:25:52257 if (tests_have_location_tags) {
258 data += [ "//testing/location_tags.json" ]
259 }
Dirk Pranke19a58732021-03-24 22:26:22260
agrieve62ab00282016-04-05 02:03:45261 # Don't output to the root or else conflict with the group() below.
262 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11263
264 if (use_rts) {
265 data_deps += [ ":${invoker.target_name}__rts_filters" ]
266 }
agrieve62ab00282016-04-05 02:03:45267 }
268
269 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45270 dist_dir = "$root_out_dir/$target_name"
271 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22272 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45273 if (defined(invoker.extra_dist_files)) {
274 extra_files = invoker.extra_dist_files
275 }
Greg Guterman50ed4b42021-04-08 01:15:11276
277 if (use_rts) {
278 if (!defined(data_deps)) {
279 data_deps = []
280 }
281 data_deps += [ ":${invoker.target_name}__rts_filters" ]
282 }
agrieve62ab00282016-04-05 02:03:45283 }
284 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38285 _library_target_name = "${target_name}__library"
danakj98e073722022-02-24 21:01:49286 _library_crate_name = "${target_name}_library"
Andrew Grieveee8aa44d2022-09-23 17:14:38287 _apk_target_name = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45288 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43289 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45290 "android_manifest",
agrievec6811b422016-06-23 02:25:09291 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27292 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55293 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45294 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50295 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07296 "product_config_java_packages",
Andrew Grieve43f24fd02022-04-06 23:04:04297 "loadable_modules",
298 "loadable_module_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02299 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07300 "proguard_configs",
301 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45302 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02303 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45304 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56305 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45306 ]
Siddhartha764226b2018-03-13 02:32:55307
Andrew Grieveee8aa44d2022-09-23 17:14:38308 _add_unwind_tables_in_apk =
309 defined(invoker.add_unwind_tables_in_apk) &&
310 invoker.add_unwind_tables_in_apk && target_cpu == "arm"
Andrew Grieved5fdf2af2022-08-23 07:47:55311
Siddhartha764226b2018-03-13 02:32:55312 # Adds the unwind tables from unstripped binary as an asset file in the
313 # apk, if |add_unwind_tables_in_apk| is specified by the test.
Andrew Grieved5fdf2af2022-08-23 07:47:55314 if (_add_unwind_tables_in_apk) {
Andrew Grieveee8aa44d2022-09-23 17:14:38315 # TODO(crbug.com/1315603): Remove generation of v1 unwind asset when
316 # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroidV2`.
317 _unwind_table_name = "${_library_target_name}_unwind_v1"
318 unwind_table_v1(_unwind_table_name) {
319 library_target = ":$_library_target_name"
320 }
321
Arthur Sonzogni54424e92022-09-23 13:30:45322 if (use_android_unwinder_v2) {
Andrew Grieveee8aa44d2022-09-23 17:14:38323 _unwind_table_v2_name = "${_library_target_name}_unwind_v2"
324 unwind_table_v2(_unwind_table_v2_name) {
325 library_target = ":$_library_target_name"
Arthur Sonzogni54424e92022-09-23 13:30:45326 }
327 }
328
Andrew Grieveee8aa44d2022-09-23 17:14:38329 _unwind_table_asset_name = "${target_name}__unwind_assets"
330 android_assets(_unwind_table_asset_name) {
331 sources = [ "$target_out_dir/$_unwind_table_name/$unwind_table_asset_v1_filename" ]
332 disable_compression = true
333 deps = [ ":$_unwind_table_name" ]
334 if (use_android_unwinder_v2) {
335 sources += [ "$target_out_dir/$_unwind_table_v2_name/$unwind_table_asset_v2_filename" ]
336 deps += [ ":$_unwind_table_v2_name" ]
337 }
Siddhartha764226b2018-03-13 02:32:55338 }
339 }
340
Andrew Grieveee8aa44d2022-09-23 17:14:38341 mixed_test(_library_target_name) {
danakjebb9cc4d2022-03-04 21:30:11342 target_type = "shared_library"
343
danakj98e073722022-02-24 21:01:49344 # Configs will always be defined since we set_defaults in
345 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45346 configs = [] # Prevent list overwriting warning.
347 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45348
Andrew Grieved5fdf2af2022-08-23 07:47:55349 if (_add_unwind_tables_in_apk) {
350 # Remove -gz if present, as dump_syms does not support it.
351 # Add and then remove because "-=" removes all, but errors if none are found.
352 configs += [ "//build/config:compress_debug_sections" ]
353 configs -= [ "//build/config:compress_debug_sections" ]
354 }
355
jbudorickd29ecfa72016-11-18 22:45:42356 forward_variables_from(
357 invoker,
358 "*",
Andrew Grieved5fdf2af2022-08-23 07:47:55359 [
360 "configs",
361 "deps",
362 ] + _apk_specific_vars + _wrapper_script_vars +
Peter Wen2052bd12020-12-03 20:15:07363 TESTONLY_AND_VISIBILITY)
364
danakj482580a2022-11-18 18:00:59365 # Use a crate name that avoids creating a warning due to double
366 # underscore (ie. `__`).
367 crate_name = _library_crate_name
368
Peter Wen2052bd12020-12-03 20:15:07369 # Native targets do not need to depend on java targets. Filter them out
370 # so that the shared library can be built without needing to wait for
371 # dependent java targets.
372 deps = []
373 if (defined(invoker.deps)) {
Andrew Grieve841ed072022-08-23 16:42:33374 deps = filter_exclude(invoker.deps, java_target_patterns)
Peter Wen2052bd12020-12-03 20:15:07375 }
agrieve62ab00282016-04-05 02:03:45376
Peter Kotwiczb9957d62021-04-12 21:09:43377 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37378 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45379 }
380 }
Andrew Grieveee8aa44d2022-09-23 17:14:38381 unittest_apk(_apk_target_name) {
Daniel Bratellfdda4652019-01-31 15:45:54382 forward_variables_from(invoker, _apk_specific_vars)
Andrew Grieveee8aa44d2022-09-23 17:14:38383 shared_library = ":$_library_target_name"
agrieve62ab00282016-04-05 02:03:45384 apk_name = invoker.target_name
385 if (defined(invoker.output_name)) {
386 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45387 install_script_name = "install_${invoker.output_name}"
388 }
agrieveb355ad152016-04-19 03:45:23389
Daniel Bratellfdda4652019-01-31 15:45:54390 if (defined(invoker.deps)) {
391 deps = invoker.deps
392 } else {
393 deps = []
394 }
Andrew Grieve43f24fd02022-04-06 23:04:04395 if (defined(loadable_module_deps)) {
396 deps += loadable_module_deps
397 }
Daniel Bratellfdda4652019-01-31 15:45:54398
jcivellif4462a352017-01-10 04:45:59399 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43400 if (_use_default_launcher) {
401 deps += [ "//base/test:test_support_java" ]
402 }
jcivellif4462a352017-01-10 04:45:59403
Siddhartha764226b2018-03-13 02:32:55404 if (defined(_unwind_table_asset_name)) {
405 deps += [ ":${_unwind_table_asset_name}" ]
406 }
Greg Guterman50ed4b42021-04-08 01:15:11407
408 if (use_rts) {
409 data_deps = [ ":${invoker.target_name}__rts_filters" ]
410 }
agrieve62ab00282016-04-05 02:03:45411 }
Andrew Grievee1dc23f2019-10-22 16:26:36412 }
agrieve62ab00282016-04-05 02:03:45413
Andrew Grievee1dc23f2019-10-22 16:26:36414 test_runner_script(_test_runner_target) {
415 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57416
Andrew Grievee1dc23f2019-10-22 16:26:36417 if (_use_raw_android_executable) {
418 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34419 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36420 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38421 apk_target = ":$_apk_target_name"
Andrew Grievee1dc23f2019-10-22 16:26:36422 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47423
424 # Dep needed for the test runner .runtime_deps file to pick up data
425 # deps from the forward_variables_from(invoker, "*") on the library.
Andrew Grieveee8aa44d2022-09-23 17:14:38426 data_deps = [ ":$_library_target_name" ]
agrieve62ab00282016-04-05 02:03:45427 }
Andrew Grievee1dc23f2019-10-22 16:26:36428 test_name = _output_name
429 test_suite = _output_name
430 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59431
432 if (use_rts) {
433 data_deps += [ ":${invoker.target_name}__rts_filters" ]
434 }
mikecase56d80d72015-06-03 00:57:26435 }
436
Andrew Grieve7ca6de32019-10-18 03:57:47437 # Create a wrapper script rather than using a group() in order to ensure
438 # "ninja $target_name" always works. If this was a group(), then GN would
439 # not create a top-level alias for it if a target exists in another
440 # directory with the same $target_name.
441 # Also - bots run this script directly for "components_perftests".
442 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01443 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47444 executable = "$root_build_dir/bin/run_$_output_name"
445 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22446 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40447 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47448 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40449 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47450 # Dep needed for the swarming .isolate file to pick up data
451 # deps from the forward_variables_from(invoker, "*") on the library.
452 deps += [
Andrew Grieveee8aa44d2022-09-23 17:14:38453 ":$_apk_target_name",
454 ":$_library_target_name",
Andrew Grieve7ca6de32019-10-18 03:57:47455 ]
agrieve62ab00282016-04-05 02:03:45456 }
Dirk Pranke19a58732021-03-24 22:26:22457
458 if (defined(invoker.data_deps)) {
459 data_deps = invoker.data_deps
460 } else {
461 data_deps = []
462 }
Kevin Marshall23529362022-02-23 16:50:36463
464 data_deps += [ "//testing:test_scripts_shared" ]
465
Jamie Madilldd60ee62021-04-13 19:25:52466 if (tests_have_location_tags) {
467 data = [ "//testing/location_tags.json" ]
468 }
Greg Guterman6963dc082021-04-07 05:20:59469
470 if (use_rts) {
471 data_deps += [ ":${invoker.target_name}__rts_filters" ]
472 }
agrieve1a02e582015-10-15 21:35:39473 }
Scott Graham4c4cdc52017-05-29 20:45:03474 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30475 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
476
Scott Graham4c4cdc52017-05-29 20:45:03477 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42478 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42479 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb42022-04-05 12:30:35480 _program_name = get_label_info(":${_exec_target}", "name")
Scott Graham4c4cdc52017-05-29 20:45:03481
Greg Thompson2f1e3762022-10-17 19:53:44482 # Generate a CML fragment that provides the program name.
483 _test_program_fragment_target = "${target_name}_program-fragment"
484 _test_program_fragment = "${target_out_dir}/${target_name}_program.test-cml"
485 generated_file(_test_program_fragment_target) {
486 contents = {
487 program = {
488 binary = _program_name
Kevin Marshall2ec60032022-05-09 17:38:28489 }
Greg Thompson26516592021-12-16 08:34:45490 }
Greg Thompson2f1e3762022-10-17 19:53:44491 outputs = [ _test_program_fragment ]
492 output_conversion = "json"
Greg Thompson9765eeb42022-04-05 12:30:35493 }
494
Chong Guc2f17c32022-11-15 23:14:45495 use_v2_script = use_v2_script_default
Chong Gu3c6fe122022-11-16 08:15:19496 if (target_cpu == "x64") {
497 use_v2_script = false
498 }
Chong Guc2f17c32022-11-15 23:14:45499 if (defined(invoker.fuchsia_legacy_script_required) &&
500 invoker.fuchsia_legacy_script_required) {
501 use_v2_script = false
502 }
503
Greg Thompson2f1e3762022-10-17 19:53:44504 _test_runner_shard =
505 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
506 if (defined(invoker.test_runner_shard)) {
507 _test_runner_shard = invoker.test_runner_shard
Wez6879f8a2021-09-07 20:27:02508 }
509
Greg Thompson2f1e3762022-10-17 19:53:44510 # Collate the complete set of elements to include in the test component's
511 # manifest.
512 _manifest_fragments = [
513 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
514 "//build/config/fuchsia/test/minimum.shard.test-cml",
515 _test_program_fragment,
516 _test_runner_shard,
517 ]
518
519 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
520 _merged_manifest_name = "${_output_name}.cml"
521
522 if (defined(invoker.additional_manifest_fragments)) {
523 _manifest_fragments += invoker.additional_manifest_fragments
524 }
525
526 # Generate the test component manifest from the specified elements.
527 _test_component_manifest_target = "${target_name}_component-manifest"
528 cmc_merge(_test_component_manifest_target) {
529 sources = _manifest_fragments
530 output_name = "${_merged_manifest_name}"
531 deps = [ ":${_test_program_fragment_target}" ]
532 }
533
534 # Define the test component, dependent on the generated manifest, and the
535 # test executable target.
536 _test_component_target = "${target_name}_component"
537 fuchsia_component(_test_component_target) {
538 deps = [ ":$_test_component_manifest_target" ]
539 data_deps = [ ":$_exec_target" ]
540 manifest = _test_component_manifest
541 visibility = [ ":*" ]
542 }
543
544 _test_component_targets = [ ":${_test_component_target}" ]
545
Wez6879f8a2021-09-07 20:27:02546 # Define components for each entry in |additional_manifests|, if any. Since
547 # manifests may themselves depend-on the outputs of |deps|, these components
548 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02549 if (defined(invoker.additional_manifests)) {
550 foreach(filename, invoker.additional_manifests) {
551 _additional_component_target =
552 target_name + "_" + get_path_info(filename, "name")
553 _test_component_targets += [ ":${_additional_component_target}" ]
554 fuchsia_component(_additional_component_target) {
555 forward_variables_from(invoker, [ "testonly" ])
556 data_deps = [ ":$_exec_target" ]
557 visibility = [ ":*" ]
558 manifest = filename
559
560 # Depend on |invoker.deps|, in case it includes a dependency that
561 # creates this additional component's manifest.
562 if (defined(invoker.deps)) {
563 deps = invoker.deps
564 }
565 }
566 }
567 }
568
569 # Define the package target that will bundle the test and additional
570 # components and their data.
571 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21572 forward_variables_from(invoker,
573 [
574 "excluded_files",
575 "excluded_dirs",
576 ])
Wez6879f8a2021-09-07 20:27:02577 package_name = _output_name
578 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21579
Greg Thompsonfd269652022-10-28 12:06:55580 if (defined(invoker.fuchsia_package_deps)) {
581 deps += invoker.fuchsia_package_deps
582 }
Kevin Marshall36c602c2021-11-04 16:16:21583 if (!defined(excluded_dirs)) {
584 excluded_dirs = []
585 }
Sarah Pham80972efc2022-05-31 17:40:15586 if (devtools_root_location != "") {
587 excluded_dirs += [ devtools_root_location ]
588 }
Wez6879f8a2021-09-07 20:27:02589 }
590
591 # |target_name| refers to the package-runner rule, so that building
592 # "base_unittests" will build not only the executable, component, and
593 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25594 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53595 forward_variables_from(invoker,
596 [
Kevin Marshall5fadadd2021-10-16 00:08:25597 "data",
598 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53599 "package_deps",
Kevin Marshall5fadadd2021-10-16 00:08:25600 "use_test_server",
Chong Guc2f17c32022-11-15 23:14:45601 "use_v2_script",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53602 ])
Kevin Marshall5fadadd2021-10-16 00:08:25603
Chong Guc6bfdf62021-10-20 23:37:00604 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15605 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25606 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42607
Kevin Marshall5fadadd2021-10-16 00:08:25608 if (!defined(deps)) {
609 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52610 }
Kevin Marshall5fadadd2021-10-16 00:08:25611 if (defined(invoker.deps)) {
612 deps += invoker.deps
613 }
Greg Guterman6963dc082021-04-07 05:20:59614
Kevin Marshall5fadadd2021-10-16 00:08:25615 if (!defined(data)) {
616 data = []
617 }
618 if (tests_have_location_tags) {
619 data += [ "//testing/location_tags.json" ]
620 }
621
622 if (!defined(data_deps)) {
623 data_deps = []
624 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28625
Kevin Marshall23529362022-02-23 16:50:36626 data_deps += [ "//testing:test_scripts_shared" ]
627
Greg Guterman6963dc082021-04-07 05:20:59628 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25629 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59630 }
Kevin Marshallf35fa5f2018-01-29 19:24:42631 }
632
danakjebb9cc4d2022-03-04 21:30:11633 mixed_test(_exec_target) {
634 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01635 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42636 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03637 }
dpranke2a294622015-08-07 05:23:01638 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30639 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46640 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30641
Rohit Raof9b096d2019-09-09 22:26:23642 declare_args() {
643 # Keep the unittest-as-xctest functionality defaulted to off until the
644 # bots are updated to handle it properly.
645 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
646 # supports running unittests with xctest.
647 enable_run_ios_unittests_with_xctest = false
648 }
649
sdefresne012857872016-03-16 10:55:37650 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27651 _output_name = target_name
652 if (defined(invoker.output_name)) {
653 _output_name = invoker.output_name
654 }
655
Jeff Yoonf7f4eb42020-03-06 18:55:36656 _wrapper_output_name = "run_${target_name}"
657 ios_test_runner_wrapper(_wrapper_output_name) {
658 forward_variables_from(invoker,
659 [
660 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36661 "deps",
662 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27663 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36664 "retries",
665 "shards",
666 ])
667
668 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
669
670 if (!defined(executable_args)) {
671 executable_args = []
672 }
673 executable_args += [
674 "--app",
675 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
676 ]
677
678 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22679
680 if (!defined(data)) {
681 data = []
682 }
Jamie Madilldd60ee62021-04-13 19:25:52683 if (tests_have_location_tags) {
684 data += [ "//testing/location_tags.json" ]
685 }
Jeff Yoonf7f4eb42020-03-06 18:55:36686 }
687
sdefresne012857872016-03-16 10:55:37688 _resources_bundle_data = target_name + "_resources_bundle_data"
689
690 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34691 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22692 sources = [ "//testing/gtest_ios/Default.png" ]
693 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01694 }
695
Mirko Bonadei15522bc2020-09-16 20:38:39696 force_xctest = enable_run_ios_unittests_with_xctest ||
697 (defined(invoker.is_xctest) && invoker.is_xctest)
698
danakjfae603fc602022-11-18 18:40:22699 mixed_test(_test_target) {
700 if (force_xctest) {
701 target_type = "ios_xctest_test"
702 } else {
703 target_type = "ios_app_bundle"
704 }
dpranke2a294622015-08-07 05:23:01705 testonly = true
sdefresnea828c282016-05-30 18:04:20706
Mirko Bonadei15522bc2020-09-16 20:38:39707 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23708 xctest_module_target = "//base/test:google_test_runner"
709 }
710
Andrew Grieve1b290e4a22020-11-24 20:07:01711 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13712
713 # Provide sensible defaults in case invoker did not define any of those
714 # required variables.
sdefresne05b97ca2016-06-08 07:19:46715 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13716 info_plist = "//testing/gtest_ios/unittest-Info.plist"
717 }
sdefresne9e147e02016-06-07 00:10:13718
Sylvain Defresne3c5a1312021-09-23 17:08:09719 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13720 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50721 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09722 } else {
Ali Juma75be0fe2022-01-24 19:39:29723 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27724 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09725 }
dpranke2a294622015-08-07 05:23:01726
sdefresne047490e2016-07-22 08:49:34727 if (!defined(bundle_deps)) {
728 bundle_deps = []
729 }
730 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36731
732 if (!defined(data_deps)) {
733 data_deps = []
734 }
735
Kevin Marshall23529362022-02-23 16:50:36736 data_deps += [ "//testing:test_scripts_shared" ]
737
Jeff Yoonf7f4eb42020-03-06 18:55:36738 # Include the generate_wrapper as part of data_deps
739 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46740 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59741
742 if (use_rts) {
743 data_deps += [ ":${invoker.target_name}__rts_filters" ]
744 }
dpranke2a294622015-08-07 05:23:01745 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11746 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
747 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30748 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
749
Yuke Liao2a9b2f0e2021-04-16 00:40:11750 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32751
Benjamin Pastene3bce864e2018-04-14 01:16:32752 _gen_runner_target = "${target_name}__runner"
753 _runtime_deps_file =
754 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
755 "/" + get_label_info(target_name, "name") + ".runtime_deps"
756
Xinan Lin6be01252021-06-25 23:07:36757 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
758 if (is_skylab) {
Struan Shrimptonf61293f62022-04-11 19:33:40759 generate_skylab_deps(_gen_runner_target) {
Xinan Lin6be01252021-06-25 23:07:36760 generated_script = _generated_script
761 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34762 }
Xinan Lin6be01252021-06-25 23:07:36763 } else {
764 generate_runner_script(_gen_runner_target) {
765 generated_script = _generated_script
766 test_exe = invoker.target_name
767 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34768
Xinan Lin6be01252021-06-25 23:07:36769 if (is_chromeos_lacros) {
770 # At build time, Lacros tests don't know whether they'll run on VM or
771 # HW, and instead, these flags are specified at runtime when invoking
772 # the generated runner script.
773 skip_generating_board_args = true
774 }
Greg Guterman6963dc082021-04-07 05:20:59775
Xinan Lin6be01252021-06-25 23:07:36776 if (tests_have_location_tags) {
777 data = [ "//testing/location_tags.json" ]
778 }
779
780 if (use_rts) {
781 data_deps = [ ":${invoker.target_name}__rts_filters" ]
782 }
Greg Guterman6963dc082021-04-07 05:20:59783 }
Benjamin Pastene3bce864e2018-04-14 01:16:32784 }
785
danakjebb9cc4d2022-03-04 21:30:11786 mixed_test(target_name) {
787 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01788 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
789 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32790 if (!defined(deps)) {
791 deps = []
792 }
793 if (!defined(data)) {
794 data = []
795 }
796
Ben Pastene41041782019-02-16 04:21:58797 # We use a special trigger script for CrOS hardware tests.
798 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
799
Benjamin Pastene3bce864e2018-04-14 01:16:32800 output_name = target_name
801 write_runtime_deps = _runtime_deps_file
802 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37803 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59804
Kevin Marshall23529362022-02-23 16:50:36805 if (!defined(data_deps)) {
806 data_deps = []
807 }
808
809 data_deps += [ "//testing:test_scripts_shared" ]
810
Greg Guterman6963dc082021-04-07 05:20:59811 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59812 data_deps += [ ":${invoker.target_name}__rts_filters" ]
813 }
Benjamin Pastene3bce864e2018-04-14 01:16:32814 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11815 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24816 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
817 _executable = target_name
818 _gen_runner_target = "${target_name}__runner"
819
Yuke Liao32af4242020-07-16 21:48:02820 if (defined(invoker.use_xvfb)) {
821 _use_xvfb = invoker.use_xvfb
822 } else {
823 _use_xvfb = false
824 }
825
Yuke Liaod037abc2020-10-06 22:48:22826 # When use_xvfb is set by the invoker, it indicates that running this test
827 # target requires a window, and in lacros build, ash-chrome serves as the
828 # display server. Note that even though the tests themselves do not require
829 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
830 # because ash-chrome is based on x11.
831 _use_ash_chrome = _use_xvfb
832
Yuke Liaoe703384b2020-07-16 01:05:24833 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24834 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02835
Yuke Liao2e4953cf2020-07-26 19:20:19836 data = []
Will Harrisd35e2c92021-04-07 01:42:02837 data_deps = [ "//testing:test_scripts_shared" ]
838
Yuke Liao32af4242020-07-16 21:48:02839 if (_use_xvfb) {
840 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22841 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02842 } else {
843 executable = "//testing/test_env.py"
844 }
Jamie Madilldd60ee62021-04-13 19:25:52845 if (tests_have_location_tags) {
846 data += [ "//testing/location_tags.json" ]
847 }
Yuke Liao32af4242020-07-16 21:48:02848
Yuke Liaoe703384b2020-07-16 01:05:24849 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02850 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39851 "test",
Yuke Liaoe703384b2020-07-16 01:05:24852 "@WrappedPath(./${_executable})",
853 "--test-launcher-bot-mode",
854 ]
Yuke Liao32af4242020-07-16 21:48:02855
Yuke Liaof540c742020-07-29 16:28:34856 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37857 executable_args += [ "--ash-chrome-path" ]
858
859 # Can't use --ash-chrome-path=path because WrappedPath
860 # won't be expanded for that usage.
861 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39862 }
863
Yuke Liaoe703384b2020-07-16 01:05:24864 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:00865 executable_args += [ "--asan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24866 }
867 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:00868 executable_args += [ "--msan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24869 }
870 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:00871 executable_args += [ "--tsan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24872 }
873 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:00874 executable_args += [ "--cfi-diag=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24875 }
876
Takuto Ikuta38ebd0e2022-01-19 17:56:22877 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59878
879 if (use_rts) {
880 data_deps += [ ":${invoker.target_name}__rts_filters" ]
881 }
Yuke Liaoe703384b2020-07-16 01:05:24882 }
883
danakjebb9cc4d2022-03-04 21:30:11884 mixed_test(target_name) {
885 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01886 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
887 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24888 if (!defined(deps)) {
889 deps = []
890 }
891
Yuke Liaod037abc2020-10-06 22:48:22892 if (!defined(data_deps)) {
893 data_deps = []
894 }
895
Kevin Marshall23529362022-02-23 16:50:36896 data_deps += [ "//testing:test_scripts_shared" ]
897
Yuke Liaoe703384b2020-07-16 01:05:24898 write_runtime_deps = _runtime_deps_file
899 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22900 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56901 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22902 }
Greg Guterman6963dc082021-04-07 05:20:59903
904 if (use_rts) {
905 data_deps += [ ":${invoker.target_name}__rts_filters" ]
906 }
Yuke Liaoe703384b2020-07-16 01:05:24907 }
Dirk Prankedd4ff742020-11-18 19:57:32908 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30909 if (is_mac || is_win) {
910 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
911 }
912
Dirk Prankedd4ff742020-11-18 19:57:32913 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
914 _executable = target_name
915 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06916
Dirk Prankedd4ff742020-11-18 19:57:32917 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
918 _use_xvfb = invoker.use_xvfb
919 } else {
920 _use_xvfb = false
921 }
922
923 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32924 wrapper_script = "$root_build_dir/bin/run_" + _executable
925
926 data = []
Will Harrisd35e2c92021-04-07 01:42:02927 data_deps = [ "//testing:test_scripts_shared" ]
928
Dirk Prankedd4ff742020-11-18 19:57:32929 if (_use_xvfb) {
930 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06931 } else {
Dirk Prankedd4ff742020-11-18 19:57:32932 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06933 }
Jamie Madilldd60ee62021-04-13 19:25:52934 if (tests_have_location_tags) {
935 data += [ "//testing/location_tags.json" ]
936 }
Dirk Pranke31e346e2020-07-15 00:54:06937
Dirk Prankedd4ff742020-11-18 19:57:32938 executable_args = [
939 "@WrappedPath(./${_executable})",
940 "--test-launcher-bot-mode",
941 ]
942 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:00943 executable_args += [ "--asan=1" ]
Dirk Pranke31e346e2020-07-15 00:54:06944 }
Dirk Prankedd4ff742020-11-18 19:57:32945 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:00946 executable_args += [ "--msan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:32947 }
948 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:00949 executable_args += [ "--tsan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:32950 }
951 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:00952 executable_args += [ "--cfi-diag=1" ]
Dirk Prankedd4ff742020-11-18 19:57:32953 }
954
Greg Guterman6963dc082021-04-07 05:20:59955 if (use_rts) {
956 data_deps += [ ":${invoker.target_name}__rts_filters" ]
957 }
Dirk Pranke31e346e2020-07-15 00:54:06958 }
959
danakjebb9cc4d2022-03-04 21:30:11960 mixed_test(target_name) {
961 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01962 forward_variables_from(invoker,
963 "*",
964 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
965 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06966 if (!defined(deps)) {
967 deps = []
968 }
969
Dirk Pranke31e346e2020-07-15 00:54:06970 deps += [
971 # Give tests the default manifest on Windows (a no-op elsewhere).
972 "//build/win:default_exe_manifest",
973 ]
974
Dirk Prankedd4ff742020-11-18 19:57:32975 write_runtime_deps = _runtime_deps_file
976 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11977
Kevin Marshall23529362022-02-23 16:50:36978 if (!defined(data_deps)) {
979 data_deps = []
980 }
981
982 data_deps += [ "//testing:test_scripts_shared" ]
983
Greg Guterman50ed4b42021-04-08 01:15:11984 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:11985 data_deps += [ ":${invoker.target_name}__rts_filters" ]
986 }
Dirk Prankedd4ff742020-11-18 19:57:32987 }
988 } else {
989 # This is a catch-all clause for NaCl toolchains and other random
990 # configurations that might define tests; test() in these configs
991 # will just define the underlying executables.
992 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
993 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:11994 mixed_test(target_name) {
995 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01996 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
997 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32998 if (!defined(deps)) {
999 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061000 }
Greg Guterman6963dc082021-04-07 05:20:591001
Kevin Marshall23529362022-02-23 16:50:361002 if (!defined(data_deps)) {
1003 data_deps = []
1004 }
1005
1006 data_deps += [ "//testing:test_scripts_shared" ]
1007
Greg Guterman6963dc082021-04-07 05:20:591008 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:591009 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1010 }
Dirk Pranke31e346e2020-07-15 00:54:061011 }
qsrfb5251d12015-01-21 15:57:221012 }
1013}
brettwedb6ecc2016-07-14 23:37:031014
Dirk Pranke6188075b2020-10-01 19:31:281015# Defines a type of test that invokes a script to run, rather than
1016# invoking an executable.
1017#
1018# The script must implement the
1019# [test executable API](//docs/testing/test_executable_api.md).
1020#
1021# The template must be passed the `script` parameter, which specifies
1022# the path to the script to run. It may optionally be passed a
1023# `script_args` parameter, which can be used to include a list of
1024# args to be specified by default. The template will produce
1025# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
1026# for the target to $root_build_dir/${target_name}.runtime_deps, as per
1027# the conventions listed in the
1028# [test wrapper API](//docs/testing/test_wrapper_api.md).
1029template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:591030 if (use_rts) {
1031 action("${target_name}__rts_filters") {
1032 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:531033 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:051034 inverted_rts_file =
1035 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
1036 args = [
1037 rebase_path(rts_file, root_build_dir),
1038 rebase_path(inverted_rts_file, root_build_dir),
1039 ]
1040 outputs = [
1041 rts_file,
1042 inverted_rts_file,
1043 ]
Greg Guterman6963dc082021-04-07 05:20:591044 }
1045 }
1046
Dirk Pranke6188075b2020-10-01 19:31:281047 generate_wrapper(target_name) {
1048 testonly = true
1049 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1050
1051 executable = "//testing/test_env.py"
1052
1053 executable_args =
1054 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1055 if (defined(invoker.args)) {
1056 executable_args += invoker.args
1057 }
1058
Will Harrisd35e2c92021-04-07 01:42:021059 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471060
Dirk Pranke6188075b2020-10-01 19:31:281061 if (defined(invoker.data)) {
1062 data += invoker.data
1063 }
Jamie Madilldd60ee62021-04-13 19:25:521064 if (tests_have_location_tags) {
1065 data += [ "//testing/location_tags.json" ]
1066 }
Dirk Pranke19a58732021-03-24 22:26:221067
Will Harrisd35e2c92021-04-07 01:42:021068 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281069 if (defined(invoker.data_deps)) {
1070 data_deps += invoker.data_deps
1071 }
1072
1073 forward_variables_from(invoker,
1074 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:011075 TESTONLY_AND_VISIBILITY + [
1076 "data",
1077 "data_deps",
1078 "script",
1079 "script_args",
1080 ])
1081 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281082
1083 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591084
1085 if (use_rts) {
1086 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1087 }
Dirk Pranke6188075b2020-10-01 19:31:281088 }
1089}
1090
brettwedb6ecc2016-07-14 23:37:031091# Test defaults.
1092set_defaults("test") {
1093 if (is_android) {
1094 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411095 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591096 configs += [ "//build/config/android:hide_all_but_jni" ]
Andrew Grieved5fdf2af2022-08-23 07:47:551097
1098 # Compress sections to stay under 4gb hard limit on 32-bit current_cpu.
1099 # https://crbug.com/1354616
1100 if (symbol_level == 2 && !use_debug_fission &&
1101 (current_cpu == "arm" || current_cpu == "x86")) {
1102 configs += [ "//build/config:compress_debug_sections" ]
1103 }
brettwedb6ecc2016-07-14 23:37:031104 } else {
1105 configs = default_executable_configs
1106 }
1107}