blob: bb6fbd2dcc27f2e146f9a07fae93ce68e800cd74 [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().
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") {
Mirko Bonadei15522bc2020-09-16 20:38:3952 if (!is_ios) {
53 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
54 "is_xctest can be set only for iOS builds")
55 }
qsrfb5251d12015-01-21 15:57:2256 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3057 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
58
agrieve62ab00282016-04-05 02:03:4559 _use_raw_android_executable = defined(invoker.use_raw_android_executable) &&
60 invoker.use_raw_android_executable
qsrfb5251d12015-01-21 15:57:2261
agrieve67855de2016-03-30 14:46:0162 # output_name is used to allow targets with the same name but in different
63 # packages to still produce unique runner scripts.
64 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2665 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0166 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2667 }
agrieve62ab00282016-04-05 02:03:4568
agrieveb355ad152016-04-19 03:45:2369 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4270 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:5171 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4272 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:5173 ]
agrieve3ac557f02016-04-12 15:52:0074
jbudorickced2a252016-06-09 16:38:5475 assert(_use_raw_android_executable || enable_java_templates)
76
agrieve62ab00282016-04-05 02:03:4577 if (_use_raw_android_executable) {
78 _exec_target = "${target_name}__exec"
79 _dist_target = "${target_name}__dist"
80 _exec_output =
81 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
82
83 executable(_exec_target) {
84 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
85 configs = []
86 data_deps = []
jbudorickd29ecfa72016-11-18 22:45:4287 forward_variables_from(invoker,
88 "*",
89 _wrapper_script_vars + [ "extra_dist_files" ])
agrieve62ab00282016-04-05 02:03:4590 testonly = true
91
92 # Thanks to the set_defaults() for test(), configs are initialized with
93 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:5994 configs -= [
95 "//build/config:shared_library_config",
96 "//build/config/android:hide_all_but_jni",
97 ]
agrieve62ab00282016-04-05 02:03:4598 configs += [ "//build/config:executable_config" ]
99
100 # Don't output to the root or else conflict with the group() below.
101 output_name = rebase_path(_exec_output, root_out_dir)
agrieve62ab00282016-04-05 02:03:45102 }
103
104 create_native_executable_dist(_dist_target) {
105 testonly = true
106 dist_dir = "$root_out_dir/$target_name"
107 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22108 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45109 if (defined(invoker.extra_dist_files)) {
110 extra_files = invoker.extra_dist_files
111 }
112 }
113 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02114 _library_target = "${target_name}__library"
115 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45116 _apk_specific_vars = [
117 "android_manifest",
agrievec6811b422016-06-23 02:25:09118 "android_manifest_dep",
Clark DuVall1bee5322020-06-10 05:51:55119 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45120 "enable_multidex",
Benoît Lizéd8b8f742019-11-07 12:50:07121 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02122 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07123 "proguard_configs",
124 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45125 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02126 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45127 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56128 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45129 ]
Siddhartha764226b2018-03-13 02:32:55130
131 # Adds the unwind tables from unstripped binary as an asset file in the
132 # apk, if |add_unwind_tables_in_apk| is specified by the test.
133 if (defined(invoker.add_unwind_tables_in_apk) &&
134 invoker.add_unwind_tables_in_apk) {
135 _unwind_table_asset_name = "${target_name}_unwind_assets"
136 unwind_table_asset(_unwind_table_asset_name) {
137 testonly = true
138 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22139 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55140 }
141 }
142
agrieve62ab00282016-04-05 02:03:45143 shared_library(_library_target) {
144 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
145 configs = [] # Prevent list overwriting warning.
146 configs = invoker.configs
147 testonly = true
148
149 deps = []
jbudorickd29ecfa72016-11-18 22:45:42150 forward_variables_from(
151 invoker,
152 "*",
153 _apk_specific_vars + _wrapper_script_vars + [ "visibility" ])
agrieve62ab00282016-04-05 02:03:45154
155 if (!defined(invoker.use_default_launcher) ||
156 invoker.use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37157 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45158 }
159 }
160 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54161 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07162 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45163 apk_name = invoker.target_name
164 if (defined(invoker.output_name)) {
165 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45166 install_script_name = "install_${invoker.output_name}"
167 }
agrieveb355ad152016-04-19 03:45:23168
Daniel Bratellfdda4652019-01-31 15:45:54169 if (defined(invoker.deps)) {
170 deps = invoker.deps
171 } else {
172 deps = []
173 }
174
jcivellif4462a352017-01-10 04:45:59175 # Add the Java classes so that each target does not have to do it.
176 deps += [ "//base/test:test_support_java" ]
177
Siddhartha764226b2018-03-13 02:32:55178 if (defined(_unwind_table_asset_name)) {
179 deps += [ ":${_unwind_table_asset_name}" ]
180 }
agrieve62ab00282016-04-05 02:03:45181 }
Andrew Grievee1dc23f2019-10-22 16:26:36182 }
agrieve62ab00282016-04-05 02:03:45183
Andrew Grievee1dc23f2019-10-22 16:26:36184 test_runner_script(_test_runner_target) {
185 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57186
Andrew Grievee1dc23f2019-10-22 16:26:36187 if (_use_raw_android_executable) {
188 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34189 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36190 } else {
191 apk_target = ":$_apk_target"
192 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47193
194 # Dep needed for the test runner .runtime_deps file to pick up data
195 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22196 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45197 }
Andrew Grievee1dc23f2019-10-22 16:26:36198 test_name = _output_name
199 test_suite = _output_name
200 test_type = "gtest"
mikecase56d80d72015-06-03 00:57:26201 }
202
Andrew Grieve7ca6de32019-10-18 03:57:47203 # Create a wrapper script rather than using a group() in order to ensure
204 # "ninja $target_name" always works. If this was a group(), then GN would
205 # not create a top-level alias for it if a target exists in another
206 # directory with the same $target_name.
207 # Also - bots run this script directly for "components_perftests".
208 generate_wrapper(target_name) {
209 testonly = true
210 executable = "$root_build_dir/bin/run_$_output_name"
211 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22212 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40213 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47214 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40215 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47216 # Dep needed for the swarming .isolate file to pick up data
217 # deps from the forward_variables_from(invoker, "*") on the library.
218 deps += [
219 ":$_apk_target",
220 ":$_library_target",
221 ]
agrieve62ab00282016-04-05 02:03:45222 }
agrieve1a02e582015-10-15 21:35:39223 }
Scott Graham4c4cdc52017-05-29 20:45:03224 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30225 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
226
Scott Graham4c4cdc52017-05-29 20:45:03227 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42228 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42229 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03230
Kevin Marshall39b4aa82018-06-23 00:12:15231 fuchsia_package_runner(target_name) {
Kevin Marshallf35fa5f2018-01-29 19:24:42232 testonly = true
Dirk Pranked5e9a1b22020-10-28 22:52:59233 is_test_exe = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53234 forward_variables_from(invoker,
235 [
236 "use_test_server",
237 "package_deps",
238 ])
Kevin Marshall39b4aa82018-06-23 00:12:15239 runner_script = "//build/fuchsia/test_runner.py"
240 package = ":$_pkg_target"
241 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42242
Wezdd593a52020-04-08 17:09:46243 data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Kevin Marshallf35fa5f2018-01-29 19:24:42244 }
245
Wezabe2d752020-02-11 17:12:23246 cr_fuchsia_package(_pkg_target) {
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20247 testonly = true
Fabrice de Gans-Ribericc810d32019-07-08 22:44:16248 forward_variables_from(invoker, [ "manifest" ])
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20249 binary = ":$_exec_target"
250 package_name_override = _output_name
251 }
252
Kevin Marshallf35fa5f2018-01-29 19:24:42253 executable(_exec_target) {
Scott Graham4c4cdc52017-05-29 20:45:03254 forward_variables_from(invoker, "*")
Kevin Marshall39b4aa82018-06-23 00:12:15255 testonly = true
Kevin Marshallf35fa5f2018-01-29 19:24:42256 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03257 }
dpranke2a294622015-08-07 05:23:01258 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30259 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46260 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30261
Rohit Raof9b096d2019-09-09 22:26:23262 declare_args() {
263 # Keep the unittest-as-xctest functionality defaulted to off until the
264 # bots are updated to handle it properly.
265 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
266 # supports running unittests with xctest.
267 enable_run_ios_unittests_with_xctest = false
268 }
269
sdefresne012857872016-03-16 10:55:37270 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36271 _wrapper_output_name = "run_${target_name}"
272 ios_test_runner_wrapper(_wrapper_output_name) {
273 forward_variables_from(invoker,
274 [
275 "data",
276 "data_deps",
277 "deps",
278 "executable_args",
279 "retries",
280 "shards",
281 ])
282
283 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
284
285 if (!defined(executable_args)) {
286 executable_args = []
287 }
288 executable_args += [
289 "--app",
290 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
291 ]
292
293 wrapper_output_name = "${_wrapper_output_name}"
294 }
295
sdefresne012857872016-03-16 10:55:37296 _resources_bundle_data = target_name + "_resources_bundle_data"
297
298 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34299 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22300 sources = [ "//testing/gtest_ios/Default.png" ]
301 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01302 }
303
Mirko Bonadei15522bc2020-09-16 20:38:39304 force_xctest = enable_run_ios_unittests_with_xctest ||
305 (defined(invoker.is_xctest) && invoker.is_xctest)
306
307 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23308 ios_test_target_type = "ios_xctest_test"
309 } else {
310 ios_test_target_type = "ios_app_bundle"
311 }
312
313 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01314 testonly = true
sdefresnea828c282016-05-30 18:04:20315
Mirko Bonadei15522bc2020-09-16 20:38:39316 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23317 xctest_module_target = "//base/test:google_test_runner"
318 }
319
sdefresne9e147e02016-06-07 00:10:13320 forward_variables_from(invoker, "*", [ "testonly" ])
321
322 # Provide sensible defaults in case invoker did not define any of those
323 # required variables.
sdefresne05b97ca2016-06-08 07:19:46324 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13325 info_plist = "//testing/gtest_ios/unittest-Info.plist"
326 }
sdefresne9e147e02016-06-07 00:10:13327
Olivier Robin9689c562020-04-17 14:03:57328 _gtest_bundle_id_suffix = "${target_name}"
329 xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19330
sdefresne9e147e02016-06-07 00:10:13331 if (!defined(extra_substitutions)) {
332 extra_substitutions = []
333 }
Olivier Robin9689c562020-04-17 14:03:57334 extra_substitutions +=
335 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01336
sdefresne047490e2016-07-22 08:49:34337 if (!defined(bundle_deps)) {
338 bundle_deps = []
339 }
340 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36341
342 if (!defined(data_deps)) {
343 data_deps = []
344 }
345
346 # Include the generate_wrapper as part of data_deps
347 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46348 write_runtime_deps = _runtime_deps_file
dpranke2a294622015-08-07 05:23:01349 }
George Burgess IVe62d7c52020-02-22 01:22:42350 } else if (is_chromeos && cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30351 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
352
Ben Pastene16882032018-09-21 01:16:39353 # Building for a cros board (ie: not linux-chromeos).
Benjamin Pastene3bce864e2018-04-14 01:16:32354
Benjamin Pastene3bce864e2018-04-14 01:16:32355 _gen_runner_target = "${target_name}__runner"
356 _runtime_deps_file =
357 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
358 "/" + get_label_info(target_name, "name") + ".runtime_deps"
359
Ben Pastene4ab98652018-12-17 18:33:18360 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32361 testonly = true
362 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39363 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32364 runtime_deps_file = _runtime_deps_file
365 }
366
367 executable(target_name) {
368 forward_variables_from(invoker, "*")
369 if (!defined(deps)) {
370 deps = []
371 }
372 if (!defined(data)) {
373 data = []
374 }
375
Ben Pastene41041782019-02-16 04:21:58376 # We use a special trigger script for CrOS hardware tests.
377 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
378
Benjamin Pastene3bce864e2018-04-14 01:16:32379 testonly = true
380 output_name = target_name
381 write_runtime_deps = _runtime_deps_file
382 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37383 deps += [ ":$_gen_runner_target" ]
Benjamin Pastene3bce864e2018-04-14 01:16:32384 }
Dirk Pranke31e346e2020-07-15 00:54:06385 } else if (is_chromeos && cros_board == "") {
Dirk Pranke79d065d2020-08-29 03:28:30386 # TODO(crbug.com/816629) - Make use_xvfb work right in this situation.
387 not_needed([ "use_xvfb" ])
Dirk Pranke956c4dc2020-07-02 00:54:27388 executable(target_name) {
Dirk Pranke79d065d2020-08-29 03:28:30389 forward_variables_from(invoker, "*", [ "use_xvfb" ])
Dirk Pranke956c4dc2020-07-02 00:54:27390 if (!defined(deps)) {
391 deps = []
392 }
393
Dirk Pranke956c4dc2020-07-02 00:54:27394 testonly = true
Dirk Pranke956c4dc2020-07-02 00:54:27395 }
Yuke Liaoe703384b2020-07-16 01:05:24396 } else if (chromeos_is_browser_only) {
397 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
398 _executable = target_name
399 _gen_runner_target = "${target_name}__runner"
400
Yuke Liao32af4242020-07-16 21:48:02401 if (defined(invoker.use_xvfb)) {
402 _use_xvfb = invoker.use_xvfb
403 } else {
404 _use_xvfb = false
405 }
406
Yuke Liaod037abc2020-10-06 22:48:22407 # When use_xvfb is set by the invoker, it indicates that running this test
408 # target requires a window, and in lacros build, ash-chrome serves as the
409 # display server. Note that even though the tests themselves do not require
410 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
411 # because ash-chrome is based on x11.
412 _use_ash_chrome = _use_xvfb
413
Yuke Liaoe703384b2020-07-16 01:05:24414 generate_wrapper(_gen_runner_target) {
415 testonly = true
416 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02417
Yuke Liao2e4953cf2020-07-26 19:20:19418 data = []
Yuke Liao32af4242020-07-16 21:48:02419 if (_use_xvfb) {
420 executable = "//testing/xvfb.py"
Yuke Liao2e4953cf2020-07-26 19:20:19421 data += [ "//testing/xvfb.py" ]
Yuke Liao32af4242020-07-16 21:48:02422 } else {
423 executable = "//testing/test_env.py"
Yuke Liao2e4953cf2020-07-26 19:20:19424 data += [ "//testing/test_env.py" ]
Yuke Liao32af4242020-07-16 21:48:02425 }
426
Yuke Liaoe703384b2020-07-16 01:05:24427 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02428 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39429 "test",
Yuke Liaoe703384b2020-07-16 01:05:24430 "@WrappedPath(./${_executable})",
431 "--test-launcher-bot-mode",
432 ]
Yuke Liao32af4242020-07-16 21:48:02433
Yuke Liaof540c742020-07-29 16:28:34434 if (_use_ash_chrome) {
Yuke Liao8348aa42020-11-04 19:35:23435 executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ]
Yuke Liao240816d2020-07-22 00:10:39436 }
437
Yuke Liaoe703384b2020-07-16 01:05:24438 if (is_asan) {
439 executable_args += [ "--asan=true" ]
440 }
441 if (is_msan) {
442 executable_args += [ "--msan=true" ]
443 }
444 if (is_tsan) {
445 executable_args += [ "--tsan=true" ]
446 }
447 if (use_cfi_diag) {
448 executable_args += [ "--cfi-diag=true" ]
449 }
450
Yuke Liao2e4953cf2020-07-26 19:20:19451 data += [
Yuke Liao240816d2020-07-22 00:10:39452 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24453 "//.vpython",
454 ]
455 }
456
457 executable(target_name) {
458 forward_variables_from(invoker, "*")
459 if (!defined(deps)) {
460 deps = []
461 }
462
Yuke Liaod037abc2020-10-06 22:48:22463 if (!defined(data_deps)) {
464 data_deps = []
465 }
466
Yuke Liaoe703384b2020-07-16 01:05:24467 testonly = true
468 write_runtime_deps = _runtime_deps_file
469 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22470 if (_use_ash_chrome && also_build_ash_chrome) {
471 data_deps +=
472 [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ]
473 }
Yuke Liaoe703384b2020-07-16 01:05:24474 }
Dirk Pranke31e346e2020-07-15 00:54:06475 } else {
Dirk Pranke79d065d2020-08-29 03:28:30476 if (is_mac || is_win) {
477 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
478 }
479
Dirk Pranke31e346e2020-07-15 00:54:06480 if ((is_linux && !is_chromeos) || is_mac || is_win) {
481 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
482 _executable = target_name
483 _gen_runner_target = "${target_name}__runner"
484
Sean McAllister88fbd902020-07-30 19:27:03485 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
Dirk Pranke31e346e2020-07-15 00:54:06486 _use_xvfb = invoker.use_xvfb
487 } else {
488 _use_xvfb = false
489 }
490
491 generate_wrapper(_gen_runner_target) {
492 testonly = true
493 wrapper_script = "$root_build_dir/bin/run_" + _executable
494
Yuke Liao2e4953cf2020-07-26 19:20:19495 data = []
Dirk Pranke31e346e2020-07-15 00:54:06496 if (_use_xvfb) {
497 executable = "//testing/xvfb.py"
Yuke Liao2e4953cf2020-07-26 19:20:19498 data += [ "//testing/xvfb.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06499 } else {
500 executable = "//testing/test_env.py"
Yuke Liao2e4953cf2020-07-26 19:20:19501 data += [ "//testing/test_env.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06502 }
503
504 executable_args = [
505 "@WrappedPath(./${_executable})",
506 "--test-launcher-bot-mode",
507 ]
508 if (is_asan) {
509 executable_args += [ "--asan=true" ]
510 }
511 if (is_msan) {
512 executable_args += [ "--msan=true" ]
513 }
514 if (is_tsan) {
515 executable_args += [ "--tsan=true" ]
516 }
517 if (use_cfi_diag) {
518 executable_args += [ "--cfi-diag=true" ]
519 }
520
Yuke Liao2e4953cf2020-07-26 19:20:19521 data += [ "//.vpython" ]
Dirk Pranke31e346e2020-07-15 00:54:06522 }
523 }
524
525 executable(target_name) {
Dirk Pranke79d065d2020-08-29 03:28:30526 forward_variables_from(invoker, "*", [ "use_xvfb" ])
Dirk Pranke31e346e2020-07-15 00:54:06527 if (!defined(deps)) {
528 deps = []
529 }
530
Dirk Pranke31e346e2020-07-15 00:54:06531 testonly = true
532 deps += [
533 # Give tests the default manifest on Windows (a no-op elsewhere).
534 "//build/win:default_exe_manifest",
535 ]
536
Sean McAllister88fbd902020-07-30 19:27:03537 if (is_linux || is_chromeos || is_mac || is_win) {
Dirk Pranke31e346e2020-07-15 00:54:06538 write_runtime_deps = _runtime_deps_file
539 deps += [ ":$_gen_runner_target" ]
540 }
541 }
qsrfb5251d12015-01-21 15:57:22542 }
543}
brettwedb6ecc2016-07-14 23:37:03544
Dirk Pranke6188075b2020-10-01 19:31:28545# Defines a type of test that invokes a script to run, rather than
546# invoking an executable.
547#
548# The script must implement the
549# [test executable API](//docs/testing/test_executable_api.md).
550#
551# The template must be passed the `script` parameter, which specifies
552# the path to the script to run. It may optionally be passed a
553# `script_args` parameter, which can be used to include a list of
554# args to be specified by default. The template will produce
555# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
556# for the target to $root_build_dir/${target_name}.runtime_deps, as per
557# the conventions listed in the
558# [test wrapper API](//docs/testing/test_wrapper_api.md).
559template("script_test") {
560 generate_wrapper(target_name) {
561 testonly = true
562 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
563
564 executable = "//testing/test_env.py"
565
566 executable_args =
567 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
568 if (defined(invoker.args)) {
569 executable_args += invoker.args
570 }
571
572 data = [
573 "//.vpython",
574 "//testing/test_env.py",
575
576 # These aren't needed by *every* test, but they're likely needed often
577 # enough to just make it easier to declare them here.
578 "//testing/xvfb.py",
579 "//testing/scripts/common.py",
580
581 invoker.script,
582 ]
583 if (defined(invoker.data)) {
584 data += invoker.data
585 }
586 data_deps = []
587 if (defined(invoker.data_deps)) {
588 data_deps += invoker.data_deps
589 }
590
591 forward_variables_from(invoker,
592 [ "*" ],
593 [
594 "data",
595 "data_deps",
596 "script",
597 "script_args",
598 "testonly",
599 ])
600
601 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
602 }
603}
604
brettwedb6ecc2016-07-14 23:37:03605# Test defaults.
606set_defaults("test") {
607 if (is_android) {
608 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41609 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59610 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03611 } else {
612 configs = default_executable_configs
613 }
614}