blob: 473b486b09ffd0960c766c5e91135f64f9238420 [file] [log] [blame]
qsrc6c612c2015-01-13 22:07:481# Copyright 2015 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
qsrfb5251d12015-01-21 15:57:224
5# ==============================================================================
6# TEST SETUP
7# ==============================================================================
8
Yuke Liaoe703384b2020-07-16 01:05:249import("//build/config/chromeos/ui_mode.gni")
Mirko Bonadei4a0df432020-09-08 19:06:0210import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2411
jcivellif4462a352017-01-10 04:45:5912if (is_android) {
13 import("//build/config/android/config.gni")
James Cook209256f2018-12-07 18:40:5014 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5915 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4416 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3217} else if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0618 import("//build/config/chromecast_build.gni")
Kevin Marshall55fd8522019-10-04 22:47:0119 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4220 import("//build/config/fuchsia/package.gni")
Yuta Hijikatac2975452020-12-16 15:59:3921} else if (is_chromeos_ash) {
Ben Pastene4c35c572018-04-30 23:21:4822 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3223 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2824 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3225} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3626 import("//build/config/ios/ios_sdk.gni")
27 import("//build/config/ios/ios_test_runner_wrapper.gni")
28 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3229} else {
Dirk Pranke31e346e2020-07-15 00:54:0630 import("//build/config/sanitizers/sanitizers.gni")
31 import("//build/util/generate_wrapper.gni")
32}
33
qsrfb5251d12015-01-21 15:57:2234# Define a test as an executable (or apk on Android) with the "testonly" flag
35# set.
agrieve62ab00282016-04-05 02:03:4536# Variable:
Dirk Pranke79d065d2020-08-29 03:28:3037# use_xvfb: (optional) whether to run the executable under Xvfb.
agrieve62ab00282016-04-05 02:03:4538# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:5639# use_native_activity: Test implements ANativeActivity_onCreate().
Mirko Bonadei15522bc2020-09-16 20:38:3940# is_xctest: (iOS, optional) whether to build the executable as XCTest.
41# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
42# for build targets.
qsrfb5251d12015-01-21 15:57:2243template("test") {
Andrew Grieve1b290e4a22020-11-24 20:07:0144 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:3945 if (!is_ios) {
46 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
47 "is_xctest can be set only for iOS builds")
48 }
qsrfb5251d12015-01-21 15:57:2249 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:3050 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
51
agrieve62ab00282016-04-05 02:03:4552 _use_raw_android_executable = defined(invoker.use_raw_android_executable) &&
53 invoker.use_raw_android_executable
qsrfb5251d12015-01-21 15:57:2254
agrieve67855de2016-03-30 14:46:0155 # output_name is used to allow targets with the same name but in different
56 # packages to still produce unique runner scripts.
57 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2658 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0159 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2660 }
agrieve62ab00282016-04-05 02:03:4561
agrieveb355ad152016-04-19 03:45:2362 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4263 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:5164 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4265 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:5166 ]
agrieve3ac557f02016-04-12 15:52:0067
jbudorickced2a252016-06-09 16:38:5468 assert(_use_raw_android_executable || enable_java_templates)
69
agrieve62ab00282016-04-05 02:03:4570 if (_use_raw_android_executable) {
71 _exec_target = "${target_name}__exec"
72 _dist_target = "${target_name}__dist"
73 _exec_output =
74 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
75
76 executable(_exec_target) {
77 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
78 configs = []
79 data_deps = []
jbudorickd29ecfa72016-11-18 22:45:4280 forward_variables_from(invoker,
81 "*",
Andrew Grieve1b290e4a22020-11-24 20:07:0182 TESTONLY_AND_VISIBILITY + _wrapper_script_vars +
83 [ "extra_dist_files" ])
agrieve62ab00282016-04-05 02:03:4584
85 # Thanks to the set_defaults() for test(), configs are initialized with
86 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:5987 configs -= [
88 "//build/config:shared_library_config",
89 "//build/config/android:hide_all_but_jni",
90 ]
agrieve62ab00282016-04-05 02:03:4591 configs += [ "//build/config:executable_config" ]
92
93 # Don't output to the root or else conflict with the group() below.
94 output_name = rebase_path(_exec_output, root_out_dir)
agrieve62ab00282016-04-05 02:03:4595 }
96
97 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:4598 dist_dir = "$root_out_dir/$target_name"
99 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22100 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45101 if (defined(invoker.extra_dist_files)) {
102 extra_files = invoker.extra_dist_files
103 }
104 }
105 } else {
Andrew Grievec61b8dff2019-10-21 16:32:02106 _library_target = "${target_name}__library"
107 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45108 _apk_specific_vars = [
109 "android_manifest",
agrievec6811b422016-06-23 02:25:09110 "android_manifest_dep",
Clark DuVall1bee5322020-06-10 05:51:55111 "app_as_shared_lib",
agrieve62ab00282016-04-05 02:03:45112 "enable_multidex",
Benoît Lizéd8b8f742019-11-07 12:50:07113 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:02114 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07115 "proguard_configs",
116 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45117 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02118 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45119 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56120 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45121 ]
Siddhartha764226b2018-03-13 02:32:55122
123 # Adds the unwind tables from unstripped binary as an asset file in the
124 # apk, if |add_unwind_tables_in_apk| is specified by the test.
125 if (defined(invoker.add_unwind_tables_in_apk) &&
126 invoker.add_unwind_tables_in_apk) {
127 _unwind_table_asset_name = "${target_name}_unwind_assets"
128 unwind_table_asset(_unwind_table_asset_name) {
Siddhartha764226b2018-03-13 02:32:55129 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22130 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55131 }
132 }
133
agrieve62ab00282016-04-05 02:03:45134 shared_library(_library_target) {
135 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
136 configs = [] # Prevent list overwriting warning.
137 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45138
jbudorickd29ecfa72016-11-18 22:45:42139 forward_variables_from(
140 invoker,
141 "*",
Peter Wen2052bd12020-12-03 20:15:07142 [ "deps" ] + _apk_specific_vars + _wrapper_script_vars +
143 TESTONLY_AND_VISIBILITY)
144
145 # Native targets do not need to depend on java targets. Filter them out
146 # so that the shared library can be built without needing to wait for
147 # dependent java targets.
148 deps = []
149 if (defined(invoker.deps)) {
150 foreach(_dep, invoker.deps) {
151 _target_label = get_label_info(_dep, "label_no_toolchain")
152 if (filter_exclude([ _target_label ], java_target_patterns) != []) {
153 deps += [ _dep ]
154 }
155 }
156 }
agrieve62ab00282016-04-05 02:03:45157
158 if (!defined(invoker.use_default_launcher) ||
159 invoker.use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37160 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45161 }
162 }
163 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54164 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07165 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45166 apk_name = invoker.target_name
167 if (defined(invoker.output_name)) {
168 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45169 install_script_name = "install_${invoker.output_name}"
170 }
agrieveb355ad152016-04-19 03:45:23171
Daniel Bratellfdda4652019-01-31 15:45:54172 if (defined(invoker.deps)) {
173 deps = invoker.deps
174 } else {
175 deps = []
176 }
177
jcivellif4462a352017-01-10 04:45:59178 # Add the Java classes so that each target does not have to do it.
179 deps += [ "//base/test:test_support_java" ]
180
Siddhartha764226b2018-03-13 02:32:55181 if (defined(_unwind_table_asset_name)) {
182 deps += [ ":${_unwind_table_asset_name}" ]
183 }
agrieve62ab00282016-04-05 02:03:45184 }
Andrew Grievee1dc23f2019-10-22 16:26:36185 }
agrieve62ab00282016-04-05 02:03:45186
Andrew Grievee1dc23f2019-10-22 16:26:36187 test_runner_script(_test_runner_target) {
188 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57189
Andrew Grievee1dc23f2019-10-22 16:26:36190 if (_use_raw_android_executable) {
191 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34192 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36193 } else {
194 apk_target = ":$_apk_target"
195 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47196
197 # Dep needed for the test runner .runtime_deps file to pick up data
198 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22199 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45200 }
Andrew Grievee1dc23f2019-10-22 16:26:36201 test_name = _output_name
202 test_suite = _output_name
203 test_type = "gtest"
mikecase56d80d72015-06-03 00:57:26204 }
205
Andrew Grieve7ca6de32019-10-18 03:57:47206 # Create a wrapper script rather than using a group() in order to ensure
207 # "ninja $target_name" always works. If this was a group(), then GN would
208 # not create a top-level alias for it if a target exists in another
209 # directory with the same $target_name.
210 # Also - bots run this script directly for "components_perftests".
211 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01212 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47213 executable = "$root_build_dir/bin/run_$_output_name"
214 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22215 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40216 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47217 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40218 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47219 # Dep needed for the swarming .isolate file to pick up data
220 # deps from the forward_variables_from(invoker, "*") on the library.
221 deps += [
222 ":$_apk_target",
223 ":$_library_target",
224 ]
agrieve62ab00282016-04-05 02:03:45225 }
agrieve1a02e582015-10-15 21:35:39226 }
Scott Graham4c4cdc52017-05-29 20:45:03227 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30228 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
229
Scott Graham4c4cdc52017-05-29 20:45:03230 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42231 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42232 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03233
Kevin Marshall39b4aa82018-06-23 00:12:15234 fuchsia_package_runner(target_name) {
Dirk Pranked5e9a1b22020-10-28 22:52:59235 is_test_exe = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53236 forward_variables_from(invoker,
237 [
238 "use_test_server",
239 "package_deps",
Andrew Grieve1b290e4a22020-11-24 20:07:01240 "visibility",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53241 ])
Kevin Marshall39b4aa82018-06-23 00:12:15242 runner_script = "//build/fuchsia/test_runner.py"
243 package = ":$_pkg_target"
244 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42245
Wezdd593a52020-04-08 17:09:46246 data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Kevin Marshallf35fa5f2018-01-29 19:24:42247 }
248
Wezabe2d752020-02-11 17:12:23249 cr_fuchsia_package(_pkg_target) {
Fabrice de Gans-Ribericc810d32019-07-08 22:44:16250 forward_variables_from(invoker, [ "manifest" ])
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20251 binary = ":$_exec_target"
252 package_name_override = _output_name
253 }
254
Kevin Marshallf35fa5f2018-01-29 19:24:42255 executable(_exec_target) {
Andrew Grieve1b290e4a22020-11-24 20:07:01256 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42257 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03258 }
dpranke2a294622015-08-07 05:23:01259 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30260 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46261 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30262
Rohit Raof9b096d2019-09-09 22:26:23263 declare_args() {
264 # Keep the unittest-as-xctest functionality defaulted to off until the
265 # bots are updated to handle it properly.
266 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
267 # supports running unittests with xctest.
268 enable_run_ios_unittests_with_xctest = false
269 }
270
sdefresne012857872016-03-16 10:55:37271 _test_target = target_name
Jeff Yoonf7f4eb42020-03-06 18:55:36272 _wrapper_output_name = "run_${target_name}"
273 ios_test_runner_wrapper(_wrapper_output_name) {
274 forward_variables_from(invoker,
275 [
276 "data",
277 "data_deps",
278 "deps",
279 "executable_args",
280 "retries",
281 "shards",
282 ])
283
284 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
285
286 if (!defined(executable_args)) {
287 executable_args = []
288 }
289 executable_args += [
290 "--app",
291 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
292 ]
293
294 wrapper_output_name = "${_wrapper_output_name}"
295 }
296
sdefresne012857872016-03-16 10:55:37297 _resources_bundle_data = target_name + "_resources_bundle_data"
298
299 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34300 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22301 sources = [ "//testing/gtest_ios/Default.png" ]
302 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01303 }
304
Mirko Bonadei15522bc2020-09-16 20:38:39305 force_xctest = enable_run_ios_unittests_with_xctest ||
306 (defined(invoker.is_xctest) && invoker.is_xctest)
307
308 if (force_xctest) {
Rohit Raof9b096d2019-09-09 22:26:23309 ios_test_target_type = "ios_xctest_test"
310 } else {
311 ios_test_target_type = "ios_app_bundle"
312 }
313
314 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01315 testonly = true
sdefresnea828c282016-05-30 18:04:20316
Mirko Bonadei15522bc2020-09-16 20:38:39317 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23318 xctest_module_target = "//base/test:google_test_runner"
319 }
320
Andrew Grieve1b290e4a22020-11-24 20:07:01321 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13322
323 # Provide sensible defaults in case invoker did not define any of those
324 # required variables.
sdefresne05b97ca2016-06-08 07:19:46325 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13326 info_plist = "//testing/gtest_ios/unittest-Info.plist"
327 }
sdefresne9e147e02016-06-07 00:10:13328
Olivier Robin9689c562020-04-17 14:03:57329 _gtest_bundle_id_suffix = "${target_name}"
330 xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix"
Justin Cohena819c112019-08-17 02:19:19331
sdefresne9e147e02016-06-07 00:10:13332 if (!defined(extra_substitutions)) {
333 extra_substitutions = []
334 }
Olivier Robin9689c562020-04-17 14:03:57335 extra_substitutions +=
336 [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01337
sdefresne047490e2016-07-22 08:49:34338 if (!defined(bundle_deps)) {
339 bundle_deps = []
340 }
341 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36342
343 if (!defined(data_deps)) {
344 data_deps = []
345 }
346
347 # Include the generate_wrapper as part of data_deps
348 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46349 write_runtime_deps = _runtime_deps_file
dpranke2a294622015-08-07 05:23:01350 }
Yuta Hijikatac2975452020-12-16 15:59:39351 } else if (is_chromeos_ash && cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30352 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
353
Ben Pastene16882032018-09-21 01:16:39354 # Building for a cros board (ie: not linux-chromeos).
Benjamin Pastene3bce864e2018-04-14 01:16:32355
Benjamin Pastene3bce864e2018-04-14 01:16:32356 _gen_runner_target = "${target_name}__runner"
357 _runtime_deps_file =
358 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
359 "/" + get_label_info(target_name, "name") + ".runtime_deps"
360
Ben Pastene4ab98652018-12-17 18:33:18361 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32362 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) {
Andrew Grieve1b290e4a22020-11-24 20:07:01368 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
369 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32370 if (!defined(deps)) {
371 deps = []
372 }
373 if (!defined(data)) {
374 data = []
375 }
376
Ben Pastene41041782019-02-16 04:21:58377 # We use a special trigger script for CrOS hardware tests.
378 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
379
Benjamin Pastene3bce864e2018-04-14 01:16:32380 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 }
Yuke Liaoe703384b2020-07-16 01:05:24385 } else if (chromeos_is_browser_only) {
386 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
387 _executable = target_name
388 _gen_runner_target = "${target_name}__runner"
389
Yuke Liao32af4242020-07-16 21:48:02390 if (defined(invoker.use_xvfb)) {
391 _use_xvfb = invoker.use_xvfb
392 } else {
393 _use_xvfb = false
394 }
395
Yuke Liaod037abc2020-10-06 22:48:22396 # When use_xvfb is set by the invoker, it indicates that running this test
397 # target requires a window, and in lacros build, ash-chrome serves as the
398 # display server. Note that even though the tests themselves do not require
399 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
400 # because ash-chrome is based on x11.
401 _use_ash_chrome = _use_xvfb
402
Yuke Liaoe703384b2020-07-16 01:05:24403 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24404 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02405
Yuke Liao2e4953cf2020-07-26 19:20:19406 data = []
Yuke Liao32af4242020-07-16 21:48:02407 if (_use_xvfb) {
408 executable = "//testing/xvfb.py"
Yuke Liao2e4953cf2020-07-26 19:20:19409 data += [ "//testing/xvfb.py" ]
Yuke Liao32af4242020-07-16 21:48:02410 } else {
411 executable = "//testing/test_env.py"
Yuke Liao2e4953cf2020-07-26 19:20:19412 data += [ "//testing/test_env.py" ]
Yuke Liao32af4242020-07-16 21:48:02413 }
414
Yuke Liaoe703384b2020-07-16 01:05:24415 executable_args = [
Yuke Liao32af4242020-07-16 21:48:02416 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:39417 "test",
Yuke Liaoe703384b2020-07-16 01:05:24418 "@WrappedPath(./${_executable})",
419 "--test-launcher-bot-mode",
420 ]
Yuke Liao32af4242020-07-16 21:48:02421
Yuke Liaof540c742020-07-29 16:28:34422 if (_use_ash_chrome) {
Yuke Liao8348aa42020-11-04 19:35:23423 executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ]
Yuke Liao240816d2020-07-22 00:10:39424 }
425
Yuke Liaoe703384b2020-07-16 01:05:24426 if (is_asan) {
427 executable_args += [ "--asan=true" ]
428 }
429 if (is_msan) {
430 executable_args += [ "--msan=true" ]
431 }
432 if (is_tsan) {
433 executable_args += [ "--tsan=true" ]
434 }
435 if (use_cfi_diag) {
436 executable_args += [ "--cfi-diag=true" ]
437 }
438
Yuke Liao2e4953cf2020-07-26 19:20:19439 data += [
Yuke Liao240816d2020-07-22 00:10:39440 "//build/lacros/test_runner.py",
Yuke Liaoe703384b2020-07-16 01:05:24441 "//.vpython",
442 ]
443 }
444
445 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01446 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
447 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:24448 if (!defined(deps)) {
449 deps = []
450 }
451
Yuke Liaod037abc2020-10-06 22:48:22452 if (!defined(data_deps)) {
453 data_deps = []
454 }
455
Yuke Liaoe703384b2020-07-16 01:05:24456 write_runtime_deps = _runtime_deps_file
457 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:22458 if (_use_ash_chrome && also_build_ash_chrome) {
459 data_deps +=
460 [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ]
461 }
Yuke Liaoe703384b2020-07-16 01:05:24462 }
Dirk Prankedd4ff742020-11-18 19:57:32463 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:30464 if (is_mac || is_win) {
465 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
466 }
467
Dirk Prankedd4ff742020-11-18 19:57:32468 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
469 _executable = target_name
470 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:06471
Dirk Prankedd4ff742020-11-18 19:57:32472 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
473 _use_xvfb = invoker.use_xvfb
474 } else {
475 _use_xvfb = false
476 }
477
478 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:32479 wrapper_script = "$root_build_dir/bin/run_" + _executable
480
481 data = []
482 if (_use_xvfb) {
483 executable = "//testing/xvfb.py"
484 data += [ "//testing/xvfb.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06485 } else {
Dirk Prankedd4ff742020-11-18 19:57:32486 executable = "//testing/test_env.py"
487 data += [ "//testing/test_env.py" ]
Dirk Pranke31e346e2020-07-15 00:54:06488 }
489
Dirk Prankedd4ff742020-11-18 19:57:32490 executable_args = [
491 "@WrappedPath(./${_executable})",
492 "--test-launcher-bot-mode",
493 ]
494 if (is_asan) {
495 executable_args += [ "--asan=true" ]
Dirk Pranke31e346e2020-07-15 00:54:06496 }
Dirk Prankedd4ff742020-11-18 19:57:32497 if (is_msan) {
498 executable_args += [ "--msan=true" ]
499 }
500 if (is_tsan) {
501 executable_args += [ "--tsan=true" ]
502 }
503 if (use_cfi_diag) {
504 executable_args += [ "--cfi-diag=true" ]
505 }
506
507 data += [ "//.vpython" ]
Dirk Pranke31e346e2020-07-15 00:54:06508 }
509
510 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01511 forward_variables_from(invoker,
512 "*",
513 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
514 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:06515 if (!defined(deps)) {
516 deps = []
517 }
518
Dirk Pranke31e346e2020-07-15 00:54:06519 deps += [
520 # Give tests the default manifest on Windows (a no-op elsewhere).
521 "//build/win:default_exe_manifest",
522 ]
523
Dirk Prankedd4ff742020-11-18 19:57:32524 write_runtime_deps = _runtime_deps_file
525 deps += [ ":$_gen_runner_target" ]
526 }
527 } else {
528 # This is a catch-all clause for NaCl toolchains and other random
529 # configurations that might define tests; test() in these configs
530 # will just define the underlying executables.
531 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
532 "use_xvfb should not be defined for a non-linux configuration")
533 executable(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01534 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
535 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:32536 if (!defined(deps)) {
537 deps = []
Dirk Pranke31e346e2020-07-15 00:54:06538 }
539 }
qsrfb5251d12015-01-21 15:57:22540 }
541}
brettwedb6ecc2016-07-14 23:37:03542
Dirk Pranke6188075b2020-10-01 19:31:28543# Defines a type of test that invokes a script to run, rather than
544# invoking an executable.
545#
546# The script must implement the
547# [test executable API](//docs/testing/test_executable_api.md).
548#
549# The template must be passed the `script` parameter, which specifies
550# the path to the script to run. It may optionally be passed a
551# `script_args` parameter, which can be used to include a list of
552# args to be specified by default. The template will produce
553# a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps
554# for the target to $root_build_dir/${target_name}.runtime_deps, as per
555# the conventions listed in the
556# [test wrapper API](//docs/testing/test_wrapper_api.md).
557template("script_test") {
558 generate_wrapper(target_name) {
559 testonly = true
560 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
561
562 executable = "//testing/test_env.py"
563
564 executable_args =
565 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
566 if (defined(invoker.args)) {
567 executable_args += invoker.args
568 }
569
570 data = [
571 "//.vpython",
572 "//testing/test_env.py",
573
574 # These aren't needed by *every* test, but they're likely needed often
575 # enough to just make it easier to declare them here.
576 "//testing/xvfb.py",
577 "//testing/scripts/common.py",
578
579 invoker.script,
580 ]
581 if (defined(invoker.data)) {
582 data += invoker.data
583 }
584 data_deps = []
585 if (defined(invoker.data_deps)) {
586 data_deps += invoker.data_deps
587 }
588
589 forward_variables_from(invoker,
590 [ "*" ],
Andrew Grieve1b290e4a22020-11-24 20:07:01591 TESTONLY_AND_VISIBILITY + [
592 "data",
593 "data_deps",
594 "script",
595 "script_args",
596 ])
597 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:28598
599 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
600 }
601}
602
brettwedb6ecc2016-07-14 23:37:03603# Test defaults.
604set_defaults("test") {
605 if (is_android) {
606 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41607 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59608 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03609 } else {
610 configs = default_executable_configs
611 }
612}