[go: nahoru, domu]

blob: a8c369e79593cd4547a78464fd144ceaff987f53 [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")
Mirko Bonadei4a0df432020-09-08 19:06:0211import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2412
Greg Guterman6963dc02021-04-07 05:20:5913declare_args() {
14 # For more info about RTS, please see
15 # //docs/testing/regression-test-selection.md
16 use_rts = false
Jamie Madilldd60ee62021-04-13 19:25:5217
18 # Some component repos (e.g. ANGLE) import //testing but do not have "location_tags.json"
19 tests_have_location_tags = true
Greg Guterman6963dc02021-04-07 05:20:5920}
21
jcivellif4462a352017-01-10 04:45:5922if (is_android) {
23 import("//build/config/android/config.gni")
James Cook209256f2018-12-07 18:40:5024 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5925 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4426 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3227} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0628 import("//build/config/chromecast_build.gni")
Chong Gu26908f42021-01-29 03:13:0729 import("//build/config/coverage/coverage.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 Gu26908f42021-01-29 03:13:0732 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Yuke Liao2a9b2f0e2021-04-16 00:40:1133} 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.
Haoming Chena9e205c2021-03-25 02:27:1155# override_board: (ash, optional) override the 'cros_board' used in
56# generating the test runner script.
qsrfb5251d12015-01-21 15:57:2257template("test") {
Greg Guterman6963dc02021-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 Guterman6963dc02021-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 }
Haoming Chena9e205c2021-03-25 02:27:1173 if (!is_chromeos_ash || cros_board == "") {
74 assert(
75 !defined(invoker.override_board),
76 "override_board can be set only for ChromeOS builds with target board")
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 = [
agrievee41ae1902016-04-25 14:12:51106 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42107 "shard_timeout",
agrievee41ae1902016-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) {
113 _exec_target = "${target_name}__exec"
114 _dist_target = "${target_name}__dist"
115 _exec_output =
116 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
117
118 executable(_exec_target) {
119 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
120 configs = []
Dirk Pranke19a58732021-03-24 22:26:22121 forward_variables_from(
122 invoker,
123 "*",
124 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
125 "data_deps",
126 "extra_dist_files",
127 ])
agrieve62ab00282016-04-05 02:03:45128
129 # Thanks to the set_defaults() for test(), configs are initialized with
130 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59131 configs -= [
132 "//build/config:shared_library_config",
133 "//build/config/android:hide_all_but_jni",
134 ]
agrieve62ab00282016-04-05 02:03:45135 configs += [ "//build/config:executable_config" ]
136
Dirk Pranke19a58732021-03-24 22:26:22137 if (defined(invoker.data_deps)) {
138 data_deps = invoker.data_deps
139 } else {
140 data_deps = []
141 }
142 if (!defined(data)) {
143 data = []
144 }
Jamie Madilldd60ee62021-04-13 19:25:52145 if (tests_have_location_tags) {
146 data += [ "//testing/location_tags.json" ]
147 }
Dirk Pranke19a58732021-03-24 22:26:22148
agrieve62ab00282016-04-05 02:03:45149 # Don't output to the root or else conflict with the group() below.
150 output_name = rebase_path(_exec_output, root_out_dir)
Greg Guterman50ed4b42021-04-08 01:15:11151
152 if (use_rts) {
153 data_deps += [ ":${invoker.target_name}__rts_filters" ]
154 }
agrieve62ab00282016-04-05 02:03:45155 }
156
157 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45158 dist_dir = "$root_out_dir/$target_name"
159 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22160 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45161 if (defined(invoker.extra_dist_files)) {
162 extra_files = invoker.extra_dist_files
163 }
Greg Guterman50ed4b42021-04-08 01:15:11164
165 if (use_rts) {
166 if (!defined(data_deps)) {
167 data_deps = []
168 }
169 data_deps += [ ":${invoker.target_name}__rts_filters" ]
170 }
agrieve62ab00282016-04-05 02:03:45171 }
172 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02173 _library_target = "${target_name}__library"
174 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45175 _apk_specific_vars = [
176 "android_manifest",
agrievec6811b422016-06-23 02:25:09177 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27178 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55179 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45180 "enable_multidex",
Peter Kotwicz10742f82021-04-15 22:32:50181 "generate_final_jni",
Benoît Lizéd8b8f742019-11-07 12:50:07182 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02183 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07184 "proguard_configs",
185 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45186 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02187 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45188 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56189 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45190 ]
Siddhartha764226b2018-03-13 02:32:55191
192 # Adds the unwind tables from unstripped binary as an asset file in the
193 # apk, if |add_unwind_tables_in_apk| is specified by the test.
194 if (defined(invoker.add_unwind_tables_in_apk) &&
195 invoker.add_unwind_tables_in_apk) {
196 _unwind_table_asset_name = "${target_name}_unwind_assets"
197 unwind_table_asset(_unwind_table_asset_name) {
Siddhartha764226b2018-03-13 02:32:55198 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22199 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55200 }
201 }
202
agrieve62ab00282016-04-05 02:03:45203 shared_library(_library_target) {
204 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
205 configs = [] # Prevent list overwriting warning.
206 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45207
jbudorickd29ecfa72016-11-18 22:45:42208 forward_variables_from(
209 invoker,
210 "*",
Peter Wen2052bd12020-12-03 20:15:07211 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
212 TESTONLY_AND_VISIBILITY)
213
214 # Native targets do not need to depend on java targets. Filter them out
215 # so that the shared library can be built without needing to wait for
216 # dependent java targets.
217 deps = []
218 if (defined(invoker.deps)) {
219 foreach(_dep, invoker.deps) {
220 _target_label = get_label_info(_dep, "label_no_toolchain")
221 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
222 deps += [ _dep ]
223 }
224 }
225 }
agrieve62ab00282016-04-05 02:03:45226
Peter Kotwiczb9957d62021-04-12 21:09:43227 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37228 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45229 }
230 }
231 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54232 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07233 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45234 apk_name = invoker.target_name
235 if (defined(invoker.output_name)) {
236 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45237 install_script_name = "install_${invoker.output_name}"
238 }
agrieveb355ad152016-04-19 03:45:23239
Daniel Bratellfdda4652019-01-31 15:45:54240 if (defined(invoker.deps)) {
241 deps = invoker.deps
242 } else {
243 deps = []
244 }
245
jcivellif4462a352017-01-10 04:45:59246 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43247 if (_use_default_launcher) {
248 deps += [ "//base/test:test_support_java" ]
249 }
jcivellif4462a352017-01-10 04:45:59250
Siddhartha764226b2018-03-13 02:32:55251 if (defined(_unwind_table_asset_name)) {
252 deps += [ ":${_unwind_table_asset_name}" ]
253 }
Greg Guterman50ed4b42021-04-08 01:15:11254
255 if (use_rts) {
256 data_deps = [ ":${invoker.target_name}__rts_filters" ]
257 }
agrieve62ab00282016-04-05 02:03:45258 }
Andrew Grievee1dc23f2019-10-22 16:26:36259 }
agrieve62ab00282016-04-05 02:03:45260
Andrew Grievee1dc23f2019-10-22 16:26:36261 test_runner_script(_test_runner_target) {
262 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce844392016-12-15 19:57:57263
Andrew Grievee1dc23f2019-10-22 16:26:36264 if (_use_raw_android_executable) {
265 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34266 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36267 } else {
268 apk_target = ":$_apk_target"
269 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47270
271 # Dep needed for the test runner .runtime_deps file to pick up data
272 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22273 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45274 }
Andrew Grievee1dc23f2019-10-22 16:26:36275 test_name = _output_name
276 test_suite = _output_name
277 test_type = "gtest"
Greg Guterman6963dc02021-04-07 05:20:59278
279 if (use_rts) {
280 data_deps += [ ":${invoker.target_name}__rts_filters" ]
281 }
mikecase56d80d72015-06-03 00:57:26282 }
283
Andrew Grieve7ca6de32019-10-18 03:57:47284 # Create a wrapper script rather than using a group() in order to ensure
285 # "ninja $target_name" always works. If this was a group(), then GN would
286 # not create a top-level alias for it if a target exists in another
287 # directory with the same $target_name.
288 # Also - bots run this script directly for "components_perftests".
289 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01290 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47291 executable = "$root_build_dir/bin/run_$_output_name"
292 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22293 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40294 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47295 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40296 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47297 # Dep needed for the swarming .isolate file to pick up data
298 # deps from the forward_variables_from(invoker, "*") on the library.
299 deps += [
300 ":$_apk_target",
301 ":$_library_target",
302 ]
agrieve62ab00282016-04-05 02:03:45303 }
Dirk Pranke19a58732021-03-24 22:26:22304
305 if (defined(invoker.data_deps)) {
306 data_deps = invoker.data_deps
307 } else {
308 data_deps = []
309 }
Jamie Madilldd60ee62021-04-13 19:25:52310 if (tests_have_location_tags) {
311 data = [ "//testing/location_tags.json" ]
312 }
Greg Guterman6963dc02021-04-07 05:20:59313
314 if (use_rts) {
315 data_deps += [ ":${invoker.target_name}__rts_filters" ]
316 }
agrieve1a02e582015-10-15 21:35:39317 }
Scott Graham4c4cdc52017-05-29 20:45:03318 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30319 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
320
Scott Graham4c4cdc52017-05-29 20:45:03321 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42322 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42323 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03324
Chong Gu50c83392021-04-06 23:00:27325 manifest_fragments =
326 [ "//build/config/fuchsia/test/minimum_capabilities.test-cmx" ]
Chong Gu26908f42021-01-29 03:13:07327
Chong Gu91a1fea2021-03-30 17:24:31328 if (defined(invoker.additional_manifest_fragments)) {
329 manifest_fragments += invoker.additional_manifest_fragments
Chong Guacf19a32021-03-10 01:07:41330 }
Chong Gu26908f42021-01-29 03:13:07331 if (use_clang_coverage) {
Chong Gu7ad57c22021-03-11 00:24:38332 manifest_fragments +=
333 [ "//build/config/fuchsia/add_DebugData_service.test-cmx" ]
Chong Gu26908f42021-01-29 03:13:07334 }
Chong Gu7ad57c22021-03-11 00:24:38335 combined_manifest = "${target_name}.test-cmx"
336 cmc_merge(combined_manifest) {
337 sources = manifest_fragments
338 output_name = target_name
339 }
340 manifest = "${target_out_dir}/${combined_manifest}"
Chong Gu26908f42021-01-29 03:13:07341
Kevin Marshall39b4aa82018-06-23 00:12:15342 fuchsia_package_runner(target_name) {
Dirk Pranked5e9a1b22020-10-28 22:52:59343 is_test_exe = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53344 forward_variables_from(invoker,
345 [
346 "use_test_server",
347 "package_deps",
Andrew Grieve1b290e4a22020-11-24 20:07:01348 "visibility",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53349 ])
Kevin Marshall39b4aa82018-06-23 00:12:15350 runner_script = "//build/fuchsia/test_runner.py"
351 package = ":$_pkg_target"
352 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42353
Jamie Madilldd60ee62021-04-13 19:25:52354 if (tests_have_location_tags) {
355 data = [ "//testing/location_tags.json" ]
356 }
Wezdd593a52020-04-08 17:09:46357 data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Greg Guterman6963dc02021-04-07 05:20:59358
359 if (use_rts) {
360 data_deps += [ ":${invoker.target_name}__rts_filters" ]
361 }
Kevin Marshallf35fa5f2018-01-29 19:24:42362 }
363
Wezabe2d752020-02-11 17:12:23364 cr_fuchsia_package(_pkg_target) {
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20365 binary = ":$_exec_target"
366 package_name_override = _output_name
Chong Gu7ad57c22021-03-11 00:24:38367 deps = [ ":$combined_manifest" ]
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20368 }
369
Kevin Marshallf35fa5f2018-01-29 19:24:42370 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01371 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42372 output_name = _exec_target
Greg Guterman50ed4b42021-04-08 01:15:11373
374 if (use_rts) {
375 if (!defined(data_deps)) {
376 data_deps = []
377 }
378 data_deps += [ ":${invoker.target_name}__rts_filters" ]
379 }
Scott Graham4c4cdc52017-05-29 20:45:03380 }
dpranke2a294622015-08-07 05:23:01381 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30382 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46383 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30384
Rohit Raof9b096d2019-09-09 22:26:23385 declare_args() {
386 # Keep the unittest-as-xctest functionality defaulted to off until the
387 # bots are updated to handle it properly.
388 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
389 # supports running unittests with xctest.
390 enable_run_ios_unittests_with_xctest = false
391 }
392
sdefresne012857872016-03-16 10:55:37393 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36394 _wrapper_output_name = "run_${target_name}"
395 ios_test_runner_wrapper(_wrapper_output_name) {
396 forward_variables_from(invoker,
397 [
398 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36399 "deps",
400 "executable_args",
401 "retries",
402 "shards",
403 ])
404
405 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
406
407 if (!defined(executable_args)) {
408 executable_args = []
409 }
410 executable_args += [
411 "--app",
412 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
413 ]
414
415 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22416
417 if (!defined(data)) {
418 data = []
419 }
Jamie Madilldd60ee62021-04-13 19:25:52420 if (tests_have_location_tags) {
421 data += [ "//testing/location_tags.json" ]
422 }
Jeff Yoonf7f4eb42020-03-06 18:55:36423 }
424
sdefresne012857872016-03-16 10:55:37425 _resources_bundle_data = target_name + "_resources_bundle_data"
426
427 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34428 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22429 sources = [ "//testing/gtest_ios/Default.png" ]
430 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01431 }
432
Mirko Bonadei15522bc2020-09-16 20:38:39433 force_xctest = enable_run_ios_unittests_with_xctest ||
434 (defined(invoker.is_xctest) && invoker.is_xctest)
435
436 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23437 ios_test_target_type = "ios_xctest_test"
438 } else {
439 ios_test_target_type = "ios_app_bundle"
440 }
441
442 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01443 testonly = true
sdefresnea828c282016-05-30 18:04:20444
Mirko Bonadei15522bc2020-09-16 20:38:39445 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23446 xctest_module_target = "//base/test:google_test_runner"
447 }
448
Andrew Grieve1b290e4a22020-11-24 20:07:01449 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13450
451 # Provide sensible defaults in case invoker did not define any of those
452 # required variables.
sdefresne05b97ca2016-06-08 07:19:46453 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13454 info_plist = "//testing/gtest_ios/unittest-Info.plist"
455 }
sdefresne9e147e02016-06-07 00:10:13456
Olivier Robin9689c562020-04-17 14:03:57457 _gtest_bundle_id_suffix = "${target_name}"
458 xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19459
sdefresne9e147e02016-06-07 00:10:13460 if (!defined(extra_substitutions)) {
461 extra_substitutions = []
462 }
Olivier Robin9689c562020-04-17 14:03:57463 extra_substitutions +=
464 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01465
sdefresne047490e2016-07-22 08:49:34466 if (!defined(bundle_deps)) {
467 bundle_deps = []
468 }
469 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36470
471 if (!defined(data_deps)) {
472 data_deps = []
473 }
474
475 # Include the generate_wrapper as part of data_deps
476 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46477 write_runtime_deps = _runtime_deps_file
Greg Guterman6963dc02021-04-07 05:20:59478
479 if (use_rts) {
480 data_deps += [ ":${invoker.target_name}__rts_filters" ]
481 }
dpranke2a294622015-08-07 05:23:01482 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11483 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
484 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30485 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
486
Yuke Liao2a9b2f0e2021-04-16 00:40:11487 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32488
Benjamin Pastene3bce864e2018-04-14 01:16:32489 _gen_runner_target = "${target_name}__runner"
490 _runtime_deps_file =
491 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
492 "/" + get_label_info(target_name, "name") + ".runtime_deps"
493
Ben Pastene4ab98652018-12-17 18:33:18494 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32495 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39496 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32497 runtime_deps_file = _runtime_deps_file
Haoming Chena9e205c2021-03-25 02:27:11498
499 if (defined(invoker.override_board)) {
500 override_board = invoker.override_board
501 }
502
Jamie Madilldd60ee62021-04-13 19:25:52503 if (tests_have_location_tags) {
504 data = [ "//testing/location_tags.json" ]
505 }
Greg Guterman6963dc02021-04-07 05:20:59506
507 if (use_rts) {
508 data_deps = [ ":${invoker.target_name}__rts_filters" ]
509 }
Benjamin Pastene3bce864e2018-04-14 01:16:32510 }
511
512 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01513 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
514 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32515 if (!defined(deps)) {
516 deps = []
517 }
518 if (!defined(data)) {
519 data = []
520 }
521
Ben Pastene41041782019-02-16 04:21:58522 # We use a special trigger script for CrOS hardware tests.
523 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
524
Benjamin Pastene3bce864e2018-04-14 01:16:32525 output_name = target_name
526 write_runtime_deps = _runtime_deps_file
527 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37528 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc02021-04-07 05:20:59529
530 if (use_rts) {
531 if (!defined(data_deps)) {
532 data_deps = []
533 }
534 data_deps += [ ":${invoker.target_name}__rts_filters" ]
535 }
Benjamin Pastene3bce864e2018-04-14 01:16:32536 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11537 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24538 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
539 _executable = target_name
540 _gen_runner_target = "${target_name}__runner"
541
Yuke Liao32af4242020-07-16 21:48:02542 if (defined(invoker.use_xvfb)) {
543 _use_xvfb = invoker.use_xvfb
544 } else {
545 _use_xvfb = false
546 }
547
Yuke Liaod037abc2020-10-06 22:48:22548 # When use_xvfb is set by the invoker, it indicates that running this test
549 # target requires a window, and in lacros build, ash-chrome serves as the
550 # display server. Note that even though the tests themselves do not require
551 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
552 # because ash-chrome is based on x11.
553 _use_ash_chrome = _use_xvfb
554
Yuke Liaoe703384b2020-07-16 01:05:24555 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24556 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02557
Yuke Liao2e4953cf2020-07-26 19:20:19558 data = []
Will Harrisd35e2c92021-04-07 01:42:02559 data_deps = [ "//testing:test_scripts_shared" ]
560
Yuke Liao32af4242020-07-16 21:48:02561 if (_use_xvfb) {
562 executable = "//testing/xvfb.py"
563 } else {
564 executable = "//testing/test_env.py"
565 }
Jamie Madilldd60ee62021-04-13 19:25:52566 if (tests_have_location_tags) {
567 data += [ "//testing/location_tags.json" ]
568 }
Yuke Liao32af4242020-07-16 21:48:02569
Yuke Liaoe703384b2020-07-16 01:05:24570 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02571 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39572 "test",
Yuke Liaoe703384b2020-07-16 01:05:24573 "@WrappedPath(./${_executable})",
574 "--test-launcher-bot-mode",
575 ]
Yuke Liao32af4242020-07-16 21:48:02576
Yuke Liaof540c742020-07-29 16:28:34577 if (_use_ash_chrome) {
Yuke Liao8348aa42020-11-04 19:35:23578 executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ]
Yuke Liao240816d2020-07-22 00:10:39579 }
580
Yuke Liaoe703384b2020-07-16 01:05:24581 if (is_asan) {
582 executable_args += [ "--asan=true" ]
583 }
584 if (is_msan) {
585 executable_args += [ "--msan=true" ]
586 }
587 if (is_tsan) {
588 executable_args += [ "--tsan=true" ]
589 }
590 if (use_cfi_diag) {
591 executable_args += [ "--cfi-diag=true" ]
592 }
593
Yuke Liao2e4953cf2020-07-26 19:20:19594 data += [
Yuke Liao240816d2020-07-22 00:10:39595 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24596 "//.vpython",
597 ]
Greg Guterman6963dc02021-04-07 05:20:59598
599 if (use_rts) {
600 data_deps += [ ":${invoker.target_name}__rts_filters" ]
601 }
Yuke Liaoe703384b2020-07-16 01:05:24602 }
603
604 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01605 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
606 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24607 if (!defined(deps)) {
608 deps = []
609 }
610
Yuke Liaod037abc2020-10-06 22:48:22611 if (!defined(data_deps)) {
612 data_deps = []
613 }
614
Yuke Liaoe703384b2020-07-16 01:05:24615 write_runtime_deps = _runtime_deps_file
616 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22617 if (_use_ash_chrome && also_build_ash_chrome) {
618 data_deps +=
619 [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ]
620 }
Greg Guterman6963dc02021-04-07 05:20:59621
622 if (use_rts) {
623 data_deps += [ ":${invoker.target_name}__rts_filters" ]
624 }
Yuke Liaoe703384b2020-07-16 01:05:24625 }
Dirk Prankedd4ff742020-11-18 19:57:32626 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30627 if (is_mac || is_win) {
628 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
629 }
630
Dirk Prankedd4ff742020-11-18 19:57:32631 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
632 _executable = target_name
633 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06634
Dirk Prankedd4ff742020-11-18 19:57:32635 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
636 _use_xvfb = invoker.use_xvfb
637 } else {
638 _use_xvfb = false
639 }
640
641 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32642 wrapper_script = "$root_build_dir/bin/run_" + _executable
643
644 data = []
Will Harrisd35e2c92021-04-07 01:42:02645 data_deps = [ "//testing:test_scripts_shared" ]
646
Dirk Prankedd4ff742020-11-18 19:57:32647 if (_use_xvfb) {
648 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:06649 } else {
Dirk Prankedd4ff742020-11-18 19:57:32650 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:06651 }
Jamie Madilldd60ee62021-04-13 19:25:52652 if (tests_have_location_tags) {
653 data += [ "//testing/location_tags.json" ]
654 }
Dirk Pranke31e346e2020-07-15 00:54:06655
Dirk Prankedd4ff742020-11-18 19:57:32656 executable_args = [
657 "@WrappedPath(./${_executable})",
658 "--test-launcher-bot-mode",
659 ]
660 if (is_asan) {
661 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06662 }
Dirk Prankedd4ff742020-11-18 19:57:32663 if (is_msan) {
664 executable_args += [ "--msan=true" ]
665 }
666 if (is_tsan) {
667 executable_args += [ "--tsan=true" ]
668 }
669 if (use_cfi_diag) {
670 executable_args += [ "--cfi-diag=true" ]
671 }
672
673 data += [ "//.vpython" ]
Greg Guterman6963dc02021-04-07 05:20:59674
675 if (use_rts) {
676 data_deps += [ ":${invoker.target_name}__rts_filters" ]
677 }
Dirk Pranke31e346e2020-07-15 00:54:06678 }
679
680 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01681 forward_variables_from(invoker,
682 "*",
683 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
684 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06685 if (!defined(deps)) {
686 deps = []
687 }
688
Dirk Pranke31e346e2020-07-15 00:54:06689 deps += [
690 # Give tests the default manifest on Windows (a no-op elsewhere).
691 "//build/win:default_exe_manifest",
692 ]
693
Dirk Prankedd4ff742020-11-18 19:57:32694 write_runtime_deps = _runtime_deps_file
695 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:11696
697 if (use_rts) {
698 if (!defined(data_deps)) {
699 data_deps = []
700 }
701 data_deps += [ ":${invoker.target_name}__rts_filters" ]
702 }
Dirk Prankedd4ff742020-11-18 19:57:32703 }
704 } else {
705 # This is a catch-all clause for NaCl toolchains and other random
706 # configurations that might define tests; test() in these configs
707 # will just define the underlying executables.
708 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
709 "use_xvfb should not be defined for a non-linux configuration")
710 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01711 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
712 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32713 if (!defined(deps)) {
714 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06715 }
Greg Guterman6963dc02021-04-07 05:20:59716
717 if (use_rts) {
718 if (!defined(data_deps)) {
719 data_deps = []
720 }
721 data_deps += [ ":${invoker.target_name}__rts_filters" ]
722 }
Dirk Pranke31e346e2020-07-15 00:54:06723 }
qsrfb5251d12015-01-21 15:57:22724 }
725}
brettwedb6ecc2016-07-14 23:37:03726
Dirk Pranke6188075b2020-10-01 19:31:28727# Defines a type of test that invokes a script to run, rather than
728# invoking an executable.
729#
730# The script must implement the
731# [test executable API](//docs/testing/test_executable_api.md).
732#
733# The template must be passed the `script` parameter, which specifies
734# the path to the script to run. It may optionally be passed a
735# `script_args` parameter, which can be used to include a list of
736# args to be specified by default. The template will produce
737# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
738# for the target to $root_build_dir/${target_name}.runtime_deps, as per
739# the conventions listed in the
740# [test wrapper API](//docs/testing/test_wrapper_api.md).
741template("script_test") {
Greg Guterman6963dc02021-04-07 05:20:59742 if (use_rts) {
743 action("${target_name}__rts_filters") {
744 script = "//build/add_rts_filters.py"
Greg Guterman49a42172021-04-08 22:04:53745 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter"
Greg Guterman6963dc02021-04-07 05:20:59746 args = [ rebase_path(rts_file, root_build_dir) ]
747 outputs = [ rts_file ]
748 }
749 }
750
Dirk Pranke6188075b2020-10-01 19:31:28751 generate_wrapper(target_name) {
752 testonly = true
753 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
754
755 executable = "//testing/test_env.py"
756
757 executable_args =
758 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
759 if (defined(invoker.args)) {
760 executable_args += invoker.args
761 }
762
Will Harrisd35e2c92021-04-07 01:42:02763 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:47764
765 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
766 use_vpython3 = false
767 data += [ "//.vpython" ]
768 } else {
769 use_vpython3 = true
770 data += [ "//.vpython3" ]
771 }
772
Dirk Pranke6188075b2020-10-01 19:31:28773 if (defined(invoker.data)) {
774 data += invoker.data
775 }
Jamie Madilldd60ee62021-04-13 19:25:52776 if (tests_have_location_tags) {
777 data += [ "//testing/location_tags.json" ]
778 }
Dirk Pranke19a58732021-03-24 22:26:22779
Will Harrisd35e2c92021-04-07 01:42:02780 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:28781 if (defined(invoker.data_deps)) {
782 data_deps += invoker.data_deps
783 }
784
785 forward_variables_from(invoker,
786 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01787 TESTONLY_AND_VISIBILITY + [
788 "data",
789 "data_deps",
790 "script",
791 "script_args",
792 ])
793 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28794
795 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Greg Guterman6963dc02021-04-07 05:20:59796
797 if (use_rts) {
798 data_deps += [ ":${invoker.target_name}__rts_filters" ]
799 }
Dirk Pranke6188075b2020-10-01 19:31:28800 }
801}
802
brettwedb6ecc2016-07-14 23:37:03803# Test defaults.
804set_defaults("test") {
805 if (is_android) {
806 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41807 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59808 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03809 } else {
810 configs = default_executable_configs
811 }
812}