blob: 0e0e35e90bcb71731d81535d6a29611037a97293 [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
Chong Guc6bfdf62021-10-20 23:37:00410 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15411 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25412 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42413
Kevin Marshall5fadadd2021-10-16 00:08:25414 if (!defined(deps)) {
415 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52416 }
Kevin Marshall5fadadd2021-10-16 00:08:25417 if (defined(invoker.deps)) {
418 deps += invoker.deps
419 }
Greg Guterman6963dc082021-04-07 05:20:59420
Kevin Marshall5fadadd2021-10-16 00:08:25421 if (!defined(data)) {
422 data = []
423 }
424 if (tests_have_location_tags) {
425 data += [ "//testing/location_tags.json" ]
426 }
427
428 if (!defined(data_deps)) {
429 data_deps = []
430 }
Chong Guc6bfdf62021-10-20 23:37:00431 data_deps += [ "//testing/buildbot/filters:fuchsia_filters" ]
Chong Gu258e22c2021-10-20 18:39:50432
Greg Guterman6963dc082021-04-07 05:20:59433 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25434 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59435 }
Kevin Marshallf35fa5f2018-01-29 19:24:42436 }
437
438 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01439 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42440 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03441 }
dpranke2a294622015-08-07 05:23:01442 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30443 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46444 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30445
Rohit Raof9b096d2019-09-09 22:26:23446 declare_args() {
447 # Keep the unittest-as-xctest functionality defaulted to off until the
448 # bots are updated to handle it properly.
449 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
450 # supports running unittests with xctest.
451 enable_run_ios_unittests_with_xctest = false
452 }
453
sdefresne012857872016-03-16 10:55:37454 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27455 _output_name = target_name
456 if (defined(invoker.output_name)) {
457 _output_name = invoker.output_name
458 }
459
Jeff Yoonf7f4eb42020-03-06 18:55:36460 _wrapper_output_name = "run_${target_name}"
461 ios_test_runner_wrapper(_wrapper_output_name) {
462 forward_variables_from(invoker,
463 [
464 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36465 "deps",
466 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27467 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36468 "retries",
469 "shards",
470 ])
471
472 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
473
474 if (!defined(executable_args)) {
475 executable_args = []
476 }
477 executable_args += [
478 "--app",
479 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
480 ]
481
482 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22483
484 if (!defined(data)) {
485 data = []
486 }
Jamie Madilldd60ee62021-04-13 19:25:52487 if (tests_have_location_tags) {
488 data += [ "//testing/location_tags.json" ]
489 }
Jeff Yoonf7f4eb42020-03-06 18:55:36490 }
491
sdefresne012857872016-03-16 10:55:37492 _resources_bundle_data = target_name + "_resources_bundle_data"
493
494 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34495 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22496 sources = [ "//testing/gtest_ios/Default.png" ]
497 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01498 }
499
Mirko Bonadei15522bc2020-09-16 20:38:39500 force_xctest = enable_run_ios_unittests_with_xctest ||
501 (defined(invoker.is_xctest) && invoker.is_xctest)
502
503 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23504 ios_test_target_type = "ios_xctest_test"
505 } else {
506 ios_test_target_type = "ios_app_bundle"
507 }
508
509 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01510 testonly = true
sdefresnea828c282016-05-30 18:04:20511
Mirko Bonadei15522bc2020-09-16 20:38:39512 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23513 xctest_module_target = "//base/test:google_test_runner"
514 }
515
Andrew Grieve1b290e4a22020-11-24 20:07:01516 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13517
518 # Provide sensible defaults in case invoker did not define any of those
519 # required variables.
sdefresne05b97ca2016-06-08 07:19:46520 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13521 info_plist = "//testing/gtest_ios/unittest-Info.plist"
522 }
sdefresne9e147e02016-06-07 00:10:13523
Sylvain Defresne3c5a1312021-09-23 17:08:09524 if (ios_use_shared_bundle_id_for_test_apps) {
Sylvain Defresne3f48aedc2021-10-07 10:17:27525 bundle_identifier = "$ios_app_bundle_id_prefix.gtest.unittests"
Sylvain Defresne3c5a1312021-09-23 17:08:09526 } else {
Sylvain Defresne3f48aedc2021-10-07 10:17:27527 bundle_identifier = "$ios_app_bundle_id_prefix.gtest." +
528 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09529 }
dpranke2a294622015-08-07 05:23:01530
sdefresne047490e2016-07-22 08:49:34531 if (!defined(bundle_deps)) {
532 bundle_deps = []
533 }
534 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36535
536 if (!defined(data_deps)) {
537 data_deps = []
538 }
539
540 # Include the generate_wrapper as part of data_deps
541 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46542 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59543
544 if (use_rts) {
545 data_deps += [ ":${invoker.target_name}__rts_filters" ]
546 }
dpranke2a294622015-08-07 05:23:01547 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11548 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
549 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30550 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
551
Yuke Liao2a9b2f0e2021-04-16 00:40:11552 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32553
Benjamin Pastene3bce864e2018-04-14 01:16:32554 _gen_runner_target = "${target_name}__runner"
555 _runtime_deps_file =
556 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
557 "/" + get_label_info(target_name, "name") + ".runtime_deps"
558
Xinan Lin6be01252021-06-25 23:07:36559 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
560 if (is_skylab) {
561 generate_skylab_runner_script(_gen_runner_target) {
562 generated_script = _generated_script
563 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34564 }
Xinan Lin6be01252021-06-25 23:07:36565 } else {
566 generate_runner_script(_gen_runner_target) {
567 generated_script = _generated_script
568 test_exe = invoker.target_name
569 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34570
Xinan Lin6be01252021-06-25 23:07:36571 if (is_chromeos_lacros) {
572 # At build time, Lacros tests don't know whether they'll run on VM or
573 # HW, and instead, these flags are specified at runtime when invoking
574 # the generated runner script.
575 skip_generating_board_args = true
576 }
Greg Guterman6963dc082021-04-07 05:20:59577
Xinan Lin6be01252021-06-25 23:07:36578 if (tests_have_location_tags) {
579 data = [ "//testing/location_tags.json" ]
580 }
581
582 if (use_rts) {
583 data_deps = [ ":${invoker.target_name}__rts_filters" ]
584 }
Greg Guterman6963dc082021-04-07 05:20:59585 }
Benjamin Pastene3bce864e2018-04-14 01:16:32586 }
587
588 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01589 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
590 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32591 if (!defined(deps)) {
592 deps = []
593 }
594 if (!defined(data)) {
595 data = []
596 }
597
Ben Pastene41041782019-02-16 04:21:58598 # We use a special trigger script for CrOS hardware tests.
599 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
600
Benjamin Pastene3bce864e2018-04-14 01:16:32601 output_name = target_name
602 write_runtime_deps = _runtime_deps_file
603 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37604 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59605
606 if (use_rts) {
607 if (!defined(data_deps)) {
608 data_deps = []
609 }
610 data_deps += [ ":${invoker.target_name}__rts_filters" ]
611 }
Benjamin Pastene3bce864e2018-04-14 01:16:32612 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11613 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24614 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
615 _executable = target_name
616 _gen_runner_target = "${target_name}__runner"
617
Yuke Liao32af4242020-07-16 21:48:02618 if (defined(invoker.use_xvfb)) {
619 _use_xvfb = invoker.use_xvfb
620 } else {
621 _use_xvfb = false
622 }
623
Yuke Liaod037abc2020-10-06 22:48:22624 # When use_xvfb is set by the invoker, it indicates that running this test
625 # target requires a window, and in lacros build, ash-chrome serves as the
626 # display server. Note that even though the tests themselves do not require
627 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
628 # because ash-chrome is based on x11.
629 _use_ash_chrome = _use_xvfb
630
Yuke Liaoe703384b2020-07-16 01:05:24631 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24632 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02633
Yuke Liao2e4953cf2020-07-26 19:20:19634 data = []
Will Harrisd35e2c92021-04-07 01:42:02635 data_deps = [ "//testing:test_scripts_shared" ]
636
Yuke Liao32af4242020-07-16 21:48:02637 if (_use_xvfb) {
638 executable = "//testing/xvfb.py"
639 } else {
640 executable = "//testing/test_env.py"
641 }
Jamie Madilldd60ee62021-04-13 19:25:52642 if (tests_have_location_tags) {
643 data += [ "//testing/location_tags.json" ]
644 }
Yuke Liao32af4242020-07-16 21:48:02645
Yuke Liaoe703384b2020-07-16 01:05:24646 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02647 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39648 "test",
Yuke Liaoe703384b2020-07-16 01:05:24649 "@WrappedPath(./${_executable})",
650 "--test-launcher-bot-mode",
651 ]
Yuke Liao32af4242020-07-16 21:48:02652
Yuke Liaof540c742020-07-29 16:28:34653 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37654 executable_args += [ "--ash-chrome-path" ]
655
656 # Can't use --ash-chrome-path=path because WrappedPath
657 # won't be expanded for that usage.
658 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39659 }
660
Yuke Liaoe703384b2020-07-16 01:05:24661 if (is_asan) {
662 executable_args += [ "--asan=true" ]
663 }
664 if (is_msan) {
665 executable_args += [ "--msan=true" ]
666 }
667 if (is_tsan) {
668 executable_args += [ "--tsan=true" ]
669 }
670 if (use_cfi_diag) {
671 executable_args += [ "--cfi-diag=true" ]
672 }
673
Yuke Liao2e4953cf2020-07-26 19:20:19674 data += [
Yuke Liao240816d2020-07-22 00:10:39675 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24676 "//.vpython",
677 ]
Greg Guterman6963dc082021-04-07 05:20:59678
679 if (use_rts) {
680 data_deps += [ ":${invoker.target_name}__rts_filters" ]
681 }
Yuke Liaoe703384b2020-07-16 01:05:24682 }
683
684 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01685 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
686 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24687 if (!defined(deps)) {
688 deps = []
689 }
690
Yuke Liaod037abc2020-10-06 22:48:22691 if (!defined(data_deps)) {
692 data_deps = []
693 }
694
Yuke Liaoe703384b2020-07-16 01:05:24695 write_runtime_deps = _runtime_deps_file
696 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22697 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56698 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22699 }
Greg Guterman6963dc082021-04-07 05:20:59700
701 if (use_rts) {
702 data_deps += [ ":${invoker.target_name}__rts_filters" ]
703 }
Yuke Liaoe703384b2020-07-16 01:05:24704 }
Dirk Prankedd4ff742020-11-18 19:57:32705 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30706 if (is_mac || is_win) {
707 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
708 }
709
Dirk Prankedd4ff742020-11-18 19:57:32710 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
711 _executable = target_name
712 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06713
Dirk Prankedd4ff742020-11-18 19:57:32714 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
715 _use_xvfb = invoker.use_xvfb
716 } else {
717 _use_xvfb = false
718 }
719
720 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32721 wrapper_script = "$root_build_dir/bin/run_" + _executable
722
723 data = []
Will Harrisd35e2c92021-04-07 01:42:02724 data_deps = [ "//testing:test_scripts_shared" ]
725
Dirk Prankedd4ff742020-11-18 19:57:32726 if (_use_xvfb) {
727 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06728 } else {
Dirk Prankedd4ff742020-11-18 19:57:32729 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06730 }
Jamie Madilldd60ee62021-04-13 19:25:52731 if (tests_have_location_tags) {
732 data += [ "//testing/location_tags.json" ]
733 }
Dirk Pranke31e346e2020-07-15 00:54:06734
Dirk Prankedd4ff742020-11-18 19:57:32735 executable_args = [
736 "@WrappedPath(./${_executable})",
737 "--test-launcher-bot-mode",
738 ]
739 if (is_asan) {
740 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06741 }
Dirk Prankedd4ff742020-11-18 19:57:32742 if (is_msan) {
743 executable_args += [ "--msan=true" ]
744 }
745 if (is_tsan) {
746 executable_args += [ "--tsan=true" ]
747 }
748 if (use_cfi_diag) {
749 executable_args += [ "--cfi-diag=true" ]
750 }
751
752 data += [ "//.vpython" ]
Greg Guterman6963dc082021-04-07 05:20:59753
754 if (use_rts) {
755 data_deps += [ ":${invoker.target_name}__rts_filters" ]
756 }
Dirk Pranke31e346e2020-07-15 00:54:06757 }
758
759 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01760 forward_variables_from(invoker,
761 "*",
762 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
763 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06764 if (!defined(deps)) {
765 deps = []
766 }
767
Dirk Pranke31e346e2020-07-15 00:54:06768 deps += [
769 # Give tests the default manifest on Windows (a no-op elsewhere).
770 "//build/win:default_exe_manifest",
771 ]
772
Dirk Prankedd4ff742020-11-18 19:57:32773 write_runtime_deps = _runtime_deps_file
774 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11775
776 if (use_rts) {
777 if (!defined(data_deps)) {
778 data_deps = []
779 }
780 data_deps += [ ":${invoker.target_name}__rts_filters" ]
781 }
Dirk Prankedd4ff742020-11-18 19:57:32782 }
783 } else {
784 # This is a catch-all clause for NaCl toolchains and other random
785 # configurations that might define tests; test() in these configs
786 # will just define the underlying executables.
787 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
788 "use_xvfb should not be defined for a non-linux configuration")
789 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01790 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
791 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32792 if (!defined(deps)) {
793 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06794 }
Greg Guterman6963dc082021-04-07 05:20:59795
796 if (use_rts) {
797 if (!defined(data_deps)) {
798 data_deps = []
799 }
800 data_deps += [ ":${invoker.target_name}__rts_filters" ]
801 }
Dirk Pranke31e346e2020-07-15 00:54:06802 }
qsrfb5251d12015-01-21 15:57:22803 }
804}
brettwedb6ecc2016-07-14 23:37:03805
Dirk Pranke6188075b2020-10-01 19:31:28806# Defines a type of test that invokes a script to run, rather than
807# invoking an executable.
808#
809# The script must implement the
810# [test executable API](//docs/testing/test_executable_api.md).
811#
812# The template must be passed the `script` parameter, which specifies
813# the path to the script to run. It may optionally be passed a
814# `script_args` parameter, which can be used to include a list of
815# args to be specified by default. The template will produce
816# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
817# for the target to $root_build_dir/${target_name}.runtime_deps, as per
818# the conventions listed in the
819# [test wrapper API](//docs/testing/test_wrapper_api.md).
820template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:59821 if (use_rts) {
822 action("${target_name}__rts_filters") {
823 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53824 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:59825 args = [ rebase_path(rts_file, root_build_dir) ]
826 outputs = [ rts_file ]
827 }
828 }
829
Dirk Pranke6188075b2020-10-01 19:31:28830 generate_wrapper(target_name) {
831 testonly = true
832 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
833
834 executable = "//testing/test_env.py"
835
836 executable_args =
837 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
838 if (defined(invoker.args)) {
839 executable_args += invoker.args
840 }
841
Will Harrisd35e2c92021-04-07 01:42:02842 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:47843
844 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
845 use_vpython3 = false
846 data += [ "//.vpython" ]
847 } else {
848 use_vpython3 = true
849 data += [ "//.vpython3" ]
850 }
851
Dirk Pranke6188075b2020-10-01 19:31:28852 if (defined(invoker.data)) {
853 data += invoker.data
854 }
Jamie Madilldd60ee62021-04-13 19:25:52855 if (tests_have_location_tags) {
856 data += [ "//testing/location_tags.json" ]
857 }
Dirk Pranke19a58732021-03-24 22:26:22858
Will Harrisd35e2c92021-04-07 01:42:02859 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:28860 if (defined(invoker.data_deps)) {
861 data_deps += invoker.data_deps
862 }
863
864 forward_variables_from(invoker,
865 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01866 TESTONLY_AND_VISIBILITY + [
867 "data",
868 "data_deps",
869 "script",
870 "script_args",
871 ])
872 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28873
874 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:59875
876 if (use_rts) {
877 data_deps += [ ":${invoker.target_name}__rts_filters" ]
878 }
Dirk Pranke6188075b2020-10-01 19:31:28879 }
880}
881
brettwedb6ecc2016-07-14 23:37:03882# Test defaults.
883set_defaults("test") {
884 if (is_android) {
885 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41886 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59887 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03888 } else {
889 configs = default_executable_configs
890 }
891}