[go: nahoru, domu]

blob: a522190857f246f3374a1f689a08ad52f7fae28b [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") {
Greg Guterman8da79b72021-01-07 23:41:0946 # RTS
47 if (rts_exclude_file != "" && defined(invoker.sources) &&
48 invoker.sources != []) {
49 # Normalize paths
50 abs_paths = get_path_info(invoker.sources, "abspath")
51
52 # Filter
53 filtered_sources = filter_exclude(abs_paths, rts_exclusions)
54
55 # Do the replacement
56 invoker.sources = []
57 invoker.sources = filtered_sources
58 }
59
Andrew Grieve1b290e4a22020-11-24 20:07:0160 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:3961 if (!is_ios) {
62 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
63 "is_xctest can be set only for iOS builds")
64 }
qsrfb5251d12015-01-21 15:57:2265 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3066 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
67
agrieve62ab00282016-04-05 02:03:4568 _use_raw_android_executable = defined(invoker.use_raw_android_executable) &&
69 invoker.use_raw_android_executable
qsrfb5251d12015-01-21 15:57:2270
agrieve67855de2016-03-30 14:46:0171 # output_name is used to allow targets with the same name but in different
72 # packages to still produce unique runner scripts.
73 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2674 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0175 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2676 }
agrieve62ab00282016-04-05 02:03:4577
agrieveb355ad152016-04-19 03:45:2378 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4279 _wrapper_script_vars = [
agrievee41ae1902016-04-25 14:12:5180 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4281 "shard_timeout",
agrievee41ae1902016-04-25 14:12:5182 ]
agrieve3ac557f02016-04-12 15:52:0083
jbudorickced2a252016-06-09 16:38:5484 assert(_use_raw_android_executable || enable_java_templates)
85
agrieve62ab00282016-04-05 02:03:4586 if (_use_raw_android_executable) {
87 _exec_target = "${target_name}__exec"
88 _dist_target = "${target_name}__dist"
89 _exec_output =
90 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
91
92 executable(_exec_target) {
93 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
94 configs = []
95 data_deps = []
jbudorickd29ecfa72016-11-18 22:45:4296 forward_variables_from(invoker,
97 "*",
Andrew Grieve1b290e4a22020-11-24 20:07:0198 TESTONLY_AND_VISIBILITY + _wrapper_script_vars +
99 [ "extra_dist_files" ])
agrieve62ab00282016-04-05 02:03:45100
101 # Thanks to the set_defaults() for test(), configs are initialized with
102 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59103 configs -= [
104 "//build/config:shared_library_config",
105 "//build/config/android:hide_all_but_jni",
106 ]
agrieve62ab00282016-04-05 02:03:45107 configs += [ "//build/config:executable_config" ]
108
109 # Don't output to the root or else conflict with the group() below.
110 output_name = rebase_path(_exec_output, root_out_dir)
agrieve62ab00282016-04-05 02:03:45111 }
112
113 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45114 dist_dir = "$root_out_dir/$target_name"
115 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22116 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45117 if (defined(invoker.extra_dist_files)) {
118 extra_files = invoker.extra_dist_files
119 }
120 }
121 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02122 _library_target = "${target_name}__library"
123 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45124 _apk_specific_vars = [
125 "android_manifest",
agrievec6811b422016-06-23 02:25:09126 "android_manifest_dep",
Clark DuVall1bee5322020-06-10 05:51:55127 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45128 "enable_multidex",
Benoît Lizéd8b8f742019-11-07 12:50:07129 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02130 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07131 "proguard_configs",
132 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45133 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02134 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45135 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56136 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45137 ]
Siddhartha764226b2018-03-13 02:32:55138
139 # Adds the unwind tables from unstripped binary as an asset file in the
140 # apk, if |add_unwind_tables_in_apk| is specified by the test.
141 if (defined(invoker.add_unwind_tables_in_apk) &&
142 invoker.add_unwind_tables_in_apk) {
143 _unwind_table_asset_name = "${target_name}_unwind_assets"
144 unwind_table_asset(_unwind_table_asset_name) {
Siddhartha764226b2018-03-13 02:32:55145 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22146 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55147 }
148 }
149
agrieve62ab00282016-04-05 02:03:45150 shared_library(_library_target) {
151 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
152 configs = [] # Prevent list overwriting warning.
153 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45154
jbudorickd29ecfa72016-11-18 22:45:42155 forward_variables_from(
156 invoker,
157 "*",
Peter Wen2052bd12020-12-03 20:15:07158 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
159 TESTONLY_AND_VISIBILITY)
160
161 # Native targets do not need to depend on java targets. Filter them out
162 # so that the shared library can be built without needing to wait for
163 # dependent java targets.
164 deps = []
165 if (defined(invoker.deps)) {
166 foreach(_dep, invoker.deps) {
167 _target_label = get_label_info(_dep, "label_no_toolchain")
168 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
169 deps += [ _dep ]
170 }
171 }
172 }
agrieve62ab00282016-04-05 02:03:45173
174 if (!defined(invoker.use_default_launcher) ||
175 invoker.use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37176 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45177 }
178 }
179 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54180 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07181 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45182 apk_name = invoker.target_name
183 if (defined(invoker.output_name)) {
184 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45185 install_script_name = "install_${invoker.output_name}"
186 }
agrieveb355ad152016-04-19 03:45:23187
Daniel Bratellfdda4652019-01-31 15:45:54188 if (defined(invoker.deps)) {
189 deps = invoker.deps
190 } else {
191 deps = []
192 }
193
jcivellif4462a352017-01-10 04:45:59194 # Add the Java classes so that each target does not have to do it.
195 deps += [ "//base/test:test_support_java" ]
196
Siddhartha764226b2018-03-13 02:32:55197 if (defined(_unwind_table_asset_name)) {
198 deps += [ ":${_unwind_table_asset_name}" ]
199 }
agrieve62ab00282016-04-05 02:03:45200 }
Andrew Grievee1dc23f2019-10-22 16:26:36201 }
agrieve62ab00282016-04-05 02:03:45202
Andrew Grievee1dc23f2019-10-22 16:26:36203 test_runner_script(_test_runner_target) {
204 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce844392016-12-15 19:57:57205
Andrew Grievee1dc23f2019-10-22 16:26:36206 if (_use_raw_android_executable) {
207 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34208 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36209 } else {
210 apk_target = ":$_apk_target"
211 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47212
213 # Dep needed for the test runner .runtime_deps file to pick up data
214 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22215 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45216 }
Andrew Grievee1dc23f2019-10-22 16:26:36217 test_name = _output_name
218 test_suite = _output_name
219 test_type = "gtest"
mikecase56d80d72015-06-03 00:57:26220 }
221
Andrew Grieve7ca6de32019-10-18 03:57:47222 # Create a wrapper script rather than using a group() in order to ensure
223 # "ninja $target_name" always works. If this was a group(), then GN would
224 # not create a top-level alias for it if a target exists in another
225 # directory with the same $target_name.
226 # Also - bots run this script directly for "components_perftests".
227 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01228 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47229 executable = "$root_build_dir/bin/run_$_output_name"
230 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22231 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40232 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47233 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40234 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47235 # Dep needed for the swarming .isolate file to pick up data
236 # deps from the forward_variables_from(invoker, "*") on the library.
237 deps += [
238 ":$_apk_target",
239 ":$_library_target",
240 ]
agrieve62ab00282016-04-05 02:03:45241 }
agrieve1a02e582015-10-15 21:35:39242 }
Scott Graham4c4cdc52017-05-29 20:45:03243 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30244 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
245
Scott Graham4c4cdc52017-05-29 20:45:03246 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42247 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42248 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03249
Chong Gu26908f42021-01-29 03:13:07250 # TODO(1019938): switch the default to tests.cmx which doesn't request
251 # the deprecated-ambient-replace-as-executable feature.
252 if (!defined(invoker.manifest)) {
253 manifest = "//build/config/fuchsia/tests-with-exec.cmx"
254 } else {
255 manifest = invoker.manifest
256 }
257
258 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 Gu26908f42021-01-29 03:13:07288 if (use_clang_coverage) {
289 deps = [ ":$component_with_coverage_manifest" ]
290 }
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20291 }
292
Kevin Marshallf35fa5f2018-01-29 19:24:42293 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01294 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42295 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03296 }
dpranke2a294622015-08-07 05:23:01297 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30298 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46299 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30300
Rohit Raof9b096d2019-09-09 22:26:23301 declare_args() {
302 # Keep the unittest-as-xctest functionality defaulted to off until the
303 # bots are updated to handle it properly.
304 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
305 # supports running unittests with xctest.
306 enable_run_ios_unittests_with_xctest = false
307 }
308
sdefresne012857872016-03-16 10:55:37309 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36310 _wrapper_output_name = "run_${target_name}"
311 ios_test_runner_wrapper(_wrapper_output_name) {
312 forward_variables_from(invoker,
313 [
314 "data",
315 "data_deps",
316 "deps",
317 "executable_args",
318 "retries",
319 "shards",
320 ])
321
322 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
323
324 if (!defined(executable_args)) {
325 executable_args = []
326 }
327 executable_args += [
328 "--app",
329 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
330 ]
331
332 wrapper_output_name = "${_wrapper_output_name}"
333 }
334
sdefresne012857872016-03-16 10:55:37335 _resources_bundle_data = target_name + "_resources_bundle_data"
336
337 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34338 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22339 sources = [ "//testing/gtest_ios/Default.png" ]
340 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01341 }
342
Mirko Bonadei15522bc2020-09-16 20:38:39343 force_xctest = enable_run_ios_unittests_with_xctest ||
344 (defined(invoker.is_xctest) && invoker.is_xctest)
345
346 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23347 ios_test_target_type = "ios_xctest_test"
348 } else {
349 ios_test_target_type = "ios_app_bundle"
350 }
351
352 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01353 testonly = true
sdefresnea828c282016-05-30 18:04:20354
Mirko Bonadei15522bc2020-09-16 20:38:39355 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23356 xctest_module_target = "//base/test:google_test_runner"
357 }
358
Andrew Grieve1b290e4a22020-11-24 20:07:01359 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13360
361 # Provide sensible defaults in case invoker did not define any of those
362 # required variables.
sdefresne05b97ca2016-06-08 07:19:46363 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13364 info_plist = "//testing/gtest_ios/unittest-Info.plist"
365 }
sdefresne9e147e02016-06-07 00:10:13366
Olivier Robin9689c562020-04-17 14:03:57367 _gtest_bundle_id_suffix = "${target_name}"
368 xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19369
sdefresne9e147e02016-06-07 00:10:13370 if (!defined(extra_substitutions)) {
371 extra_substitutions = []
372 }
Olivier Robin9689c562020-04-17 14:03:57373 extra_substitutions +=
374 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01375
sdefresne047490e2016-07-22 08:49:34376 if (!defined(bundle_deps)) {
377 bundle_deps = []
378 }
379 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36380
381 if (!defined(data_deps)) {
382 data_deps = []
383 }
384
385 # Include the generate_wrapper as part of data_deps
386 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46387 write_runtime_deps = _runtime_deps_file
dpranke2a294622015-08-07 05:23:01388 }
Yuta Hijikatac2975452020-12-16 15:59:39389 } else if (is_chromeos_ash && cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30390 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
391
Ben Pastene16882032018-09-21 01:16:39392 # Building for a cros board (ie: not linux-chromeos).
Benjamin Pastene3bce864e2018-04-14 01:16:32393
Benjamin Pastene3bce864e2018-04-14 01:16:32394 _gen_runner_target = "${target_name}__runner"
395 _runtime_deps_file =
396 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
397 "/" + get_label_info(target_name, "name") + ".runtime_deps"
398
Ben Pastene4ab98652018-12-17 18:33:18399 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32400 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39401 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32402 runtime_deps_file = _runtime_deps_file
403 }
404
405 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01406 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
407 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32408 if (!defined(deps)) {
409 deps = []
410 }
411 if (!defined(data)) {
412 data = []
413 }
414
Ben Pastene41041782019-02-16 04:21:58415 # We use a special trigger script for CrOS hardware tests.
416 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
417
Benjamin Pastene3bce864e2018-04-14 01:16:32418 output_name = target_name
419 write_runtime_deps = _runtime_deps_file
420 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37421 deps += [ ":$_gen_runner_target" ]
Benjamin Pastene3bce864e2018-04-14 01:16:32422 }
Yuke Liaoe703384b2020-07-16 01:05:24423 } else if (chromeos_is_browser_only) {
424 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
425 _executable = target_name
426 _gen_runner_target = "${target_name}__runner"
427
Yuke Liao32af4242020-07-16 21:48:02428 if (defined(invoker.use_xvfb)) {
429 _use_xvfb = invoker.use_xvfb
430 } else {
431 _use_xvfb = false
432 }
433
Yuke Liaod037abc2020-10-06 22:48:22434 # When use_xvfb is set by the invoker, it indicates that running this test
435 # target requires a window, and in lacros build, ash-chrome serves as the
436 # display server. Note that even though the tests themselves do not require
437 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
438 # because ash-chrome is based on x11.
439 _use_ash_chrome = _use_xvfb
440
Yuke Liaoe703384b2020-07-16 01:05:24441 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24442 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02443
Yuke Liao2e4953cf2020-07-26 19:20:19444 data = []
Yuke Liao32af4242020-07-16 21:48:02445 if (_use_xvfb) {
446 executable = "//testing/xvfb.py"
Yuke Liao2e4953cf2020-07-26 19:20:19447 data += [ "//testing/xvfb.py" ]
Yuke Liao32af4242020-07-16 21:48:02448 } else {
449 executable = "//testing/test_env.py"
Yuke Liao2e4953cf2020-07-26 19:20:19450 data += [ "//testing/test_env.py" ]
Yuke Liao32af4242020-07-16 21:48:02451 }
452
Yuke Liaoe703384b2020-07-16 01:05:24453 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02454 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39455 "test",
Yuke Liaoe703384b2020-07-16 01:05:24456 "@WrappedPath(./${_executable})",
457 "--test-launcher-bot-mode",
458 ]
Yuke Liao32af4242020-07-16 21:48:02459
Yuke Liaof540c742020-07-29 16:28:34460 if (_use_ash_chrome) {
Yuke Liao8348aa42020-11-04 19:35:23461 executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ]
Yuke Liao240816d2020-07-22 00:10:39462 }
463
Yuke Liaoe703384b2020-07-16 01:05:24464 if (is_asan) {
465 executable_args += [ "--asan=true" ]
466 }
467 if (is_msan) {
468 executable_args += [ "--msan=true" ]
469 }
470 if (is_tsan) {
471 executable_args += [ "--tsan=true" ]
472 }
473 if (use_cfi_diag) {
474 executable_args += [ "--cfi-diag=true" ]
475 }
476
Yuke Liao2e4953cf2020-07-26 19:20:19477 data += [
Yuke Liao240816d2020-07-22 00:10:39478 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24479 "//.vpython",
480 ]
481 }
482
483 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01484 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
485 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24486 if (!defined(deps)) {
487 deps = []
488 }
489
Yuke Liaod037abc2020-10-06 22:48:22490 if (!defined(data_deps)) {
491 data_deps = []
492 }
493
Yuke Liaoe703384b2020-07-16 01:05:24494 write_runtime_deps = _runtime_deps_file
495 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22496 if (_use_ash_chrome && also_build_ash_chrome) {
497 data_deps +=
498 [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ]
499 }
Yuke Liaoe703384b2020-07-16 01:05:24500 }
Dirk Prankedd4ff742020-11-18 19:57:32501 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30502 if (is_mac || is_win) {
503 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
504 }
505
Dirk Prankedd4ff742020-11-18 19:57:32506 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
507 _executable = target_name
508 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06509
Dirk Prankedd4ff742020-11-18 19:57:32510 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
511 _use_xvfb = invoker.use_xvfb
512 } else {
513 _use_xvfb = false
514 }
515
516 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32517 wrapper_script = "$root_build_dir/bin/run_" + _executable
518
519 data = []
520 if (_use_xvfb) {
521 executable = "//testing/xvfb.py"
522 data += [ "//testing/xvfb.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06523 } else {
Dirk Prankedd4ff742020-11-18 19:57:32524 executable = "//testing/test_env.py"
525 data += [ "//testing/test_env.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06526 }
527
Dirk Prankedd4ff742020-11-18 19:57:32528 executable_args = [
529 "@WrappedPath(./${_executable})",
530 "--test-launcher-bot-mode",
531 ]
532 if (is_asan) {
533 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06534 }
Dirk Prankedd4ff742020-11-18 19:57:32535 if (is_msan) {
536 executable_args += [ "--msan=true" ]
537 }
538 if (is_tsan) {
539 executable_args += [ "--tsan=true" ]
540 }
541 if (use_cfi_diag) {
542 executable_args += [ "--cfi-diag=true" ]
543 }
544
545 data += [ "//.vpython" ]
Dirk Pranke31e346e2020-07-15 00:54:06546 }
547
548 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01549 forward_variables_from(invoker,
550 "*",
551 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
552 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06553 if (!defined(deps)) {
554 deps = []
555 }
556
Dirk Pranke31e346e2020-07-15 00:54:06557 deps += [
558 # Give tests the default manifest on Windows (a no-op elsewhere).
559 "//build/win:default_exe_manifest",
560 ]
561
Dirk Prankedd4ff742020-11-18 19:57:32562 write_runtime_deps = _runtime_deps_file
563 deps += [ ":$_gen_runner_target" ]
564 }
565 } else {
566 # This is a catch-all clause for NaCl toolchains and other random
567 # configurations that might define tests; test() in these configs
568 # will just define the underlying executables.
569 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
570 "use_xvfb should not be defined for a non-linux configuration")
571 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01572 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
573 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32574 if (!defined(deps)) {
575 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06576 }
577 }
qsrfb5251d12015-01-21 15:57:22578 }
579}
brettwedb6ecc2016-07-14 23:37:03580
Dirk Pranke6188075b2020-10-01 19:31:28581# Defines a type of test that invokes a script to run, rather than
582# invoking an executable.
583#
584# The script must implement the
585# [test executable API](//docs/testing/test_executable_api.md).
586#
587# The template must be passed the `script` parameter, which specifies
588# the path to the script to run. It may optionally be passed a
589# `script_args` parameter, which can be used to include a list of
590# args to be specified by default. The template will produce
591# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
592# for the target to $root_build_dir/${target_name}.runtime_deps, as per
593# the conventions listed in the
594# [test wrapper API](//docs/testing/test_wrapper_api.md).
595template("script_test") {
596 generate_wrapper(target_name) {
597 testonly = true
598 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
599
600 executable = "//testing/test_env.py"
601
602 executable_args =
603 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
604 if (defined(invoker.args)) {
605 executable_args += invoker.args
606 }
607
608 data = [
609 "//.vpython",
610 "//testing/test_env.py",
611
612 # These aren't needed by *every* test, but they're likely needed often
613 # enough to just make it easier to declare them here.
614 "//testing/xvfb.py",
615 "//testing/scripts/common.py",
616
617 invoker.script,
618 ]
619 if (defined(invoker.data)) {
620 data += invoker.data
621 }
622 data_deps = []
623 if (defined(invoker.data_deps)) {
624 data_deps += invoker.data_deps
625 }
626
627 forward_variables_from(invoker,
628 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01629 TESTONLY_AND_VISIBILITY + [
630 "data",
631 "data_deps",
632 "script",
633 "script_args",
634 ])
635 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28636
637 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
638 }
639}
640
brettwedb6ecc2016-07-14 23:37:03641# Test defaults.
642set_defaults("test") {
643 if (is_android) {
644 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41645 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59646 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03647 } else {
648 configs = default_executable_configs
649 }
650}