blob: 7594f859b1e9db1457f48ab4cbb2762546fd6c6c [file] [log] [blame]
qsrc6c612c2015-01-13 22:07:481# Copyright 2015 The Chromium Authors. All rights reserved.
2# 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")
Kevin Marshallf35fa5f2018-01-29 19:24:4246 import("//build/config/fuchsia/package.gni")
Chong Gu26908f4e2021-01-29 03:13:0747 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Nico Weberd73c90382022-03-30 20:37:5048} else if (is_chromeos && is_chromeos_device) {
Ben Pastene4c35c572018-04-30 23:21:4849 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3250 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2851 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3252} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3653 import("//build/config/ios/ios_sdk.gni")
54 import("//build/config/ios/ios_test_runner_wrapper.gni")
55 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3256} else {
Dirk Pranke31e346e2020-07-15 00:54:0657 import("//build/config/sanitizers/sanitizers.gni")
58 import("//build/util/generate_wrapper.gni")
59}
60
danakjebb9cc4d2022-03-04 21:30:1161template("mixed_test") {
62 assert(defined(invoker.target_type) && invoker.target_type != "")
63 target("mixed_${invoker.target_type}", target_name) {
64 forward_variables_from(invoker,
65 "*",
66 TESTONLY_AND_VISIBILITY + [ "target_type" ])
67 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
68 if (!defined(rs_configs)) {
69 rs_configs = []
70 }
71 rs_configs += [ "//build/rust:test" ]
72
danakjaa85aad2022-03-10 18:45:1073 # The crate_root is generated and should not be specified.
74 assert(!defined(rs_crate_root))
75 rs_generate_crate_root = true
76
danakjebb9cc4d2022-03-04 21:30:1177 # We could automatically add `rs_deps += [ "//testing/rust_gtest_interop" ]`
78 # if `rs_sources` is non-empty. But we don't automatically provide
79 # //testing/gtest either so it would be asymmetric and could break in that
80 # case. So, we act instead as if //testing/rust_gtest_interop is part of the
81 # //testing/gtest dependency. If you add one, and have `rs_sources` listed,
82 # you get both.
83 _gtest_is_in_deps = false
84 if (defined(rs_sources) && rs_sources != [] && defined(deps) &&
85 deps != []) {
86 foreach(dep, deps) {
87 if (dep == "//testing/gtest") {
88 _gtest_is_in_deps = true
89 }
90 }
91 }
92 if (_gtest_is_in_deps) {
93 if (!defined(rs_deps)) {
94 rs_deps = []
95 }
96 rs_deps += [ "//testing/rust_gtest_interop" ]
97 }
98 }
99}
100
qsrfb5251d12015-01-21 15:57:22101# Define a test as an executable (or apk on Android) with the "testonly" flag
102# set.
agrieve62ab00282016-04-05 02:03:45103# Variable:
Dirk Pranke79d065d2020-08-29 03:28:30104# use_xvfb: (optional) whether to run the executable under Xvfb.
danakj02dddc42022-02-11 23:24:30105# use_raw_android_executable: Use mixed_executable() rather than
106# android_apk().
ynovikov389d9e442016-05-27 02:34:56107# use_native_activity: Test implements ANativeActivity_onCreate().
Greg Thompson26516592021-12-16 08:34:45108# use_cfv2: (Fuchsia, optional): build the test as a framework v2 component;
109# see https://fuchsia.dev/fuchsia-src/concepts/components/v2 for details.
Greg Thompson9765eeb42022-04-05 12:30:35110# The default value is true; set it to false explicitly to omit a .cm
111# manifest from the package.
112# use_cfv1: (Fuchsia, optional): build the test as a framework v1 component.
113# The default value is true; set it to false explicitly to omit a .cmx
114# manifest from the package.
Greg Thompson318cd692022-03-28 08:12:06115# test_runner_shard: (Fuchsia, optional): for CFv2 tests, use the given test
116# runner shard rather than the default shard for the ELF runner. This is
117# useful, for example, to use the elf_test_ambient_exec_runner for tests
118# that require job_policy_ambient_mark_vmo_exec.
Mirko Bonadei15522bc2020-09-16 20:38:39119# is_xctest: (iOS, optional) whether to build the executable as XCTest.
120# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
121# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:43122# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
123# network requests during the test.
qsrfb5251d12015-01-21 15:57:22124template("test") {
Greg Guterman6963dc082021-04-07 05:20:59125 # Ensures the rts file exists and if not, creates a dummy file
126 if (use_rts) {
127 action("${target_name}__rts_filters") {
128 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53129 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:59130 args = [ rebase_path(rts_file, root_build_dir) ]
131 outputs = [ rts_file ]
132 }
133 }
134
Andrew Grieve1b290e4a22020-11-24 20:07:01135 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:39136 if (!is_ios) {
137 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
138 "is_xctest can be set only for iOS builds")
139 }
Stefano Duo4128b6b2021-08-02 21:24:43140 if (!is_android) {
141 assert(!defined(invoker.allow_cleartext_traffic),
142 "allow_cleartext_traffic can be set only for Android tests")
143 }
144
qsrfb5251d12015-01-21 15:57:22145 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:30146 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
147
Peter Kotwicz10742f82021-04-15 22:32:50148 _use_default_launcher =
149 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
150 if (!defined(invoker.use_raw_android_executable)) {
151 # Checkouts where build_with_chromium == false often have a custom GN
152 # template wrapper around test() which sets use_default_launcher == false.
153 # Set the _use_raw_android_executable default so that test() targets which
154 # do not use the custom wrapper
155 # (1) Do not cause "gn gen" to fail
156 # (2) Do not need to be moved into if(build_with_chromium) block.
157 _use_raw_android_executable =
158 !build_with_chromium && _use_default_launcher
159 } else {
160 not_needed([ "_use_default_launcher" ])
161 _use_raw_android_executable = invoker.use_raw_android_executable
162 }
qsrfb5251d12015-01-21 15:57:22163
agrieve67855de2016-03-30 14:46:01164 # output_name is used to allow targets with the same name but in different
165 # packages to still produce unique runner scripts.
166 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26167 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01168 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26169 }
agrieve62ab00282016-04-05 02:03:45170
agrieveb355ad152016-04-19 03:45:23171 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42172 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:51173 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42174 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51175 ]
agrieve3ac557f02016-04-12 15:52:00176
jbudorickced2a252016-06-09 16:38:54177 assert(_use_raw_android_executable || enable_java_templates)
178
agrieve62ab00282016-04-05 02:03:45179 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49180 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
181
agrieve62ab00282016-04-05 02:03:45182 _exec_target = "${target_name}__exec"
183 _dist_target = "${target_name}__dist"
184 _exec_output =
185 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
186
danakjebb9cc4d2022-03-04 21:30:11187 mixed_test(_exec_target) {
188 target_type = "executable"
189
danakje94f40d2022-02-16 18:13:53190 # Configs will always be defined since we set_defaults in
191 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45192 configs = []
Dirk Pranke19a58732021-03-24 22:26:22193 forward_variables_from(
194 invoker,
195 "*",
196 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
197 "data_deps",
198 "extra_dist_files",
199 ])
agrieve62ab00282016-04-05 02:03:45200
201 # Thanks to the set_defaults() for test(), configs are initialized with
202 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59203 configs -= [
204 "//build/config:shared_library_config",
205 "//build/config/android:hide_all_but_jni",
206 ]
agrieve62ab00282016-04-05 02:03:45207 configs += [ "//build/config:executable_config" ]
208
Dirk Pranke19a58732021-03-24 22:26:22209 if (defined(invoker.data_deps)) {
210 data_deps = invoker.data_deps
211 } else {
212 data_deps = []
213 }
214 if (!defined(data)) {
215 data = []
216 }
Jamie Madilldd60ee62021-04-13 19:25:52217 if (tests_have_location_tags) {
218 data += [ "//testing/location_tags.json" ]
219 }
Dirk Pranke19a58732021-03-24 22:26:22220
agrieve62ab00282016-04-05 02:03:45221 # Don't output to the root or else conflict with the group() below.
222 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11223
224 if (use_rts) {
225 data_deps += [ ":${invoker.target_name}__rts_filters" ]
226 }
agrieve62ab00282016-04-05 02:03:45227 }
228
229 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45230 dist_dir = "$root_out_dir/$target_name"
231 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22232 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45233 if (defined(invoker.extra_dist_files)) {
234 extra_files = invoker.extra_dist_files
235 }
Greg Guterman50ed4b42021-04-08 01:15:11236
237 if (use_rts) {
238 if (!defined(data_deps)) {
239 data_deps = []
240 }
241 data_deps += [ ":${invoker.target_name}__rts_filters" ]
242 }
agrieve62ab00282016-04-05 02:03:45243 }
244 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02245 _library_target = "${target_name}__library"
danakj98e073722022-02-24 21:01:49246 _library_crate_name = "${target_name}_library"
Andrew Grievec61b8dff2019-10-21 16:32:02247 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45248 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43249 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45250 "android_manifest",
agrievec6811b422016-06-23 02:25:09251 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27252 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55253 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45254 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50255 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07256 "product_config_java_packages",
Andrew Grieve43f24fd02022-04-06 23:04:04257 "loadable_modules",
258 "loadable_module_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02259 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07260 "proguard_configs",
261 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45262 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02263 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45264 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56265 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45266 ]
Siddhartha764226b2018-03-13 02:32:55267
268 # Adds the unwind tables from unstripped binary as an asset file in the
269 # apk, if |add_unwind_tables_in_apk| is specified by the test.
270 if (defined(invoker.add_unwind_tables_in_apk) &&
271 invoker.add_unwind_tables_in_apk) {
Charlie Hud98dc692021-12-08 01:01:02272 if (use_android_unwinder_v2) {
Charlie Hu1481dd22022-04-12 19:06:00273 _unwind_table_asset_v2_name = "${target_name}_v2_unwind_assets"
274 unwind_table_asset_v2(_unwind_table_asset_v2_name) {
Charlie Hud98dc692021-12-08 01:01:02275 library_target = _library_target
276 deps = [ ":$_library_target" ]
277 }
Charlie Hu1481dd22022-04-12 19:06:00278 }
279
280 # TODO(crbug.com/1315603): Remove generation of v1 unwind asset when
281 # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroidV2`.
282 _unwind_table_asset_name = "${target_name}_unwind_assets"
283 unwind_table_asset(_unwind_table_asset_name) {
284 library_target = _library_target
285 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55286 }
287 }
288
danakjebb9cc4d2022-03-04 21:30:11289 mixed_test(_library_target) {
290 target_type = "shared_library"
291
danakj98e073722022-02-24 21:01:49292 # Configs will always be defined since we set_defaults in
293 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45294 configs = [] # Prevent list overwriting warning.
295 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45296
danakjebb9cc4d2022-03-04 21:30:11297 # Use a crate name that avoids creating a warning due to double
298 # underscore (ie. `__`).
danakj98e073722022-02-24 21:01:49299 rs_crate_name = _library_crate_name
danakj98e073722022-02-24 21:01:49300
jbudorickd29ecfa72016-11-18 22:45:42301 forward_variables_from(
302 invoker,
303 "*",
Peter Wen2052bd12020-12-03 20:15:07304 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
305 TESTONLY_AND_VISIBILITY)
306
307 # Native targets do not need to depend on java targets. Filter them out
308 # so that the shared library can be built without needing to wait for
309 # dependent java targets.
310 deps = []
311 if (defined(invoker.deps)) {
312 foreach(_dep, invoker.deps) {
313 _target_label = get_label_info(_dep, "label_no_toolchain")
314 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
315 deps += [ _dep ]
316 }
317 }
318 }
agrieve62ab00282016-04-05 02:03:45319
Peter Kotwiczb9957d62021-04-12 21:09:43320 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37321 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45322 }
323 }
324 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54325 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07326 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45327 apk_name = invoker.target_name
328 if (defined(invoker.output_name)) {
329 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45330 install_script_name = "install_${invoker.output_name}"
331 }
agrieveb355ad152016-04-19 03:45:23332
Daniel Bratellfdda4652019-01-31 15:45:54333 if (defined(invoker.deps)) {
334 deps = invoker.deps
335 } else {
336 deps = []
337 }
Andrew Grieve43f24fd02022-04-06 23:04:04338 if (defined(loadable_module_deps)) {
339 deps += loadable_module_deps
340 }
Daniel Bratellfdda4652019-01-31 15:45:54341
jcivellif4462a352017-01-10 04:45:59342 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43343 if (_use_default_launcher) {
344 deps += [ "//base/test:test_support_java" ]
345 }
jcivellif4462a352017-01-10 04:45:59346
Siddhartha764226b2018-03-13 02:32:55347 if (defined(_unwind_table_asset_name)) {
348 deps += [ ":${_unwind_table_asset_name}" ]
349 }
Greg Guterman50ed4b42021-04-08 01:15:11350
Charlie Hu05672742022-04-13 19:34:51351 if (defined(_unwind_table_asset_v2_name)) {
352 deps += [ ":${_unwind_table_asset_v2_name}" ]
353 }
354
Greg Guterman50ed4b42021-04-08 01:15:11355 if (use_rts) {
356 data_deps = [ ":${invoker.target_name}__rts_filters" ]
357 }
agrieve62ab00282016-04-05 02:03:45358 }
Andrew Grievee1dc23f2019-10-22 16:26:36359 }
agrieve62ab00282016-04-05 02:03:45360
Andrew Grievee1dc23f2019-10-22 16:26:36361 test_runner_script(_test_runner_target) {
362 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57363
Andrew Grievee1dc23f2019-10-22 16:26:36364 if (_use_raw_android_executable) {
365 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34366 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36367 } else {
368 apk_target = ":$_apk_target"
369 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47370
371 # Dep needed for the test runner .runtime_deps file to pick up data
372 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22373 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45374 }
Andrew Grievee1dc23f2019-10-22 16:26:36375 test_name = _output_name
376 test_suite = _output_name
377 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59378
379 if (use_rts) {
380 data_deps += [ ":${invoker.target_name}__rts_filters" ]
381 }
mikecase56d80d72015-06-03 00:57:26382 }
383
Andrew Grieve7ca6de32019-10-18 03:57:47384 # Create a wrapper script rather than using a group() in order to ensure
385 # "ninja $target_name" always works. If this was a group(), then GN would
386 # not create a top-level alias for it if a target exists in another
387 # directory with the same $target_name.
388 # Also - bots run this script directly for "components_perftests".
389 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01390 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47391 executable = "$root_build_dir/bin/run_$_output_name"
392 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22393 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40394 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47395 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40396 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47397 # Dep needed for the swarming .isolate file to pick up data
398 # deps from the forward_variables_from(invoker, "*") on the library.
399 deps += [
400 ":$_apk_target",
401 ":$_library_target",
402 ]
agrieve62ab00282016-04-05 02:03:45403 }
Dirk Pranke19a58732021-03-24 22:26:22404
405 if (defined(invoker.data_deps)) {
406 data_deps = invoker.data_deps
407 } else {
408 data_deps = []
409 }
Kevin Marshall23529362022-02-23 16:50:36410
411 data_deps += [ "//testing:test_scripts_shared" ]
412
Jamie Madilldd60ee62021-04-13 19:25:52413 if (tests_have_location_tags) {
414 data = [ "//testing/location_tags.json" ]
415 }
Greg Guterman6963dc082021-04-07 05:20:59416
417 if (use_rts) {
418 data_deps += [ ":${invoker.target_name}__rts_filters" ]
419 }
agrieve1a02e582015-10-15 21:35:39420 }
Scott Graham4c4cdc52017-05-29 20:45:03421 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30422 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
423
Greg Thompson9765eeb42022-04-05 12:30:35424 # It's meaningless to omit both types of manifest from the package.
425 assert(!defined(invoker.use_cfv2) || invoker.use_cfv2 ||
426 !defined(invoker.use_cfv1) || invoker.use_cfv1)
427
Scott Graham4c4cdc52017-05-29 20:45:03428 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42429 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42430 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb42022-04-05 12:30:35431 _program_name = get_label_info(":${_exec_target}", "name")
432 _test_component_targets = []
Scott Graham4c4cdc52017-05-29 20:45:03433
Greg Thompson9765eeb42022-04-05 12:30:35434 # Generate a CFv2 manifest unless the target opts-out via `use_cfv2=false`.
Greg Thompson5e4f41f2022-02-09 16:35:14435 if (!defined(invoker.use_cfv2) || invoker.use_cfv2) {
Greg Thompson26516592021-12-16 08:34:45436 # Generate a CML fragment that provides the program name.
437 _test_program_fragment_target = "${target_name}_program-fragment"
438 _test_program_fragment =
439 "${target_out_dir}/${target_name}_program.test-cml"
Greg Thompson26516592021-12-16 08:34:45440 generated_file(_test_program_fragment_target) {
Kevin Marshall2ec60032022-05-09 17:38:28441 contents = {
442 program = {
443 binary = _program_name
444 }
445 }
Greg Thompson26516592021-12-16 08:34:45446 outputs = [ _test_program_fragment ]
Kevin Marshall2ec60032022-05-09 17:38:28447 output_conversion = "json"
Greg Thompson26516592021-12-16 08:34:45448 }
449
Greg Thompson318cd692022-03-28 08:12:06450 _test_runner_shard =
451 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
452 if (defined(invoker.test_runner_shard)) {
453 _test_runner_shard = invoker.test_runner_shard
454 }
455
Greg Thompson26516592021-12-16 08:34:45456 # Collate the complete set of elements to include in the test component's
457 # manifest.
458 _manifest_fragments = [
Greg Thompson6cdcdb32022-01-31 11:12:44459 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
Greg Thompsonf31d7d22022-01-26 09:17:45460 "//build/config/fuchsia/test/minimum.shard.test-cml",
Greg Thompson26516592021-12-16 08:34:45461 _test_program_fragment,
Greg Thompson318cd692022-03-28 08:12:06462 _test_runner_shard,
Greg Thompson26516592021-12-16 08:34:45463 ]
464
465 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
466 _merged_manifest_name = "${_output_name}.cml"
Greg Thompson9765eeb42022-04-05 12:30:35467
468 if (defined(invoker.additional_manifest_fragments)) {
469 _manifest_fragments +=
470 filter_include(invoker.additional_manifest_fragments,
471 [
472 "*.cml",
473 "*.test-cml",
474 ])
475 }
476
477 # Generate the test component manifest from the specified elements.
478 _test_component_manifest_target = "${target_name}_component-manifest"
479 cmc_merge(_test_component_manifest_target) {
480 sources = _manifest_fragments
481 output_name = "${_merged_manifest_name}"
482 deps = [ ":${_test_program_fragment_target}" ]
483 }
484
485 # Define the test component, dependent on the generated manifest, and the
486 # test executable target.
487 _test_component_target = "${target_name}_component"
488 fuchsia_component(_test_component_target) {
489 deps = [ ":$_test_component_manifest_target" ]
490 data_deps = [ ":$_exec_target" ]
491 manifest = _test_component_manifest
492 visibility = [ ":*" ]
493 }
494
495 _test_component_targets += [ ":${_test_component_target}" ]
496 }
497
498 # Generate a CFv1 manifest unless the target opts-out via `use_cfv1=false`.
499 if (!defined(invoker.use_cfv1) || invoker.use_cfv1) {
Greg Thompson26516592021-12-16 08:34:45500 # Generate a CMX fragment that provides the program name.
Greg Thompson9765eeb42022-04-05 12:30:35501 _test_program_fragment_target_v1 = "${target_name}_program-fragment_v1"
502 _test_program_fragment_v1 =
Greg Thompson26516592021-12-16 08:34:45503 "${target_out_dir}/${target_name}_program.test-cmx"
Greg Thompson9765eeb42022-04-05 12:30:35504 generated_file(_test_program_fragment_target_v1) {
Greg Thompson26516592021-12-16 08:34:45505 contents = "{ \"program\": { \"binary\": \"${_program_name}\"}}"
Greg Thompson9765eeb42022-04-05 12:30:35506 outputs = [ _test_program_fragment_v1 ]
Greg Thompson26516592021-12-16 08:34:45507 }
508
509 # Collate the complete set of elements to include in the test component's
510 # manifest.
Greg Thompson9765eeb42022-04-05 12:30:35511 _manifest_fragments_v1 = [
Greg Thompson26516592021-12-16 08:34:45512 "//build/config/fuchsia/test/minimum_capabilities.test-cmx",
Greg Thompson9765eeb42022-04-05 12:30:35513 _test_program_fragment_v1,
Greg Thompson26516592021-12-16 08:34:45514 ]
515
Greg Thompson9765eeb42022-04-05 12:30:35516 _test_component_manifest_v1 = "${target_out_dir}/${target_name}.cmx"
517 _merged_manifest_name_v1 = "${_output_name}.cmx"
Chong Gu26908f4e2021-01-29 03:13:07518
Greg Thompson9765eeb42022-04-05 12:30:35519 if (defined(invoker.additional_manifest_fragments)) {
520 _manifest_fragments_v1 +=
521 filter_include(invoker.additional_manifest_fragments,
522 [
523 "*.cmx",
524 "*.test-cmx",
525 ])
526 }
Chong Gu28bf7e72021-05-26 01:36:19527
Greg Thompson9765eeb42022-04-05 12:30:35528 # Generate the test component manifest from the specified elements.
529 _test_component_manifest_target_v1 =
530 "${target_name}_component-manifest_v1"
531 cmc_merge(_test_component_manifest_target_v1) {
532 sources = _manifest_fragments_v1
533 output_name = "${_merged_manifest_name_v1}"
534 deps = [ ":${_test_program_fragment_target_v1}" ]
535 }
Chong Gu26908f4e2021-01-29 03:13:07536
Greg Thompson9765eeb42022-04-05 12:30:35537 # Define the test component, dependent on the generated manifest, and the
538 # test executable target.
539 _test_component_target_v1 = "${target_name}_component_v1"
540 fuchsia_component(_test_component_target_v1) {
541 deps = [ ":$_test_component_manifest_target_v1" ]
542 data_deps = [ ":$_exec_target" ]
543 manifest = _test_component_manifest_v1
544 visibility = [ ":*" ]
545 }
546
547 _test_component_targets += [ ":${_test_component_target_v1}" ]
Wez6879f8a2021-09-07 20:27:02548 }
549
550 # Define components for each entry in |additional_manifests|, if any. Since
551 # manifests may themselves depend-on the outputs of |deps|, these components
552 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02553 if (defined(invoker.additional_manifests)) {
554 foreach(filename, invoker.additional_manifests) {
555 _additional_component_target =
556 target_name + "_" + get_path_info(filename, "name")
557 _test_component_targets += [ ":${_additional_component_target}" ]
558 fuchsia_component(_additional_component_target) {
559 forward_variables_from(invoker, [ "testonly" ])
560 data_deps = [ ":$_exec_target" ]
561 visibility = [ ":*" ]
562 manifest = filename
563
564 # Depend on |invoker.deps|, in case it includes a dependency that
565 # creates this additional component's manifest.
566 if (defined(invoker.deps)) {
567 deps = invoker.deps
568 }
569 }
570 }
571 }
572
573 # Define the package target that will bundle the test and additional
574 # components and their data.
575 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21576 forward_variables_from(invoker,
577 [
578 "excluded_files",
579 "excluded_dirs",
580 ])
Wez6879f8a2021-09-07 20:27:02581 package_name = _output_name
582 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21583
584 if (!defined(excluded_dirs)) {
585 excluded_dirs = []
586 }
Sarah Pham80972efc2022-05-31 17:40:15587 if (devtools_root_location != "") {
588 excluded_dirs += [ devtools_root_location ]
589 }
Wez6879f8a2021-09-07 20:27:02590 }
591
592 # |target_name| refers to the package-runner rule, so that building
593 # "base_unittests" will build not only the executable, component, and
594 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25595 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53596 forward_variables_from(invoker,
597 [
Kevin Marshall5fadadd2021-10-16 00:08:25598 "data",
599 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53600 "package_deps",
Greg Thompson26516592021-12-16 08:34:45601 "use_cfv2",
Kevin Marshall5fadadd2021-10-16 00:08:25602 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53603 ])
Kevin Marshall5fadadd2021-10-16 00:08:25604
Chong Guc6bfdf62021-10-20 23:37:00605 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15606 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25607 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42608
Kevin Marshall5fadadd2021-10-16 00:08:25609 if (!defined(deps)) {
610 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52611 }
Kevin Marshall5fadadd2021-10-16 00:08:25612 if (defined(invoker.deps)) {
613 deps += invoker.deps
614 }
Greg Guterman6963dc082021-04-07 05:20:59615
Kevin Marshall5fadadd2021-10-16 00:08:25616 if (!defined(data)) {
617 data = []
618 }
619 if (tests_have_location_tags) {
620 data += [ "//testing/location_tags.json" ]
621 }
622
623 if (!defined(data_deps)) {
624 data_deps = []
625 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28626
Kevin Marshall23529362022-02-23 16:50:36627 data_deps += [ "//testing:test_scripts_shared" ]
628
Benjamin Lerman5e3cb3362022-01-25 16:46:28629 # TODO(crbug.com/1199334): Because perfetto unit test is defined outside
630 # of chromium, the dependency to the filter file is added here.
631 data_deps += [ "//testing/buildbot/filters:perfetto_unittests_filters" ]
Chong Gu258e22c2021-10-20 18:39:50632
Greg Guterman6963dc082021-04-07 05:20:59633 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25634 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59635 }
Kevin Marshallf35fa5f2018-01-29 19:24:42636 }
637
danakjebb9cc4d2022-03-04 21:30:11638 mixed_test(_exec_target) {
639 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01640 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42641 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03642 }
dpranke2a294622015-08-07 05:23:01643 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30644 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46645 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30646
Rohit Raof9b096d2019-09-09 22:26:23647 declare_args() {
648 # Keep the unittest-as-xctest functionality defaulted to off until the
649 # bots are updated to handle it properly.
650 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
651 # supports running unittests with xctest.
652 enable_run_ios_unittests_with_xctest = false
653 }
654
sdefresne012857872016-03-16 10:55:37655 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27656 _output_name = target_name
657 if (defined(invoker.output_name)) {
658 _output_name = invoker.output_name
659 }
660
Jeff Yoonf7f4eb42020-03-06 18:55:36661 _wrapper_output_name = "run_${target_name}"
662 ios_test_runner_wrapper(_wrapper_output_name) {
663 forward_variables_from(invoker,
664 [
665 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36666 "deps",
667 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27668 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36669 "retries",
670 "shards",
671 ])
672
673 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
674
675 if (!defined(executable_args)) {
676 executable_args = []
677 }
678 executable_args += [
679 "--app",
680 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
681 ]
682
683 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22684
685 if (!defined(data)) {
686 data = []
687 }
Jamie Madilldd60ee62021-04-13 19:25:52688 if (tests_have_location_tags) {
689 data += [ "//testing/location_tags.json" ]
690 }
Jeff Yoonf7f4eb42020-03-06 18:55:36691 }
692
sdefresne012857872016-03-16 10:55:37693 _resources_bundle_data = target_name + "_resources_bundle_data"
694
695 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34696 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22697 sources = [ "//testing/gtest_ios/Default.png" ]
698 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01699 }
700
Mirko Bonadei15522bc2020-09-16 20:38:39701 force_xctest = enable_run_ios_unittests_with_xctest ||
702 (defined(invoker.is_xctest) && invoker.is_xctest)
703
704 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23705 ios_test_target_type = "ios_xctest_test"
706 } else {
707 ios_test_target_type = "ios_app_bundle"
708 }
709
710 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01711 testonly = true
sdefresnea828c282016-05-30 18:04:20712
Mirko Bonadei15522bc2020-09-16 20:38:39713 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23714 xctest_module_target = "//base/test:google_test_runner"
715 }
716
Andrew Grieve1b290e4a22020-11-24 20:07:01717 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13718
719 # Provide sensible defaults in case invoker did not define any of those
720 # required variables.
sdefresne05b97ca2016-06-08 07:19:46721 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13722 info_plist = "//testing/gtest_ios/unittest-Info.plist"
723 }
sdefresne9e147e02016-06-07 00:10:13724
Sylvain Defresne3c5a1312021-09-23 17:08:09725 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13726 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50727 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09728 } else {
Ali Juma75be0fe2022-01-24 19:39:29729 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27730 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09731 }
dpranke2a294622015-08-07 05:23:01732
sdefresne047490e2016-07-22 08:49:34733 if (!defined(bundle_deps)) {
734 bundle_deps = []
735 }
736 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36737
738 if (!defined(data_deps)) {
739 data_deps = []
740 }
741
Kevin Marshall23529362022-02-23 16:50:36742 data_deps += [ "//testing:test_scripts_shared" ]
743
Jeff Yoonf7f4eb42020-03-06 18:55:36744 # Include the generate_wrapper as part of data_deps
745 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46746 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59747
748 if (use_rts) {
749 data_deps += [ ":${invoker.target_name}__rts_filters" ]
750 }
dpranke2a294622015-08-07 05:23:01751 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11752 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
753 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30754 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
755
Yuke Liao2a9b2f0e2021-04-16 00:40:11756 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32757
Benjamin Pastene3bce864e2018-04-14 01:16:32758 _gen_runner_target = "${target_name}__runner"
759 _runtime_deps_file =
760 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
761 "/" + get_label_info(target_name, "name") + ".runtime_deps"
762
Xinan Lin6be01252021-06-25 23:07:36763 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
764 if (is_skylab) {
Struan Shrimptonf61293f62022-04-11 19:33:40765 generate_skylab_deps(_gen_runner_target) {
Xinan Lin6be01252021-06-25 23:07:36766 generated_script = _generated_script
767 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34768 }
Xinan Lin6be01252021-06-25 23:07:36769 } else {
770 generate_runner_script(_gen_runner_target) {
771 generated_script = _generated_script
772 test_exe = invoker.target_name
773 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34774
Xinan Lin6be01252021-06-25 23:07:36775 if (is_chromeos_lacros) {
776 # At build time, Lacros tests don't know whether they'll run on VM or
777 # HW, and instead, these flags are specified at runtime when invoking
778 # the generated runner script.
779 skip_generating_board_args = true
780 }
Greg Guterman6963dc082021-04-07 05:20:59781
Xinan Lin6be01252021-06-25 23:07:36782 if (tests_have_location_tags) {
783 data = [ "//testing/location_tags.json" ]
784 }
785
786 if (use_rts) {
787 data_deps = [ ":${invoker.target_name}__rts_filters" ]
788 }
Greg Guterman6963dc082021-04-07 05:20:59789 }
Benjamin Pastene3bce864e2018-04-14 01:16:32790 }
791
danakjebb9cc4d2022-03-04 21:30:11792 mixed_test(target_name) {
793 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01794 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
795 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32796 if (!defined(deps)) {
797 deps = []
798 }
799 if (!defined(data)) {
800 data = []
801 }
802
Ben Pastene41041782019-02-16 04:21:58803 # We use a special trigger script for CrOS hardware tests.
804 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
805
Benjamin Pastene3bce864e2018-04-14 01:16:32806 output_name = target_name
807 write_runtime_deps = _runtime_deps_file
808 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37809 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59810
Kevin Marshall23529362022-02-23 16:50:36811 if (!defined(data_deps)) {
812 data_deps = []
813 }
814
815 data_deps += [ "//testing:test_scripts_shared" ]
816
Greg Guterman6963dc082021-04-07 05:20:59817 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59818 data_deps += [ ":${invoker.target_name}__rts_filters" ]
819 }
Benjamin Pastene3bce864e2018-04-14 01:16:32820 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11821 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24822 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
823 _executable = target_name
824 _gen_runner_target = "${target_name}__runner"
825
Yuke Liao32af4242020-07-16 21:48:02826 if (defined(invoker.use_xvfb)) {
827 _use_xvfb = invoker.use_xvfb
828 } else {
829 _use_xvfb = false
830 }
831
Yuke Liaod037abc2020-10-06 22:48:22832 # When use_xvfb is set by the invoker, it indicates that running this test
833 # target requires a window, and in lacros build, ash-chrome serves as the
834 # display server. Note that even though the tests themselves do not require
835 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
836 # because ash-chrome is based on x11.
837 _use_ash_chrome = _use_xvfb
838
Yuke Liaoe703384b2020-07-16 01:05:24839 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24840 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02841
Yuke Liao2e4953cf2020-07-26 19:20:19842 data = []
Will Harrisd35e2c92021-04-07 01:42:02843 data_deps = [ "//testing:test_scripts_shared" ]
844
Yuke Liao32af4242020-07-16 21:48:02845 if (_use_xvfb) {
846 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22847 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02848 } else {
849 executable = "//testing/test_env.py"
850 }
Jamie Madilldd60ee62021-04-13 19:25:52851 if (tests_have_location_tags) {
852 data += [ "//testing/location_tags.json" ]
853 }
Yuke Liao32af4242020-07-16 21:48:02854
Yuke Liaoe703384b2020-07-16 01:05:24855 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02856 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39857 "test",
Yuke Liaoe703384b2020-07-16 01:05:24858 "@WrappedPath(./${_executable})",
859 "--test-launcher-bot-mode",
860 ]
Yuke Liao32af4242020-07-16 21:48:02861
Yuke Liaof540c742020-07-29 16:28:34862 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37863 executable_args += [ "--ash-chrome-path" ]
864
865 # Can't use --ash-chrome-path=path because WrappedPath
866 # won't be expanded for that usage.
867 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39868 }
869
Yuke Liaoe703384b2020-07-16 01:05:24870 if (is_asan) {
871 executable_args += [ "--asan=true" ]
872 }
873 if (is_msan) {
874 executable_args += [ "--msan=true" ]
875 }
876 if (is_tsan) {
877 executable_args += [ "--tsan=true" ]
878 }
879 if (use_cfi_diag) {
880 executable_args += [ "--cfi-diag=true" ]
881 }
882
Takuto Ikuta38ebd0e2022-01-19 17:56:22883 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59884
885 if (use_rts) {
886 data_deps += [ ":${invoker.target_name}__rts_filters" ]
887 }
Yuke Liaoe703384b2020-07-16 01:05:24888 }
889
danakjebb9cc4d2022-03-04 21:30:11890 mixed_test(target_name) {
891 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01892 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
893 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24894 if (!defined(deps)) {
895 deps = []
896 }
897
Yuke Liaod037abc2020-10-06 22:48:22898 if (!defined(data_deps)) {
899 data_deps = []
900 }
901
Kevin Marshall23529362022-02-23 16:50:36902 data_deps += [ "//testing:test_scripts_shared" ]
903
Yuke Liaoe703384b2020-07-16 01:05:24904 write_runtime_deps = _runtime_deps_file
905 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22906 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56907 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22908 }
Greg Guterman6963dc082021-04-07 05:20:59909
910 if (use_rts) {
911 data_deps += [ ":${invoker.target_name}__rts_filters" ]
912 }
Yuke Liaoe703384b2020-07-16 01:05:24913 }
Dirk Prankedd4ff742020-11-18 19:57:32914 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30915 if (is_mac || is_win) {
916 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
917 }
918
Dirk Prankedd4ff742020-11-18 19:57:32919 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
920 _executable = target_name
921 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06922
Dirk Prankedd4ff742020-11-18 19:57:32923 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
924 _use_xvfb = invoker.use_xvfb
925 } else {
926 _use_xvfb = false
927 }
928
929 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32930 wrapper_script = "$root_build_dir/bin/run_" + _executable
931
932 data = []
Will Harrisd35e2c92021-04-07 01:42:02933 data_deps = [ "//testing:test_scripts_shared" ]
934
Dirk Prankedd4ff742020-11-18 19:57:32935 if (_use_xvfb) {
936 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06937 } else {
Dirk Prankedd4ff742020-11-18 19:57:32938 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06939 }
Jamie Madilldd60ee62021-04-13 19:25:52940 if (tests_have_location_tags) {
941 data += [ "//testing/location_tags.json" ]
942 }
Dirk Pranke31e346e2020-07-15 00:54:06943
Dirk Prankedd4ff742020-11-18 19:57:32944 executable_args = [
945 "@WrappedPath(./${_executable})",
946 "--test-launcher-bot-mode",
947 ]
948 if (is_asan) {
949 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06950 }
Dirk Prankedd4ff742020-11-18 19:57:32951 if (is_msan) {
952 executable_args += [ "--msan=true" ]
953 }
954 if (is_tsan) {
955 executable_args += [ "--tsan=true" ]
956 }
957 if (use_cfi_diag) {
958 executable_args += [ "--cfi-diag=true" ]
959 }
960
Greg Guterman6963dc082021-04-07 05:20:59961 if (use_rts) {
962 data_deps += [ ":${invoker.target_name}__rts_filters" ]
963 }
Dirk Pranke31e346e2020-07-15 00:54:06964 }
965
danakjebb9cc4d2022-03-04 21:30:11966 mixed_test(target_name) {
967 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01968 forward_variables_from(invoker,
969 "*",
970 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
971 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06972 if (!defined(deps)) {
973 deps = []
974 }
975
Dirk Pranke31e346e2020-07-15 00:54:06976 deps += [
977 # Give tests the default manifest on Windows (a no-op elsewhere).
978 "//build/win:default_exe_manifest",
979 ]
980
Dirk Prankedd4ff742020-11-18 19:57:32981 write_runtime_deps = _runtime_deps_file
982 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11983
Kevin Marshall23529362022-02-23 16:50:36984 if (!defined(data_deps)) {
985 data_deps = []
986 }
987
988 data_deps += [ "//testing:test_scripts_shared" ]
989
Greg Guterman50ed4b42021-04-08 01:15:11990 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:11991 data_deps += [ ":${invoker.target_name}__rts_filters" ]
992 }
Dirk Prankedd4ff742020-11-18 19:57:32993 }
994 } else {
995 # This is a catch-all clause for NaCl toolchains and other random
996 # configurations that might define tests; test() in these configs
997 # will just define the underlying executables.
998 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
999 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:111000 mixed_test(target_name) {
1001 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011002 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1003 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:321004 if (!defined(deps)) {
1005 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061006 }
Greg Guterman6963dc082021-04-07 05:20:591007
Kevin Marshall23529362022-02-23 16:50:361008 if (!defined(data_deps)) {
1009 data_deps = []
1010 }
1011
1012 data_deps += [ "//testing:test_scripts_shared" ]
1013
Greg Guterman6963dc082021-04-07 05:20:591014 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:591015 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1016 }
Dirk Pranke31e346e2020-07-15 00:54:061017 }
qsrfb5251d12015-01-21 15:57:221018 }
1019}
brettwedb6ecc2016-07-14 23:37:031020
Dirk Pranke6188075b2020-10-01 19:31:281021# Defines a type of test that invokes a script to run, rather than
1022# invoking an executable.
1023#
1024# The script must implement the
1025# [test executable API](//docs/testing/test_executable_api.md).
1026#
1027# The template must be passed the `script` parameter, which specifies
1028# the path to the script to run. It may optionally be passed a
1029# `script_args` parameter, which can be used to include a list of
1030# args to be specified by default. The template will produce
1031# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
1032# for the target to $root_build_dir/${target_name}.runtime_deps, as per
1033# the conventions listed in the
1034# [test wrapper API](//docs/testing/test_wrapper_api.md).
1035template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:591036 if (use_rts) {
1037 action("${target_name}__rts_filters") {
1038 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:531039 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:591040 args = [ rebase_path(rts_file, root_build_dir) ]
1041 outputs = [ rts_file ]
1042 }
1043 }
1044
Dirk Pranke6188075b2020-10-01 19:31:281045 generate_wrapper(target_name) {
1046 testonly = true
1047 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1048
1049 executable = "//testing/test_env.py"
1050
1051 executable_args =
1052 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1053 if (defined(invoker.args)) {
1054 executable_args += invoker.args
1055 }
1056
Will Harrisd35e2c92021-04-07 01:42:021057 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471058
Dirk Pranke6188075b2020-10-01 19:31:281059 if (defined(invoker.data)) {
1060 data += invoker.data
1061 }
Jamie Madilldd60ee62021-04-13 19:25:521062 if (tests_have_location_tags) {
1063 data += [ "//testing/location_tags.json" ]
1064 }
Dirk Pranke19a58732021-03-24 22:26:221065
Will Harrisd35e2c92021-04-07 01:42:021066 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281067 if (defined(invoker.data_deps)) {
1068 data_deps += invoker.data_deps
1069 }
1070
1071 forward_variables_from(invoker,
1072 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:011073 TESTONLY_AND_VISIBILITY + [
1074 "data",
1075 "data_deps",
1076 "script",
1077 "script_args",
1078 ])
1079 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281080
1081 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591082
1083 if (use_rts) {
1084 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1085 }
Dirk Pranke6188075b2020-10-01 19:31:281086 }
1087}
1088
brettwedb6ecc2016-07-14 23:37:031089# Test defaults.
1090set_defaults("test") {
1091 if (is_android) {
1092 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411093 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591094 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:031095 } else {
1096 configs = default_executable_configs
Leonard Grey077a28302021-12-16 14:14:261097 if (is_mac) {
1098 # TODO(lgrey): Maybe restore this.
1099 # Don't strip tests for visibility into test crashes/hangs.
1100 # https://bugs.chromium.org/p/chromium/issues/detail?id=1244047#c49
1101 configs -= [ "//build/config/mac:strip_all" ]
1102 }
brettwedb6ecc2016-07-14 23:37:031103 }
1104}