[go: nahoru, domu]

blob: 086b27daa6e62a5abd6ecd280e76d49c797bb1c4 [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
jcivellif4462a352017-01-10 04:45:599if (is_android) {
10 import("//build/config/android/config.gni")
James Cook209256f2018-12-07 18:40:5011 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5912 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4413 import("//build/config/sanitizers/sanitizers.gni")
jcivellif4462a352017-01-10 04:45:5914}
15
Scott Graham4c4cdc52017-05-29 20:45:0316if (is_fuchsia) {
Kevin Marshall184e9092018-02-07 21:09:0617 import("//build/config/chromecast_build.gni")
Kevin Marshall55fd8522019-10-04 22:47:0118 import("//build/config/fuchsia/generate_runner_scripts.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4219 import("//build/config/fuchsia/package.gni")
Scott Graham4c4cdc52017-05-29 20:45:0320}
21
Ben Pastene4c35c572018-04-30 23:21:4822if (is_chromeos) {
23 import("//build/config/chromeos/rules.gni")
24}
25
qsrfb5251d12015-01-21 15:57:2226# Define a test as an executable (or apk on Android) with the "testonly" flag
27# set.
agrieve62ab00282016-04-05 02:03:4528# Variable:
29# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:5630# use_native_activity: Test implements ANativeActivity_onCreate().
qsrfb5251d12015-01-21 15:57:2231template("test") {
32 if (is_android) {
agrieve62ab00282016-04-05 02:03:4533 _use_raw_android_executable = defined(invoker.use_raw_android_executable) &&
34 invoker.use_raw_android_executable
qsrfb5251d12015-01-21 15:57:2235
agrieve67855de2016-03-30 14:46:0136 # output_name is used to allow targets with the same name but in different
37 # packages to still produce unique runner scripts.
38 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2639 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0140 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2641 }
agrieve62ab00282016-04-05 02:03:4542
agrieveb355ad152016-04-19 03:45:2343 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4244 _wrapper_script_vars = [
agrievee41ae1902016-04-25 14:12:5145 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4246 "shard_timeout",
agrievee41ae1902016-04-25 14:12:5147 ]
agrieve3ac557f02016-04-12 15:52:0048
jbudorickced2a252016-06-09 16:38:5449 assert(_use_raw_android_executable || enable_java_templates)
50
agrieve62ab00282016-04-05 02:03:4551 if (_use_raw_android_executable) {
52 _exec_target = "${target_name}__exec"
53 _dist_target = "${target_name}__dist"
54 _exec_output =
55 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
56
57 executable(_exec_target) {
58 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
59 configs = []
60 data_deps = []
jbudorickd29ecfa72016-11-18 22:45:4261 forward_variables_from(invoker,
62 "*",
63 _wrapper_script_vars + [ "extra_dist_files" ])
agrieve62ab00282016-04-05 02:03:4564 testonly = true
65
66 # Thanks to the set_defaults() for test(), configs are initialized with
67 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:5968 configs -= [
69 "//build/config:shared_library_config",
70 "//build/config/android:hide_all_but_jni",
71 ]
agrieve62ab00282016-04-05 02:03:4572 configs += [ "//build/config:executable_config" ]
73
74 # Don't output to the root or else conflict with the group() below.
75 output_name = rebase_path(_exec_output, root_out_dir)
agrieve62ab00282016-04-05 02:03:4576 }
77
78 create_native_executable_dist(_dist_target) {
79 testonly = true
80 dist_dir = "$root_out_dir/$target_name"
81 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:2282 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:4583 if (defined(invoker.extra_dist_files)) {
84 extra_files = invoker.extra_dist_files
85 }
86 }
87 } else {
Andrew Grievec61b8dff2019-10-21 16:32:0288 _library_target = "${target_name}__library"
89 _apk_target = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:4590 _apk_specific_vars = [
91 "android_manifest",
agrievec6811b422016-06-23 02:25:0992 "android_manifest_dep",
agrieve62ab00282016-04-05 02:03:4593 "enable_multidex",
Benoît Lizéd8b8f742019-11-07 12:50:0794 "product_config_java_packages",
Tibor Goldschwendt95db95d2019-06-17 20:32:0295 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:0796 "proguard_configs",
97 "proguard_enabled",
Clark DuVall329a6882019-10-16 23:55:2198 "shared_resources",
Fred Mello0cc91c62019-08-24 01:53:4599 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02100 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45101 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56102 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45103 ]
Siddhartha764226b2018-03-13 02:32:55104
105 # Adds the unwind tables from unstripped binary as an asset file in the
106 # apk, if |add_unwind_tables_in_apk| is specified by the test.
107 if (defined(invoker.add_unwind_tables_in_apk) &&
108 invoker.add_unwind_tables_in_apk) {
109 _unwind_table_asset_name = "${target_name}_unwind_assets"
110 unwind_table_asset(_unwind_table_asset_name) {
111 testonly = true
112 library_target = _library_target
Nico Weber852532f2020-01-28 18:17:22113 deps = [ ":$_library_target" ]
Siddhartha764226b2018-03-13 02:32:55114 }
115 }
116
agrieve62ab00282016-04-05 02:03:45117 shared_library(_library_target) {
118 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
119 configs = [] # Prevent list overwriting warning.
120 configs = invoker.configs
121 testonly = true
122
123 deps = []
jbudorickd29ecfa72016-11-18 22:45:42124 forward_variables_from(
125 invoker,
126 "*",
127 _apk_specific_vars + _wrapper_script_vars + [ "visibility" ])
agrieve62ab00282016-04-05 02:03:45128
129 if (!defined(invoker.use_default_launcher) ||
130 invoker.use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37131 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45132 }
133 }
134 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54135 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07136 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45137 apk_name = invoker.target_name
138 if (defined(invoker.output_name)) {
139 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45140 install_script_name = "install_${invoker.output_name}"
141 }
agrieveb355ad152016-04-19 03:45:23142
Daniel Bratellfdda4652019-01-31 15:45:54143 if (defined(invoker.deps)) {
144 deps = invoker.deps
145 } else {
146 deps = []
147 }
148
jcivellif4462a352017-01-10 04:45:59149 # Add the Java classes so that each target does not have to do it.
150 deps += [ "//base/test:test_support_java" ]
151
Siddhartha764226b2018-03-13 02:32:55152 if (defined(_unwind_table_asset_name)) {
153 deps += [ ":${_unwind_table_asset_name}" ]
154 }
agrieve62ab00282016-04-05 02:03:45155 }
Andrew Grievee1dc23f2019-10-22 16:26:36156 }
agrieve62ab00282016-04-05 02:03:45157
Andrew Grievee1dc23f2019-10-22 16:26:36158 test_runner_script(_test_runner_target) {
159 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce844392016-12-15 19:57:57160
Andrew Grievee1dc23f2019-10-22 16:26:36161 if (_use_raw_android_executable) {
162 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34163 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36164 } else {
165 apk_target = ":$_apk_target"
166 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47167
168 # Dep needed for the test runner .runtime_deps file to pick up data
169 # deps from the forward_variables_from(invoker, "*") on the library.
Nico Weber852532f2020-01-28 18:17:22170 data_deps = [ ":$_library_target" ]
agrieve62ab00282016-04-05 02:03:45171 }
Andrew Grievee1dc23f2019-10-22 16:26:36172 test_name = _output_name
173 test_suite = _output_name
174 test_type = "gtest"
mikecase56d80d72015-06-03 00:57:26175 }
176
Andrew Grieve7ca6de32019-10-18 03:57:47177 # Create a wrapper script rather than using a group() in order to ensure
178 # "ninja $target_name" always works. If this was a group(), then GN would
179 # not create a top-level alias for it if a target exists in another
180 # directory with the same $target_name.
181 # Also - bots run this script directly for "components_perftests".
182 generate_wrapper(target_name) {
183 testonly = true
184 executable = "$root_build_dir/bin/run_$_output_name"
185 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22186 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40187 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47188 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40189 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47190 # Dep needed for the swarming .isolate file to pick up data
191 # deps from the forward_variables_from(invoker, "*") on the library.
192 deps += [
193 ":$_apk_target",
194 ":$_library_target",
195 ]
agrieve62ab00282016-04-05 02:03:45196 }
agrieve1a02e582015-10-15 21:35:39197 }
Scott Graham4c4cdc52017-05-29 20:45:03198 } else if (is_fuchsia) {
199 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42200 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42201 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03202
Kevin Marshall39b4aa82018-06-23 00:12:15203 fuchsia_package_runner(target_name) {
Kevin Marshallf35fa5f2018-01-29 19:24:42204 testonly = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53205 forward_variables_from(invoker,
206 [
207 "use_test_server",
208 "package_deps",
209 ])
Kevin Marshall39b4aa82018-06-23 00:12:15210 runner_script = "//build/fuchsia/test_runner.py"
211 package = ":$_pkg_target"
212 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42213
Nico Weber852532f2020-01-28 18:17:22214 deps = [ "//testing/buildbot/filters:fuchsia_filters" ]
Kevin Marshallf35fa5f2018-01-29 19:24:42215 }
216
Wezabe2d752020-02-11 17:12:23217 cr_fuchsia_package(_pkg_target) {
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20218 testonly = true
Fabrice de Gans-Ribericc810d32019-07-08 22:44:16219 forward_variables_from(invoker, [ "manifest" ])
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20220 binary = ":$_exec_target"
221 package_name_override = _output_name
222 }
223
Kevin Marshallf35fa5f2018-01-29 19:24:42224 executable(_exec_target) {
Scott Graham4c4cdc52017-05-29 20:45:03225 forward_variables_from(invoker, "*")
Kevin Marshall39b4aa82018-06-23 00:12:15226 testonly = true
Kevin Marshallf35fa5f2018-01-29 19:24:42227 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03228 }
dpranke2a294622015-08-07 05:23:01229 } else if (is_ios) {
sdefresneeb7eea72017-02-23 17:15:57230 import("//build/config/ios/ios_sdk.gni")
sdefresne012857872016-03-16 10:55:37231 import("//build/config/ios/rules.gni")
232
Rohit Raof9b096d2019-09-09 22:26:23233 declare_args() {
234 # Keep the unittest-as-xctest functionality defaulted to off until the
235 # bots are updated to handle it properly.
236 # TODO(crbug.com/1001667): Remove this arg once the iOS test runner
237 # supports running unittests with xctest.
238 enable_run_ios_unittests_with_xctest = false
239 }
240
sdefresne012857872016-03-16 10:55:37241 _test_target = target_name
242 _resources_bundle_data = target_name + "_resources_bundle_data"
243
244 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34245 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22246 sources = [ "//testing/gtest_ios/Default.png" ]
247 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01248 }
249
Rohit Raof9b096d2019-09-09 22:26:23250 if (enable_run_ios_unittests_with_xctest) {
251 ios_test_target_type = "ios_xctest_test"
252 } else {
253 ios_test_target_type = "ios_app_bundle"
254 }
255
256 target(ios_test_target_type, _test_target) {
dpranke2a294622015-08-07 05:23:01257 testonly = true
sdefresnea828c282016-05-30 18:04:20258
Rohit Raof9b096d2019-09-09 22:26:23259 if (enable_run_ios_unittests_with_xctest) {
260 xctest_module_target = "//base/test:google_test_runner"
261 }
262
sdefresne9e147e02016-06-07 00:10:13263 # See above call.
264 set_sources_assignment_filter([])
265 forward_variables_from(invoker, "*", [ "testonly" ])
266
267 # Provide sensible defaults in case invoker did not define any of those
268 # required variables.
sdefresne05b97ca2016-06-08 07:19:46269 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13270 info_plist = "//testing/gtest_ios/unittest-Info.plist"
271 }
sdefresne9e147e02016-06-07 00:10:13272
Justin Cohena819c112019-08-17 02:19:19273 _bundle_id_suffix = "${target_name}"
274
sdefresne9e147e02016-06-07 00:10:13275 if (!defined(extra_substitutions)) {
276 extra_substitutions = []
277 }
sdefresneae44722d2016-10-24 13:34:37278 extra_substitutions += [ "GTEST_BUNDLE_ID_SUFFIX=$_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01279
sdefresne047490e2016-07-22 08:49:34280 if (!defined(bundle_deps)) {
281 bundle_deps = []
282 }
283 bundle_deps += [ ":$_resources_bundle_data" ]
dpranke2a294622015-08-07 05:23:01284 }
Ben Pastenefc33e132019-12-03 01:23:20285 } else if (is_chromeos && is_chromeos_device) {
Ben Pastene16882032018-09-21 01:16:39286 # Building for a cros board (ie: not linux-chromeos).
Benjamin Pastene3bce864e2018-04-14 01:16:32287
Benjamin Pastene3bce864e2018-04-14 01:16:32288 _gen_runner_target = "${target_name}__runner"
289 _runtime_deps_file =
290 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
291 "/" + get_label_info(target_name, "name") + ".runtime_deps"
292
Ben Pastene4ab98652018-12-17 18:33:18293 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32294 testonly = true
295 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39296 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32297 runtime_deps_file = _runtime_deps_file
298 }
299
300 executable(target_name) {
301 forward_variables_from(invoker, "*")
302 if (!defined(deps)) {
303 deps = []
304 }
305 if (!defined(data)) {
306 data = []
307 }
308
Ben Pastene41041782019-02-16 04:21:58309 # We use a special trigger script for CrOS hardware tests.
310 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
311
Benjamin Pastene3bce864e2018-04-14 01:16:32312 testonly = true
313 output_name = target_name
314 write_runtime_deps = _runtime_deps_file
315 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37316 deps += [ ":$_gen_runner_target" ]
Benjamin Pastene3bce864e2018-04-14 01:16:32317 }
qsrfb5251d12015-01-21 15:57:22318 } else {
319 executable(target_name) {
brettwa0902982015-08-04 19:50:33320 forward_variables_from(invoker, "*")
Abhishek Arya2f5f7342018-06-13 16:59:44321 if (!defined(deps)) {
Tom Andersonce772fa2018-05-30 22:20:37322 deps = []
323 }
qsrfb5251d12015-01-21 15:57:22324
Bruce Dawson3cad68fa2019-04-18 20:30:17325 if (is_win) {
326 # Initializing CFG data during process creation is a significant
327 # bottleneck for large test binaries, and CFG is not needed for tests,
328 # so disable it. See https://crbug.com/950923 for details.
329 configs -= [ "//build/config/win:cfi_linker" ]
330 }
qsrfb5251d12015-01-21 15:57:22331 testonly = true
brettw2e2220c2015-07-21 18:56:35332 deps += [
brettw2e2220c2015-07-21 18:56:35333 # Give tests the default manifest on Windows (a no-op elsewhere).
334 "//build/win:default_exe_manifest",
335 ]
qsrfb5251d12015-01-21 15:57:22336 }
337 }
338}
brettwedb6ecc2016-07-14 23:37:03339
340# Test defaults.
341set_defaults("test") {
342 if (is_android) {
343 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41344 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59345 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03346 } else {
347 configs = default_executable_configs
348 }
349}