blob: e3d8870966d1065893e101624783df8167c52081 [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 Gu26908f4e2021-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 Gu26908f4e2021-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 = [
agrievee41ae190d2016-04-25 14:12:5166 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4267 "shard_timeout",
agrievee41ae190d2016-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 = []
Dirk Pranke19a58732021-03-24 22:26:2281 forward_variables_from(
82 invoker,
83 "*",
84 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
85 "data_deps",
86 "extra_dist_files",
87 ])
agrieve62ab00282016-04-05 02:03:4588
89 # Thanks to the set_defaults() for test(), configs are initialized with
90 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:5991 configs -= [
92 "//build/config:shared_library_config",
93 "//build/config/android:hide_all_but_jni",
94 ]
agrieve62ab00282016-04-05 02:03:4595 configs += [ "//build/config:executable_config" ]
96
Dirk Pranke19a58732021-03-24 22:26:2297 if (defined(invoker.data_deps)) {
98 data_deps = invoker.data_deps
99 } else {
100 data_deps = []
101 }
102 if (!defined(data)) {
103 data = []
104 }
105 data += [ "//testing/location_tags.json" ]
106
agrieve62ab00282016-04-05 02:03:45107 # Don't output to the root or else conflict with the group() below.
108 output_name = rebase_path(_exec_output, root_out_dir)
agrieve62ab00282016-04-05 02:03:45109 }
110
111 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45112 dist_dir = "$root_out_dir/$target_name"
113 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22114 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45115 if (defined(invoker.extra_dist_files)) {
116 extra_files = invoker.extra_dist_files
117 }
118 }
119 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02120 _library_target = "${target_name}__library"
121 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45122 _apk_specific_vars = [
123 "android_manifest",
agrievec6811b422016-06-23 02:25:09124 "android_manifest_dep",
Clark DuVall1bee5322020-06-10 05:51:55125 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45126 "enable_multidex",
Benoît Lizéd8b8f742019-11-07 12:50:07127 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02128 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07129 "proguard_configs",
130 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45131 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02132 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45133 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56134 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45135 ]
Siddhartha764226b2018-03-13 02:32:55136
137 # Adds the unwind tables from unstripped binary as an asset file in the
138 # apk, if |add_unwind_tables_in_apk| is specified by the test.
139 if (defined(invoker.add_unwind_tables_in_apk) &&
140 invoker.add_unwind_tables_in_apk) {
141 _unwind_table_asset_name = "${target_name}_unwind_assets"
142 unwind_table_asset(_unwind_table_asset_name) {
Siddhartha764226b2018-03-13 02:32:55143 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22144 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55145 }
146 }
147
agrieve62ab00282016-04-05 02:03:45148 shared_library(_library_target) {
149 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
150 configs = [] # Prevent list overwriting warning.
151 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45152
jbudorickd29ecfa72016-11-18 22:45:42153 forward_variables_from(
154 invoker,
155 "*",
Peter Wen2052bd12020-12-03 20:15:07156 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
157 TESTONLY_AND_VISIBILITY)
158
159 # Native targets do not need to depend on java targets. Filter them out
160 # so that the shared library can be built without needing to wait for
161 # dependent java targets.
162 deps = []
163 if (defined(invoker.deps)) {
164 foreach(_dep, invoker.deps) {
165 _target_label = get_label_info(_dep, "label_no_toolchain")
166 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
167 deps += [ _dep ]
168 }
169 }
170 }
agrieve62ab00282016-04-05 02:03:45171
172 if (!defined(invoker.use_default_launcher) ||
173 invoker.use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37174 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45175 }
176 }
177 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54178 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07179 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45180 apk_name = invoker.target_name
181 if (defined(invoker.output_name)) {
182 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45183 install_script_name = "install_${invoker.output_name}"
184 }
agrieveb355ad152016-04-19 03:45:23185
Daniel Bratellfdda4652019-01-31 15:45:54186 if (defined(invoker.deps)) {
187 deps = invoker.deps
188 } else {
189 deps = []
190 }
191
jcivellif4462a352017-01-10 04:45:59192 # Add the Java classes so that each target does not have to do it.
193 deps += [ "//base/test:test_support_java" ]
194
Siddhartha764226b2018-03-13 02:32:55195 if (defined(_unwind_table_asset_name)) {
196 deps += [ ":${_unwind_table_asset_name}" ]
197 }
agrieve62ab00282016-04-05 02:03:45198 }
Andrew Grievee1dc23f2019-10-22 16:26:36199 }
agrieve62ab00282016-04-05 02:03:45200
Andrew Grievee1dc23f2019-10-22 16:26:36201 test_runner_script(_test_runner_target) {
202 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57203
Andrew Grievee1dc23f2019-10-22 16:26:36204 if (_use_raw_android_executable) {
205 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34206 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36207 } else {
208 apk_target = ":$_apk_target"
209 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47210
211 # Dep needed for the test runner .runtime_deps file to pick up data
212 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22213 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45214 }
Andrew Grievee1dc23f2019-10-22 16:26:36215 test_name = _output_name
216 test_suite = _output_name
217 test_type = "gtest"
mikecase56d80d72015-06-03 00:57:26218 }
219
Andrew Grieve7ca6de32019-10-18 03:57:47220 # Create a wrapper script rather than using a group() in order to ensure
221 # "ninja $target_name" always works. If this was a group(), then GN would
222 # not create a top-level alias for it if a target exists in another
223 # directory with the same $target_name.
224 # Also - bots run this script directly for "components_perftests".
225 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01226 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47227 executable = "$root_build_dir/bin/run_$_output_name"
228 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22229 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40230 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47231 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40232 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47233 # Dep needed for the swarming .isolate file to pick up data
234 # deps from the forward_variables_from(invoker, "*") on the library.
235 deps += [
236 ":$_apk_target",
237 ":$_library_target",
238 ]
agrieve62ab00282016-04-05 02:03:45239 }
Dirk Pranke19a58732021-03-24 22:26:22240
241 if (defined(invoker.data_deps)) {
242 data_deps = invoker.data_deps
243 } else {
244 data_deps = []
245 }
246 data = [ "//testing/location_tags.json" ]
agrieve1a02e582015-10-15 21:35:39247 }
Scott Graham4c4cdc52017-05-29 20:45:03248 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30249 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
250
Scott Graham4c4cdc52017-05-29 20:45:03251 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42252 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42253 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03254
Chong Guacf19a32021-03-10 01:07:41255 # TODO(1019938): make minimum_capabilities.test-cmx the default and have
256 # everything added via additional_manifests
Chong Gu26908f4e2021-01-29 03:13:07257 if (!defined(invoker.manifest)) {
Chong Guacf19a32021-03-10 01:07:41258 if (!defined(invoker.additional_manifests)) {
Chong Gu7ad57c22021-03-11 00:24:38259 manifest_fragments = [ "//build/config/fuchsia/tests-with-exec.cmx" ]
Chong Guacf19a32021-03-10 01:07:41260 } else {
Chong Gu7ad57c22021-03-11 00:24:38261 manifest_fragments =
262 [ "//build/config/fuchsia/test/minimum_capabilities.test-cmx" ]
Chong Guacf19a32021-03-10 01:07:41263 }
Chong Gu26908f4e2021-01-29 03:13:07264 } else {
Chong Gu7ad57c22021-03-11 00:24:38265 manifest_fragments = [ invoker.manifest ]
Chong Gu26908f4e2021-01-29 03:13:07266 }
267
Chong Guacf19a32021-03-10 01:07:41268 if (defined(invoker.additional_manifests)) {
Chong Gu7ad57c22021-03-11 00:24:38269 manifest_fragments += invoker.additional_manifests
Chong Guacf19a32021-03-10 01:07:41270 }
Chong Gu26908f4e2021-01-29 03:13:07271 if (use_clang_coverage) {
Chong Gu7ad57c22021-03-11 00:24:38272 manifest_fragments +=
273 [ "//build/config/fuchsia/add_DebugData_service.test-cmx" ]
Chong Gu26908f4e2021-01-29 03:13:07274 }
Chong Gu7ad57c22021-03-11 00:24:38275 combined_manifest = "${target_name}.test-cmx"
276 cmc_merge(combined_manifest) {
277 sources = manifest_fragments
278 output_name = target_name
279 }
280 manifest = "${target_out_dir}/${combined_manifest}"
Chong Gu26908f4e2021-01-29 03:13:07281
Kevin Marshall39b4aa82018-06-23 00:12:15282 fuchsia_package_runner(target_name) {
Dirk Pranked5e9a1b22020-10-28 22:52:59283 is_test_exe = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53284 forward_variables_from(invoker,
285 [
286 "use_test_server",
287 "package_deps",
Andrew Grieve1b290e4a22020-11-24 20:07:01288 "visibility",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53289 ])
Kevin Marshall39b4aa82018-06-23 00:12:15290 runner_script = "//build/fuchsia/test_runner.py"
291 package = ":$_pkg_target"
292 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42293
Dirk Pranke19a58732021-03-24 22:26:22294 data = [ "//testing/location_tags.json" ]
Wezdd593a52020-04-08 17:09:46295 data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Kevin Marshallf35fa5f2018-01-29 19:24:42296 }
297
Wezabe2d752020-02-11 17:12:23298 cr_fuchsia_package(_pkg_target) {
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20299 binary = ":$_exec_target"
300 package_name_override = _output_name
Chong Gu7ad57c22021-03-11 00:24:38301 deps = [ ":$combined_manifest" ]
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20302 }
303
Kevin Marshallf35fa5f2018-01-29 19:24:42304 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01305 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42306 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03307 }
dpranke2a294622015-08-07 05:23:01308 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30309 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46310 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30311
Rohit Raof9b096d2019-09-09 22:26:23312 declare_args() {
313 # Keep the unittest-as-xctest functionality defaulted to off until the
314 # bots are updated to handle it properly.
315 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
316 # supports running unittests with xctest.
317 enable_run_ios_unittests_with_xctest = false
318 }
319
sdefresne012857872016-03-16 10:55:37320 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36321 _wrapper_output_name = "run_${target_name}"
322 ios_test_runner_wrapper(_wrapper_output_name) {
323 forward_variables_from(invoker,
324 [
325 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36326 "deps",
327 "executable_args",
328 "retries",
329 "shards",
330 ])
331
332 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
333
334 if (!defined(executable_args)) {
335 executable_args = []
336 }
337 executable_args += [
338 "--app",
339 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
340 ]
341
342 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22343
344 if (!defined(data)) {
345 data = []
346 }
347 data += [ "//testing/location_tags.json" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36348 }
349
sdefresne012857872016-03-16 10:55:37350 _resources_bundle_data = target_name + "_resources_bundle_data"
351
352 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34353 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22354 sources = [ "//testing/gtest_ios/Default.png" ]
355 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01356 }
357
Mirko Bonadei15522bc2020-09-16 20:38:39358 force_xctest = enable_run_ios_unittests_with_xctest ||
359 (defined(invoker.is_xctest) && invoker.is_xctest)
360
361 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23362 ios_test_target_type = "ios_xctest_test"
363 } else {
364 ios_test_target_type = "ios_app_bundle"
365 }
366
367 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01368 testonly = true
sdefresnea828c282016-05-30 18:04:20369
Mirko Bonadei15522bc2020-09-16 20:38:39370 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23371 xctest_module_target = "//base/test:google_test_runner"
372 }
373
Andrew Grieve1b290e4a22020-11-24 20:07:01374 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13375
376 # Provide sensible defaults in case invoker did not define any of those
377 # required variables.
sdefresne05b97ca2016-06-08 07:19:46378 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13379 info_plist = "//testing/gtest_ios/unittest-Info.plist"
380 }
sdefresne9e147e02016-06-07 00:10:13381
Olivier Robin9689c562020-04-17 14:03:57382 _gtest_bundle_id_suffix = "${target_name}"
383 xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19384
sdefresne9e147e02016-06-07 00:10:13385 if (!defined(extra_substitutions)) {
386 extra_substitutions = []
387 }
Olivier Robin9689c562020-04-17 14:03:57388 extra_substitutions +=
389 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01390
sdefresne047490e2016-07-22 08:49:34391 if (!defined(bundle_deps)) {
392 bundle_deps = []
393 }
394 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36395
396 if (!defined(data_deps)) {
397 data_deps = []
398 }
399
400 # Include the generate_wrapper as part of data_deps
401 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46402 write_runtime_deps = _runtime_deps_file
dpranke2a294622015-08-07 05:23:01403 }
Yuta Hijikatac2975452020-12-16 15:59:39404 } else if (is_chromeos_ash && cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30405 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
406
Ben Pastene16882032018-09-21 01:16:39407 # Building for a cros board (ie: not linux-chromeos).
Benjamin Pastene3bce864e2018-04-14 01:16:32408
Benjamin Pastene3bce864e2018-04-14 01:16:32409 _gen_runner_target = "${target_name}__runner"
410 _runtime_deps_file =
411 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
412 "/" + get_label_info(target_name, "name") + ".runtime_deps"
413
Ben Pastene4ab98652018-12-17 18:33:18414 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32415 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39416 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32417 runtime_deps_file = _runtime_deps_file
Dirk Pranke19a58732021-03-24 22:26:22418 data = [ "//testing/location_tags.json" ]
Benjamin Pastene3bce864e2018-04-14 01:16:32419 }
420
421 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01422 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
423 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32424 if (!defined(deps)) {
425 deps = []
426 }
427 if (!defined(data)) {
428 data = []
429 }
430
Ben Pastene41041782019-02-16 04:21:58431 # We use a special trigger script for CrOS hardware tests.
432 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
433
Benjamin Pastene3bce864e2018-04-14 01:16:32434 output_name = target_name
435 write_runtime_deps = _runtime_deps_file
436 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37437 deps += [ ":$_gen_runner_target" ]
Benjamin Pastene3bce864e2018-04-14 01:16:32438 }
Yuke Liaoe703384b2020-07-16 01:05:24439 } else if (chromeos_is_browser_only) {
440 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
441 _executable = target_name
442 _gen_runner_target = "${target_name}__runner"
443
Yuke Liao32af4242020-07-16 21:48:02444 if (defined(invoker.use_xvfb)) {
445 _use_xvfb = invoker.use_xvfb
446 } else {
447 _use_xvfb = false
448 }
449
Yuke Liaod037abc2020-10-06 22:48:22450 # When use_xvfb is set by the invoker, it indicates that running this test
451 # target requires a window, and in lacros build, ash-chrome serves as the
452 # display server. Note that even though the tests themselves do not require
453 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
454 # because ash-chrome is based on x11.
455 _use_ash_chrome = _use_xvfb
456
Yuke Liaoe703384b2020-07-16 01:05:24457 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24458 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02459
Yuke Liao2e4953cf2020-07-26 19:20:19460 data = []
Yuke Liao32af4242020-07-16 21:48:02461 if (_use_xvfb) {
462 executable = "//testing/xvfb.py"
Yuke Liao2e4953cf2020-07-26 19:20:19463 data += [ "//testing/xvfb.py" ]
Yuke Liao32af4242020-07-16 21:48:02464 } else {
465 executable = "//testing/test_env.py"
Yuke Liao2e4953cf2020-07-26 19:20:19466 data += [ "//testing/test_env.py" ]
Yuke Liao32af4242020-07-16 21:48:02467 }
Dirk Pranke19a58732021-03-24 22:26:22468 data += [ "//testing/location_tags.json" ]
Yuke Liao32af4242020-07-16 21:48:02469
Yuke Liaoe703384b2020-07-16 01:05:24470 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02471 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39472 "test",
Yuke Liaoe703384b2020-07-16 01:05:24473 "@WrappedPath(./${_executable})",
474 "--test-launcher-bot-mode",
475 ]
Yuke Liao32af4242020-07-16 21:48:02476
Yuke Liaof540c742020-07-29 16:28:34477 if (_use_ash_chrome) {
Yuke Liao8348aa42020-11-04 19:35:23478 executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ]
Yuke Liao240816d2020-07-22 00:10:39479 }
480
Yuke Liaoe703384b2020-07-16 01:05:24481 if (is_asan) {
482 executable_args += [ "--asan=true" ]
483 }
484 if (is_msan) {
485 executable_args += [ "--msan=true" ]
486 }
487 if (is_tsan) {
488 executable_args += [ "--tsan=true" ]
489 }
490 if (use_cfi_diag) {
491 executable_args += [ "--cfi-diag=true" ]
492 }
493
Yuke Liao2e4953cf2020-07-26 19:20:19494 data += [
Yuke Liao240816d2020-07-22 00:10:39495 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24496 "//.vpython",
497 ]
498 }
499
500 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01501 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
502 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24503 if (!defined(deps)) {
504 deps = []
505 }
506
Yuke Liaod037abc2020-10-06 22:48:22507 if (!defined(data_deps)) {
508 data_deps = []
509 }
510
Yuke Liaoe703384b2020-07-16 01:05:24511 write_runtime_deps = _runtime_deps_file
512 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22513 if (_use_ash_chrome && also_build_ash_chrome) {
514 data_deps +=
515 [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ]
516 }
Yuke Liaoe703384b2020-07-16 01:05:24517 }
Dirk Prankedd4ff742020-11-18 19:57:32518 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30519 if (is_mac || is_win) {
520 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
521 }
522
Dirk Prankedd4ff742020-11-18 19:57:32523 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
524 _executable = target_name
525 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06526
Dirk Prankedd4ff742020-11-18 19:57:32527 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
528 _use_xvfb = invoker.use_xvfb
529 } else {
530 _use_xvfb = false
531 }
532
533 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32534 wrapper_script = "$root_build_dir/bin/run_" + _executable
535
536 data = []
537 if (_use_xvfb) {
538 executable = "//testing/xvfb.py"
539 data += [ "//testing/xvfb.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06540 } else {
Dirk Prankedd4ff742020-11-18 19:57:32541 executable = "//testing/test_env.py"
542 data += [ "//testing/test_env.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06543 }
Dirk Pranke19a58732021-03-24 22:26:22544 data += [ "//testing/location_tags.json" ]
Dirk Pranke31e346e2020-07-15 00:54:06545
Dirk Prankedd4ff742020-11-18 19:57:32546 executable_args = [
547 "@WrappedPath(./${_executable})",
548 "--test-launcher-bot-mode",
549 ]
550 if (is_asan) {
551 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06552 }
Dirk Prankedd4ff742020-11-18 19:57:32553 if (is_msan) {
554 executable_args += [ "--msan=true" ]
555 }
556 if (is_tsan) {
557 executable_args += [ "--tsan=true" ]
558 }
559 if (use_cfi_diag) {
560 executable_args += [ "--cfi-diag=true" ]
561 }
562
563 data += [ "//.vpython" ]
Dirk Pranke31e346e2020-07-15 00:54:06564 }
565
566 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01567 forward_variables_from(invoker,
568 "*",
569 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
570 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06571 if (!defined(deps)) {
572 deps = []
573 }
574
Dirk Pranke31e346e2020-07-15 00:54:06575 deps += [
576 # Give tests the default manifest on Windows (a no-op elsewhere).
577 "//build/win:default_exe_manifest",
578 ]
579
Dirk Prankedd4ff742020-11-18 19:57:32580 write_runtime_deps = _runtime_deps_file
581 deps += [ ":$_gen_runner_target" ]
582 }
583 } else {
584 # This is a catch-all clause for NaCl toolchains and other random
585 # configurations that might define tests; test() in these configs
586 # will just define the underlying executables.
587 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
588 "use_xvfb should not be defined for a non-linux configuration")
589 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01590 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
591 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32592 if (!defined(deps)) {
593 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06594 }
595 }
qsrfb5251d12015-01-21 15:57:22596 }
597}
brettwedb6ecc2016-07-14 23:37:03598
Dirk Pranke6188075b2020-10-01 19:31:28599# Defines a type of test that invokes a script to run, rather than
600# invoking an executable.
601#
602# The script must implement the
603# [test executable API](//docs/testing/test_executable_api.md).
604#
605# The template must be passed the `script` parameter, which specifies
606# the path to the script to run. It may optionally be passed a
607# `script_args` parameter, which can be used to include a list of
608# args to be specified by default. The template will produce
609# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
610# for the target to $root_build_dir/${target_name}.runtime_deps, as per
611# the conventions listed in the
612# [test wrapper API](//docs/testing/test_wrapper_api.md).
613template("script_test") {
614 generate_wrapper(target_name) {
615 testonly = true
616 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
617
618 executable = "//testing/test_env.py"
619
620 executable_args =
621 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
622 if (defined(invoker.args)) {
623 executable_args += invoker.args
624 }
625
626 data = [
Dirk Pranke6188075b2020-10-01 19:31:28627 "//testing/test_env.py",
628
629 # These aren't needed by *every* test, but they're likely needed often
630 # enough to just make it easier to declare them here.
631 "//testing/xvfb.py",
632 "//testing/scripts/common.py",
633
634 invoker.script,
635 ]
Dirk Pranke2dd666cd2021-03-03 16:57:47636
637 if (defined(invoker.run_under_python2) && invoker.run_under_python2) {
638 use_vpython3 = false
639 data += [ "//.vpython" ]
640 } else {
641 use_vpython3 = true
642 data += [ "//.vpython3" ]
643 }
644
Dirk Pranke6188075b2020-10-01 19:31:28645 if (defined(invoker.data)) {
646 data += invoker.data
647 }
Dirk Pranke19a58732021-03-24 22:26:22648 data += [ "//testing/location_tags.json" ]
649
Dirk Pranke6188075b2020-10-01 19:31:28650 data_deps = []
651 if (defined(invoker.data_deps)) {
652 data_deps += invoker.data_deps
653 }
654
655 forward_variables_from(invoker,
656 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01657 TESTONLY_AND_VISIBILITY + [
658 "data",
659 "data_deps",
660 "script",
661 "script_args",
662 ])
663 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28664
665 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
666 }
667}
668
brettwedb6ecc2016-07-14 23:37:03669# Test defaults.
670set_defaults("test") {
671 if (is_android) {
672 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41673 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59674 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03675 } else {
676 configs = default_executable_configs
677 }
678}