blob: 90a0a14d6a62e097b42b471e41477c92f7be8787 [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")
Dirk Prankedd4ff742020-11-18 19:57:3217} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0618 import("//build/config/chromecast_build.gni")
Kevin Marshall55fd8522019-10-04 22:47:0119 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4220 import("//build/config/fuchsia/package.gni")
Dirk Prankedd4ff742020-11-18 19:57:3221} else if (is_chromeos) {
Ben Pastene4c35c572018-04-30 23:21:4822 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3223 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2824 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3225} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3626 import("//build/config/ios/ios_sdk.gni")
27 import("//build/config/ios/ios_test_runner_wrapper.gni")
28 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3229} else {
Dirk Pranke31e346e2020-07-15 00:54:0630 import("//build/config/sanitizers/sanitizers.gni")
31 import("//build/util/generate_wrapper.gni")
32}
33
qsrfb5251d12015-01-21 15:57:2234# Define a test as an executable (or apk on Android) with the "testonly" flag
35# set.
agrieve62ab00282016-04-05 02:03:4536# Variable:
Dirk Pranke79d065d2020-08-29 03:28:3037# use_xvfb: (optional) whether to run the executable under Xvfb.
agrieve62ab00282016-04-05 02:03:4538# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:5639# use_native_activity: Test implements ANativeActivity_onCreate().
Mirko Bonadei15522bc2020-09-16 20:38:3940# is_xctest: (iOS, optional) whether to build the executable as XCTest.
41# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
42# for build targets.
qsrfb5251d12015-01-21 15:57:2243template("test") {
Mirko Bonadei15522bc2020-09-16 20:38:3944 if (!is_ios) {
45 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
46 "is_xctest can be set only for iOS builds")
47 }
qsrfb5251d12015-01-21 15:57:2248 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3049 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
50
agrieve62ab00282016-04-05 02:03:4551 _use_raw_android_executable = defined(invoker.use_raw_android_executable) &&
52 invoker.use_raw_android_executable
qsrfb5251d12015-01-21 15:57:2253
agrieve67855de2016-03-30 14:46:0154 # output_name is used to allow targets with the same name but in different
55 # packages to still produce unique runner scripts.
56 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2657 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0158 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2659 }
agrieve62ab00282016-04-05 02:03:4560
agrieveb355ad152016-04-19 03:45:2361 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4262 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:5163 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4264 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:5165 ]
agrieve3ac557f02016-04-12 15:52:0066
jbudorickced2a252016-06-09 16:38:5467 assert(_use_raw_android_executable || enable_java_templates)
68
agrieve62ab00282016-04-05 02:03:4569 if (_use_raw_android_executable) {
70 _exec_target = "${target_name}__exec"
71 _dist_target = "${target_name}__dist"
72 _exec_output =
73 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
74
75 executable(_exec_target) {
76 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
77 configs = []
78 data_deps = []
jbudorickd29ecfa72016-11-18 22:45:4279 forward_variables_from(invoker,
80 "*",
81 _wrapper_script_vars + [ "extra_dist_files" ])
agrieve62ab00282016-04-05 02:03:4582 testonly = true
83
84 # Thanks to the set_defaults() for test(), configs are initialized with
85 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:5986 configs -= [
87 "//build/config:shared_library_config",
88 "//build/config/android:hide_all_but_jni",
89 ]
agrieve62ab00282016-04-05 02:03:4590 configs += [ "//build/config:executable_config" ]
91
92 # Don't output to the root or else conflict with the group() below.
93 output_name = rebase_path(_exec_output, root_out_dir)
agrieve62ab00282016-04-05 02:03:4594 }
95
96 create_native_executable_dist(_dist_target) {
97 testonly = true
98 dist_dir = "$root_out_dir/$target_name"
99 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22100 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45101 if (defined(invoker.extra_dist_files)) {
102 extra_files = invoker.extra_dist_files
103 }
104 }
105 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02106 _library_target = "${target_name}__library"
107 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45108 _apk_specific_vars = [
109 "android_manifest",
agrievec6811b422016-06-23 02:25:09110 "android_manifest_dep",
Clark DuVall1bee5322020-06-10 05:51:55111 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45112 "enable_multidex",
Benoît Lizéd8b8f742019-11-07 12:50:07113 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02114 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07115 "proguard_configs",
116 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45117 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02118 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45119 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56120 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45121 ]
Siddhartha764226b2018-03-13 02:32:55122
123 # Adds the unwind tables from unstripped binary as an asset file in the
124 # apk, if |add_unwind_tables_in_apk| is specified by the test.
125 if (defined(invoker.add_unwind_tables_in_apk) &&
126 invoker.add_unwind_tables_in_apk) {
127 _unwind_table_asset_name = "${target_name}_unwind_assets"
128 unwind_table_asset(_unwind_table_asset_name) {
129 testonly = true
130 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22131 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55132 }
133 }
134
agrieve62ab00282016-04-05 02:03:45135 shared_library(_library_target) {
136 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
137 configs = [] # Prevent list overwriting warning.
138 configs = invoker.configs
139 testonly = true
140
141 deps = []
jbudorickd29ecfa72016-11-18 22:45:42142 forward_variables_from(
143 invoker,
144 "*",
145 _apk_specific_vars + _wrapper_script_vars + [ "visibility" ])
agrieve62ab00282016-04-05 02:03:45146
147 if (!defined(invoker.use_default_launcher) ||
148 invoker.use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37149 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45150 }
151 }
152 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54153 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07154 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45155 apk_name = invoker.target_name
156 if (defined(invoker.output_name)) {
157 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45158 install_script_name = "install_${invoker.output_name}"
159 }
agrieveb355ad152016-04-19 03:45:23160
Daniel Bratellfdda4652019-01-31 15:45:54161 if (defined(invoker.deps)) {
162 deps = invoker.deps
163 } else {
164 deps = []
165 }
166
jcivellif4462a352017-01-10 04:45:59167 # Add the Java classes so that each target does not have to do it.
168 deps += [ "//base/test:test_support_java" ]
169
Siddhartha764226b2018-03-13 02:32:55170 if (defined(_unwind_table_asset_name)) {
171 deps += [ ":${_unwind_table_asset_name}" ]
172 }
agrieve62ab00282016-04-05 02:03:45173 }
Andrew Grievee1dc23f2019-10-22 16:26:36174 }
agrieve62ab00282016-04-05 02:03:45175
Andrew Grievee1dc23f2019-10-22 16:26:36176 test_runner_script(_test_runner_target) {
177 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57178
Andrew Grievee1dc23f2019-10-22 16:26:36179 if (_use_raw_android_executable) {
180 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34181 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36182 } else {
183 apk_target = ":$_apk_target"
184 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47185
186 # Dep needed for the test runner .runtime_deps file to pick up data
187 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22188 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45189 }
Andrew Grievee1dc23f2019-10-22 16:26:36190 test_name = _output_name
191 test_suite = _output_name
192 test_type = "gtest"
mikecase56d80d72015-06-03 00:57:26193 }
194
Andrew Grieve7ca6de32019-10-18 03:57:47195 # Create a wrapper script rather than using a group() in order to ensure
196 # "ninja $target_name" always works. If this was a group(), then GN would
197 # not create a top-level alias for it if a target exists in another
198 # directory with the same $target_name.
199 # Also - bots run this script directly for "components_perftests".
200 generate_wrapper(target_name) {
201 testonly = true
202 executable = "$root_build_dir/bin/run_$_output_name"
203 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22204 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40205 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47206 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40207 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47208 # Dep needed for the swarming .isolate file to pick up data
209 # deps from the forward_variables_from(invoker, "*") on the library.
210 deps += [
211 ":$_apk_target",
212 ":$_library_target",
213 ]
agrieve62ab00282016-04-05 02:03:45214 }
agrieve1a02e582015-10-15 21:35:39215 }
Scott Graham4c4cdc52017-05-29 20:45:03216 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30217 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
218
Scott Graham4c4cdc52017-05-29 20:45:03219 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42220 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42221 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03222
Kevin Marshall39b4aa82018-06-23 00:12:15223 fuchsia_package_runner(target_name) {
Kevin Marshallf35fa5f2018-01-29 19:24:42224 testonly = true
Dirk Pranked5e9a1b22020-10-28 22:52:59225 is_test_exe = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53226 forward_variables_from(invoker,
227 [
228 "use_test_server",
229 "package_deps",
230 ])
Kevin Marshall39b4aa82018-06-23 00:12:15231 runner_script = "//build/fuchsia/test_runner.py"
232 package = ":$_pkg_target"
233 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42234
Wezdd593a52020-04-08 17:09:46235 data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Kevin Marshallf35fa5f2018-01-29 19:24:42236 }
237
Wezabe2d752020-02-11 17:12:23238 cr_fuchsia_package(_pkg_target) {
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20239 testonly = true
Fabrice de Gans-Ribericc810d32019-07-08 22:44:16240 forward_variables_from(invoker, [ "manifest" ])
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20241 binary = ":$_exec_target"
242 package_name_override = _output_name
243 }
244
Kevin Marshallf35fa5f2018-01-29 19:24:42245 executable(_exec_target) {
Scott Graham4c4cdc52017-05-29 20:45:03246 forward_variables_from(invoker, "*")
Kevin Marshall39b4aa82018-06-23 00:12:15247 testonly = true
Kevin Marshallf35fa5f2018-01-29 19:24:42248 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03249 }
dpranke2a294622015-08-07 05:23:01250 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30251 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46252 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30253
Rohit Raof9b096d2019-09-09 22:26:23254 declare_args() {
255 # Keep the unittest-as-xctest functionality defaulted to off until the
256 # bots are updated to handle it properly.
257 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
258 # supports running unittests with xctest.
259 enable_run_ios_unittests_with_xctest = false
260 }
261
sdefresne012857872016-03-16 10:55:37262 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36263 _wrapper_output_name = "run_${target_name}"
264 ios_test_runner_wrapper(_wrapper_output_name) {
265 forward_variables_from(invoker,
266 [
267 "data",
268 "data_deps",
269 "deps",
270 "executable_args",
271 "retries",
272 "shards",
273 ])
274
275 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
276
277 if (!defined(executable_args)) {
278 executable_args = []
279 }
280 executable_args += [
281 "--app",
282 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
283 ]
284
285 wrapper_output_name = "${_wrapper_output_name}"
286 }
287
sdefresne012857872016-03-16 10:55:37288 _resources_bundle_data = target_name + "_resources_bundle_data"
289
290 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34291 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22292 sources = [ "//testing/gtest_ios/Default.png" ]
293 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01294 }
295
Mirko Bonadei15522bc2020-09-16 20:38:39296 force_xctest = enable_run_ios_unittests_with_xctest ||
297 (defined(invoker.is_xctest) && invoker.is_xctest)
298
299 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23300 ios_test_target_type = "ios_xctest_test"
301 } else {
302 ios_test_target_type = "ios_app_bundle"
303 }
304
305 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01306 testonly = true
sdefresnea828c282016-05-30 18:04:20307
Mirko Bonadei15522bc2020-09-16 20:38:39308 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23309 xctest_module_target = "//base/test:google_test_runner"
310 }
311
sdefresne9e147e02016-06-07 00:10:13312 forward_variables_from(invoker, "*", [ "testonly" ])
313
314 # Provide sensible defaults in case invoker did not define any of those
315 # required variables.
sdefresne05b97ca2016-06-08 07:19:46316 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13317 info_plist = "//testing/gtest_ios/unittest-Info.plist"
318 }
sdefresne9e147e02016-06-07 00:10:13319
Olivier Robin9689c562020-04-17 14:03:57320 _gtest_bundle_id_suffix = "${target_name}"
321 xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19322
sdefresne9e147e02016-06-07 00:10:13323 if (!defined(extra_substitutions)) {
324 extra_substitutions = []
325 }
Olivier Robin9689c562020-04-17 14:03:57326 extra_substitutions +=
327 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01328
sdefresne047490e2016-07-22 08:49:34329 if (!defined(bundle_deps)) {
330 bundle_deps = []
331 }
332 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36333
334 if (!defined(data_deps)) {
335 data_deps = []
336 }
337
338 # Include the generate_wrapper as part of data_deps
339 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46340 write_runtime_deps = _runtime_deps_file
dpranke2a294622015-08-07 05:23:01341 }
George Burgess IVe62d7c52020-02-22 01:22:42342 } else if (is_chromeos && cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30343 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
344
Ben Pastene16882032018-09-21 01:16:39345 # Building for a cros board (ie: not linux-chromeos).
Benjamin Pastene3bce864e2018-04-14 01:16:32346
Benjamin Pastene3bce864e2018-04-14 01:16:32347 _gen_runner_target = "${target_name}__runner"
348 _runtime_deps_file =
349 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
350 "/" + get_label_info(target_name, "name") + ".runtime_deps"
351
Ben Pastene4ab98652018-12-17 18:33:18352 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32353 testonly = true
354 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39355 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32356 runtime_deps_file = _runtime_deps_file
357 }
358
359 executable(target_name) {
360 forward_variables_from(invoker, "*")
361 if (!defined(deps)) {
362 deps = []
363 }
364 if (!defined(data)) {
365 data = []
366 }
367
Ben Pastene41041782019-02-16 04:21:58368 # We use a special trigger script for CrOS hardware tests.
369 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
370
Benjamin Pastene3bce864e2018-04-14 01:16:32371 testonly = true
372 output_name = target_name
373 write_runtime_deps = _runtime_deps_file
374 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37375 deps += [ ":$_gen_runner_target" ]
Benjamin Pastene3bce864e2018-04-14 01:16:32376 }
Yuke Liaoe703384b2020-07-16 01:05:24377 } else if (chromeos_is_browser_only) {
378 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
379 _executable = target_name
380 _gen_runner_target = "${target_name}__runner"
381
Yuke Liao32af4242020-07-16 21:48:02382 if (defined(invoker.use_xvfb)) {
383 _use_xvfb = invoker.use_xvfb
384 } else {
385 _use_xvfb = false
386 }
387
Yuke Liaod037abc2020-10-06 22:48:22388 # When use_xvfb is set by the invoker, it indicates that running this test
389 # target requires a window, and in lacros build, ash-chrome serves as the
390 # display server. Note that even though the tests themselves do not require
391 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
392 # because ash-chrome is based on x11.
393 _use_ash_chrome = _use_xvfb
394
Yuke Liaoe703384b2020-07-16 01:05:24395 generate_wrapper(_gen_runner_target) {
396 testonly = true
397 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02398
Yuke Liao2e4953cf2020-07-26 19:20:19399 data = []
Yuke Liao32af4242020-07-16 21:48:02400 if (_use_xvfb) {
401 executable = "//testing/xvfb.py"
Yuke Liao2e4953cf2020-07-26 19:20:19402 data += [ "//testing/xvfb.py" ]
Yuke Liao32af4242020-07-16 21:48:02403 } else {
404 executable = "//testing/test_env.py"
Yuke Liao2e4953cf2020-07-26 19:20:19405 data += [ "//testing/test_env.py" ]
Yuke Liao32af4242020-07-16 21:48:02406 }
407
Yuke Liaoe703384b2020-07-16 01:05:24408 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02409 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39410 "test",
Yuke Liaoe703384b2020-07-16 01:05:24411 "@WrappedPath(./${_executable})",
412 "--test-launcher-bot-mode",
413 ]
Yuke Liao32af4242020-07-16 21:48:02414
Yuke Liaof540c742020-07-29 16:28:34415 if (_use_ash_chrome) {
Yuke Liao8348aa42020-11-04 19:35:23416 executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ]
Yuke Liao240816d2020-07-22 00:10:39417 }
418
Yuke Liaoe703384b2020-07-16 01:05:24419 if (is_asan) {
420 executable_args += [ "--asan=true" ]
421 }
422 if (is_msan) {
423 executable_args += [ "--msan=true" ]
424 }
425 if (is_tsan) {
426 executable_args += [ "--tsan=true" ]
427 }
428 if (use_cfi_diag) {
429 executable_args += [ "--cfi-diag=true" ]
430 }
431
Yuke Liao2e4953cf2020-07-26 19:20:19432 data += [
Yuke Liao240816d2020-07-22 00:10:39433 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24434 "//.vpython",
435 ]
436 }
437
438 executable(target_name) {
439 forward_variables_from(invoker, "*")
440 if (!defined(deps)) {
441 deps = []
442 }
443
Yuke Liaod037abc2020-10-06 22:48:22444 if (!defined(data_deps)) {
445 data_deps = []
446 }
447
Yuke Liaoe703384b2020-07-16 01:05:24448 testonly = true
449 write_runtime_deps = _runtime_deps_file
450 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22451 if (_use_ash_chrome && also_build_ash_chrome) {
452 data_deps +=
453 [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ]
454 }
Yuke Liaoe703384b2020-07-16 01:05:24455 }
Dirk Prankedd4ff742020-11-18 19:57:32456 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30457 if (is_mac || is_win) {
458 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
459 }
460
Dirk Prankedd4ff742020-11-18 19:57:32461 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
462 _executable = target_name
463 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06464
Dirk Prankedd4ff742020-11-18 19:57:32465 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
466 _use_xvfb = invoker.use_xvfb
467 } else {
468 _use_xvfb = false
469 }
470
471 generate_wrapper(_gen_runner_target) {
472 testonly = true
473 wrapper_script = "$root_build_dir/bin/run_" + _executable
474
475 data = []
476 if (_use_xvfb) {
477 executable = "//testing/xvfb.py"
478 data += [ "//testing/xvfb.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06479 } else {
Dirk Prankedd4ff742020-11-18 19:57:32480 executable = "//testing/test_env.py"
481 data += [ "//testing/test_env.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06482 }
483
Dirk Prankedd4ff742020-11-18 19:57:32484 executable_args = [
485 "@WrappedPath(./${_executable})",
486 "--test-launcher-bot-mode",
487 ]
488 if (is_asan) {
489 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06490 }
Dirk Prankedd4ff742020-11-18 19:57:32491 if (is_msan) {
492 executable_args += [ "--msan=true" ]
493 }
494 if (is_tsan) {
495 executable_args += [ "--tsan=true" ]
496 }
497 if (use_cfi_diag) {
498 executable_args += [ "--cfi-diag=true" ]
499 }
500
501 data += [ "//.vpython" ]
Dirk Pranke31e346e2020-07-15 00:54:06502 }
503
504 executable(target_name) {
Dirk Pranke79d065d2020-08-29 03:28:30505 forward_variables_from(invoker, "*", [ "use_xvfb" ])
Dirk Pranke31e346e2020-07-15 00:54:06506 if (!defined(deps)) {
507 deps = []
508 }
509
Dirk Pranke31e346e2020-07-15 00:54:06510 testonly = true
511 deps += [
512 # Give tests the default manifest on Windows (a no-op elsewhere).
513 "//build/win:default_exe_manifest",
514 ]
515
Dirk Prankedd4ff742020-11-18 19:57:32516 write_runtime_deps = _runtime_deps_file
517 deps += [ ":$_gen_runner_target" ]
518 }
519 } else {
520 # This is a catch-all clause for NaCl toolchains and other random
521 # configurations that might define tests; test() in these configs
522 # will just define the underlying executables.
523 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
524 "use_xvfb should not be defined for a non-linux configuration")
525 executable(target_name) {
526 forward_variables_from(invoker, "*")
527 if (!defined(deps)) {
528 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06529 }
Dirk Prankedd4ff742020-11-18 19:57:32530
531 testonly = true
Dirk Pranke31e346e2020-07-15 00:54:06532 }
qsrfb5251d12015-01-21 15:57:22533 }
534}
brettwedb6ecc2016-07-14 23:37:03535
Dirk Pranke6188075b2020-10-01 19:31:28536# Defines a type of test that invokes a script to run, rather than
537# invoking an executable.
538#
539# The script must implement the
540# [test executable API](//docs/testing/test_executable_api.md).
541#
542# The template must be passed the `script` parameter, which specifies
543# the path to the script to run. It may optionally be passed a
544# `script_args` parameter, which can be used to include a list of
545# args to be specified by default. The template will produce
546# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
547# for the target to $root_build_dir/${target_name}.runtime_deps, as per
548# the conventions listed in the
549# [test wrapper API](//docs/testing/test_wrapper_api.md).
550template("script_test") {
551 generate_wrapper(target_name) {
552 testonly = true
553 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
554
555 executable = "//testing/test_env.py"
556
557 executable_args =
558 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
559 if (defined(invoker.args)) {
560 executable_args += invoker.args
561 }
562
563 data = [
564 "//.vpython",
565 "//testing/test_env.py",
566
567 # These aren't needed by *every* test, but they're likely needed often
568 # enough to just make it easier to declare them here.
569 "//testing/xvfb.py",
570 "//testing/scripts/common.py",
571
572 invoker.script,
573 ]
574 if (defined(invoker.data)) {
575 data += invoker.data
576 }
577 data_deps = []
578 if (defined(invoker.data_deps)) {
579 data_deps += invoker.data_deps
580 }
581
582 forward_variables_from(invoker,
583 [ "*" ],
584 [
585 "data",
586 "data_deps",
587 "script",
588 "script_args",
589 "testonly",
590 ])
591
592 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
593 }
594}
595
brettwedb6ecc2016-07-14 23:37:03596# Test defaults.
597set_defaults("test") {
598 if (is_android) {
599 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41600 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59601 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03602 } else {
603 configs = default_executable_configs
604 }
605}