blob: bc664d40acb9e691a29b0f10fa44d7d9c7cc8211 [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")
Mirko Bonadei4a0df432020-09-08 19:06:0214import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2415
Greg Guterman6963dc082021-04-07 05:20:5916declare_args() {
Dirk Prankeb404c3b2021-06-14 19:57:5017 # Some component repos (e.g. ANGLE) import //testing but do not have
18 # "location_tags.json", and so we don't want to try and upload the tags
19 # for their tests.
20 # And, some build configs may simply turn off generation altogether.
21 tests_have_location_tags = generate_location_tags
Greg Guterman6963dc082021-04-07 05:20:5922}
23
jcivellif4462a352017-01-10 04:45:5924if (is_android) {
25 import("//build/config/android/config.gni")
James Cook209256f2018-12-07 18:40:5026 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5927 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4428 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3229} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0630 import("//build/config/chromecast_build.gni")
Kevin Marshall55fd8522019-10-04 22:47:0131 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4232 import("//build/config/fuchsia/package.gni")
Chong Gu26908f4e2021-01-29 03:13:0733 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Yuke Liaoe502a742021-04-19 23:15:0234} else if ((is_chromeos_ash || is_chromeos_lacros) && is_chromeos_device) {
Ben Pastene4c35c572018-04-30 23:21:4835 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3236 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2837 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3238} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3639 import("//build/config/ios/ios_sdk.gni")
40 import("//build/config/ios/ios_test_runner_wrapper.gni")
41 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3242} else {
Dirk Pranke31e346e2020-07-15 00:54:0643 import("//build/config/sanitizers/sanitizers.gni")
44 import("//build/util/generate_wrapper.gni")
45}
46
qsrfb5251d12015-01-21 15:57:2247# Define a test as an executable (or apk on Android) with the "testonly" flag
48# set.
agrieve62ab00282016-04-05 02:03:4549# Variable:
Dirk Pranke79d065d2020-08-29 03:28:3050# use_xvfb: (optional) whether to run the executable under Xvfb.
agrieve62ab00282016-04-05 02:03:4551# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:5652# use_native_activity: Test implements ANativeActivity_onCreate().
Mirko Bonadei15522bc2020-09-16 20:38:3953# is_xctest: (iOS, optional) whether to build the executable as XCTest.
54# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
55# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:4356# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
57# network requests during the test.
qsrfb5251d12015-01-21 15:57:2258template("test") {
Greg Guterman6963dc082021-04-07 05:20:5959 # Ensures the rts file exists and if not, creates a dummy file
60 if (use_rts) {
61 action("${target_name}__rts_filters") {
62 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:5363 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:5964 args = [ rebase_path(rts_file, root_build_dir) ]
65 outputs = [ rts_file ]
66 }
67 }
68
Andrew Grieve1b290e4a22020-11-24 20:07:0169 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:3970 if (!is_ios) {
71 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
72 "is_xctest can be set only for iOS builds")
73 }
Stefano Duo4128b6b2021-08-02 21:24:4374 if (!is_android) {
75 assert(!defined(invoker.allow_cleartext_traffic),
76 "allow_cleartext_traffic can be set only for Android tests")
77 }
78
qsrfb5251d12015-01-21 15:57:2279 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3080 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
81
Peter Kotwicz10742f82021-04-15 22:32:5082 _use_default_launcher =
83 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
84 if (!defined(invoker.use_raw_android_executable)) {
85 # Checkouts where build_with_chromium == false often have a custom GN
86 # template wrapper around test() which sets use_default_launcher == false.
87 # Set the _use_raw_android_executable default so that test() targets which
88 # do not use the custom wrapper
89 # (1) Do not cause "gn gen" to fail
90 # (2) Do not need to be moved into if(build_with_chromium) block.
91 _use_raw_android_executable =
92 !build_with_chromium && _use_default_launcher
93 } else {
94 not_needed([ "_use_default_launcher" ])
95 _use_raw_android_executable = invoker.use_raw_android_executable
96 }
qsrfb5251d12015-01-21 15:57:2297
agrieve67855de2016-03-30 14:46:0198 # output_name is used to allow targets with the same name but in different
99 # packages to still produce unique runner scripts.
100 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26101 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01102 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26103 }
agrieve62ab00282016-04-05 02:03:45104
agrieveb355ad152016-04-19 03:45:23105 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42106 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:51107 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42108 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51109 ]
agrieve3ac557f02016-04-12 15:52:00110
jbudorickced2a252016-06-09 16:38:54111 assert(_use_raw_android_executable || enable_java_templates)
112
agrieve62ab00282016-04-05 02:03:45113 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49114 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
115
agrieve62ab00282016-04-05 02:03:45116 _exec_target = "${target_name}__exec"
117 _dist_target = "${target_name}__dist"
118 _exec_output =
119 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
120
121 executable(_exec_target) {
122 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
123 configs = []
Dirk Pranke19a58732021-03-24 22:26:22124 forward_variables_from(
125 invoker,
126 "*",
127 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
128 "data_deps",
129 "extra_dist_files",
130 ])
agrieve62ab00282016-04-05 02:03:45131
132 # Thanks to the set_defaults() for test(), configs are initialized with
133 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59134 configs -= [
135 "//build/config:shared_library_config",
136 "//build/config/android:hide_all_but_jni",
137 ]
agrieve62ab00282016-04-05 02:03:45138 configs += [ "//build/config:executable_config" ]
139
Dirk Pranke19a58732021-03-24 22:26:22140 if (defined(invoker.data_deps)) {
141 data_deps = invoker.data_deps
142 } else {
143 data_deps = []
144 }
145 if (!defined(data)) {
146 data = []
147 }
Jamie Madilldd60ee62021-04-13 19:25:52148 if (tests_have_location_tags) {
149 data += [ "//testing/location_tags.json" ]
150 }
Dirk Pranke19a58732021-03-24 22:26:22151
agrieve62ab00282016-04-05 02:03:45152 # Don't output to the root or else conflict with the group() below.
153 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11154
155 if (use_rts) {
156 data_deps += [ ":${invoker.target_name}__rts_filters" ]
157 }
agrieve62ab00282016-04-05 02:03:45158 }
159
160 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45161 dist_dir = "$root_out_dir/$target_name"
162 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22163 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45164 if (defined(invoker.extra_dist_files)) {
165 extra_files = invoker.extra_dist_files
166 }
Greg Guterman50ed4b42021-04-08 01:15:11167
168 if (use_rts) {
169 if (!defined(data_deps)) {
170 data_deps = []
171 }
172 data_deps += [ ":${invoker.target_name}__rts_filters" ]
173 }
agrieve62ab00282016-04-05 02:03:45174 }
175 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02176 _library_target = "${target_name}__library"
177 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45178 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43179 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45180 "android_manifest",
agrievec6811b422016-06-23 02:25:09181 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27182 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55183 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45184 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50185 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07186 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02187 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07188 "proguard_configs",
189 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45190 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02191 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45192 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56193 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45194 ]
Siddhartha764226b2018-03-13 02:32:55195
196 # Adds the unwind tables from unstripped binary as an asset file in the
197 # apk, if |add_unwind_tables_in_apk| is specified by the test.
198 if (defined(invoker.add_unwind_tables_in_apk) &&
199 invoker.add_unwind_tables_in_apk) {
200 _unwind_table_asset_name = "${target_name}_unwind_assets"
201 unwind_table_asset(_unwind_table_asset_name) {
Siddhartha764226b2018-03-13 02:32:55202 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22203 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55204 }
205 }
206
agrieve62ab00282016-04-05 02:03:45207 shared_library(_library_target) {
208 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
209 configs = [] # Prevent list overwriting warning.
210 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45211
jbudorickd29ecfa72016-11-18 22:45:42212 forward_variables_from(
213 invoker,
214 "*",
Peter Wen2052bd12020-12-03 20:15:07215 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
216 TESTONLY_AND_VISIBILITY)
217
218 # Native targets do not need to depend on java targets. Filter them out
219 # so that the shared library can be built without needing to wait for
220 # dependent java targets.
221 deps = []
222 if (defined(invoker.deps)) {
223 foreach(_dep, invoker.deps) {
224 _target_label = get_label_info(_dep, "label_no_toolchain")
225 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
226 deps += [ _dep ]
227 }
228 }
229 }
agrieve62ab00282016-04-05 02:03:45230
Peter Kotwiczb9957d62021-04-12 21:09:43231 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37232 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45233 }
234 }
235 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54236 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07237 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45238 apk_name = invoker.target_name
239 if (defined(invoker.output_name)) {
240 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45241 install_script_name = "install_${invoker.output_name}"
242 }
agrieveb355ad152016-04-19 03:45:23243
Daniel Bratellfdda4652019-01-31 15:45:54244 if (defined(invoker.deps)) {
245 deps = invoker.deps
246 } else {
247 deps = []
248 }
249
jcivellif4462a352017-01-10 04:45:59250 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43251 if (_use_default_launcher) {
252 deps += [ "//base/test:test_support_java" ]
253 }
jcivellif4462a352017-01-10 04:45:59254
Siddhartha764226b2018-03-13 02:32:55255 if (defined(_unwind_table_asset_name)) {
256 deps += [ ":${_unwind_table_asset_name}" ]
257 }
Greg Guterman50ed4b42021-04-08 01:15:11258
259 if (use_rts) {
260 data_deps = [ ":${invoker.target_name}__rts_filters" ]
261 }
agrieve62ab00282016-04-05 02:03:45262 }
Andrew Grievee1dc23f2019-10-22 16:26:36263 }
agrieve62ab00282016-04-05 02:03:45264
Andrew Grievee1dc23f2019-10-22 16:26:36265 test_runner_script(_test_runner_target) {
266 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57267
Andrew Grievee1dc23f2019-10-22 16:26:36268 if (_use_raw_android_executable) {
269 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34270 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36271 } else {
272 apk_target = ":$_apk_target"
273 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47274
275 # Dep needed for the test runner .runtime_deps file to pick up data
276 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22277 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45278 }
Andrew Grievee1dc23f2019-10-22 16:26:36279 test_name = _output_name
280 test_suite = _output_name
281 test_type = "gtest"
Greg Guterman6963dc082021-04-07 05:20:59282
283 if (use_rts) {
284 data_deps += [ ":${invoker.target_name}__rts_filters" ]
285 }
mikecase56d80d72015-06-03 00:57:26286 }
287
Andrew Grieve7ca6de32019-10-18 03:57:47288 # Create a wrapper script rather than using a group() in order to ensure
289 # "ninja $target_name" always works. If this was a group(), then GN would
290 # not create a top-level alias for it if a target exists in another
291 # directory with the same $target_name.
292 # Also - bots run this script directly for "components_perftests".
293 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01294 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47295 executable = "$root_build_dir/bin/run_$_output_name"
296 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22297 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40298 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47299 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40300 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47301 # Dep needed for the swarming .isolate file to pick up data
302 # deps from the forward_variables_from(invoker, "*") on the library.
303 deps += [
304 ":$_apk_target",
305 ":$_library_target",
306 ]
agrieve62ab00282016-04-05 02:03:45307 }
Dirk Pranke19a58732021-03-24 22:26:22308
309 if (defined(invoker.data_deps)) {
310 data_deps = invoker.data_deps
311 } else {
312 data_deps = []
313 }
Jamie Madilldd60ee62021-04-13 19:25:52314 if (tests_have_location_tags) {
315 data = [ "//testing/location_tags.json" ]
316 }
Greg Guterman6963dc082021-04-07 05:20:59317
318 if (use_rts) {
319 data_deps += [ ":${invoker.target_name}__rts_filters" ]
320 }
agrieve1a02e582015-10-15 21:35:39321 }
Scott Graham4c4cdc52017-05-29 20:45:03322 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30323 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
324
Scott Graham4c4cdc52017-05-29 20:45:03325 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42326 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42327 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03328
Wez6879f8a2021-09-07 20:27:02329 # Generate a CMX fragment that provides the program name.
330 _test_program_fragment_target = "${target_name}_program-fragment"
331 _test_program_fragment = "${target_out_dir}/${target_name}_program.test-cmx"
332 _program_name = get_label_info(":${_exec_target}", "name")
333 generated_file(_test_program_fragment_target) {
334 contents = "{ \"program\": { \"binary\": \"${_program_name}\"}}"
335 outputs = [ _test_program_fragment ]
336 }
Chong Gu26908f4e2021-01-29 03:13:07337
Wez6879f8a2021-09-07 20:27:02338 # Collate the complete set of elements to include in the test component's
339 # manifest.
340 _manifest_fragments = [
341 "//build/config/fuchsia/test/minimum_capabilities.test-cmx",
342 _test_program_fragment,
343 ]
Chong Gu91a1fea2021-03-30 17:24:31344 if (defined(invoker.additional_manifest_fragments)) {
Wez6879f8a2021-09-07 20:27:02345 _manifest_fragments += invoker.additional_manifest_fragments
Chong Guacf19a32021-03-10 01:07:41346 }
Chong Gu28bf7e72021-05-26 01:36:19347
Wez6879f8a2021-09-07 20:27:02348 # Generate the test component manifest from the specified elements.
349 _test_component_manifest_target = "${target_name}_component-manifest"
350 _test_component_manifest = "${target_out_dir}/${target_name}.cmx"
351 cmc_merge(_test_component_manifest_target) {
352 sources = _manifest_fragments
353 output_name = "${_output_name}.cmx"
354 deps = [ ":${_test_program_fragment_target}" ]
Chong Gu7ad57c22021-03-11 00:24:38355 }
Chong Gu26908f4e2021-01-29 03:13:07356
Wez6879f8a2021-09-07 20:27:02357 # Define the test component, dependent on the generated manifest, and the
358 # test executable target.
359 _test_component_target = "${target_name}_component"
360 fuchsia_component(_test_component_target) {
361 deps = [ ":$_test_component_manifest_target" ]
362 data_deps = [ ":$_exec_target" ]
363 manifest = _test_component_manifest
364 visibility = [ ":*" ]
365 }
366
367 # Define components for each entry in |additional_manifests|, if any. Since
368 # manifests may themselves depend-on the outputs of |deps|, these components
369 # must each individually depend on |invoker.deps|.
370 _test_component_targets = [ ":${_test_component_target}" ]
371 if (defined(invoker.additional_manifests)) {
372 foreach(filename, invoker.additional_manifests) {
373 _additional_component_target =
374 target_name + "_" + get_path_info(filename, "name")
375 _test_component_targets += [ ":${_additional_component_target}" ]
376 fuchsia_component(_additional_component_target) {
377 forward_variables_from(invoker, [ "testonly" ])
378 data_deps = [ ":$_exec_target" ]
379 visibility = [ ":*" ]
380 manifest = filename
381
382 # Depend on |invoker.deps|, in case it includes a dependency that
383 # creates this additional component's manifest.
384 if (defined(invoker.deps)) {
385 deps = invoker.deps
386 }
387 }
388 }
389 }
390
391 # Define the package target that will bundle the test and additional
392 # components and their data.
393 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21394 forward_variables_from(invoker,
395 [
396 "excluded_files",
397 "excluded_dirs",
398 ])
Wez6879f8a2021-09-07 20:27:02399 package_name = _output_name
400 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21401
402 if (!defined(excluded_dirs)) {
403 excluded_dirs = []
404 }
405 excluded_dirs += [ devtools_root_location ]
Wez6879f8a2021-09-07 20:27:02406 }
407
408 # |target_name| refers to the package-runner rule, so that building
409 # "base_unittests" will build not only the executable, component, and
410 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25411 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53412 forward_variables_from(invoker,
413 [
Kevin Marshall5fadadd2021-10-16 00:08:25414 "data",
415 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53416 "package_deps",
Kevin Marshall5fadadd2021-10-16 00:08:25417 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53418 ])
Kevin Marshall5fadadd2021-10-16 00:08:25419
Chong Guc6bfdf62021-10-20 23:37:00420 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15421 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25422 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42423
Kevin Marshall5fadadd2021-10-16 00:08:25424 if (!defined(deps)) {
425 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52426 }
Kevin Marshall5fadadd2021-10-16 00:08:25427 if (defined(invoker.deps)) {
428 deps += invoker.deps
429 }
Greg Guterman6963dc082021-04-07 05:20:59430
Kevin Marshall5fadadd2021-10-16 00:08:25431 if (!defined(data)) {
432 data = []
433 }
434 if (tests_have_location_tags) {
435 data += [ "//testing/location_tags.json" ]
436 }
437
438 if (!defined(data_deps)) {
439 data_deps = []
440 }
Chong Guc6bfdf62021-10-20 23:37:00441 data_deps += [ "//testing/buildbot/filters:fuchsia_filters" ]
Chong Gu258e22c2021-10-20 18:39:50442
Greg Guterman6963dc082021-04-07 05:20:59443 if (use_rts) {
Kevin Marshall5fadadd2021-10-16 00:08:25444 data_deps += [ ":${target_name}__rts_filters" ]
Greg Guterman6963dc082021-04-07 05:20:59445 }
Kevin Marshallf35fa5f2018-01-29 19:24:42446 }
447
448 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01449 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42450 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03451 }
dpranke2a294622015-08-07 05:23:01452 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30453 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46454 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30455
Rohit Raof9b096d2019-09-09 22:26:23456 declare_args() {
457 # Keep the unittest-as-xctest functionality defaulted to off until the
458 # bots are updated to handle it properly.
459 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
460 # supports running unittests with xctest.
461 enable_run_ios_unittests_with_xctest = false
462 }
463
sdefresne012857872016-03-16 10:55:37464 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27465 _output_name = target_name
466 if (defined(invoker.output_name)) {
467 _output_name = invoker.output_name
468 }
469
Jeff Yoonf7f4eb42020-03-06 18:55:36470 _wrapper_output_name = "run_${target_name}"
471 ios_test_runner_wrapper(_wrapper_output_name) {
472 forward_variables_from(invoker,
473 [
474 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36475 "deps",
476 "executable_args",
Sylvain Defresne3f48aedc2021-10-07 10:17:27477 "output_name",
Jeff Yoonf7f4eb42020-03-06 18:55:36478 "retries",
479 "shards",
480 ])
481
482 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
483
484 if (!defined(executable_args)) {
485 executable_args = []
486 }
487 executable_args += [
488 "--app",
489 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
490 ]
491
492 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22493
494 if (!defined(data)) {
495 data = []
496 }
Jamie Madilldd60ee62021-04-13 19:25:52497 if (tests_have_location_tags) {
498 data += [ "//testing/location_tags.json" ]
499 }
Jeff Yoonf7f4eb42020-03-06 18:55:36500 }
501
sdefresne012857872016-03-16 10:55:37502 _resources_bundle_data = target_name + "_resources_bundle_data"
503
504 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34505 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22506 sources = [ "//testing/gtest_ios/Default.png" ]
507 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01508 }
509
Mirko Bonadei15522bc2020-09-16 20:38:39510 force_xctest = enable_run_ios_unittests_with_xctest ||
511 (defined(invoker.is_xctest) && invoker.is_xctest)
512
513 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23514 ios_test_target_type = "ios_xctest_test"
515 } else {
516 ios_test_target_type = "ios_app_bundle"
517 }
518
519 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01520 testonly = true
sdefresnea828c282016-05-30 18:04:20521
Mirko Bonadei15522bc2020-09-16 20:38:39522 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23523 xctest_module_target = "//base/test:google_test_runner"
524 }
525
Andrew Grieve1b290e4a22020-11-24 20:07:01526 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13527
528 # Provide sensible defaults in case invoker did not define any of those
529 # required variables.
sdefresne05b97ca2016-06-08 07:19:46530 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13531 info_plist = "//testing/gtest_ios/unittest-Info.plist"
532 }
sdefresne9e147e02016-06-07 00:10:13533
Sylvain Defresne3c5a1312021-09-23 17:08:09534 if (ios_use_shared_bundle_id_for_test_apps) {
Sylvain Defresne3f48aedc2021-10-07 10:17:27535 bundle_identifier = "$ios_app_bundle_id_prefix.gtest.unittests"
Sylvain Defresne3c5a1312021-09-23 17:08:09536 } else {
Sylvain Defresne3f48aedc2021-10-07 10:17:27537 bundle_identifier = "$ios_app_bundle_id_prefix.gtest." +
538 string_replace(_output_name, "_", "-")
Sylvain Defresne3c5a1312021-09-23 17:08:09539 }
dpranke2a294622015-08-07 05:23:01540
sdefresne047490e2016-07-22 08:49:34541 if (!defined(bundle_deps)) {
542 bundle_deps = []
543 }
544 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36545
546 if (!defined(data_deps)) {
547 data_deps = []
548 }
549
550 # Include the generate_wrapper as part of data_deps
551 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46552 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc082021-04-07 05:20:59553
554 if (use_rts) {
555 data_deps += [ ":${invoker.target_name}__rts_filters" ]
556 }
dpranke2a294622015-08-07 05:23:01557 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11558 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
559 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30560 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
561
Yuke Liao2a9b2f0e2021-04-16 00:40:11562 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32563
Benjamin Pastene3bce864e2018-04-14 01:16:32564 _gen_runner_target = "${target_name}__runner"
565 _runtime_deps_file =
566 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
567 "/" + get_label_info(target_name, "name") + ".runtime_deps"
568
Xinan Lin6be01252021-06-25 23:07:36569 _generated_script = "$root_build_dir/bin/run_" + invoker.target_name
570 if (is_skylab) {
571 generate_skylab_runner_script(_gen_runner_target) {
572 generated_script = _generated_script
573 test_exe = invoker.target_name
Yuke Liaoacb74b12021-04-23 23:37:34574 }
Xinan Lin6be01252021-06-25 23:07:36575 } else {
576 generate_runner_script(_gen_runner_target) {
577 generated_script = _generated_script
578 test_exe = invoker.target_name
579 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34580
Xinan Lin6be01252021-06-25 23:07:36581 if (is_chromeos_lacros) {
582 # At build time, Lacros tests don't know whether they'll run on VM or
583 # HW, and instead, these flags are specified at runtime when invoking
584 # the generated runner script.
585 skip_generating_board_args = true
586 }
Greg Guterman6963dc082021-04-07 05:20:59587
Xinan Lin6be01252021-06-25 23:07:36588 if (tests_have_location_tags) {
589 data = [ "//testing/location_tags.json" ]
590 }
591
592 if (use_rts) {
593 data_deps = [ ":${invoker.target_name}__rts_filters" ]
594 }
Greg Guterman6963dc082021-04-07 05:20:59595 }
Benjamin Pastene3bce864e2018-04-14 01:16:32596 }
597
598 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01599 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
600 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32601 if (!defined(deps)) {
602 deps = []
603 }
604 if (!defined(data)) {
605 data = []
606 }
607
Ben Pastene41041782019-02-16 04:21:58608 # We use a special trigger script for CrOS hardware tests.
609 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
610
Benjamin Pastene3bce864e2018-04-14 01:16:32611 output_name = target_name
612 write_runtime_deps = _runtime_deps_file
613 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37614 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59615
616 if (use_rts) {
617 if (!defined(data_deps)) {
618 data_deps = []
619 }
620 data_deps += [ ":${invoker.target_name}__rts_filters" ]
621 }
Benjamin Pastene3bce864e2018-04-14 01:16:32622 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11623 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24624 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
625 _executable = target_name
626 _gen_runner_target = "${target_name}__runner"
627
Yuke Liao32af4242020-07-16 21:48:02628 if (defined(invoker.use_xvfb)) {
629 _use_xvfb = invoker.use_xvfb
630 } else {
631 _use_xvfb = false
632 }
633
Yuke Liaod037abc2020-10-06 22:48:22634 # When use_xvfb is set by the invoker, it indicates that running this test
635 # target requires a window, and in lacros build, ash-chrome serves as the
636 # display server. Note that even though the tests themselves do not require
637 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
638 # because ash-chrome is based on x11.
639 _use_ash_chrome = _use_xvfb
640
Yuke Liaoe703384b2020-07-16 01:05:24641 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24642 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02643
Yuke Liao2e4953cf2020-07-26 19:20:19644 data = []
Will Harrisd35e2c92021-04-07 01:42:02645 data_deps = [ "//testing:test_scripts_shared" ]
646
Yuke Liao32af4242020-07-16 21:48:02647 if (_use_xvfb) {
648 executable = "//testing/xvfb.py"
649 } else {
650 executable = "//testing/test_env.py"
651 }
Jamie Madilldd60ee62021-04-13 19:25:52652 if (tests_have_location_tags) {
653 data += [ "//testing/location_tags.json" ]
654 }
Yuke Liao32af4242020-07-16 21:48:02655
Yuke Liaoe703384b2020-07-16 01:05:24656 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02657 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39658 "test",
Yuke Liaoe703384b2020-07-16 01:05:24659 "@WrappedPath(./${_executable})",
660 "--test-launcher-bot-mode",
661 ]
Yuke Liao32af4242020-07-16 21:48:02662
Yuke Liaof540c742020-07-29 16:28:34663 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:37664 executable_args += [ "--ash-chrome-path" ]
665
666 # Can't use --ash-chrome-path=path because WrappedPath
667 # won't be expanded for that usage.
668 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:39669 }
670
Yuke Liaoe703384b2020-07-16 01:05:24671 if (is_asan) {
672 executable_args += [ "--asan=true" ]
673 }
674 if (is_msan) {
675 executable_args += [ "--msan=true" ]
676 }
677 if (is_tsan) {
678 executable_args += [ "--tsan=true" ]
679 }
680 if (use_cfi_diag) {
681 executable_args += [ "--cfi-diag=true" ]
682 }
683
Yuke Liao2e4953cf2020-07-26 19:20:19684 data += [
Yuke Liao240816d2020-07-22 00:10:39685 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24686 "//.vpython",
687 ]
Greg Guterman6963dc082021-04-07 05:20:59688
689 if (use_rts) {
690 data_deps += [ ":${invoker.target_name}__rts_filters" ]
691 }
Yuke Liaoe703384b2020-07-16 01:05:24692 }
693
694 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01695 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
696 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24697 if (!defined(deps)) {
698 deps = []
699 }
700
Yuke Liaod037abc2020-10-06 22:48:22701 if (!defined(data_deps)) {
702 data_deps = []
703 }
704
Yuke Liaoe703384b2020-07-16 01:05:24705 write_runtime_deps = _runtime_deps_file
706 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22707 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:56708 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:22709 }
Greg Guterman6963dc082021-04-07 05:20:59710
711 if (use_rts) {
712 data_deps += [ ":${invoker.target_name}__rts_filters" ]
713 }
Yuke Liaoe703384b2020-07-16 01:05:24714 }
Dirk Prankedd4ff742020-11-18 19:57:32715 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30716 if (is_mac || is_win) {
717 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
718 }
719
Dirk Prankedd4ff742020-11-18 19:57:32720 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
721 _executable = target_name
722 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06723
Dirk Prankedd4ff742020-11-18 19:57:32724 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
725 _use_xvfb = invoker.use_xvfb
726 } else {
727 _use_xvfb = false
728 }
729
730 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32731 wrapper_script = "$root_build_dir/bin/run_" + _executable
732
733 data = []
Will Harrisd35e2c92021-04-07 01:42:02734 data_deps = [ "//testing:test_scripts_shared" ]
735
Dirk Prankedd4ff742020-11-18 19:57:32736 if (_use_xvfb) {
737 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06738 } else {
Dirk Prankedd4ff742020-11-18 19:57:32739 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06740 }
Jamie Madilldd60ee62021-04-13 19:25:52741 if (tests_have_location_tags) {
742 data += [ "//testing/location_tags.json" ]
743 }
Dirk Pranke31e346e2020-07-15 00:54:06744
Dirk Prankedd4ff742020-11-18 19:57:32745 executable_args = [
746 "@WrappedPath(./${_executable})",
747 "--test-launcher-bot-mode",
748 ]
749 if (is_asan) {
750 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06751 }
Dirk Prankedd4ff742020-11-18 19:57:32752 if (is_msan) {
753 executable_args += [ "--msan=true" ]
754 }
755 if (is_tsan) {
756 executable_args += [ "--tsan=true" ]
757 }
758 if (use_cfi_diag) {
759 executable_args += [ "--cfi-diag=true" ]
760 }
761
762 data += [ "//.vpython" ]
Greg Guterman6963dc082021-04-07 05:20:59763
764 if (use_rts) {
765 data_deps += [ ":${invoker.target_name}__rts_filters" ]
766 }
Dirk Pranke31e346e2020-07-15 00:54:06767 }
768
769 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01770 forward_variables_from(invoker,
771 "*",
772 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
773 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06774 if (!defined(deps)) {
775 deps = []
776 }
777
Dirk Pranke31e346e2020-07-15 00:54:06778 deps += [
779 # Give tests the default manifest on Windows (a no-op elsewhere).
780 "//build/win:default_exe_manifest",
781 ]
782
Dirk Prankedd4ff742020-11-18 19:57:32783 write_runtime_deps = _runtime_deps_file
784 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11785
786 if (use_rts) {
787 if (!defined(data_deps)) {
788 data_deps = []
789 }
790 data_deps += [ ":${invoker.target_name}__rts_filters" ]
791 }
Dirk Prankedd4ff742020-11-18 19:57:32792 }
793 } else {
794 # This is a catch-all clause for NaCl toolchains and other random
795 # configurations that might define tests; test() in these configs
796 # will just define the underlying executables.
797 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
798 "use_xvfb should not be defined for a non-linux configuration")
799 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01800 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
801 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32802 if (!defined(deps)) {
803 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06804 }
Greg Guterman6963dc082021-04-07 05:20:59805
806 if (use_rts) {
807 if (!defined(data_deps)) {
808 data_deps = []
809 }
810 data_deps += [ ":${invoker.target_name}__rts_filters" ]
811 }
Dirk Pranke31e346e2020-07-15 00:54:06812 }
qsrfb5251d12015-01-21 15:57:22813 }
814}
brettwedb6ecc2016-07-14 23:37:03815
Dirk Pranke6188075b2020-10-01 19:31:28816# Defines a type of test that invokes a script to run, rather than
817# invoking an executable.
818#
819# The script must implement the
820# [test executable API](//docs/testing/test_executable_api.md).
821#
822# The template must be passed the `script` parameter, which specifies
823# the path to the script to run. It may optionally be passed a
824# `script_args` parameter, which can be used to include a list of
825# args to be specified by default. The template will produce
826# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
827# for the target to $root_build_dir/${target_name}.runtime_deps, as per
828# the conventions listed in the
829# [test wrapper API](//docs/testing/test_wrapper_api.md).
830template("script_test") {
Greg Guterman6963dc082021-04-07 05:20:59831 if (use_rts) {
832 action("${target_name}__rts_filters") {
833 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53834 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc082021-04-07 05:20:59835 args = [ rebase_path(rts_file, root_build_dir) ]
836 outputs = [ rts_file ]
837 }
838 }
839
Dirk Pranke6188075b2020-10-01 19:31:28840 generate_wrapper(target_name) {
841 testonly = true
842 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
843
844 executable = "//testing/test_env.py"
845
846 executable_args =
847 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
848 if (defined(invoker.args)) {
849 executable_args += invoker.args
850 }
851
Will Harrisd35e2c92021-04-07 01:42:02852 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:47853
854 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
855 use_vpython3 = false
856 data += [ "//.vpython" ]
857 } else {
858 use_vpython3 = true
859 data += [ "//.vpython3" ]
860 }
861
Dirk Pranke6188075b2020-10-01 19:31:28862 if (defined(invoker.data)) {
863 data += invoker.data
864 }
Jamie Madilldd60ee62021-04-13 19:25:52865 if (tests_have_location_tags) {
866 data += [ "//testing/location_tags.json" ]
867 }
Dirk Pranke19a58732021-03-24 22:26:22868
Will Harrisd35e2c92021-04-07 01:42:02869 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:28870 if (defined(invoker.data_deps)) {
871 data_deps += invoker.data_deps
872 }
873
874 forward_variables_from(invoker,
875 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01876 TESTONLY_AND_VISIBILITY + [
877 "data",
878 "data_deps",
879 "script",
880 "script_args",
881 ])
882 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28883
884 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc082021-04-07 05:20:59885
886 if (use_rts) {
887 data_deps += [ ":${invoker.target_name}__rts_filters" ]
888 }
Dirk Pranke6188075b2020-10-01 19:31:28889 }
890}
891
brettwedb6ecc2016-07-14 23:37:03892# Test defaults.
893set_defaults("test") {
894 if (is_android) {
895 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41896 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59897 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03898 } else {
899 configs = default_executable_configs
900 }
901}