blob: 02b1b402f35560be2f7ed7a7b544fd345d8d393d [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")
Mirko Bonadei4a0df432020-09-08 19:06:0215import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2416
Greg Guterman6963dc082021-04-07 05:20:5917declare_args() {
Dirk Prankeb404c3b2021-06-14 19:57:5018 # Some component repos (e.g. ANGLE) import //testing but do not have
19 # "location_tags.json", and so we don't want to try and upload the tags
20 # for their tests.
21 # And, some build configs may simply turn off generation altogether.
22 tests_have_location_tags = generate_location_tags
Greg Guterman6963dc082021-04-07 05:20:5923}
24
jcivellif4462a352017-01-10 04:45:5925if (is_android) {
26 import("//build/config/android/config.gni")
Charlie Hud98dc692021-12-08 01:01:0227 import("//build/config/android/create_unwind_table.gni")
James Cook209256f2018-12-07 18:40:5028 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5929 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4430 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3231} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0632 import("//build/config/chromecast_build.gni")
Kevin Marshall55fd8522019-10-04 22:47:0133 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4234 import("//build/config/fuchsia/package.gni")
Chong Gu26908f4e2021-01-29 03:13:0735 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Yuke Liaoe502a742021-04-19 23:15:0236} else if ((is_chromeos_ash || is_chromeos_lacros) && is_chromeos_device) {
Ben Pastene4c35c572018-04-30 23:21:4837 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3238 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2839 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3240} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3641 import("//build/config/ios/ios_sdk.gni")
42 import("//build/config/ios/ios_test_runner_wrapper.gni")
43 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3244} else {
Dirk Pranke31e346e2020-07-15 00:54:0645 import("//build/config/sanitizers/sanitizers.gni")
46 import("//build/util/generate_wrapper.gni")
47}
48
qsrfb5251d12015-01-21 15:57:2249# Define a test as an executable (or apk on Android) with the "testonly" flag
50# set.
agrieve62ab00282016-04-05 02:03:4551# Variable:
Dirk Pranke79d065d2020-08-29 03:28:3052# use_xvfb: (optional) whether to run the executable under Xvfb.
danakj02dddc42022-02-11 23:24:3053# use_raw_android_executable: Use mixed_executable() rather than
54# android_apk().
ynovikov389d9e442016-05-27 02:34:5655# use_native_activity: Test implements ANativeActivity_onCreate().
Greg Thompson26516592021-12-16 08:34:4556# use_cfv2: (Fuchsia, optional): build the test as a framework v2 component;
57# see https://fuchsia.dev/fuchsia-src/concepts/components/v2 for details.
Greg Thompson5e4f41f2022-02-09 16:35:1458# The default value is true; set it to false explicitly to build a test as
59# a v1 component.
Mirko Bonadei15522bc2020-09-16 20:38:3960# is_xctest: (iOS, optional) whether to build the executable as XCTest.
61# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
62# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:4363# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
64# network requests during the test.
qsrfb5251d12015-01-21 15:57:2265template("test") {
Greg Guterman6963dc082021-04-07 05:20:5966 # Ensures the rts file exists and if not, creates a dummy file
67 if (use_rts) {
68 action("${target_name}__rts_filters") {
69 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:5370 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:5971 args = [ rebase_path(rts_file, root_build_dir) ]
72 outputs = [ rts_file ]
73 }
74 }
75
Andrew Grieve1b290e4a22020-11-24 20:07:0176 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:3977 if (!is_ios) {
78 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
79 "is_xctest can be set only for iOS builds")
80 }
Stefano Duo4128b6b2021-08-02 21:24:4381 if (!is_android) {
82 assert(!defined(invoker.allow_cleartext_traffic),
83 "allow_cleartext_traffic can be set only for Android tests")
84 }
85
qsrfb5251d12015-01-21 15:57:2286 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3087 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
88
Peter Kotwicz10742f82021-04-15 22:32:5089 _use_default_launcher =
90 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
91 if (!defined(invoker.use_raw_android_executable)) {
92 # Checkouts where build_with_chromium == false often have a custom GN
93 # template wrapper around test() which sets use_default_launcher == false.
94 # Set the _use_raw_android_executable default so that test() targets which
95 # do not use the custom wrapper
96 # (1) Do not cause "gn gen" to fail
97 # (2) Do not need to be moved into if(build_with_chromium) block.
98 _use_raw_android_executable =
99 !build_with_chromium && _use_default_launcher
100 } else {
101 not_needed([ "_use_default_launcher" ])
102 _use_raw_android_executable = invoker.use_raw_android_executable
103 }
qsrfb5251d12015-01-21 15:57:22104
agrieve67855de2016-03-30 14:46:01105 # output_name is used to allow targets with the same name but in different
106 # packages to still produce unique runner scripts.
107 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26108 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01109 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26110 }
agrieve62ab00282016-04-05 02:03:45111
agrieveb355ad152016-04-19 03:45:23112 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42113 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:51114 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42115 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51116 ]
agrieve3ac557f02016-04-12 15:52:00117
jbudorickced2a252016-06-09 16:38:54118 assert(_use_raw_android_executable || enable_java_templates)
119
agrieve62ab00282016-04-05 02:03:45120 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49121 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
122
agrieve62ab00282016-04-05 02:03:45123 _exec_target = "${target_name}__exec"
124 _dist_target = "${target_name}__dist"
125 _exec_output =
126 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
127
danakj02dddc42022-02-11 23:24:30128 mixed_executable(_exec_target) {
danakje94f40d2022-02-16 18:13:53129 # Configs will always be defined since we set_defaults in
130 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45131 configs = []
Dirk Pranke19a58732021-03-24 22:26:22132 forward_variables_from(
133 invoker,
134 "*",
135 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
136 "data_deps",
137 "extra_dist_files",
138 ])
agrieve62ab00282016-04-05 02:03:45139
140 # Thanks to the set_defaults() for test(), configs are initialized with
141 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59142 configs -= [
143 "//build/config:shared_library_config",
144 "//build/config/android:hide_all_but_jni",
145 ]
agrieve62ab00282016-04-05 02:03:45146 configs += [ "//build/config:executable_config" ]
147
danakje94f40d2022-02-16 18:13:53148 rs_configs = [ "//build/rust:test" ]
149
Dirk Pranke19a58732021-03-24 22:26:22150 if (defined(invoker.data_deps)) {
151 data_deps = invoker.data_deps
152 } else {
153 data_deps = []
154 }
155 if (!defined(data)) {
156 data = []
157 }
Jamie Madilldd60ee62021-04-13 19:25:52158 if (tests_have_location_tags) {
159 data += [ "//testing/location_tags.json" ]
160 }
Dirk Pranke19a58732021-03-24 22:26:22161
agrieve62ab00282016-04-05 02:03:45162 # Don't output to the root or else conflict with the group() below.
163 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11164
165 if (use_rts) {
166 data_deps += [ ":${invoker.target_name}__rts_filters" ]
167 }
agrieve62ab00282016-04-05 02:03:45168 }
169
170 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45171 dist_dir = "$root_out_dir/$target_name"
172 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22173 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45174 if (defined(invoker.extra_dist_files)) {
175 extra_files = invoker.extra_dist_files
176 }
Greg Guterman50ed4b42021-04-08 01:15:11177
178 if (use_rts) {
179 if (!defined(data_deps)) {
180 data_deps = []
181 }
182 data_deps += [ ":${invoker.target_name}__rts_filters" ]
183 }
agrieve62ab00282016-04-05 02:03:45184 }
185 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02186 _library_target = "${target_name}__library"
187 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45188 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43189 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45190 "android_manifest",
agrievec6811b422016-06-23 02:25:09191 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27192 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55193 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45194 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50195 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07196 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02197 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07198 "proguard_configs",
199 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45200 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02201 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45202 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56203 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45204 ]
Siddhartha764226b2018-03-13 02:32:55205
206 # Adds the unwind tables from unstripped binary as an asset file in the
207 # apk, if |add_unwind_tables_in_apk| is specified by the test.
208 if (defined(invoker.add_unwind_tables_in_apk) &&
209 invoker.add_unwind_tables_in_apk) {
210 _unwind_table_asset_name = "${target_name}_unwind_assets"
Charlie Hud98dc692021-12-08 01:01:02211 if (use_android_unwinder_v2) {
212 unwind_table_asset_v2(_unwind_table_asset_name) {
213 library_target = _library_target
214 deps = [ ":$_library_target" ]
215 }
216 } else {
217 unwind_table_asset(_unwind_table_asset_name) {
218 library_target = _library_target
219 deps = [ ":$_library_target" ]
220 }
Siddhartha764226b2018-03-13 02:32:55221 }
222 }
223
danakj02dddc42022-02-11 23:24:30224 # TODO(crbug.com/1296718): Need a mixed_shared_library for rust tests on
225 # Android (or can it be a mixed_component?).
agrieve62ab00282016-04-05 02:03:45226 shared_library(_library_target) {
227 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
228 configs = [] # Prevent list overwriting warning.
229 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45230
jbudorickd29ecfa72016-11-18 22:45:42231 forward_variables_from(
232 invoker,
233 "*",
Peter Wen2052bd12020-12-03 20:15:07234 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
235 TESTONLY_AND_VISIBILITY)
236
237 # Native targets do not need to depend on java targets. Filter them out
238 # so that the shared library can be built without needing to wait for
239 # dependent java targets.
240 deps = []
241 if (defined(invoker.deps)) {
242 foreach(_dep, invoker.deps) {
243 _target_label = get_label_info(_dep, "label_no_toolchain")
244 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
245 deps += [ _dep ]
246 }
247 }
248 }
agrieve62ab00282016-04-05 02:03:45249
Peter Kotwiczb9957d62021-04-12 21:09:43250 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37251 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45252 }
253 }
254 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54255 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07256 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45257 apk_name = invoker.target_name
258 if (defined(invoker.output_name)) {
259 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45260 install_script_name = "install_${invoker.output_name}"
261 }
agrieveb355ad152016-04-19 03:45:23262
Daniel Bratellfdda4652019-01-31 15:45:54263 if (defined(invoker.deps)) {
264 deps = invoker.deps
265 } else {
266 deps = []
267 }
268
jcivellif4462a352017-01-10 04:45:59269 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43270 if (_use_default_launcher) {
271 deps += [ "//base/test:test_support_java" ]
272 }
jcivellif4462a352017-01-10 04:45:59273
Siddhartha764226b2018-03-13 02:32:55274 if (defined(_unwind_table_asset_name)) {
275 deps += [ ":${_unwind_table_asset_name}" ]
276 }
Greg Guterman50ed4b42021-04-08 01:15:11277
278 if (use_rts) {
279 data_deps = [ ":${invoker.target_name}__rts_filters" ]
280 }
agrieve62ab00282016-04-05 02:03:45281 }
Andrew Grievee1dc23f2019-10-22 16:26:36282 }
agrieve62ab00282016-04-05 02:03:45283
Andrew Grievee1dc23f2019-10-22 16:26:36284 test_runner_script(_test_runner_target) {
285 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57286
Andrew Grievee1dc23f2019-10-22 16:26:36287 if (_use_raw_android_executable) {
288 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34289 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36290 } else {
291 apk_target = ":$_apk_target"
292 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47293
294 # Dep needed for the test runner .runtime_deps file to pick up data
295 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22296 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45297 }
Andrew Grievee1dc23f2019-10-22 16:26:36298 test_name = _output_name
299 test_suite = _output_name
300 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59301
302 if (use_rts) {
303 data_deps += [ ":${invoker.target_name}__rts_filters" ]
304 }
mikecase56d80d72015-06-03 00:57:26305 }
306
Andrew Grieve7ca6de32019-10-18 03:57:47307 # Create a wrapper script rather than using a group() in order to ensure
308 # "ninja $target_name" always works. If this was a group(), then GN would
309 # not create a top-level alias for it if a target exists in another
310 # directory with the same $target_name.
311 # Also - bots run this script directly for "components_perftests".
312 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01313 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47314 executable = "$root_build_dir/bin/run_$_output_name"
315 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22316 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40317 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47318 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40319 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47320 # Dep needed for the swarming .isolate file to pick up data
321 # deps from the forward_variables_from(invoker, "*") on the library.
322 deps += [
323 ":$_apk_target",
324 ":$_library_target",
325 ]
agrieve62ab00282016-04-05 02:03:45326 }
Dirk Pranke19a58732021-03-24 22:26:22327
328 if (defined(invoker.data_deps)) {
329 data_deps = invoker.data_deps
330 } else {
331 data_deps = []
332 }
Jamie Madilldd60ee62021-04-13 19:25:52333 if (tests_have_location_tags) {
334 data = [ "//testing/location_tags.json" ]
335 }
Greg Guterman6963dc082021-04-07 05:20:59336
337 if (use_rts) {
338 data_deps += [ ":${invoker.target_name}__rts_filters" ]
339 }
agrieve1a02e582015-10-15 21:35:39340 }
Scott Graham4c4cdc52017-05-29 20:45:03341 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30342 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
343
Scott Graham4c4cdc52017-05-29 20:45:03344 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42345 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42346 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03347
Greg Thompson5e4f41f2022-02-09 16:35:14348 if (!defined(invoker.use_cfv2) || invoker.use_cfv2) {
Greg Thompson26516592021-12-16 08:34:45349 # Generate a CML fragment that provides the program name.
350 _test_program_fragment_target = "${target_name}_program-fragment"
351 _test_program_fragment =
352 "${target_out_dir}/${target_name}_program.test-cml"
353 _program_name = get_label_info(":${_exec_target}", "name")
354 generated_file(_test_program_fragment_target) {
355 contents = "{ program: { binary: \"${_program_name}\",},}"
356 outputs = [ _test_program_fragment ]
357 }
358
359 # Collate the complete set of elements to include in the test component's
360 # manifest.
361 _manifest_fragments = [
Greg Thompson6cdcdb32022-01-31 11:12:44362 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
Greg Thompson26516592021-12-16 08:34:45363 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml",
Greg Thompsonf31d7d22022-01-26 09:17:45364 "//build/config/fuchsia/test/minimum.shard.test-cml",
Greg Thompson26516592021-12-16 08:34:45365 _test_program_fragment,
366 ]
367
368 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
369 _merged_manifest_name = "${_output_name}.cml"
370 } else {
371 # Generate a CMX fragment that provides the program name.
372 _test_program_fragment_target = "${target_name}_program-fragment"
373 _test_program_fragment =
374 "${target_out_dir}/${target_name}_program.test-cmx"
375 _program_name = get_label_info(":${_exec_target}", "name")
376 generated_file(_test_program_fragment_target) {
377 contents = "{ \"program\": { \"binary\": \"${_program_name}\"}}"
378 outputs = [ _test_program_fragment ]
379 }
380
381 # Collate the complete set of elements to include in the test component's
382 # manifest.
383 _manifest_fragments = [
384 "//build/config/fuchsia/test/minimum_capabilities.test-cmx",
385 _test_program_fragment,
386 ]
387
388 _test_component_manifest = "${target_out_dir}/${target_name}.cmx"
389 _merged_manifest_name = "${_output_name}.cmx"
Wez6879f8a2021-09-07 20:27:02390 }
Chong Gu26908f4e2021-01-29 03:13:07391
Chong Gu91a1fea2021-03-30 17:24:31392 if (defined(invoker.additional_manifest_fragments)) {
Wez6879f8a2021-09-07 20:27:02393 _manifest_fragments += invoker.additional_manifest_fragments
Chong Guacf19a32021-03-10 01:07:41394 }
Chong Gu28bf7e72021-05-26 01:36:19395
Wez6879f8a2021-09-07 20:27:02396 # Generate the test component manifest from the specified elements.
397 _test_component_manifest_target = "${target_name}_component-manifest"
Wez6879f8a2021-09-07 20:27:02398 cmc_merge(_test_component_manifest_target) {
399 sources = _manifest_fragments
Greg Thompson26516592021-12-16 08:34:45400 output_name = "${_merged_manifest_name}"
Wez6879f8a2021-09-07 20:27:02401 deps = [ ":${_test_program_fragment_target}" ]
Chong Gu7ad57c22021-03-11 00:24:38402 }
Chong Gu26908f4e2021-01-29 03:13:07403
Wez6879f8a2021-09-07 20:27:02404 # Define the test component, dependent on the generated manifest, and the
405 # test executable target.
406 _test_component_target = "${target_name}_component"
407 fuchsia_component(_test_component_target) {
408 deps = [ ":$_test_component_manifest_target" ]
409 data_deps = [ ":$_exec_target" ]
410 manifest = _test_component_manifest
411 visibility = [ ":*" ]
412 }
413
414 # Define components for each entry in |additional_manifests|, if any. Since
415 # manifests may themselves depend-on the outputs of |deps|, these components
416 # must each individually depend on |invoker.deps|.
417 _test_component_targets = [ ":${_test_component_target}" ]
418 if (defined(invoker.additional_manifests)) {
419 foreach(filename, invoker.additional_manifests) {
420 _additional_component_target =
421 target_name + "_" + get_path_info(filename, "name")
422 _test_component_targets += [ ":${_additional_component_target}" ]
423 fuchsia_component(_additional_component_target) {
424 forward_variables_from(invoker, [ "testonly" ])
425 data_deps = [ ":$_exec_target" ]
426 visibility = [ ":*" ]
427 manifest = filename
428
429 # Depend on |invoker.deps|, in case it includes a dependency that
430 # creates this additional component's manifest.
431 if (defined(invoker.deps)) {
432 deps = invoker.deps
433 }
434 }
435 }
436 }
437
438 # Define the package target that will bundle the test and additional
439 # components and their data.
440 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21441 forward_variables_from(invoker,
442 [
443 "excluded_files",
444 "excluded_dirs",
445 ])
Wez6879f8a2021-09-07 20:27:02446 package_name = _output_name
447 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21448
449 if (!defined(excluded_dirs)) {
450 excluded_dirs = []
451 }
452 excluded_dirs += [ devtools_root_location ]
Wez6879f8a2021-09-07 20:27:02453 }
454
455 # |target_name| refers to the package-runner rule, so that building
456 # "base_unittests" will build not only the executable, component, and
457 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25458 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53459 forward_variables_from(invoker,
460 [
Kevin Marshall5fadadd2021-10-16 00:08:25461 "data",
462 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53463 "package_deps",
Greg Thompson26516592021-12-16 08:34:45464 "use_cfv2",
Kevin Marshall5fadadd2021-10-16 00:08:25465 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53466 ])
Kevin Marshall5fadadd2021-10-16 00:08:25467
Chong Guc6bfdf62021-10-20 23:37:00468 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15469 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25470 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42471
Kevin Marshall5fadadd2021-10-16 00:08:25472 if (!defined(deps)) {
473 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52474 }
Kevin Marshall5fadadd2021-10-16 00:08:25475 if (defined(invoker.deps)) {
476 deps += invoker.deps
477 }
Greg Guterman6963dc082021-04-07 05:20:59478
Kevin Marshall5fadadd2021-10-16 00:08:25479 if (!defined(data)) {
480 data = []
481 }
482 if (tests_have_location_tags) {
483 data += [ "//testing/location_tags.json" ]
484 }
485
486 if (!defined(data_deps)) {
487 data_deps = []
488 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28489
490 # TODO(crbug.com/1199334): Because perfetto unit test is defined outside
491 # of chromium, the dependency to the filter file is added here.
492 data_deps += [ "//testing/buildbot/filters:perfetto_unittests_filters" ]
Chong Gu258e22c2021-10-20 18:39:50493
Greg Guterman6963dc082021-04-07 05:20:59494 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25495 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59496 }
Kevin Marshallf35fa5f2018-01-29 19:24:42497 }
498
danakj02dddc42022-02-11 23:24:30499 mixed_executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01500 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42501 output_name = _exec_target
danakje94f40d2022-02-16 18:13:53502 rs_configs = [ "//build/rust:test" ]
Scott Graham4c4cdc52017-05-29 20:45:03503 }
dpranke2a294622015-08-07 05:23:01504 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30505 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46506 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30507
Rohit Raof9b096d2019-09-09 22:26:23508 declare_args() {
509 # Keep the unittest-as-xctest functionality defaulted to off until the
510 # bots are updated to handle it properly.
511 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
512 # supports running unittests with xctest.
513 enable_run_ios_unittests_with_xctest = false
514 }
515
sdefresne012857872016-03-16 10:55:37516 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27517 _output_name = target_name
518 if (defined(invoker.output_name)) {
519 _output_name = invoker.output_name
520 }
521
Jeff Yoonf7f4eb42020-03-06 18:55:36522 _wrapper_output_name = "run_${target_name}"
523 ios_test_runner_wrapper(_wrapper_output_name) {
524 forward_variables_from(invoker,
525 [
526 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36527 "deps",
528 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27529 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36530 "retries",
531 "shards",
532 ])
533
534 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
535
536 if (!defined(executable_args)) {
537 executable_args = []
538 }
539 executable_args += [
540 "--app",
541 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
542 ]
543
544 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22545
546 if (!defined(data)) {
547 data = []
548 }
Jamie Madilldd60ee62021-04-13 19:25:52549 if (tests_have_location_tags) {
550 data += [ "//testing/location_tags.json" ]
551 }
Jeff Yoonf7f4eb42020-03-06 18:55:36552 }
553
sdefresne012857872016-03-16 10:55:37554 _resources_bundle_data = target_name + "_resources_bundle_data"
555
556 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34557 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22558 sources = [ "//testing/gtest_ios/Default.png" ]
559 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01560 }
561
Mirko Bonadei15522bc2020-09-16 20:38:39562 force_xctest = enable_run_ios_unittests_with_xctest ||
563 (defined(invoker.is_xctest) && invoker.is_xctest)
564
565 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23566 ios_test_target_type = "ios_xctest_test"
567 } else {
568 ios_test_target_type = "ios_app_bundle"
569 }
570
571 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01572 testonly = true
sdefresnea828c282016-05-30 18:04:20573
Mirko Bonadei15522bc2020-09-16 20:38:39574 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23575 xctest_module_target = "//base/test:google_test_runner"
576 }
577
Andrew Grieve1b290e4a22020-11-24 20:07:01578 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13579
580 # Provide sensible defaults in case invoker did not define any of those
581 # required variables.
sdefresne05b97ca2016-06-08 07:19:46582 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13583 info_plist = "//testing/gtest_ios/unittest-Info.plist"
584 }
sdefresne9e147e02016-06-07 00:10:13585
Sylvain Defresne3c5a1312021-09-23 17:08:09586 if (ios_use_shared_bundle_id_for_test_apps) {
Ali Juma75be0fe2022-01-24 19:39:29587 bundle_identifier = "$ios_app_bundle_id_prefix.chrome.unittests"
Ali Jumaff45dd82021-11-08 21:53:50588 not_needed([ "_output_name" ])
Sylvain Defresne3c5a1312021-09-23 17:08:09589 } else {
Ali Juma75be0fe2022-01-24 19:39:29590 bundle_identifier = "$ios_app_bundle_id_prefix.chrome." +
Sylvain Defresne3f48aedc2021-10-07 10:17:27591 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09592 }
dpranke2a294622015-08-07 05:23:01593
sdefresne047490e2016-07-22 08:49:34594 if (!defined(bundle_deps)) {
595 bundle_deps = []
596 }
597 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36598
599 if (!defined(data_deps)) {
600 data_deps = []
601 }
602
603 # Include the generate_wrapper as part of data_deps
604 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46605 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59606
607 if (use_rts) {
608 data_deps += [ ":${invoker.target_name}__rts_filters" ]
609 }
dpranke2a294622015-08-07 05:23:01610 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11611 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
612 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30613 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
614
Yuke Liao2a9b2f0e2021-04-16 00:40:11615 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32616
Benjamin Pastene3bce864e2018-04-14 01:16:32617 _gen_runner_target = "${target_name}__runner"
618 _runtime_deps_file =
619 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
620 "/" + get_label_info(target_name, "name") + ".runtime_deps"
621
Xinan Lin6be01252021-06-25 23:07:36622 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
623 if (is_skylab) {
624 generate_skylab_runner_script(_gen_runner_target) {
625 generated_script = _generated_script
626 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34627 }
Xinan Lin6be01252021-06-25 23:07:36628 } else {
629 generate_runner_script(_gen_runner_target) {
630 generated_script = _generated_script
631 test_exe = invoker.target_name
632 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34633
Xinan Lin6be01252021-06-25 23:07:36634 if (is_chromeos_lacros) {
635 # At build time, Lacros tests don't know whether they'll run on VM or
636 # HW, and instead, these flags are specified at runtime when invoking
637 # the generated runner script.
638 skip_generating_board_args = true
639 }
Greg Guterman6963dc082021-04-07 05:20:59640
Xinan Lin6be01252021-06-25 23:07:36641 if (tests_have_location_tags) {
642 data = [ "//testing/location_tags.json" ]
643 }
644
645 if (use_rts) {
646 data_deps = [ ":${invoker.target_name}__rts_filters" ]
647 }
Greg Guterman6963dc082021-04-07 05:20:59648 }
Benjamin Pastene3bce864e2018-04-14 01:16:32649 }
650
danakj02dddc42022-02-11 23:24:30651 mixed_executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01652 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
653 forward_variables_from(invoker, [ "visibility" ])
danakje94f40d2022-02-16 18:13:53654 rs_configs = [ "//build/rust:test" ]
Benjamin Pastene3bce864e2018-04-14 01:16:32655 if (!defined(deps)) {
656 deps = []
657 }
658 if (!defined(data)) {
659 data = []
660 }
661
Ben Pastene41041782019-02-16 04:21:58662 # We use a special trigger script for CrOS hardware tests.
663 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
664
Benjamin Pastene3bce864e2018-04-14 01:16:32665 output_name = target_name
666 write_runtime_deps = _runtime_deps_file
667 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37668 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59669
670 if (use_rts) {
671 if (!defined(data_deps)) {
672 data_deps = []
673 }
674 data_deps += [ ":${invoker.target_name}__rts_filters" ]
675 }
Benjamin Pastene3bce864e2018-04-14 01:16:32676 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11677 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24678 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
679 _executable = target_name
680 _gen_runner_target = "${target_name}__runner"
681
Yuke Liao32af4242020-07-16 21:48:02682 if (defined(invoker.use_xvfb)) {
683 _use_xvfb = invoker.use_xvfb
684 } else {
685 _use_xvfb = false
686 }
687
Yuke Liaod037abc2020-10-06 22:48:22688 # When use_xvfb is set by the invoker, it indicates that running this test
689 # target requires a window, and in lacros build, ash-chrome serves as the
690 # display server. Note that even though the tests themselves do not require
691 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
692 # because ash-chrome is based on x11.
693 _use_ash_chrome = _use_xvfb
694
Yuke Liaoe703384b2020-07-16 01:05:24695 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24696 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02697
Yuke Liao2e4953cf2020-07-26 19:20:19698 data = []
Will Harrisd35e2c92021-04-07 01:42:02699 data_deps = [ "//testing:test_scripts_shared" ]
700
Yuke Liao32af4242020-07-16 21:48:02701 if (_use_xvfb) {
702 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:22703 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:02704 } else {
705 executable = "//testing/test_env.py"
706 }
Jamie Madilldd60ee62021-04-13 19:25:52707 if (tests_have_location_tags) {
708 data += [ "//testing/location_tags.json" ]
709 }
Yuke Liao32af4242020-07-16 21:48:02710
Yuke Liaoe703384b2020-07-16 01:05:24711 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02712 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39713 "test",
Yuke Liaoe703384b2020-07-16 01:05:24714 "@WrappedPath(./${_executable})",
715 "--test-launcher-bot-mode",
716 ]
Yuke Liao32af4242020-07-16 21:48:02717
Yuke Liaof540c742020-07-29 16:28:34718 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37719 executable_args += [ "--ash-chrome-path" ]
720
721 # Can't use --ash-chrome-path=path because WrappedPath
722 # won't be expanded for that usage.
723 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39724 }
725
Yuke Liaoe703384b2020-07-16 01:05:24726 if (is_asan) {
727 executable_args += [ "--asan=true" ]
728 }
729 if (is_msan) {
730 executable_args += [ "--msan=true" ]
731 }
732 if (is_tsan) {
733 executable_args += [ "--tsan=true" ]
734 }
735 if (use_cfi_diag) {
736 executable_args += [ "--cfi-diag=true" ]
737 }
738
Takuto Ikuta38ebd0e2022-01-19 17:56:22739 data += [ "//build/lacros/test_runner.py" ]
Greg Guterman6963dc082021-04-07 05:20:59740
741 if (use_rts) {
742 data_deps += [ ":${invoker.target_name}__rts_filters" ]
743 }
Yuke Liaoe703384b2020-07-16 01:05:24744 }
745
danakj02dddc42022-02-11 23:24:30746 mixed_executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01747 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
748 forward_variables_from(invoker, [ "visibility" ])
danakje94f40d2022-02-16 18:13:53749 rs_configs = [ "//build/rust:test" ]
Yuke Liaoe703384b2020-07-16 01:05:24750 if (!defined(deps)) {
751 deps = []
752 }
753
Yuke Liaod037abc2020-10-06 22:48:22754 if (!defined(data_deps)) {
755 data_deps = []
756 }
757
Yuke Liaoe703384b2020-07-16 01:05:24758 write_runtime_deps = _runtime_deps_file
759 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22760 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56761 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22762 }
Greg Guterman6963dc082021-04-07 05:20:59763
764 if (use_rts) {
765 data_deps += [ ":${invoker.target_name}__rts_filters" ]
766 }
Yuke Liaoe703384b2020-07-16 01:05:24767 }
Dirk Prankedd4ff742020-11-18 19:57:32768 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30769 if (is_mac || is_win) {
770 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
771 }
772
Dirk Prankedd4ff742020-11-18 19:57:32773 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
774 _executable = target_name
775 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06776
Dirk Prankedd4ff742020-11-18 19:57:32777 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
778 _use_xvfb = invoker.use_xvfb
779 } else {
780 _use_xvfb = false
781 }
782
783 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32784 wrapper_script = "$root_build_dir/bin/run_" + _executable
785
786 data = []
Will Harrisd35e2c92021-04-07 01:42:02787 data_deps = [ "//testing:test_scripts_shared" ]
788
Dirk Prankedd4ff742020-11-18 19:57:32789 if (_use_xvfb) {
790 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06791 } else {
Dirk Prankedd4ff742020-11-18 19:57:32792 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06793 }
Jamie Madilldd60ee62021-04-13 19:25:52794 if (tests_have_location_tags) {
795 data += [ "//testing/location_tags.json" ]
796 }
Dirk Pranke31e346e2020-07-15 00:54:06797
Dirk Prankedd4ff742020-11-18 19:57:32798 executable_args = [
799 "@WrappedPath(./${_executable})",
800 "--test-launcher-bot-mode",
801 ]
802 if (is_asan) {
803 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06804 }
Dirk Prankedd4ff742020-11-18 19:57:32805 if (is_msan) {
806 executable_args += [ "--msan=true" ]
807 }
808 if (is_tsan) {
809 executable_args += [ "--tsan=true" ]
810 }
811 if (use_cfi_diag) {
812 executable_args += [ "--cfi-diag=true" ]
813 }
814
815 data += [ "//.vpython" ]
Greg Guterman6963dc082021-04-07 05:20:59816
817 if (use_rts) {
818 data_deps += [ ":${invoker.target_name}__rts_filters" ]
819 }
Dirk Pranke31e346e2020-07-15 00:54:06820 }
821
danakj02dddc42022-02-11 23:24:30822 mixed_executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01823 forward_variables_from(invoker,
824 "*",
825 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
826 forward_variables_from(invoker, [ "visibility" ])
danakje94f40d2022-02-16 18:13:53827 rs_configs = [ "//build/rust:test" ]
Dirk Pranke31e346e2020-07-15 00:54:06828 if (!defined(deps)) {
829 deps = []
830 }
831
Dirk Pranke31e346e2020-07-15 00:54:06832 deps += [
833 # Give tests the default manifest on Windows (a no-op elsewhere).
834 "//build/win:default_exe_manifest",
835 ]
836
Dirk Prankedd4ff742020-11-18 19:57:32837 write_runtime_deps = _runtime_deps_file
838 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11839
840 if (use_rts) {
841 if (!defined(data_deps)) {
842 data_deps = []
843 }
844 data_deps += [ ":${invoker.target_name}__rts_filters" ]
845 }
Dirk Prankedd4ff742020-11-18 19:57:32846 }
847 } else {
848 # This is a catch-all clause for NaCl toolchains and other random
849 # configurations that might define tests; test() in these configs
850 # will just define the underlying executables.
851 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
852 "use_xvfb should not be defined for a non-linux configuration")
danakj02dddc42022-02-11 23:24:30853 mixed_executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01854 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
855 forward_variables_from(invoker, [ "visibility" ])
danakje94f40d2022-02-16 18:13:53856 rs_configs = [ "//build/rust:test" ]
Dirk Prankedd4ff742020-11-18 19:57:32857 if (!defined(deps)) {
858 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06859 }
Greg Guterman6963dc082021-04-07 05:20:59860
861 if (use_rts) {
862 if (!defined(data_deps)) {
863 data_deps = []
864 }
865 data_deps += [ ":${invoker.target_name}__rts_filters" ]
866 }
Dirk Pranke31e346e2020-07-15 00:54:06867 }
qsrfb5251d12015-01-21 15:57:22868 }
869}
brettwedb6ecc2016-07-14 23:37:03870
Dirk Pranke6188075b2020-10-01 19:31:28871# Defines a type of test that invokes a script to run, rather than
872# invoking an executable.
873#
874# The script must implement the
875# [test executable API](//docs/testing/test_executable_api.md).
876#
877# The template must be passed the `script` parameter, which specifies
878# the path to the script to run. It may optionally be passed a
879# `script_args` parameter, which can be used to include a list of
880# args to be specified by default. The template will produce
881# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
882# for the target to $root_build_dir/${target_name}.runtime_deps, as per
883# the conventions listed in the
884# [test wrapper API](//docs/testing/test_wrapper_api.md).
885template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:59886 if (use_rts) {
887 action("${target_name}__rts_filters") {
888 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53889 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:59890 args = [ rebase_path(rts_file, root_build_dir) ]
891 outputs = [ rts_file ]
892 }
893 }
894
Dirk Pranke6188075b2020-10-01 19:31:28895 generate_wrapper(target_name) {
896 testonly = true
897 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
898
899 executable = "//testing/test_env.py"
900
901 executable_args =
902 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
903 if (defined(invoker.args)) {
904 executable_args += invoker.args
905 }
906
Will Harrisd35e2c92021-04-07 01:42:02907 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:47908
909 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
910 use_vpython3 = false
911 data += [ "//.vpython" ]
Dirk Pranke2dd666cd2021-03-03 16:57:47912 }
913
Dirk Pranke6188075b2020-10-01 19:31:28914 if (defined(invoker.data)) {
915 data += invoker.data
916 }
Jamie Madilldd60ee62021-04-13 19:25:52917 if (tests_have_location_tags) {
918 data += [ "//testing/location_tags.json" ]
919 }
Dirk Pranke19a58732021-03-24 22:26:22920
Will Harrisd35e2c92021-04-07 01:42:02921 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:28922 if (defined(invoker.data_deps)) {
923 data_deps += invoker.data_deps
924 }
925
926 forward_variables_from(invoker,
927 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01928 TESTONLY_AND_VISIBILITY + [
929 "data",
930 "data_deps",
931 "script",
932 "script_args",
933 ])
934 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28935
936 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:59937
938 if (use_rts) {
939 data_deps += [ ":${invoker.target_name}__rts_filters" ]
940 }
Dirk Pranke6188075b2020-10-01 19:31:28941 }
942}
943
brettwedb6ecc2016-07-14 23:37:03944# Test defaults.
945set_defaults("test") {
946 if (is_android) {
947 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41948 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59949 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03950 } else {
951 configs = default_executable_configs
Leonard Grey077a28302021-12-16 14:14:26952 if (is_mac) {
953 # TODO(lgrey): Maybe restore this.
954 # Don't strip tests for visibility into test crashes/hangs.
955 # https://bugs.chromium.org/p/chromium/issues/detail?id=1244047#c49
956 configs -= [ "//build/config/mac:strip_all" ]
957 }
brettwedb6ecc2016-07-14 23:37:03958 }
959}