blob: 470f1c8014570252c109f27bd38bb0f69ae33a5f [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
Zijie He78d978e2023-07-19 21:46:42574 if (is_asan) {
575 # TODO(crbug.com/1465997): Remove the extra cml segment for asan.
576 _manifest_fragments +=
577 [ "//build/config/fuchsia/test/asan_options.shard.test-cml" ]
578 }
579
Greg Thompson2f1e3762022-10-17 19:53:44580 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
581 _merged_manifest_name = "${_output_name}.cml"
582
583 if (defined(invoker.additional_manifest_fragments)) {
584 _manifest_fragments += invoker.additional_manifest_fragments
585 }
586
587 # Generate the test component manifest from the specified elements.
588 _test_component_manifest_target = "${target_name}_component-manifest"
589 cmc_merge(_test_component_manifest_target) {
590 sources = _manifest_fragments
591 output_name = "${_merged_manifest_name}"
592 deps = [ ":${_test_program_fragment_target}" ]
593 }
594
595 # Define the test component, dependent on the generated manifest, and the
596 # test executable target.
597 _test_component_target = "${target_name}_component"
598 fuchsia_component(_test_component_target) {
599 deps = [ ":$_test_component_manifest_target" ]
600 data_deps = [ ":$_exec_target" ]
601 manifest = _test_component_manifest
602 visibility = [ ":*" ]
603 }
604
605 _test_component_targets = [ ":${_test_component_target}" ]
606
Wez6879f8a2021-09-07 20:27:02607 # Define components for each entry in |additional_manifests|, if any. Since
608 # manifests may themselves depend-on the outputs of |deps|, these components
609 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02610 if (defined(invoker.additional_manifests)) {
611 foreach(filename, invoker.additional_manifests) {
612 _additional_component_target =
613 target_name + "_" + get_path_info(filename, "name")
614 _test_component_targets += [ ":${_additional_component_target}" ]
615 fuchsia_component(_additional_component_target) {
616 forward_variables_from(invoker, [ "testonly" ])
617 data_deps = [ ":$_exec_target" ]
618 visibility = [ ":*" ]
619 manifest = filename
620
621 # Depend on |invoker.deps|, in case it includes a dependency that
622 # creates this additional component's manifest.
623 if (defined(invoker.deps)) {
624 deps = invoker.deps
625 }
626 }
627 }
628 }
629
630 # Define the package target that will bundle the test and additional
631 # components and their data.
632 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21633 forward_variables_from(invoker,
634 [
635 "excluded_files",
636 "excluded_dirs",
Bryant Chandlerc40f2672023-01-27 23:33:30637 "excluded_paths",
Kevin Marshall36c602c2021-11-04 16:16:21638 ])
Wez6879f8a2021-09-07 20:27:02639 package_name = _output_name
640 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21641
Greg Thompsonfd269652022-10-28 12:06:55642 if (defined(invoker.fuchsia_package_deps)) {
643 deps += invoker.fuchsia_package_deps
644 }
Bryant Chandlerc40f2672023-01-27 23:33:30645 if (!defined(excluded_paths)) {
646 excluded_paths = []
Kevin Marshall36c602c2021-11-04 16:16:21647 }
Bryant Chandlerc40f2672023-01-27 23:33:30648 excluded_paths += [
649 "${devtools_root_location}/*",
650 "*.git/*",
651 "*.svn/*",
652 "*.hg/*",
653 ]
Sarah Pham80972efc2022-05-31 17:40:15654 if (devtools_root_location != "") {
Bryant Chandlerc40f2672023-01-27 23:33:30655 excluded_paths += [ "${devtools_root_location}/*" ]
Sarah Pham80972efc2022-05-31 17:40:15656 }
Wez6879f8a2021-09-07 20:27:02657 }
658
659 # |target_name| refers to the package-runner rule, so that building
660 # "base_unittests" will build not only the executable, component, and
661 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25662 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53663 forward_variables_from(invoker,
664 [
Kevin Marshall5fadadd2021-10-16 00:08:25665 "data",
666 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53667 "package_deps",
Kevin Marshall5fadadd2021-10-16 00:08:25668 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53669 ])
Kevin Marshall5fadadd2021-10-16 00:08:25670
Chong Guc6bfdf62021-10-20 23:37:00671 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15672 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25673 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42674
Kevin Marshall5fadadd2021-10-16 00:08:25675 if (!defined(deps)) {
676 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52677 }
Kevin Marshall5fadadd2021-10-16 00:08:25678 if (defined(invoker.deps)) {
679 deps += invoker.deps
680 }
Greg Guterman6963dc082021-04-07 05:20:59681
Kevin Marshall5fadadd2021-10-16 00:08:25682 if (!defined(data)) {
683 data = []
684 }
685 if (tests_have_location_tags) {
686 data += [ "//testing/location_tags.json" ]
687 }
688
689 if (!defined(data_deps)) {
690 data_deps = []
691 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28692
Kevin Marshall23529362022-02-23 16:50:36693 data_deps += [ "//testing:test_scripts_shared" ]
694
Greg Guterman6963dc082021-04-07 05:20:59695 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25696 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59697 }
Kevin Marshallf35fa5f2018-01-29 19:24:42698 }
699
danakjebb9cc4d2022-03-04 21:30:11700 mixed_test(_exec_target) {
701 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01702 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42703 output_name = _exec_target
danakj505b7f062023-07-05 19:02:02704
705 # Use a crate name that avoids creating a warning due to double
706 # underscore (ie. `__`).
707 crate_name = _crate_name
Scott Graham4c4cdc52017-05-29 20:45:03708 }
dpranke2a294622015-08-07 05:23:01709 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30710 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46711 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30712
Rohit Raof9b096d2019-09-09 22:26:23713 declare_args() {
Zhaoyang Li34fb05e2023-07-25 18:02:00714 # Keep the unittest-as-xctest functionality defaulted to off for
715 # local builds and test executions.
Rohit Raof9b096d2019-09-09 22:26:23716 enable_run_ios_unittests_with_xctest = false
717 }
718
sdefresne012857872016-03-16 10:55:37719 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27720 _output_name = target_name
721 if (defined(invoker.output_name)) {
722 _output_name = invoker.output_name
723 }
724
Jeff Yoonf7f4eb42020-03-06 18:55:36725 _wrapper_output_name = "run_${target_name}"
726 ios_test_runner_wrapper(_wrapper_output_name) {
727 forward_variables_from(invoker,
728 [
729 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36730 "deps",
731 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27732 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36733 "retries",
734 "shards",
735 ])
736
737 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
738
739 if (!defined(executable_args)) {
740 executable_args = []
741 }
742 executable_args += [
743 "--app",
744 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
745 ]
746
747 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22748
749 if (!defined(data)) {
750 data = []
751 }
Jamie Madilldd60ee62021-04-13 19:25:52752 if (tests_have_location_tags) {
753 data += [ "//testing/location_tags.json" ]
754 }
Jeff Yoonf7f4eb42020-03-06 18:55:36755 }
756
sdefresne012857872016-03-16 10:55:37757 _resources_bundle_data = target_name + "_resources_bundle_data"
758
759 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34760 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22761 sources = [ "//testing/gtest_ios/Default.png" ]
762 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01763 }
764
Mirko Bonadei15522bc2020-09-16 20:38:39765 force_xctest = enable_run_ios_unittests_with_xctest ||
766 (defined(invoker.is_xctest) && invoker.is_xctest)
767
danakjfae603fc602022-11-18 18:40:22768 mixed_test(_test_target) {
769 if (force_xctest) {
770 target_type = "ios_xctest_test"
771 } else {
772 target_type = "ios_app_bundle"
773 }
dpranke2a294622015-08-07 05:23:01774 testonly = true
sdefresnea828c282016-05-30 18:04:20775
Mirko Bonadei15522bc2020-09-16 20:38:39776 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23777 xctest_module_target = "//base/test:google_test_runner"
778 }
779
Andrew Grieve1b290e4a22020-11-24 20:07:01780 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13781
782 # Provide sensible defaults in case invoker did not define any of those
783 # required variables.
sdefresne05b97ca2016-06-08 07:19:46784 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13785 info_plist = "//testing/gtest_ios/unittest-Info.plist"
786 }
sdefresne9e147e02016-06-07 00:10:13787
Sylvain Defresne3c5a1312021-09-23 17:08:09788 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13789 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50790 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09791 } else {
Ali Juma75be0fe2022-01-24 19:39:29792 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27793 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09794 }
dpranke2a294622015-08-07 05:23:01795
sdefresne047490e2016-07-22 08:49:34796 if (!defined(bundle_deps)) {
797 bundle_deps = []
798 }
799 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36800
801 if (!defined(data_deps)) {
802 data_deps = []
803 }
804
Kevin Marshall23529362022-02-23 16:50:36805 data_deps += [ "//testing:test_scripts_shared" ]
806
Jeff Yoonf7f4eb42020-03-06 18:55:36807 # Include the generate_wrapper as part of data_deps
808 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46809 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59810
811 if (use_rts) {
812 data_deps += [ ":${invoker.target_name}__rts_filters" ]
813 }
dpranke2a294622015-08-07 05:23:01814 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11815 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
816 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30817 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
818
Yuke Liao2a9b2f0e2021-04-16 00:40:11819 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32820
Benjamin Pastene3bce864e2018-04-14 01:16:32821 _gen_runner_target = "${target_name}__runner"
822 _runtime_deps_file =
823 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
824 "/" + get_label_info(target_name, "name") + ".runtime_deps"
825
Xinan Lin6be01252021-06-25 23:07:36826 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
827 if (is_skylab) {
Struan Shrimptonf61293f62022-04-11 19:33:40828 generate_skylab_deps(_gen_runner_target) {
Xinan Lin6be01252021-06-25 23:07:36829 generated_script = _generated_script
830 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34831 }
Xinan Lin6be01252021-06-25 23:07:36832 } else {
833 generate_runner_script(_gen_runner_target) {
834 generated_script = _generated_script
835 test_exe = invoker.target_name
836 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34837
Xinan Lin6be01252021-06-25 23:07:36838 if (is_chromeos_lacros) {
839 # At build time, Lacros tests don't know whether they'll run on VM or
840 # HW, and instead, these flags are specified at runtime when invoking
841 # the generated runner script.
842 skip_generating_board_args = true
843 }
Greg Guterman6963dc082021-04-07 05:20:59844
Xinan Lin6be01252021-06-25 23:07:36845 if (tests_have_location_tags) {
846 data = [ "//testing/location_tags.json" ]
847 }
848
849 if (use_rts) {
850 data_deps = [ ":${invoker.target_name}__rts_filters" ]
851 }
Greg Guterman6963dc082021-04-07 05:20:59852 }
Benjamin Pastene3bce864e2018-04-14 01:16:32853 }
854
danakjebb9cc4d2022-03-04 21:30:11855 mixed_test(target_name) {
856 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01857 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
858 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32859 if (!defined(deps)) {
860 deps = []
861 }
862 if (!defined(data)) {
863 data = []
864 }
865
Ben Pastene41041782019-02-16 04:21:58866 # We use a special trigger script for CrOS hardware tests.
867 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
868
Benjamin Pastene3bce864e2018-04-14 01:16:32869 write_runtime_deps = _runtime_deps_file
870 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37871 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59872
Kevin Marshall23529362022-02-23 16:50:36873 if (!defined(data_deps)) {
874 data_deps = []
875 }
876
877 data_deps += [ "//testing:test_scripts_shared" ]
878
Greg Guterman6963dc082021-04-07 05:20:59879 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59880 data_deps += [ ":${invoker.target_name}__rts_filters" ]
881 }
Benjamin Pastene3bce864e2018-04-14 01:16:32882 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11883 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24884 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
885 _executable = target_name
886 _gen_runner_target = "${target_name}__runner"
887
Yuke Liao32af4242020-07-16 21:48:02888 if (defined(invoker.use_xvfb)) {
889 _use_xvfb = invoker.use_xvfb
890 } else {
891 _use_xvfb = false
892 }
893
Yuke Liaod037abc2020-10-06 22:48:22894 # When use_xvfb is set by the invoker, it indicates that running this test
895 # target requires a window, and in lacros build, ash-chrome serves as the
896 # display server. Note that even though the tests themselves do not require
897 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
898 # because ash-chrome is based on x11.
899 _use_ash_chrome = _use_xvfb
900
Yuke Liaoe703384b2020-07-16 01:05:24901 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24902 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02903
Yuke Liao2e4953cf2020-07-26 19:20:19904 data = []
Will Harrisd35e2c92021-04-07 01:42:02905 data_deps = [ "//testing:test_scripts_shared" ]
906
Yuke Liao32af4242020-07-16 21:48:02907 if (_use_xvfb) {
908 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22909 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02910 } else {
911 executable = "//testing/test_env.py"
912 }
Jamie Madilldd60ee62021-04-13 19:25:52913 if (tests_have_location_tags) {
914 data += [ "//testing/location_tags.json" ]
915 }
Yuke Liao32af4242020-07-16 21:48:02916
Yuke Liaoe703384b2020-07-16 01:05:24917 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02918 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39919 "test",
Yuke Liaoe703384b2020-07-16 01:05:24920 "@WrappedPath(./${_executable})",
921 "--test-launcher-bot-mode",
922 ]
Yuke Liao32af4242020-07-16 21:48:02923
Yuke Liaof540c742020-07-29 16:28:34924 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37925 executable_args += [ "--ash-chrome-path" ]
926
927 # Can't use --ash-chrome-path=path because WrappedPath
928 # won't be expanded for that usage.
929 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39930 }
931
Yuke Liaoe703384b2020-07-16 01:05:24932 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:00933 executable_args += [ "--asan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24934 }
935 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:00936 executable_args += [ "--msan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24937 }
938 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:00939 executable_args += [ "--tsan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24940 }
941 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:00942 executable_args += [ "--cfi-diag=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24943 }
Ian Struiksma2ebc3222023-05-24 00:28:46944 if (fail_on_san_warnings) {
945 executable_args += [ "--fail-san=1" ]
946 }
Yuke Liaoe703384b2020-07-16 01:05:24947
Takuto Ikuta38ebd0e2022-01-19 17:56:22948 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59949
950 if (use_rts) {
951 data_deps += [ ":${invoker.target_name}__rts_filters" ]
952 }
Yuke Liaoe703384b2020-07-16 01:05:24953 }
954
danakjebb9cc4d2022-03-04 21:30:11955 mixed_test(target_name) {
956 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01957 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
958 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24959 if (!defined(deps)) {
960 deps = []
961 }
962
Yuke Liaod037abc2020-10-06 22:48:22963 if (!defined(data_deps)) {
964 data_deps = []
965 }
966
Kevin Marshall23529362022-02-23 16:50:36967 data_deps += [ "//testing:test_scripts_shared" ]
968
Yuke Liaoe703384b2020-07-16 01:05:24969 write_runtime_deps = _runtime_deps_file
970 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22971 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56972 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22973 }
Greg Guterman6963dc082021-04-07 05:20:59974
975 if (use_rts) {
976 data_deps += [ ":${invoker.target_name}__rts_filters" ]
977 }
Yuke Liaoe703384b2020-07-16 01:05:24978 }
Dirk Prankedd4ff742020-11-18 19:57:32979 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30980 if (is_mac || is_win) {
981 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
982 }
983
Dirk Prankedd4ff742020-11-18 19:57:32984 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
985 _executable = target_name
986 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06987
Dirk Prankedd4ff742020-11-18 19:57:32988 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
989 _use_xvfb = invoker.use_xvfb
990 } else {
991 _use_xvfb = false
992 }
993
994 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32995 wrapper_script = "$root_build_dir/bin/run_" + _executable
996
997 data = []
Will Harrisd35e2c92021-04-07 01:42:02998 data_deps = [ "//testing:test_scripts_shared" ]
999
Dirk Prankedd4ff742020-11-18 19:57:321000 if (_use_xvfb) {
1001 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:061002 } else {
Dirk Prankedd4ff742020-11-18 19:57:321003 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:061004 }
Jamie Madilldd60ee62021-04-13 19:25:521005 if (tests_have_location_tags) {
1006 data += [ "//testing/location_tags.json" ]
1007 }
Dirk Pranke31e346e2020-07-15 00:54:061008
Dirk Prankedd4ff742020-11-18 19:57:321009 executable_args = [
1010 "@WrappedPath(./${_executable})",
1011 "--test-launcher-bot-mode",
1012 ]
1013 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:001014 executable_args += [ "--asan=1" ]
Dirk Pranke31e346e2020-07-15 00:54:061015 }
Dirk Prankedd4ff742020-11-18 19:57:321016 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:001017 executable_args += [ "--msan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321018 }
1019 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:001020 executable_args += [ "--tsan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321021 }
1022 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:001023 executable_args += [ "--cfi-diag=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321024 }
Ian Struiksma2ebc3222023-05-24 00:28:461025 if (fail_on_san_warnings) {
1026 executable_args += [ "--fail-san=1" ]
1027 }
Dirk Prankedd4ff742020-11-18 19:57:321028
Greg Guterman6963dc082021-04-07 05:20:591029 if (use_rts) {
1030 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1031 }
Dirk Pranke31e346e2020-07-15 00:54:061032 }
1033
danakjebb9cc4d2022-03-04 21:30:111034 mixed_test(target_name) {
1035 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011036 forward_variables_from(invoker,
1037 "*",
1038 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
1039 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:061040 if (!defined(deps)) {
1041 deps = []
1042 }
1043
Dirk Pranke31e346e2020-07-15 00:54:061044 deps += [
1045 # Give tests the default manifest on Windows (a no-op elsewhere).
1046 "//build/win:default_exe_manifest",
1047 ]
1048
Dirk Prankedd4ff742020-11-18 19:57:321049 write_runtime_deps = _runtime_deps_file
1050 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:111051
Kevin Marshall23529362022-02-23 16:50:361052 if (!defined(data_deps)) {
1053 data_deps = []
1054 }
1055
1056 data_deps += [ "//testing:test_scripts_shared" ]
1057
Greg Guterman50ed4b42021-04-08 01:15:111058 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:111059 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1060 }
Dirk Prankedd4ff742020-11-18 19:57:321061 }
1062 } else {
1063 # This is a catch-all clause for NaCl toolchains and other random
1064 # configurations that might define tests; test() in these configs
1065 # will just define the underlying executables.
1066 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
1067 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:111068 mixed_test(target_name) {
1069 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011070 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1071 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:321072 if (!defined(deps)) {
1073 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061074 }
Greg Guterman6963dc082021-04-07 05:20:591075
Kevin Marshall23529362022-02-23 16:50:361076 if (!defined(data_deps)) {
1077 data_deps = []
1078 }
1079
1080 data_deps += [ "//testing:test_scripts_shared" ]
1081
Greg Guterman6963dc082021-04-07 05:20:591082 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:591083 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1084 }
Dirk Pranke31e346e2020-07-15 00:54:061085 }
qsrfb5251d12015-01-21 15:57:221086 }
1087}
brettwedb6ecc2016-07-14 23:37:031088
Dirk Pranke6188075b2020-10-01 19:31:281089# Defines a type of test that invokes a script to run, rather than
1090# invoking an executable.
1091#
1092# The script must implement the
1093# [test executable API](//docs/testing/test_executable_api.md).
1094#
Andrew Grievea16222d42023-02-10 15:31:101095# The template must be passed the `script` parameter, which specifies the path
1096# to the script to run. It may optionally be passed a `args` parameter, which
1097# can be used to include a list of args to be specified by default. The
1098# template will produce a `$root_build_dir/run_$target_name` wrapper and write
1099# the runtime_deps for the target to
1100# $root_build_dir/${target_name}.runtime_deps, as per the conventions listed in
1101# the [test wrapper API](//docs/testing/test_wrapper_api.md).
Dirk Pranke6188075b2020-10-01 19:31:281102template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:591103 if (use_rts) {
1104 action("${target_name}__rts_filters") {
1105 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:531106 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:051107 inverted_rts_file =
1108 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
1109 args = [
1110 rebase_path(rts_file, root_build_dir),
1111 rebase_path(inverted_rts_file, root_build_dir),
1112 ]
1113 outputs = [
1114 rts_file,
1115 inverted_rts_file,
1116 ]
Greg Guterman6963dc082021-04-07 05:20:591117 }
1118 }
1119
Dirk Pranke6188075b2020-10-01 19:31:281120 generate_wrapper(target_name) {
1121 testonly = true
1122 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1123
1124 executable = "//testing/test_env.py"
1125
1126 executable_args =
1127 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1128 if (defined(invoker.args)) {
1129 executable_args += invoker.args
1130 }
1131
Will Harrisd35e2c92021-04-07 01:42:021132 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471133
Dirk Pranke6188075b2020-10-01 19:31:281134 if (defined(invoker.data)) {
1135 data += invoker.data
1136 }
Jamie Madilldd60ee62021-04-13 19:25:521137 if (tests_have_location_tags) {
1138 data += [ "//testing/location_tags.json" ]
1139 }
Dirk Pranke19a58732021-03-24 22:26:221140
Will Harrisd35e2c92021-04-07 01:42:021141 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281142 if (defined(invoker.data_deps)) {
1143 data_deps += invoker.data_deps
1144 }
1145
1146 forward_variables_from(invoker,
Andrew Grievea16222d42023-02-10 15:31:101147 "*",
Andrew Grieve1b290e4a22020-11-24 20:07:011148 TESTONLY_AND_VISIBILITY + [
Andrew Grievea16222d42023-02-10 15:31:101149 "args",
Andrew Grieve1b290e4a22020-11-24 20:07:011150 "data",
1151 "data_deps",
1152 "script",
Andrew Grieve1b290e4a22020-11-24 20:07:011153 ])
1154 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281155
1156 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591157
1158 if (use_rts) {
1159 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1160 }
Dirk Pranke6188075b2020-10-01 19:31:281161 }
1162}
1163
Andrew Grievea16222d42023-02-10 15:31:101164# Defines a test target that uses exit code for pass/fail.
1165template("isolated_script_test") {
1166 script_test(target_name) {
1167 forward_variables_from(invoker,
1168 "*",
1169 TESTONLY_AND_VISIBILITY + [
1170 "args",
1171 "deps",
1172 "script",
1173 ])
1174 forward_variables_from(invoker, [ "visibility" ])
1175 deps = [ "//testing:run_isolated_script_test" ]
1176 if (defined(invoker.deps)) {
1177 deps += invoker.deps
1178 }
1179 script = "//testing/scripts/run_isolated_script_test.py"
1180 data = [ invoker.script ]
1181 args = [
1182 rebase_path(invoker.script, root_build_dir),
1183 "--script-type=bare",
1184 ]
1185 if (defined(invoker.args)) {
1186 args += invoker.args
1187 }
1188 }
1189}
1190
brettwedb6ecc2016-07-14 23:37:031191# Test defaults.
1192set_defaults("test") {
1193 if (is_android) {
1194 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411195 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591196 configs += [ "//build/config/android:hide_all_but_jni" ]
Andrew Grieved5fdf2af2022-08-23 07:47:551197
1198 # Compress sections to stay under 4gb hard limit on 32-bit current_cpu.
1199 # https://crbug.com/1354616
1200 if (symbol_level == 2 && !use_debug_fission &&
1201 (current_cpu == "arm" || current_cpu == "x86")) {
1202 configs += [ "//build/config:compress_debug_sections" ]
1203 }
brettwedb6ecc2016-07-14 23:37:031204 } else {
1205 configs = default_executable_configs
1206 }
1207}