blob: 01443447562494ca51aad16f6566a9b06d436d88 [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
351 if (use_rts) {
352 data_deps = [ ":${invoker.target_name}__rts_filters" ]
353 }
agrieve62ab00282016-04-05 02:03:45354 }
Andrew Grievee1dc23f2019-10-22 16:26:36355 }
agrieve62ab00282016-04-05 02:03:45356
Andrew Grievee1dc23f2019-10-22 16:26:36357 test_runner_script(_test_runner_target) {
358 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57359
Andrew Grievee1dc23f2019-10-22 16:26:36360 if (_use_raw_android_executable) {
361 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34362 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36363 } else {
364 apk_target = ":$_apk_target"
365 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47366
367 # Dep needed for the test runner .runtime_deps file to pick up data
368 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22369 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45370 }
Andrew Grievee1dc23f2019-10-22 16:26:36371 test_name = _output_name
372 test_suite = _output_name
373 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59374
375 if (use_rts) {
376 data_deps += [ ":${invoker.target_name}__rts_filters" ]
377 }
mikecase56d80d72015-06-03 00:57:26378 }
379
Andrew Grieve7ca6de32019-10-18 03:57:47380 # Create a wrapper script rather than using a group() in order to ensure
381 # "ninja $target_name" always works. If this was a group(), then GN would
382 # not create a top-level alias for it if a target exists in another
383 # directory with the same $target_name.
384 # Also - bots run this script directly for "components_perftests".
385 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01386 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47387 executable = "$root_build_dir/bin/run_$_output_name"
388 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22389 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40390 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47391 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40392 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47393 # Dep needed for the swarming .isolate file to pick up data
394 # deps from the forward_variables_from(invoker, "*") on the library.
395 deps += [
396 ":$_apk_target",
397 ":$_library_target",
398 ]
agrieve62ab00282016-04-05 02:03:45399 }
Dirk Pranke19a58732021-03-24 22:26:22400
401 if (defined(invoker.data_deps)) {
402 data_deps = invoker.data_deps
403 } else {
404 data_deps = []
405 }
Kevin Marshall23529362022-02-23 16:50:36406
407 data_deps += [ "//testing:test_scripts_shared" ]
408
Jamie Madilldd60ee62021-04-13 19:25:52409 if (tests_have_location_tags) {
410 data = [ "//testing/location_tags.json" ]
411 }
Greg Guterman6963dc082021-04-07 05:20:59412
413 if (use_rts) {
414 data_deps += [ ":${invoker.target_name}__rts_filters" ]
415 }
agrieve1a02e582015-10-15 21:35:39416 }
Scott Graham4c4cdc52017-05-29 20:45:03417 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30418 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
419
Greg Thompson9765eeb42022-04-05 12:30:35420 # It's meaningless to omit both types of manifest from the package.
421 assert(!defined(invoker.use_cfv2) || invoker.use_cfv2 ||
422 !defined(invoker.use_cfv1) || invoker.use_cfv1)
423
Scott Graham4c4cdc52017-05-29 20:45:03424 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42425 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42426 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb42022-04-05 12:30:35427 _program_name = get_label_info(":${_exec_target}", "name")
428 _test_component_targets = []
Scott Graham4c4cdc52017-05-29 20:45:03429
Greg Thompson9765eeb42022-04-05 12:30:35430 # Generate a CFv2 manifest unless the target opts-out via `use_cfv2=false`.
Greg Thompson5e4f41f2022-02-09 16:35:14431 if (!defined(invoker.use_cfv2) || invoker.use_cfv2) {
Greg Thompson26516592021-12-16 08:34:45432 # Generate a CML fragment that provides the program name.
433 _test_program_fragment_target = "${target_name}_program-fragment"
434 _test_program_fragment =
435 "${target_out_dir}/${target_name}_program.test-cml"
Greg Thompson26516592021-12-16 08:34:45436 generated_file(_test_program_fragment_target) {
437 contents = "{ program: { binary: \"${_program_name}\",},}"
438 outputs = [ _test_program_fragment ]
439 }
440
Greg Thompson318cd692022-03-28 08:12:06441 _test_runner_shard =
442 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
443 if (defined(invoker.test_runner_shard)) {
444 _test_runner_shard = invoker.test_runner_shard
445 }
446
Greg Thompson26516592021-12-16 08:34:45447 # Collate the complete set of elements to include in the test component's
448 # manifest.
449 _manifest_fragments = [
Greg Thompson6cdcdb32022-01-31 11:12:44450 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
Greg Thompsonf31d7d22022-01-26 09:17:45451 "//build/config/fuchsia/test/minimum.shard.test-cml",
Greg Thompson26516592021-12-16 08:34:45452 _test_program_fragment,
Greg Thompson318cd692022-03-28 08:12:06453 _test_runner_shard,
Greg Thompson26516592021-12-16 08:34:45454 ]
455
456 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
457 _merged_manifest_name = "${_output_name}.cml"
Greg Thompson9765eeb42022-04-05 12:30:35458
459 if (defined(invoker.additional_manifest_fragments)) {
460 _manifest_fragments +=
461 filter_include(invoker.additional_manifest_fragments,
462 [
463 "*.cml",
464 "*.test-cml",
465 ])
466 }
467
468 # Generate the test component manifest from the specified elements.
469 _test_component_manifest_target = "${target_name}_component-manifest"
470 cmc_merge(_test_component_manifest_target) {
471 sources = _manifest_fragments
472 output_name = "${_merged_manifest_name}"
473 deps = [ ":${_test_program_fragment_target}" ]
474 }
475
476 # Define the test component, dependent on the generated manifest, and the
477 # test executable target.
478 _test_component_target = "${target_name}_component"
479 fuchsia_component(_test_component_target) {
480 deps = [ ":$_test_component_manifest_target" ]
481 data_deps = [ ":$_exec_target" ]
482 manifest = _test_component_manifest
483 visibility = [ ":*" ]
484 }
485
486 _test_component_targets += [ ":${_test_component_target}" ]
487 }
488
489 # Generate a CFv1 manifest unless the target opts-out via `use_cfv1=false`.
490 if (!defined(invoker.use_cfv1) || invoker.use_cfv1) {
Greg Thompson26516592021-12-16 08:34:45491 # Generate a CMX fragment that provides the program name.
Greg Thompson9765eeb42022-04-05 12:30:35492 _test_program_fragment_target_v1 = "${target_name}_program-fragment_v1"
493 _test_program_fragment_v1 =
Greg Thompson26516592021-12-16 08:34:45494 "${target_out_dir}/${target_name}_program.test-cmx"
Greg Thompson9765eeb42022-04-05 12:30:35495 generated_file(_test_program_fragment_target_v1) {
Greg Thompson26516592021-12-16 08:34:45496 contents = "{ \"program\": { \"binary\": \"${_program_name}\"}}"
Greg Thompson9765eeb42022-04-05 12:30:35497 outputs = [ _test_program_fragment_v1 ]
Greg Thompson26516592021-12-16 08:34:45498 }
499
500 # Collate the complete set of elements to include in the test component's
501 # manifest.
Greg Thompson9765eeb42022-04-05 12:30:35502 _manifest_fragments_v1 = [
Greg Thompson26516592021-12-16 08:34:45503 "//build/config/fuchsia/test/minimum_capabilities.test-cmx",
Greg Thompson9765eeb42022-04-05 12:30:35504 _test_program_fragment_v1,
Greg Thompson26516592021-12-16 08:34:45505 ]
506
Greg Thompson9765eeb42022-04-05 12:30:35507 _test_component_manifest_v1 = "${target_out_dir}/${target_name}.cmx"
508 _merged_manifest_name_v1 = "${_output_name}.cmx"
Chong Gu26908f4e2021-01-29 03:13:07509
Greg Thompson9765eeb42022-04-05 12:30:35510 if (defined(invoker.additional_manifest_fragments)) {
511 _manifest_fragments_v1 +=
512 filter_include(invoker.additional_manifest_fragments,
513 [
514 "*.cmx",
515 "*.test-cmx",
516 ])
517 }
Chong Gu28bf7e72021-05-26 01:36:19518
Greg Thompson9765eeb42022-04-05 12:30:35519 # Generate the test component manifest from the specified elements.
520 _test_component_manifest_target_v1 =
521 "${target_name}_component-manifest_v1"
522 cmc_merge(_test_component_manifest_target_v1) {
523 sources = _manifest_fragments_v1
524 output_name = "${_merged_manifest_name_v1}"
525 deps = [ ":${_test_program_fragment_target_v1}" ]
526 }
Chong Gu26908f4e2021-01-29 03:13:07527
Greg Thompson9765eeb42022-04-05 12:30:35528 # Define the test component, dependent on the generated manifest, and the
529 # test executable target.
530 _test_component_target_v1 = "${target_name}_component_v1"
531 fuchsia_component(_test_component_target_v1) {
532 deps = [ ":$_test_component_manifest_target_v1" ]
533 data_deps = [ ":$_exec_target" ]
534 manifest = _test_component_manifest_v1
535 visibility = [ ":*" ]
536 }
537
538 _test_component_targets += [ ":${_test_component_target_v1}" ]
Wez6879f8a2021-09-07 20:27:02539 }
540
541 # Define components for each entry in |additional_manifests|, if any. Since
542 # manifests may themselves depend-on the outputs of |deps|, these components
543 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02544 if (defined(invoker.additional_manifests)) {
545 foreach(filename, invoker.additional_manifests) {
546 _additional_component_target =
547 target_name + "_" + get_path_info(filename, "name")
548 _test_component_targets += [ ":${_additional_component_target}" ]
549 fuchsia_component(_additional_component_target) {
550 forward_variables_from(invoker, [ "testonly" ])
551 data_deps = [ ":$_exec_target" ]
552 visibility = [ ":*" ]
553 manifest = filename
554
555 # Depend on |invoker.deps|, in case it includes a dependency that
556 # creates this additional component's manifest.
557 if (defined(invoker.deps)) {
558 deps = invoker.deps
559 }
560 }
561 }
562 }
563
564 # Define the package target that will bundle the test and additional
565 # components and their data.
566 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21567 forward_variables_from(invoker,
568 [
569 "excluded_files",
570 "excluded_dirs",
571 ])
Wez6879f8a2021-09-07 20:27:02572 package_name = _output_name
573 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21574
575 if (!defined(excluded_dirs)) {
576 excluded_dirs = []
577 }
578 excluded_dirs += [ devtools_root_location ]
Wez6879f8a2021-09-07 20:27:02579 }
580
581 # |target_name| refers to the package-runner rule, so that building
582 # "base_unittests" will build not only the executable, component, and
583 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25584 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53585 forward_variables_from(invoker,
586 [
Kevin Marshall5fadadd2021-10-16 00:08:25587 "data",
588 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53589 "package_deps",
Greg Thompson26516592021-12-16 08:34:45590 "use_cfv2",
Kevin Marshall5fadadd2021-10-16 00:08:25591 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53592 ])
Kevin Marshall5fadadd2021-10-16 00:08:25593
Chong Guc6bfdf62021-10-20 23:37:00594 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15595 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25596 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42597
Kevin Marshall5fadadd2021-10-16 00:08:25598 if (!defined(deps)) {
599 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52600 }
Kevin Marshall5fadadd2021-10-16 00:08:25601 if (defined(invoker.deps)) {
602 deps += invoker.deps
603 }
Greg Guterman6963dc082021-04-07 05:20:59604
Kevin Marshall5fadadd2021-10-16 00:08:25605 if (!defined(data)) {
606 data = []
607 }
608 if (tests_have_location_tags) {
609 data += [ "//testing/location_tags.json" ]
610 }
611
612 if (!defined(data_deps)) {
613 data_deps = []
614 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28615
Kevin Marshall23529362022-02-23 16:50:36616 data_deps += [ "//testing:test_scripts_shared" ]
617
Benjamin Lerman5e3cb3362022-01-25 16:46:28618 # TODO(crbug.com/1199334): Because perfetto unit test is defined outside
619 # of chromium, the dependency to the filter file is added here.
620 data_deps += [ "//testing/buildbot/filters:perfetto_unittests_filters" ]
Chong Gu258e22c2021-10-20 18:39:50621
Greg Guterman6963dc082021-04-07 05:20:59622 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25623 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59624 }
Kevin Marshallf35fa5f2018-01-29 19:24:42625 }
626
danakjebb9cc4d2022-03-04 21:30:11627 mixed_test(_exec_target) {
628 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01629 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42630 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03631 }
dpranke2a294622015-08-07 05:23:01632 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30633 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46634 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30635
Rohit Raof9b096d2019-09-09 22:26:23636 declare_args() {
637 # Keep the unittest-as-xctest functionality defaulted to off until the
638 # bots are updated to handle it properly.
639 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
640 # supports running unittests with xctest.
641 enable_run_ios_unittests_with_xctest = false
642 }
643
sdefresne012857872016-03-16 10:55:37644 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27645 _output_name = target_name
646 if (defined(invoker.output_name)) {
647 _output_name = invoker.output_name
648 }
649
Jeff Yoonf7f4eb42020-03-06 18:55:36650 _wrapper_output_name = "run_${target_name}"
651 ios_test_runner_wrapper(_wrapper_output_name) {
652 forward_variables_from(invoker,
653 [
654 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36655 "deps",
656 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27657 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36658 "retries",
659 "shards",
660 ])
661
662 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
663
664 if (!defined(executable_args)) {
665 executable_args = []
666 }
667 executable_args += [
668 "--app",
669 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
670 ]
671
672 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22673
674 if (!defined(data)) {
675 data = []
676 }
Jamie Madilldd60ee62021-04-13 19:25:52677 if (tests_have_location_tags) {
678 data += [ "//testing/location_tags.json" ]
679 }
Jeff Yoonf7f4eb42020-03-06 18:55:36680 }
681
sdefresne012857872016-03-16 10:55:37682 _resources_bundle_data = target_name + "_resources_bundle_data"
683
684 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34685 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22686 sources = [ "//testing/gtest_ios/Default.png" ]
687 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01688 }
689
Mirko Bonadei15522bc2020-09-16 20:38:39690 force_xctest = enable_run_ios_unittests_with_xctest ||
691 (defined(invoker.is_xctest) && invoker.is_xctest)
692
693 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23694 ios_test_target_type = "ios_xctest_test"
695 } else {
696 ios_test_target_type = "ios_app_bundle"
697 }
698
699 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01700 testonly = true
sdefresnea828c282016-05-30 18:04:20701
Mirko Bonadei15522bc2020-09-16 20:38:39702 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23703 xctest_module_target = "//base/test:google_test_runner"
704 }
705
Andrew Grieve1b290e4a22020-11-24 20:07:01706 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13707
708 # Provide sensible defaults in case invoker did not define any of those
709 # required variables.
sdefresne05b97ca2016-06-08 07:19:46710 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13711 info_plist = "//testing/gtest_ios/unittest-Info.plist"
712 }
sdefresne9e147e02016-06-07 00:10:13713
Sylvain Defresne3c5a1312021-09-23 17:08:09714 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Jumac9da0242022-02-18 20:43:13715 bundle_identifier = shared_bundle_id_for_test_apps
Ali Jumaff45dd82021-11-08 21:53:50716 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09717 } else {
Ali Juma75be0fe2022-01-24 19:39:29718 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27719 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09720 }
dpranke2a294622015-08-07 05:23:01721
sdefresne047490e2016-07-22 08:49:34722 if (!defined(bundle_deps)) {
723 bundle_deps = []
724 }
725 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36726
727 if (!defined(data_deps)) {
728 data_deps = []
729 }
730
Kevin Marshall23529362022-02-23 16:50:36731 data_deps += [ "//testing:test_scripts_shared" ]
732
Jeff Yoonf7f4eb42020-03-06 18:55:36733 # Include the generate_wrapper as part of data_deps
734 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46735 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59736
737 if (use_rts) {
738 data_deps += [ ":${invoker.target_name}__rts_filters" ]
739 }
dpranke2a294622015-08-07 05:23:01740 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11741 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
742 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30743 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
744
Yuke Liao2a9b2f0e2021-04-16 00:40:11745 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32746
Benjamin Pastene3bce864e2018-04-14 01:16:32747 _gen_runner_target = "${target_name}__runner"
748 _runtime_deps_file =
749 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
750 "/" + get_label_info(target_name, "name") + ".runtime_deps"
751
Xinan Lin6be01252021-06-25 23:07:36752 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
753 if (is_skylab) {
Struan Shrimptonf61293f62022-04-11 19:33:40754 generate_skylab_deps(_gen_runner_target) {
Xinan Lin6be01252021-06-25 23:07:36755 generated_script = _generated_script
756 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34757 }
Xinan Lin6be01252021-06-25 23:07:36758 } else {
759 generate_runner_script(_gen_runner_target) {
760 generated_script = _generated_script
761 test_exe = invoker.target_name
762 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34763
Xinan Lin6be01252021-06-25 23:07:36764 if (is_chromeos_lacros) {
765 # At build time, Lacros tests don't know whether they'll run on VM or
766 # HW, and instead, these flags are specified at runtime when invoking
767 # the generated runner script.
768 skip_generating_board_args = true
769 }
Greg Guterman6963dc082021-04-07 05:20:59770
Xinan Lin6be01252021-06-25 23:07:36771 if (tests_have_location_tags) {
772 data = [ "//testing/location_tags.json" ]
773 }
774
775 if (use_rts) {
776 data_deps = [ ":${invoker.target_name}__rts_filters" ]
777 }
Greg Guterman6963dc082021-04-07 05:20:59778 }
Benjamin Pastene3bce864e2018-04-14 01:16:32779 }
780
danakjebb9cc4d2022-03-04 21:30:11781 mixed_test(target_name) {
782 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01783 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
784 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32785 if (!defined(deps)) {
786 deps = []
787 }
788 if (!defined(data)) {
789 data = []
790 }
791
Ben Pastene41041782019-02-16 04:21:58792 # We use a special trigger script for CrOS hardware tests.
793 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
794
Benjamin Pastene3bce864e2018-04-14 01:16:32795 output_name = target_name
796 write_runtime_deps = _runtime_deps_file
797 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37798 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59799
Kevin Marshall23529362022-02-23 16:50:36800 if (!defined(data_deps)) {
801 data_deps = []
802 }
803
804 data_deps += [ "//testing:test_scripts_shared" ]
805
Greg Guterman6963dc082021-04-07 05:20:59806 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:59807 data_deps += [ ":${invoker.target_name}__rts_filters" ]
808 }
Benjamin Pastene3bce864e2018-04-14 01:16:32809 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11810 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24811 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
812 _executable = target_name
813 _gen_runner_target = "${target_name}__runner"
814
Yuke Liao32af4242020-07-16 21:48:02815 if (defined(invoker.use_xvfb)) {
816 _use_xvfb = invoker.use_xvfb
817 } else {
818 _use_xvfb = false
819 }
820
Yuke Liaod037abc2020-10-06 22:48:22821 # When use_xvfb is set by the invoker, it indicates that running this test
822 # target requires a window, and in lacros build, ash-chrome serves as the
823 # display server. Note that even though the tests themselves do not require
824 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
825 # because ash-chrome is based on x11.
826 _use_ash_chrome = _use_xvfb
827
Yuke Liaoe703384b2020-07-16 01:05:24828 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24829 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02830
Yuke Liao2e4953cf2020-07-26 19:20:19831 data = []
Will Harrisd35e2c92021-04-07 01:42:02832 data_deps = [ "//testing:test_scripts_shared" ]
833
Yuke Liao32af4242020-07-16 21:48:02834 if (_use_xvfb) {
835 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22836 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02837 } else {
838 executable = "//testing/test_env.py"
839 }
Jamie Madilldd60ee62021-04-13 19:25:52840 if (tests_have_location_tags) {
841 data += [ "//testing/location_tags.json" ]
842 }
Yuke Liao32af4242020-07-16 21:48:02843
Yuke Liaoe703384b2020-07-16 01:05:24844 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02845 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39846 "test",
Yuke Liaoe703384b2020-07-16 01:05:24847 "@WrappedPath(./${_executable})",
848 "--test-launcher-bot-mode",
849 ]
Yuke Liao32af4242020-07-16 21:48:02850
Yuke Liaof540c742020-07-29 16:28:34851 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37852 executable_args += [ "--ash-chrome-path" ]
853
854 # Can't use --ash-chrome-path=path because WrappedPath
855 # won't be expanded for that usage.
856 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39857 }
858
Yuke Liaoe703384b2020-07-16 01:05:24859 if (is_asan) {
860 executable_args += [ "--asan=true" ]
861 }
862 if (is_msan) {
863 executable_args += [ "--msan=true" ]
864 }
865 if (is_tsan) {
866 executable_args += [ "--tsan=true" ]
867 }
868 if (use_cfi_diag) {
869 executable_args += [ "--cfi-diag=true" ]
870 }
871
Takuto Ikuta38ebd0e2022-01-19 17:56:22872 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59873
874 if (use_rts) {
875 data_deps += [ ":${invoker.target_name}__rts_filters" ]
876 }
Yuke Liaoe703384b2020-07-16 01:05:24877 }
878
danakjebb9cc4d2022-03-04 21:30:11879 mixed_test(target_name) {
880 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01881 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
882 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24883 if (!defined(deps)) {
884 deps = []
885 }
886
Yuke Liaod037abc2020-10-06 22:48:22887 if (!defined(data_deps)) {
888 data_deps = []
889 }
890
Kevin Marshall23529362022-02-23 16:50:36891 data_deps += [ "//testing:test_scripts_shared" ]
892
Yuke Liaoe703384b2020-07-16 01:05:24893 write_runtime_deps = _runtime_deps_file
894 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22895 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56896 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22897 }
Greg Guterman6963dc082021-04-07 05:20:59898
899 if (use_rts) {
900 data_deps += [ ":${invoker.target_name}__rts_filters" ]
901 }
Yuke Liaoe703384b2020-07-16 01:05:24902 }
Dirk Prankedd4ff742020-11-18 19:57:32903 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30904 if (is_mac || is_win) {
905 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
906 }
907
Dirk Prankedd4ff742020-11-18 19:57:32908 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
909 _executable = target_name
910 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06911
Dirk Prankedd4ff742020-11-18 19:57:32912 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
913 _use_xvfb = invoker.use_xvfb
914 } else {
915 _use_xvfb = false
916 }
917
918 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32919 wrapper_script = "$root_build_dir/bin/run_" + _executable
920
921 data = []
Will Harrisd35e2c92021-04-07 01:42:02922 data_deps = [ "//testing:test_scripts_shared" ]
923
Dirk Prankedd4ff742020-11-18 19:57:32924 if (_use_xvfb) {
925 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06926 } else {
Dirk Prankedd4ff742020-11-18 19:57:32927 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06928 }
Jamie Madilldd60ee62021-04-13 19:25:52929 if (tests_have_location_tags) {
930 data += [ "//testing/location_tags.json" ]
931 }
Dirk Pranke31e346e2020-07-15 00:54:06932
Dirk Prankedd4ff742020-11-18 19:57:32933 executable_args = [
934 "@WrappedPath(./${_executable})",
935 "--test-launcher-bot-mode",
936 ]
937 if (is_asan) {
938 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06939 }
Dirk Prankedd4ff742020-11-18 19:57:32940 if (is_msan) {
941 executable_args += [ "--msan=true" ]
942 }
943 if (is_tsan) {
944 executable_args += [ "--tsan=true" ]
945 }
946 if (use_cfi_diag) {
947 executable_args += [ "--cfi-diag=true" ]
948 }
949
950 data += [ "//.vpython" ]
Greg Guterman6963dc082021-04-07 05:20:59951
952 if (use_rts) {
953 data_deps += [ ":${invoker.target_name}__rts_filters" ]
954 }
Dirk Pranke31e346e2020-07-15 00:54:06955 }
956
danakjebb9cc4d2022-03-04 21:30:11957 mixed_test(target_name) {
958 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01959 forward_variables_from(invoker,
960 "*",
961 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
962 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06963 if (!defined(deps)) {
964 deps = []
965 }
966
Dirk Pranke31e346e2020-07-15 00:54:06967 deps += [
968 # Give tests the default manifest on Windows (a no-op elsewhere).
969 "//build/win:default_exe_manifest",
970 ]
971
Dirk Prankedd4ff742020-11-18 19:57:32972 write_runtime_deps = _runtime_deps_file
973 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11974
Kevin Marshall23529362022-02-23 16:50:36975 if (!defined(data_deps)) {
976 data_deps = []
977 }
978
979 data_deps += [ "//testing:test_scripts_shared" ]
980
Greg Guterman50ed4b42021-04-08 01:15:11981 if (use_rts) {
Greg Guterman50ed4b42021-04-08 01:15:11982 data_deps += [ ":${invoker.target_name}__rts_filters" ]
983 }
Dirk Prankedd4ff742020-11-18 19:57:32984 }
985 } else {
986 # This is a catch-all clause for NaCl toolchains and other random
987 # configurations that might define tests; test() in these configs
988 # will just define the underlying executables.
989 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
990 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:11991 mixed_test(target_name) {
992 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01993 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
994 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32995 if (!defined(deps)) {
996 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06997 }
Greg Guterman6963dc082021-04-07 05:20:59998
Kevin Marshall23529362022-02-23 16:50:36999 if (!defined(data_deps)) {
1000 data_deps = []
1001 }
1002
1003 data_deps += [ "//testing:test_scripts_shared" ]
1004
Greg Guterman6963dc082021-04-07 05:20:591005 if (use_rts) {
Greg Guterman6963dc082021-04-07 05:20:591006 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1007 }
Dirk Pranke31e346e2020-07-15 00:54:061008 }
qsrfb5251d12015-01-21 15:57:221009 }
1010}
brettwedb6ecc2016-07-14 23:37:031011
Dirk Pranke6188075b2020-10-01 19:31:281012# Defines a type of test that invokes a script to run, rather than
1013# invoking an executable.
1014#
1015# The script must implement the
1016# [test executable API](//docs/testing/test_executable_api.md).
1017#
1018# The template must be passed the `script` parameter, which specifies
1019# the path to the script to run. It may optionally be passed a
1020# `script_args` parameter, which can be used to include a list of
1021# args to be specified by default. The template will produce
1022# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
1023# for the target to $root_build_dir/${target_name}.runtime_deps, as per
1024# the conventions listed in the
1025# [test wrapper API](//docs/testing/test_wrapper_api.md).
1026template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:591027 if (use_rts) {
1028 action("${target_name}__rts_filters") {
1029 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:531030 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:591031 args = [ rebase_path(rts_file, root_build_dir) ]
1032 outputs = [ rts_file ]
1033 }
1034 }
1035
Dirk Pranke6188075b2020-10-01 19:31:281036 generate_wrapper(target_name) {
1037 testonly = true
1038 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1039
1040 executable = "//testing/test_env.py"
1041
1042 executable_args =
1043 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1044 if (defined(invoker.args)) {
1045 executable_args += invoker.args
1046 }
1047
Will Harrisd35e2c92021-04-07 01:42:021048 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471049
Dirk Pranke6188075b2020-10-01 19:31:281050 if (defined(invoker.data)) {
1051 data += invoker.data
1052 }
Jamie Madilldd60ee62021-04-13 19:25:521053 if (tests_have_location_tags) {
1054 data += [ "//testing/location_tags.json" ]
1055 }
Dirk Pranke19a58732021-03-24 22:26:221056
Will Harrisd35e2c92021-04-07 01:42:021057 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281058 if (defined(invoker.data_deps)) {
1059 data_deps += invoker.data_deps
1060 }
1061
1062 forward_variables_from(invoker,
1063 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:011064 TESTONLY_AND_VISIBILITY + [
1065 "data",
1066 "data_deps",
1067 "script",
1068 "script_args",
1069 ])
1070 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281071
1072 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:591073
1074 if (use_rts) {
1075 data_deps += [ ":${invoker.target_name}__rts_filters" ]
1076 }
Dirk Pranke6188075b2020-10-01 19:31:281077 }
1078}
1079
brettwedb6ecc2016-07-14 23:37:031080# Test defaults.
1081set_defaults("test") {
1082 if (is_android) {
1083 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411084 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591085 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:031086 } else {
1087 configs = default_executable_configs
Leonard Grey077a28302021-12-16 14:14:261088 if (is_mac) {
1089 # TODO(lgrey): Maybe restore this.
1090 # Don't strip tests for visibility into test crashes/hangs.
1091 # https://bugs.chromium.org/p/chromium/issues/detail?id=1244047#c49
1092 configs -= [ "//build/config/mac:strip_all" ]
1093 }
brettwedb6ecc2016-07-14 23:37:031094 }
1095}