[go: nahoru, domu]

blob: dcb883baa09eac8f676bb6fd6170db6d6e255cbb [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")
Greg Guterman28b3cba2021-05-12 22:21:0311import("//build/config/rts.gni")
Mirko Bonadei4a0df432020-09-08 19:06:0212import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2413
Greg Guterman6963dc02021-04-07 05:20:5914declare_args() {
Jamie Madilldd60ee62021-04-13 19:25:5215 # Some component repos (e.g. ANGLE) import //testing but do not have "location_tags.json"
16 tests_have_location_tags = true
Greg Guterman6963dc02021-04-07 05:20:5917}
18
jcivellif4462a352017-01-10 04:45:5919if (is_android) {
20 import("//build/config/android/config.gni")
James Cook209256f2018-12-07 18:40:5021 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5922 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4423 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3224} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0625 import("//build/config/chromecast_build.gni")
Kevin Marshall55fd8522019-10-04 22:47:0126 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4227 import("//build/config/fuchsia/package.gni")
Chong Gu26908f42021-01-29 03:13:0728 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Yuke Liaoe502a742021-04-19 23:15:0229} else if ((is_chromeos_ash || is_chromeos_lacros) && is_chromeos_device) {
Ben Pastene4c35c572018-04-30 23:21:4830 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3231 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2832 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3233} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3634 import("//build/config/ios/ios_sdk.gni")
35 import("//build/config/ios/ios_test_runner_wrapper.gni")
36 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3237} else {
Dirk Pranke31e346e2020-07-15 00:54:0638 import("//build/config/sanitizers/sanitizers.gni")
39 import("//build/util/generate_wrapper.gni")
40}
41
qsrfb5251d12015-01-21 15:57:2242# Define a test as an executable (or apk on Android) with the "testonly" flag
43# set.
agrieve62ab00282016-04-05 02:03:4544# Variable:
Dirk Pranke79d065d2020-08-29 03:28:3045# use_xvfb: (optional) whether to run the executable under Xvfb.
agrieve62ab00282016-04-05 02:03:4546# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:5647# use_native_activity: Test implements ANativeActivity_onCreate().
Mirko Bonadei15522bc2020-09-16 20:38:3948# is_xctest: (iOS, optional) whether to build the executable as XCTest.
49# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
50# for build targets.
qsrfb5251d12015-01-21 15:57:2251template("test") {
Greg Guterman6963dc02021-04-07 05:20:5952 # Ensures the rts file exists and if not, creates a dummy file
53 if (use_rts) {
54 action("${target_name}__rts_filters") {
55 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:5356 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc02021-04-07 05:20:5957 args = [ rebase_path(rts_file, root_build_dir) ]
58 outputs = [ rts_file ]
59 }
60 }
61
Andrew Grieve1b290e4a22020-11-24 20:07:0162 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:3963 if (!is_ios) {
64 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
65 "is_xctest can be set only for iOS builds")
66 }
qsrfb5251d12015-01-21 15:57:2267 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3068 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
69
Peter Kotwicz10742f82021-04-15 22:32:5070 _use_default_launcher =
71 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
72 if (!defined(invoker.use_raw_android_executable)) {
73 # Checkouts where build_with_chromium == false often have a custom GN
74 # template wrapper around test() which sets use_default_launcher == false.
75 # Set the _use_raw_android_executable default so that test() targets which
76 # do not use the custom wrapper
77 # (1) Do not cause "gn gen" to fail
78 # (2) Do not need to be moved into if(build_with_chromium) block.
79 _use_raw_android_executable =
80 !build_with_chromium && _use_default_launcher
81 } else {
82 not_needed([ "_use_default_launcher" ])
83 _use_raw_android_executable = invoker.use_raw_android_executable
84 }
qsrfb5251d12015-01-21 15:57:2285
agrieve67855de2016-03-30 14:46:0186 # output_name is used to allow targets with the same name but in different
87 # packages to still produce unique runner scripts.
88 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2689 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0190 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2691 }
agrieve62ab00282016-04-05 02:03:4592
agrieveb355ad152016-04-19 03:45:2393 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4294 _wrapper_script_vars = [
agrievee41ae1902016-04-25 14:12:5195 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4296 "shard_timeout",
agrievee41ae1902016-04-25 14:12:5197 ]
agrieve3ac557f02016-04-12 15:52:0098
jbudorickced2a252016-06-09 16:38:5499 assert(_use_raw_android_executable || enable_java_templates)
100
agrieve62ab00282016-04-05 02:03:45101 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49102 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
103
agrieve62ab00282016-04-05 02:03:45104 _exec_target = "${target_name}__exec"
105 _dist_target = "${target_name}__dist"
106 _exec_output =
107 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
108
109 executable(_exec_target) {
110 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
111 configs = []
Dirk Pranke19a58732021-03-24 22:26:22112 forward_variables_from(
113 invoker,
114 "*",
115 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
116 "data_deps",
117 "extra_dist_files",
118 ])
agrieve62ab00282016-04-05 02:03:45119
120 # Thanks to the set_defaults() for test(), configs are initialized with
121 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59122 configs -= [
123 "//build/config:shared_library_config",
124 "//build/config/android:hide_all_but_jni",
125 ]
agrieve62ab00282016-04-05 02:03:45126 configs += [ "//build/config:executable_config" ]
127
Dirk Pranke19a58732021-03-24 22:26:22128 if (defined(invoker.data_deps)) {
129 data_deps = invoker.data_deps
130 } else {
131 data_deps = []
132 }
133 if (!defined(data)) {
134 data = []
135 }
Jamie Madilldd60ee62021-04-13 19:25:52136 if (tests_have_location_tags) {
137 data += [ "//testing/location_tags.json" ]
138 }
Dirk Pranke19a58732021-03-24 22:26:22139
agrieve62ab00282016-04-05 02:03:45140 # Don't output to the root or else conflict with the group() below.
141 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11142
143 if (use_rts) {
144 data_deps += [ ":${invoker.target_name}__rts_filters" ]
145 }
agrieve62ab00282016-04-05 02:03:45146 }
147
148 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45149 dist_dir = "$root_out_dir/$target_name"
150 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22151 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45152 if (defined(invoker.extra_dist_files)) {
153 extra_files = invoker.extra_dist_files
154 }
Greg Guterman50ed4b42021-04-08 01:15:11155
156 if (use_rts) {
157 if (!defined(data_deps)) {
158 data_deps = []
159 }
160 data_deps += [ ":${invoker.target_name}__rts_filters" ]
161 }
agrieve62ab00282016-04-05 02:03:45162 }
163 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02164 _library_target = "${target_name}__library"
165 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45166 _apk_specific_vars = [
167 "android_manifest",
agrievec6811b422016-06-23 02:25:09168 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27169 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55170 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45171 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50172 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07173 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02174 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07175 "proguard_configs",
176 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45177 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02178 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45179 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56180 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45181 ]
Siddhartha764226b2018-03-13 02:32:55182
183 # Adds the unwind tables from unstripped binary as an asset file in the
184 # apk, if |add_unwind_tables_in_apk| is specified by the test.
185 if (defined(invoker.add_unwind_tables_in_apk) &&
186 invoker.add_unwind_tables_in_apk) {
187 _unwind_table_asset_name = "${target_name}_unwind_assets"
188 unwind_table_asset(_unwind_table_asset_name) {
Siddhartha764226b2018-03-13 02:32:55189 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22190 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55191 }
192 }
193
agrieve62ab00282016-04-05 02:03:45194 shared_library(_library_target) {
195 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
196 configs = [] # Prevent list overwriting warning.
197 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45198
jbudorickd29ecfa72016-11-18 22:45:42199 forward_variables_from(
200 invoker,
201 "*",
Peter Wen2052bd12020-12-03 20:15:07202 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
203 TESTONLY_AND_VISIBILITY)
204
205 # Native targets do not need to depend on java targets. Filter them out
206 # so that the shared library can be built without needing to wait for
207 # dependent java targets.
208 deps = []
209 if (defined(invoker.deps)) {
210 foreach(_dep, invoker.deps) {
211 _target_label = get_label_info(_dep, "label_no_toolchain")
212 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
213 deps += [ _dep ]
214 }
215 }
216 }
agrieve62ab00282016-04-05 02:03:45217
Peter Kotwiczb9957d62021-04-12 21:09:43218 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37219 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45220 }
221 }
222 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54223 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07224 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45225 apk_name = invoker.target_name
226 if (defined(invoker.output_name)) {
227 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45228 install_script_name = "install_${invoker.output_name}"
229 }
agrieveb355ad152016-04-19 03:45:23230
Daniel Bratellfdda4652019-01-31 15:45:54231 if (defined(invoker.deps)) {
232 deps = invoker.deps
233 } else {
234 deps = []
235 }
236
jcivellif4462a352017-01-10 04:45:59237 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43238 if (_use_default_launcher) {
239 deps += [ "//base/test:test_support_java" ]
240 }
jcivellif4462a352017-01-10 04:45:59241
Siddhartha764226b2018-03-13 02:32:55242 if (defined(_unwind_table_asset_name)) {
243 deps += [ ":${_unwind_table_asset_name}" ]
244 }
Greg Guterman50ed4b42021-04-08 01:15:11245
246 if (use_rts) {
247 data_deps = [ ":${invoker.target_name}__rts_filters" ]
248 }
agrieve62ab00282016-04-05 02:03:45249 }
Andrew Grievee1dc23f2019-10-22 16:26:36250 }
agrieve62ab00282016-04-05 02:03:45251
Andrew Grievee1dc23f2019-10-22 16:26:36252 test_runner_script(_test_runner_target) {
253 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce844392016-12-15 19:57:57254
Andrew Grievee1dc23f2019-10-22 16:26:36255 if (_use_raw_android_executable) {
256 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34257 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36258 } else {
259 apk_target = ":$_apk_target"
260 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47261
262 # Dep needed for the test runner .runtime_deps file to pick up data
263 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22264 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45265 }
Andrew Grievee1dc23f2019-10-22 16:26:36266 test_name = _output_name
267 test_suite = _output_name
268 test_type = "gtest"
Greg Guterman6963dc02021-04-07 05:20:59269
270 if (use_rts) {
271 data_deps += [ ":${invoker.target_name}__rts_filters" ]
272 }
mikecase56d80d72015-06-03 00:57:26273 }
274
Andrew Grieve7ca6de32019-10-18 03:57:47275 # Create a wrapper script rather than using a group() in order to ensure
276 # "ninja $target_name" always works. If this was a group(), then GN would
277 # not create a top-level alias for it if a target exists in another
278 # directory with the same $target_name.
279 # Also - bots run this script directly for "components_perftests".
280 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01281 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47282 executable = "$root_build_dir/bin/run_$_output_name"
283 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22284 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40285 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47286 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40287 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47288 # Dep needed for the swarming .isolate file to pick up data
289 # deps from the forward_variables_from(invoker, "*") on the library.
290 deps += [
291 ":$_apk_target",
292 ":$_library_target",
293 ]
agrieve62ab00282016-04-05 02:03:45294 }
Dirk Pranke19a58732021-03-24 22:26:22295
296 if (defined(invoker.data_deps)) {
297 data_deps = invoker.data_deps
298 } else {
299 data_deps = []
300 }
Jamie Madilldd60ee62021-04-13 19:25:52301 if (tests_have_location_tags) {
302 data = [ "//testing/location_tags.json" ]
303 }
Greg Guterman6963dc02021-04-07 05:20:59304
305 if (use_rts) {
306 data_deps += [ ":${invoker.target_name}__rts_filters" ]
307 }
agrieve1a02e582015-10-15 21:35:39308 }
Scott Graham4c4cdc52017-05-29 20:45:03309 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30310 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
311
Scott Graham4c4cdc52017-05-29 20:45:03312 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42313 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42314 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03315
Chong Gu50c83392021-04-06 23:00:27316 manifest_fragments =
317 [ "//build/config/fuchsia/test/minimum_capabilities.test-cmx" ]
Chong Gu26908f42021-01-29 03:13:07318
Chong Gu91a1fea2021-03-30 17:24:31319 if (defined(invoker.additional_manifest_fragments)) {
320 manifest_fragments += invoker.additional_manifest_fragments
Chong Guacf19a32021-03-10 01:07:41321 }
Chong Gu28bf7e72021-05-26 01:36:19322
Chong Gu7ad57c22021-03-11 00:24:38323 combined_manifest = "${target_name}.test-cmx"
324 cmc_merge(combined_manifest) {
325 sources = manifest_fragments
326 output_name = target_name
327 }
328 manifest = "${target_out_dir}/${combined_manifest}"
Chong Gu26908f42021-01-29 03:13:07329
Kevin Marshall39b4aa82018-06-23 00:12:15330 fuchsia_package_runner(target_name) {
Dirk Pranked5e9a1b22020-10-28 22:52:59331 is_test_exe = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53332 forward_variables_from(invoker,
333 [
334 "use_test_server",
335 "package_deps",
Andrew Grieve1b290e4a22020-11-24 20:07:01336 "visibility",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53337 ])
Kevin Marshall39b4aa82018-06-23 00:12:15338 runner_script = "//build/fuchsia/test_runner.py"
339 package = ":$_pkg_target"
340 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42341
Jamie Madilldd60ee62021-04-13 19:25:52342 if (tests_have_location_tags) {
343 data = [ "//testing/location_tags.json" ]
344 }
Wezdd593a52020-04-08 17:09:46345 data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Greg Guterman6963dc02021-04-07 05:20:59346
347 if (use_rts) {
348 data_deps += [ ":${invoker.target_name}__rts_filters" ]
349 }
Kevin Marshallf35fa5f2018-01-29 19:24:42350 }
351
Wezabe2d752020-02-11 17:12:23352 cr_fuchsia_package(_pkg_target) {
Wez890b18c2021-04-16 13:20:46353 forward_variables_from(invoker, [ "additional_manifests" ])
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20354 binary = ":$_exec_target"
355 package_name_override = _output_name
Chong Gu7ad57c22021-03-11 00:24:38356 deps = [ ":$combined_manifest" ]
Wez890b18c2021-04-16 13:20:46357
358 # Pass on the test() target's |deps|, in case any of the files listed in
359 # |additional_manifests| are generated by them.
360 if (defined(invoker.deps)) {
361 deps += invoker.deps
362 }
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20363 }
364
Kevin Marshallf35fa5f2018-01-29 19:24:42365 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01366 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42367 output_name = _exec_target
Greg Guterman50ed4b42021-04-08 01:15:11368
369 if (use_rts) {
370 if (!defined(data_deps)) {
371 data_deps = []
372 }
373 data_deps += [ ":${invoker.target_name}__rts_filters" ]
374 }
Scott Graham4c4cdc52017-05-29 20:45:03375 }
dpranke2a294622015-08-07 05:23:01376 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30377 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46378 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30379
Rohit Raof9b096d2019-09-09 22:26:23380 declare_args() {
381 # Keep the unittest-as-xctest functionality defaulted to off until the
382 # bots are updated to handle it properly.
383 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
384 # supports running unittests with xctest.
385 enable_run_ios_unittests_with_xctest = false
386 }
387
sdefresne012857872016-03-16 10:55:37388 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36389 _wrapper_output_name = "run_${target_name}"
390 ios_test_runner_wrapper(_wrapper_output_name) {
391 forward_variables_from(invoker,
392 [
393 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36394 "deps",
395 "executable_args",
396 "retries",
397 "shards",
398 ])
399
400 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
401
402 if (!defined(executable_args)) {
403 executable_args = []
404 }
405 executable_args += [
406 "--app",
407 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
408 ]
409
410 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22411
412 if (!defined(data)) {
413 data = []
414 }
Jamie Madilldd60ee62021-04-13 19:25:52415 if (tests_have_location_tags) {
416 data += [ "//testing/location_tags.json" ]
417 }
Jeff Yoonf7f4eb42020-03-06 18:55:36418 }
419
sdefresne012857872016-03-16 10:55:37420 _resources_bundle_data = target_name + "_resources_bundle_data"
421
422 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34423 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22424 sources = [ "//testing/gtest_ios/Default.png" ]
425 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01426 }
427
Mirko Bonadei15522bc2020-09-16 20:38:39428 force_xctest = enable_run_ios_unittests_with_xctest ||
429 (defined(invoker.is_xctest) && invoker.is_xctest)
430
431 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23432 ios_test_target_type = "ios_xctest_test"
433 } else {
434 ios_test_target_type = "ios_app_bundle"
435 }
436
437 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01438 testonly = true
sdefresnea828c282016-05-30 18:04:20439
Mirko Bonadei15522bc2020-09-16 20:38:39440 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23441 xctest_module_target = "//base/test:google_test_runner"
442 }
443
Andrew Grieve1b290e4a22020-11-24 20:07:01444 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13445
446 # Provide sensible defaults in case invoker did not define any of those
447 # required variables.
sdefresne05b97ca2016-06-08 07:19:46448 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13449 info_plist = "//testing/gtest_ios/unittest-Info.plist"
450 }
sdefresne9e147e02016-06-07 00:10:13451
Olivier Robin9689c562020-04-17 14:03:57452 _gtest_bundle_id_suffix = "${target_name}"
453 xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19454
sdefresne9e147e02016-06-07 00:10:13455 if (!defined(extra_substitutions)) {
456 extra_substitutions = []
457 }
Olivier Robin9689c562020-04-17 14:03:57458 extra_substitutions +=
459 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01460
sdefresne047490e2016-07-22 08:49:34461 if (!defined(bundle_deps)) {
462 bundle_deps = []
463 }
464 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36465
466 if (!defined(data_deps)) {
467 data_deps = []
468 }
469
470 # Include the generate_wrapper as part of data_deps
471 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46472 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc02021-04-07 05:20:59473
474 if (use_rts) {
475 data_deps += [ ":${invoker.target_name}__rts_filters" ]
476 }
dpranke2a294622015-08-07 05:23:01477 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11478 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
479 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30480 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
481
Yuke Liao2a9b2f0e2021-04-16 00:40:11482 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32483
Benjamin Pastene3bce864e2018-04-14 01:16:32484 _gen_runner_target = "${target_name}__runner"
485 _runtime_deps_file =
486 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
487 "/" + get_label_info(target_name, "name") + ".runtime_deps"
488
Ben Pastene4ab98652018-12-17 18:33:18489 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32490 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39491 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32492 runtime_deps_file = _runtime_deps_file
Haoming Chena9e205c2021-03-25 02:27:11493
Yuke Liaoacb74b12021-04-23 23:37:34494 if (is_chromeos_lacros) {
495 # At build time, Lacros tests don't know whether they'll run on VM or
496 # HW, and instead, these flags are specified at runtime when invoking
497 # the generated runner script.
498 skip_generating_board_args = true
499 }
500
Jamie Madilldd60ee62021-04-13 19:25:52501 if (tests_have_location_tags) {
502 data = [ "//testing/location_tags.json" ]
503 }
Greg Guterman6963dc02021-04-07 05:20:59504
505 if (use_rts) {
506 data_deps = [ ":${invoker.target_name}__rts_filters" ]
507 }
Benjamin Pastene3bce864e2018-04-14 01:16:32508 }
509
510 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01511 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
512 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32513 if (!defined(deps)) {
514 deps = []
515 }
516 if (!defined(data)) {
517 data = []
518 }
519
Ben Pastene41041782019-02-16 04:21:58520 # We use a special trigger script for CrOS hardware tests.
521 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
522
Benjamin Pastene3bce864e2018-04-14 01:16:32523 output_name = target_name
524 write_runtime_deps = _runtime_deps_file
525 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37526 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc02021-04-07 05:20:59527
528 if (use_rts) {
529 if (!defined(data_deps)) {
530 data_deps = []
531 }
532 data_deps += [ ":${invoker.target_name}__rts_filters" ]
533 }
Benjamin Pastene3bce864e2018-04-14 01:16:32534 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11535 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24536 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
537 _executable = target_name
538 _gen_runner_target = "${target_name}__runner"
539
Yuke Liao32af4242020-07-16 21:48:02540 if (defined(invoker.use_xvfb)) {
541 _use_xvfb = invoker.use_xvfb
542 } else {
543 _use_xvfb = false
544 }
545
Yuke Liaod037abc2020-10-06 22:48:22546 # When use_xvfb is set by the invoker, it indicates that running this test
547 # target requires a window, and in lacros build, ash-chrome serves as the
548 # display server. Note that even though the tests themselves do not require
549 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
550 # because ash-chrome is based on x11.
551 _use_ash_chrome = _use_xvfb
552
Yuke Liaoe703384b2020-07-16 01:05:24553 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24554 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02555
Yuke Liao2e4953cf2020-07-26 19:20:19556 data = []
Will Harrisd35e2c92021-04-07 01:42:02557 data_deps = [ "//testing:test_scripts_shared" ]
558
Yuke Liao32af4242020-07-16 21:48:02559 if (_use_xvfb) {
560 executable = "//testing/xvfb.py"
561 } else {
562 executable = "//testing/test_env.py"
563 }
Jamie Madilldd60ee62021-04-13 19:25:52564 if (tests_have_location_tags) {
565 data += [ "//testing/location_tags.json" ]
566 }
Yuke Liao32af4242020-07-16 21:48:02567
Yuke Liaoe703384b2020-07-16 01:05:24568 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02569 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39570 "test",
Yuke Liaoe703384b2020-07-16 01:05:24571 "@WrappedPath(./${_executable})",
572 "--test-launcher-bot-mode",
573 ]
Yuke Liao32af4242020-07-16 21:48:02574
Yuke Liaof540c742020-07-29 16:28:34575 if (_use_ash_chrome) {
Yuke Liao8348aa42020-11-04 19:35:23576 executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ]
Yuke Liao240816d2020-07-22 00:10:39577 }
578
Yuke Liaoe703384b2020-07-16 01:05:24579 if (is_asan) {
580 executable_args += [ "--asan=true" ]
581 }
582 if (is_msan) {
583 executable_args += [ "--msan=true" ]
584 }
585 if (is_tsan) {
586 executable_args += [ "--tsan=true" ]
587 }
588 if (use_cfi_diag) {
589 executable_args += [ "--cfi-diag=true" ]
590 }
591
Yuke Liao2e4953cf2020-07-26 19:20:19592 data += [
Yuke Liao240816d2020-07-22 00:10:39593 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24594 "//.vpython",
595 ]
Greg Guterman6963dc02021-04-07 05:20:59596
597 if (use_rts) {
598 data_deps += [ ":${invoker.target_name}__rts_filters" ]
599 }
Yuke Liaoe703384b2020-07-16 01:05:24600 }
601
602 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01603 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
604 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24605 if (!defined(deps)) {
606 deps = []
607 }
608
Yuke Liaod037abc2020-10-06 22:48:22609 if (!defined(data_deps)) {
610 data_deps = []
611 }
612
Yuke Liaoe703384b2020-07-16 01:05:24613 write_runtime_deps = _runtime_deps_file
614 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22615 if (_use_ash_chrome && also_build_ash_chrome) {
616 data_deps +=
617 [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ]
618 }
Greg Guterman6963dc02021-04-07 05:20:59619
620 if (use_rts) {
621 data_deps += [ ":${invoker.target_name}__rts_filters" ]
622 }
Yuke Liaoe703384b2020-07-16 01:05:24623 }
Dirk Prankedd4ff742020-11-18 19:57:32624 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30625 if (is_mac || is_win) {
626 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
627 }
628
Dirk Prankedd4ff742020-11-18 19:57:32629 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
630 _executable = target_name
631 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06632
Dirk Prankedd4ff742020-11-18 19:57:32633 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
634 _use_xvfb = invoker.use_xvfb
635 } else {
636 _use_xvfb = false
637 }
638
639 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32640 wrapper_script = "$root_build_dir/bin/run_" + _executable
641
642 data = []
Will Harrisd35e2c92021-04-07 01:42:02643 data_deps = [ "//testing:test_scripts_shared" ]
644
Dirk Prankedd4ff742020-11-18 19:57:32645 if (_use_xvfb) {
646 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06647 } else {
Dirk Prankedd4ff742020-11-18 19:57:32648 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06649 }
Jamie Madilldd60ee62021-04-13 19:25:52650 if (tests_have_location_tags) {
651 data += [ "//testing/location_tags.json" ]
652 }
Dirk Pranke31e346e2020-07-15 00:54:06653
Dirk Prankedd4ff742020-11-18 19:57:32654 executable_args = [
655 "@WrappedPath(./${_executable})",
656 "--test-launcher-bot-mode",
657 ]
658 if (is_asan) {
659 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06660 }
Dirk Prankedd4ff742020-11-18 19:57:32661 if (is_msan) {
662 executable_args += [ "--msan=true" ]
663 }
664 if (is_tsan) {
665 executable_args += [ "--tsan=true" ]
666 }
667 if (use_cfi_diag) {
668 executable_args += [ "--cfi-diag=true" ]
669 }
670
671 data += [ "//.vpython" ]
Greg Guterman6963dc02021-04-07 05:20:59672
673 if (use_rts) {
674 data_deps += [ ":${invoker.target_name}__rts_filters" ]
675 }
Dirk Pranke31e346e2020-07-15 00:54:06676 }
677
678 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01679 forward_variables_from(invoker,
680 "*",
681 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
682 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06683 if (!defined(deps)) {
684 deps = []
685 }
686
Dirk Pranke31e346e2020-07-15 00:54:06687 deps += [
688 # Give tests the default manifest on Windows (a no-op elsewhere).
689 "//build/win:default_exe_manifest",
690 ]
691
Dirk Prankedd4ff742020-11-18 19:57:32692 write_runtime_deps = _runtime_deps_file
693 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11694
695 if (use_rts) {
696 if (!defined(data_deps)) {
697 data_deps = []
698 }
699 data_deps += [ ":${invoker.target_name}__rts_filters" ]
700 }
Dirk Prankedd4ff742020-11-18 19:57:32701 }
702 } else {
703 # This is a catch-all clause for NaCl toolchains and other random
704 # configurations that might define tests; test() in these configs
705 # will just define the underlying executables.
706 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
707 "use_xvfb should not be defined for a non-linux configuration")
708 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01709 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
710 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32711 if (!defined(deps)) {
712 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06713 }
Greg Guterman6963dc02021-04-07 05:20:59714
715 if (use_rts) {
716 if (!defined(data_deps)) {
717 data_deps = []
718 }
719 data_deps += [ ":${invoker.target_name}__rts_filters" ]
720 }
Dirk Pranke31e346e2020-07-15 00:54:06721 }
qsrfb5251d12015-01-21 15:57:22722 }
723}
brettwedb6ecc2016-07-14 23:37:03724
Dirk Pranke6188075b2020-10-01 19:31:28725# Defines a type of test that invokes a script to run, rather than
726# invoking an executable.
727#
728# The script must implement the
729# [test executable API](//docs/testing/test_executable_api.md).
730#
731# The template must be passed the `script` parameter, which specifies
732# the path to the script to run. It may optionally be passed a
733# `script_args` parameter, which can be used to include a list of
734# args to be specified by default. The template will produce
735# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
736# for the target to $root_build_dir/${target_name}.runtime_deps, as per
737# the conventions listed in the
738# [test wrapper API](//docs/testing/test_wrapper_api.md).
739template("script_test") {
Greg Guterman6963dc02021-04-07 05:20:59740 if (use_rts) {
741 action("${target_name}__rts_filters") {
742 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53743 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc02021-04-07 05:20:59744 args = [ rebase_path(rts_file, root_build_dir) ]
745 outputs = [ rts_file ]
746 }
747 }
748
Dirk Pranke6188075b2020-10-01 19:31:28749 generate_wrapper(target_name) {
750 testonly = true
751 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
752
753 executable = "//testing/test_env.py"
754
755 executable_args =
756 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
757 if (defined(invoker.args)) {
758 executable_args += invoker.args
759 }
760
Will Harrisd35e2c92021-04-07 01:42:02761 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:47762
763 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
764 use_vpython3 = false
765 data += [ "//.vpython" ]
766 } else {
767 use_vpython3 = true
768 data += [ "//.vpython3" ]
769 }
770
Dirk Pranke6188075b2020-10-01 19:31:28771 if (defined(invoker.data)) {
772 data += invoker.data
773 }
Jamie Madilldd60ee62021-04-13 19:25:52774 if (tests_have_location_tags) {
775 data += [ "//testing/location_tags.json" ]
776 }
Dirk Pranke19a58732021-03-24 22:26:22777
Will Harrisd35e2c92021-04-07 01:42:02778 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:28779 if (defined(invoker.data_deps)) {
780 data_deps += invoker.data_deps
781 }
782
783 forward_variables_from(invoker,
784 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01785 TESTONLY_AND_VISIBILITY + [
786 "data",
787 "data_deps",
788 "script",
789 "script_args",
790 ])
791 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28792
793 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc02021-04-07 05:20:59794
795 if (use_rts) {
796 data_deps += [ ":${invoker.target_name}__rts_filters" ]
797 }
Dirk Pranke6188075b2020-10-01 19:31:28798 }
799}
800
brettwedb6ecc2016-07-14 23:37:03801# Test defaults.
802set_defaults("test") {
803 if (is_android) {
804 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41805 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59806 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03807 } else {
808 configs = default_executable_configs
809 }
810}