blob: 004ffe4f5eb38e37d2cff80a819aaf7433c8cd39 [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 != []) {
danakjc858ce72022-12-20 21:39:5181 if (defined(invoker.crate_name)) {
82 _rust_target_name = "${invoker.crate_name}_rust_objects"
83 } else {
84 _rust_target_name = "${target_name}_rust_objects"
85 }
danakj482580a2022-11-18 18:00:5986
87 # We could automatically add `deps += [ "//testing/rust_gtest_interop" ]`
danakjebb9cc4d2022-03-04 21:30:1188 # if `rs_sources` is non-empty. But we don't automatically provide
89 # //testing/gtest either so it would be asymmetric and could break in that
danakj482580a2022-11-18 18:00:5990 # case. So, we act instead as if //testing/rust_gtest_interop is part of
91 # the //testing/gtest dependency. If you add one, and have `rs_sources`
92 # listed, you get both.
danakjebb9cc4d2022-03-04 21:30:1193 _gtest_is_in_deps = false
danakj482580a2022-11-18 18:00:5994 if (defined(invoker.deps) && invoker.deps != []) {
95 foreach(dep, invoker.deps) {
danakjc1f000c2022-11-18 19:31:0696 if (get_label_info(dep, "label_no_toolchain") ==
97 "//testing/gtest:gtest") {
danakjebb9cc4d2022-03-04 21:30:1198 _gtest_is_in_deps = true
99 }
100 }
101 }
danakj482580a2022-11-18 18:00:59102
103 # TODO(danakj): This could be a rust_source_set perhaps, the point being
104 # that we need to link in all the .o object files inside the library,
105 # instead of dropping unreachable ones during linking (which would drop the
106 # tests). Alternatively we could use a special name suffix or other similar
107 # trick perhaps to ensure that all object files are linked in here.
108 rust_static_library(_rust_target_name) {
109 forward_variables_from(invoker,
110 TESTONLY_AND_VISIBILITY + [
danakj482580a2022-11-18 18:00:59111 "deps",
112 "public_deps",
113 ])
114 configs += [ "//build/rust:test" ]
115 generate_crate_root = true
116 sources = _rs_sources
117 if (_gtest_is_in_deps) {
118 deps += [ "//testing/rust_gtest_interop" ]
danakjebb9cc4d2022-03-04 21:30:11119 }
danakjc858ce72022-12-20 21:39:51120
121 # Inform the build system that this library contains gtest unit tests.
122 # They must not be discarded by the linker even though there will be no
123 # edges going into them.
124 is_gtest_unittests = true
danakj482580a2022-11-18 18:00:59125 }
126 } else {
127 not_needed(invoker, _rs_vars)
128 }
129
130 target(invoker.target_type, target_name) {
131 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY + _rs_vars)
132 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
133 sources = _cc_sources
134 if (!defined(deps)) {
135 deps = []
136 }
137 if (_rs_sources != []) {
138 deps += [ ":${_rust_target_name}" ]
danakjebb9cc4d2022-03-04 21:30:11139 }
140 }
141}
142
qsrfb5251d12015-01-21 15:57:22143# Define a test as an executable (or apk on Android) with the "testonly" flag
144# set.
agrieve62ab00282016-04-05 02:03:45145# Variable:
Dirk Pranke79d065d2020-08-29 03:28:30146# use_xvfb: (optional) whether to run the executable under Xvfb.
danakj482580a2022-11-18 18:00:59147# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:56148# use_native_activity: Test implements ANativeActivity_onCreate().
Greg Thompson318cd692022-03-28 08:12:06149# test_runner_shard: (Fuchsia, optional): for CFv2 tests, use the given test
Greg Thompsonfd269652022-10-28 12:06:55150# runner shard rather than the default shard for the ELF runner when
151# assembling the test component. This is useful, for example, to use the
152# elf_test_ambient_exec_runner for tests that require
153# job_policy_ambient_mark_vmo_exec.
154# fuchsia_package_deps: (Fuchsia, optional) List of fuchsia_component()
155# targets that this test package contains.
Chong Guc2f17c32022-11-15 23:14:45156# # TODO(crbug/1280705): remove when all tests are migrated to CFv2.
157# fuchsia_legacy_script_required: (Fuchsia, optional) Whether the old test
158# scripts are required to run the test target.
Mirko Bonadei15522bc2020-09-16 20:38:39159# is_xctest: (iOS, optional) whether to build the executable as XCTest.
160# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
161# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:43162# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
163# network requests during the test.
qsrfb5251d12015-01-21 15:57:22164template("test") {
Greg Guterman6963dc082021-04-07 05:20:59165 # Ensures the rts file exists and if not, creates a dummy file
166 if (use_rts) {
167 action("${target_name}__rts_filters") {
168 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53169 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:05170 inverted_rts_file =
171 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
172 args = [
173 rebase_path(rts_file, root_build_dir),
174 rebase_path(inverted_rts_file, root_build_dir),
175 ]
176 outputs = [
177 rts_file,
178 inverted_rts_file,
179 ]
Greg Guterman6963dc082021-04-07 05:20:59180 }
181 }
182
Andrew Grieve1b290e4a22020-11-24 20:07:01183 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:39184 if (!is_ios) {
185 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
186 "is_xctest can be set only for iOS builds")
187 }
Stefano Duo4128b6b2021-08-02 21:24:43188 if (!is_android) {
189 assert(!defined(invoker.allow_cleartext_traffic),
190 "allow_cleartext_traffic can be set only for Android tests")
191 }
192
qsrfb5251d12015-01-21 15:57:22193 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:30194 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
195
Peter Kotwicz10742f82021-04-15 22:32:50196 _use_default_launcher =
197 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
198 if (!defined(invoker.use_raw_android_executable)) {
199 # Checkouts where build_with_chromium == false often have a custom GN
200 # template wrapper around test() which sets use_default_launcher == false.
201 # Set the _use_raw_android_executable default so that test() targets which
202 # do not use the custom wrapper
203 # (1) Do not cause "gn gen" to fail
204 # (2) Do not need to be moved into if(build_with_chromium) block.
205 _use_raw_android_executable =
206 !build_with_chromium && _use_default_launcher
207 } else {
208 not_needed([ "_use_default_launcher" ])
209 _use_raw_android_executable = invoker.use_raw_android_executable
210 }
qsrfb5251d12015-01-21 15:57:22211
agrieve67855de2016-03-30 14:46:01212 # output_name is used to allow targets with the same name but in different
213 # packages to still produce unique runner scripts.
214 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26215 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01216 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26217 }
agrieve62ab00282016-04-05 02:03:45218
agrieveb355ad152016-04-19 03:45:23219 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42220 _wrapper_script_vars = [
Jamie Madill73b9af332022-08-03 19:27:47221 "android_test_runner_script",
agrievee41ae190d2016-04-25 14:12:51222 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42223 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51224 ]
agrieve3ac557f02016-04-12 15:52:00225
jbudorickced2a252016-06-09 16:38:54226 assert(_use_raw_android_executable || enable_java_templates)
227
agrieve62ab00282016-04-05 02:03:45228 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49229 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
230
agrieve62ab00282016-04-05 02:03:45231 _exec_target = "${target_name}__exec"
232 _dist_target = "${target_name}__dist"
233 _exec_output =
234 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
235
danakjebb9cc4d2022-03-04 21:30:11236 mixed_test(_exec_target) {
237 target_type = "executable"
238
danakje94f40d2022-02-16 18:13:53239 # Configs will always be defined since we set_defaults in
240 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45241 configs = []
Dirk Pranke19a58732021-03-24 22:26:22242 forward_variables_from(
243 invoker,
244 "*",
245 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
246 "data_deps",
247 "extra_dist_files",
248 ])
agrieve62ab00282016-04-05 02:03:45249
250 # Thanks to the set_defaults() for test(), configs are initialized with
251 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59252 configs -= [
253 "//build/config:shared_library_config",
254 "//build/config/android:hide_all_but_jni",
255 ]
agrieve62ab00282016-04-05 02:03:45256 configs += [ "//build/config:executable_config" ]
257
Dirk Pranke19a58732021-03-24 22:26:22258 if (defined(invoker.data_deps)) {
259 data_deps = invoker.data_deps
260 } else {
261 data_deps = []
262 }
263 if (!defined(data)) {
264 data = []
265 }
Jamie Madilldd60ee62021-04-13 19:25:52266 if (tests_have_location_tags) {
267 data += [ "//testing/location_tags.json" ]
268 }
Dirk Pranke19a58732021-03-24 22:26:22269
agrieve62ab00282016-04-05 02:03:45270 # Don't output to the root or else conflict with the group() below.
271 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11272
273 if (use_rts) {
274 data_deps += [ ":${invoker.target_name}__rts_filters" ]
275 }
agrieve62ab00282016-04-05 02:03:45276 }
277
278 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45279 dist_dir = "$root_out_dir/$target_name"
280 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22281 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45282 if (defined(invoker.extra_dist_files)) {
283 extra_files = invoker.extra_dist_files
284 }
Greg Guterman50ed4b42021-04-08 01:15:11285
286 if (use_rts) {
287 if (!defined(data_deps)) {
288 data_deps = []
289 }
290 data_deps += [ ":${invoker.target_name}__rts_filters" ]
291 }
agrieve62ab00282016-04-05 02:03:45292 }
293 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38294 _library_target_name = "${target_name}__library"
danakj98e073722022-02-24 21:01:49295 _library_crate_name = "${target_name}_library"
Andrew Grieveee8aa44d2022-09-23 17:14:38296 _apk_target_name = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45297 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43298 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45299 "android_manifest",
agrievec6811b422016-06-23 02:25:09300 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27301 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55302 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45303 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50304 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07305 "product_config_java_packages",
Andrew Grieve43f24fd02022-04-06 23:04:04306 "loadable_modules",
307 "loadable_module_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02308 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07309 "proguard_configs",
310 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45311 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02312 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45313 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56314 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45315 ]
Siddhartha764226b2018-03-13 02:32:55316
Andrew Grieveee8aa44d2022-09-23 17:14:38317 _add_unwind_tables_in_apk =
318 defined(invoker.add_unwind_tables_in_apk) &&
319 invoker.add_unwind_tables_in_apk && target_cpu == "arm"
Andrew Grieved5fdf2af2022-08-23 07:47:55320
Siddhartha764226b2018-03-13 02:32:55321 # Adds the unwind tables from unstripped binary as an asset file in the
322 # apk, if |add_unwind_tables_in_apk| is specified by the test.
Andrew Grieved5fdf2af2022-08-23 07:47:55323 if (_add_unwind_tables_in_apk) {
Andrew Grieveee8aa44d2022-09-23 17:14:38324 # TODO(crbug.com/1315603): Remove generation of v1 unwind asset when
Tushar Agarwaldcafb622022-11-30 17:32:27325 # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroid`.
Andrew Grieveee8aa44d2022-09-23 17:14:38326 _unwind_table_name = "${_library_target_name}_unwind_v1"
327 unwind_table_v1(_unwind_table_name) {
328 library_target = ":$_library_target_name"
329 }
330
Arthur Sonzogni54424e92022-09-23 13:30:45331 if (use_android_unwinder_v2) {
Andrew Grieveee8aa44d2022-09-23 17:14:38332 _unwind_table_v2_name = "${_library_target_name}_unwind_v2"
333 unwind_table_v2(_unwind_table_v2_name) {
334 library_target = ":$_library_target_name"
Arthur Sonzogni54424e92022-09-23 13:30:45335 }
336 }
337
Andrew Grieveee8aa44d2022-09-23 17:14:38338 _unwind_table_asset_name = "${target_name}__unwind_assets"
339 android_assets(_unwind_table_asset_name) {
340 sources = [ "$target_out_dir/$_unwind_table_name/$unwind_table_asset_v1_filename" ]
341 disable_compression = true
342 deps = [ ":$_unwind_table_name" ]
343 if (use_android_unwinder_v2) {
344 sources += [ "$target_out_dir/$_unwind_table_v2_name/$unwind_table_asset_v2_filename" ]
345 deps += [ ":$_unwind_table_v2_name" ]
346 }
Siddhartha764226b2018-03-13 02:32:55347 }
348 }
349
Andrew Grieveee8aa44d2022-09-23 17:14:38350 mixed_test(_library_target_name) {
danakjebb9cc4d2022-03-04 21:30:11351 target_type = "shared_library"
352
danakj98e073722022-02-24 21:01:49353 # Configs will always be defined since we set_defaults in
354 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45355 configs = [] # Prevent list overwriting warning.
356 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45357
Andrew Grieved5fdf2af2022-08-23 07:47:55358 if (_add_unwind_tables_in_apk) {
359 # Remove -gz if present, as dump_syms does not support it.
360 # Add and then remove because "-=" removes all, but errors if none are found.
361 configs += [ "//build/config:compress_debug_sections" ]
362 configs -= [ "//build/config:compress_debug_sections" ]
363 }
364
jbudorickd29ecfa72016-11-18 22:45:42365 forward_variables_from(
366 invoker,
367 "*",
Andrew Grieved5fdf2af2022-08-23 07:47:55368 [
369 "configs",
370 "deps",
371 ] + _apk_specific_vars + _wrapper_script_vars +
Peter Wen2052bd12020-12-03 20:15:07372 TESTONLY_AND_VISIBILITY)
373
danakj482580a2022-11-18 18:00:59374 # Use a crate name that avoids creating a warning due to double
375 # underscore (ie. `__`).
376 crate_name = _library_crate_name
377
Peter Wen2052bd12020-12-03 20:15:07378 # Native targets do not need to depend on java targets. Filter them out
379 # so that the shared library can be built without needing to wait for
380 # dependent java targets.
381 deps = []
382 if (defined(invoker.deps)) {
Andrew Grieve841ed072022-08-23 16:42:33383 deps = filter_exclude(invoker.deps, java_target_patterns)
Peter Wen2052bd12020-12-03 20:15:07384 }
agrieve62ab00282016-04-05 02:03:45385
Peter Kotwiczb9957d62021-04-12 21:09:43386 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37387 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45388 }
389 }
Andrew Grieveee8aa44d2022-09-23 17:14:38390 unittest_apk(_apk_target_name) {
Daniel Bratellfdda4652019-01-31 15:45:54391 forward_variables_from(invoker, _apk_specific_vars)
Andrew Grieveee8aa44d2022-09-23 17:14:38392 shared_library = ":$_library_target_name"
agrieve62ab00282016-04-05 02:03:45393 apk_name = invoker.target_name
394 if (defined(invoker.output_name)) {
395 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45396 install_script_name = "install_${invoker.output_name}"
397 }
agrieveb355ad152016-04-19 03:45:23398
Daniel Bratellfdda4652019-01-31 15:45:54399 if (defined(invoker.deps)) {
400 deps = invoker.deps
401 } else {
402 deps = []
403 }
Andrew Grieve43f24fd02022-04-06 23:04:04404 if (defined(loadable_module_deps)) {
405 deps += loadable_module_deps
406 }
Daniel Bratellfdda4652019-01-31 15:45:54407
jcivellif4462a352017-01-10 04:45:59408 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43409 if (_use_default_launcher) {
410 deps += [ "//base/test:test_support_java" ]
411 }
jcivellif4462a352017-01-10 04:45:59412
Siddhartha764226b2018-03-13 02:32:55413 if (defined(_unwind_table_asset_name)) {
414 deps += [ ":${_unwind_table_asset_name}" ]
415 }
Greg Guterman50ed4b42021-04-08 01:15:11416
417 if (use_rts) {
418 data_deps = [ ":${invoker.target_name}__rts_filters" ]
419 }
agrieve62ab00282016-04-05 02:03:45420 }
Andrew Grievee1dc23f2019-10-22 16:26:36421 }
agrieve62ab00282016-04-05 02:03:45422
Andrew Grievee1dc23f2019-10-22 16:26:36423 test_runner_script(_test_runner_target) {
424 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57425
Andrew Grievee1dc23f2019-10-22 16:26:36426 if (_use_raw_android_executable) {
427 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34428 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36429 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38430 apk_target = ":$_apk_target_name"
Andrew Grievee1dc23f2019-10-22 16:26:36431 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47432
433 # Dep needed for the test runner .runtime_deps file to pick up data
434 # deps from the forward_variables_from(invoker, "*") on the library.
Andrew Grieveee8aa44d2022-09-23 17:14:38435 data_deps = [ ":$_library_target_name" ]
agrieve62ab00282016-04-05 02:03:45436 }
Andrew Grievee1dc23f2019-10-22 16:26:36437 test_name = _output_name
438 test_suite = _output_name
439 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59440
441 if (use_rts) {
442 data_deps += [ ":${invoker.target_name}__rts_filters" ]
443 }
mikecase56d80d72015-06-03 00:57:26444 }
445
Andrew Grieve7ca6de32019-10-18 03:57:47446 # Create a wrapper script rather than using a group() in order to ensure
447 # "ninja $target_name" always works. If this was a group(), then GN would
448 # not create a top-level alias for it if a target exists in another
449 # directory with the same $target_name.
450 # Also - bots run this script directly for "components_perftests".
451 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01452 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47453 executable = "$root_build_dir/bin/run_$_output_name"
454 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22455 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40456 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47457 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40458 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47459 # Dep needed for the swarming .isolate file to pick up data
460 # deps from the forward_variables_from(invoker, "*") on the library.
461 deps += [
Andrew Grieveee8aa44d2022-09-23 17:14:38462 ":$_apk_target_name",
463 ":$_library_target_name",
Andrew Grieve7ca6de32019-10-18 03:57:47464 ]
agrieve62ab00282016-04-05 02:03:45465 }
Dirk Pranke19a58732021-03-24 22:26:22466
467 if (defined(invoker.data_deps)) {
468 data_deps = invoker.data_deps
469 } else {
470 data_deps = []
471 }
Kevin Marshall23529362022-02-23 16:50:36472
473 data_deps += [ "//testing:test_scripts_shared" ]
474
Jamie Madilldd60ee62021-04-13 19:25:52475 if (tests_have_location_tags) {
476 data = [ "//testing/location_tags.json" ]
477 }
Greg Guterman6963dc082021-04-07 05:20:59478
479 if (use_rts) {
480 data_deps += [ ":${invoker.target_name}__rts_filters" ]
481 }
agrieve1a02e582015-10-15 21:35:39482 }
Scott Graham4c4cdc52017-05-29 20:45:03483 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30484 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
485
Scott Graham4c4cdc52017-05-29 20:45:03486 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42487 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42488 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb42022-04-05 12:30:35489 _program_name = get_label_info(":${_exec_target}", "name")
Scott Graham4c4cdc52017-05-29 20:45:03490
Greg Thompson2f1e3762022-10-17 19:53:44491 # Generate a CML fragment that provides the program name.
492 _test_program_fragment_target = "${target_name}_program-fragment"
493 _test_program_fragment = "${target_out_dir}/${target_name}_program.test-cml"
494 generated_file(_test_program_fragment_target) {
495 contents = {
496 program = {
497 binary = _program_name
Kevin Marshall2ec60032022-05-09 17:38:28498 }
Greg Thompson26516592021-12-16 08:34:45499 }
Greg Thompson2f1e3762022-10-17 19:53:44500 outputs = [ _test_program_fragment ]
501 output_conversion = "json"
Greg Thompson9765eeb42022-04-05 12:30:35502 }
503
Chong Guc2f17c32022-11-15 23:14:45504 use_v2_script = use_v2_script_default
505 if (defined(invoker.fuchsia_legacy_script_required) &&
506 invoker.fuchsia_legacy_script_required) {
507 use_v2_script = false
508 }
509
Greg Thompson2f1e3762022-10-17 19:53:44510 _test_runner_shard =
511 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
512 if (defined(invoker.test_runner_shard)) {
513 _test_runner_shard = invoker.test_runner_shard
Wez6879f8a2021-09-07 20:27:02514 }
515
Greg Thompson2f1e3762022-10-17 19:53:44516 # Collate the complete set of elements to include in the test component's
517 # manifest.
David Dorwin2c4872c2023-02-22 20:00:56518
Greg Thompson2f1e3762022-10-17 19:53:44519 _manifest_fragments = [
Greg Thompson2f1e3762022-10-17 19:53:44520 _test_program_fragment,
521 _test_runner_shard,
522 ]
523
David Dorwin2c4872c2023-02-22 20:00:56524 # Select the Fuchsia test realm in which to run the test.
525 if (defined(invoker.run_as_chromium_system_test) &&
526 invoker.run_as_chromium_system_test) {
527 _manifest_fragments += [
528 "//build/config/fuchsia/test/chromium_system_test_facet.shard.test-cml",
529 "//build/config/fuchsia/test/system_test_minimum.shard.test-cml",
530 ]
531 } else {
532 _manifest_fragments += [
533 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
534 "//build/config/fuchsia/test/minimum.shard.test-cml",
535 ]
536 }
537
Greg Thompson2f1e3762022-10-17 19:53:44538 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
539 _merged_manifest_name = "${_output_name}.cml"
540
541 if (defined(invoker.additional_manifest_fragments)) {
542 _manifest_fragments += invoker.additional_manifest_fragments
543 }
544
545 # Generate the test component manifest from the specified elements.
546 _test_component_manifest_target = "${target_name}_component-manifest"
547 cmc_merge(_test_component_manifest_target) {
548 sources = _manifest_fragments
549 output_name = "${_merged_manifest_name}"
550 deps = [ ":${_test_program_fragment_target}" ]
551 }
552
553 # Define the test component, dependent on the generated manifest, and the
554 # test executable target.
555 _test_component_target = "${target_name}_component"
556 fuchsia_component(_test_component_target) {
557 deps = [ ":$_test_component_manifest_target" ]
558 data_deps = [ ":$_exec_target" ]
559 manifest = _test_component_manifest
560 visibility = [ ":*" ]
561 }
562
563 _test_component_targets = [ ":${_test_component_target}" ]
564
Wez6879f8a2021-09-07 20:27:02565 # Define components for each entry in |additional_manifests|, if any. Since
566 # manifests may themselves depend-on the outputs of |deps|, these components
567 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02568 if (defined(invoker.additional_manifests)) {
569 foreach(filename, invoker.additional_manifests) {
570 _additional_component_target =
571 target_name + "_" + get_path_info(filename, "name")
572 _test_component_targets += [ ":${_additional_component_target}" ]
573 fuchsia_component(_additional_component_target) {
574 forward_variables_from(invoker, [ "testonly" ])
575 data_deps = [ ":$_exec_target" ]
576 visibility = [ ":*" ]
577 manifest = filename
578
579 # Depend on |invoker.deps|, in case it includes a dependency that
580 # creates this additional component's manifest.
581 if (defined(invoker.deps)) {
582 deps = invoker.deps
583 }
584 }
585 }
586 }
587
588 # Define the package target that will bundle the test and additional
589 # components and their data.
590 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21591 forward_variables_from(invoker,
592 [
593 "excluded_files",
594 "excluded_dirs",
Bryant Chandlerc40f2672023-01-27 23:33:30595 "excluded_paths",
Kevin Marshall36c602c2021-11-04 16:16:21596 ])
Wez6879f8a2021-09-07 20:27:02597 package_name = _output_name
598 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21599
Greg Thompsonfd269652022-10-28 12:06:55600 if (defined(invoker.fuchsia_package_deps)) {
601 deps += invoker.fuchsia_package_deps
602 }
Bryant Chandlerc40f2672023-01-27 23:33:30603 if (!defined(excluded_paths)) {
604 excluded_paths = []
Kevin Marshall36c602c2021-11-04 16:16:21605 }
Bryant Chandlerc40f2672023-01-27 23:33:30606 excluded_paths += [
607 "${devtools_root_location}/*",
608 "*.git/*",
609 "*.svn/*",
610 "*.hg/*",
611 ]
Sarah Pham80972efc2022-05-31 17:40:15612 if (devtools_root_location != "") {
Bryant Chandlerc40f2672023-01-27 23:33:30613 excluded_paths += [ "${devtools_root_location}/*" ]
Sarah Pham80972efc2022-05-31 17:40:15614 }
Wez6879f8a2021-09-07 20:27:02615 }
616
617 # |target_name| refers to the package-runner rule, so that building
618 # "base_unittests" will build not only the executable, component, and
619 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25620 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53621 forward_variables_from(invoker,
622 [
Kevin Marshall5fadadd2021-10-16 00:08:25623 "data",
624 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53625 "package_deps",
Kevin Marshall5fadadd2021-10-16 00:08:25626 "use_test_server",
Chong Guc2f17c32022-11-15 23:14:45627 "use_v2_script",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53628 ])
Kevin Marshall5fadadd2021-10-16 00:08:25629
Chong Guc6bfdf62021-10-20 23:37:00630 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15631 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25632 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42633
Kevin Marshall5fadadd2021-10-16 00:08:25634 if (!defined(deps)) {
635 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52636 }
Kevin Marshall5fadadd2021-10-16 00:08:25637 if (defined(invoker.deps)) {
638 deps += invoker.deps
639 }
Greg Guterman6963dc082021-04-07 05:20:59640
Kevin Marshall5fadadd2021-10-16 00:08:25641 if (!defined(data)) {
642 data = []
643 }
644 if (tests_have_location_tags) {
645 data += [ "//testing/location_tags.json" ]
646 }
647
648 if (!defined(data_deps)) {
649 data_deps = []
650 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28651
Kevin Marshall23529362022-02-23 16:50:36652 data_deps += [ "//testing:test_scripts_shared" ]
653
Greg Guterman6963dc082021-04-07 05:20:59654 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25655 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59656 }
Kevin Marshallf35fa5f2018-01-29 19:24:42657 }
658
danakjebb9cc4d2022-03-04 21:30:11659 mixed_test(_exec_target) {
660 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01661 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42662 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03663 }
dpranke2a294622015-08-07 05:23:01664 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30665 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46666 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30667
Rohit Raof9b096d2019-09-09 22:26:23668 declare_args() {
669 # Keep the unittest-as-xctest functionality defaulted to off until the
670 # bots are updated to handle it properly.
671 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
672 # supports running unittests with xctest.
673 enable_run_ios_unittests_with_xctest = false
674 }
675
sdefresne012857872016-03-16 10:55:37676 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27677 _output_name = target_name
678 if (defined(invoker.output_name)) {
679 _output_name = invoker.output_name
680 }
681
Jeff Yoonf7f4eb42020-03-06 18:55:36682 _wrapper_output_name = "run_${target_name}"
683 ios_test_runner_wrapper(_wrapper_output_name) {
684 forward_variables_from(invoker,
685 [
686 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36687 "deps",
688 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27689 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36690 "retries",
691 "shards",
692 ])
693
694 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
695
696 if (!defined(executable_args)) {
697 executable_args = []
698 }
699 executable_args += [
700 "--app",
701 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
702 ]
703
704 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22705
706 if (!defined(data)) {
707 data = []
708 }
Jamie Madilldd60ee62021-04-13 19:25:52709 if (tests_have_location_tags) {
710 data += [ "//testing/location_tags.json" ]
711 }
Jeff Yoonf7f4eb42020-03-06 18:55:36712 }
713
sdefresne012857872016-03-16 10:55:37714 _resources_bundle_data = target_name + "_resources_bundle_data"
715
716 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34717 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22718 sources = [ "//testing/gtest_ios/Default.png" ]
719 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01720 }
721
Mirko Bonadei15522bc2020-09-16 20:38:39722 force_xctest = enable_run_ios_unittests_with_xctest ||
723 (defined(invoker.is_xctest) && invoker.is_xctest)
724
danakjfae603fc602022-11-18 18:40:22725 mixed_test(_test_target) {
726 if (force_xctest) {
727 target_type = "ios_xctest_test"
728 } else {
729 target_type = "ios_app_bundle"
730 }
dpranke2a294622015-08-07 05:23:01731 testonly = true
sdefresnea828c282016-05-30 18:04:20732
Mirko Bonadei15522bc2020-09-16 20:38:39733 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23734 xctest_module_target = "//base/test:google_test_runner"
735 }
736
Andrew Grieve1b290e4a22020-11-24 20:07:01737 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13738
739 # Provide sensible defaults in case invoker did not define any of those
740 # required variables.
sdefresne05b97ca2016-06-08 07:19:46741 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13742 info_plist = "//testing/gtest_ios/unittest-Info.plist"
743 }
sdefresne9e147e02016-06-07 00:10:13744
Sylvain Defresne3c5a1312021-09-23 17:08:09745 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13746 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50747 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09748 } else {
Ali Juma75be0fe2022-01-24 19:39:29749 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27750 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09751 }
dpranke2a294622015-08-07 05:23:01752
sdefresne047490e2016-07-22 08:49:34753 if (!defined(bundle_deps)) {
754 bundle_deps = []
755 }
756 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36757
758 if (!defined(data_deps)) {
759 data_deps = []
760 }
761
Kevin Marshall23529362022-02-23 16:50:36762 data_deps += [ "//testing:test_scripts_shared" ]
763
Jeff Yoonf7f4eb42020-03-06 18:55:36764 # Include the generate_wrapper as part of data_deps
765 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46766 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59767
768 if (use_rts) {
769 data_deps += [ ":${invoker.target_name}__rts_filters" ]
770 }
dpranke2a294622015-08-07 05:23:01771 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11772 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
773 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30774 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
775
Yuke Liao2a9b2f0e2021-04-16 00:40:11776 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32777
Benjamin Pastene3bce864e2018-04-14 01:16:32778 _gen_runner_target = "${target_name}__runner"
779 _runtime_deps_file =
780 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
781 "/" + get_label_info(target_name, "name") + ".runtime_deps"
782
Xinan Lin6be01252021-06-25 23:07:36783 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
784 if (is_skylab) {
Struan Shrimptonf61293f62022-04-11 19:33:40785 generate_skylab_deps(_gen_runner_target) {
Xinan Lin6be01252021-06-25 23:07:36786 generated_script = _generated_script
787 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34788 }
Xinan Lin6be01252021-06-25 23:07:36789 } else {
790 generate_runner_script(_gen_runner_target) {
791 generated_script = _generated_script
792 test_exe = invoker.target_name
793 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34794
Xinan Lin6be01252021-06-25 23:07:36795 if (is_chromeos_lacros) {
796 # At build time, Lacros tests don't know whether they'll run on VM or
797 # HW, and instead, these flags are specified at runtime when invoking
798 # the generated runner script.
799 skip_generating_board_args = true
800 }
Greg Guterman6963dc082021-04-07 05:20:59801
Xinan Lin6be01252021-06-25 23:07:36802 if (tests_have_location_tags) {
803 data = [ "//testing/location_tags.json" ]
804 }
805
806 if (use_rts) {
807 data_deps = [ ":${invoker.target_name}__rts_filters" ]
808 }
Greg Guterman6963dc082021-04-07 05:20:59809 }
Benjamin Pastene3bce864e2018-04-14 01:16:32810 }
811
danakjebb9cc4d2022-03-04 21:30:11812 mixed_test(target_name) {
813 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01814 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
815 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32816 if (!defined(deps)) {
817 deps = []
818 }
819 if (!defined(data)) {
820 data = []
821 }
822
Ben Pastene41041782019-02-16 04:21:58823 # We use a special trigger script for CrOS hardware tests.
824 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
825
Benjamin Pastene3bce864e2018-04-14 01:16:32826 output_name = target_name
827 write_runtime_deps = _runtime_deps_file
828 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37829 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59830
Kevin Marshall23529362022-02-23 16:50:36831 if (!defined(data_deps)) {
832 data_deps = []
833 }
834
835 data_deps += [ "//testing:test_scripts_shared" ]
836
Greg Guterman6963dc082021-04-07 05:20:59837 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59838 data_deps += [ ":${invoker.target_name}__rts_filters" ]
839 }
Benjamin Pastene3bce864e2018-04-14 01:16:32840 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11841 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24842 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
843 _executable = target_name
844 _gen_runner_target = "${target_name}__runner"
845
Yuke Liao32af4242020-07-16 21:48:02846 if (defined(invoker.use_xvfb)) {
847 _use_xvfb = invoker.use_xvfb
848 } else {
849 _use_xvfb = false
850 }
851
Yuke Liaod037abc2020-10-06 22:48:22852 # When use_xvfb is set by the invoker, it indicates that running this test
853 # target requires a window, and in lacros build, ash-chrome serves as the
854 # display server. Note that even though the tests themselves do not require
855 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
856 # because ash-chrome is based on x11.
857 _use_ash_chrome = _use_xvfb
858
Yuke Liaoe703384b2020-07-16 01:05:24859 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24860 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02861
Yuke Liao2e4953cf2020-07-26 19:20:19862 data = []
Will Harrisd35e2c92021-04-07 01:42:02863 data_deps = [ "//testing:test_scripts_shared" ]
864
Yuke Liao32af4242020-07-16 21:48:02865 if (_use_xvfb) {
866 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22867 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02868 } else {
869 executable = "//testing/test_env.py"
870 }
Jamie Madilldd60ee62021-04-13 19:25:52871 if (tests_have_location_tags) {
872 data += [ "//testing/location_tags.json" ]
873 }
Yuke Liao32af4242020-07-16 21:48:02874
Yuke Liaoe703384b2020-07-16 01:05:24875 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02876 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39877 "test",
Yuke Liaoe703384b2020-07-16 01:05:24878 "@WrappedPath(./${_executable})",
879 "--test-launcher-bot-mode",
880 ]
Yuke Liao32af4242020-07-16 21:48:02881
Yuke Liaof540c742020-07-29 16:28:34882 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37883 executable_args += [ "--ash-chrome-path" ]
884
885 # Can't use --ash-chrome-path=path because WrappedPath
886 # won't be expanded for that usage.
887 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39888 }
889
Yuke Liaoe703384b2020-07-16 01:05:24890 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:00891 executable_args += [ "--asan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24892 }
893 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:00894 executable_args += [ "--msan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24895 }
896 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:00897 executable_args += [ "--tsan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24898 }
899 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:00900 executable_args += [ "--cfi-diag=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24901 }
902
Takuto Ikuta38ebd0e2022-01-19 17:56:22903 data += [ "//build/lacros/test_runner.py" ]
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 }
909
danakjebb9cc4d2022-03-04 21:30:11910 mixed_test(target_name) {
911 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01912 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
913 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24914 if (!defined(deps)) {
915 deps = []
916 }
917
Yuke Liaod037abc2020-10-06 22:48:22918 if (!defined(data_deps)) {
919 data_deps = []
920 }
921
Kevin Marshall23529362022-02-23 16:50:36922 data_deps += [ "//testing:test_scripts_shared" ]
923
Yuke Liaoe703384b2020-07-16 01:05:24924 write_runtime_deps = _runtime_deps_file
925 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22926 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56927 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22928 }
Greg Guterman6963dc082021-04-07 05:20:59929
930 if (use_rts) {
931 data_deps += [ ":${invoker.target_name}__rts_filters" ]
932 }
Yuke Liaoe703384b2020-07-16 01:05:24933 }
Dirk Prankedd4ff742020-11-18 19:57:32934 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30935 if (is_mac || is_win) {
936 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
937 }
938
Dirk Prankedd4ff742020-11-18 19:57:32939 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
940 _executable = target_name
941 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06942
Dirk Prankedd4ff742020-11-18 19:57:32943 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
944 _use_xvfb = invoker.use_xvfb
945 } else {
946 _use_xvfb = false
947 }
948
949 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32950 wrapper_script = "$root_build_dir/bin/run_" + _executable
951
952 data = []
Will Harrisd35e2c92021-04-07 01:42:02953 data_deps = [ "//testing:test_scripts_shared" ]
954
Dirk Prankedd4ff742020-11-18 19:57:32955 if (_use_xvfb) {
956 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06957 } else {
Dirk Prankedd4ff742020-11-18 19:57:32958 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06959 }
Jamie Madilldd60ee62021-04-13 19:25:52960 if (tests_have_location_tags) {
961 data += [ "//testing/location_tags.json" ]
962 }
Dirk Pranke31e346e2020-07-15 00:54:06963
Dirk Prankedd4ff742020-11-18 19:57:32964 executable_args = [
965 "@WrappedPath(./${_executable})",
966 "--test-launcher-bot-mode",
967 ]
968 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:00969 executable_args += [ "--asan=1" ]
Dirk Pranke31e346e2020-07-15 00:54:06970 }
Dirk Prankedd4ff742020-11-18 19:57:32971 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:00972 executable_args += [ "--msan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:32973 }
974 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:00975 executable_args += [ "--tsan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:32976 }
977 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:00978 executable_args += [ "--cfi-diag=1" ]
Dirk Prankedd4ff742020-11-18 19:57:32979 }
980
Greg Guterman6963dc082021-04-07 05:20:59981 if (use_rts) {
982 data_deps += [ ":${invoker.target_name}__rts_filters" ]
983 }
Dirk Pranke31e346e2020-07-15 00:54:06984 }
985
danakjebb9cc4d2022-03-04 21:30:11986 mixed_test(target_name) {
987 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01988 forward_variables_from(invoker,
989 "*",
990 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
991 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06992 if (!defined(deps)) {
993 deps = []
994 }
995
Dirk Pranke31e346e2020-07-15 00:54:06996 deps += [
997 # Give tests the default manifest on Windows (a no-op elsewhere).
998 "//build/win:default_exe_manifest",
999 ]
1000
Dirk Prankedd4ff742020-11-18 19:57:321001 write_runtime_deps = _runtime_deps_file
1002 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:111003
Kevin Marshall23529362022-02-23 16:50:361004 if (!defined(data_deps)) {
1005 data_deps = []
1006 }
1007
1008 data_deps += [ "//testing:test_scripts_shared" ]
1009
Greg Guterman50ed4b42021-04-08 01:15:111010 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:111011 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1012 }
Dirk Prankedd4ff742020-11-18 19:57:321013 }
1014 } else {
1015 # This is a catch-all clause for NaCl toolchains and other random
1016 # configurations that might define tests; test() in these configs
1017 # will just define the underlying executables.
1018 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
1019 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:111020 mixed_test(target_name) {
1021 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011022 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1023 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:321024 if (!defined(deps)) {
1025 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061026 }
Greg Guterman6963dc082021-04-07 05:20:591027
Kevin Marshall23529362022-02-23 16:50:361028 if (!defined(data_deps)) {
1029 data_deps = []
1030 }
1031
1032 data_deps += [ "//testing:test_scripts_shared" ]
1033
Greg Guterman6963dc082021-04-07 05:20:591034 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:591035 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1036 }
Dirk Pranke31e346e2020-07-15 00:54:061037 }
qsrfb5251d12015-01-21 15:57:221038 }
1039}
brettwedb6ecc2016-07-14 23:37:031040
Dirk Pranke6188075b2020-10-01 19:31:281041# Defines a type of test that invokes a script to run, rather than
1042# invoking an executable.
1043#
1044# The script must implement the
1045# [test executable API](//docs/testing/test_executable_api.md).
1046#
Andrew Grievea16222d42023-02-10 15:31:101047# The template must be passed the `script` parameter, which specifies the path
1048# to the script to run. It may optionally be passed a `args` parameter, which
1049# can be used to include a list of args to be specified by default. The
1050# template will produce a `$root_build_dir/run_$target_name` wrapper and write
1051# the runtime_deps for the target to
1052# $root_build_dir/${target_name}.runtime_deps, as per the conventions listed in
1053# the [test wrapper API](//docs/testing/test_wrapper_api.md).
Dirk Pranke6188075b2020-10-01 19:31:281054template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:591055 if (use_rts) {
1056 action("${target_name}__rts_filters") {
1057 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:531058 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:051059 inverted_rts_file =
1060 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
1061 args = [
1062 rebase_path(rts_file, root_build_dir),
1063 rebase_path(inverted_rts_file, root_build_dir),
1064 ]
1065 outputs = [
1066 rts_file,
1067 inverted_rts_file,
1068 ]
Greg Guterman6963dc082021-04-07 05:20:591069 }
1070 }
1071
Dirk Pranke6188075b2020-10-01 19:31:281072 generate_wrapper(target_name) {
1073 testonly = true
1074 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1075
1076 executable = "//testing/test_env.py"
1077
1078 executable_args =
1079 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1080 if (defined(invoker.args)) {
1081 executable_args += invoker.args
1082 }
1083
Will Harrisd35e2c92021-04-07 01:42:021084 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471085
Dirk Pranke6188075b2020-10-01 19:31:281086 if (defined(invoker.data)) {
1087 data += invoker.data
1088 }
Jamie Madilldd60ee62021-04-13 19:25:521089 if (tests_have_location_tags) {
1090 data += [ "//testing/location_tags.json" ]
1091 }
Dirk Pranke19a58732021-03-24 22:26:221092
Will Harrisd35e2c92021-04-07 01:42:021093 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281094 if (defined(invoker.data_deps)) {
1095 data_deps += invoker.data_deps
1096 }
1097
1098 forward_variables_from(invoker,
Andrew Grievea16222d42023-02-10 15:31:101099 "*",
Andrew Grieve1b290e4a22020-11-24 20:07:011100 TESTONLY_AND_VISIBILITY + [
Andrew Grievea16222d42023-02-10 15:31:101101 "args",
Andrew Grieve1b290e4a22020-11-24 20:07:011102 "data",
1103 "data_deps",
1104 "script",
Andrew Grieve1b290e4a22020-11-24 20:07:011105 ])
1106 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281107
1108 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591109
1110 if (use_rts) {
1111 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1112 }
Dirk Pranke6188075b2020-10-01 19:31:281113 }
1114}
1115
Andrew Grievea16222d42023-02-10 15:31:101116# Defines a test target that uses exit code for pass/fail.
1117template("isolated_script_test") {
1118 script_test(target_name) {
1119 forward_variables_from(invoker,
1120 "*",
1121 TESTONLY_AND_VISIBILITY + [
1122 "args",
1123 "deps",
1124 "script",
1125 ])
1126 forward_variables_from(invoker, [ "visibility" ])
1127 deps = [ "//testing:run_isolated_script_test" ]
1128 if (defined(invoker.deps)) {
1129 deps += invoker.deps
1130 }
1131 script = "//testing/scripts/run_isolated_script_test.py"
1132 data = [ invoker.script ]
1133 args = [
1134 rebase_path(invoker.script, root_build_dir),
1135 "--script-type=bare",
1136 ]
1137 if (defined(invoker.args)) {
1138 args += invoker.args
1139 }
1140 }
1141}
1142
brettwedb6ecc2016-07-14 23:37:031143# Test defaults.
1144set_defaults("test") {
1145 if (is_android) {
1146 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411147 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591148 configs += [ "//build/config/android:hide_all_but_jni" ]
Andrew Grieved5fdf2af2022-08-23 07:47:551149
1150 # Compress sections to stay under 4gb hard limit on 32-bit current_cpu.
1151 # https://crbug.com/1354616
1152 if (symbol_level == 2 && !use_debug_fission &&
1153 (current_cpu == "arm" || current_cpu == "x86")) {
1154 configs += [ "//build/config:compress_debug_sections" ]
1155 }
brettwedb6ecc2016-07-14 23:37:031156 } else {
1157 configs = default_executable_configs
1158 }
1159}