[go: nahoru, domu]

blob: 2708c5f834eb785b7490c8b01de51b9d34a92681 [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")
Chong Gu26908f42021-01-29 03:13:0719 import("//build/config/coverage/coverage.gni")
Kevin Marshall55fd8522019-10-04 22:47:0120 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4221 import("//build/config/fuchsia/package.gni")
Chong Gu26908f42021-01-29 03:13:0722 import("//third_party/fuchsia-sdk/sdk/build/cmc.gni")
Yuta Hijikatac2975452020-12-16 15:59:3923} else if (is_chromeos_ash) {
Ben Pastene4c35c572018-04-30 23:21:4824 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3225 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2826 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3227} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3628 import("//build/config/ios/ios_sdk.gni")
29 import("//build/config/ios/ios_test_runner_wrapper.gni")
30 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3231} else {
Dirk Pranke31e346e2020-07-15 00:54:0632 import("//build/config/sanitizers/sanitizers.gni")
33 import("//build/util/generate_wrapper.gni")
34}
35
qsrfb5251d12015-01-21 15:57:2236# Define a test as an executable (or apk on Android) with the "testonly" flag
37# set.
agrieve62ab00282016-04-05 02:03:4538# Variable:
Dirk Pranke79d065d2020-08-29 03:28:3039# use_xvfb: (optional) whether to run the executable under Xvfb.
agrieve62ab00282016-04-05 02:03:4540# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:5641# use_native_activity: Test implements ANativeActivity_onCreate().
Mirko Bonadei15522bc2020-09-16 20:38:3942# is_xctest: (iOS, optional) whether to build the executable as XCTest.
43# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
44# for build targets.
qsrfb5251d12015-01-21 15:57:2245template("test") {
Andrew Grieve1b290e4a22020-11-24 20:07:0146 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:3947 if (!is_ios) {
48 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
49 "is_xctest can be set only for iOS builds")
50 }
qsrfb5251d12015-01-21 15:57:2251 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3052 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
53
agrieve62ab00282016-04-05 02:03:4554 _use_raw_android_executable = defined(invoker.use_raw_android_executable) &&
55 invoker.use_raw_android_executable
qsrfb5251d12015-01-21 15:57:2256
agrieve67855de2016-03-30 14:46:0157 # output_name is used to allow targets with the same name but in different
58 # packages to still produce unique runner scripts.
59 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2660 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0161 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2662 }
agrieve62ab00282016-04-05 02:03:4563
agrieveb355ad152016-04-19 03:45:2364 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4265 _wrapper_script_vars = [
agrievee41ae1902016-04-25 14:12:5166 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4267 "shard_timeout",
agrievee41ae1902016-04-25 14:12:5168 ]
agrieve3ac557f02016-04-12 15:52:0069
jbudorickced2a252016-06-09 16:38:5470 assert(_use_raw_android_executable || enable_java_templates)
71
agrieve62ab00282016-04-05 02:03:4572 if (_use_raw_android_executable) {
73 _exec_target = "${target_name}__exec"
74 _dist_target = "${target_name}__dist"
75 _exec_output =
76 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
77
78 executable(_exec_target) {
79 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
80 configs = []
81 data_deps = []
jbudorickd29ecfa72016-11-18 22:45:4282 forward_variables_from(invoker,
83 "*",
Andrew Grieve1b290e4a22020-11-24 20:07:0184 TESTONLY_AND_VISIBILITY + _wrapper_script_vars +
85 [ "extra_dist_files" ])
agrieve62ab00282016-04-05 02:03:4586
87 # Thanks to the set_defaults() for test(), configs are initialized with
88 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:5989 configs -= [
90 "//build/config:shared_library_config",
91 "//build/config/android:hide_all_but_jni",
92 ]
agrieve62ab00282016-04-05 02:03:4593 configs += [ "//build/config:executable_config" ]
94
95 # Don't output to the root or else conflict with the group() below.
96 output_name = rebase_path(_exec_output, root_out_dir)
agrieve62ab00282016-04-05 02:03:4597 }
98
99 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45100 dist_dir = "$root_out_dir/$target_name"
101 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22102 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45103 if (defined(invoker.extra_dist_files)) {
104 extra_files = invoker.extra_dist_files
105 }
106 }
107 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02108 _library_target = "${target_name}__library"
109 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45110 _apk_specific_vars = [
111 "android_manifest",
agrievec6811b422016-06-23 02:25:09112 "android_manifest_dep",
Clark DuVall1bee5322020-06-10 05:51:55113 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45114 "enable_multidex",
Benoît Lizéd8b8f742019-11-07 12:50:07115 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02116 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07117 "proguard_configs",
118 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45119 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02120 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45121 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56122 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45123 ]
Siddhartha764226b2018-03-13 02:32:55124
125 # Adds the unwind tables from unstripped binary as an asset file in the
126 # apk, if |add_unwind_tables_in_apk| is specified by the test.
127 if (defined(invoker.add_unwind_tables_in_apk) &&
128 invoker.add_unwind_tables_in_apk) {
129 _unwind_table_asset_name = "${target_name}_unwind_assets"
130 unwind_table_asset(_unwind_table_asset_name) {
Siddhartha764226b2018-03-13 02:32:55131 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22132 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55133 }
134 }
135
agrieve62ab00282016-04-05 02:03:45136 shared_library(_library_target) {
137 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
138 configs = [] # Prevent list overwriting warning.
139 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45140
jbudorickd29ecfa72016-11-18 22:45:42141 forward_variables_from(
142 invoker,
143 "*",
Peter Wen2052bd12020-12-03 20:15:07144 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
145 TESTONLY_AND_VISIBILITY)
146
147 # Native targets do not need to depend on java targets. Filter them out
148 # so that the shared library can be built without needing to wait for
149 # dependent java targets.
150 deps = []
151 if (defined(invoker.deps)) {
152 foreach(_dep, invoker.deps) {
153 _target_label = get_label_info(_dep, "label_no_toolchain")
154 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
155 deps += [ _dep ]
156 }
157 }
158 }
agrieve62ab00282016-04-05 02:03:45159
160 if (!defined(invoker.use_default_launcher) ||
161 invoker.use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37162 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45163 }
164 }
165 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54166 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07167 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45168 apk_name = invoker.target_name
169 if (defined(invoker.output_name)) {
170 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45171 install_script_name = "install_${invoker.output_name}"
172 }
agrieveb355ad152016-04-19 03:45:23173
Daniel Bratellfdda4652019-01-31 15:45:54174 if (defined(invoker.deps)) {
175 deps = invoker.deps
176 } else {
177 deps = []
178 }
179
jcivellif4462a352017-01-10 04:45:59180 # Add the Java classes so that each target does not have to do it.
181 deps += [ "//base/test:test_support_java" ]
182
Siddhartha764226b2018-03-13 02:32:55183 if (defined(_unwind_table_asset_name)) {
184 deps += [ ":${_unwind_table_asset_name}" ]
185 }
agrieve62ab00282016-04-05 02:03:45186 }
Andrew Grievee1dc23f2019-10-22 16:26:36187 }
agrieve62ab00282016-04-05 02:03:45188
Andrew Grievee1dc23f2019-10-22 16:26:36189 test_runner_script(_test_runner_target) {
190 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce844392016-12-15 19:57:57191
Andrew Grievee1dc23f2019-10-22 16:26:36192 if (_use_raw_android_executable) {
193 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34194 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36195 } else {
196 apk_target = ":$_apk_target"
197 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47198
199 # Dep needed for the test runner .runtime_deps file to pick up data
200 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22201 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45202 }
Andrew Grievee1dc23f2019-10-22 16:26:36203 test_name = _output_name
204 test_suite = _output_name
205 test_type = "gtest"
mikecase56d80d72015-06-03 00:57:26206 }
207
Andrew Grieve7ca6de32019-10-18 03:57:47208 # Create a wrapper script rather than using a group() in order to ensure
209 # "ninja $target_name" always works. If this was a group(), then GN would
210 # not create a top-level alias for it if a target exists in another
211 # directory with the same $target_name.
212 # Also - bots run this script directly for "components_perftests".
213 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01214 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47215 executable = "$root_build_dir/bin/run_$_output_name"
216 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22217 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40218 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47219 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40220 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47221 # Dep needed for the swarming .isolate file to pick up data
222 # deps from the forward_variables_from(invoker, "*") on the library.
223 deps += [
224 ":$_apk_target",
225 ":$_library_target",
226 ]
agrieve62ab00282016-04-05 02:03:45227 }
agrieve1a02e582015-10-15 21:35:39228 }
Scott Graham4c4cdc52017-05-29 20:45:03229 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30230 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
231
Scott Graham4c4cdc52017-05-29 20:45:03232 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42233 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42234 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03235
Chong Guacf19a32021-03-10 01:07:41236 # TODO(1019938): make minimum_capabilities.test-cmx the default and have
237 # everything added via additional_manifests
Chong Gu26908f42021-01-29 03:13:07238 if (!defined(invoker.manifest)) {
Chong Guacf19a32021-03-10 01:07:41239 if (!defined(invoker.additional_manifests)) {
240 manifest = "//build/config/fuchsia/tests-with-exec.cmx"
241 } else {
242 manifest = "//build/config/fuchsia/test/minimum_capabilities.test-cmx"
243 }
Chong Gu26908f42021-01-29 03:13:07244 } else {
245 manifest = invoker.manifest
246 }
247
Chong Guacf19a32021-03-10 01:07:41248 if (defined(invoker.additional_manifests)) {
249 combined_manifest = "${target_name}.test-cmx"
250 cmc_merge(combined_manifest) {
251 sources = [ manifest ]
252 sources += invoker.additional_manifests
253 output_name = target_name
254 }
255 manifest = "${target_out_dir}/${combined_manifest}"
256 }
257
Chong Gu26908f42021-01-29 03:13:07258 if (use_clang_coverage) {
259 component_with_coverage_manifest = "${target_name}-coverage.test-cmx"
260 cmc_merge(component_with_coverage_manifest) {
261 sources = [
262 "//build/config/fuchsia/add_DebugData_service.test-cmx",
263 manifest,
264 ]
265 output_name = target_name
266 }
267 manifest = "${target_out_dir}/${component_with_coverage_manifest}"
268 }
269
Kevin Marshall39b4aa82018-06-23 00:12:15270 fuchsia_package_runner(target_name) {
Dirk Pranked5e9a1b22020-10-28 22:52:59271 is_test_exe = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53272 forward_variables_from(invoker,
273 [
274 "use_test_server",
275 "package_deps",
Andrew Grieve1b290e4a22020-11-24 20:07:01276 "visibility",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53277 ])
Kevin Marshall39b4aa82018-06-23 00:12:15278 runner_script = "//build/fuchsia/test_runner.py"
279 package = ":$_pkg_target"
280 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42281
Wezdd593a52020-04-08 17:09:46282 data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Kevin Marshallf35fa5f2018-01-29 19:24:42283 }
284
Wezabe2d752020-02-11 17:12:23285 cr_fuchsia_package(_pkg_target) {
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20286 binary = ":$_exec_target"
287 package_name_override = _output_name
Chong Guacf19a32021-03-10 01:07:41288 deps = []
Chong Gu26908f42021-01-29 03:13:07289 if (use_clang_coverage) {
Chong Guacf19a32021-03-10 01:07:41290 deps += [ ":$component_with_coverage_manifest" ]
291 }
292 if (defined(invoker.additional_manifests)) {
293 deps += [ ":$combined_manifest" ]
Chong Gu26908f42021-01-29 03:13:07294 }
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20295 }
296
Kevin Marshallf35fa5f2018-01-29 19:24:42297 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01298 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42299 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03300 }
dpranke2a294622015-08-07 05:23:01301 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30302 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46303 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30304
Rohit Raof9b096d2019-09-09 22:26:23305 declare_args() {
306 # Keep the unittest-as-xctest functionality defaulted to off until the
307 # bots are updated to handle it properly.
308 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
309 # supports running unittests with xctest.
310 enable_run_ios_unittests_with_xctest = false
311 }
312
sdefresne012857872016-03-16 10:55:37313 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36314 _wrapper_output_name = "run_${target_name}"
315 ios_test_runner_wrapper(_wrapper_output_name) {
316 forward_variables_from(invoker,
317 [
318 "data",
319 "data_deps",
320 "deps",
321 "executable_args",
322 "retries",
323 "shards",
324 ])
325
326 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
327
328 if (!defined(executable_args)) {
329 executable_args = []
330 }
331 executable_args += [
332 "--app",
333 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
334 ]
335
336 wrapper_output_name = "${_wrapper_output_name}"
337 }
338
sdefresne012857872016-03-16 10:55:37339 _resources_bundle_data = target_name + "_resources_bundle_data"
340
341 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34342 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22343 sources = [ "//testing/gtest_ios/Default.png" ]
344 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01345 }
346
Mirko Bonadei15522bc2020-09-16 20:38:39347 force_xctest = enable_run_ios_unittests_with_xctest ||
348 (defined(invoker.is_xctest) && invoker.is_xctest)
349
350 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23351 ios_test_target_type = "ios_xctest_test"
352 } else {
353 ios_test_target_type = "ios_app_bundle"
354 }
355
356 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01357 testonly = true
sdefresnea828c282016-05-30 18:04:20358
Mirko Bonadei15522bc2020-09-16 20:38:39359 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23360 xctest_module_target = "//base/test:google_test_runner"
361 }
362
Andrew Grieve1b290e4a22020-11-24 20:07:01363 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13364
365 # Provide sensible defaults in case invoker did not define any of those
366 # required variables.
sdefresne05b97ca2016-06-08 07:19:46367 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13368 info_plist = "//testing/gtest_ios/unittest-Info.plist"
369 }
sdefresne9e147e02016-06-07 00:10:13370
Olivier Robin9689c562020-04-17 14:03:57371 _gtest_bundle_id_suffix = "${target_name}"
372 xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19373
sdefresne9e147e02016-06-07 00:10:13374 if (!defined(extra_substitutions)) {
375 extra_substitutions = []
376 }
Olivier Robin9689c562020-04-17 14:03:57377 extra_substitutions +=
378 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01379
sdefresne047490e2016-07-22 08:49:34380 if (!defined(bundle_deps)) {
381 bundle_deps = []
382 }
383 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36384
385 if (!defined(data_deps)) {
386 data_deps = []
387 }
388
389 # Include the generate_wrapper as part of data_deps
390 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46391 write_runtime_deps = _runtime_deps_file
dpranke2a294622015-08-07 05:23:01392 }
Yuta Hijikatac2975452020-12-16 15:59:39393 } else if (is_chromeos_ash && cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30394 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
395
Ben Pastene16882032018-09-21 01:16:39396 # Building for a cros board (ie: not linux-chromeos).
Benjamin Pastene3bce864e2018-04-14 01:16:32397
Benjamin Pastene3bce864e2018-04-14 01:16:32398 _gen_runner_target = "${target_name}__runner"
399 _runtime_deps_file =
400 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
401 "/" + get_label_info(target_name, "name") + ".runtime_deps"
402
Ben Pastene4ab98652018-12-17 18:33:18403 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32404 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39405 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32406 runtime_deps_file = _runtime_deps_file
407 }
408
409 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01410 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
411 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32412 if (!defined(deps)) {
413 deps = []
414 }
415 if (!defined(data)) {
416 data = []
417 }
418
Ben Pastene41041782019-02-16 04:21:58419 # We use a special trigger script for CrOS hardware tests.
420 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
421
Benjamin Pastene3bce864e2018-04-14 01:16:32422 output_name = target_name
423 write_runtime_deps = _runtime_deps_file
424 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37425 deps += [ ":$_gen_runner_target" ]
Benjamin Pastene3bce864e2018-04-14 01:16:32426 }
Yuke Liaoe703384b2020-07-16 01:05:24427 } else if (chromeos_is_browser_only) {
428 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
429 _executable = target_name
430 _gen_runner_target = "${target_name}__runner"
431
Yuke Liao32af4242020-07-16 21:48:02432 if (defined(invoker.use_xvfb)) {
433 _use_xvfb = invoker.use_xvfb
434 } else {
435 _use_xvfb = false
436 }
437
Yuke Liaod037abc2020-10-06 22:48:22438 # When use_xvfb is set by the invoker, it indicates that running this test
439 # target requires a window, and in lacros build, ash-chrome serves as the
440 # display server. Note that even though the tests themselves do not require
441 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
442 # because ash-chrome is based on x11.
443 _use_ash_chrome = _use_xvfb
444
Yuke Liaoe703384b2020-07-16 01:05:24445 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24446 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02447
Yuke Liao2e4953cf2020-07-26 19:20:19448 data = []
Yuke Liao32af4242020-07-16 21:48:02449 if (_use_xvfb) {
450 executable = "//testing/xvfb.py"
Yuke Liao2e4953cf2020-07-26 19:20:19451 data += [ "//testing/xvfb.py" ]
Yuke Liao32af4242020-07-16 21:48:02452 } else {
453 executable = "//testing/test_env.py"
Yuke Liao2e4953cf2020-07-26 19:20:19454 data += [ "//testing/test_env.py" ]
Yuke Liao32af4242020-07-16 21:48:02455 }
456
Yuke Liaoe703384b2020-07-16 01:05:24457 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02458 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39459 "test",
Yuke Liaoe703384b2020-07-16 01:05:24460 "@WrappedPath(./${_executable})",
461 "--test-launcher-bot-mode",
462 ]
Yuke Liao32af4242020-07-16 21:48:02463
Yuke Liaof540c742020-07-29 16:28:34464 if (_use_ash_chrome) {
Yuke Liao8348aa42020-11-04 19:35:23465 executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ]
Yuke Liao240816d2020-07-22 00:10:39466 }
467
Yuke Liaoe703384b2020-07-16 01:05:24468 if (is_asan) {
469 executable_args += [ "--asan=true" ]
470 }
471 if (is_msan) {
472 executable_args += [ "--msan=true" ]
473 }
474 if (is_tsan) {
475 executable_args += [ "--tsan=true" ]
476 }
477 if (use_cfi_diag) {
478 executable_args += [ "--cfi-diag=true" ]
479 }
480
Yuke Liao2e4953cf2020-07-26 19:20:19481 data += [
Yuke Liao240816d2020-07-22 00:10:39482 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24483 "//.vpython",
484 ]
485 }
486
487 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01488 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
489 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24490 if (!defined(deps)) {
491 deps = []
492 }
493
Yuke Liaod037abc2020-10-06 22:48:22494 if (!defined(data_deps)) {
495 data_deps = []
496 }
497
Yuke Liaoe703384b2020-07-16 01:05:24498 write_runtime_deps = _runtime_deps_file
499 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22500 if (_use_ash_chrome && also_build_ash_chrome) {
501 data_deps +=
502 [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ]
503 }
Yuke Liaoe703384b2020-07-16 01:05:24504 }
Dirk Prankedd4ff742020-11-18 19:57:32505 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30506 if (is_mac || is_win) {
507 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
508 }
509
Dirk Prankedd4ff742020-11-18 19:57:32510 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
511 _executable = target_name
512 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06513
Dirk Prankedd4ff742020-11-18 19:57:32514 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
515 _use_xvfb = invoker.use_xvfb
516 } else {
517 _use_xvfb = false
518 }
519
520 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32521 wrapper_script = "$root_build_dir/bin/run_" + _executable
522
523 data = []
524 if (_use_xvfb) {
525 executable = "//testing/xvfb.py"
526 data += [ "//testing/xvfb.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06527 } else {
Dirk Prankedd4ff742020-11-18 19:57:32528 executable = "//testing/test_env.py"
529 data += [ "//testing/test_env.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06530 }
531
Dirk Prankedd4ff742020-11-18 19:57:32532 executable_args = [
533 "@WrappedPath(./${_executable})",
534 "--test-launcher-bot-mode",
535 ]
536 if (is_asan) {
537 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06538 }
Dirk Prankedd4ff742020-11-18 19:57:32539 if (is_msan) {
540 executable_args += [ "--msan=true" ]
541 }
542 if (is_tsan) {
543 executable_args += [ "--tsan=true" ]
544 }
545 if (use_cfi_diag) {
546 executable_args += [ "--cfi-diag=true" ]
547 }
548
549 data += [ "//.vpython" ]
Dirk Pranke31e346e2020-07-15 00:54:06550 }
551
552 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01553 forward_variables_from(invoker,
554 "*",
555 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
556 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06557 if (!defined(deps)) {
558 deps = []
559 }
560
Dirk Pranke31e346e2020-07-15 00:54:06561 deps += [
562 # Give tests the default manifest on Windows (a no-op elsewhere).
563 "//build/win:default_exe_manifest",
564 ]
565
Dirk Prankedd4ff742020-11-18 19:57:32566 write_runtime_deps = _runtime_deps_file
567 deps += [ ":$_gen_runner_target" ]
568 }
569 } else {
570 # This is a catch-all clause for NaCl toolchains and other random
571 # configurations that might define tests; test() in these configs
572 # will just define the underlying executables.
573 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
574 "use_xvfb should not be defined for a non-linux configuration")
575 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01576 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
577 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32578 if (!defined(deps)) {
579 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06580 }
581 }
qsrfb5251d12015-01-21 15:57:22582 }
583}
brettwedb6ecc2016-07-14 23:37:03584
Dirk Pranke6188075b2020-10-01 19:31:28585# Defines a type of test that invokes a script to run, rather than
586# invoking an executable.
587#
588# The script must implement the
589# [test executable API](//docs/testing/test_executable_api.md).
590#
591# The template must be passed the `script` parameter, which specifies
592# the path to the script to run. It may optionally be passed a
593# `script_args` parameter, which can be used to include a list of
594# args to be specified by default. The template will produce
595# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
596# for the target to $root_build_dir/${target_name}.runtime_deps, as per
597# the conventions listed in the
598# [test wrapper API](//docs/testing/test_wrapper_api.md).
599template("script_test") {
600 generate_wrapper(target_name) {
601 testonly = true
602 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
603
604 executable = "//testing/test_env.py"
605
606 executable_args =
607 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
608 if (defined(invoker.args)) {
609 executable_args += invoker.args
610 }
611
612 data = [
Dirk Pranke6188075b2020-10-01 19:31:28613 "//testing/test_env.py",
614
615 # These aren't needed by *every* test, but they're likely needed often
616 # enough to just make it easier to declare them here.
617 "//testing/xvfb.py",
618 "//testing/scripts/common.py",
619
620 invoker.script,
621 ]
Dirk Pranke2dd666cd2021-03-03 16:57:47622
623 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
624 use_vpython3 = false
625 data += [ "//.vpython" ]
626 } else {
627 use_vpython3 = true
628 data += [ "//.vpython3" ]
629 }
630
Dirk Pranke6188075b2020-10-01 19:31:28631 if (defined(invoker.data)) {
632 data += invoker.data
633 }
634 data_deps = []
635 if (defined(invoker.data_deps)) {
636 data_deps += invoker.data_deps
637 }
638
639 forward_variables_from(invoker,
640 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01641 TESTONLY_AND_VISIBILITY + [
642 "data",
643 "data_deps",
644 "script",
645 "script_args",
646 ])
647 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28648
649 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
650 }
651}
652
brettwedb6ecc2016-07-14 23:37:03653# Test defaults.
654set_defaults("test") {
655 if (is_android) {
656 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41657 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59658 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03659 } else {
660 configs = default_executable_configs
661 }
662}