blob: ec9317eac1b1304ebcc985cdb2dd12cbfbd1d312 [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")
Dirk Prankeb404c3b2021-06-14 19:57:5011import("//build/config/gclient_args.gni")
Greg Guterman28b3cba2021-05-12 22:21:0312import("//build/config/rts.gni")
Mirko Bonadei4a0df432020-09-08 19:06:0213import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2414
Greg Guterman6963dc082021-04-07 05:20:5915declare_args() {
Dirk Prankeb404c3b2021-06-14 19:57:5016 # Some component repos (e.g. ANGLE) import //testing but do not have
17 # "location_tags.json", and so we don't want to try and upload the tags
18 # for their tests.
19 # And, some build configs may simply turn off generation altogether.
20 tests_have_location_tags = generate_location_tags
Greg Guterman6963dc082021-04-07 05:20:5921}
22
jcivellif4462a352017-01-10 04:45:5923if (is_android) {
24 import("//build/config/android/config.gni")
James Cook209256f2018-12-07 18:40:5025 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5926 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4427 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3228} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0629 import("//build/config/chromecast_build.gni")
Kevin Marshall55fd8522019-10-04 22:47:0130 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4231 import("//build/config/fuchsia/package.gni")
Chong Gu26908f4e2021-01-29 03:13:0732 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Yuke Liaoe502a742021-04-19 23:15:0233} else if ((is_chromeos_ash || is_chromeos_lacros) && is_chromeos_device) {
Ben Pastene4c35c572018-04-30 23:21:4834 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3235 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2836 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3237} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3638 import("//build/config/ios/ios_sdk.gni")
39 import("//build/config/ios/ios_test_runner_wrapper.gni")
40 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3241} else {
Dirk Pranke31e346e2020-07-15 00:54:0642 import("//build/config/sanitizers/sanitizers.gni")
43 import("//build/util/generate_wrapper.gni")
44}
45
qsrfb5251d12015-01-21 15:57:2246# Define a test as an executable (or apk on Android) with the "testonly" flag
47# set.
agrieve62ab00282016-04-05 02:03:4548# Variable:
Dirk Pranke79d065d2020-08-29 03:28:3049# use_xvfb: (optional) whether to run the executable under Xvfb.
agrieve62ab00282016-04-05 02:03:4550# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:5651# use_native_activity: Test implements ANativeActivity_onCreate().
Mirko Bonadei15522bc2020-09-16 20:38:3952# is_xctest: (iOS, optional) whether to build the executable as XCTest.
53# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
54# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:4355# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
56# network requests during the test.
qsrfb5251d12015-01-21 15:57:2257template("test") {
Greg Guterman6963dc082021-04-07 05:20:5958 # Ensures the rts file exists and if not, creates a dummy file
59 if (use_rts) {
60 action("${target_name}__rts_filters") {
61 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:5362 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:5963 args = [ rebase_path(rts_file, root_build_dir) ]
64 outputs = [ rts_file ]
65 }
66 }
67
Andrew Grieve1b290e4a22020-11-24 20:07:0168 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:3969 if (!is_ios) {
70 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
71 "is_xctest can be set only for iOS builds")
72 }
Stefano Duo4128b6b2021-08-02 21:24:4373 if (!is_android) {
74 assert(!defined(invoker.allow_cleartext_traffic),
75 "allow_cleartext_traffic can be set only for Android tests")
76 }
77
qsrfb5251d12015-01-21 15:57:2278 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3079 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
80
Peter Kotwicz10742f82021-04-15 22:32:5081 _use_default_launcher =
82 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
83 if (!defined(invoker.use_raw_android_executable)) {
84 # Checkouts where build_with_chromium == false often have a custom GN
85 # template wrapper around test() which sets use_default_launcher == false.
86 # Set the _use_raw_android_executable default so that test() targets which
87 # do not use the custom wrapper
88 # (1) Do not cause "gn gen" to fail
89 # (2) Do not need to be moved into if(build_with_chromium) block.
90 _use_raw_android_executable =
91 !build_with_chromium && _use_default_launcher
92 } else {
93 not_needed([ "_use_default_launcher" ])
94 _use_raw_android_executable = invoker.use_raw_android_executable
95 }
qsrfb5251d12015-01-21 15:57:2296
agrieve67855de2016-03-30 14:46:0197 # output_name is used to allow targets with the same name but in different
98 # packages to still produce unique runner scripts.
99 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26100 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01101 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26102 }
agrieve62ab00282016-04-05 02:03:45103
agrieveb355ad152016-04-19 03:45:23104 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42105 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:51106 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42107 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51108 ]
agrieve3ac557f02016-04-12 15:52:00109
jbudorickced2a252016-06-09 16:38:54110 assert(_use_raw_android_executable || enable_java_templates)
111
agrieve62ab00282016-04-05 02:03:45112 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49113 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
114
agrieve62ab00282016-04-05 02:03:45115 _exec_target = "${target_name}__exec"
116 _dist_target = "${target_name}__dist"
117 _exec_output =
118 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
119
120 executable(_exec_target) {
121 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
122 configs = []
Dirk Pranke19a58732021-03-24 22:26:22123 forward_variables_from(
124 invoker,
125 "*",
126 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
127 "data_deps",
128 "extra_dist_files",
129 ])
agrieve62ab00282016-04-05 02:03:45130
131 # Thanks to the set_defaults() for test(), configs are initialized with
132 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59133 configs -= [
134 "//build/config:shared_library_config",
135 "//build/config/android:hide_all_but_jni",
136 ]
agrieve62ab00282016-04-05 02:03:45137 configs += [ "//build/config:executable_config" ]
138
Dirk Pranke19a58732021-03-24 22:26:22139 if (defined(invoker.data_deps)) {
140 data_deps = invoker.data_deps
141 } else {
142 data_deps = []
143 }
144 if (!defined(data)) {
145 data = []
146 }
Jamie Madilldd60ee62021-04-13 19:25:52147 if (tests_have_location_tags) {
148 data += [ "//testing/location_tags.json" ]
149 }
Dirk Pranke19a58732021-03-24 22:26:22150
agrieve62ab00282016-04-05 02:03:45151 # Don't output to the root or else conflict with the group() below.
152 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11153
154 if (use_rts) {
155 data_deps += [ ":${invoker.target_name}__rts_filters" ]
156 }
agrieve62ab00282016-04-05 02:03:45157 }
158
159 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45160 dist_dir = "$root_out_dir/$target_name"
161 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22162 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45163 if (defined(invoker.extra_dist_files)) {
164 extra_files = invoker.extra_dist_files
165 }
Greg Guterman50ed4b42021-04-08 01:15:11166
167 if (use_rts) {
168 if (!defined(data_deps)) {
169 data_deps = []
170 }
171 data_deps += [ ":${invoker.target_name}__rts_filters" ]
172 }
agrieve62ab00282016-04-05 02:03:45173 }
174 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02175 _library_target = "${target_name}__library"
176 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45177 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43178 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45179 "android_manifest",
agrievec6811b422016-06-23 02:25:09180 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27181 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55182 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45183 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50184 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07185 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02186 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07187 "proguard_configs",
188 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45189 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02190 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45191 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56192 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45193 ]
Siddhartha764226b2018-03-13 02:32:55194
195 # Adds the unwind tables from unstripped binary as an asset file in the
196 # apk, if |add_unwind_tables_in_apk| is specified by the test.
197 if (defined(invoker.add_unwind_tables_in_apk) &&
198 invoker.add_unwind_tables_in_apk) {
199 _unwind_table_asset_name = "${target_name}_unwind_assets"
200 unwind_table_asset(_unwind_table_asset_name) {
Siddhartha764226b2018-03-13 02:32:55201 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22202 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55203 }
204 }
205
agrieve62ab00282016-04-05 02:03:45206 shared_library(_library_target) {
207 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
208 configs = [] # Prevent list overwriting warning.
209 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45210
jbudorickd29ecfa72016-11-18 22:45:42211 forward_variables_from(
212 invoker,
213 "*",
Peter Wen2052bd12020-12-03 20:15:07214 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
215 TESTONLY_AND_VISIBILITY)
216
217 # Native targets do not need to depend on java targets. Filter them out
218 # so that the shared library can be built without needing to wait for
219 # dependent java targets.
220 deps = []
221 if (defined(invoker.deps)) {
222 foreach(_dep, invoker.deps) {
223 _target_label = get_label_info(_dep, "label_no_toolchain")
224 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
225 deps += [ _dep ]
226 }
227 }
228 }
agrieve62ab00282016-04-05 02:03:45229
Peter Kotwiczb9957d62021-04-12 21:09:43230 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37231 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45232 }
233 }
234 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54235 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07236 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45237 apk_name = invoker.target_name
238 if (defined(invoker.output_name)) {
239 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45240 install_script_name = "install_${invoker.output_name}"
241 }
agrieveb355ad152016-04-19 03:45:23242
Daniel Bratellfdda4652019-01-31 15:45:54243 if (defined(invoker.deps)) {
244 deps = invoker.deps
245 } else {
246 deps = []
247 }
248
jcivellif4462a352017-01-10 04:45:59249 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43250 if (_use_default_launcher) {
251 deps += [ "//base/test:test_support_java" ]
252 }
jcivellif4462a352017-01-10 04:45:59253
Siddhartha764226b2018-03-13 02:32:55254 if (defined(_unwind_table_asset_name)) {
255 deps += [ ":${_unwind_table_asset_name}" ]
256 }
Greg Guterman50ed4b42021-04-08 01:15:11257
258 if (use_rts) {
259 data_deps = [ ":${invoker.target_name}__rts_filters" ]
260 }
agrieve62ab00282016-04-05 02:03:45261 }
Andrew Grievee1dc23f2019-10-22 16:26:36262 }
agrieve62ab00282016-04-05 02:03:45263
Andrew Grievee1dc23f2019-10-22 16:26:36264 test_runner_script(_test_runner_target) {
265 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57266
Andrew Grievee1dc23f2019-10-22 16:26:36267 if (_use_raw_android_executable) {
268 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34269 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36270 } else {
271 apk_target = ":$_apk_target"
272 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47273
274 # Dep needed for the test runner .runtime_deps file to pick up data
275 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22276 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45277 }
Andrew Grievee1dc23f2019-10-22 16:26:36278 test_name = _output_name
279 test_suite = _output_name
280 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59281
282 if (use_rts) {
283 data_deps += [ ":${invoker.target_name}__rts_filters" ]
284 }
mikecase56d80d72015-06-03 00:57:26285 }
286
Andrew Grieve7ca6de32019-10-18 03:57:47287 # Create a wrapper script rather than using a group() in order to ensure
288 # "ninja $target_name" always works. If this was a group(), then GN would
289 # not create a top-level alias for it if a target exists in another
290 # directory with the same $target_name.
291 # Also - bots run this script directly for "components_perftests".
292 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01293 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47294 executable = "$root_build_dir/bin/run_$_output_name"
295 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22296 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40297 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47298 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40299 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47300 # Dep needed for the swarming .isolate file to pick up data
301 # deps from the forward_variables_from(invoker, "*") on the library.
302 deps += [
303 ":$_apk_target",
304 ":$_library_target",
305 ]
agrieve62ab00282016-04-05 02:03:45306 }
Dirk Pranke19a58732021-03-24 22:26:22307
308 if (defined(invoker.data_deps)) {
309 data_deps = invoker.data_deps
310 } else {
311 data_deps = []
312 }
Jamie Madilldd60ee62021-04-13 19:25:52313 if (tests_have_location_tags) {
314 data = [ "//testing/location_tags.json" ]
315 }
Greg Guterman6963dc082021-04-07 05:20:59316
317 if (use_rts) {
318 data_deps += [ ":${invoker.target_name}__rts_filters" ]
319 }
agrieve1a02e582015-10-15 21:35:39320 }
Scott Graham4c4cdc52017-05-29 20:45:03321 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30322 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
323
Scott Graham4c4cdc52017-05-29 20:45:03324 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42325 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42326 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03327
Wez6879f8a2021-09-07 20:27:02328 # Generate a CMX fragment that provides the program name.
329 _test_program_fragment_target = "${target_name}_program-fragment"
330 _test_program_fragment = "${target_out_dir}/${target_name}_program.test-cmx"
331 _program_name = get_label_info(":${_exec_target}", "name")
332 generated_file(_test_program_fragment_target) {
333 contents = "{ \"program\": { \"binary\": \"${_program_name}\"}}"
334 outputs = [ _test_program_fragment ]
335 }
Chong Gu26908f4e2021-01-29 03:13:07336
Wez6879f8a2021-09-07 20:27:02337 # Collate the complete set of elements to include in the test component's
338 # manifest.
339 _manifest_fragments = [
340 "//build/config/fuchsia/test/minimum_capabilities.test-cmx",
341 _test_program_fragment,
342 ]
Chong Gu91a1fea2021-03-30 17:24:31343 if (defined(invoker.additional_manifest_fragments)) {
Wez6879f8a2021-09-07 20:27:02344 _manifest_fragments += invoker.additional_manifest_fragments
Chong Guacf19a32021-03-10 01:07:41345 }
Chong Gu28bf7e72021-05-26 01:36:19346
Wez6879f8a2021-09-07 20:27:02347 # Generate the test component manifest from the specified elements.
348 _test_component_manifest_target = "${target_name}_component-manifest"
349 _test_component_manifest = "${target_out_dir}/${target_name}.cmx"
350 cmc_merge(_test_component_manifest_target) {
351 sources = _manifest_fragments
352 output_name = "${_output_name}.cmx"
353 deps = [ ":${_test_program_fragment_target}" ]
Chong Gu7ad57c22021-03-11 00:24:38354 }
Chong Gu26908f4e2021-01-29 03:13:07355
Wez6879f8a2021-09-07 20:27:02356 # Define the test component, dependent on the generated manifest, and the
357 # test executable target.
358 _test_component_target = "${target_name}_component"
359 fuchsia_component(_test_component_target) {
360 deps = [ ":$_test_component_manifest_target" ]
361 data_deps = [ ":$_exec_target" ]
362 manifest = _test_component_manifest
363 visibility = [ ":*" ]
364 }
365
366 # Define components for each entry in |additional_manifests|, if any. Since
367 # manifests may themselves depend-on the outputs of |deps|, these components
368 # must each individually depend on |invoker.deps|.
369 _test_component_targets = [ ":${_test_component_target}" ]
370 if (defined(invoker.additional_manifests)) {
371 foreach(filename, invoker.additional_manifests) {
372 _additional_component_target =
373 target_name + "_" + get_path_info(filename, "name")
374 _test_component_targets += [ ":${_additional_component_target}" ]
375 fuchsia_component(_additional_component_target) {
376 forward_variables_from(invoker, [ "testonly" ])
377 data_deps = [ ":$_exec_target" ]
378 visibility = [ ":*" ]
379 manifest = filename
380
381 # Depend on |invoker.deps|, in case it includes a dependency that
382 # creates this additional component's manifest.
383 if (defined(invoker.deps)) {
384 deps = invoker.deps
385 }
386 }
387 }
388 }
389
390 # Define the package target that will bundle the test and additional
391 # components and their data.
392 fuchsia_package(_pkg_target) {
393 forward_variables_from(invoker, [ "excluded_files" ])
394 package_name = _output_name
395 deps = _test_component_targets
396 }
397
398 # |target_name| refers to the package-runner rule, so that building
399 # "base_unittests" will build not only the executable, component, and
400 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25401 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53402 forward_variables_from(invoker,
403 [
Kevin Marshall5fadadd2021-10-16 00:08:25404 "data",
405 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53406 "package_deps",
Kevin Marshall5fadadd2021-10-16 00:08:25407 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53408 ])
Kevin Marshall5fadadd2021-10-16 00:08:25409
Kevin Marshall39b4aa82018-06-23 00:12:15410 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25411 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42412
Kevin Marshall5fadadd2021-10-16 00:08:25413 if (!defined(deps)) {
414 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52415 }
Kevin Marshall5fadadd2021-10-16 00:08:25416 if (defined(invoker.deps)) {
417 deps += invoker.deps
418 }
Greg Guterman6963dc082021-04-07 05:20:59419
Kevin Marshall5fadadd2021-10-16 00:08:25420 if (!defined(data)) {
421 data = []
422 }
423 if (tests_have_location_tags) {
424 data += [ "//testing/location_tags.json" ]
425 }
426
427 if (!defined(data_deps)) {
428 data_deps = []
429 }
Chong Gu258e22c2021-10-20 18:39:50430 data_deps += [
431 "//testing:test_scripts_shared",
432 "//testing/buildbot/filters:fuchsia_filters",
433 ]
434
Greg Guterman6963dc082021-04-07 05:20:59435 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25436 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59437 }
Kevin Marshallf35fa5f2018-01-29 19:24:42438 }
439
440 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01441 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42442 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03443 }
dpranke2a294622015-08-07 05:23:01444 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30445 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46446 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30447
Rohit Raof9b096d2019-09-09 22:26:23448 declare_args() {
449 # Keep the unittest-as-xctest functionality defaulted to off until the
450 # bots are updated to handle it properly.
451 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
452 # supports running unittests with xctest.
453 enable_run_ios_unittests_with_xctest = false
454 }
455
sdefresne012857872016-03-16 10:55:37456 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27457 _output_name = target_name
458 if (defined(invoker.output_name)) {
459 _output_name = invoker.output_name
460 }
461
Jeff Yoonf7f4eb42020-03-06 18:55:36462 _wrapper_output_name = "run_${target_name}"
463 ios_test_runner_wrapper(_wrapper_output_name) {
464 forward_variables_from(invoker,
465 [
466 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36467 "deps",
468 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27469 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36470 "retries",
471 "shards",
472 ])
473
474 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
475
476 if (!defined(executable_args)) {
477 executable_args = []
478 }
479 executable_args += [
480 "--app",
481 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
482 ]
483
484 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22485
486 if (!defined(data)) {
487 data = []
488 }
Jamie Madilldd60ee62021-04-13 19:25:52489 if (tests_have_location_tags) {
490 data += [ "//testing/location_tags.json" ]
491 }
Jeff Yoonf7f4eb42020-03-06 18:55:36492 }
493
sdefresne012857872016-03-16 10:55:37494 _resources_bundle_data = target_name + "_resources_bundle_data"
495
496 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34497 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22498 sources = [ "//testing/gtest_ios/Default.png" ]
499 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01500 }
501
Mirko Bonadei15522bc2020-09-16 20:38:39502 force_xctest = enable_run_ios_unittests_with_xctest ||
503 (defined(invoker.is_xctest) && invoker.is_xctest)
504
505 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23506 ios_test_target_type = "ios_xctest_test"
507 } else {
508 ios_test_target_type = "ios_app_bundle"
509 }
510
511 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01512 testonly = true
sdefresnea828c282016-05-30 18:04:20513
Mirko Bonadei15522bc2020-09-16 20:38:39514 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23515 xctest_module_target = "//base/test:google_test_runner"
516 }
517
Andrew Grieve1b290e4a22020-11-24 20:07:01518 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13519
520 # Provide sensible defaults in case invoker did not define any of those
521 # required variables.
sdefresne05b97ca2016-06-08 07:19:46522 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13523 info_plist = "//testing/gtest_ios/unittest-Info.plist"
524 }
sdefresne9e147e02016-06-07 00:10:13525
Sylvain Defresne3c5a1312021-09-23 17:08:09526 if (ios_use_shared_bundle_id_for_test_apps) {
Sylvain Defresne3f48aedc2021-10-07 10:17:27527 bundle_identifier = "$ios_app_bundle_id_prefix.gtest.unittests"
Sylvain Defresne3c5a1312021-09-23 17:08:09528 } else {
Sylvain Defresne3f48aedc2021-10-07 10:17:27529 bundle_identifier = "$ios_app_bundle_id_prefix.gtest." +
530 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09531 }
dpranke2a294622015-08-07 05:23:01532
sdefresne047490e2016-07-22 08:49:34533 if (!defined(bundle_deps)) {
534 bundle_deps = []
535 }
536 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36537
538 if (!defined(data_deps)) {
539 data_deps = []
540 }
541
542 # Include the generate_wrapper as part of data_deps
543 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46544 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59545
546 if (use_rts) {
547 data_deps += [ ":${invoker.target_name}__rts_filters" ]
548 }
dpranke2a294622015-08-07 05:23:01549 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11550 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
551 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30552 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
553
Yuke Liao2a9b2f0e2021-04-16 00:40:11554 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32555
Benjamin Pastene3bce864e2018-04-14 01:16:32556 _gen_runner_target = "${target_name}__runner"
557 _runtime_deps_file =
558 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
559 "/" + get_label_info(target_name, "name") + ".runtime_deps"
560
Xinan Lin6be01252021-06-25 23:07:36561 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
562 if (is_skylab) {
563 generate_skylab_runner_script(_gen_runner_target) {
564 generated_script = _generated_script
565 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34566 }
Xinan Lin6be01252021-06-25 23:07:36567 } else {
568 generate_runner_script(_gen_runner_target) {
569 generated_script = _generated_script
570 test_exe = invoker.target_name
571 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34572
Xinan Lin6be01252021-06-25 23:07:36573 if (is_chromeos_lacros) {
574 # At build time, Lacros tests don't know whether they'll run on VM or
575 # HW, and instead, these flags are specified at runtime when invoking
576 # the generated runner script.
577 skip_generating_board_args = true
578 }
Greg Guterman6963dc082021-04-07 05:20:59579
Xinan Lin6be01252021-06-25 23:07:36580 if (tests_have_location_tags) {
581 data = [ "//testing/location_tags.json" ]
582 }
583
584 if (use_rts) {
585 data_deps = [ ":${invoker.target_name}__rts_filters" ]
586 }
Greg Guterman6963dc082021-04-07 05:20:59587 }
Benjamin Pastene3bce864e2018-04-14 01:16:32588 }
589
590 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01591 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
592 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32593 if (!defined(deps)) {
594 deps = []
595 }
596 if (!defined(data)) {
597 data = []
598 }
599
Ben Pastene41041782019-02-16 04:21:58600 # We use a special trigger script for CrOS hardware tests.
601 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
602
Benjamin Pastene3bce864e2018-04-14 01:16:32603 output_name = target_name
604 write_runtime_deps = _runtime_deps_file
605 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37606 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59607
608 if (use_rts) {
609 if (!defined(data_deps)) {
610 data_deps = []
611 }
612 data_deps += [ ":${invoker.target_name}__rts_filters" ]
613 }
Benjamin Pastene3bce864e2018-04-14 01:16:32614 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11615 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24616 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
617 _executable = target_name
618 _gen_runner_target = "${target_name}__runner"
619
Yuke Liao32af4242020-07-16 21:48:02620 if (defined(invoker.use_xvfb)) {
621 _use_xvfb = invoker.use_xvfb
622 } else {
623 _use_xvfb = false
624 }
625
Yuke Liaod037abc2020-10-06 22:48:22626 # When use_xvfb is set by the invoker, it indicates that running this test
627 # target requires a window, and in lacros build, ash-chrome serves as the
628 # display server. Note that even though the tests themselves do not require
629 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
630 # because ash-chrome is based on x11.
631 _use_ash_chrome = _use_xvfb
632
Yuke Liaoe703384b2020-07-16 01:05:24633 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24634 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02635
Yuke Liao2e4953cf2020-07-26 19:20:19636 data = []
Will Harrisd35e2c92021-04-07 01:42:02637 data_deps = [ "//testing:test_scripts_shared" ]
638
Yuke Liao32af4242020-07-16 21:48:02639 if (_use_xvfb) {
640 executable = "//testing/xvfb.py"
641 } else {
642 executable = "//testing/test_env.py"
643 }
Jamie Madilldd60ee62021-04-13 19:25:52644 if (tests_have_location_tags) {
645 data += [ "//testing/location_tags.json" ]
646 }
Yuke Liao32af4242020-07-16 21:48:02647
Yuke Liaoe703384b2020-07-16 01:05:24648 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02649 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39650 "test",
Yuke Liaoe703384b2020-07-16 01:05:24651 "@WrappedPath(./${_executable})",
652 "--test-launcher-bot-mode",
653 ]
Yuke Liao32af4242020-07-16 21:48:02654
Yuke Liaof540c742020-07-29 16:28:34655 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37656 executable_args += [ "--ash-chrome-path" ]
657
658 # Can't use --ash-chrome-path=path because WrappedPath
659 # won't be expanded for that usage.
660 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39661 }
662
Yuke Liaoe703384b2020-07-16 01:05:24663 if (is_asan) {
664 executable_args += [ "--asan=true" ]
665 }
666 if (is_msan) {
667 executable_args += [ "--msan=true" ]
668 }
669 if (is_tsan) {
670 executable_args += [ "--tsan=true" ]
671 }
672 if (use_cfi_diag) {
673 executable_args += [ "--cfi-diag=true" ]
674 }
675
Yuke Liao2e4953cf2020-07-26 19:20:19676 data += [
Yuke Liao240816d2020-07-22 00:10:39677 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24678 "//.vpython",
679 ]
Greg Guterman6963dc082021-04-07 05:20:59680
681 if (use_rts) {
682 data_deps += [ ":${invoker.target_name}__rts_filters" ]
683 }
Yuke Liaoe703384b2020-07-16 01:05:24684 }
685
686 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01687 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
688 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24689 if (!defined(deps)) {
690 deps = []
691 }
692
Yuke Liaod037abc2020-10-06 22:48:22693 if (!defined(data_deps)) {
694 data_deps = []
695 }
696
Yuke Liaoe703384b2020-07-16 01:05:24697 write_runtime_deps = _runtime_deps_file
698 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22699 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56700 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22701 }
Greg Guterman6963dc082021-04-07 05:20:59702
703 if (use_rts) {
704 data_deps += [ ":${invoker.target_name}__rts_filters" ]
705 }
Yuke Liaoe703384b2020-07-16 01:05:24706 }
Dirk Prankedd4ff742020-11-18 19:57:32707 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30708 if (is_mac || is_win) {
709 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
710 }
711
Dirk Prankedd4ff742020-11-18 19:57:32712 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
713 _executable = target_name
714 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06715
Dirk Prankedd4ff742020-11-18 19:57:32716 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
717 _use_xvfb = invoker.use_xvfb
718 } else {
719 _use_xvfb = false
720 }
721
722 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32723 wrapper_script = "$root_build_dir/bin/run_" + _executable
724
725 data = []
Will Harrisd35e2c92021-04-07 01:42:02726 data_deps = [ "//testing:test_scripts_shared" ]
727
Dirk Prankedd4ff742020-11-18 19:57:32728 if (_use_xvfb) {
729 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06730 } else {
Dirk Prankedd4ff742020-11-18 19:57:32731 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06732 }
Jamie Madilldd60ee62021-04-13 19:25:52733 if (tests_have_location_tags) {
734 data += [ "//testing/location_tags.json" ]
735 }
Dirk Pranke31e346e2020-07-15 00:54:06736
Dirk Prankedd4ff742020-11-18 19:57:32737 executable_args = [
738 "@WrappedPath(./${_executable})",
739 "--test-launcher-bot-mode",
740 ]
741 if (is_asan) {
742 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06743 }
Dirk Prankedd4ff742020-11-18 19:57:32744 if (is_msan) {
745 executable_args += [ "--msan=true" ]
746 }
747 if (is_tsan) {
748 executable_args += [ "--tsan=true" ]
749 }
750 if (use_cfi_diag) {
751 executable_args += [ "--cfi-diag=true" ]
752 }
753
754 data += [ "//.vpython" ]
Greg Guterman6963dc082021-04-07 05:20:59755
756 if (use_rts) {
757 data_deps += [ ":${invoker.target_name}__rts_filters" ]
758 }
Dirk Pranke31e346e2020-07-15 00:54:06759 }
760
761 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01762 forward_variables_from(invoker,
763 "*",
764 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
765 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06766 if (!defined(deps)) {
767 deps = []
768 }
769
Dirk Pranke31e346e2020-07-15 00:54:06770 deps += [
771 # Give tests the default manifest on Windows (a no-op elsewhere).
772 "//build/win:default_exe_manifest",
773 ]
774
Dirk Prankedd4ff742020-11-18 19:57:32775 write_runtime_deps = _runtime_deps_file
776 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11777
778 if (use_rts) {
779 if (!defined(data_deps)) {
780 data_deps = []
781 }
782 data_deps += [ ":${invoker.target_name}__rts_filters" ]
783 }
Dirk Prankedd4ff742020-11-18 19:57:32784 }
785 } else {
786 # This is a catch-all clause for NaCl toolchains and other random
787 # configurations that might define tests; test() in these configs
788 # will just define the underlying executables.
789 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
790 "use_xvfb should not be defined for a non-linux configuration")
791 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01792 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
793 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32794 if (!defined(deps)) {
795 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06796 }
Greg Guterman6963dc082021-04-07 05:20:59797
798 if (use_rts) {
799 if (!defined(data_deps)) {
800 data_deps = []
801 }
802 data_deps += [ ":${invoker.target_name}__rts_filters" ]
803 }
Dirk Pranke31e346e2020-07-15 00:54:06804 }
qsrfb5251d12015-01-21 15:57:22805 }
806}
brettwedb6ecc2016-07-14 23:37:03807
Dirk Pranke6188075b2020-10-01 19:31:28808# Defines a type of test that invokes a script to run, rather than
809# invoking an executable.
810#
811# The script must implement the
812# [test executable API](//docs/testing/test_executable_api.md).
813#
814# The template must be passed the `script` parameter, which specifies
815# the path to the script to run. It may optionally be passed a
816# `script_args` parameter, which can be used to include a list of
817# args to be specified by default. The template will produce
818# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
819# for the target to $root_build_dir/${target_name}.runtime_deps, as per
820# the conventions listed in the
821# [test wrapper API](//docs/testing/test_wrapper_api.md).
822template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:59823 if (use_rts) {
824 action("${target_name}__rts_filters") {
825 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53826 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:59827 args = [ rebase_path(rts_file, root_build_dir) ]
828 outputs = [ rts_file ]
829 }
830 }
831
Dirk Pranke6188075b2020-10-01 19:31:28832 generate_wrapper(target_name) {
833 testonly = true
834 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
835
836 executable = "//testing/test_env.py"
837
838 executable_args =
839 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
840 if (defined(invoker.args)) {
841 executable_args += invoker.args
842 }
843
Will Harrisd35e2c92021-04-07 01:42:02844 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:47845
846 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
847 use_vpython3 = false
848 data += [ "//.vpython" ]
849 } else {
850 use_vpython3 = true
851 data += [ "//.vpython3" ]
852 }
853
Dirk Pranke6188075b2020-10-01 19:31:28854 if (defined(invoker.data)) {
855 data += invoker.data
856 }
Jamie Madilldd60ee62021-04-13 19:25:52857 if (tests_have_location_tags) {
858 data += [ "//testing/location_tags.json" ]
859 }
Dirk Pranke19a58732021-03-24 22:26:22860
Will Harrisd35e2c92021-04-07 01:42:02861 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:28862 if (defined(invoker.data_deps)) {
863 data_deps += invoker.data_deps
864 }
865
866 forward_variables_from(invoker,
867 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01868 TESTONLY_AND_VISIBILITY + [
869 "data",
870 "data_deps",
871 "script",
872 "script_args",
873 ])
874 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28875
876 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:59877
878 if (use_rts) {
879 data_deps += [ ":${invoker.target_name}__rts_filters" ]
880 }
Dirk Pranke6188075b2020-10-01 19:31:28881 }
882}
883
brettwedb6ecc2016-07-14 23:37:03884# Test defaults.
885set_defaults("test") {
886 if (is_android) {
887 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41888 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59889 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03890 } else {
891 configs = default_executable_configs
892 }
893}