blob: d193b6074b0a6e581b374b33aa69f816e8f1dde4 [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",
Peter Kotwicz10742f82021-04-15 22:32:50338 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07339 "product_config_java_packages",
Andrew Grieve43f24fd02022-04-06 23:04:04340 "loadable_modules",
341 "loadable_module_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02342 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07343 "proguard_configs",
344 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45345 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02346 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45347 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56348 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45349 ]
Siddhartha764226b2018-03-13 02:32:55350
Andrew Grieveee8aa44d2022-09-23 17:14:38351 _add_unwind_tables_in_apk =
352 defined(invoker.add_unwind_tables_in_apk) &&
353 invoker.add_unwind_tables_in_apk && target_cpu == "arm"
Andrew Grieved5fdf2af2022-08-23 07:47:55354
Siddhartha764226b2018-03-13 02:32:55355 # Adds the unwind tables from unstripped binary as an asset file in the
356 # apk, if |add_unwind_tables_in_apk| is specified by the test.
Andrew Grieved5fdf2af2022-08-23 07:47:55357 if (_add_unwind_tables_in_apk) {
Andrew Grieveee8aa44d2022-09-23 17:14:38358 # TODO(crbug.com/1315603): Remove generation of v1 unwind asset when
Tushar Agarwaldcafb622022-11-30 17:32:27359 # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroid`.
Andrew Grieveee8aa44d2022-09-23 17:14:38360 _unwind_table_name = "${_library_target_name}_unwind_v1"
361 unwind_table_v1(_unwind_table_name) {
362 library_target = ":$_library_target_name"
363 }
364
Arthur Sonzogni54424e92022-09-23 13:30:45365 if (use_android_unwinder_v2) {
Andrew Grieveee8aa44d2022-09-23 17:14:38366 _unwind_table_v2_name = "${_library_target_name}_unwind_v2"
367 unwind_table_v2(_unwind_table_v2_name) {
368 library_target = ":$_library_target_name"
Arthur Sonzogni54424e92022-09-23 13:30:45369 }
370 }
371
Andrew Grieveee8aa44d2022-09-23 17:14:38372 _unwind_table_asset_name = "${target_name}__unwind_assets"
373 android_assets(_unwind_table_asset_name) {
374 sources = [ "$target_out_dir/$_unwind_table_name/$unwind_table_asset_v1_filename" ]
375 disable_compression = true
376 deps = [ ":$_unwind_table_name" ]
377 if (use_android_unwinder_v2) {
378 sources += [ "$target_out_dir/$_unwind_table_v2_name/$unwind_table_asset_v2_filename" ]
379 deps += [ ":$_unwind_table_v2_name" ]
380 }
Siddhartha764226b2018-03-13 02:32:55381 }
382 }
383
Andrew Grieveee8aa44d2022-09-23 17:14:38384 mixed_test(_library_target_name) {
Sam Maier7acb8d6b2023-05-15 14:00:22385 target_type = "shared_library_with_jni"
386 java_targets = [ ":$_apk_target_name" ]
danakjebb9cc4d2022-03-04 21:30:11387
danakj98e073722022-02-24 21:01:49388 # Configs will always be defined since we set_defaults in
389 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45390 configs = [] # Prevent list overwriting warning.
391 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45392
Andrew Grieved5fdf2af2022-08-23 07:47:55393 if (_add_unwind_tables_in_apk) {
394 # Remove -gz if present, as dump_syms does not support it.
395 # Add and then remove because "-=" removes all, but errors if none are found.
396 configs += [ "//build/config:compress_debug_sections" ]
397 configs -= [ "//build/config:compress_debug_sections" ]
398 }
399
jbudorickd29ecfa72016-11-18 22:45:42400 forward_variables_from(
401 invoker,
402 "*",
Andrew Grieved5fdf2af2022-08-23 07:47:55403 [
404 "configs",
405 "deps",
406 ] + _apk_specific_vars + _wrapper_script_vars +
Peter Wen2052bd12020-12-03 20:15:07407 TESTONLY_AND_VISIBILITY)
408
danakj482580a2022-11-18 18:00:59409 # Use a crate name that avoids creating a warning due to double
410 # underscore (ie. `__`).
411 crate_name = _library_crate_name
412
Peter Wen2052bd12020-12-03 20:15:07413 # Native targets do not need to depend on java targets. Filter them out
414 # so that the shared library can be built without needing to wait for
415 # dependent java targets.
416 deps = []
417 if (defined(invoker.deps)) {
Andrew Grieve841ed072022-08-23 16:42:33418 deps = filter_exclude(invoker.deps, java_target_patterns)
Peter Wen2052bd12020-12-03 20:15:07419 }
agrieve62ab00282016-04-05 02:03:45420
Peter Kotwiczb9957d62021-04-12 21:09:43421 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37422 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45423 }
424 }
Andrew Grieveee8aa44d2022-09-23 17:14:38425 unittest_apk(_apk_target_name) {
Daniel Bratellfdda4652019-01-31 15:45:54426 forward_variables_from(invoker, _apk_specific_vars)
Andrew Grieveee8aa44d2022-09-23 17:14:38427 shared_library = ":$_library_target_name"
Sam Maier7acb8d6b2023-05-15 14:00:22428 srcjar_deps = [ "${shared_library}__jni_registration" ]
agrieve62ab00282016-04-05 02:03:45429 apk_name = invoker.target_name
430 if (defined(invoker.output_name)) {
431 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45432 install_script_name = "install_${invoker.output_name}"
433 }
agrieveb355ad152016-04-19 03:45:23434
Daniel Bratellfdda4652019-01-31 15:45:54435 if (defined(invoker.deps)) {
436 deps = invoker.deps
437 } else {
438 deps = []
439 }
Andrew Grieve43f24fd02022-04-06 23:04:04440 if (defined(loadable_module_deps)) {
441 deps += loadable_module_deps
442 }
Daniel Bratellfdda4652019-01-31 15:45:54443
jcivellif4462a352017-01-10 04:45:59444 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43445 if (_use_default_launcher) {
446 deps += [ "//base/test:test_support_java" ]
447 }
jcivellif4462a352017-01-10 04:45:59448
Siddhartha764226b2018-03-13 02:32:55449 if (defined(_unwind_table_asset_name)) {
450 deps += [ ":${_unwind_table_asset_name}" ]
451 }
Greg Guterman50ed4b42021-04-08 01:15:11452
453 if (use_rts) {
454 data_deps = [ ":${invoker.target_name}__rts_filters" ]
455 }
agrieve62ab00282016-04-05 02:03:45456 }
Andrew Grievee1dc23f2019-10-22 16:26:36457 }
agrieve62ab00282016-04-05 02:03:45458
Andrew Grievee1dc23f2019-10-22 16:26:36459 test_runner_script(_test_runner_target) {
460 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57461
Andrew Grievee1dc23f2019-10-22 16:26:36462 if (_use_raw_android_executable) {
463 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34464 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36465 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38466 apk_target = ":$_apk_target_name"
Andrew Grievee1dc23f2019-10-22 16:26:36467 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47468
469 # Dep needed for the test runner .runtime_deps file to pick up data
470 # deps from the forward_variables_from(invoker, "*") on the library.
Andrew Grieveee8aa44d2022-09-23 17:14:38471 data_deps = [ ":$_library_target_name" ]
agrieve62ab00282016-04-05 02:03:45472 }
Andrew Grievee1dc23f2019-10-22 16:26:36473 test_name = _output_name
474 test_suite = _output_name
475 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59476
477 if (use_rts) {
478 data_deps += [ ":${invoker.target_name}__rts_filters" ]
479 }
mikecase56d80d72015-06-03 00:57:26480 }
481
Andrew Grieve7ca6de32019-10-18 03:57:47482 # Create a wrapper script rather than using a group() in order to ensure
483 # "ninja $target_name" always works. If this was a group(), then GN would
484 # not create a top-level alias for it if a target exists in another
485 # directory with the same $target_name.
486 # Also - bots run this script directly for "components_perftests".
487 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01488 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47489 executable = "$root_build_dir/bin/run_$_output_name"
490 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22491 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40492 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47493 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40494 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47495 # Dep needed for the swarming .isolate file to pick up data
496 # deps from the forward_variables_from(invoker, "*") on the library.
497 deps += [
Andrew Grieveee8aa44d2022-09-23 17:14:38498 ":$_apk_target_name",
499 ":$_library_target_name",
Andrew Grieve7ca6de32019-10-18 03:57:47500 ]
agrieve62ab00282016-04-05 02:03:45501 }
Dirk Pranke19a58732021-03-24 22:26:22502
503 if (defined(invoker.data_deps)) {
504 data_deps = invoker.data_deps
505 } else {
506 data_deps = []
507 }
Kevin Marshall23529362022-02-23 16:50:36508
509 data_deps += [ "//testing:test_scripts_shared" ]
510
Jamie Madilldd60ee62021-04-13 19:25:52511 if (tests_have_location_tags) {
512 data = [ "//testing/location_tags.json" ]
513 }
Greg Guterman6963dc082021-04-07 05:20:59514
515 if (use_rts) {
516 data_deps += [ ":${invoker.target_name}__rts_filters" ]
517 }
agrieve1a02e582015-10-15 21:35:39518 }
Scott Graham4c4cdc52017-05-29 20:45:03519 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30520 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
521
Scott Graham4c4cdc52017-05-29 20:45:03522 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42523 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42524 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb42022-04-05 12:30:35525 _program_name = get_label_info(":${_exec_target}", "name")
Scott Graham4c4cdc52017-05-29 20:45:03526
Greg Thompson2f1e3762022-10-17 19:53:44527 # Generate a CML fragment that provides the program name.
528 _test_program_fragment_target = "${target_name}_program-fragment"
529 _test_program_fragment = "${target_out_dir}/${target_name}_program.test-cml"
530 generated_file(_test_program_fragment_target) {
531 contents = {
532 program = {
533 binary = _program_name
Kevin Marshall2ec60032022-05-09 17:38:28534 }
Greg Thompson26516592021-12-16 08:34:45535 }
Greg Thompson2f1e3762022-10-17 19:53:44536 outputs = [ _test_program_fragment ]
537 output_conversion = "json"
Greg Thompson9765eeb42022-04-05 12:30:35538 }
539
Greg Thompson2f1e3762022-10-17 19:53:44540 _test_runner_shard =
541 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
542 if (defined(invoker.test_runner_shard)) {
543 _test_runner_shard = invoker.test_runner_shard
Wez6879f8a2021-09-07 20:27:02544 }
545
Greg Thompson2f1e3762022-10-17 19:53:44546 # Collate the complete set of elements to include in the test component's
547 # manifest.
David Dorwin2c4872c2023-02-22 20:00:56548
Greg Thompson2f1e3762022-10-17 19:53:44549 _manifest_fragments = [
Greg Thompson2f1e3762022-10-17 19:53:44550 _test_program_fragment,
551 _test_runner_shard,
552 ]
553
David Dorwin2c4872c2023-02-22 20:00:56554 # Select the Fuchsia test realm in which to run the test.
555 if (defined(invoker.run_as_chromium_system_test) &&
556 invoker.run_as_chromium_system_test) {
557 _manifest_fragments += [
558 "//build/config/fuchsia/test/chromium_system_test_facet.shard.test-cml",
559 "//build/config/fuchsia/test/system_test_minimum.shard.test-cml",
560 ]
561 } else {
562 _manifest_fragments += [
563 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
564 "//build/config/fuchsia/test/minimum.shard.test-cml",
565 ]
566 }
567
Greg Thompson2f1e3762022-10-17 19:53:44568 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
569 _merged_manifest_name = "${_output_name}.cml"
570
571 if (defined(invoker.additional_manifest_fragments)) {
572 _manifest_fragments += invoker.additional_manifest_fragments
573 }
574
575 # Generate the test component manifest from the specified elements.
576 _test_component_manifest_target = "${target_name}_component-manifest"
577 cmc_merge(_test_component_manifest_target) {
578 sources = _manifest_fragments
579 output_name = "${_merged_manifest_name}"
580 deps = [ ":${_test_program_fragment_target}" ]
581 }
582
583 # Define the test component, dependent on the generated manifest, and the
584 # test executable target.
585 _test_component_target = "${target_name}_component"
586 fuchsia_component(_test_component_target) {
587 deps = [ ":$_test_component_manifest_target" ]
588 data_deps = [ ":$_exec_target" ]
589 manifest = _test_component_manifest
590 visibility = [ ":*" ]
591 }
592
593 _test_component_targets = [ ":${_test_component_target}" ]
594
Wez6879f8a2021-09-07 20:27:02595 # Define components for each entry in |additional_manifests|, if any. Since
596 # manifests may themselves depend-on the outputs of |deps|, these components
597 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02598 if (defined(invoker.additional_manifests)) {
599 foreach(filename, invoker.additional_manifests) {
600 _additional_component_target =
601 target_name + "_" + get_path_info(filename, "name")
602 _test_component_targets += [ ":${_additional_component_target}" ]
603 fuchsia_component(_additional_component_target) {
604 forward_variables_from(invoker, [ "testonly" ])
605 data_deps = [ ":$_exec_target" ]
606 visibility = [ ":*" ]
607 manifest = filename
608
609 # Depend on |invoker.deps|, in case it includes a dependency that
610 # creates this additional component's manifest.
611 if (defined(invoker.deps)) {
612 deps = invoker.deps
613 }
614 }
615 }
616 }
617
618 # Define the package target that will bundle the test and additional
619 # components and their data.
620 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21621 forward_variables_from(invoker,
622 [
623 "excluded_files",
624 "excluded_dirs",
Bryant Chandlerc40f2672023-01-27 23:33:30625 "excluded_paths",
Kevin Marshall36c602c2021-11-04 16:16:21626 ])
Wez6879f8a2021-09-07 20:27:02627 package_name = _output_name
628 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21629
Greg Thompsonfd269652022-10-28 12:06:55630 if (defined(invoker.fuchsia_package_deps)) {
631 deps += invoker.fuchsia_package_deps
632 }
Bryant Chandlerc40f2672023-01-27 23:33:30633 if (!defined(excluded_paths)) {
634 excluded_paths = []
Kevin Marshall36c602c2021-11-04 16:16:21635 }
Bryant Chandlerc40f2672023-01-27 23:33:30636 excluded_paths += [
637 "${devtools_root_location}/*",
638 "*.git/*",
639 "*.svn/*",
640 "*.hg/*",
641 ]
Sarah Pham80972efc2022-05-31 17:40:15642 if (devtools_root_location != "") {
Bryant Chandlerc40f2672023-01-27 23:33:30643 excluded_paths += [ "${devtools_root_location}/*" ]
Sarah Pham80972efc2022-05-31 17:40:15644 }
Wez6879f8a2021-09-07 20:27:02645 }
646
647 # |target_name| refers to the package-runner rule, so that building
648 # "base_unittests" will build not only the executable, component, and
649 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25650 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53651 forward_variables_from(invoker,
652 [
Kevin Marshall5fadadd2021-10-16 00:08:25653 "data",
654 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53655 "package_deps",
Kevin Marshall5fadadd2021-10-16 00:08:25656 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53657 ])
Kevin Marshall5fadadd2021-10-16 00:08:25658
Chong Guc6bfdf62021-10-20 23:37:00659 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15660 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25661 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42662
Kevin Marshall5fadadd2021-10-16 00:08:25663 if (!defined(deps)) {
664 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52665 }
Kevin Marshall5fadadd2021-10-16 00:08:25666 if (defined(invoker.deps)) {
667 deps += invoker.deps
668 }
Greg Guterman6963dc082021-04-07 05:20:59669
Kevin Marshall5fadadd2021-10-16 00:08:25670 if (!defined(data)) {
671 data = []
672 }
673 if (tests_have_location_tags) {
674 data += [ "//testing/location_tags.json" ]
675 }
676
677 if (!defined(data_deps)) {
678 data_deps = []
679 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28680
Kevin Marshall23529362022-02-23 16:50:36681 data_deps += [ "//testing:test_scripts_shared" ]
682
Greg Guterman6963dc082021-04-07 05:20:59683 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25684 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59685 }
Kevin Marshallf35fa5f2018-01-29 19:24:42686 }
687
danakjebb9cc4d2022-03-04 21:30:11688 mixed_test(_exec_target) {
689 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01690 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42691 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03692 }
dpranke2a294622015-08-07 05:23:01693 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30694 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46695 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30696
Rohit Raof9b096d2019-09-09 22:26:23697 declare_args() {
698 # Keep the unittest-as-xctest functionality defaulted to off until the
699 # bots are updated to handle it properly.
700 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
701 # supports running unittests with xctest.
702 enable_run_ios_unittests_with_xctest = false
703 }
704
sdefresne012857872016-03-16 10:55:37705 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27706 _output_name = target_name
707 if (defined(invoker.output_name)) {
708 _output_name = invoker.output_name
709 }
710
Jeff Yoonf7f4eb42020-03-06 18:55:36711 _wrapper_output_name = "run_${target_name}"
712 ios_test_runner_wrapper(_wrapper_output_name) {
713 forward_variables_from(invoker,
714 [
715 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36716 "deps",
717 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27718 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36719 "retries",
720 "shards",
721 ])
722
723 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
724
725 if (!defined(executable_args)) {
726 executable_args = []
727 }
728 executable_args += [
729 "--app",
730 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
731 ]
732
733 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22734
735 if (!defined(data)) {
736 data = []
737 }
Jamie Madilldd60ee62021-04-13 19:25:52738 if (tests_have_location_tags) {
739 data += [ "//testing/location_tags.json" ]
740 }
Jeff Yoonf7f4eb42020-03-06 18:55:36741 }
742
sdefresne012857872016-03-16 10:55:37743 _resources_bundle_data = target_name + "_resources_bundle_data"
744
745 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34746 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22747 sources = [ "//testing/gtest_ios/Default.png" ]
748 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01749 }
750
Mirko Bonadei15522bc2020-09-16 20:38:39751 force_xctest = enable_run_ios_unittests_with_xctest ||
752 (defined(invoker.is_xctest) && invoker.is_xctest)
753
danakjfae603fc602022-11-18 18:40:22754 mixed_test(_test_target) {
755 if (force_xctest) {
756 target_type = "ios_xctest_test"
757 } else {
758 target_type = "ios_app_bundle"
759 }
dpranke2a294622015-08-07 05:23:01760 testonly = true
sdefresnea828c282016-05-30 18:04:20761
Mirko Bonadei15522bc2020-09-16 20:38:39762 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23763 xctest_module_target = "//base/test:google_test_runner"
764 }
765
Andrew Grieve1b290e4a22020-11-24 20:07:01766 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13767
768 # Provide sensible defaults in case invoker did not define any of those
769 # required variables.
sdefresne05b97ca2016-06-08 07:19:46770 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13771 info_plist = "//testing/gtest_ios/unittest-Info.plist"
772 }
sdefresne9e147e02016-06-07 00:10:13773
Sylvain Defresne3c5a1312021-09-23 17:08:09774 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13775 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50776 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09777 } else {
Ali Juma75be0fe2022-01-24 19:39:29778 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27779 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09780 }
dpranke2a294622015-08-07 05:23:01781
sdefresne047490e2016-07-22 08:49:34782 if (!defined(bundle_deps)) {
783 bundle_deps = []
784 }
785 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36786
787 if (!defined(data_deps)) {
788 data_deps = []
789 }
790
Kevin Marshall23529362022-02-23 16:50:36791 data_deps += [ "//testing:test_scripts_shared" ]
792
Jeff Yoonf7f4eb42020-03-06 18:55:36793 # Include the generate_wrapper as part of data_deps
794 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46795 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59796
797 if (use_rts) {
798 data_deps += [ ":${invoker.target_name}__rts_filters" ]
799 }
dpranke2a294622015-08-07 05:23:01800 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11801 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
802 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30803 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
804
Yuke Liao2a9b2f0e2021-04-16 00:40:11805 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32806
Benjamin Pastene3bce864e2018-04-14 01:16:32807 _gen_runner_target = "${target_name}__runner"
808 _runtime_deps_file =
809 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
810 "/" + get_label_info(target_name, "name") + ".runtime_deps"
811
Xinan Lin6be01252021-06-25 23:07:36812 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
813 if (is_skylab) {
Struan Shrimptonf61293f62022-04-11 19:33:40814 generate_skylab_deps(_gen_runner_target) {
Xinan Lin6be01252021-06-25 23:07:36815 generated_script = _generated_script
816 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34817 }
Xinan Lin6be01252021-06-25 23:07:36818 } else {
819 generate_runner_script(_gen_runner_target) {
820 generated_script = _generated_script
821 test_exe = invoker.target_name
822 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34823
Xinan Lin6be01252021-06-25 23:07:36824 if (is_chromeos_lacros) {
825 # At build time, Lacros tests don't know whether they'll run on VM or
826 # HW, and instead, these flags are specified at runtime when invoking
827 # the generated runner script.
828 skip_generating_board_args = true
829 }
Greg Guterman6963dc082021-04-07 05:20:59830
Xinan Lin6be01252021-06-25 23:07:36831 if (tests_have_location_tags) {
832 data = [ "//testing/location_tags.json" ]
833 }
834
835 if (use_rts) {
836 data_deps = [ ":${invoker.target_name}__rts_filters" ]
837 }
Greg Guterman6963dc082021-04-07 05:20:59838 }
Benjamin Pastene3bce864e2018-04-14 01:16:32839 }
840
danakjebb9cc4d2022-03-04 21:30:11841 mixed_test(target_name) {
842 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01843 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
844 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32845 if (!defined(deps)) {
846 deps = []
847 }
848 if (!defined(data)) {
849 data = []
850 }
851
Ben Pastene41041782019-02-16 04:21:58852 # We use a special trigger script for CrOS hardware tests.
853 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
854
Benjamin Pastene3bce864e2018-04-14 01:16:32855 write_runtime_deps = _runtime_deps_file
856 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37857 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59858
Kevin Marshall23529362022-02-23 16:50:36859 if (!defined(data_deps)) {
860 data_deps = []
861 }
862
863 data_deps += [ "//testing:test_scripts_shared" ]
864
Greg Guterman6963dc082021-04-07 05:20:59865 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59866 data_deps += [ ":${invoker.target_name}__rts_filters" ]
867 }
Benjamin Pastene3bce864e2018-04-14 01:16:32868 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11869 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24870 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
871 _executable = target_name
872 _gen_runner_target = "${target_name}__runner"
873
Yuke Liao32af4242020-07-16 21:48:02874 if (defined(invoker.use_xvfb)) {
875 _use_xvfb = invoker.use_xvfb
876 } else {
877 _use_xvfb = false
878 }
879
Yuke Liaod037abc2020-10-06 22:48:22880 # When use_xvfb is set by the invoker, it indicates that running this test
881 # target requires a window, and in lacros build, ash-chrome serves as the
882 # display server. Note that even though the tests themselves do not require
883 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
884 # because ash-chrome is based on x11.
885 _use_ash_chrome = _use_xvfb
886
Yuke Liaoe703384b2020-07-16 01:05:24887 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24888 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02889
Yuke Liao2e4953cf2020-07-26 19:20:19890 data = []
Will Harrisd35e2c92021-04-07 01:42:02891 data_deps = [ "//testing:test_scripts_shared" ]
892
Yuke Liao32af4242020-07-16 21:48:02893 if (_use_xvfb) {
894 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22895 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02896 } else {
897 executable = "//testing/test_env.py"
898 }
Jamie Madilldd60ee62021-04-13 19:25:52899 if (tests_have_location_tags) {
900 data += [ "//testing/location_tags.json" ]
901 }
Yuke Liao32af4242020-07-16 21:48:02902
Yuke Liaoe703384b2020-07-16 01:05:24903 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02904 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39905 "test",
Yuke Liaoe703384b2020-07-16 01:05:24906 "@WrappedPath(./${_executable})",
907 "--test-launcher-bot-mode",
908 ]
Yuke Liao32af4242020-07-16 21:48:02909
Yuke Liaof540c742020-07-29 16:28:34910 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37911 executable_args += [ "--ash-chrome-path" ]
912
913 # Can't use --ash-chrome-path=path because WrappedPath
914 # won't be expanded for that usage.
915 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39916 }
917
Yuke Liaoe703384b2020-07-16 01:05:24918 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:00919 executable_args += [ "--asan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24920 }
921 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:00922 executable_args += [ "--msan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24923 }
924 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:00925 executable_args += [ "--tsan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24926 }
927 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:00928 executable_args += [ "--cfi-diag=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24929 }
930
Takuto Ikuta38ebd0e2022-01-19 17:56:22931 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59932
933 if (use_rts) {
934 data_deps += [ ":${invoker.target_name}__rts_filters" ]
935 }
Yuke Liaoe703384b2020-07-16 01:05:24936 }
937
danakjebb9cc4d2022-03-04 21:30:11938 mixed_test(target_name) {
939 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01940 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
941 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24942 if (!defined(deps)) {
943 deps = []
944 }
945
Yuke Liaod037abc2020-10-06 22:48:22946 if (!defined(data_deps)) {
947 data_deps = []
948 }
949
Kevin Marshall23529362022-02-23 16:50:36950 data_deps += [ "//testing:test_scripts_shared" ]
951
Yuke Liaoe703384b2020-07-16 01:05:24952 write_runtime_deps = _runtime_deps_file
953 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22954 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56955 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22956 }
Greg Guterman6963dc082021-04-07 05:20:59957
958 if (use_rts) {
959 data_deps += [ ":${invoker.target_name}__rts_filters" ]
960 }
Yuke Liaoe703384b2020-07-16 01:05:24961 }
Dirk Prankedd4ff742020-11-18 19:57:32962 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30963 if (is_mac || is_win) {
964 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
965 }
966
Dirk Prankedd4ff742020-11-18 19:57:32967 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
968 _executable = target_name
969 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06970
Dirk Prankedd4ff742020-11-18 19:57:32971 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
972 _use_xvfb = invoker.use_xvfb
973 } else {
974 _use_xvfb = false
975 }
976
977 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32978 wrapper_script = "$root_build_dir/bin/run_" + _executable
979
980 data = []
Will Harrisd35e2c92021-04-07 01:42:02981 data_deps = [ "//testing:test_scripts_shared" ]
982
Dirk Prankedd4ff742020-11-18 19:57:32983 if (_use_xvfb) {
984 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06985 } else {
Dirk Prankedd4ff742020-11-18 19:57:32986 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06987 }
Jamie Madilldd60ee62021-04-13 19:25:52988 if (tests_have_location_tags) {
989 data += [ "//testing/location_tags.json" ]
990 }
Dirk Pranke31e346e2020-07-15 00:54:06991
Dirk Prankedd4ff742020-11-18 19:57:32992 executable_args = [
993 "@WrappedPath(./${_executable})",
994 "--test-launcher-bot-mode",
995 ]
996 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:00997 executable_args += [ "--asan=1" ]
Dirk Pranke31e346e2020-07-15 00:54:06998 }
Dirk Prankedd4ff742020-11-18 19:57:32999 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:001000 executable_args += [ "--msan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321001 }
1002 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:001003 executable_args += [ "--tsan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321004 }
1005 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:001006 executable_args += [ "--cfi-diag=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321007 }
1008
Greg Guterman6963dc082021-04-07 05:20:591009 if (use_rts) {
1010 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1011 }
Dirk Pranke31e346e2020-07-15 00:54:061012 }
1013
danakjebb9cc4d2022-03-04 21:30:111014 mixed_test(target_name) {
1015 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011016 forward_variables_from(invoker,
1017 "*",
1018 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
1019 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:061020 if (!defined(deps)) {
1021 deps = []
1022 }
1023
Dirk Pranke31e346e2020-07-15 00:54:061024 deps += [
1025 # Give tests the default manifest on Windows (a no-op elsewhere).
1026 "//build/win:default_exe_manifest",
1027 ]
1028
Dirk Prankedd4ff742020-11-18 19:57:321029 write_runtime_deps = _runtime_deps_file
1030 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:111031
Kevin Marshall23529362022-02-23 16:50:361032 if (!defined(data_deps)) {
1033 data_deps = []
1034 }
1035
1036 data_deps += [ "//testing:test_scripts_shared" ]
1037
Greg Guterman50ed4b42021-04-08 01:15:111038 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:111039 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1040 }
Dirk Prankedd4ff742020-11-18 19:57:321041 }
1042 } else {
1043 # This is a catch-all clause for NaCl toolchains and other random
1044 # configurations that might define tests; test() in these configs
1045 # will just define the underlying executables.
1046 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
1047 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:111048 mixed_test(target_name) {
1049 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011050 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1051 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:321052 if (!defined(deps)) {
1053 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061054 }
Greg Guterman6963dc082021-04-07 05:20:591055
Kevin Marshall23529362022-02-23 16:50:361056 if (!defined(data_deps)) {
1057 data_deps = []
1058 }
1059
1060 data_deps += [ "//testing:test_scripts_shared" ]
1061
Greg Guterman6963dc082021-04-07 05:20:591062 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:591063 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1064 }
Dirk Pranke31e346e2020-07-15 00:54:061065 }
qsrfb5251d12015-01-21 15:57:221066 }
1067}
brettwedb6ecc2016-07-14 23:37:031068
Dirk Pranke6188075b2020-10-01 19:31:281069# Defines a type of test that invokes a script to run, rather than
1070# invoking an executable.
1071#
1072# The script must implement the
1073# [test executable API](//docs/testing/test_executable_api.md).
1074#
Andrew Grievea16222d42023-02-10 15:31:101075# The template must be passed the `script` parameter, which specifies the path
1076# to the script to run. It may optionally be passed a `args` parameter, which
1077# can be used to include a list of args to be specified by default. The
1078# template will produce a `$root_build_dir/run_$target_name` wrapper and write
1079# the runtime_deps for the target to
1080# $root_build_dir/${target_name}.runtime_deps, as per the conventions listed in
1081# the [test wrapper API](//docs/testing/test_wrapper_api.md).
Dirk Pranke6188075b2020-10-01 19:31:281082template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:591083 if (use_rts) {
1084 action("${target_name}__rts_filters") {
1085 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:531086 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:051087 inverted_rts_file =
1088 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
1089 args = [
1090 rebase_path(rts_file, root_build_dir),
1091 rebase_path(inverted_rts_file, root_build_dir),
1092 ]
1093 outputs = [
1094 rts_file,
1095 inverted_rts_file,
1096 ]
Greg Guterman6963dc082021-04-07 05:20:591097 }
1098 }
1099
Dirk Pranke6188075b2020-10-01 19:31:281100 generate_wrapper(target_name) {
1101 testonly = true
1102 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1103
1104 executable = "//testing/test_env.py"
1105
1106 executable_args =
1107 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1108 if (defined(invoker.args)) {
1109 executable_args += invoker.args
1110 }
1111
Will Harrisd35e2c92021-04-07 01:42:021112 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471113
Dirk Pranke6188075b2020-10-01 19:31:281114 if (defined(invoker.data)) {
1115 data += invoker.data
1116 }
Jamie Madilldd60ee62021-04-13 19:25:521117 if (tests_have_location_tags) {
1118 data += [ "//testing/location_tags.json" ]
1119 }
Dirk Pranke19a58732021-03-24 22:26:221120
Will Harrisd35e2c92021-04-07 01:42:021121 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281122 if (defined(invoker.data_deps)) {
1123 data_deps += invoker.data_deps
1124 }
1125
1126 forward_variables_from(invoker,
Andrew Grievea16222d42023-02-10 15:31:101127 "*",
Andrew Grieve1b290e4a22020-11-24 20:07:011128 TESTONLY_AND_VISIBILITY + [
Andrew Grievea16222d42023-02-10 15:31:101129 "args",
Andrew Grieve1b290e4a22020-11-24 20:07:011130 "data",
1131 "data_deps",
1132 "script",
Andrew Grieve1b290e4a22020-11-24 20:07:011133 ])
1134 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281135
1136 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591137
1138 if (use_rts) {
1139 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1140 }
Dirk Pranke6188075b2020-10-01 19:31:281141 }
1142}
1143
Andrew Grievea16222d42023-02-10 15:31:101144# Defines a test target that uses exit code for pass/fail.
1145template("isolated_script_test") {
1146 script_test(target_name) {
1147 forward_variables_from(invoker,
1148 "*",
1149 TESTONLY_AND_VISIBILITY + [
1150 "args",
1151 "deps",
1152 "script",
1153 ])
1154 forward_variables_from(invoker, [ "visibility" ])
1155 deps = [ "//testing:run_isolated_script_test" ]
1156 if (defined(invoker.deps)) {
1157 deps += invoker.deps
1158 }
1159 script = "//testing/scripts/run_isolated_script_test.py"
1160 data = [ invoker.script ]
1161 args = [
1162 rebase_path(invoker.script, root_build_dir),
1163 "--script-type=bare",
1164 ]
1165 if (defined(invoker.args)) {
1166 args += invoker.args
1167 }
1168 }
1169}
1170
brettwedb6ecc2016-07-14 23:37:031171# Test defaults.
1172set_defaults("test") {
1173 if (is_android) {
1174 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411175 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591176 configs += [ "//build/config/android:hide_all_but_jni" ]
Andrew Grieved5fdf2af2022-08-23 07:47:551177
1178 # Compress sections to stay under 4gb hard limit on 32-bit current_cpu.
1179 # https://crbug.com/1354616
1180 if (symbol_level == 2 && !use_debug_fission &&
1181 (current_cpu == "arm" || current_cpu == "x86")) {
1182 configs += [ "//build/config:compress_debug_sections" ]
1183 }
brettwedb6ecc2016-07-14 23:37:031184 } else {
1185 configs = default_executable_configs
1186 }
1187}