blob: 4cccaeaf5dd9b6bde33b5612322a9c381ebfb4e4 [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")
danakj02dddc42022-02-11 23:24:3014import("//build/rust/mixed_executable.gni")
danakj98e073722022-02-24 21:01:4915import("//build/rust/mixed_shared_library.gni")
Mirko Bonadei4a0df432020-09-08 19:06:0216import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2417
Greg Guterman6963dc082021-04-07 05:20:5918declare_args() {
Dirk Prankeb404c3b2021-06-14 19:57:5019 # Some component repos (e.g. ANGLE) import //testing but do not have
20 # "location_tags.json", and so we don't want to try and upload the tags
21 # for their tests.
22 # And, some build configs may simply turn off generation altogether.
23 tests_have_location_tags = generate_location_tags
Greg Guterman6963dc082021-04-07 05:20:5924}
25
David Dorwin621c5072022-03-30 00:32:5326# On Fuchsia, the test executable has a suffix and is a dependency of the
27# common |target_name| target. For `visibility`, the executable must be
28# specified. Cross-platform targets that include `test` targets in their
29# visibility lists, add `${exec_target_suffix}` immediately after the test
30# target name. This is not necessary when the target is a `source_set`.
31if (is_fuchsia) {
32 exec_target_suffix = "__exec"
33} else {
34 exec_target_suffix = ""
35}
36
jcivellif4462a352017-01-10 04:45:5937if (is_android) {
38 import("//build/config/android/config.gni")
Charlie Hud98dc692021-12-08 01:01:0239 import("//build/config/android/create_unwind_table.gni")
James Cook209256f2018-12-07 18:40:5040 import("//build/config/android/extract_unwind_tables.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
danakjebb9cc4d2022-03-04 21:30:1162template("mixed_test") {
63 assert(defined(invoker.target_type) && invoker.target_type != "")
64 target("mixed_${invoker.target_type}", target_name) {
65 forward_variables_from(invoker,
66 "*",
67 TESTONLY_AND_VISIBILITY + [ "target_type" ])
68 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
69 if (!defined(rs_configs)) {
70 rs_configs = []
71 }
72 rs_configs += [ "//build/rust:test" ]
73
danakjaa85aad2022-03-10 18:45:1074 # The crate_root is generated and should not be specified.
75 assert(!defined(rs_crate_root))
76 rs_generate_crate_root = true
77
danakjebb9cc4d2022-03-04 21:30:1178 # We could automatically add `rs_deps += [ "//testing/rust_gtest_interop" ]`
79 # if `rs_sources` is non-empty. But we don't automatically provide
80 # //testing/gtest either so it would be asymmetric and could break in that
81 # case. So, we act instead as if //testing/rust_gtest_interop is part of the
82 # //testing/gtest dependency. If you add one, and have `rs_sources` listed,
83 # you get both.
84 _gtest_is_in_deps = false
85 if (defined(rs_sources) && rs_sources != [] && defined(deps) &&
86 deps != []) {
87 foreach(dep, deps) {
88 if (dep == "//testing/gtest") {
89 _gtest_is_in_deps = true
90 }
91 }
92 }
93 if (_gtest_is_in_deps) {
94 if (!defined(rs_deps)) {
95 rs_deps = []
96 }
97 rs_deps += [ "//testing/rust_gtest_interop" ]
98 }
99 }
100}
101
qsrfb5251d12015-01-21 15:57:22102# Define a test as an executable (or apk on Android) with the "testonly" flag
103# set.
agrieve62ab00282016-04-05 02:03:45104# Variable:
Dirk Pranke79d065d2020-08-29 03:28:30105# use_xvfb: (optional) whether to run the executable under Xvfb.
danakj02dddc42022-02-11 23:24:30106# use_raw_android_executable: Use mixed_executable() rather than
107# android_apk().
ynovikov389d9e442016-05-27 02:34:56108# use_native_activity: Test implements ANativeActivity_onCreate().
Greg Thompson26516592021-12-16 08:34:45109# use_cfv2: (Fuchsia, optional): build the test as a framework v2 component;
110# see https://fuchsia.dev/fuchsia-src/concepts/components/v2 for details.
Greg Thompson9765eeb42022-04-05 12:30:35111# The default value is true; set it to false explicitly to omit a .cm
112# manifest from the package.
113# use_cfv1: (Fuchsia, optional): build the test as a framework v1 component.
114# The default value is true; set it to false explicitly to omit a .cmx
115# manifest from the package.
Greg Thompson318cd692022-03-28 08:12:06116# test_runner_shard: (Fuchsia, optional): for CFv2 tests, use the given test
117# runner shard rather than the default shard for the ELF runner. This is
118# useful, for example, to use the elf_test_ambient_exec_runner for tests
119# that require job_policy_ambient_mark_vmo_exec.
Mirko Bonadei15522bc2020-09-16 20:38:39120# is_xctest: (iOS, optional) whether to build the executable as XCTest.
121# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
122# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:43123# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
124# network requests during the test.
qsrfb5251d12015-01-21 15:57:22125template("test") {
Greg Guterman6963dc082021-04-07 05:20:59126 # Ensures the rts file exists and if not, creates a dummy file
127 if (use_rts) {
128 action("${target_name}__rts_filters") {
129 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53130 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:05131 inverted_rts_file =
132 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
133 args = [
134 rebase_path(rts_file, root_build_dir),
135 rebase_path(inverted_rts_file, root_build_dir),
136 ]
137 outputs = [
138 rts_file,
139 inverted_rts_file,
140 ]
Greg Guterman6963dc082021-04-07 05:20:59141 }
142 }
143
Andrew Grieve1b290e4a22020-11-24 20:07:01144 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:39145 if (!is_ios) {
146 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
147 "is_xctest can be set only for iOS builds")
148 }
Stefano Duo4128b6b2021-08-02 21:24:43149 if (!is_android) {
150 assert(!defined(invoker.allow_cleartext_traffic),
151 "allow_cleartext_traffic can be set only for Android tests")
152 }
153
qsrfb5251d12015-01-21 15:57:22154 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:30155 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
156
Peter Kotwicz10742f82021-04-15 22:32:50157 _use_default_launcher =
158 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
159 if (!defined(invoker.use_raw_android_executable)) {
160 # Checkouts where build_with_chromium == false often have a custom GN
161 # template wrapper around test() which sets use_default_launcher == false.
162 # Set the _use_raw_android_executable default so that test() targets which
163 # do not use the custom wrapper
164 # (1) Do not cause "gn gen" to fail
165 # (2) Do not need to be moved into if(build_with_chromium) block.
166 _use_raw_android_executable =
167 !build_with_chromium && _use_default_launcher
168 } else {
169 not_needed([ "_use_default_launcher" ])
170 _use_raw_android_executable = invoker.use_raw_android_executable
171 }
qsrfb5251d12015-01-21 15:57:22172
agrieve67855de2016-03-30 14:46:01173 # output_name is used to allow targets with the same name but in different
174 # packages to still produce unique runner scripts.
175 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26176 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01177 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26178 }
agrieve62ab00282016-04-05 02:03:45179
agrieveb355ad152016-04-19 03:45:23180 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42181 _wrapper_script_vars = [
Jamie Madill73b9af332022-08-03 19:27:47182 "android_test_runner_script",
agrievee41ae190d2016-04-25 14:12:51183 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42184 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51185 ]
agrieve3ac557f02016-04-12 15:52:00186
jbudorickced2a252016-06-09 16:38:54187 assert(_use_raw_android_executable || enable_java_templates)
188
agrieve62ab00282016-04-05 02:03:45189 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49190 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
191
agrieve62ab00282016-04-05 02:03:45192 _exec_target = "${target_name}__exec"
193 _dist_target = "${target_name}__dist"
194 _exec_output =
195 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
196
danakjebb9cc4d2022-03-04 21:30:11197 mixed_test(_exec_target) {
198 target_type = "executable"
199
danakje94f40d2022-02-16 18:13:53200 # Configs will always be defined since we set_defaults in
201 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45202 configs = []
Dirk Pranke19a58732021-03-24 22:26:22203 forward_variables_from(
204 invoker,
205 "*",
206 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
207 "data_deps",
208 "extra_dist_files",
209 ])
agrieve62ab00282016-04-05 02:03:45210
211 # Thanks to the set_defaults() for test(), configs are initialized with
212 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59213 configs -= [
214 "//build/config:shared_library_config",
215 "//build/config/android:hide_all_but_jni",
216 ]
agrieve62ab00282016-04-05 02:03:45217 configs += [ "//build/config:executable_config" ]
218
Dirk Pranke19a58732021-03-24 22:26:22219 if (defined(invoker.data_deps)) {
220 data_deps = invoker.data_deps
221 } else {
222 data_deps = []
223 }
224 if (!defined(data)) {
225 data = []
226 }
Jamie Madilldd60ee62021-04-13 19:25:52227 if (tests_have_location_tags) {
228 data += [ "//testing/location_tags.json" ]
229 }
Dirk Pranke19a58732021-03-24 22:26:22230
agrieve62ab00282016-04-05 02:03:45231 # Don't output to the root or else conflict with the group() below.
232 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11233
234 if (use_rts) {
235 data_deps += [ ":${invoker.target_name}__rts_filters" ]
236 }
agrieve62ab00282016-04-05 02:03:45237 }
238
239 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45240 dist_dir = "$root_out_dir/$target_name"
241 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22242 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45243 if (defined(invoker.extra_dist_files)) {
244 extra_files = invoker.extra_dist_files
245 }
Greg Guterman50ed4b42021-04-08 01:15:11246
247 if (use_rts) {
248 if (!defined(data_deps)) {
249 data_deps = []
250 }
251 data_deps += [ ":${invoker.target_name}__rts_filters" ]
252 }
agrieve62ab00282016-04-05 02:03:45253 }
254 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02255 _library_target = "${target_name}__library"
danakj98e073722022-02-24 21:01:49256 _library_crate_name = "${target_name}_library"
Andrew Grievec61b8dff2019-10-21 16:32:02257 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45258 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43259 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45260 "android_manifest",
agrievec6811b422016-06-23 02:25:09261 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27262 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55263 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45264 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50265 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07266 "product_config_java_packages",
Andrew Grieve43f24fd02022-04-06 23:04:04267 "loadable_modules",
268 "loadable_module_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02269 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07270 "proguard_configs",
271 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45272 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02273 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45274 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56275 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45276 ]
Siddhartha764226b2018-03-13 02:32:55277
Andrew Grieved5fdf2af2022-08-23 07:47:55278 _add_unwind_tables_in_apk = defined(invoker.add_unwind_tables_in_apk) &&
279 invoker.add_unwind_tables_in_apk
280
Siddhartha764226b2018-03-13 02:32:55281 # Adds the unwind tables from unstripped binary as an asset file in the
282 # apk, if |add_unwind_tables_in_apk| is specified by the test.
Andrew Grieved5fdf2af2022-08-23 07:47:55283 if (_add_unwind_tables_in_apk) {
Charlie Hud98dc692021-12-08 01:01:02284 if (use_android_unwinder_v2) {
Charlie Hu1481dd22022-04-12 19:06:00285 _unwind_table_asset_v2_name = "${target_name}_v2_unwind_assets"
286 unwind_table_asset_v2(_unwind_table_asset_v2_name) {
Charlie Hud98dc692021-12-08 01:01:02287 library_target = _library_target
288 deps = [ ":$_library_target" ]
289 }
Charlie Hu1481dd22022-04-12 19:06:00290 }
291
292 # TODO(crbug.com/1315603): Remove generation of v1 unwind asset when
293 # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroidV2`.
294 _unwind_table_asset_name = "${target_name}_unwind_assets"
295 unwind_table_asset(_unwind_table_asset_name) {
296 library_target = _library_target
297 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55298 }
299 }
300
danakjebb9cc4d2022-03-04 21:30:11301 mixed_test(_library_target) {
302 target_type = "shared_library"
303
danakj98e073722022-02-24 21:01:49304 # Configs will always be defined since we set_defaults in
305 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45306 configs = [] # Prevent list overwriting warning.
307 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45308
Andrew Grieved5fdf2af2022-08-23 07:47:55309 if (_add_unwind_tables_in_apk) {
310 # Remove -gz if present, as dump_syms does not support it.
311 # Add and then remove because "-=" removes all, but errors if none are found.
312 configs += [ "//build/config:compress_debug_sections" ]
313 configs -= [ "//build/config:compress_debug_sections" ]
314 }
315
danakjebb9cc4d2022-03-04 21:30:11316 # Use a crate name that avoids creating a warning due to double
317 # underscore (ie. `__`).
danakj98e073722022-02-24 21:01:49318 rs_crate_name = _library_crate_name
danakj98e073722022-02-24 21:01:49319
jbudorickd29ecfa72016-11-18 22:45:42320 forward_variables_from(
321 invoker,
322 "*",
Andrew Grieved5fdf2af2022-08-23 07:47:55323 [
324 "configs",
325 "deps",
326 ] + _apk_specific_vars + _wrapper_script_vars +
Peter Wen2052bd12020-12-03 20:15:07327 TESTONLY_AND_VISIBILITY)
328
329 # Native targets do not need to depend on java targets. Filter them out
330 # so that the shared library can be built without needing to wait for
331 # dependent java targets.
332 deps = []
333 if (defined(invoker.deps)) {
Andrew Grieve841ed072022-08-23 16:42:33334 deps = filter_exclude(invoker.deps, java_target_patterns)
Peter Wen2052bd12020-12-03 20:15:07335 }
agrieve62ab00282016-04-05 02:03:45336
Peter Kotwiczb9957d62021-04-12 21:09:43337 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37338 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45339 }
340 }
341 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54342 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07343 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45344 apk_name = invoker.target_name
345 if (defined(invoker.output_name)) {
346 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45347 install_script_name = "install_${invoker.output_name}"
348 }
agrieveb355ad152016-04-19 03:45:23349
Daniel Bratellfdda4652019-01-31 15:45:54350 if (defined(invoker.deps)) {
351 deps = invoker.deps
352 } else {
353 deps = []
354 }
Andrew Grieve43f24fd02022-04-06 23:04:04355 if (defined(loadable_module_deps)) {
356 deps += loadable_module_deps
357 }
Daniel Bratellfdda4652019-01-31 15:45:54358
jcivellif4462a352017-01-10 04:45:59359 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43360 if (_use_default_launcher) {
361 deps += [ "//base/test:test_support_java" ]
362 }
jcivellif4462a352017-01-10 04:45:59363
Siddhartha764226b2018-03-13 02:32:55364 if (defined(_unwind_table_asset_name)) {
365 deps += [ ":${_unwind_table_asset_name}" ]
366 }
Greg Guterman50ed4b42021-04-08 01:15:11367
Charlie Hu05672742022-04-13 19:34:51368 if (defined(_unwind_table_asset_v2_name)) {
369 deps += [ ":${_unwind_table_asset_v2_name}" ]
370 }
371
Greg Guterman50ed4b42021-04-08 01:15:11372 if (use_rts) {
373 data_deps = [ ":${invoker.target_name}__rts_filters" ]
374 }
agrieve62ab00282016-04-05 02:03:45375 }
Andrew Grievee1dc23f2019-10-22 16:26:36376 }
agrieve62ab00282016-04-05 02:03:45377
Andrew Grievee1dc23f2019-10-22 16:26:36378 test_runner_script(_test_runner_target) {
379 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57380
Andrew Grievee1dc23f2019-10-22 16:26:36381 if (_use_raw_android_executable) {
382 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34383 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36384 } else {
385 apk_target = ":$_apk_target"
386 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47387
388 # Dep needed for the test runner .runtime_deps file to pick up data
389 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22390 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45391 }
Andrew Grievee1dc23f2019-10-22 16:26:36392 test_name = _output_name
393 test_suite = _output_name
394 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59395
396 if (use_rts) {
397 data_deps += [ ":${invoker.target_name}__rts_filters" ]
398 }
mikecase56d80d72015-06-03 00:57:26399 }
400
Andrew Grieve7ca6de32019-10-18 03:57:47401 # Create a wrapper script rather than using a group() in order to ensure
402 # "ninja $target_name" always works. If this was a group(), then GN would
403 # not create a top-level alias for it if a target exists in another
404 # directory with the same $target_name.
405 # Also - bots run this script directly for "components_perftests".
406 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01407 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47408 executable = "$root_build_dir/bin/run_$_output_name"
409 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22410 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40411 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47412 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40413 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47414 # Dep needed for the swarming .isolate file to pick up data
415 # deps from the forward_variables_from(invoker, "*") on the library.
416 deps += [
417 ":$_apk_target",
418 ":$_library_target",
419 ]
agrieve62ab00282016-04-05 02:03:45420 }
Dirk Pranke19a58732021-03-24 22:26:22421
422 if (defined(invoker.data_deps)) {
423 data_deps = invoker.data_deps
424 } else {
425 data_deps = []
426 }
Kevin Marshall23529362022-02-23 16:50:36427
428 data_deps += [ "//testing:test_scripts_shared" ]
429
Jamie Madilldd60ee62021-04-13 19:25:52430 if (tests_have_location_tags) {
431 data = [ "//testing/location_tags.json" ]
432 }
Greg Guterman6963dc082021-04-07 05:20:59433
434 if (use_rts) {
435 data_deps += [ ":${invoker.target_name}__rts_filters" ]
436 }
agrieve1a02e582015-10-15 21:35:39437 }
Scott Graham4c4cdc52017-05-29 20:45:03438 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30439 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
440
Greg Thompson9765eeb42022-04-05 12:30:35441 # It's meaningless to omit both types of manifest from the package.
442 assert(!defined(invoker.use_cfv2) || invoker.use_cfv2 ||
443 !defined(invoker.use_cfv1) || invoker.use_cfv1)
444
Scott Graham4c4cdc52017-05-29 20:45:03445 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42446 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42447 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb42022-04-05 12:30:35448 _program_name = get_label_info(":${_exec_target}", "name")
449 _test_component_targets = []
Scott Graham4c4cdc52017-05-29 20:45:03450
Greg Thompson9765eeb42022-04-05 12:30:35451 # Generate a CFv2 manifest unless the target opts-out via `use_cfv2=false`.
Greg Thompson5e4f41f2022-02-09 16:35:14452 if (!defined(invoker.use_cfv2) || invoker.use_cfv2) {
Greg Thompson26516592021-12-16 08:34:45453 # Generate a CML fragment that provides the program name.
454 _test_program_fragment_target = "${target_name}_program-fragment"
455 _test_program_fragment =
456 "${target_out_dir}/${target_name}_program.test-cml"
Greg Thompson26516592021-12-16 08:34:45457 generated_file(_test_program_fragment_target) {
Kevin Marshall2ec60032022-05-09 17:38:28458 contents = {
459 program = {
460 binary = _program_name
461 }
462 }
Greg Thompson26516592021-12-16 08:34:45463 outputs = [ _test_program_fragment ]
Kevin Marshall2ec60032022-05-09 17:38:28464 output_conversion = "json"
Greg Thompson26516592021-12-16 08:34:45465 }
466
Greg Thompson318cd692022-03-28 08:12:06467 _test_runner_shard =
468 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
469 if (defined(invoker.test_runner_shard)) {
470 _test_runner_shard = invoker.test_runner_shard
471 }
472
Greg Thompson26516592021-12-16 08:34:45473 # Collate the complete set of elements to include in the test component's
474 # manifest.
475 _manifest_fragments = [
Greg Thompson6cdcdb32022-01-31 11:12:44476 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
Greg Thompsonf31d7d22022-01-26 09:17:45477 "//build/config/fuchsia/test/minimum.shard.test-cml",
Greg Thompson26516592021-12-16 08:34:45478 _test_program_fragment,
Greg Thompson318cd692022-03-28 08:12:06479 _test_runner_shard,
Greg Thompson26516592021-12-16 08:34:45480 ]
481
482 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
483 _merged_manifest_name = "${_output_name}.cml"
Greg Thompson9765eeb42022-04-05 12:30:35484
485 if (defined(invoker.additional_manifest_fragments)) {
486 _manifest_fragments +=
487 filter_include(invoker.additional_manifest_fragments,
488 [
489 "*.cml",
490 "*.test-cml",
491 ])
492 }
493
494 # Generate the test component manifest from the specified elements.
495 _test_component_manifest_target = "${target_name}_component-manifest"
496 cmc_merge(_test_component_manifest_target) {
497 sources = _manifest_fragments
498 output_name = "${_merged_manifest_name}"
499 deps = [ ":${_test_program_fragment_target}" ]
500 }
501
502 # Define the test component, dependent on the generated manifest, and the
503 # test executable target.
504 _test_component_target = "${target_name}_component"
505 fuchsia_component(_test_component_target) {
506 deps = [ ":$_test_component_manifest_target" ]
507 data_deps = [ ":$_exec_target" ]
508 manifest = _test_component_manifest
509 visibility = [ ":*" ]
510 }
511
512 _test_component_targets += [ ":${_test_component_target}" ]
513 }
514
515 # Generate a CFv1 manifest unless the target opts-out via `use_cfv1=false`.
516 if (!defined(invoker.use_cfv1) || invoker.use_cfv1) {
Greg Thompson26516592021-12-16 08:34:45517 # Generate a CMX fragment that provides the program name.
Greg Thompson9765eeb42022-04-05 12:30:35518 _test_program_fragment_target_v1 = "${target_name}_program-fragment_v1"
519 _test_program_fragment_v1 =
Greg Thompson26516592021-12-16 08:34:45520 "${target_out_dir}/${target_name}_program.test-cmx"
Greg Thompson9765eeb42022-04-05 12:30:35521 generated_file(_test_program_fragment_target_v1) {
Greg Thompson26516592021-12-16 08:34:45522 contents = "{ \"program\": { \"binary\": \"${_program_name}\"}}"
Greg Thompson9765eeb42022-04-05 12:30:35523 outputs = [ _test_program_fragment_v1 ]
Greg Thompson26516592021-12-16 08:34:45524 }
525
526 # Collate the complete set of elements to include in the test component's
527 # manifest.
Greg Thompson9765eeb42022-04-05 12:30:35528 _manifest_fragments_v1 = [
Greg Thompson26516592021-12-16 08:34:45529 "//build/config/fuchsia/test/minimum_capabilities.test-cmx",
Greg Thompson9765eeb42022-04-05 12:30:35530 _test_program_fragment_v1,
Greg Thompson26516592021-12-16 08:34:45531 ]
532
Greg Thompson9765eeb42022-04-05 12:30:35533 _test_component_manifest_v1 = "${target_out_dir}/${target_name}.cmx"
534 _merged_manifest_name_v1 = "${_output_name}.cmx"
Chong Gu26908f4e2021-01-29 03:13:07535
Greg Thompson9765eeb42022-04-05 12:30:35536 if (defined(invoker.additional_manifest_fragments)) {
537 _manifest_fragments_v1 +=
538 filter_include(invoker.additional_manifest_fragments,
539 [
540 "*.cmx",
541 "*.test-cmx",
542 ])
543 }
Chong Gu28bf7e72021-05-26 01:36:19544
Greg Thompson9765eeb42022-04-05 12:30:35545 # Generate the test component manifest from the specified elements.
546 _test_component_manifest_target_v1 =
547 "${target_name}_component-manifest_v1"
548 cmc_merge(_test_component_manifest_target_v1) {
549 sources = _manifest_fragments_v1
550 output_name = "${_merged_manifest_name_v1}"
551 deps = [ ":${_test_program_fragment_target_v1}" ]
552 }
Chong Gu26908f4e2021-01-29 03:13:07553
Greg Thompson9765eeb42022-04-05 12:30:35554 # Define the test component, dependent on the generated manifest, and the
555 # test executable target.
556 _test_component_target_v1 = "${target_name}_component_v1"
557 fuchsia_component(_test_component_target_v1) {
558 deps = [ ":$_test_component_manifest_target_v1" ]
559 data_deps = [ ":$_exec_target" ]
560 manifest = _test_component_manifest_v1
561 visibility = [ ":*" ]
562 }
563
564 _test_component_targets += [ ":${_test_component_target_v1}" ]
Wez6879f8a2021-09-07 20:27:02565 }
566
567 # Define components for each entry in |additional_manifests|, if any. Since
568 # manifests may themselves depend-on the outputs of |deps|, these components
569 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02570 if (defined(invoker.additional_manifests)) {
571 foreach(filename, invoker.additional_manifests) {
572 _additional_component_target =
573 target_name + "_" + get_path_info(filename, "name")
574 _test_component_targets += [ ":${_additional_component_target}" ]
575 fuchsia_component(_additional_component_target) {
576 forward_variables_from(invoker, [ "testonly" ])
577 data_deps = [ ":$_exec_target" ]
578 visibility = [ ":*" ]
579 manifest = filename
580
581 # Depend on |invoker.deps|, in case it includes a dependency that
582 # creates this additional component's manifest.
583 if (defined(invoker.deps)) {
584 deps = invoker.deps
585 }
586 }
587 }
588 }
589
590 # Define the package target that will bundle the test and additional
591 # components and their data.
592 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21593 forward_variables_from(invoker,
594 [
595 "excluded_files",
596 "excluded_dirs",
597 ])
Wez6879f8a2021-09-07 20:27:02598 package_name = _output_name
599 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21600
601 if (!defined(excluded_dirs)) {
602 excluded_dirs = []
603 }
Sarah Pham80972efc2022-05-31 17:40:15604 if (devtools_root_location != "") {
605 excluded_dirs += [ devtools_root_location ]
606 }
Wez6879f8a2021-09-07 20:27:02607 }
608
609 # |target_name| refers to the package-runner rule, so that building
610 # "base_unittests" will build not only the executable, component, and
611 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25612 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53613 forward_variables_from(invoker,
614 [
Kevin Marshall5fadadd2021-10-16 00:08:25615 "data",
616 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53617 "package_deps",
Greg Thompson26516592021-12-16 08:34:45618 "use_cfv2",
Kevin Marshall5fadadd2021-10-16 00:08:25619 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53620 ])
Kevin Marshall5fadadd2021-10-16 00:08:25621
Chong Guc6bfdf62021-10-20 23:37:00622 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15623 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25624 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42625
Kevin Marshall5fadadd2021-10-16 00:08:25626 if (!defined(deps)) {
627 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52628 }
Kevin Marshall5fadadd2021-10-16 00:08:25629 if (defined(invoker.deps)) {
630 deps += invoker.deps
631 }
Greg Guterman6963dc082021-04-07 05:20:59632
Kevin Marshall5fadadd2021-10-16 00:08:25633 if (!defined(data)) {
634 data = []
635 }
636 if (tests_have_location_tags) {
637 data += [ "//testing/location_tags.json" ]
638 }
639
640 if (!defined(data_deps)) {
641 data_deps = []
642 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28643
Kevin Marshall23529362022-02-23 16:50:36644 data_deps += [ "//testing:test_scripts_shared" ]
645
Greg Guterman6963dc082021-04-07 05:20:59646 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25647 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59648 }
Kevin Marshallf35fa5f2018-01-29 19:24:42649 }
650
danakjebb9cc4d2022-03-04 21:30:11651 mixed_test(_exec_target) {
652 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01653 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42654 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03655 }
dpranke2a294622015-08-07 05:23:01656 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30657 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46658 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30659
Rohit Raof9b096d2019-09-09 22:26:23660 declare_args() {
661 # Keep the unittest-as-xctest functionality defaulted to off until the
662 # bots are updated to handle it properly.
663 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
664 # supports running unittests with xctest.
665 enable_run_ios_unittests_with_xctest = false
666 }
667
sdefresne012857872016-03-16 10:55:37668 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27669 _output_name = target_name
670 if (defined(invoker.output_name)) {
671 _output_name = invoker.output_name
672 }
673
Jeff Yoonf7f4eb42020-03-06 18:55:36674 _wrapper_output_name = "run_${target_name}"
675 ios_test_runner_wrapper(_wrapper_output_name) {
676 forward_variables_from(invoker,
677 [
678 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36679 "deps",
680 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27681 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36682 "retries",
683 "shards",
684 ])
685
686 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
687
688 if (!defined(executable_args)) {
689 executable_args = []
690 }
691 executable_args += [
692 "--app",
693 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
694 ]
695
696 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22697
698 if (!defined(data)) {
699 data = []
700 }
Jamie Madilldd60ee62021-04-13 19:25:52701 if (tests_have_location_tags) {
702 data += [ "//testing/location_tags.json" ]
703 }
Jeff Yoonf7f4eb42020-03-06 18:55:36704 }
705
sdefresne012857872016-03-16 10:55:37706 _resources_bundle_data = target_name + "_resources_bundle_data"
707
708 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34709 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22710 sources = [ "//testing/gtest_ios/Default.png" ]
711 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01712 }
713
Mirko Bonadei15522bc2020-09-16 20:38:39714 force_xctest = enable_run_ios_unittests_with_xctest ||
715 (defined(invoker.is_xctest) && invoker.is_xctest)
716
717 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23718 ios_test_target_type = "ios_xctest_test"
719 } else {
720 ios_test_target_type = "ios_app_bundle"
721 }
722
723 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01724 testonly = true
sdefresnea828c282016-05-30 18:04:20725
Mirko Bonadei15522bc2020-09-16 20:38:39726 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23727 xctest_module_target = "//base/test:google_test_runner"
728 }
729
Andrew Grieve1b290e4a22020-11-24 20:07:01730 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13731
732 # Provide sensible defaults in case invoker did not define any of those
733 # required variables.
sdefresne05b97ca2016-06-08 07:19:46734 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13735 info_plist = "//testing/gtest_ios/unittest-Info.plist"
736 }
sdefresne9e147e02016-06-07 00:10:13737
Sylvain Defresne3c5a1312021-09-23 17:08:09738 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13739 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50740 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09741 } else {
Ali Juma75be0fe2022-01-24 19:39:29742 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27743 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09744 }
dpranke2a294622015-08-07 05:23:01745
sdefresne047490e2016-07-22 08:49:34746 if (!defined(bundle_deps)) {
747 bundle_deps = []
748 }
749 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36750
751 if (!defined(data_deps)) {
752 data_deps = []
753 }
754
Kevin Marshall23529362022-02-23 16:50:36755 data_deps += [ "//testing:test_scripts_shared" ]
756
Jeff Yoonf7f4eb42020-03-06 18:55:36757 # Include the generate_wrapper as part of data_deps
758 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46759 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59760
761 if (use_rts) {
762 data_deps += [ ":${invoker.target_name}__rts_filters" ]
763 }
dpranke2a294622015-08-07 05:23:01764 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11765 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
766 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30767 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
768
Yuke Liao2a9b2f0e2021-04-16 00:40:11769 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32770
Benjamin Pastene3bce864e2018-04-14 01:16:32771 _gen_runner_target = "${target_name}__runner"
772 _runtime_deps_file =
773 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
774 "/" + get_label_info(target_name, "name") + ".runtime_deps"
775
Xinan Lin6be01252021-06-25 23:07:36776 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
777 if (is_skylab) {
Struan Shrimptonf61293f62022-04-11 19:33:40778 generate_skylab_deps(_gen_runner_target) {
Xinan Lin6be01252021-06-25 23:07:36779 generated_script = _generated_script
780 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34781 }
Xinan Lin6be01252021-06-25 23:07:36782 } else {
783 generate_runner_script(_gen_runner_target) {
784 generated_script = _generated_script
785 test_exe = invoker.target_name
786 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34787
Xinan Lin6be01252021-06-25 23:07:36788 if (is_chromeos_lacros) {
789 # At build time, Lacros tests don't know whether they'll run on VM or
790 # HW, and instead, these flags are specified at runtime when invoking
791 # the generated runner script.
792 skip_generating_board_args = true
793 }
Greg Guterman6963dc082021-04-07 05:20:59794
Xinan Lin6be01252021-06-25 23:07:36795 if (tests_have_location_tags) {
796 data = [ "//testing/location_tags.json" ]
797 }
798
799 if (use_rts) {
800 data_deps = [ ":${invoker.target_name}__rts_filters" ]
801 }
Greg Guterman6963dc082021-04-07 05:20:59802 }
Benjamin Pastene3bce864e2018-04-14 01:16:32803 }
804
danakjebb9cc4d2022-03-04 21:30:11805 mixed_test(target_name) {
806 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01807 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
808 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32809 if (!defined(deps)) {
810 deps = []
811 }
812 if (!defined(data)) {
813 data = []
814 }
815
Ben Pastene41041782019-02-16 04:21:58816 # We use a special trigger script for CrOS hardware tests.
817 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
818
Benjamin Pastene3bce864e2018-04-14 01:16:32819 output_name = target_name
820 write_runtime_deps = _runtime_deps_file
821 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37822 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59823
Kevin Marshall23529362022-02-23 16:50:36824 if (!defined(data_deps)) {
825 data_deps = []
826 }
827
828 data_deps += [ "//testing:test_scripts_shared" ]
829
Greg Guterman6963dc082021-04-07 05:20:59830 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59831 data_deps += [ ":${invoker.target_name}__rts_filters" ]
832 }
Benjamin Pastene3bce864e2018-04-14 01:16:32833 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11834 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24835 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
836 _executable = target_name
837 _gen_runner_target = "${target_name}__runner"
838
Yuke Liao32af4242020-07-16 21:48:02839 if (defined(invoker.use_xvfb)) {
840 _use_xvfb = invoker.use_xvfb
841 } else {
842 _use_xvfb = false
843 }
844
Yuke Liaod037abc2020-10-06 22:48:22845 # When use_xvfb is set by the invoker, it indicates that running this test
846 # target requires a window, and in lacros build, ash-chrome serves as the
847 # display server. Note that even though the tests themselves do not require
848 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
849 # because ash-chrome is based on x11.
850 _use_ash_chrome = _use_xvfb
851
Yuke Liaoe703384b2020-07-16 01:05:24852 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24853 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02854
Yuke Liao2e4953cf2020-07-26 19:20:19855 data = []
Will Harrisd35e2c92021-04-07 01:42:02856 data_deps = [ "//testing:test_scripts_shared" ]
857
Yuke Liao32af4242020-07-16 21:48:02858 if (_use_xvfb) {
859 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22860 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02861 } else {
862 executable = "//testing/test_env.py"
863 }
Jamie Madilldd60ee62021-04-13 19:25:52864 if (tests_have_location_tags) {
865 data += [ "//testing/location_tags.json" ]
866 }
Yuke Liao32af4242020-07-16 21:48:02867
Yuke Liaoe703384b2020-07-16 01:05:24868 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02869 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39870 "test",
Yuke Liaoe703384b2020-07-16 01:05:24871 "@WrappedPath(./${_executable})",
872 "--test-launcher-bot-mode",
873 ]
Yuke Liao32af4242020-07-16 21:48:02874
Yuke Liaof540c742020-07-29 16:28:34875 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37876 executable_args += [ "--ash-chrome-path" ]
877
878 # Can't use --ash-chrome-path=path because WrappedPath
879 # won't be expanded for that usage.
880 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39881 }
882
Yuke Liaoe703384b2020-07-16 01:05:24883 if (is_asan) {
884 executable_args += [ "--asan=true" ]
885 }
886 if (is_msan) {
887 executable_args += [ "--msan=true" ]
888 }
889 if (is_tsan) {
890 executable_args += [ "--tsan=true" ]
891 }
892 if (use_cfi_diag) {
893 executable_args += [ "--cfi-diag=true" ]
894 }
895
Takuto Ikuta38ebd0e2022-01-19 17:56:22896 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59897
898 if (use_rts) {
899 data_deps += [ ":${invoker.target_name}__rts_filters" ]
900 }
Yuke Liaoe703384b2020-07-16 01:05:24901 }
902
danakjebb9cc4d2022-03-04 21:30:11903 mixed_test(target_name) {
904 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01905 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
906 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24907 if (!defined(deps)) {
908 deps = []
909 }
910
Yuke Liaod037abc2020-10-06 22:48:22911 if (!defined(data_deps)) {
912 data_deps = []
913 }
914
Kevin Marshall23529362022-02-23 16:50:36915 data_deps += [ "//testing:test_scripts_shared" ]
916
Yuke Liaoe703384b2020-07-16 01:05:24917 write_runtime_deps = _runtime_deps_file
918 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22919 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56920 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22921 }
Greg Guterman6963dc082021-04-07 05:20:59922
923 if (use_rts) {
924 data_deps += [ ":${invoker.target_name}__rts_filters" ]
925 }
Yuke Liaoe703384b2020-07-16 01:05:24926 }
Dirk Prankedd4ff742020-11-18 19:57:32927 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30928 if (is_mac || is_win) {
929 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
930 }
931
Dirk Prankedd4ff742020-11-18 19:57:32932 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
933 _executable = target_name
934 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06935
Dirk Prankedd4ff742020-11-18 19:57:32936 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
937 _use_xvfb = invoker.use_xvfb
938 } else {
939 _use_xvfb = false
940 }
941
942 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32943 wrapper_script = "$root_build_dir/bin/run_" + _executable
944
945 data = []
Will Harrisd35e2c92021-04-07 01:42:02946 data_deps = [ "//testing:test_scripts_shared" ]
947
Dirk Prankedd4ff742020-11-18 19:57:32948 if (_use_xvfb) {
949 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06950 } else {
Dirk Prankedd4ff742020-11-18 19:57:32951 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06952 }
Jamie Madilldd60ee62021-04-13 19:25:52953 if (tests_have_location_tags) {
954 data += [ "//testing/location_tags.json" ]
955 }
Dirk Pranke31e346e2020-07-15 00:54:06956
Dirk Prankedd4ff742020-11-18 19:57:32957 executable_args = [
958 "@WrappedPath(./${_executable})",
959 "--test-launcher-bot-mode",
960 ]
961 if (is_asan) {
962 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06963 }
Dirk Prankedd4ff742020-11-18 19:57:32964 if (is_msan) {
965 executable_args += [ "--msan=true" ]
966 }
967 if (is_tsan) {
968 executable_args += [ "--tsan=true" ]
969 }
970 if (use_cfi_diag) {
971 executable_args += [ "--cfi-diag=true" ]
972 }
973
Greg Guterman6963dc082021-04-07 05:20:59974 if (use_rts) {
975 data_deps += [ ":${invoker.target_name}__rts_filters" ]
976 }
Dirk Pranke31e346e2020-07-15 00:54:06977 }
978
danakjebb9cc4d2022-03-04 21:30:11979 mixed_test(target_name) {
980 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01981 forward_variables_from(invoker,
982 "*",
983 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
984 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06985 if (!defined(deps)) {
986 deps = []
987 }
988
Dirk Pranke31e346e2020-07-15 00:54:06989 deps += [
990 # Give tests the default manifest on Windows (a no-op elsewhere).
991 "//build/win:default_exe_manifest",
992 ]
993
Dirk Prankedd4ff742020-11-18 19:57:32994 write_runtime_deps = _runtime_deps_file
995 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11996
Kevin Marshall23529362022-02-23 16:50:36997 if (!defined(data_deps)) {
998 data_deps = []
999 }
1000
1001 data_deps += [ "//testing:test_scripts_shared" ]
1002
Greg Guterman50ed4b42021-04-08 01:15:111003 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:111004 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1005 }
Dirk Prankedd4ff742020-11-18 19:57:321006 }
1007 } else {
1008 # This is a catch-all clause for NaCl toolchains and other random
1009 # configurations that might define tests; test() in these configs
1010 # will just define the underlying executables.
1011 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
1012 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:111013 mixed_test(target_name) {
1014 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011015 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1016 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:321017 if (!defined(deps)) {
1018 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061019 }
Greg Guterman6963dc082021-04-07 05:20:591020
Kevin Marshall23529362022-02-23 16:50:361021 if (!defined(data_deps)) {
1022 data_deps = []
1023 }
1024
1025 data_deps += [ "//testing:test_scripts_shared" ]
1026
Greg Guterman6963dc082021-04-07 05:20:591027 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:591028 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1029 }
Dirk Pranke31e346e2020-07-15 00:54:061030 }
qsrfb5251d12015-01-21 15:57:221031 }
1032}
brettwedb6ecc2016-07-14 23:37:031033
Dirk Pranke6188075b2020-10-01 19:31:281034# Defines a type of test that invokes a script to run, rather than
1035# invoking an executable.
1036#
1037# The script must implement the
1038# [test executable API](//docs/testing/test_executable_api.md).
1039#
1040# The template must be passed the `script` parameter, which specifies
1041# the path to the script to run. It may optionally be passed a
1042# `script_args` parameter, which can be used to include a list of
1043# args to be specified by default. The template will produce
1044# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
1045# for the target to $root_build_dir/${target_name}.runtime_deps, as per
1046# the conventions listed in the
1047# [test wrapper API](//docs/testing/test_wrapper_api.md).
1048template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:591049 if (use_rts) {
1050 action("${target_name}__rts_filters") {
1051 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:531052 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Struan Shrimpton570c87842022-08-16 22:30:051053 inverted_rts_file =
1054 "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter"
1055 args = [
1056 rebase_path(rts_file, root_build_dir),
1057 rebase_path(inverted_rts_file, root_build_dir),
1058 ]
1059 outputs = [
1060 rts_file,
1061 inverted_rts_file,
1062 ]
Greg Guterman6963dc082021-04-07 05:20:591063 }
1064 }
1065
Dirk Pranke6188075b2020-10-01 19:31:281066 generate_wrapper(target_name) {
1067 testonly = true
1068 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1069
1070 executable = "//testing/test_env.py"
1071
1072 executable_args =
1073 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1074 if (defined(invoker.args)) {
1075 executable_args += invoker.args
1076 }
1077
Will Harrisd35e2c92021-04-07 01:42:021078 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471079
Dirk Pranke6188075b2020-10-01 19:31:281080 if (defined(invoker.data)) {
1081 data += invoker.data
1082 }
Jamie Madilldd60ee62021-04-13 19:25:521083 if (tests_have_location_tags) {
1084 data += [ "//testing/location_tags.json" ]
1085 }
Dirk Pranke19a58732021-03-24 22:26:221086
Will Harrisd35e2c92021-04-07 01:42:021087 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281088 if (defined(invoker.data_deps)) {
1089 data_deps += invoker.data_deps
1090 }
1091
1092 forward_variables_from(invoker,
1093 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:011094 TESTONLY_AND_VISIBILITY + [
1095 "data",
1096 "data_deps",
1097 "script",
1098 "script_args",
1099 ])
1100 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281101
1102 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591103
1104 if (use_rts) {
1105 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1106 }
Dirk Pranke6188075b2020-10-01 19:31:281107 }
1108}
1109
brettwedb6ecc2016-07-14 23:37:031110# Test defaults.
1111set_defaults("test") {
1112 if (is_android) {
1113 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411114 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591115 configs += [ "//build/config/android:hide_all_but_jni" ]
Andrew Grieved5fdf2af2022-08-23 07:47:551116
1117 # Compress sections to stay under 4gb hard limit on 32-bit current_cpu.
1118 # https://crbug.com/1354616
1119 if (symbol_level == 2 && !use_debug_fission &&
1120 (current_cpu == "arm" || current_cpu == "x86")) {
1121 configs += [ "//build/config:compress_debug_sections" ]
1122 }
brettwedb6ecc2016-07-14 23:37:031123 } else {
1124 configs = default_executable_configs
Leonard Grey077a28302021-12-16 14:14:261125 if (is_mac) {
1126 # TODO(lgrey): Maybe restore this.
1127 # Don't strip tests for visibility into test crashes/hangs.
1128 # https://bugs.chromium.org/p/chromium/issues/detail?id=1244047#c49
1129 configs -= [ "//build/config/mac:strip_all" ]
1130 }
brettwedb6ecc2016-07-14 23:37:031131 }
1132}