blob: a0d5e1ad509852d84f2cba38af738ab305be53c4 [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}"
269
danakjebb9cc4d2022-03-04 21:30:11270 mixed_test(_exec_target) {
271 target_type = "executable"
272
danakje94f40d2022-02-16 18:13:53273 # Configs will always be defined since we set_defaults in
274 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45275 configs = []
Dirk Pranke19a58732021-03-24 22:26:22276 forward_variables_from(
277 invoker,
278 "*",
279 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
280 "data_deps",
281 "extra_dist_files",
282 ])
agrieve62ab00282016-04-05 02:03:45283
284 # Thanks to the set_defaults() for test(), configs are initialized with
285 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59286 configs -= [
287 "//build/config:shared_library_config",
288 "//build/config/android:hide_all_but_jni",
289 ]
agrieve62ab00282016-04-05 02:03:45290 configs += [ "//build/config:executable_config" ]
291
Dirk Pranke19a58732021-03-24 22:26:22292 if (defined(invoker.data_deps)) {
293 data_deps = invoker.data_deps
294 } else {
295 data_deps = []
296 }
297 if (!defined(data)) {
298 data = []
299 }
Jamie Madilldd60ee62021-04-13 19:25:52300 if (tests_have_location_tags) {
301 data += [ "//testing/location_tags.json" ]
302 }
Dirk Pranke19a58732021-03-24 22:26:22303
agrieve62ab00282016-04-05 02:03:45304 # Don't output to the root or else conflict with the group() below.
305 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11306
307 if (use_rts) {
308 data_deps += [ ":${invoker.target_name}__rts_filters" ]
309 }
agrieve62ab00282016-04-05 02:03:45310 }
311
312 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45313 dist_dir = "$root_out_dir/$target_name"
314 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22315 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45316 if (defined(invoker.extra_dist_files)) {
317 extra_files = invoker.extra_dist_files
318 }
Greg Guterman50ed4b42021-04-08 01:15:11319
320 if (use_rts) {
321 if (!defined(data_deps)) {
322 data_deps = []
323 }
324 data_deps += [ ":${invoker.target_name}__rts_filters" ]
325 }
agrieve62ab00282016-04-05 02:03:45326 }
327 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38328 _library_target_name = "${target_name}__library"
danakj98e073722022-02-24 21:01:49329 _library_crate_name = "${target_name}_library"
Andrew Grieveee8aa44d2022-09-23 17:14:38330 _apk_target_name = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45331 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43332 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45333 "android_manifest",
agrievec6811b422016-06-23 02:25:09334 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27335 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55336 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45337 "enable_multidex",
Benoît Lizéd8b8f742019-11-07 12:50:07338 "product_config_java_packages",
Andrew Grieve43f24fd02022-04-06 23:04:04339 "loadable_modules",
340 "loadable_module_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02341 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07342 "proguard_configs",
343 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45344 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02345 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45346 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56347 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45348 ]
Siddhartha764226b2018-03-13 02:32:55349
Andrew Grieveee8aa44d2022-09-23 17:14:38350 _add_unwind_tables_in_apk =
351 defined(invoker.add_unwind_tables_in_apk) &&
352 invoker.add_unwind_tables_in_apk && target_cpu == "arm"
Andrew Grieved5fdf2af2022-08-23 07:47:55353
Siddhartha764226b2018-03-13 02:32:55354 # Adds the unwind tables from unstripped binary as an asset file in the
355 # apk, if |add_unwind_tables_in_apk| is specified by the test.
Andrew Grieved5fdf2af2022-08-23 07:47:55356 if (_add_unwind_tables_in_apk) {
Andrew Grieveee8aa44d2022-09-23 17:14:38357 # TODO(crbug.com/1315603): Remove generation of v1 unwind asset when
Tushar Agarwaldcafb622022-11-30 17:32:27358 # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroid`.
Andrew Grieveee8aa44d2022-09-23 17:14:38359 _unwind_table_name = "${_library_target_name}_unwind_v1"
360 unwind_table_v1(_unwind_table_name) {
361 library_target = ":$_library_target_name"
362 }
363
Arthur Sonzogni54424e92022-09-23 13:30:45364 if (use_android_unwinder_v2) {
Andrew Grieveee8aa44d2022-09-23 17:14:38365 _unwind_table_v2_name = "${_library_target_name}_unwind_v2"
366 unwind_table_v2(_unwind_table_v2_name) {
367 library_target = ":$_library_target_name"
Arthur Sonzogni54424e92022-09-23 13:30:45368 }
369 }
370
Andrew Grieveee8aa44d2022-09-23 17:14:38371 _unwind_table_asset_name = "${target_name}__unwind_assets"
372 android_assets(_unwind_table_asset_name) {
373 sources = [ "$target_out_dir/$_unwind_table_name/$unwind_table_asset_v1_filename" ]
374 disable_compression = true
375 deps = [ ":$_unwind_table_name" ]
376 if (use_android_unwinder_v2) {
377 sources += [ "$target_out_dir/$_unwind_table_v2_name/$unwind_table_asset_v2_filename" ]
378 deps += [ ":$_unwind_table_v2_name" ]
379 }
Siddhartha764226b2018-03-13 02:32:55380 }
381 }
382
Sam Maierbc320a9482023-05-17 19:44:16383 _generate_final_jni =
384 !defined(invoker.generate_final_jni) || invoker.generate_final_jni
Andrew Grieveee8aa44d2022-09-23 17:14:38385 mixed_test(_library_target_name) {
Sam Maierbc320a9482023-05-17 19:44:16386 if (_generate_final_jni) {
387 target_type = "shared_library_with_jni"
388 java_targets = [ ":$_apk_target_name" ]
389 } else {
390 target_type = "shared_library"
391 }
danakjebb9cc4d2022-03-04 21:30:11392
danakj98e073722022-02-24 21:01:49393 # Configs will always be defined since we set_defaults in
394 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45395 configs = [] # Prevent list overwriting warning.
396 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45397
Andrew Grieved5fdf2af2022-08-23 07:47:55398 if (_add_unwind_tables_in_apk) {
399 # Remove -gz if present, as dump_syms does not support it.
400 # Add and then remove because "-=" removes all, but errors if none are found.
401 configs += [ "//build/config:compress_debug_sections" ]
402 configs -= [ "//build/config:compress_debug_sections" ]
403 }
404
jbudorickd29ecfa72016-11-18 22:45:42405 forward_variables_from(
406 invoker,
407 "*",
Andrew Grieved5fdf2af2022-08-23 07:47:55408 [
409 "configs",
410 "deps",
411 ] + _apk_specific_vars + _wrapper_script_vars +
Peter Wen2052bd12020-12-03 20:15:07412 TESTONLY_AND_VISIBILITY)
413
danakj482580a2022-11-18 18:00:59414 # Use a crate name that avoids creating a warning due to double
415 # underscore (ie. `__`).
416 crate_name = _library_crate_name
417
Peter Wen2052bd12020-12-03 20:15:07418 # Native targets do not need to depend on java targets. Filter them out
419 # so that the shared library can be built without needing to wait for
420 # dependent java targets.
421 deps = []
422 if (defined(invoker.deps)) {
Andrew Grieve841ed072022-08-23 16:42:33423 deps = filter_exclude(invoker.deps, java_target_patterns)
Peter Wen2052bd12020-12-03 20:15:07424 }
agrieve62ab00282016-04-05 02:03:45425
Peter Kotwiczb9957d62021-04-12 21:09:43426 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37427 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45428 }
429 }
Andrew Grieveee8aa44d2022-09-23 17:14:38430 unittest_apk(_apk_target_name) {
Daniel Bratellfdda4652019-01-31 15:45:54431 forward_variables_from(invoker, _apk_specific_vars)
Andrew Grieveee8aa44d2022-09-23 17:14:38432 shared_library = ":$_library_target_name"
Sam Maierbc320a9482023-05-17 19:44:16433 if (_generate_final_jni) {
434 srcjar_deps = [ "${shared_library}__jni_registration" ]
435 } else {
436 # TODO(smaier) delete this once we clean up our apk targets to never
437 # have the fallback path of __final_jni.
438 generate_final_jni = _generate_final_jni
439 }
agrieve62ab00282016-04-05 02:03:45440 apk_name = invoker.target_name
441 if (defined(invoker.output_name)) {
442 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45443 install_script_name = "install_${invoker.output_name}"
444 }
agrieveb355ad152016-04-19 03:45:23445
Daniel Bratellfdda4652019-01-31 15:45:54446 if (defined(invoker.deps)) {
447 deps = invoker.deps
448 } else {
449 deps = []
450 }
Andrew Grieve43f24fd02022-04-06 23:04:04451 if (defined(loadable_module_deps)) {
452 deps += loadable_module_deps
453 }
Daniel Bratellfdda4652019-01-31 15:45:54454
jcivellif4462a352017-01-10 04:45:59455 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43456 if (_use_default_launcher) {
457 deps += [ "//base/test:test_support_java" ]
458 }
jcivellif4462a352017-01-10 04:45:59459
Siddhartha764226b2018-03-13 02:32:55460 if (defined(_unwind_table_asset_name)) {
461 deps += [ ":${_unwind_table_asset_name}" ]
462 }
Greg Guterman50ed4b42021-04-08 01:15:11463
464 if (use_rts) {
465 data_deps = [ ":${invoker.target_name}__rts_filters" ]
466 }
agrieve62ab00282016-04-05 02:03:45467 }
Andrew Grievee1dc23f2019-10-22 16:26:36468 }
agrieve62ab00282016-04-05 02:03:45469
Andrew Grievee1dc23f2019-10-22 16:26:36470 test_runner_script(_test_runner_target) {
471 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57472
Andrew Grievee1dc23f2019-10-22 16:26:36473 if (_use_raw_android_executable) {
474 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34475 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36476 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38477 apk_target = ":$_apk_target_name"
Andrew Grievee1dc23f2019-10-22 16:26:36478 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47479
480 # Dep needed for the test runner .runtime_deps file to pick up data
481 # deps from the forward_variables_from(invoker, "*") on the library.
Andrew Grieveee8aa44d2022-09-23 17:14:38482 data_deps = [ ":$_library_target_name" ]
agrieve62ab00282016-04-05 02:03:45483 }
Andrew Grievee1dc23f2019-10-22 16:26:36484 test_name = _output_name
485 test_suite = _output_name
486 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59487
488 if (use_rts) {
489 data_deps += [ ":${invoker.target_name}__rts_filters" ]
490 }
mikecase56d80d72015-06-03 00:57:26491 }
492
Andrew Grieve7ca6de32019-10-18 03:57:47493 # Create a wrapper script rather than using a group() in order to ensure
494 # "ninja $target_name" always works. If this was a group(), then GN would
495 # not create a top-level alias for it if a target exists in another
496 # directory with the same $target_name.
497 # Also - bots run this script directly for "components_perftests".
498 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01499 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47500 executable = "$root_build_dir/bin/run_$_output_name"
501 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22502 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40503 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47504 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40505 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47506 # Dep needed for the swarming .isolate file to pick up data
507 # deps from the forward_variables_from(invoker, "*") on the library.
508 deps += [
Andrew Grieveee8aa44d2022-09-23 17:14:38509 ":$_apk_target_name",
510 ":$_library_target_name",
Andrew Grieve7ca6de32019-10-18 03:57:47511 ]
agrieve62ab00282016-04-05 02:03:45512 }
Dirk Pranke19a58732021-03-24 22:26:22513
514 if (defined(invoker.data_deps)) {
515 data_deps = invoker.data_deps
516 } else {
517 data_deps = []
518 }
Kevin Marshall23529362022-02-23 16:50:36519
520 data_deps += [ "//testing:test_scripts_shared" ]
521
Jamie Madilldd60ee62021-04-13 19:25:52522 if (tests_have_location_tags) {
523 data = [ "//testing/location_tags.json" ]
524 }
Greg Guterman6963dc082021-04-07 05:20:59525
526 if (use_rts) {
527 data_deps += [ ":${invoker.target_name}__rts_filters" ]
528 }
agrieve1a02e582015-10-15 21:35:39529 }
Scott Graham4c4cdc52017-05-29 20:45:03530 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30531 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
532
Scott Graham4c4cdc52017-05-29 20:45:03533 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42534 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42535 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb42022-04-05 12:30:35536 _program_name = get_label_info(":${_exec_target}", "name")
Scott Graham4c4cdc52017-05-29 20:45:03537
Greg Thompson2f1e3762022-10-17 19:53:44538 # Generate a CML fragment that provides the program name.
539 _test_program_fragment_target = "${target_name}_program-fragment"
540 _test_program_fragment = "${target_out_dir}/${target_name}_program.test-cml"
541 generated_file(_test_program_fragment_target) {
542 contents = {
543 program = {
544 binary = _program_name
Kevin Marshall2ec60032022-05-09 17:38:28545 }
Greg Thompson26516592021-12-16 08:34:45546 }
Greg Thompson2f1e3762022-10-17 19:53:44547 outputs = [ _test_program_fragment ]
548 output_conversion = "json"
Greg Thompson9765eeb42022-04-05 12:30:35549 }
550
Greg Thompson2f1e3762022-10-17 19:53:44551 _test_runner_shard =
552 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
553 if (defined(invoker.test_runner_shard)) {
554 _test_runner_shard = invoker.test_runner_shard
Wez6879f8a2021-09-07 20:27:02555 }
556
Greg Thompson2f1e3762022-10-17 19:53:44557 # Collate the complete set of elements to include in the test component's
558 # manifest.
David Dorwin2c4872c2023-02-22 20:00:56559
Greg Thompson2f1e3762022-10-17 19:53:44560 _manifest_fragments = [
Greg Thompson2f1e3762022-10-17 19:53:44561 _test_program_fragment,
562 _test_runner_shard,
563 ]
564
David Dorwin2c4872c2023-02-22 20:00:56565 # Select the Fuchsia test realm in which to run the test.
566 if (defined(invoker.run_as_chromium_system_test) &&
567 invoker.run_as_chromium_system_test) {
568 _manifest_fragments += [
569 "//build/config/fuchsia/test/chromium_system_test_facet.shard.test-cml",
570 "//build/config/fuchsia/test/system_test_minimum.shard.test-cml",
571 ]
572 } else {
573 _manifest_fragments += [
574 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
575 "//build/config/fuchsia/test/minimum.shard.test-cml",
576 ]
577 }
578
Greg Thompson2f1e3762022-10-17 19:53:44579 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
580 _merged_manifest_name = "${_output_name}.cml"
581
582 if (defined(invoker.additional_manifest_fragments)) {
583 _manifest_fragments += invoker.additional_manifest_fragments
584 }
585
586 # Generate the test component manifest from the specified elements.
587 _test_component_manifest_target = "${target_name}_component-manifest"
588 cmc_merge(_test_component_manifest_target) {
589 sources = _manifest_fragments
590 output_name = "${_merged_manifest_name}"
591 deps = [ ":${_test_program_fragment_target}" ]
592 }
593
594 # Define the test component, dependent on the generated manifest, and the
595 # test executable target.
596 _test_component_target = "${target_name}_component"
597 fuchsia_component(_test_component_target) {
598 deps = [ ":$_test_component_manifest_target" ]
599 data_deps = [ ":$_exec_target" ]
600 manifest = _test_component_manifest
601 visibility = [ ":*" ]
602 }
603
604 _test_component_targets = [ ":${_test_component_target}" ]
605
Wez6879f8a2021-09-07 20:27:02606 # Define components for each entry in |additional_manifests|, if any. Since
607 # manifests may themselves depend-on the outputs of |deps|, these components
608 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02609 if (defined(invoker.additional_manifests)) {
610 foreach(filename, invoker.additional_manifests) {
611 _additional_component_target =
612 target_name + "_" + get_path_info(filename, "name")
613 _test_component_targets += [ ":${_additional_component_target}" ]
614 fuchsia_component(_additional_component_target) {
615 forward_variables_from(invoker, [ "testonly" ])
616 data_deps = [ ":$_exec_target" ]
617 visibility = [ ":*" ]
618 manifest = filename
619
620 # Depend on |invoker.deps|, in case it includes a dependency that
621 # creates this additional component's manifest.
622 if (defined(invoker.deps)) {
623 deps = invoker.deps
624 }
625 }
626 }
627 }
628
629 # Define the package target that will bundle the test and additional
630 # components and their data.
631 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21632 forward_variables_from(invoker,
633 [
634 "excluded_files",
635 "excluded_dirs",
Bryant Chandlerc40f2672023-01-27 23:33:30636 "excluded_paths",
Kevin Marshall36c602c2021-11-04 16:16:21637 ])
Wez6879f8a2021-09-07 20:27:02638 package_name = _output_name
639 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21640
Greg Thompsonfd269652022-10-28 12:06:55641 if (defined(invoker.fuchsia_package_deps)) {
642 deps += invoker.fuchsia_package_deps
643 }
Bryant Chandlerc40f2672023-01-27 23:33:30644 if (!defined(excluded_paths)) {
645 excluded_paths = []
Kevin Marshall36c602c2021-11-04 16:16:21646 }
Bryant Chandlerc40f2672023-01-27 23:33:30647 excluded_paths += [
648 "${devtools_root_location}/*",
649 "*.git/*",
650 "*.svn/*",
651 "*.hg/*",
652 ]
Sarah Pham80972efc2022-05-31 17:40:15653 if (devtools_root_location != "") {
Bryant Chandlerc40f2672023-01-27 23:33:30654 excluded_paths += [ "${devtools_root_location}/*" ]
Sarah Pham80972efc2022-05-31 17:40:15655 }
Wez6879f8a2021-09-07 20:27:02656 }
657
658 # |target_name| refers to the package-runner rule, so that building
659 # "base_unittests" will build not only the executable, component, and
660 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25661 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53662 forward_variables_from(invoker,
663 [
Kevin Marshall5fadadd2021-10-16 00:08:25664 "data",
665 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53666 "package_deps",
Kevin Marshall5fadadd2021-10-16 00:08:25667 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53668 ])
Kevin Marshall5fadadd2021-10-16 00:08:25669
Chong Guc6bfdf62021-10-20 23:37:00670 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15671 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25672 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42673
Kevin Marshall5fadadd2021-10-16 00:08:25674 if (!defined(deps)) {
675 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52676 }
Kevin Marshall5fadadd2021-10-16 00:08:25677 if (defined(invoker.deps)) {
678 deps += invoker.deps
679 }
Greg Guterman6963dc082021-04-07 05:20:59680
Kevin Marshall5fadadd2021-10-16 00:08:25681 if (!defined(data)) {
682 data = []
683 }
684 if (tests_have_location_tags) {
685 data += [ "//testing/location_tags.json" ]
686 }
687
688 if (!defined(data_deps)) {
689 data_deps = []
690 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28691
Kevin Marshall23529362022-02-23 16:50:36692 data_deps += [ "//testing:test_scripts_shared" ]
693
Greg Guterman6963dc082021-04-07 05:20:59694 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25695 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59696 }
Kevin Marshallf35fa5f2018-01-29 19:24:42697 }
698
danakjebb9cc4d2022-03-04 21:30:11699 mixed_test(_exec_target) {
700 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01701 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42702 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03703 }
dpranke2a294622015-08-07 05:23:01704 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30705 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46706 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30707
Rohit Raof9b096d2019-09-09 22:26:23708 declare_args() {
709 # Keep the unittest-as-xctest functionality defaulted to off until the
710 # bots are updated to handle it properly.
711 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
712 # supports running unittests with xctest.
713 enable_run_ios_unittests_with_xctest = false
714 }
715
sdefresne012857872016-03-16 10:55:37716 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27717 _output_name = target_name
718 if (defined(invoker.output_name)) {
719 _output_name = invoker.output_name
720 }
721
Jeff Yoonf7f4eb42020-03-06 18:55:36722 _wrapper_output_name = "run_${target_name}"
723 ios_test_runner_wrapper(_wrapper_output_name) {
724 forward_variables_from(invoker,
725 [
726 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36727 "deps",
728 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27729 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36730 "retries",
731 "shards",
732 ])
733
734 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
735
736 if (!defined(executable_args)) {
737 executable_args = []
738 }
739 executable_args += [
740 "--app",
741 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
742 ]
743
744 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22745
746 if (!defined(data)) {
747 data = []
748 }
Jamie Madilldd60ee62021-04-13 19:25:52749 if (tests_have_location_tags) {
750 data += [ "//testing/location_tags.json" ]
751 }
Jeff Yoonf7f4eb42020-03-06 18:55:36752 }
753
sdefresne012857872016-03-16 10:55:37754 _resources_bundle_data = target_name + "_resources_bundle_data"
755
756 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34757 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22758 sources = [ "//testing/gtest_ios/Default.png" ]
759 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01760 }
761
Mirko Bonadei15522bc2020-09-16 20:38:39762 force_xctest = enable_run_ios_unittests_with_xctest ||
763 (defined(invoker.is_xctest) && invoker.is_xctest)
764
danakjfae603fc602022-11-18 18:40:22765 mixed_test(_test_target) {
766 if (force_xctest) {
767 target_type = "ios_xctest_test"
768 } else {
769 target_type = "ios_app_bundle"
770 }
dpranke2a294622015-08-07 05:23:01771 testonly = true
sdefresnea828c282016-05-30 18:04:20772
Mirko Bonadei15522bc2020-09-16 20:38:39773 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23774 xctest_module_target = "//base/test:google_test_runner"
775 }
776
Andrew Grieve1b290e4a22020-11-24 20:07:01777 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13778
779 # Provide sensible defaults in case invoker did not define any of those
780 # required variables.
sdefresne05b97ca2016-06-08 07:19:46781 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13782 info_plist = "//testing/gtest_ios/unittest-Info.plist"
783 }
sdefresne9e147e02016-06-07 00:10:13784
Sylvain Defresne3c5a1312021-09-23 17:08:09785 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13786 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50787 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09788 } else {
Ali Juma75be0fe2022-01-24 19:39:29789 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27790 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09791 }
dpranke2a294622015-08-07 05:23:01792
sdefresne047490e2016-07-22 08:49:34793 if (!defined(bundle_deps)) {
794 bundle_deps = []
795 }
796 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36797
798 if (!defined(data_deps)) {
799 data_deps = []
800 }
801
Kevin Marshall23529362022-02-23 16:50:36802 data_deps += [ "//testing:test_scripts_shared" ]
803
Jeff Yoonf7f4eb42020-03-06 18:55:36804 # Include the generate_wrapper as part of data_deps
805 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46806 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59807
808 if (use_rts) {
809 data_deps += [ ":${invoker.target_name}__rts_filters" ]
810 }
dpranke2a294622015-08-07 05:23:01811 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11812 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
813 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30814 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
815
Yuke Liao2a9b2f0e2021-04-16 00:40:11816 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32817
Benjamin Pastene3bce864e2018-04-14 01:16:32818 _gen_runner_target = "${target_name}__runner"
819 _runtime_deps_file =
820 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
821 "/" + get_label_info(target_name, "name") + ".runtime_deps"
822
Xinan Lin6be01252021-06-25 23:07:36823 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
824 if (is_skylab) {
Struan Shrimptonf61293f62022-04-11 19:33:40825 generate_skylab_deps(_gen_runner_target) {
Xinan Lin6be01252021-06-25 23:07:36826 generated_script = _generated_script
827 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34828 }
Xinan Lin6be01252021-06-25 23:07:36829 } else {
830 generate_runner_script(_gen_runner_target) {
831 generated_script = _generated_script
832 test_exe = invoker.target_name
833 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34834
Xinan Lin6be01252021-06-25 23:07:36835 if (is_chromeos_lacros) {
836 # At build time, Lacros tests don't know whether they'll run on VM or
837 # HW, and instead, these flags are specified at runtime when invoking
838 # the generated runner script.
839 skip_generating_board_args = true
840 }
Greg Guterman6963dc082021-04-07 05:20:59841
Xinan Lin6be01252021-06-25 23:07:36842 if (tests_have_location_tags) {
843 data = [ "//testing/location_tags.json" ]
844 }
845
846 if (use_rts) {
847 data_deps = [ ":${invoker.target_name}__rts_filters" ]
848 }
Greg Guterman6963dc082021-04-07 05:20:59849 }
Benjamin Pastene3bce864e2018-04-14 01:16:32850 }
851
danakjebb9cc4d2022-03-04 21:30:11852 mixed_test(target_name) {
853 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01854 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
855 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32856 if (!defined(deps)) {
857 deps = []
858 }
859 if (!defined(data)) {
860 data = []
861 }
862
Ben Pastene41041782019-02-16 04:21:58863 # We use a special trigger script for CrOS hardware tests.
864 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
865
Benjamin Pastene3bce864e2018-04-14 01:16:32866 write_runtime_deps = _runtime_deps_file
867 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37868 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59869
Kevin Marshall23529362022-02-23 16:50:36870 if (!defined(data_deps)) {
871 data_deps = []
872 }
873
874 data_deps += [ "//testing:test_scripts_shared" ]
875
Greg Guterman6963dc082021-04-07 05:20:59876 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59877 data_deps += [ ":${invoker.target_name}__rts_filters" ]
878 }
Benjamin Pastene3bce864e2018-04-14 01:16:32879 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11880 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24881 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
882 _executable = target_name
883 _gen_runner_target = "${target_name}__runner"
884
Yuke Liao32af4242020-07-16 21:48:02885 if (defined(invoker.use_xvfb)) {
886 _use_xvfb = invoker.use_xvfb
887 } else {
888 _use_xvfb = false
889 }
890
Yuke Liaod037abc2020-10-06 22:48:22891 # When use_xvfb is set by the invoker, it indicates that running this test
892 # target requires a window, and in lacros build, ash-chrome serves as the
893 # display server. Note that even though the tests themselves do not require
894 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
895 # because ash-chrome is based on x11.
896 _use_ash_chrome = _use_xvfb
897
Yuke Liaoe703384b2020-07-16 01:05:24898 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24899 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02900
Yuke Liao2e4953cf2020-07-26 19:20:19901 data = []
Will Harrisd35e2c92021-04-07 01:42:02902 data_deps = [ "//testing:test_scripts_shared" ]
903
Yuke Liao32af4242020-07-16 21:48:02904 if (_use_xvfb) {
905 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22906 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02907 } else {
908 executable = "//testing/test_env.py"
909 }
Jamie Madilldd60ee62021-04-13 19:25:52910 if (tests_have_location_tags) {
911 data += [ "//testing/location_tags.json" ]
912 }
Yuke Liao32af4242020-07-16 21:48:02913
Yuke Liaoe703384b2020-07-16 01:05:24914 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02915 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39916 "test",
Yuke Liaoe703384b2020-07-16 01:05:24917 "@WrappedPath(./${_executable})",
918 "--test-launcher-bot-mode",
919 ]
Yuke Liao32af4242020-07-16 21:48:02920
Yuke Liaof540c742020-07-29 16:28:34921 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37922 executable_args += [ "--ash-chrome-path" ]
923
924 # Can't use --ash-chrome-path=path because WrappedPath
925 # won't be expanded for that usage.
926 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39927 }
928
Yuke Liaoe703384b2020-07-16 01:05:24929 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:00930 executable_args += [ "--asan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24931 }
932 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:00933 executable_args += [ "--msan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24934 }
935 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:00936 executable_args += [ "--tsan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24937 }
938 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:00939 executable_args += [ "--cfi-diag=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24940 }
941
Takuto Ikuta38ebd0e2022-01-19 17:56:22942 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59943
944 if (use_rts) {
945 data_deps += [ ":${invoker.target_name}__rts_filters" ]
946 }
Yuke Liaoe703384b2020-07-16 01:05:24947 }
948
danakjebb9cc4d2022-03-04 21:30:11949 mixed_test(target_name) {
950 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01951 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
952 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24953 if (!defined(deps)) {
954 deps = []
955 }
956
Yuke Liaod037abc2020-10-06 22:48:22957 if (!defined(data_deps)) {
958 data_deps = []
959 }
960
Kevin Marshall23529362022-02-23 16:50:36961 data_deps += [ "//testing:test_scripts_shared" ]
962
Yuke Liaoe703384b2020-07-16 01:05:24963 write_runtime_deps = _runtime_deps_file
964 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22965 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56966 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22967 }
Greg Guterman6963dc082021-04-07 05:20:59968
969 if (use_rts) {
970 data_deps += [ ":${invoker.target_name}__rts_filters" ]
971 }
Yuke Liaoe703384b2020-07-16 01:05:24972 }
Dirk Prankedd4ff742020-11-18 19:57:32973 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30974 if (is_mac || is_win) {
975 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
976 }
977
Dirk Prankedd4ff742020-11-18 19:57:32978 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
979 _executable = target_name
980 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06981
Dirk Prankedd4ff742020-11-18 19:57:32982 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
983 _use_xvfb = invoker.use_xvfb
984 } else {
985 _use_xvfb = false
986 }
987
988 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32989 wrapper_script = "$root_build_dir/bin/run_" + _executable
990
991 data = []
Will Harrisd35e2c92021-04-07 01:42:02992 data_deps = [ "//testing:test_scripts_shared" ]
993
Dirk Prankedd4ff742020-11-18 19:57:32994 if (_use_xvfb) {
995 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06996 } else {
Dirk Prankedd4ff742020-11-18 19:57:32997 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06998 }
Jamie Madilldd60ee62021-04-13 19:25:52999 if (tests_have_location_tags) {
1000 data += [ "//testing/location_tags.json" ]
1001 }
Dirk Pranke31e346e2020-07-15 00:54:061002
Dirk Prankedd4ff742020-11-18 19:57:321003 executable_args = [
1004 "@WrappedPath(./${_executable})",
1005 "--test-launcher-bot-mode",
1006 ]
1007 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:001008 executable_args += [ "--asan=1" ]
Dirk Pranke31e346e2020-07-15 00:54:061009 }
Dirk Prankedd4ff742020-11-18 19:57:321010 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:001011 executable_args += [ "--msan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321012 }
1013 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:001014 executable_args += [ "--tsan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321015 }
1016 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:001017 executable_args += [ "--cfi-diag=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321018 }
1019
Greg Guterman6963dc082021-04-07 05:20:591020 if (use_rts) {
1021 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1022 }
Dirk Pranke31e346e2020-07-15 00:54:061023 }
1024
danakjebb9cc4d2022-03-04 21:30:111025 mixed_test(target_name) {
1026 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011027 forward_variables_from(invoker,
1028 "*",
1029 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
1030 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:061031 if (!defined(deps)) {
1032 deps = []
1033 }
1034
Dirk Pranke31e346e2020-07-15 00:54:061035 deps += [
1036 # Give tests the default manifest on Windows (a no-op elsewhere).
1037 "//build/win:default_exe_manifest",
1038 ]
1039
Dirk Prankedd4ff742020-11-18 19:57:321040 write_runtime_deps = _runtime_deps_file
1041 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:111042
Kevin Marshall23529362022-02-23 16:50:361043 if (!defined(data_deps)) {
1044 data_deps = []
1045 }
1046
1047 data_deps += [ "//testing:test_scripts_shared" ]
1048
Greg Guterman50ed4b42021-04-08 01:15:111049 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:111050 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1051 }
Dirk Prankedd4ff742020-11-18 19:57:321052 }
1053 } else {
1054 # This is a catch-all clause for NaCl toolchains and other random
1055 # configurations that might define tests; test() in these configs
1056 # will just define the underlying executables.
1057 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
1058 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:111059 mixed_test(target_name) {
1060 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011061 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1062 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:321063 if (!defined(deps)) {
1064 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061065 }
Greg Guterman6963dc082021-04-07 05:20:591066
Kevin Marshall23529362022-02-23 16:50:361067 if (!defined(data_deps)) {
1068 data_deps = []
1069 }
1070
1071 data_deps += [ "//testing:test_scripts_shared" ]
1072
Greg Guterman6963dc082021-04-07 05:20:591073 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:591074 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1075 }
Dirk Pranke31e346e2020-07-15 00:54:061076 }
qsrfb5251d12015-01-21 15:57:221077 }
1078}
brettwedb6ecc2016-07-14 23:37:031079
Dirk Pranke6188075b2020-10-01 19:31:281080# Defines a type of test that invokes a script to run, rather than
1081# invoking an executable.
1082#
1083# The script must implement the
1084# [test executable API](//docs/testing/test_executable_api.md).
1085#
Andrew Grievea16222d42023-02-10 15:31:101086# The template must be passed the `script` parameter, which specifies the path
1087# to the script to run. It may optionally be passed a `args` parameter, which
1088# can be used to include a list of args to be specified by default. The
1089# template will produce a `$root_build_dir/run_$target_name` wrapper and write
1090# the runtime_deps for the target to
1091# $root_build_dir/${target_name}.runtime_deps, as per the conventions listed in
1092# the [test wrapper API](//docs/testing/test_wrapper_api.md).
Dirk Pranke6188075b2020-10-01 19:31:281093template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:591094 if (use_rts) {
1095 action("${target_name}__rts_filters") {
1096 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:531097 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:051098 inverted_rts_file =
1099 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
1100 args = [
1101 rebase_path(rts_file, root_build_dir),
1102 rebase_path(inverted_rts_file, root_build_dir),
1103 ]
1104 outputs = [
1105 rts_file,
1106 inverted_rts_file,
1107 ]
Greg Guterman6963dc082021-04-07 05:20:591108 }
1109 }
1110
Dirk Pranke6188075b2020-10-01 19:31:281111 generate_wrapper(target_name) {
1112 testonly = true
1113 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1114
1115 executable = "//testing/test_env.py"
1116
1117 executable_args =
1118 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1119 if (defined(invoker.args)) {
1120 executable_args += invoker.args
1121 }
1122
Will Harrisd35e2c92021-04-07 01:42:021123 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471124
Dirk Pranke6188075b2020-10-01 19:31:281125 if (defined(invoker.data)) {
1126 data += invoker.data
1127 }
Jamie Madilldd60ee62021-04-13 19:25:521128 if (tests_have_location_tags) {
1129 data += [ "//testing/location_tags.json" ]
1130 }
Dirk Pranke19a58732021-03-24 22:26:221131
Will Harrisd35e2c92021-04-07 01:42:021132 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281133 if (defined(invoker.data_deps)) {
1134 data_deps += invoker.data_deps
1135 }
1136
1137 forward_variables_from(invoker,
Andrew Grievea16222d42023-02-10 15:31:101138 "*",
Andrew Grieve1b290e4a22020-11-24 20:07:011139 TESTONLY_AND_VISIBILITY + [
Andrew Grievea16222d42023-02-10 15:31:101140 "args",
Andrew Grieve1b290e4a22020-11-24 20:07:011141 "data",
1142 "data_deps",
1143 "script",
Andrew Grieve1b290e4a22020-11-24 20:07:011144 ])
1145 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281146
1147 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591148
1149 if (use_rts) {
1150 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1151 }
Dirk Pranke6188075b2020-10-01 19:31:281152 }
1153}
1154
Andrew Grievea16222d42023-02-10 15:31:101155# Defines a test target that uses exit code for pass/fail.
1156template("isolated_script_test") {
1157 script_test(target_name) {
1158 forward_variables_from(invoker,
1159 "*",
1160 TESTONLY_AND_VISIBILITY + [
1161 "args",
1162 "deps",
1163 "script",
1164 ])
1165 forward_variables_from(invoker, [ "visibility" ])
1166 deps = [ "//testing:run_isolated_script_test" ]
1167 if (defined(invoker.deps)) {
1168 deps += invoker.deps
1169 }
1170 script = "//testing/scripts/run_isolated_script_test.py"
1171 data = [ invoker.script ]
1172 args = [
1173 rebase_path(invoker.script, root_build_dir),
1174 "--script-type=bare",
1175 ]
1176 if (defined(invoker.args)) {
1177 args += invoker.args
1178 }
1179 }
1180}
1181
brettwedb6ecc2016-07-14 23:37:031182# Test defaults.
1183set_defaults("test") {
1184 if (is_android) {
1185 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411186 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591187 configs += [ "//build/config/android:hide_all_but_jni" ]
Andrew Grieved5fdf2af2022-08-23 07:47:551188
1189 # Compress sections to stay under 4gb hard limit on 32-bit current_cpu.
1190 # https://crbug.com/1354616
1191 if (symbol_level == 2 && !use_debug_fission &&
1192 (current_cpu == "arm" || current_cpu == "x86")) {
1193 configs += [ "//build/config:compress_debug_sections" ]
1194 }
brettwedb6ecc2016-07-14 23:37:031195 } else {
1196 configs = default_executable_configs
1197 }
1198}