[go: nahoru, domu]

blob: 057bf2f8c01522c5a142056ddc91acd166a08692 [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")
danakj482580a2022-11-18 18:00:5913import("//build/rust/rust_static_library.gni")
Mirko Bonadei4a0df432020-09-08 19:06:0214import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2415
Greg Guterman6963dc02021-04-07 05:20:5916declare_args() {
Dirk Prankeb404c3b2021-06-14 19:57:5017 # Some component repos (e.g. ANGLE) import //testing but do not have
18 # "location_tags.json", and so we don't want to try and upload the tags
19 # for their tests.
20 # And, some build configs may simply turn off generation altogether.
21 tests_have_location_tags = generate_location_tags
Greg Guterman6963dc02021-04-07 05:20:5922}
23
David Dorwin621c5072022-03-30 00:32:5324# On Fuchsia, the test executable has a suffix and is a dependency of the
25# common |target_name| target. For `visibility`, the executable must be
26# specified. Cross-platform targets that include `test` targets in their
27# visibility lists, add `${exec_target_suffix}` immediately after the test
28# target name. This is not necessary when the target is a `source_set`.
29if (is_fuchsia) {
30 exec_target_suffix = "__exec"
31} else {
32 exec_target_suffix = ""
33}
34
jcivellif4462a352017-01-10 04:45:5935if (is_android) {
36 import("//build/config/android/config.gni")
Charlie Hud98dc692021-12-08 01:01:0237 import("//build/config/android/create_unwind_table.gni")
James Cook209256f2018-12-07 18:40:5038 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5939 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4440 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3241} else if (is_fuchsia) {
mark a. foltze185ab2fa2023-11-06 21:21:2042 import("//build/config/cast.gni")
Kevin Marshall55fd8522019-10-04 22:47:0143 import("//build/config/fuchsia/generate_runner_scripts.gni")
Wez691dde42023-10-19 17:47:2944 import("//third_party/fuchsia-gn-sdk/src/cmc.gni")
45 import("//third_party/fuchsia-gn-sdk/src/component.gni")
46 import("//third_party/fuchsia-gn-sdk/src/package.gni")
Nico Weberd73c90382022-03-30 20:37:5047} else if (is_chromeos && is_chromeos_device) {
Ben Pastene4c35c572018-04-30 23:21:4848 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3249 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2850 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3251} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3652 import("//build/config/ios/ios_sdk.gni")
53 import("//build/config/ios/ios_test_runner_wrapper.gni")
54 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3255} else {
Dirk Pranke31e346e2020-07-15 00:54:0656 import("//build/config/sanitizers/sanitizers.gni")
57 import("//build/util/generate_wrapper.gni")
58}
59
danakj482580a2022-11-18 18:00:5960# This template generates the test target (of type `target_type`) but also
61# generates a rust library that includes all .rs files found in sources and
62# depends on that from the test target.
danakjebb9cc42022-03-04 21:30:1163template("mixed_test") {
64 assert(defined(invoker.target_type) && invoker.target_type != "")
danakjebb9cc42022-03-04 21:30:1165
danakjca3cae62023-04-12 15:20:5766 # The crate_root variable would transform the target into a Rust binary
67 # which is incorrect. To not use a generated crate root set:
68 # ```
69 # test_crate_root = "path/to/root.rs"
70 # ```
71 assert(!defined(invoker.crate_root))
72
danakj482580a2022-11-18 18:00:5973 _rs_vars = [
74 "sources", # We split this list into two.
75 "crate_name", # Android test template overrides the crate name.
76 ]
danakjaa85aad2022-03-10 18:45:1077
danakj482580a2022-11-18 18:00:5978 if (defined(invoker.sources)) {
79 _rs_sources = filter_include(invoker.sources, [ "*.rs" ])
80 _cc_sources = filter_exclude(invoker.sources, [ "*.rs" ])
81 } else {
82 _rs_sources = []
83 _cc_sources = []
84 }
85
86 if (_rs_sources != []) {
Daniel Cheng8629dd72023-11-22 10:56:4587 # Note: as a weak convention, __ is usually used before a suffix for
88 # internally-generated targets. However, rust_target requires a strict
89 # snake_case name.
danakjc858ce72022-12-20 21:39:5190 if (defined(invoker.crate_name)) {
91 _rust_target_name = "${invoker.crate_name}_rust_objects"
92 } else {
93 _rust_target_name = "${target_name}_rust_objects"
94 }
danakj482580a2022-11-18 18:00:5995
96 # We could automatically add `deps += [ "//testing/rust_gtest_interop" ]`
danakjebb9cc42022-03-04 21:30:1197 # if `rs_sources` is non-empty. But we don't automatically provide
98 # //testing/gtest either so it would be asymmetric and could break in that
danakj482580a2022-11-18 18:00:5999 # case. So, we act instead as if //testing/rust_gtest_interop is part of
100 # the //testing/gtest dependency. If you add one, and have `rs_sources`
101 # listed, you get both.
danakjebb9cc42022-03-04 21:30:11102 _gtest_is_in_deps = false
danakj482580a2022-11-18 18:00:59103 if (defined(invoker.deps) && invoker.deps != []) {
104 foreach(dep, invoker.deps) {
danakjc1f000c2022-11-18 19:31:06105 if (get_label_info(dep, "label_no_toolchain") ==
106 "//testing/gtest:gtest") {
danakjebb9cc42022-03-04 21:30:11107 _gtest_is_in_deps = true
108 }
109 }
110 }
danakj482580a2022-11-18 18:00:59111
112 # TODO(danakj): This could be a rust_source_set perhaps, the point being
113 # that we need to link in all the .o object files inside the library,
114 # instead of dropping unreachable ones during linking (which would drop the
115 # tests). Alternatively we could use a special name suffix or other similar
116 # trick perhaps to ensure that all object files are linked in here.
117 rust_static_library(_rust_target_name) {
118 forward_variables_from(invoker,
119 TESTONLY_AND_VISIBILITY + [
danakjca3cae62023-04-12 15:20:57120 "allow_unsafe",
danakj482580a2022-11-18 18:00:59121 "deps",
danakjca3cae62023-04-12 15:20:57122 "generate_crate_root",
danakj482580a2022-11-18 18:00:59123 "public_deps",
124 ])
125 configs += [ "//build/rust:test" ]
danakjca3cae62023-04-12 15:20:57126 if (defined(invoker.test_crate_root)) {
127 crate_root = invoker.test_crate_root
128 } else {
129 generate_crate_root = true
130 }
danakj482580a2022-11-18 18:00:59131 sources = _rs_sources
Daniel Cheng8629dd72023-11-22 10:56:45132 is_gtest_unittests = true
danakjca3cae62023-04-12 15:20:57133
danakj482580a2022-11-18 18:00:59134 if (_gtest_is_in_deps) {
135 deps += [ "//testing/rust_gtest_interop" ]
danakjebb9cc42022-03-04 21:30:11136 }
danakj482580a2022-11-18 18:00:59137 }
138 } else {
139 not_needed(invoker, _rs_vars)
140 }
141
Sam Maierb63502c2023-09-15 16:24:41142 if (invoker.target_type == "shared_library_with_jni") {
143 # Needed for shared_library_with_jni. Keeping this import guarded so
144 # that projects who import //testing but not //third_party/jni_zero
145 # don't have issues.
146 import("//third_party/jni_zero/jni_zero.gni")
147 }
danakj482580a2022-11-18 18:00:59148 target(invoker.target_type, target_name) {
149 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY + _rs_vars)
150 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
151 sources = _cc_sources
152 if (!defined(deps)) {
153 deps = []
154 }
danakjca3cae62023-04-12 15:20:57155 if (!defined(ldflags)) {
156 ldflags = []
157 }
158
danakj482580a2022-11-18 18:00:59159 if (_rs_sources != []) {
160 deps += [ ":${_rust_target_name}" ]
danakjebb9cc42022-03-04 21:30:11161 }
162 }
163}
164
qsrfb5251d12015-01-21 15:57:22165# Define a test as an executable (or apk on Android) with the "testonly" flag
166# set.
agrieve62ab00282016-04-05 02:03:45167# Variable:
Dirk Pranke79d065d2020-08-29 03:28:30168# use_xvfb: (optional) whether to run the executable under Xvfb.
danakj482580a2022-11-18 18:00:59169# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:56170# use_native_activity: Test implements ANativeActivity_onCreate().
Greg Thompson318cd692022-03-28 08:12:06171# test_runner_shard: (Fuchsia, optional): for CFv2 tests, use the given test
Greg Thompsonfd269652022-10-28 12:06:55172# runner shard rather than the default shard for the ELF runner when
173# assembling the test component. This is useful, for example, to use the
174# elf_test_ambient_exec_runner for tests that require
175# job_policy_ambient_mark_vmo_exec.
176# fuchsia_package_deps: (Fuchsia, optional) List of fuchsia_component()
177# targets that this test package contains.
Mirko Bonadei15522bc2020-09-16 20:38:39178# is_xctest: (iOS, optional) whether to build the executable as XCTest.
179# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
180# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:43181# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
182# network requests during the test.
Adrian Taylor62dbea52023-10-25 20:29:16183# enable_fuzztest: whether to allow the use of the FUZZ_TEST macro to
184# include fuzzing tests alongside unit tests. This introduces an
185# extra dependency and also creates additional metadata so that our
186# fuzzing infrastructure can find and run such tests.
qsrfb5251d12015-01-21 15:57:22187template("test") {
Andrew Grieve1b290e4a22020-11-24 20:07:01188 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:39189 if (!is_ios) {
190 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
191 "is_xctest can be set only for iOS builds")
192 }
Stefano Duo4128b6b2021-08-02 21:24:43193 if (!is_android) {
194 assert(!defined(invoker.allow_cleartext_traffic),
195 "allow_cleartext_traffic can be set only for Android tests")
196 }
197
Adrian Taylor62dbea52023-10-25 20:29:16198 _fuzztest_deps = []
199 if (defined(invoker.enable_fuzztest) && invoker.enable_fuzztest) {
200 _output_name = invoker.target_name
201 _fuzzer_options_target = "${_output_name}__fuzzer_options"
202 _fuzztest_deps = [
203 ":${_fuzzer_options_target}",
204 "//third_party/fuzztest",
205 ]
206
207 # Generate minimal .options file so that ClusterFuzz knows to pass the
208 # -fuzz= argument. It's possible that in future we would want more
209 # fuzzing parameters to be configurable for FUZZ_TESTS, in which case
210 # perhaps we would want to abstract more of the logic from
211 # //testing/libfuzzer/fuzzer_test.gni.
212 config_file_name = _output_name + ".options"
213 action(_fuzzer_options_target) {
214 script = "//testing/libfuzzer/gen_fuzzer_config.py"
215 args = [
216 "--config",
217 rebase_path("$root_build_dir/" + config_file_name, root_build_dir),
218 "--libfuzzer_options",
219 "fuzz=",
220 ]
221 outputs = [ "$root_build_dir/$config_file_name" ]
222 }
223 }
224
qsrfb5251d12015-01-21 15:57:22225 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:30226 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
227
Peter Kotwicz10742f82021-04-15 22:32:50228 _use_default_launcher =
229 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
230 if (!defined(invoker.use_raw_android_executable)) {
231 # Checkouts where build_with_chromium == false often have a custom GN
232 # template wrapper around test() which sets use_default_launcher == false.
233 # Set the _use_raw_android_executable default so that test() targets which
234 # do not use the custom wrapper
235 # (1) Do not cause "gn gen" to fail
236 # (2) Do not need to be moved into if(build_with_chromium) block.
237 _use_raw_android_executable =
238 !build_with_chromium && _use_default_launcher
239 } else {
240 not_needed([ "_use_default_launcher" ])
241 _use_raw_android_executable = invoker.use_raw_android_executable
242 }
qsrfb5251d12015-01-21 15:57:22243
agrieve67855de2016-03-30 14:46:01244 # output_name is used to allow targets with the same name but in different
245 # packages to still produce unique runner scripts.
246 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26247 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01248 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26249 }
agrieve62ab00282016-04-05 02:03:45250
agrieveb355ad152016-04-19 03:45:23251 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42252 _wrapper_script_vars = [
Jamie Madill73b9af32022-08-03 19:27:47253 "android_test_runner_script",
agrievee41ae190d2016-04-25 14:12:51254 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42255 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51256 ]
agrieve3ac557f02016-04-12 15:52:00257
jbudorickced2a252016-06-09 16:38:54258 assert(_use_raw_android_executable || enable_java_templates)
259
agrieve62ab00282016-04-05 02:03:45260 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49261 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
262
agrieve62ab00282016-04-05 02:03:45263 _exec_target = "${target_name}__exec"
264 _dist_target = "${target_name}__dist"
265 _exec_output =
266 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
danakj505b7f02023-07-05 19:02:02267 _crate_name = "${target_name}"
agrieve62ab00282016-04-05 02:03:45268
danakjebb9cc42022-03-04 21:30:11269 mixed_test(_exec_target) {
270 target_type = "executable"
271
danakj505b7f02023-07-05 19:02:02272 # Use a crate name that avoids creating a warning due to double
273 # underscore (ie. `__`).
274 crate_name = _crate_name
275
danakje94f40d2022-02-16 18:13:53276 # Configs will always be defined since we set_defaults in
277 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45278 configs = []
Dirk Pranke19a58732021-03-24 22:26:22279 forward_variables_from(
280 invoker,
281 "*",
282 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
283 "data_deps",
284 "extra_dist_files",
285 ])
agrieve62ab00282016-04-05 02:03:45286
287 # Thanks to the set_defaults() for test(), configs are initialized with
288 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59289 configs -= [
290 "//build/config:shared_library_config",
291 "//build/config/android:hide_all_but_jni",
292 ]
agrieve62ab00282016-04-05 02:03:45293 configs += [ "//build/config:executable_config" ]
294
Dirk Pranke19a58732021-03-24 22:26:22295 if (defined(invoker.data_deps)) {
296 data_deps = invoker.data_deps
297 } else {
298 data_deps = []
299 }
300 if (!defined(data)) {
301 data = []
302 }
Jamie Madilldd60ee62021-04-13 19:25:52303 if (tests_have_location_tags) {
304 data += [ "//testing/location_tags.json" ]
305 }
Adrian Taylor62dbea52023-10-25 20:29:16306 if (!defined(deps)) {
307 deps = []
308 }
309 deps += _fuzztest_deps
Dirk Pranke19a58732021-03-24 22:26:22310
agrieve62ab00282016-04-05 02:03:45311 # Don't output to the root or else conflict with the group() below.
312 output_name = rebase_path(_exec_output, root_out_dir)
agrieve62ab00282016-04-05 02:03:45313 }
314
315 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45316 dist_dir = "$root_out_dir/$target_name"
317 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22318 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45319 if (defined(invoker.extra_dist_files)) {
320 extra_files = invoker.extra_dist_files
321 }
322 }
323 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38324 _library_target_name = "${target_name}__library"
danakj98e073722022-02-24 21:01:49325 _library_crate_name = "${target_name}_library"
Andrew Grieveee8aa44d2022-09-23 17:14:38326 _apk_target_name = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45327 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43328 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45329 "android_manifest",
agrievec6811b422016-06-23 02:25:09330 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27331 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55332 "app_as_shared_lib",
Benoît Lizéd8b8f742019-11-07 12:50:07333 "product_config_java_packages",
Andrew Grieve43f24fd02022-04-06 23:04:04334 "loadable_modules",
335 "loadable_module_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02336 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07337 "proguard_configs",
338 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45339 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02340 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45341 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56342 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45343 ]
Siddhartha764226b2018-03-13 02:32:55344
Andrew Grieveee8aa44d2022-09-23 17:14:38345 _add_unwind_tables_in_apk =
346 defined(invoker.add_unwind_tables_in_apk) &&
347 invoker.add_unwind_tables_in_apk && target_cpu == "arm"
Andrew Grieved5fdf2af2022-08-23 07:47:55348
Siddhartha764226b2018-03-13 02:32:55349 # Adds the unwind tables from unstripped binary as an asset file in the
350 # apk, if |add_unwind_tables_in_apk| is specified by the test.
Andrew Grieved5fdf2af2022-08-23 07:47:55351 if (_add_unwind_tables_in_apk) {
Andrew Grieveee8aa44d2022-09-23 17:14:38352 # TODO(crbug.com/1315603): Remove generation of v1 unwind asset when
Tushar Agarwaldcafb622022-11-30 17:32:27353 # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroid`.
Andrew Grieveee8aa44d2022-09-23 17:14:38354 _unwind_table_name = "${_library_target_name}_unwind_v1"
355 unwind_table_v1(_unwind_table_name) {
356 library_target = ":$_library_target_name"
357 }
358
Arthur Sonzogni54424e92022-09-23 13:30:45359 if (use_android_unwinder_v2) {
Andrew Grieveee8aa44d2022-09-23 17:14:38360 _unwind_table_v2_name = "${_library_target_name}_unwind_v2"
361 unwind_table_v2(_unwind_table_v2_name) {
362 library_target = ":$_library_target_name"
Arthur Sonzogni54424e92022-09-23 13:30:45363 }
364 }
365
Andrew Grieveee8aa44d2022-09-23 17:14:38366 _unwind_table_asset_name = "${target_name}__unwind_assets"
367 android_assets(_unwind_table_asset_name) {
368 sources = [ "$target_out_dir/$_unwind_table_name/$unwind_table_asset_v1_filename" ]
369 disable_compression = true
370 deps = [ ":$_unwind_table_name" ]
371 if (use_android_unwinder_v2) {
372 sources += [ "$target_out_dir/$_unwind_table_v2_name/$unwind_table_asset_v2_filename" ]
373 deps += [ ":$_unwind_table_v2_name" ]
374 }
Siddhartha764226b2018-03-13 02:32:55375 }
376 }
377
Sam Maierbc320a9482023-05-17 19:44:16378 _generate_final_jni =
379 !defined(invoker.generate_final_jni) || invoker.generate_final_jni
Andrew Grieveee8aa44d2022-09-23 17:14:38380 mixed_test(_library_target_name) {
Sam Maierbc320a9482023-05-17 19:44:16381 if (_generate_final_jni) {
382 target_type = "shared_library_with_jni"
383 java_targets = [ ":$_apk_target_name" ]
384 } else {
385 target_type = "shared_library"
386 }
danakjebb9cc42022-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
jbudorickd29ecfa72016-11-18 22:45:42393 forward_variables_from(
394 invoker,
395 "*",
Andrew Grieved5fdf2af2022-08-23 07:47:55396 [
397 "configs",
398 "deps",
399 ] + _apk_specific_vars + _wrapper_script_vars +
Peter Wen2052bd12020-12-03 20:15:07400 TESTONLY_AND_VISIBILITY)
401
danakj482580a2022-11-18 18:00:59402 # Use a crate name that avoids creating a warning due to double
403 # underscore (ie. `__`).
404 crate_name = _library_crate_name
405
Peter Wen2052bd12020-12-03 20:15:07406 # Native targets do not need to depend on java targets. Filter them out
407 # so that the shared library can be built without needing to wait for
408 # dependent java targets.
Adrian Taylor62dbea52023-10-25 20:29:16409 deps = _fuzztest_deps
Peter Wen2052bd12020-12-03 20:15:07410 if (defined(invoker.deps)) {
Adrian Taylor62dbea52023-10-25 20:29:16411 deps += filter_exclude(invoker.deps, java_target_patterns)
Peter Wen2052bd12020-12-03 20:15:07412 }
agrieve62ab00282016-04-05 02:03:45413
Peter Kotwiczb9957d62021-04-12 21:09:43414 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37415 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45416 }
417 }
Andrew Grieveee8aa44d2022-09-23 17:14:38418 unittest_apk(_apk_target_name) {
Daniel Bratellfdda4652019-01-31 15:45:54419 forward_variables_from(invoker, _apk_specific_vars)
Andrew Grieveee8aa44d2022-09-23 17:14:38420 shared_library = ":$_library_target_name"
Sam Maierbc320a9482023-05-17 19:44:16421 if (_generate_final_jni) {
422 srcjar_deps = [ "${shared_library}__jni_registration" ]
Sam Maierbc320a9482023-05-17 19:44:16423 }
agrieve62ab00282016-04-05 02:03:45424 apk_name = invoker.target_name
425 if (defined(invoker.output_name)) {
426 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45427 }
agrieveb355ad152016-04-19 03:45:23428
Daniel Bratellfdda4652019-01-31 15:45:54429 if (defined(invoker.deps)) {
430 deps = invoker.deps
431 } else {
432 deps = []
433 }
Andrew Grieve43f24fd02022-04-06 23:04:04434 if (defined(loadable_module_deps)) {
435 deps += loadable_module_deps
436 }
Daniel Bratellfdda4652019-01-31 15:45:54437
jcivellif4462a352017-01-10 04:45:59438 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43439 if (_use_default_launcher) {
440 deps += [ "//base/test:test_support_java" ]
441 }
jcivellif4462a352017-01-10 04:45:59442
Siddhartha764226b2018-03-13 02:32:55443 if (defined(_unwind_table_asset_name)) {
444 deps += [ ":${_unwind_table_asset_name}" ]
445 }
agrieve62ab00282016-04-05 02:03:45446 }
Andrew Grievee1dc23f2019-10-22 16:26:36447 }
agrieve62ab00282016-04-05 02:03:45448
Andrew Grievee1dc23f2019-10-22 16:26:36449 test_runner_script(_test_runner_target) {
450 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce844392016-12-15 19:57:57451
Andrew Grievee1dc23f2019-10-22 16:26:36452 if (_use_raw_android_executable) {
453 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34454 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36455 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38456 apk_target = ":$_apk_target_name"
Andrew Grievee1dc23f2019-10-22 16:26:36457 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47458
459 # Dep needed for the test runner .runtime_deps file to pick up data
460 # deps from the forward_variables_from(invoker, "*") on the library.
Andrew Grieveee8aa44d2022-09-23 17:14:38461 data_deps = [ ":$_library_target_name" ]
agrieve62ab00282016-04-05 02:03:45462 }
Andrew Grievee1dc23f2019-10-22 16:26:36463 test_name = _output_name
464 test_suite = _output_name
465 test_type = "gtest"
mikecase56d80d72015-06-03 00:57:26466 }
467
Andrew Grieve7ca6de32019-10-18 03:57:47468 # Create a wrapper script rather than using a group() in order to ensure
469 # "ninja $target_name" always works. If this was a group(), then GN would
470 # not create a top-level alias for it if a target exists in another
471 # directory with the same $target_name.
472 # Also - bots run this script directly for "components_perftests".
473 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01474 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47475 executable = "$root_build_dir/bin/run_$_output_name"
476 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22477 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40478 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47479 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40480 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47481 # Dep needed for the swarming .isolate file to pick up data
482 # deps from the forward_variables_from(invoker, "*") on the library.
483 deps += [
Andrew Grieveee8aa44d2022-09-23 17:14:38484 ":$_apk_target_name",
485 ":$_library_target_name",
Andrew Grieve7ca6de32019-10-18 03:57:47486 ]
agrieve62ab00282016-04-05 02:03:45487 }
Dirk Pranke19a58732021-03-24 22:26:22488
489 if (defined(invoker.data_deps)) {
490 data_deps = invoker.data_deps
491 } else {
492 data_deps = []
493 }
Kevin Marshall23529362022-02-23 16:50:36494
495 data_deps += [ "//testing:test_scripts_shared" ]
496
Jamie Madilldd60ee62021-04-13 19:25:52497 if (tests_have_location_tags) {
498 data = [ "//testing/location_tags.json" ]
499 }
agrieve1a02e582015-10-15 21:35:39500 }
Scott Graham4c4cdc52017-05-29 20:45:03501 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30502 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
503
Scott Graham4c4cdc52017-05-29 20:45:03504 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42505 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42506 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb2022-04-05 12:30:35507 _program_name = get_label_info(":${_exec_target}", "name")
danakj505b7f02023-07-05 19:02:02508 _crate_name = _output_name
Scott Graham4c4cdc52017-05-29 20:45:03509
Greg Thompson2f1e3762022-10-17 19:53:44510 # Generate a CML fragment that provides the program name.
511 _test_program_fragment_target = "${target_name}_program-fragment"
512 _test_program_fragment = "${target_out_dir}/${target_name}_program.test-cml"
513 generated_file(_test_program_fragment_target) {
514 contents = {
515 program = {
516 binary = _program_name
Kevin Marshall2ec60032022-05-09 17:38:28517 }
Greg Thompson26516592021-12-16 08:34:45518 }
Greg Thompson2f1e3762022-10-17 19:53:44519 outputs = [ _test_program_fragment ]
520 output_conversion = "json"
Greg Thompson9765eeb2022-04-05 12:30:35521 }
522
Greg Thompson2f1e3762022-10-17 19:53:44523 _test_runner_shard =
524 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
525 if (defined(invoker.test_runner_shard)) {
526 _test_runner_shard = invoker.test_runner_shard
Wez6879f8a2021-09-07 20:27:02527 }
528
Greg Thompson2f1e3762022-10-17 19:53:44529 # Collate the complete set of elements to include in the test component's
530 # manifest.
David Dorwin2c4872c2023-02-22 20:00:56531
Greg Thompson2f1e3762022-10-17 19:53:44532 _manifest_fragments = [
Greg Thompson2f1e3762022-10-17 19:53:44533 _test_program_fragment,
534 _test_runner_shard,
535 ]
536
David Dorwin2c4872c2023-02-22 20:00:56537 # Select the Fuchsia test realm in which to run the test.
538 if (defined(invoker.run_as_chromium_system_test) &&
539 invoker.run_as_chromium_system_test) {
540 _manifest_fragments += [
541 "//build/config/fuchsia/test/chromium_system_test_facet.shard.test-cml",
542 "//build/config/fuchsia/test/system_test_minimum.shard.test-cml",
543 ]
544 } else {
545 _manifest_fragments += [
546 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
547 "//build/config/fuchsia/test/minimum.shard.test-cml",
548 ]
549 }
550
Zijie He78d978e2023-07-19 21:46:42551 if (is_asan) {
552 # TODO(crbug.com/1465997): Remove the extra cml segment for asan.
553 _manifest_fragments +=
554 [ "//build/config/fuchsia/test/asan_options.shard.test-cml" ]
555 }
556
Greg Thompson2f1e3762022-10-17 19:53:44557 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
558 _merged_manifest_name = "${_output_name}.cml"
559
560 if (defined(invoker.additional_manifest_fragments)) {
561 _manifest_fragments += invoker.additional_manifest_fragments
562 }
563
564 # Generate the test component manifest from the specified elements.
565 _test_component_manifest_target = "${target_name}_component-manifest"
566 cmc_merge(_test_component_manifest_target) {
567 sources = _manifest_fragments
568 output_name = "${_merged_manifest_name}"
569 deps = [ ":${_test_program_fragment_target}" ]
570 }
571
572 # Define the test component, dependent on the generated manifest, and the
573 # test executable target.
574 _test_component_target = "${target_name}_component"
575 fuchsia_component(_test_component_target) {
576 deps = [ ":$_test_component_manifest_target" ]
577 data_deps = [ ":$_exec_target" ]
578 manifest = _test_component_manifest
579 visibility = [ ":*" ]
580 }
581
582 _test_component_targets = [ ":${_test_component_target}" ]
583
Wez6879f8a2021-09-07 20:27:02584 # Define components for each entry in |additional_manifests|, if any. Since
585 # manifests may themselves depend-on the outputs of |deps|, these components
586 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02587 if (defined(invoker.additional_manifests)) {
588 foreach(filename, invoker.additional_manifests) {
589 _additional_component_target =
590 target_name + "_" + get_path_info(filename, "name")
591 _test_component_targets += [ ":${_additional_component_target}" ]
592 fuchsia_component(_additional_component_target) {
593 forward_variables_from(invoker, [ "testonly" ])
594 data_deps = [ ":$_exec_target" ]
595 visibility = [ ":*" ]
596 manifest = filename
597
598 # Depend on |invoker.deps|, in case it includes a dependency that
599 # creates this additional component's manifest.
600 if (defined(invoker.deps)) {
601 deps = invoker.deps
602 }
603 }
604 }
605 }
606
607 # Define the package target that will bundle the test and additional
608 # components and their data.
609 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21610 forward_variables_from(invoker,
611 [
612 "excluded_files",
613 "excluded_dirs",
Bryant Chandlerc40f2672023-01-27 23:33:30614 "excluded_paths",
Kevin Marshall36c602c2021-11-04 16:16:21615 ])
Wez6879f8a2021-09-07 20:27:02616 package_name = _output_name
617 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21618
Greg Thompsonfd269652022-10-28 12:06:55619 if (defined(invoker.fuchsia_package_deps)) {
620 deps += invoker.fuchsia_package_deps
621 }
Bryant Chandlerc40f2672023-01-27 23:33:30622 if (!defined(excluded_paths)) {
623 excluded_paths = []
Kevin Marshall36c602c2021-11-04 16:16:21624 }
Bryant Chandlerc40f2672023-01-27 23:33:30625 excluded_paths += [
626 "${devtools_root_location}/*",
627 "*.git/*",
628 "*.svn/*",
629 "*.hg/*",
630 ]
Sarah Pham80972efc2022-05-31 17:40:15631 if (devtools_root_location != "") {
Bryant Chandlerc40f2672023-01-27 23:33:30632 excluded_paths += [ "${devtools_root_location}/*" ]
Sarah Pham80972efc2022-05-31 17:40:15633 }
Wez6879f8a2021-09-07 20:27:02634 }
635
636 # |target_name| refers to the package-runner rule, so that building
637 # "base_unittests" will build not only the executable, component, and
638 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25639 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53640 forward_variables_from(invoker,
641 [
Kevin Marshall5fadadd2021-10-16 00:08:25642 "data",
643 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53644 "package_deps",
Kevin Marshall5fadadd2021-10-16 00:08:25645 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53646 ])
Kevin Marshall5fadadd2021-10-16 00:08:25647
Chong Guc6bfdf62021-10-20 23:37:00648 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15649 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25650 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42651
Kevin Marshall5fadadd2021-10-16 00:08:25652 if (!defined(deps)) {
653 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52654 }
Kevin Marshall5fadadd2021-10-16 00:08:25655 if (defined(invoker.deps)) {
656 deps += invoker.deps
657 }
Greg Guterman6963dc02021-04-07 05:20:59658
Kevin Marshall5fadadd2021-10-16 00:08:25659 if (!defined(data)) {
660 data = []
661 }
662 if (tests_have_location_tags) {
663 data += [ "//testing/location_tags.json" ]
664 }
665
666 if (!defined(data_deps)) {
667 data_deps = []
668 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28669
Kevin Marshall23529362022-02-23 16:50:36670 data_deps += [ "//testing:test_scripts_shared" ]
Kevin Marshallf35fa5f2018-01-29 19:24:42671 }
672
danakjebb9cc42022-03-04 21:30:11673 mixed_test(_exec_target) {
674 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01675 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42676 output_name = _exec_target
danakj505b7f02023-07-05 19:02:02677
Adrian Taylor62dbea52023-10-25 20:29:16678 if (!defined(deps)) {
679 deps = []
680 }
681 deps += _fuzztest_deps
682
danakj505b7f02023-07-05 19:02:02683 # Use a crate name that avoids creating a warning due to double
684 # underscore (ie. `__`).
685 crate_name = _crate_name
Scott Graham4c4cdc52017-05-29 20:45:03686 }
dpranke2a294622015-08-07 05:23:01687 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30688 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46689 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30690
Rohit Raof9b096d2019-09-09 22:26:23691 declare_args() {
Zhaoyang Li34fb05e2023-07-25 18:02:00692 # Keep the unittest-as-xctest functionality defaulted to off for
693 # local builds and test executions.
Rohit Raof9b096d2019-09-09 22:26:23694 enable_run_ios_unittests_with_xctest = false
695 }
696
sdefresne012857872016-03-16 10:55:37697 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27698
Jeff Yoonf7f4eb42020-03-06 18:55:36699 _wrapper_output_name = "run_${target_name}"
700 ios_test_runner_wrapper(_wrapper_output_name) {
701 forward_variables_from(invoker,
702 [
Cameron Higgins69d21be2023-12-04 17:57:21703 "clones",
Jeff Yoonf7f4eb42020-03-06 18:55:36704 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36705 "deps",
706 "executable_args",
707 "retries",
Cameron Higgins69d21be2023-12-04 17:57:21708
709 # TODO(crbug.com/1500395) deprecate shards
Jeff Yoonf7f4eb42020-03-06 18:55:36710 "shards",
711 ])
712
713 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
714
715 if (!defined(executable_args)) {
716 executable_args = []
717 }
718 executable_args += [
719 "--app",
720 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
721 ]
722
723 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22724
725 if (!defined(data)) {
726 data = []
727 }
Jamie Madilldd60ee62021-04-13 19:25:52728 if (tests_have_location_tags) {
729 data += [ "//testing/location_tags.json" ]
730 }
Jeff Yoonf7f4eb42020-03-06 18:55:36731 }
732
sdefresne012857872016-03-16 10:55:37733 _resources_bundle_data = target_name + "_resources_bundle_data"
734
735 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34736 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22737 sources = [ "//testing/gtest_ios/Default.png" ]
738 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01739 }
740
Mirko Bonadei15522bc2020-09-16 20:38:39741 force_xctest = enable_run_ios_unittests_with_xctest ||
742 (defined(invoker.is_xctest) && invoker.is_xctest)
743
danakjfae603fc602022-11-18 18:40:22744 mixed_test(_test_target) {
745 if (force_xctest) {
746 target_type = "ios_xctest_test"
747 } else {
748 target_type = "ios_app_bundle"
749 }
dpranke2a294622015-08-07 05:23:01750 testonly = true
sdefresnea828c282016-05-30 18:04:20751
Mirko Bonadei15522bc2020-09-16 20:38:39752 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23753 xctest_module_target = "//base/test:google_test_runner"
754 }
755
Andrew Grieve1b290e4a22020-11-24 20:07:01756 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13757
758 # Provide sensible defaults in case invoker did not define any of those
759 # required variables.
sdefresne05b97ca2016-06-08 07:19:46760 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13761 info_plist = "//testing/gtest_ios/unittest-Info.plist"
762 }
sdefresne9e147e02016-06-07 00:10:13763
Sylvain Defresne8c0fc9a2023-10-16 17:26:13764 bundle_identifier = shared_bundle_id_for_test_apps
dpranke2a294622015-08-07 05:23:01765
sdefresne047490e2016-07-22 08:49:34766 if (!defined(bundle_deps)) {
767 bundle_deps = []
768 }
769 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36770
771 if (!defined(data_deps)) {
772 data_deps = []
773 }
774
Kevin Marshall23529362022-02-23 16:50:36775 data_deps += [ "//testing:test_scripts_shared" ]
776
Jeff Yoonf7f4eb42020-03-06 18:55:36777 # Include the generate_wrapper as part of data_deps
778 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46779 write_runtime_deps = _runtime_deps_file
Adrian Taylor62dbea52023-10-25 20:29:16780 if (!defined(deps)) {
781 deps = []
782 }
783 deps += _fuzztest_deps
dpranke2a294622015-08-07 05:23:01784 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11785 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
786 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30787 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
788
Yuke Liao2a9b2f0e2021-04-16 00:40:11789 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32790
Benjamin Pastene3bce864e2018-04-14 01:16:32791 _gen_runner_target = "${target_name}__runner"
792 _runtime_deps_file =
793 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
794 "/" + get_label_info(target_name, "name") + ".runtime_deps"
795
Xinan Linf3f5aa52023-08-24 22:07:28796 if (is_skylab && (defined(tast_attr_expr) || defined(tast_tests) ||
797 defined(tast_disabled_tests))) {
798 generate_skylab_tast_filter(_gen_runner_target) {
Yuke Liaoacb74b12021-04-23 23:37:34799 }
Xinan Lin6be01252021-06-25 23:07:36800 } else {
801 generate_runner_script(_gen_runner_target) {
Xinan Linf3f5aa52023-08-24 22:07:28802 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Xinan Lin6be01252021-06-25 23:07:36803 test_exe = invoker.target_name
804 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34805
Xinan Lin6be01252021-06-25 23:07:36806 if (is_chromeos_lacros) {
807 # At build time, Lacros tests don't know whether they'll run on VM or
808 # HW, and instead, these flags are specified at runtime when invoking
809 # the generated runner script.
810 skip_generating_board_args = true
811 }
Greg Guterman6963dc02021-04-07 05:20:59812
Xinan Lin6be01252021-06-25 23:07:36813 if (tests_have_location_tags) {
814 data = [ "//testing/location_tags.json" ]
815 }
Greg Guterman6963dc02021-04-07 05:20:59816 }
Benjamin Pastene3bce864e2018-04-14 01:16:32817 }
818
danakjebb9cc42022-03-04 21:30:11819 mixed_test(target_name) {
820 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01821 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
822 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32823 if (!defined(deps)) {
824 deps = []
825 }
826 if (!defined(data)) {
827 data = []
828 }
829
Ben Pastene41041782019-02-16 04:21:58830 # We use a special trigger script for CrOS hardware tests.
831 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
832
Benjamin Pastene3bce864e2018-04-14 01:16:32833 write_runtime_deps = _runtime_deps_file
834 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37835 deps += [ ":$_gen_runner_target" ]
Adrian Taylor62dbea52023-10-25 20:29:16836 deps += _fuzztest_deps
Greg Guterman6963dc02021-04-07 05:20:59837
Kevin Marshall23529362022-02-23 16:50:36838 if (!defined(data_deps)) {
839 data_deps = []
840 }
841
842 data_deps += [ "//testing:test_scripts_shared" ]
Benjamin Pastene3bce864e2018-04-14 01:16:32843 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11844 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24845 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
846 _executable = target_name
847 _gen_runner_target = "${target_name}__runner"
848
Yuke Liao32af4242020-07-16 21:48:02849 if (defined(invoker.use_xvfb)) {
850 _use_xvfb = invoker.use_xvfb
851 } else {
852 _use_xvfb = false
853 }
854
Yuke Liaod037abc2020-10-06 22:48:22855 # When use_xvfb is set by the invoker, it indicates that running this test
856 # target requires a window, and in lacros build, ash-chrome serves as the
857 # display server. Note that even though the tests themselves do not require
858 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
859 # because ash-chrome is based on x11.
860 _use_ash_chrome = _use_xvfb
861
Yuke Liaoe703384b2020-07-16 01:05:24862 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24863 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02864
Yuke Liao2e4953cf2020-07-26 19:20:19865 data = []
Will Harrisd35e2c92021-04-07 01:42:02866 data_deps = [ "//testing:test_scripts_shared" ]
867
Yuke Liao32af4242020-07-16 21:48:02868 if (_use_xvfb) {
869 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22870 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02871 } else {
872 executable = "//testing/test_env.py"
873 }
Jamie Madilldd60ee62021-04-13 19:25:52874 if (tests_have_location_tags) {
875 data += [ "//testing/location_tags.json" ]
876 }
Yuke Liao32af4242020-07-16 21:48:02877
Yuke Liaoe703384b2020-07-16 01:05:24878 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02879 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39880 "test",
Yuke Liaoe703384b2020-07-16 01:05:24881 "@WrappedPath(./${_executable})",
882 "--test-launcher-bot-mode",
883 ]
Yuke Liao32af4242020-07-16 21:48:02884
Yuke Liaof540c742020-07-29 16:28:34885 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37886 executable_args += [ "--ash-chrome-path" ]
887
888 # Can't use --ash-chrome-path=path because WrappedPath
889 # won't be expanded for that usage.
890 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39891 }
892
Yuke Liaoe703384b2020-07-16 01:05:24893 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:00894 executable_args += [ "--asan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24895 }
896 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:00897 executable_args += [ "--msan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24898 }
899 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:00900 executable_args += [ "--tsan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24901 }
902 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:00903 executable_args += [ "--cfi-diag=1" ]
Yuke Liaoe703384b2020-07-16 01:05:24904 }
Ian Struiksma2ebc3222023-05-24 00:28:46905 if (fail_on_san_warnings) {
906 executable_args += [ "--fail-san=1" ]
907 }
Yuke Liaoe703384b2020-07-16 01:05:24908
Takuto Ikuta38ebd0e2022-01-19 17:56:22909 data += [ "//build/lacros/test_runner.py" ]
Yuke Liaoe703384b2020-07-16 01:05:24910 }
911
danakjebb9cc42022-03-04 21:30:11912 mixed_test(target_name) {
913 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01914 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
915 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24916 if (!defined(deps)) {
917 deps = []
918 }
919
Yuke Liaod037abc2020-10-06 22:48:22920 if (!defined(data_deps)) {
921 data_deps = []
922 }
923
Kevin Marshall23529362022-02-23 16:50:36924 data_deps += [ "//testing:test_scripts_shared" ]
925
Yuke Liaoe703384b2020-07-16 01:05:24926 write_runtime_deps = _runtime_deps_file
927 deps += [ ":$_gen_runner_target" ]
Adrian Taylor62dbea52023-10-25 20:29:16928 deps += _fuzztest_deps
Yuke Liaod037abc2020-10-06 22:48:22929 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56930 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22931 }
Yuke Liaoe703384b2020-07-16 01:05:24932 }
Dirk Prankedd4ff742020-11-18 19:57:32933 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30934 if (is_mac || is_win) {
935 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
936 }
937
Dirk Prankedd4ff742020-11-18 19:57:32938 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
939 _executable = target_name
940 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06941
Dirk Prankedd4ff742020-11-18 19:57:32942 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
943 _use_xvfb = invoker.use_xvfb
944 } else {
945 _use_xvfb = false
946 }
947
948 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32949 wrapper_script = "$root_build_dir/bin/run_" + _executable
950
951 data = []
Will Harrisd35e2c92021-04-07 01:42:02952 data_deps = [ "//testing:test_scripts_shared" ]
953
Dirk Prankedd4ff742020-11-18 19:57:32954 if (_use_xvfb) {
955 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06956 } else {
Dirk Prankedd4ff742020-11-18 19:57:32957 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06958 }
Jamie Madilldd60ee62021-04-13 19:25:52959 if (tests_have_location_tags) {
960 data += [ "//testing/location_tags.json" ]
961 }
Dirk Pranke31e346e2020-07-15 00:54:06962
Dirk Prankedd4ff742020-11-18 19:57:32963 executable_args = [
964 "@WrappedPath(./${_executable})",
965 "--test-launcher-bot-mode",
966 ]
967 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:00968 executable_args += [ "--asan=1" ]
Dirk Pranke31e346e2020-07-15 00:54:06969 }
Dirk Prankedd4ff742020-11-18 19:57:32970 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:00971 executable_args += [ "--msan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:32972 }
973 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:00974 executable_args += [ "--tsan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:32975 }
976 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:00977 executable_args += [ "--cfi-diag=1" ]
Dirk Prankedd4ff742020-11-18 19:57:32978 }
Ian Struiksma2ebc3222023-05-24 00:28:46979 if (fail_on_san_warnings) {
980 executable_args += [ "--fail-san=1" ]
981 }
Dirk Pranke31e346e2020-07-15 00:54:06982 }
983
danakjebb9cc42022-03-04 21:30:11984 mixed_test(target_name) {
985 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01986 forward_variables_from(invoker,
987 "*",
988 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
989 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06990 if (!defined(deps)) {
991 deps = []
992 }
993
Dirk Pranke31e346e2020-07-15 00:54:06994 deps += [
995 # Give tests the default manifest on Windows (a no-op elsewhere).
996 "//build/win:default_exe_manifest",
997 ]
998
Dirk Prankedd4ff742020-11-18 19:57:32999 write_runtime_deps = _runtime_deps_file
1000 deps += [ ":$_gen_runner_target" ]
Adrian Taylor62dbea52023-10-25 20:29:161001 deps += _fuzztest_deps
Greg Guterman50ed4b42021-04-08 01:15:111002
Kevin Marshall23529362022-02-23 16:50:361003 if (!defined(data_deps)) {
1004 data_deps = []
1005 }
1006
1007 data_deps += [ "//testing:test_scripts_shared" ]
Dirk Prankedd4ff742020-11-18 19:57:321008 }
1009 } else {
1010 # This is a catch-all clause for NaCl toolchains and other random
1011 # configurations that might define tests; test() in these configs
1012 # will just define the underlying executables.
1013 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
1014 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc42022-03-04 21:30:111015 mixed_test(target_name) {
1016 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011017 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1018 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:321019 if (!defined(deps)) {
1020 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061021 }
Adrian Taylor62dbea52023-10-25 20:29:161022 deps += _fuzztest_deps
Greg Guterman6963dc02021-04-07 05:20:591023
Kevin Marshall23529362022-02-23 16:50:361024 if (!defined(data_deps)) {
1025 data_deps = []
1026 }
1027
1028 data_deps += [ "//testing:test_scripts_shared" ]
Dirk Pranke31e346e2020-07-15 00:54:061029 }
qsrfb5251d12015-01-21 15:57:221030 }
1031}
brettwedb6ecc2016-07-14 23:37:031032
Dirk Pranke6188075b2020-10-01 19:31:281033# Defines a type of test that invokes a script to run, rather than
1034# invoking an executable.
1035#
1036# The script must implement the
1037# [test executable API](//docs/testing/test_executable_api.md).
1038#
Andrew Grievea16222d42023-02-10 15:31:101039# The template must be passed the `script` parameter, which specifies the path
1040# to the script to run. It may optionally be passed a `args` parameter, which
1041# can be used to include a list of args to be specified by default. The
1042# template will produce a `$root_build_dir/run_$target_name` wrapper and write
1043# the runtime_deps for the target to
1044# $root_build_dir/${target_name}.runtime_deps, as per the conventions listed in
1045# the [test wrapper API](//docs/testing/test_wrapper_api.md).
Dirk Pranke6188075b2020-10-01 19:31:281046template("script_test") {
1047 generate_wrapper(target_name) {
1048 testonly = true
1049 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1050
1051 executable = "//testing/test_env.py"
1052
1053 executable_args =
1054 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1055 if (defined(invoker.args)) {
1056 executable_args += invoker.args
1057 }
1058
Will Harrisd35e2c92021-04-07 01:42:021059 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471060
Dirk Pranke6188075b2020-10-01 19:31:281061 if (defined(invoker.data)) {
1062 data += invoker.data
1063 }
Jamie Madilldd60ee62021-04-13 19:25:521064 if (tests_have_location_tags) {
1065 data += [ "//testing/location_tags.json" ]
1066 }
Dirk Pranke19a58732021-03-24 22:26:221067
Will Harrisd35e2c92021-04-07 01:42:021068 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281069 if (defined(invoker.data_deps)) {
1070 data_deps += invoker.data_deps
1071 }
1072
1073 forward_variables_from(invoker,
Andrew Grievea16222d42023-02-10 15:31:101074 "*",
Andrew Grieve1b290e4a22020-11-24 20:07:011075 TESTONLY_AND_VISIBILITY + [
Andrew Grievea16222d42023-02-10 15:31:101076 "args",
Andrew Grieve1b290e4a22020-11-24 20:07:011077 "data",
1078 "data_deps",
1079 "script",
Andrew Grieve1b290e4a22020-11-24 20:07:011080 ])
1081 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281082
1083 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
1084 }
1085}
1086
Andrew Grievea16222d42023-02-10 15:31:101087# Defines a test target that uses exit code for pass/fail.
1088template("isolated_script_test") {
1089 script_test(target_name) {
1090 forward_variables_from(invoker,
1091 "*",
1092 TESTONLY_AND_VISIBILITY + [
1093 "args",
1094 "deps",
1095 "script",
1096 ])
1097 forward_variables_from(invoker, [ "visibility" ])
1098 deps = [ "//testing:run_isolated_script_test" ]
1099 if (defined(invoker.deps)) {
1100 deps += invoker.deps
1101 }
1102 script = "//testing/scripts/run_isolated_script_test.py"
1103 data = [ invoker.script ]
1104 args = [
1105 rebase_path(invoker.script, root_build_dir),
1106 "--script-type=bare",
1107 ]
1108 if (defined(invoker.args)) {
1109 args += invoker.args
1110 }
1111 }
1112}
1113
brettwedb6ecc2016-07-14 23:37:031114# Test defaults.
1115set_defaults("test") {
1116 if (is_android) {
1117 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411118 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591119 configs += [ "//build/config/android:hide_all_but_jni" ]
Andrew Grieved5fdf2af2022-08-23 07:47:551120
1121 # Compress sections to stay under 4gb hard limit on 32-bit current_cpu.
1122 # https://crbug.com/1354616
1123 if (symbol_level == 2 && !use_debug_fission &&
1124 (current_cpu == "arm" || current_cpu == "x86")) {
1125 configs += [ "//build/config:compress_debug_sections" ]
1126 }
brettwedb6ecc2016-07-14 23:37:031127 } else {
1128 configs = default_executable_configs
1129 }
1130}