blob: b5584dff4a2e2140b040102cf08b32ff4ee372b5 [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")
Sam Maier7acb8d6b2023-05-15 14:00:2240 import("//build/config/android/jni.gni")
jcivellif4462a352017-01-10 04:45:5941 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4442 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3243} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0644 import("//build/config/chromecast_build.gni")
Kevin Marshall55fd8522019-10-04 22:47:0145 import("//build/config/fuchsia/generate_runner_scripts.gni")
Chong Gu26908f4e2021-01-29 03:13:0746 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Greg Thompson76d83b42022-09-15 14:30:3547 import("//third_party/fuchsia-sdk/sdk/build/component.gni")
48 import("//third_party/fuchsia-sdk/sdk/build/package.gni")
Nico Weberd73c90382022-03-30 20:37:5049} else if (is_chromeos && is_chromeos_device) {
Ben Pastene4c35c572018-04-30 23:21:4850 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3251 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2852 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3253} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3654 import("//build/config/ios/ios_sdk.gni")
55 import("//build/config/ios/ios_test_runner_wrapper.gni")
56 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3257} else {
Dirk Pranke31e346e2020-07-15 00:54:0658 import("//build/config/sanitizers/sanitizers.gni")
59 import("//build/util/generate_wrapper.gni")
60}
61
danakj482580a2022-11-18 18:00:5962# This template generates the test target (of type `target_type`) but also
63# generates a rust library that includes all .rs files found in sources and
64# depends on that from the test target.
danakjebb9cc4d2022-03-04 21:30:1165template("mixed_test") {
66 assert(defined(invoker.target_type) && invoker.target_type != "")
danakjebb9cc4d2022-03-04 21:30:1167
danakjca3cae62023-04-12 15:20:5768 # The crate_root variable would transform the target into a Rust binary
69 # which is incorrect. To not use a generated crate root set:
70 # ```
71 # test_crate_root = "path/to/root.rs"
72 # ```
73 assert(!defined(invoker.crate_root))
74
danakj482580a2022-11-18 18:00:5975 _rs_vars = [
76 "sources", # We split this list into two.
77 "crate_name", # Android test template overrides the crate name.
78 ]
danakjaa85aad2022-03-10 18:45:1079
danakj482580a2022-11-18 18:00:5980 if (defined(invoker.sources)) {
81 _rs_sources = filter_include(invoker.sources, [ "*.rs" ])
82 _cc_sources = filter_exclude(invoker.sources, [ "*.rs" ])
83 } else {
84 _rs_sources = []
85 _cc_sources = []
86 }
87
88 if (_rs_sources != []) {
danakjc858ce72022-12-20 21:39:5189 if (defined(invoker.crate_name)) {
90 _rust_target_name = "${invoker.crate_name}_rust_objects"
91 } else {
92 _rust_target_name = "${target_name}_rust_objects"
93 }
danakj482580a2022-11-18 18:00:5994
95 # We could automatically add `deps += [ "//testing/rust_gtest_interop" ]`
danakjebb9cc4d2022-03-04 21:30:1196 # if `rs_sources` is non-empty. But we don't automatically provide
97 # //testing/gtest either so it would be asymmetric and could break in that
danakj482580a2022-11-18 18:00:5998 # case. So, we act instead as if //testing/rust_gtest_interop is part of
99 # the //testing/gtest dependency. If you add one, and have `rs_sources`
100 # listed, you get both.
danakjebb9cc4d2022-03-04 21:30:11101 _gtest_is_in_deps = false
danakj482580a2022-11-18 18:00:59102 if (defined(invoker.deps) && invoker.deps != []) {
103 foreach(dep, invoker.deps) {
danakjc1f000c2022-11-18 19:31:06104 if (get_label_info(dep, "label_no_toolchain") ==
105 "//testing/gtest:gtest") {
danakjebb9cc4d2022-03-04 21:30:11106 _gtest_is_in_deps = true
107 }
108 }
109 }
danakj482580a2022-11-18 18:00:59110
111 # TODO(danakj): This could be a rust_source_set perhaps, the point being
112 # that we need to link in all the .o object files inside the library,
113 # instead of dropping unreachable ones during linking (which would drop the
114 # tests). Alternatively we could use a special name suffix or other similar
115 # trick perhaps to ensure that all object files are linked in here.
116 rust_static_library(_rust_target_name) {
117 forward_variables_from(invoker,
118 TESTONLY_AND_VISIBILITY + [
danakjca3cae62023-04-12 15:20:57119 "allow_unsafe",
danakj482580a2022-11-18 18:00:59120 "deps",
danakjca3cae62023-04-12 15:20:57121 "generate_crate_root",
danakj482580a2022-11-18 18:00:59122 "public_deps",
123 ])
124 configs += [ "//build/rust:test" ]
danakjca3cae62023-04-12 15:20:57125 if (defined(invoker.test_crate_root)) {
126 crate_root = invoker.test_crate_root
127 } else {
128 generate_crate_root = true
129 }
danakj482580a2022-11-18 18:00:59130 sources = _rs_sources
danakjca3cae62023-04-12 15:20:57131
danakj482580a2022-11-18 18:00:59132 if (_gtest_is_in_deps) {
133 deps += [ "//testing/rust_gtest_interop" ]
danakjebb9cc4d2022-03-04 21:30:11134 }
danakj482580a2022-11-18 18:00:59135 }
136 } else {
137 not_needed(invoker, _rs_vars)
138 }
139
140 target(invoker.target_type, target_name) {
141 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY + _rs_vars)
142 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
143 sources = _cc_sources
144 if (!defined(deps)) {
145 deps = []
146 }
danakjca3cae62023-04-12 15:20:57147 if (!defined(ldflags)) {
148 ldflags = []
149 }
150
danakj482580a2022-11-18 18:00:59151 if (_rs_sources != []) {
152 deps += [ ":${_rust_target_name}" ]
danakjebb9cc4d2022-03-04 21:30:11153 }
danakjca3cae62023-04-12 15:20:57154
155 if (current_os != "aix" && !is_win) {
156 # Inform the build system that this binary contains Rust unit tests. The
157 # test-containing rlibs linked into it must not be discarded by the linker
158 # even if there will be no edges going into them.
159 #
160 # For C++ this is done by not putting them in a library at all, but Rust
161 # must be compiled into an rlib.
162 #
163 # On AIX there's no flag to avoid pruning unit tests in this library from
164 # the linking step. On Windows, there's no need for it.
165 if (_rs_sources != []) {
166 ldflags +=
167 [ "-LinkWrapper,add-whole-archive=${_rust_target_name}.rlib" ]
168 }
169
170 # Do the same for any Rust dependencies with unit tests in them. This will
171 # only match rust targets by looking for rlib extensions.
172 foreach(d, deps) {
173 _dep_target_name = get_label_info(d, "name")
174 ldflags += [ "-LinkWrapper,add-whole-archive=${_dep_target_name}.rlib" ]
175 }
176 }
danakjebb9cc4d2022-03-04 21:30:11177 }
178}
179
qsrfb5251d12015-01-21 15:57:22180# Define a test as an executable (or apk on Android) with the "testonly" flag
181# set.
agrieve62ab00282016-04-05 02:03:45182# Variable:
Dirk Pranke79d065d2020-08-29 03:28:30183# use_xvfb: (optional) whether to run the executable under Xvfb.
danakj482580a2022-11-18 18:00:59184# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:56185# use_native_activity: Test implements ANativeActivity_onCreate().
Greg Thompson318cd692022-03-28 08:12:06186# test_runner_shard: (Fuchsia, optional): for CFv2 tests, use the given test
Greg Thompsonfd269652022-10-28 12:06:55187# runner shard rather than the default shard for the ELF runner when
188# assembling the test component. This is useful, for example, to use the
189# elf_test_ambient_exec_runner for tests that require
190# job_policy_ambient_mark_vmo_exec.
191# fuchsia_package_deps: (Fuchsia, optional) List of fuchsia_component()
192# targets that this test package contains.
Mirko Bonadei15522bc2020-09-16 20:38:39193# is_xctest: (iOS, optional) whether to build the executable as XCTest.
194# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
195# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:43196# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
197# network requests during the test.
qsrfb5251d12015-01-21 15:57:22198template("test") {
Greg Guterman6963dc082021-04-07 05:20:59199 # Ensures the rts file exists and if not, creates a dummy file
200 if (use_rts) {
201 action("${target_name}__rts_filters") {
202 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53203 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:05204 inverted_rts_file =
205 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
206 args = [
207 rebase_path(rts_file, root_build_dir),
208 rebase_path(inverted_rts_file, root_build_dir),
209 ]
210 outputs = [
211 rts_file,
212 inverted_rts_file,
213 ]
Greg Guterman6963dc082021-04-07 05:20:59214 }
215 }
216
Andrew Grieve1b290e4a22020-11-24 20:07:01217 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:39218 if (!is_ios) {
219 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
220 "is_xctest can be set only for iOS builds")
221 }
Stefano Duo4128b6b2021-08-02 21:24:43222 if (!is_android) {
223 assert(!defined(invoker.allow_cleartext_traffic),
224 "allow_cleartext_traffic can be set only for Android tests")
225 }
226
qsrfb5251d12015-01-21 15:57:22227 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:30228 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
229
Peter Kotwicz10742f82021-04-15 22:32:50230 _use_default_launcher =
231 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
232 if (!defined(invoker.use_raw_android_executable)) {
233 # Checkouts where build_with_chromium == false often have a custom GN
234 # template wrapper around test() which sets use_default_launcher == false.
235 # Set the _use_raw_android_executable default so that test() targets which
236 # do not use the custom wrapper
237 # (1) Do not cause "gn gen" to fail
238 # (2) Do not need to be moved into if(build_with_chromium) block.
239 _use_raw_android_executable =
240 !build_with_chromium && _use_default_launcher
241 } else {
242 not_needed([ "_use_default_launcher" ])
243 _use_raw_android_executable = invoker.use_raw_android_executable
244 }
qsrfb5251d12015-01-21 15:57:22245
agrieve67855de2016-03-30 14:46:01246 # output_name is used to allow targets with the same name but in different
247 # packages to still produce unique runner scripts.
248 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26249 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01250 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26251 }
agrieve62ab00282016-04-05 02:03:45252
agrieveb355ad152016-04-19 03:45:23253 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42254 _wrapper_script_vars = [
Jamie Madill73b9af332022-08-03 19:27:47255 "android_test_runner_script",
agrievee41ae190d2016-04-25 14:12:51256 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42257 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51258 ]
agrieve3ac557f02016-04-12 15:52:00259
jbudorickced2a252016-06-09 16:38:54260 assert(_use_raw_android_executable || enable_java_templates)
261
agrieve62ab00282016-04-05 02:03:45262 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49263 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
264
agrieve62ab00282016-04-05 02:03:45265 _exec_target = "${target_name}__exec"
266 _dist_target = "${target_name}__dist"
267 _exec_output =
268 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
danakj505b7f062023-07-05 19:02:02269 _crate_name = "${target_name}"
agrieve62ab00282016-04-05 02:03:45270
danakjebb9cc4d2022-03-04 21:30:11271 mixed_test(_exec_target) {
272 target_type = "executable"
273
danakj505b7f062023-07-05 19:02:02274 # Use a crate name that avoids creating a warning due to double
275 # underscore (ie. `__`).
276 crate_name = _crate_name
277
danakje94f40d2022-02-16 18:13:53278 # Configs will always be defined since we set_defaults in
279 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45280 configs = []
Dirk Pranke19a58732021-03-24 22:26:22281 forward_variables_from(
282 invoker,
283 "*",
284 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
285 "data_deps",
286 "extra_dist_files",
287 ])
agrieve62ab00282016-04-05 02:03:45288
289 # Thanks to the set_defaults() for test(), configs are initialized with
290 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59291 configs -= [
292 "//build/config:shared_library_config",
293 "//build/config/android:hide_all_but_jni",
294 ]
agrieve62ab00282016-04-05 02:03:45295 configs += [ "//build/config:executable_config" ]
296
Dirk Pranke19a58732021-03-24 22:26:22297 if (defined(invoker.data_deps)) {
298 data_deps = invoker.data_deps
299 } else {
300 data_deps = []
301 }
302 if (!defined(data)) {
303 data = []
304 }
Jamie Madilldd60ee62021-04-13 19:25:52305 if (tests_have_location_tags) {
306 data += [ "//testing/location_tags.json" ]
307 }
Dirk Pranke19a58732021-03-24 22:26:22308
agrieve62ab00282016-04-05 02:03:45309 # Don't output to the root or else conflict with the group() below.
310 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11311
312 if (use_rts) {
313 data_deps += [ ":${invoker.target_name}__rts_filters" ]
314 }
agrieve62ab00282016-04-05 02:03:45315 }
316
317 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45318 dist_dir = "$root_out_dir/$target_name"
319 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22320 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45321 if (defined(invoker.extra_dist_files)) {
322 extra_files = invoker.extra_dist_files
323 }
Greg Guterman50ed4b42021-04-08 01:15:11324
325 if (use_rts) {
326 if (!defined(data_deps)) {
327 data_deps = []
328 }
329 data_deps += [ ":${invoker.target_name}__rts_filters" ]
330 }
agrieve62ab00282016-04-05 02:03:45331 }
332 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38333 _library_target_name = "${target_name}__library"
danakj98e073722022-02-24 21:01:49334 _library_crate_name = "${target_name}_library"
Andrew Grieveee8aa44d2022-09-23 17:14:38335 _apk_target_name = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45336 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43337 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45338 "android_manifest",
agrievec6811b422016-06-23 02:25:09339 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27340 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55341 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45342 "enable_multidex",
Benoît Lizéd8b8f742019-11-07 12:50:07343 "product_config_java_packages",
Andrew Grieve43f24fd02022-04-06 23:04:04344 "loadable_modules",
345 "loadable_module_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02346 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07347 "proguard_configs",
348 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45349 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02350 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45351 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56352 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45353 ]
Siddhartha764226b2018-03-13 02:32:55354
Andrew Grieveee8aa44d2022-09-23 17:14:38355 _add_unwind_tables_in_apk =
356 defined(invoker.add_unwind_tables_in_apk) &&
357 invoker.add_unwind_tables_in_apk && target_cpu == "arm"
Andrew Grieved5fdf2af2022-08-23 07:47:55358
Siddhartha764226b2018-03-13 02:32:55359 # Adds the unwind tables from unstripped binary as an asset file in the
360 # apk, if |add_unwind_tables_in_apk| is specified by the test.
Andrew Grieved5fdf2af2022-08-23 07:47:55361 if (_add_unwind_tables_in_apk) {
Andrew Grieveee8aa44d2022-09-23 17:14:38362 # TODO(crbug.com/1315603): Remove generation of v1 unwind asset when
Tushar Agarwaldcafb622022-11-30 17:32:27363 # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroid`.
Andrew Grieveee8aa44d2022-09-23 17:14:38364 _unwind_table_name = "${_library_target_name}_unwind_v1"
365 unwind_table_v1(_unwind_table_name) {
366 library_target = ":$_library_target_name"
367 }
368
Arthur Sonzogni54424e92022-09-23 13:30:45369 if (use_android_unwinder_v2) {
Andrew Grieveee8aa44d2022-09-23 17:14:38370 _unwind_table_v2_name = "${_library_target_name}_unwind_v2"
371 unwind_table_v2(_unwind_table_v2_name) {
372 library_target = ":$_library_target_name"
Arthur Sonzogni54424e92022-09-23 13:30:45373 }
374 }
375
Andrew Grieveee8aa44d2022-09-23 17:14:38376 _unwind_table_asset_name = "${target_name}__unwind_assets"
377 android_assets(_unwind_table_asset_name) {
378 sources = [ "$target_out_dir/$_unwind_table_name/$unwind_table_asset_v1_filename" ]
379 disable_compression = true
380 deps = [ ":$_unwind_table_name" ]
381 if (use_android_unwinder_v2) {
382 sources += [ "$target_out_dir/$_unwind_table_v2_name/$unwind_table_asset_v2_filename" ]
383 deps += [ ":$_unwind_table_v2_name" ]
384 }
Siddhartha764226b2018-03-13 02:32:55385 }
386 }
387
Sam Maierbc320a9482023-05-17 19:44:16388 _generate_final_jni =
389 !defined(invoker.generate_final_jni) || invoker.generate_final_jni
Andrew Grieveee8aa44d2022-09-23 17:14:38390 mixed_test(_library_target_name) {
Sam Maierbc320a9482023-05-17 19:44:16391 if (_generate_final_jni) {
392 target_type = "shared_library_with_jni"
393 java_targets = [ ":$_apk_target_name" ]
394 } else {
395 target_type = "shared_library"
396 }
danakjebb9cc4d2022-03-04 21:30:11397
danakj98e073722022-02-24 21:01:49398 # Configs will always be defined since we set_defaults in
399 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45400 configs = [] # Prevent list overwriting warning.
401 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45402
jbudorickd29ecfa72016-11-18 22:45:42403 forward_variables_from(
404 invoker,
405 "*",
Andrew Grieved5fdf2af2022-08-23 07:47:55406 [
407 "configs",
408 "deps",
409 ] + _apk_specific_vars + _wrapper_script_vars +
Peter Wen2052bd12020-12-03 20:15:07410 TESTONLY_AND_VISIBILITY)
411
danakj482580a2022-11-18 18:00:59412 # Use a crate name that avoids creating a warning due to double
413 # underscore (ie. `__`).
414 crate_name = _library_crate_name
415
Peter Wen2052bd12020-12-03 20:15:07416 # Native targets do not need to depend on java targets. Filter them out
417 # so that the shared library can be built without needing to wait for
418 # dependent java targets.
419 deps = []
420 if (defined(invoker.deps)) {
Andrew Grieve841ed072022-08-23 16:42:33421 deps = filter_exclude(invoker.deps, java_target_patterns)
Peter Wen2052bd12020-12-03 20:15:07422 }
agrieve62ab00282016-04-05 02:03:45423
Peter Kotwiczb9957d62021-04-12 21:09:43424 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37425 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45426 }
427 }
Andrew Grieveee8aa44d2022-09-23 17:14:38428 unittest_apk(_apk_target_name) {
Daniel Bratellfdda4652019-01-31 15:45:54429 forward_variables_from(invoker, _apk_specific_vars)
Andrew Grieveee8aa44d2022-09-23 17:14:38430 shared_library = ":$_library_target_name"
Sam Maierbc320a9482023-05-17 19:44:16431 if (_generate_final_jni) {
432 srcjar_deps = [ "${shared_library}__jni_registration" ]
Sam Maierbc320a9482023-05-17 19:44:16433 }
agrieve62ab00282016-04-05 02:03:45434 apk_name = invoker.target_name
435 if (defined(invoker.output_name)) {
436 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45437 install_script_name = "install_${invoker.output_name}"
438 }
agrieveb355ad152016-04-19 03:45:23439
Daniel Bratellfdda4652019-01-31 15:45:54440 if (defined(invoker.deps)) {
441 deps = invoker.deps
442 } else {
443 deps = []
444 }
Andrew Grieve43f24fd02022-04-06 23:04:04445 if (defined(loadable_module_deps)) {
446 deps += loadable_module_deps
447 }
Daniel Bratellfdda4652019-01-31 15:45:54448
jcivellif4462a352017-01-10 04:45:59449 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43450 if (_use_default_launcher) {
451 deps += [ "//base/test:test_support_java" ]
452 }
jcivellif4462a352017-01-10 04:45:59453
Siddhartha764226b2018-03-13 02:32:55454 if (defined(_unwind_table_asset_name)) {
455 deps += [ ":${_unwind_table_asset_name}" ]
456 }
Greg Guterman50ed4b42021-04-08 01:15:11457
458 if (use_rts) {
459 data_deps = [ ":${invoker.target_name}__rts_filters" ]
460 }
agrieve62ab00282016-04-05 02:03:45461 }
Andrew Grievee1dc23f2019-10-22 16:26:36462 }
agrieve62ab00282016-04-05 02:03:45463
Andrew Grievee1dc23f2019-10-22 16:26:36464 test_runner_script(_test_runner_target) {
465 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57466
Andrew Grievee1dc23f2019-10-22 16:26:36467 if (_use_raw_android_executable) {
468 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34469 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36470 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38471 apk_target = ":$_apk_target_name"
Andrew Grievee1dc23f2019-10-22 16:26:36472 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47473
474 # Dep needed for the test runner .runtime_deps file to pick up data
475 # deps from the forward_variables_from(invoker, "*") on the library.
Andrew Grieveee8aa44d2022-09-23 17:14:38476 data_deps = [ ":$_library_target_name" ]
agrieve62ab00282016-04-05 02:03:45477 }
Andrew Grievee1dc23f2019-10-22 16:26:36478 test_name = _output_name
479 test_suite = _output_name
480 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59481
482 if (use_rts) {
483 data_deps += [ ":${invoker.target_name}__rts_filters" ]
484 }
mikecase56d80d72015-06-03 00:57:26485 }
486
Andrew Grieve7ca6de32019-10-18 03:57:47487 # Create a wrapper script rather than using a group() in order to ensure
488 # "ninja $target_name" always works. If this was a group(), then GN would
489 # not create a top-level alias for it if a target exists in another
490 # directory with the same $target_name.
491 # Also - bots run this script directly for "components_perftests".
492 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01493 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47494 executable = "$root_build_dir/bin/run_$_output_name"
495 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22496 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40497 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47498 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40499 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47500 # Dep needed for the swarming .isolate file to pick up data
501 # deps from the forward_variables_from(invoker, "*") on the library.
502 deps += [
Andrew Grieveee8aa44d2022-09-23 17:14:38503 ":$_apk_target_name",
504 ":$_library_target_name",
Andrew Grieve7ca6de32019-10-18 03:57:47505 ]
agrieve62ab00282016-04-05 02:03:45506 }
Dirk Pranke19a58732021-03-24 22:26:22507
508 if (defined(invoker.data_deps)) {
509 data_deps = invoker.data_deps
510 } else {
511 data_deps = []
512 }
Kevin Marshall23529362022-02-23 16:50:36513
514 data_deps += [ "//testing:test_scripts_shared" ]
515
Jamie Madilldd60ee62021-04-13 19:25:52516 if (tests_have_location_tags) {
517 data = [ "//testing/location_tags.json" ]
518 }
Greg Guterman6963dc082021-04-07 05:20:59519
520 if (use_rts) {
521 data_deps += [ ":${invoker.target_name}__rts_filters" ]
522 }
agrieve1a02e582015-10-15 21:35:39523 }
Scott Graham4c4cdc52017-05-29 20:45:03524 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30525 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
526
Scott Graham4c4cdc52017-05-29 20:45:03527 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42528 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42529 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb42022-04-05 12:30:35530 _program_name = get_label_info(":${_exec_target}", "name")
danakj505b7f062023-07-05 19:02:02531 _crate_name = _output_name
Scott Graham4c4cdc52017-05-29 20:45:03532
Greg Thompson2f1e3762022-10-17 19:53:44533 # Generate a CML fragment that provides the program name.
534 _test_program_fragment_target = "${target_name}_program-fragment"
535 _test_program_fragment = "${target_out_dir}/${target_name}_program.test-cml"
536 generated_file(_test_program_fragment_target) {
537 contents = {
538 program = {
539 binary = _program_name
Kevin Marshall2ec60032022-05-09 17:38:28540 }
Greg Thompson26516592021-12-16 08:34:45541 }
Greg Thompson2f1e3762022-10-17 19:53:44542 outputs = [ _test_program_fragment ]
543 output_conversion = "json"
Greg Thompson9765eeb42022-04-05 12:30:35544 }
545
Greg Thompson2f1e3762022-10-17 19:53:44546 _test_runner_shard =
547 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
548 if (defined(invoker.test_runner_shard)) {
549 _test_runner_shard = invoker.test_runner_shard
Wez6879f8a2021-09-07 20:27:02550 }
551
Greg Thompson2f1e3762022-10-17 19:53:44552 # Collate the complete set of elements to include in the test component's
553 # manifest.
David Dorwin2c4872c2023-02-22 20:00:56554
Greg Thompson2f1e3762022-10-17 19:53:44555 _manifest_fragments = [
Greg Thompson2f1e3762022-10-17 19:53:44556 _test_program_fragment,
557 _test_runner_shard,
558 ]
559
David Dorwin2c4872c2023-02-22 20:00:56560 # Select the Fuchsia test realm in which to run the test.
561 if (defined(invoker.run_as_chromium_system_test) &&
562 invoker.run_as_chromium_system_test) {
563 _manifest_fragments += [
564 "//build/config/fuchsia/test/chromium_system_test_facet.shard.test-cml",
565 "//build/config/fuchsia/test/system_test_minimum.shard.test-cml",
566 ]
567 } else {
568 _manifest_fragments += [
569 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
570 "//build/config/fuchsia/test/minimum.shard.test-cml",
571 ]
572 }
573
Greg Thompson2f1e3762022-10-17 19:53:44574 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
575 _merged_manifest_name = "${_output_name}.cml"
576
577 if (defined(invoker.additional_manifest_fragments)) {
578 _manifest_fragments += invoker.additional_manifest_fragments
579 }
580
581 # Generate the test component manifest from the specified elements.
582 _test_component_manifest_target = "${target_name}_component-manifest"
583 cmc_merge(_test_component_manifest_target) {
584 sources = _manifest_fragments
585 output_name = "${_merged_manifest_name}"
586 deps = [ ":${_test_program_fragment_target}" ]
587 }
588
589 # Define the test component, dependent on the generated manifest, and the
590 # test executable target.
591 _test_component_target = "${target_name}_component"
592 fuchsia_component(_test_component_target) {
593 deps = [ ":$_test_component_manifest_target" ]
594 data_deps = [ ":$_exec_target" ]
595 manifest = _test_component_manifest
596 visibility = [ ":*" ]
597 }
598
599 _test_component_targets = [ ":${_test_component_target}" ]
600
Wez6879f8a2021-09-07 20:27:02601 # Define components for each entry in |additional_manifests|, if any. Since
602 # manifests may themselves depend-on the outputs of |deps|, these components
603 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02604 if (defined(invoker.additional_manifests)) {
605 foreach(filename, invoker.additional_manifests) {
606 _additional_component_target =
607 target_name + "_" + get_path_info(filename, "name")
608 _test_component_targets += [ ":${_additional_component_target}" ]
609 fuchsia_component(_additional_component_target) {
610 forward_variables_from(invoker, [ "testonly" ])
611 data_deps = [ ":$_exec_target" ]
612 visibility = [ ":*" ]
613 manifest = filename
614
615 # Depend on |invoker.deps|, in case it includes a dependency that
616 # creates this additional component's manifest.
617 if (defined(invoker.deps)) {
618 deps = invoker.deps
619 }
620 }
621 }
622 }
623
624 # Define the package target that will bundle the test and additional
625 # components and their data.
626 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21627 forward_variables_from(invoker,
628 [
629 "excluded_files",
630 "excluded_dirs",
Bryant Chandlerc40f2672023-01-27 23:33:30631 "excluded_paths",
Kevin Marshall36c602c2021-11-04 16:16:21632 ])
Wez6879f8a2021-09-07 20:27:02633 package_name = _output_name
634 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21635
Greg Thompsonfd269652022-10-28 12:06:55636 if (defined(invoker.fuchsia_package_deps)) {
637 deps += invoker.fuchsia_package_deps
638 }
Bryant Chandlerc40f2672023-01-27 23:33:30639 if (!defined(excluded_paths)) {
640 excluded_paths = []
Kevin Marshall36c602c2021-11-04 16:16:21641 }
Bryant Chandlerc40f2672023-01-27 23:33:30642 excluded_paths += [
643 "${devtools_root_location}/*",
644 "*.git/*",
645 "*.svn/*",
646 "*.hg/*",
647 ]
Sarah Pham80972efc2022-05-31 17:40:15648 if (devtools_root_location != "") {
Bryant Chandlerc40f2672023-01-27 23:33:30649 excluded_paths += [ "${devtools_root_location}/*" ]
Sarah Pham80972efc2022-05-31 17:40:15650 }
Wez6879f8a2021-09-07 20:27:02651 }
652
653 # |target_name| refers to the package-runner rule, so that building
654 # "base_unittests" will build not only the executable, component, and
655 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25656 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53657 forward_variables_from(invoker,
658 [
Kevin Marshall5fadadd2021-10-16 00:08:25659 "data",
660 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53661 "package_deps",
Kevin Marshall5fadadd2021-10-16 00:08:25662 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53663 ])
Kevin Marshall5fadadd2021-10-16 00:08:25664
Chong Guc6bfdf62021-10-20 23:37:00665 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15666 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25667 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42668
Kevin Marshall5fadadd2021-10-16 00:08:25669 if (!defined(deps)) {
670 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52671 }
Kevin Marshall5fadadd2021-10-16 00:08:25672 if (defined(invoker.deps)) {
673 deps += invoker.deps
674 }
Greg Guterman6963dc082021-04-07 05:20:59675
Kevin Marshall5fadadd2021-10-16 00:08:25676 if (!defined(data)) {
677 data = []
678 }
679 if (tests_have_location_tags) {
680 data += [ "//testing/location_tags.json" ]
681 }
682
683 if (!defined(data_deps)) {
684 data_deps = []
685 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28686
Kevin Marshall23529362022-02-23 16:50:36687 data_deps += [ "//testing:test_scripts_shared" ]
688
Greg Guterman6963dc082021-04-07 05:20:59689 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25690 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59691 }
Kevin Marshallf35fa5f2018-01-29 19:24:42692 }
693
danakjebb9cc4d2022-03-04 21:30:11694 mixed_test(_exec_target) {
695 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01696 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42697 output_name = _exec_target
danakj505b7f062023-07-05 19:02:02698
699 # Use a crate name that avoids creating a warning due to double
700 # underscore (ie. `__`).
701 crate_name = _crate_name
Scott Graham4c4cdc52017-05-29 20:45:03702 }
dpranke2a294622015-08-07 05:23:01703 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30704 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46705 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30706
Rohit Raof9b096d2019-09-09 22:26:23707 declare_args() {
708 # Keep the unittest-as-xctest functionality defaulted to off until the
709 # bots are updated to handle it properly.
710 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
711 # supports running unittests with xctest.
712 enable_run_ios_unittests_with_xctest = false
713 }
714
sdefresne012857872016-03-16 10:55:37715 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27716 _output_name = target_name
717 if (defined(invoker.output_name)) {
718 _output_name = invoker.output_name
719 }
720
Jeff Yoonf7f4eb42020-03-06 18:55:36721 _wrapper_output_name = "run_${target_name}"
722 ios_test_runner_wrapper(_wrapper_output_name) {
723 forward_variables_from(invoker,
724 [
725 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36726 "deps",
727 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27728 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36729 "retries",
730 "shards",
731 ])
732
733 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
734
735 if (!defined(executable_args)) {
736 executable_args = []
737 }
738 executable_args += [
739 "--app",
740 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
741 ]
742
743 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22744
745 if (!defined(data)) {
746 data = []
747 }
Jamie Madilldd60ee62021-04-13 19:25:52748 if (tests_have_location_tags) {
749 data += [ "//testing/location_tags.json" ]
750 }
Jeff Yoonf7f4eb42020-03-06 18:55:36751 }
752
sdefresne012857872016-03-16 10:55:37753 _resources_bundle_data = target_name + "_resources_bundle_data"
754
755 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34756 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22757 sources = [ "//testing/gtest_ios/Default.png" ]
758 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01759 }
760
Mirko Bonadei15522bc2020-09-16 20:38:39761 force_xctest = enable_run_ios_unittests_with_xctest ||
762 (defined(invoker.is_xctest) && invoker.is_xctest)
763
danakjfae603fc602022-11-18 18:40:22764 mixed_test(_test_target) {
765 if (force_xctest) {
766 target_type = "ios_xctest_test"
767 } else {
768 target_type = "ios_app_bundle"
769 }
dpranke2a294622015-08-07 05:23:01770 testonly = true
sdefresnea828c282016-05-30 18:04:20771
Mirko Bonadei15522bc2020-09-16 20:38:39772 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23773 xctest_module_target = "//base/test:google_test_runner"
774 }
775
Andrew Grieve1b290e4a22020-11-24 20:07:01776 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13777
778 # Provide sensible defaults in case invoker did not define any of those
779 # required variables.
sdefresne05b97ca2016-06-08 07:19:46780 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13781 info_plist = "//testing/gtest_ios/unittest-Info.plist"
782 }
sdefresne9e147e02016-06-07 00:10:13783
Sylvain Defresne3c5a1312021-09-23 17:08:09784 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13785 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50786 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09787 } else {
Ali Juma75be0fe2022-01-24 19:39:29788 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27789 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09790 }
dpranke2a294622015-08-07 05:23:01791
sdefresne047490e2016-07-22 08:49:34792 if (!defined(bundle_deps)) {
793 bundle_deps = []
794 }
795 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36796
797 if (!defined(data_deps)) {
798 data_deps = []
799 }
800
Kevin Marshall23529362022-02-23 16:50:36801 data_deps += [ "//testing:test_scripts_shared" ]
802
Jeff Yoonf7f4eb42020-03-06 18:55:36803 # Include the generate_wrapper as part of data_deps
804 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46805 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59806
807 if (use_rts) {
808 data_deps += [ ":${invoker.target_name}__rts_filters" ]
809 }
dpranke2a294622015-08-07 05:23:01810 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11811 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
812 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30813 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
814
Yuke Liao2a9b2f0e2021-04-16 00:40:11815 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32816
Benjamin Pastene3bce864e2018-04-14 01:16:32817 _gen_runner_target = "${target_name}__runner"
818 _runtime_deps_file =
819 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
820 "/" + get_label_info(target_name, "name") + ".runtime_deps"
821
Xinan Lin6be01252021-06-25 23:07:36822 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
823 if (is_skylab) {
Struan Shrimptonf61293f62022-04-11 19:33:40824 generate_skylab_deps(_gen_runner_target) {
Xinan Lin6be01252021-06-25 23:07:36825 generated_script = _generated_script
826 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34827 }
Xinan Lin6be01252021-06-25 23:07:36828 } else {
829 generate_runner_script(_gen_runner_target) {
830 generated_script = _generated_script
831 test_exe = invoker.target_name
832 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34833
Xinan Lin6be01252021-06-25 23:07:36834 if (is_chromeos_lacros) {
835 # At build time, Lacros tests don't know whether they'll run on VM or
836 # HW, and instead, these flags are specified at runtime when invoking
837 # the generated runner script.
838 skip_generating_board_args = true
839 }
Greg Guterman6963dc082021-04-07 05:20:59840
Xinan Lin6be01252021-06-25 23:07:36841 if (tests_have_location_tags) {
842 data = [ "//testing/location_tags.json" ]
843 }
844
845 if (use_rts) {
846 data_deps = [ ":${invoker.target_name}__rts_filters" ]
847 }
Greg Guterman6963dc082021-04-07 05:20:59848 }
Benjamin Pastene3bce864e2018-04-14 01:16:32849 }
850
danakjebb9cc4d2022-03-04 21:30:11851 mixed_test(target_name) {
852 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01853 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
854 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32855 if (!defined(deps)) {
856 deps = []
857 }
858 if (!defined(data)) {
859 data = []
860 }
861
Ben Pastene41041782019-02-16 04:21:58862 # We use a special trigger script for CrOS hardware tests.
863 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
864
Benjamin Pastene3bce864e2018-04-14 01:16:32865 write_runtime_deps = _runtime_deps_file
866 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37867 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59868
Kevin Marshall23529362022-02-23 16:50:36869 if (!defined(data_deps)) {
870 data_deps = []
871 }
872
873 data_deps += [ "//testing:test_scripts_shared" ]
874
Greg Guterman6963dc082021-04-07 05:20:59875 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59876 data_deps += [ ":${invoker.target_name}__rts_filters" ]
877 }
Benjamin Pastene3bce864e2018-04-14 01:16:32878 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11879 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24880 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
881 _executable = target_name
882 _gen_runner_target = "${target_name}__runner"
883
Yuke Liao32af4242020-07-16 21:48:02884 if (defined(invoker.use_xvfb)) {
885 _use_xvfb = invoker.use_xvfb
886 } else {
887 _use_xvfb = false
888 }
889
Yuke Liaod037abc2020-10-06 22:48:22890 # When use_xvfb is set by the invoker, it indicates that running this test
891 # target requires a window, and in lacros build, ash-chrome serves as the
892 # display server. Note that even though the tests themselves do not require
893 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
894 # because ash-chrome is based on x11.
895 _use_ash_chrome = _use_xvfb
896
Yuke Liaoe703384b2020-07-16 01:05:24897 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24898 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02899
Yuke Liao2e4953cf2020-07-26 19:20:19900 data = []
Will Harrisd35e2c92021-04-07 01:42:02901 data_deps = [ "//testing:test_scripts_shared" ]
902
Yuke Liao32af4242020-07-16 21:48:02903 if (_use_xvfb) {
904 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22905 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02906 } else {
907 executable = "//testing/test_env.py"
908 }
Jamie Madilldd60ee62021-04-13 19:25:52909 if (tests_have_location_tags) {
910 data += [ "//testing/location_tags.json" ]
911 }
Yuke Liao32af4242020-07-16 21:48:02912
Yuke Liaoe703384b2020-07-16 01:05:24913 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02914 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39915 "test",
Yuke Liaoe703384b2020-07-16 01:05:24916 "@WrappedPath(./${_executable})",
917 "--test-launcher-bot-mode",
918 ]
Yuke Liao32af4242020-07-16 21:48:02919
Yuke Liaof540c742020-07-29 16:28:34920 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37921 executable_args += [ "--ash-chrome-path" ]
922
923 # Can't use --ash-chrome-path=path because WrappedPath
924 # won't be expanded for that usage.
925 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39926 }
927
Yuke Liaoe703384b2020-07-16 01:05:24928 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:00929 executable_args += [ "--asan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24930 }
931 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:00932 executable_args += [ "--msan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24933 }
934 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:00935 executable_args += [ "--tsan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24936 }
937 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:00938 executable_args += [ "--cfi-diag=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24939 }
Ian Struiksma2ebc3222023-05-24 00:28:46940 if (fail_on_san_warnings) {
941 executable_args += [ "--fail-san=1" ]
942 }
Yuke Liaoe703384b2020-07-16 01:05:24943
Takuto Ikuta38ebd0e2022-01-19 17:56:22944 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59945
946 if (use_rts) {
947 data_deps += [ ":${invoker.target_name}__rts_filters" ]
948 }
Yuke Liaoe703384b2020-07-16 01:05:24949 }
950
danakjebb9cc4d2022-03-04 21:30:11951 mixed_test(target_name) {
952 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01953 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
954 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24955 if (!defined(deps)) {
956 deps = []
957 }
958
Yuke Liaod037abc2020-10-06 22:48:22959 if (!defined(data_deps)) {
960 data_deps = []
961 }
962
Kevin Marshall23529362022-02-23 16:50:36963 data_deps += [ "//testing:test_scripts_shared" ]
964
Yuke Liaoe703384b2020-07-16 01:05:24965 write_runtime_deps = _runtime_deps_file
966 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22967 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56968 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22969 }
Greg Guterman6963dc082021-04-07 05:20:59970
971 if (use_rts) {
972 data_deps += [ ":${invoker.target_name}__rts_filters" ]
973 }
Yuke Liaoe703384b2020-07-16 01:05:24974 }
Dirk Prankedd4ff742020-11-18 19:57:32975 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30976 if (is_mac || is_win) {
977 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
978 }
979
Dirk Prankedd4ff742020-11-18 19:57:32980 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
981 _executable = target_name
982 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06983
Dirk Prankedd4ff742020-11-18 19:57:32984 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
985 _use_xvfb = invoker.use_xvfb
986 } else {
987 _use_xvfb = false
988 }
989
990 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32991 wrapper_script = "$root_build_dir/bin/run_" + _executable
992
993 data = []
Will Harrisd35e2c92021-04-07 01:42:02994 data_deps = [ "//testing:test_scripts_shared" ]
995
Dirk Prankedd4ff742020-11-18 19:57:32996 if (_use_xvfb) {
997 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06998 } else {
Dirk Prankedd4ff742020-11-18 19:57:32999 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:061000 }
Jamie Madilldd60ee62021-04-13 19:25:521001 if (tests_have_location_tags) {
1002 data += [ "//testing/location_tags.json" ]
1003 }
Dirk Pranke31e346e2020-07-15 00:54:061004
Dirk Prankedd4ff742020-11-18 19:57:321005 executable_args = [
1006 "@WrappedPath(./${_executable})",
1007 "--test-launcher-bot-mode",
1008 ]
1009 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:001010 executable_args += [ "--asan=1" ]
Dirk Pranke31e346e2020-07-15 00:54:061011 }
Dirk Prankedd4ff742020-11-18 19:57:321012 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:001013 executable_args += [ "--msan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321014 }
1015 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:001016 executable_args += [ "--tsan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321017 }
1018 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:001019 executable_args += [ "--cfi-diag=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321020 }
Ian Struiksma2ebc3222023-05-24 00:28:461021 if (fail_on_san_warnings) {
1022 executable_args += [ "--fail-san=1" ]
1023 }
Dirk Prankedd4ff742020-11-18 19:57:321024
Greg Guterman6963dc082021-04-07 05:20:591025 if (use_rts) {
1026 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1027 }
Dirk Pranke31e346e2020-07-15 00:54:061028 }
1029
danakjebb9cc4d2022-03-04 21:30:111030 mixed_test(target_name) {
1031 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011032 forward_variables_from(invoker,
1033 "*",
1034 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
1035 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:061036 if (!defined(deps)) {
1037 deps = []
1038 }
1039
Dirk Pranke31e346e2020-07-15 00:54:061040 deps += [
1041 # Give tests the default manifest on Windows (a no-op elsewhere).
1042 "//build/win:default_exe_manifest",
1043 ]
1044
Dirk Prankedd4ff742020-11-18 19:57:321045 write_runtime_deps = _runtime_deps_file
1046 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:111047
Kevin Marshall23529362022-02-23 16:50:361048 if (!defined(data_deps)) {
1049 data_deps = []
1050 }
1051
1052 data_deps += [ "//testing:test_scripts_shared" ]
1053
Greg Guterman50ed4b42021-04-08 01:15:111054 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:111055 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1056 }
Dirk Prankedd4ff742020-11-18 19:57:321057 }
1058 } else {
1059 # This is a catch-all clause for NaCl toolchains and other random
1060 # configurations that might define tests; test() in these configs
1061 # will just define the underlying executables.
1062 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
1063 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:111064 mixed_test(target_name) {
1065 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011066 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1067 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:321068 if (!defined(deps)) {
1069 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061070 }
Greg Guterman6963dc082021-04-07 05:20:591071
Kevin Marshall23529362022-02-23 16:50:361072 if (!defined(data_deps)) {
1073 data_deps = []
1074 }
1075
1076 data_deps += [ "//testing:test_scripts_shared" ]
1077
Greg Guterman6963dc082021-04-07 05:20:591078 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:591079 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1080 }
Dirk Pranke31e346e2020-07-15 00:54:061081 }
qsrfb5251d12015-01-21 15:57:221082 }
1083}
brettwedb6ecc2016-07-14 23:37:031084
Dirk Pranke6188075b2020-10-01 19:31:281085# Defines a type of test that invokes a script to run, rather than
1086# invoking an executable.
1087#
1088# The script must implement the
1089# [test executable API](//docs/testing/test_executable_api.md).
1090#
Andrew Grievea16222d42023-02-10 15:31:101091# The template must be passed the `script` parameter, which specifies the path
1092# to the script to run. It may optionally be passed a `args` parameter, which
1093# can be used to include a list of args to be specified by default. The
1094# template will produce a `$root_build_dir/run_$target_name` wrapper and write
1095# the runtime_deps for the target to
1096# $root_build_dir/${target_name}.runtime_deps, as per the conventions listed in
1097# the [test wrapper API](//docs/testing/test_wrapper_api.md).
Dirk Pranke6188075b2020-10-01 19:31:281098template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:591099 if (use_rts) {
1100 action("${target_name}__rts_filters") {
1101 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:531102 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:051103 inverted_rts_file =
1104 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
1105 args = [
1106 rebase_path(rts_file, root_build_dir),
1107 rebase_path(inverted_rts_file, root_build_dir),
1108 ]
1109 outputs = [
1110 rts_file,
1111 inverted_rts_file,
1112 ]
Greg Guterman6963dc082021-04-07 05:20:591113 }
1114 }
1115
Dirk Pranke6188075b2020-10-01 19:31:281116 generate_wrapper(target_name) {
1117 testonly = true
1118 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1119
1120 executable = "//testing/test_env.py"
1121
1122 executable_args =
1123 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1124 if (defined(invoker.args)) {
1125 executable_args += invoker.args
1126 }
1127
Will Harrisd35e2c92021-04-07 01:42:021128 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471129
Dirk Pranke6188075b2020-10-01 19:31:281130 if (defined(invoker.data)) {
1131 data += invoker.data
1132 }
Jamie Madilldd60ee62021-04-13 19:25:521133 if (tests_have_location_tags) {
1134 data += [ "//testing/location_tags.json" ]
1135 }
Dirk Pranke19a58732021-03-24 22:26:221136
Will Harrisd35e2c92021-04-07 01:42:021137 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281138 if (defined(invoker.data_deps)) {
1139 data_deps += invoker.data_deps
1140 }
1141
1142 forward_variables_from(invoker,
Andrew Grievea16222d42023-02-10 15:31:101143 "*",
Andrew Grieve1b290e4a22020-11-24 20:07:011144 TESTONLY_AND_VISIBILITY + [
Andrew Grievea16222d42023-02-10 15:31:101145 "args",
Andrew Grieve1b290e4a22020-11-24 20:07:011146 "data",
1147 "data_deps",
1148 "script",
Andrew Grieve1b290e4a22020-11-24 20:07:011149 ])
1150 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281151
1152 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591153
1154 if (use_rts) {
1155 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1156 }
Dirk Pranke6188075b2020-10-01 19:31:281157 }
1158}
1159
Andrew Grievea16222d42023-02-10 15:31:101160# Defines a test target that uses exit code for pass/fail.
1161template("isolated_script_test") {
1162 script_test(target_name) {
1163 forward_variables_from(invoker,
1164 "*",
1165 TESTONLY_AND_VISIBILITY + [
1166 "args",
1167 "deps",
1168 "script",
1169 ])
1170 forward_variables_from(invoker, [ "visibility" ])
1171 deps = [ "//testing:run_isolated_script_test" ]
1172 if (defined(invoker.deps)) {
1173 deps += invoker.deps
1174 }
1175 script = "//testing/scripts/run_isolated_script_test.py"
1176 data = [ invoker.script ]
1177 args = [
1178 rebase_path(invoker.script, root_build_dir),
1179 "--script-type=bare",
1180 ]
1181 if (defined(invoker.args)) {
1182 args += invoker.args
1183 }
1184 }
1185}
1186
brettwedb6ecc2016-07-14 23:37:031187# Test defaults.
1188set_defaults("test") {
1189 if (is_android) {
1190 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411191 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591192 configs += [ "//build/config/android:hide_all_but_jni" ]
Andrew Grieved5fdf2af2022-08-23 07:47:551193
1194 # Compress sections to stay under 4gb hard limit on 32-bit current_cpu.
1195 # https://crbug.com/1354616
1196 if (symbol_level == 2 && !use_debug_fission &&
1197 (current_cpu == "arm" || current_cpu == "x86")) {
1198 configs += [ "//build/config:compress_debug_sections" ]
1199 }
brettwedb6ecc2016-07-14 23:37:031200 } else {
1201 configs = default_executable_configs
1202 }
1203}