blob: 4876ec55caade4f2a0564f326fa4b191809474ef [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 Liaoe703384b2020-07-16 01:05:249import("//build/config/chromeos/ui_mode.gni")
Mirko Bonadei4a0df432020-09-08 19:06:0210import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2411
jcivellif4462a352017-01-10 04:45:5912if (is_android) {
13 import("//build/config/android/config.gni")
James Cook209256f2018-12-07 18:40:5014 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5915 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4416 import("//build/config/sanitizers/sanitizers.gni")
jcivellif4462a352017-01-10 04:45:5917}
18
Scott Graham4c4cdc52017-05-29 20:45:0319if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0620 import("//build/config/chromecast_build.gni")
Kevin Marshall55fd8522019-10-04 22:47:0121 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4222 import("//build/config/fuchsia/package.gni")
Scott Graham4c4cdc52017-05-29 20:45:0323}
24
Ben Pastene4c35c572018-04-30 23:21:4825if (is_chromeos) {
26 import("//build/config/chromeos/rules.gni")
Dirk Pranke6188075b2020-10-01 19:31:2827 import("//build/util/generate_wrapper.gni")
Ben Pastene4c35c572018-04-30 23:21:4828}
29
Jeff Yoonf7f4eb42020-03-06 18:55:3630if (is_ios) {
31 import("//build/config/ios/ios_sdk.gni")
32 import("//build/config/ios/ios_test_runner_wrapper.gni")
33 import("//build/config/ios/rules.gni")
34}
35
Yuke Liaoe703384b2020-07-16 01:05:2436if ((is_linux && !is_chromeos) || is_mac || is_win ||
37 chromeos_is_browser_only) {
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().
Will Harrisc218db232020-07-21 20:20:5748# win_test_enable_cfi_linker: (Win) Enable CFI linker for this test binary.
Mirko Bonadei15522bc2020-09-16 20:38:3949# is_xctest: (iOS, optional) whether to build the executable as XCTest.
50# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
51# for build targets.
qsrfb5251d12015-01-21 15:57:2252template("test") {
Mirko Bonadei15522bc2020-09-16 20:38:3953 if (!is_ios) {
54 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
55 "is_xctest can be set only for iOS builds")
56 }
qsrfb5251d12015-01-21 15:57:2257 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3058 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
59
agrieve62ab00282016-04-05 02:03:4560 _use_raw_android_executable = defined(invoker.use_raw_android_executable) &&
61 invoker.use_raw_android_executable
qsrfb5251d12015-01-21 15:57:2262
agrieve67855de2016-03-30 14:46:0163 # output_name is used to allow targets with the same name but in different
64 # packages to still produce unique runner scripts.
65 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2666 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0167 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2668 }
agrieve62ab00282016-04-05 02:03:4569
agrieveb355ad152016-04-19 03:45:2370 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4271 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:5172 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4273 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:5174 ]
agrieve3ac557f02016-04-12 15:52:0075
jbudorickced2a252016-06-09 16:38:5476 assert(_use_raw_android_executable || enable_java_templates)
77
agrieve62ab00282016-04-05 02:03:4578 if (_use_raw_android_executable) {
79 _exec_target = "${target_name}__exec"
80 _dist_target = "${target_name}__dist"
81 _exec_output =
82 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
83
84 executable(_exec_target) {
85 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
86 configs = []
87 data_deps = []
jbudorickd29ecfa72016-11-18 22:45:4288 forward_variables_from(invoker,
89 "*",
90 _wrapper_script_vars + [ "extra_dist_files" ])
agrieve62ab00282016-04-05 02:03:4591 testonly = true
92
93 # Thanks to the set_defaults() for test(), configs are initialized with
94 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:5995 configs -= [
96 "//build/config:shared_library_config",
97 "//build/config/android:hide_all_but_jni",
98 ]
agrieve62ab00282016-04-05 02:03:4599 configs += [ "//build/config:executable_config" ]
100
101 # Don't output to the root or else conflict with the group() below.
102 output_name = rebase_path(_exec_output, root_out_dir)
agrieve62ab00282016-04-05 02:03:45103 }
104
105 create_native_executable_dist(_dist_target) {
106 testonly = true
107 dist_dir = "$root_out_dir/$target_name"
108 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22109 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45110 if (defined(invoker.extra_dist_files)) {
111 extra_files = invoker.extra_dist_files
112 }
113 }
114 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02115 _library_target = "${target_name}__library"
116 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45117 _apk_specific_vars = [
118 "android_manifest",
agrievec6811b422016-06-23 02:25:09119 "android_manifest_dep",
Clark DuVall1bee5322020-06-10 05:51:55120 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45121 "enable_multidex",
Benoît Lizéd8b8f742019-11-07 12:50:07122 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02123 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07124 "proguard_configs",
125 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45126 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02127 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45128 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56129 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45130 ]
Siddhartha764226b2018-03-13 02:32:55131
132 # Adds the unwind tables from unstripped binary as an asset file in the
133 # apk, if |add_unwind_tables_in_apk| is specified by the test.
134 if (defined(invoker.add_unwind_tables_in_apk) &&
135 invoker.add_unwind_tables_in_apk) {
136 _unwind_table_asset_name = "${target_name}_unwind_assets"
137 unwind_table_asset(_unwind_table_asset_name) {
138 testonly = true
139 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22140 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55141 }
142 }
143
agrieve62ab00282016-04-05 02:03:45144 shared_library(_library_target) {
145 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
146 configs = [] # Prevent list overwriting warning.
147 configs = invoker.configs
148 testonly = true
149
150 deps = []
jbudorickd29ecfa72016-11-18 22:45:42151 forward_variables_from(
152 invoker,
153 "*",
154 _apk_specific_vars + _wrapper_script_vars + [ "visibility" ])
agrieve62ab00282016-04-05 02:03:45155
156 if (!defined(invoker.use_default_launcher) ||
157 invoker.use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37158 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45159 }
160 }
161 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54162 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07163 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45164 apk_name = invoker.target_name
165 if (defined(invoker.output_name)) {
166 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45167 install_script_name = "install_${invoker.output_name}"
168 }
agrieveb355ad152016-04-19 03:45:23169
Daniel Bratellfdda4652019-01-31 15:45:54170 if (defined(invoker.deps)) {
171 deps = invoker.deps
172 } else {
173 deps = []
174 }
175
jcivellif4462a352017-01-10 04:45:59176 # Add the Java classes so that each target does not have to do it.
177 deps += [ "//base/test:test_support_java" ]
178
Siddhartha764226b2018-03-13 02:32:55179 if (defined(_unwind_table_asset_name)) {
180 deps += [ ":${_unwind_table_asset_name}" ]
181 }
agrieve62ab00282016-04-05 02:03:45182 }
Andrew Grievee1dc23f2019-10-22 16:26:36183 }
agrieve62ab00282016-04-05 02:03:45184
Andrew Grievee1dc23f2019-10-22 16:26:36185 test_runner_script(_test_runner_target) {
186 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57187
Andrew Grievee1dc23f2019-10-22 16:26:36188 if (_use_raw_android_executable) {
189 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34190 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36191 } else {
192 apk_target = ":$_apk_target"
193 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47194
195 # Dep needed for the test runner .runtime_deps file to pick up data
196 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22197 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45198 }
Andrew Grievee1dc23f2019-10-22 16:26:36199 test_name = _output_name
200 test_suite = _output_name
201 test_type = "gtest"
mikecase56d80d72015-06-03 00:57:26202 }
203
Andrew Grieve7ca6de32019-10-18 03:57:47204 # Create a wrapper script rather than using a group() in order to ensure
205 # "ninja $target_name" always works. If this was a group(), then GN would
206 # not create a top-level alias for it if a target exists in another
207 # directory with the same $target_name.
208 # Also - bots run this script directly for "components_perftests".
209 generate_wrapper(target_name) {
210 testonly = true
211 executable = "$root_build_dir/bin/run_$_output_name"
212 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22213 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40214 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47215 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40216 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47217 # Dep needed for the swarming .isolate file to pick up data
218 # deps from the forward_variables_from(invoker, "*") on the library.
219 deps += [
220 ":$_apk_target",
221 ":$_library_target",
222 ]
agrieve62ab00282016-04-05 02:03:45223 }
agrieve1a02e582015-10-15 21:35:39224 }
Scott Graham4c4cdc52017-05-29 20:45:03225 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30226 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
227
Scott Graham4c4cdc52017-05-29 20:45:03228 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42229 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42230 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03231
Kevin Marshall39b4aa82018-06-23 00:12:15232 fuchsia_package_runner(target_name) {
Kevin Marshallf35fa5f2018-01-29 19:24:42233 testonly = true
Dirk Pranked5e9a1b22020-10-28 22:52:59234 is_test_exe = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53235 forward_variables_from(invoker,
236 [
237 "use_test_server",
238 "package_deps",
239 ])
Kevin Marshall39b4aa82018-06-23 00:12:15240 runner_script = "//build/fuchsia/test_runner.py"
241 package = ":$_pkg_target"
242 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42243
Wezdd593a52020-04-08 17:09:46244 data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Kevin Marshallf35fa5f2018-01-29 19:24:42245 }
246
Wezabe2d752020-02-11 17:12:23247 cr_fuchsia_package(_pkg_target) {
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20248 testonly = true
Fabrice de Gans-Ribericc810d32019-07-08 22:44:16249 forward_variables_from(invoker, [ "manifest" ])
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20250 binary = ":$_exec_target"
251 package_name_override = _output_name
252 }
253
Kevin Marshallf35fa5f2018-01-29 19:24:42254 executable(_exec_target) {
Scott Graham4c4cdc52017-05-29 20:45:03255 forward_variables_from(invoker, "*")
Kevin Marshall39b4aa82018-06-23 00:12:15256 testonly = true
Kevin Marshallf35fa5f2018-01-29 19:24:42257 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03258 }
dpranke2a294622015-08-07 05:23:01259 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30260 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46261 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30262
Rohit Raof9b096d2019-09-09 22:26:23263 declare_args() {
264 # Keep the unittest-as-xctest functionality defaulted to off until the
265 # bots are updated to handle it properly.
266 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
267 # supports running unittests with xctest.
268 enable_run_ios_unittests_with_xctest = false
269 }
270
sdefresne012857872016-03-16 10:55:37271 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36272 _wrapper_output_name = "run_${target_name}"
273 ios_test_runner_wrapper(_wrapper_output_name) {
274 forward_variables_from(invoker,
275 [
276 "data",
277 "data_deps",
278 "deps",
279 "executable_args",
280 "retries",
281 "shards",
282 ])
283
284 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
285
286 if (!defined(executable_args)) {
287 executable_args = []
288 }
289 executable_args += [
290 "--app",
291 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
292 ]
293
294 wrapper_output_name = "${_wrapper_output_name}"
295 }
296
sdefresne012857872016-03-16 10:55:37297 _resources_bundle_data = target_name + "_resources_bundle_data"
298
299 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34300 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22301 sources = [ "//testing/gtest_ios/Default.png" ]
302 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01303 }
304
Mirko Bonadei15522bc2020-09-16 20:38:39305 force_xctest = enable_run_ios_unittests_with_xctest ||
306 (defined(invoker.is_xctest) && invoker.is_xctest)
307
308 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23309 ios_test_target_type = "ios_xctest_test"
310 } else {
311 ios_test_target_type = "ios_app_bundle"
312 }
313
314 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01315 testonly = true
sdefresnea828c282016-05-30 18:04:20316
Mirko Bonadei15522bc2020-09-16 20:38:39317 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23318 xctest_module_target = "//base/test:google_test_runner"
319 }
320
sdefresne9e147e02016-06-07 00:10:13321 forward_variables_from(invoker, "*", [ "testonly" ])
322
323 # Provide sensible defaults in case invoker did not define any of those
324 # required variables.
sdefresne05b97ca2016-06-08 07:19:46325 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13326 info_plist = "//testing/gtest_ios/unittest-Info.plist"
327 }
sdefresne9e147e02016-06-07 00:10:13328
Olivier Robin9689c562020-04-17 14:03:57329 _gtest_bundle_id_suffix = "${target_name}"
330 xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19331
sdefresne9e147e02016-06-07 00:10:13332 if (!defined(extra_substitutions)) {
333 extra_substitutions = []
334 }
Olivier Robin9689c562020-04-17 14:03:57335 extra_substitutions +=
336 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01337
sdefresne047490e2016-07-22 08:49:34338 if (!defined(bundle_deps)) {
339 bundle_deps = []
340 }
341 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36342
343 if (!defined(data_deps)) {
344 data_deps = []
345 }
346
347 # Include the generate_wrapper as part of data_deps
348 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46349 write_runtime_deps = _runtime_deps_file
dpranke2a294622015-08-07 05:23:01350 }
George Burgess IVe62d7c52020-02-22 01:22:42351 } else if (is_chromeos && cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30352 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
353
Ben Pastene16882032018-09-21 01:16:39354 # Building for a cros board (ie: not linux-chromeos).
Benjamin Pastene3bce864e2018-04-14 01:16:32355
Benjamin Pastene3bce864e2018-04-14 01:16:32356 _gen_runner_target = "${target_name}__runner"
357 _runtime_deps_file =
358 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
359 "/" + get_label_info(target_name, "name") + ".runtime_deps"
360
Ben Pastene4ab98652018-12-17 18:33:18361 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32362 testonly = true
363 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39364 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32365 runtime_deps_file = _runtime_deps_file
366 }
367
368 executable(target_name) {
369 forward_variables_from(invoker, "*")
370 if (!defined(deps)) {
371 deps = []
372 }
373 if (!defined(data)) {
374 data = []
375 }
376
Ben Pastene41041782019-02-16 04:21:58377 # We use a special trigger script for CrOS hardware tests.
378 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
379
Benjamin Pastene3bce864e2018-04-14 01:16:32380 testonly = true
381 output_name = target_name
382 write_runtime_deps = _runtime_deps_file
383 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37384 deps += [ ":$_gen_runner_target" ]
Benjamin Pastene3bce864e2018-04-14 01:16:32385 }
Dirk Pranke31e346e2020-07-15 00:54:06386 } else if (is_chromeos && cros_board == "") {
Dirk Pranke79d065d2020-08-29 03:28:30387 # TODO(crbug.com/816629) - Make use_xvfb work right in this situation.
388 not_needed([ "use_xvfb" ])
Dirk Pranke956c4dc2020-07-02 00:54:27389 executable(target_name) {
Dirk Pranke79d065d2020-08-29 03:28:30390 forward_variables_from(invoker, "*", [ "use_xvfb" ])
Dirk Pranke956c4dc2020-07-02 00:54:27391 if (!defined(deps)) {
392 deps = []
393 }
394
Dirk Pranke956c4dc2020-07-02 00:54:27395 testonly = true
Dirk Pranke956c4dc2020-07-02 00:54:27396 }
Yuke Liaoe703384b2020-07-16 01:05:24397 } else if (chromeos_is_browser_only) {
398 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
399 _executable = target_name
400 _gen_runner_target = "${target_name}__runner"
401
Yuke Liao32af4242020-07-16 21:48:02402 if (defined(invoker.use_xvfb)) {
403 _use_xvfb = invoker.use_xvfb
404 } else {
405 _use_xvfb = false
406 }
407
Yuke Liaod037abc2020-10-06 22:48:22408 # When use_xvfb is set by the invoker, it indicates that running this test
409 # target requires a window, and in lacros build, ash-chrome serves as the
410 # display server. Note that even though the tests themselves do not require
411 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
412 # because ash-chrome is based on x11.
413 _use_ash_chrome = _use_xvfb
414
Yuke Liaoe703384b2020-07-16 01:05:24415 generate_wrapper(_gen_runner_target) {
416 testonly = true
417 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02418
Yuke Liao2e4953cf2020-07-26 19:20:19419 data = []
Yuke Liao32af4242020-07-16 21:48:02420 if (_use_xvfb) {
421 executable = "//testing/xvfb.py"
Yuke Liao2e4953cf2020-07-26 19:20:19422 data += [ "//testing/xvfb.py" ]
Yuke Liao32af4242020-07-16 21:48:02423 } else {
424 executable = "//testing/test_env.py"
Yuke Liao2e4953cf2020-07-26 19:20:19425 data += [ "//testing/test_env.py" ]
Yuke Liao32af4242020-07-16 21:48:02426 }
427
Yuke Liaoe703384b2020-07-16 01:05:24428 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02429 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39430 "test",
Yuke Liaoe703384b2020-07-16 01:05:24431 "@WrappedPath(./${_executable})",
432 "--test-launcher-bot-mode",
433 ]
Yuke Liao32af4242020-07-16 21:48:02434
Yuke Liaof540c742020-07-29 16:28:34435 if (_use_ash_chrome) {
Yuke Liao6d9d5be82020-10-21 05:45:01436 if (also_build_ash_chrome) {
437 executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ]
438 } else {
439 # TODO(crbug.com/1129223): Remove in ~1week after
440 # http://crrev.com/c/2487696 lands and is not reverted.
441 executable_args += [ "--ash-chrome-version=for_bots" ]
442 }
Yuke Liao240816d2020-07-22 00:10:39443 }
444
Yuke Liaoe703384b2020-07-16 01:05:24445 if (is_asan) {
446 executable_args += [ "--asan=true" ]
447 }
448 if (is_msan) {
449 executable_args += [ "--msan=true" ]
450 }
451 if (is_tsan) {
452 executable_args += [ "--tsan=true" ]
453 }
454 if (use_cfi_diag) {
455 executable_args += [ "--cfi-diag=true" ]
456 }
457
Yuke Liao2e4953cf2020-07-26 19:20:19458 data += [
Yuke Liao240816d2020-07-22 00:10:39459 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24460 "//.vpython",
461 ]
Yuke Liaof540c742020-07-29 16:28:34462 if (_use_ash_chrome) {
Yuke Liao240816d2020-07-22 00:10:39463 data += [ "//build/lacros/prebuilt_ash_chrome/for_bots" ]
464 }
Yuke Liaoe703384b2020-07-16 01:05:24465 }
466
467 executable(target_name) {
468 forward_variables_from(invoker, "*")
469 if (!defined(deps)) {
470 deps = []
471 }
472
Yuke Liaod037abc2020-10-06 22:48:22473 if (!defined(data_deps)) {
474 data_deps = []
475 }
476
Yuke Liaoe703384b2020-07-16 01:05:24477 testonly = true
478 write_runtime_deps = _runtime_deps_file
479 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22480 if (_use_ash_chrome && also_build_ash_chrome) {
481 data_deps +=
482 [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ]
483 }
Yuke Liaoe703384b2020-07-16 01:05:24484 }
Dirk Pranke31e346e2020-07-15 00:54:06485 } else {
Dirk Pranke79d065d2020-08-29 03:28:30486 if (is_mac || is_win) {
487 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
488 }
489
Dirk Pranke31e346e2020-07-15 00:54:06490 if ((is_linux && !is_chromeos) || is_mac || is_win) {
491 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
492 _executable = target_name
493 _gen_runner_target = "${target_name}__runner"
494
Sean McAllister88fbd902020-07-30 19:27:03495 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
Dirk Pranke31e346e2020-07-15 00:54:06496 _use_xvfb = invoker.use_xvfb
497 } else {
498 _use_xvfb = false
499 }
500
Will Harrisc218db232020-07-21 20:20:57501 if (is_win) {
502 if (defined(invoker.win_test_enable_cfi_linker)) {
503 _win_test_enable_cfi_linker = invoker.win_test_enable_cfi_linker
504 } else {
505 _win_test_enable_cfi_linker = false
506 }
507 }
508
Dirk Pranke31e346e2020-07-15 00:54:06509 generate_wrapper(_gen_runner_target) {
510 testonly = true
511 wrapper_script = "$root_build_dir/bin/run_" + _executable
512
Yuke Liao2e4953cf2020-07-26 19:20:19513 data = []
Dirk Pranke31e346e2020-07-15 00:54:06514 if (_use_xvfb) {
515 executable = "//testing/xvfb.py"
Yuke Liao2e4953cf2020-07-26 19:20:19516 data += [ "//testing/xvfb.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06517 } else {
518 executable = "//testing/test_env.py"
Yuke Liao2e4953cf2020-07-26 19:20:19519 data += [ "//testing/test_env.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06520 }
521
522 executable_args = [
523 "@WrappedPath(./${_executable})",
524 "--test-launcher-bot-mode",
525 ]
526 if (is_asan) {
527 executable_args += [ "--asan=true" ]
528 }
529 if (is_msan) {
530 executable_args += [ "--msan=true" ]
531 }
532 if (is_tsan) {
533 executable_args += [ "--tsan=true" ]
534 }
535 if (use_cfi_diag) {
536 executable_args += [ "--cfi-diag=true" ]
537 }
538
Yuke Liao2e4953cf2020-07-26 19:20:19539 data += [ "//.vpython" ]
Dirk Pranke31e346e2020-07-15 00:54:06540 }
541 }
542
543 executable(target_name) {
Dirk Pranke79d065d2020-08-29 03:28:30544 forward_variables_from(invoker, "*", [ "use_xvfb" ])
Dirk Pranke31e346e2020-07-15 00:54:06545 if (!defined(deps)) {
546 deps = []
547 }
548
549 if (is_win) {
Will Harrisc218db232020-07-21 20:20:57550 if (!_win_test_enable_cfi_linker) {
551 # Initializing CFG data during process creation is a significant
552 # bottleneck for large test binaries, and CFG is not needed for
553 # most tests, so disable it. See https://crbug.com/950923 for
554 # details. This can be overridden by specifying
555 # win_test_enable_cfi_linker.
556 configs -= [ "//build/config/win:cfi_linker" ]
557 }
Dirk Pranke31e346e2020-07-15 00:54:06558 }
559 testonly = true
560 deps += [
561 # Give tests the default manifest on Windows (a no-op elsewhere).
562 "//build/win:default_exe_manifest",
563 ]
564
Sean McAllister88fbd902020-07-30 19:27:03565 if (is_linux || is_chromeos || is_mac || is_win) {
Dirk Pranke31e346e2020-07-15 00:54:06566 write_runtime_deps = _runtime_deps_file
567 deps += [ ":$_gen_runner_target" ]
568 }
569 }
qsrfb5251d12015-01-21 15:57:22570 }
571}
brettwedb6ecc2016-07-14 23:37:03572
Dirk Pranke6188075b2020-10-01 19:31:28573# Defines a type of test that invokes a script to run, rather than
574# invoking an executable.
575#
576# The script must implement the
577# [test executable API](//docs/testing/test_executable_api.md).
578#
579# The template must be passed the `script` parameter, which specifies
580# the path to the script to run. It may optionally be passed a
581# `script_args` parameter, which can be used to include a list of
582# args to be specified by default. The template will produce
583# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
584# for the target to $root_build_dir/${target_name}.runtime_deps, as per
585# the conventions listed in the
586# [test wrapper API](//docs/testing/test_wrapper_api.md).
587template("script_test") {
588 generate_wrapper(target_name) {
589 testonly = true
590 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
591
592 executable = "//testing/test_env.py"
593
594 executable_args =
595 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
596 if (defined(invoker.args)) {
597 executable_args += invoker.args
598 }
599
600 data = [
601 "//.vpython",
602 "//testing/test_env.py",
603
604 # These aren't needed by *every* test, but they're likely needed often
605 # enough to just make it easier to declare them here.
606 "//testing/xvfb.py",
607 "//testing/scripts/common.py",
608
609 invoker.script,
610 ]
611 if (defined(invoker.data)) {
612 data += invoker.data
613 }
614 data_deps = []
615 if (defined(invoker.data_deps)) {
616 data_deps += invoker.data_deps
617 }
618
619 forward_variables_from(invoker,
620 [ "*" ],
621 [
622 "data",
623 "data_deps",
624 "script",
625 "script_args",
626 "testonly",
627 ])
628
629 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
630 }
631}
632
brettwedb6ecc2016-07-14 23:37:03633# Test defaults.
634set_defaults("test") {
635 if (is_android) {
636 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41637 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59638 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03639 } else {
640 configs = default_executable_configs
641 }
642}