blob: ee87c65a9a59a05bc4dadbdeb68a039c58967d33 [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 Marshallf35fa5f2018-01-29 19:24:4218 import("//build/config/fuchsia/package.gni")
James Cook209256f2018-12-07 18:40:5019 import("//build/config/fuchsia/rules.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 = [
agrievee41ae190d2016-04-25 14:12:5145 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4246 "shard_timeout",
agrievee41ae190d2016-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
estevensonce8443922016-12-15 19:57:5751 _incremental_apk_only =
52 incremental_apk_by_default && !_use_raw_android_executable
53
agrieve62ab00282016-04-05 02:03:4554 if (_use_raw_android_executable) {
55 _exec_target = "${target_name}__exec"
56 _dist_target = "${target_name}__dist"
57 _exec_output =
58 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
59
60 executable(_exec_target) {
61 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
62 configs = []
63 data_deps = []
jbudorickd29ecfa72016-11-18 22:45:4264 forward_variables_from(invoker,
65 "*",
66 _wrapper_script_vars + [ "extra_dist_files" ])
agrieve62ab00282016-04-05 02:03:4567 testonly = true
68
69 # Thanks to the set_defaults() for test(), configs are initialized with
70 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:5971 configs -= [
72 "//build/config:shared_library_config",
73 "//build/config/android:hide_all_but_jni",
74 ]
agrieve62ab00282016-04-05 02:03:4575 configs += [ "//build/config:executable_config" ]
76
77 # Don't output to the root or else conflict with the group() below.
78 output_name = rebase_path(_exec_output, root_out_dir)
agrieve62ab00282016-04-05 02:03:4579 }
80
81 create_native_executable_dist(_dist_target) {
82 testonly = true
83 dist_dir = "$root_out_dir/$target_name"
84 binary = _exec_output
85 deps = [
86 ":$_exec_target",
87 ]
88 if (defined(invoker.extra_dist_files)) {
89 extra_files = invoker.extra_dist_files
90 }
91 }
92 } else {
93 _library_target = "_${target_name}__library"
94 _apk_target = "${target_name}_apk"
95 _apk_specific_vars = [
96 "android_manifest",
agrievec6811b422016-06-23 02:25:0997 "android_manifest_dep",
agrieve62ab00282016-04-05 02:03:4598 "enable_multidex",
Tibor Goldschwendt95db95d2019-06-17 20:32:0299 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07100 "proguard_configs",
101 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45102 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02103 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45104 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56105 "use_native_activity",
Tibor Goldschwendt95db95d2019-06-17 20:32:02106 "write_asset_list",
agrieve62ab00282016-04-05 02:03:45107 ]
Siddhartha764226b2018-03-13 02:32:55108
109 # Adds the unwind tables from unstripped binary as an asset file in the
110 # apk, if |add_unwind_tables_in_apk| is specified by the test.
111 if (defined(invoker.add_unwind_tables_in_apk) &&
112 invoker.add_unwind_tables_in_apk) {
113 _unwind_table_asset_name = "${target_name}_unwind_assets"
114 unwind_table_asset(_unwind_table_asset_name) {
115 testonly = true
116 library_target = _library_target
Siddhartha6c58c0c2018-04-04 23:37:03117 deps = [
118 ":$_library_target",
119 ]
Siddhartha764226b2018-03-13 02:32:55120 }
121 }
122
agrieve62ab00282016-04-05 02:03:45123 shared_library(_library_target) {
124 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
125 configs = [] # Prevent list overwriting warning.
126 configs = invoker.configs
127 testonly = true
128
129 deps = []
jbudorickd29ecfa72016-11-18 22:45:42130 forward_variables_from(
131 invoker,
132 "*",
133 _apk_specific_vars + _wrapper_script_vars + [ "visibility" ])
agrieve62ab00282016-04-05 02:03:45134
135 if (!defined(invoker.use_default_launcher) ||
136 invoker.use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37137 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45138 }
139 }
140 unittest_apk(_apk_target) {
Daniel Bratellfdda4652019-01-31 15:45:54141 forward_variables_from(invoker, _apk_specific_vars)
agrieve48bd27e2016-06-22 21:04:07142 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45143 apk_name = invoker.target_name
144 if (defined(invoker.output_name)) {
145 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45146 install_script_name = "install_${invoker.output_name}"
147 }
agrieveb355ad152016-04-19 03:45:23148
Daniel Bratellfdda4652019-01-31 15:45:54149 if (defined(invoker.deps)) {
150 deps = invoker.deps
151 } else {
152 deps = []
153 }
154
jcivellif4462a352017-01-10 04:45:59155 # Add the Java classes so that each target does not have to do it.
156 deps += [ "//base/test:test_support_java" ]
157
Siddhartha764226b2018-03-13 02:32:55158 if (defined(_unwind_table_asset_name)) {
159 deps += [ ":${_unwind_table_asset_name}" ]
160 }
161
agrieveb355ad152016-04-19 03:45:23162 # TODO(agrieve): Remove this data_dep once bots don't build the _apk
163 # target (post-GYP).
164 # It's a bit backwards for the apk to depend on the runner script, since
165 # the apk is conceptually a runtime_dep of the script. However, it is
166 # currently necessary because the bots build this _apk target directly
167 # rather than the group() below.
168 data_deps = [
169 ":$_test_runner_target",
170 ]
agrieve62ab00282016-04-05 02:03:45171 }
172
estevensonce8443922016-12-15 19:57:57173 _test_runner_target = "${_output_name}__test_runner_script"
174 _incremental_test_name = "${_output_name}_incremental"
agrieve62ab00282016-04-05 02:03:45175 _incremental_test_runner_target =
176 "${_output_name}_incremental__test_runner_script"
estevensonce8443922016-12-15 19:57:57177 if (_incremental_apk_only) {
178 _incremental_test_name = _output_name
179 _incremental_test_runner_target = _test_runner_target
180 }
181
182 # Incremental test targets work only for .apks.
agrieve62ab00282016-04-05 02:03:45183 test_runner_script(_incremental_test_runner_target) {
jbudorickd29ecfa72016-11-18 22:45:42184 forward_variables_from(invoker,
185 _wrapper_script_vars + [
186 "data",
187 "data_deps",
188 "deps",
189 "public_deps",
190 ])
agrieve62ab00282016-04-05 02:03:45191 apk_target = ":$_apk_target"
estevensonce8443922016-12-15 19:57:57192 test_name = _incremental_test_name
agrieve62ab00282016-04-05 02:03:45193 test_type = "gtest"
194 test_suite = _output_name
195 incremental_install = true
196 }
197 group("${target_name}_incremental") {
198 testonly = true
estevensonce8443922016-12-15 19:57:57199 data_deps = [
agrieve62ab00282016-04-05 02:03:45200 ":$_incremental_test_runner_target",
201 ]
202 deps = [
203 ":${_apk_target}_incremental",
204 ]
205 }
206 }
207
estevensonce8443922016-12-15 19:57:57208 if (!_incremental_apk_only) {
209 test_runner_script(_test_runner_target) {
210 forward_variables_from(invoker,
211 _wrapper_script_vars + [
212 "data",
213 "data_deps",
214 "deps",
215 "public_deps",
216 ])
agrievee41ae190d2016-04-25 14:12:51217
estevensonce8443922016-12-15 19:57:57218 if (_use_raw_android_executable) {
219 executable_dist_dir = "$root_out_dir/$_dist_target"
220 } else {
221 apk_target = ":$_apk_target"
222 }
223 test_name = _output_name
224 test_type = "gtest"
225 test_suite = _output_name
agrieve62ab00282016-04-05 02:03:45226 }
mikecase56d80d72015-06-03 00:57:26227 }
228
jbudorick686094f62017-05-04 21:52:40229 test_runner_script(target_name) {
230 forward_variables_from(invoker,
231 _wrapper_script_vars + [
232 "data",
233 "data_deps",
234 "deps",
235 "public_deps",
236 ])
237
238 if (_use_raw_android_executable) {
239 executable_dist_dir = "$root_out_dir/$_dist_target"
240 deps += [
241 ":$_dist_target",
estevensonce8443922016-12-15 19:57:57242 ":$_test_runner_target",
243 ]
jbudorick686094f62017-05-04 21:52:40244 } else {
245 apk_target = ":$_apk_target"
246 deps += [ ":$_apk_target" ]
247 if (_incremental_apk_only) {
248 deps += [ ":${target_name}_incremental" ]
estevensonce8443922016-12-15 19:57:57249 } else {
jbudorick686094f62017-05-04 21:52:40250 deps += [ ":$_test_runner_target" ]
estevensonce8443922016-12-15 19:57:57251 }
agrieve62ab00282016-04-05 02:03:45252 }
jbudorick686094f62017-05-04 21:52:40253 generated_script = "$root_build_dir/$_output_name"
254 incremental_install = _incremental_apk_only
255 test_name = _output_name
256 test_suite = _output_name
257 test_type = "gtest"
agrieve1a02e582015-10-15 21:35:39258 }
Scott Graham4c4cdc52017-05-29 20:45:03259 } else if (is_fuchsia) {
260 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42261 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42262 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03263
Kevin Marshall39b4aa82018-06-23 00:12:15264 fuchsia_package_runner(target_name) {
Kevin Marshallf35fa5f2018-01-29 19:24:42265 testonly = true
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53266 forward_variables_from(invoker,
267 [
268 "use_test_server",
269 "package_deps",
270 ])
Kevin Marshall39b4aa82018-06-23 00:12:15271 runner_script = "//build/fuchsia/test_runner.py"
272 package = ":$_pkg_target"
273 package_name_override = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42274
275 deps = [
276 "//testing/buildbot/filters:fuchsia_filters",
277 ]
Kevin Marshallf35fa5f2018-01-29 19:24:42278 }
279
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20280 fuchsia_package(_pkg_target) {
281 testonly = true
Fabrice de Gans-Ribericc810d32019-07-08 22:44:16282 forward_variables_from(invoker, [ "manifest" ])
Fabrice de Gans-Riberia16cac82019-06-03 19:03:20283 binary = ":$_exec_target"
284 package_name_override = _output_name
285 }
286
Kevin Marshallf35fa5f2018-01-29 19:24:42287 executable(_exec_target) {
Scott Graham4c4cdc52017-05-29 20:45:03288 forward_variables_from(invoker, "*")
Kevin Marshall39b4aa82018-06-23 00:12:15289 testonly = true
Kevin Marshallf35fa5f2018-01-29 19:24:42290 output_name = _exec_target
Scott Graham4c4cdc52017-05-29 20:45:03291 }
dpranke2a294622015-08-07 05:23:01292 } else if (is_ios) {
sdefresneeb7eea72017-02-23 17:15:57293 import("//build/config/ios/ios_sdk.gni")
sdefresne012857872016-03-16 10:55:37294 import("//build/config/ios/rules.gni")
295
296 _test_target = target_name
297 _resources_bundle_data = target_name + "_resources_bundle_data"
298
299 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34300 visibility = [ ":$_test_target" ]
sdefresne012857872016-03-16 10:55:37301 sources = [
302 "//testing/gtest_ios/Default.png",
303 ]
304 outputs = [
305 "{{bundle_resources_dir}}/{{source_file_part}}",
306 ]
dpranke2a294622015-08-07 05:23:01307 }
308
sdefresne1a9694422016-04-12 13:53:44309 ios_app_bundle(_test_target) {
dpranke2a294622015-08-07 05:23:01310 testonly = true
sdefresnea828c282016-05-30 18:04:20311
sdefresne9e147e02016-06-07 00:10:13312 # See above call.
313 set_sources_assignment_filter([])
314 forward_variables_from(invoker, "*", [ "testonly" ])
315
316 # Provide sensible defaults in case invoker did not define any of those
317 # required variables.
sdefresne05b97ca2016-06-08 07:19:46318 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13319 info_plist = "//testing/gtest_ios/unittest-Info.plist"
320 }
sdefresne9e147e02016-06-07 00:10:13321
Justin Cohena819c112019-08-17 02:19:19322 _bundle_id_suffix = "${target_name}"
323
sdefresne9e147e02016-06-07 00:10:13324 if (!defined(extra_substitutions)) {
325 extra_substitutions = []
326 }
sdefresneae44722d2016-10-24 13:34:37327 extra_substitutions += [ "GTEST_BUNDLE_ID_SUFFIX=$_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01328
sdefresne047490e2016-07-22 08:49:34329 if (!defined(bundle_deps)) {
330 bundle_deps = []
331 }
332 bundle_deps += [ ":$_resources_bundle_data" ]
dpranke2a294622015-08-07 05:23:01333 }
James Cook209256f2018-12-07 18:40:50334 } else if (is_chromeos && is_cros_chrome_sdk) {
Ben Pastene16882032018-09-21 01:16:39335 # Building for a cros board (ie: not linux-chromeos).
Benjamin Pastene3bce864e2018-04-14 01:16:32336
Benjamin Pastene3bce864e2018-04-14 01:16:32337 _gen_runner_target = "${target_name}__runner"
338 _runtime_deps_file =
339 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
340 "/" + get_label_info(target_name, "name") + ".runtime_deps"
341
Ben Pastene4ab98652018-12-17 18:33:18342 generate_runner_script(_gen_runner_target) {
Benjamin Pastene3bce864e2018-04-14 01:16:32343 testonly = true
344 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Ben Pastene16882032018-09-21 01:16:39345 test_exe = invoker.target_name
Benjamin Pastene3bce864e2018-04-14 01:16:32346 runtime_deps_file = _runtime_deps_file
347 }
348
349 executable(target_name) {
350 forward_variables_from(invoker, "*")
351 if (!defined(deps)) {
352 deps = []
353 }
354 if (!defined(data)) {
355 data = []
356 }
357
Ben Pastene41041782019-02-16 04:21:58358 # We use a special trigger script for CrOS hardware tests.
359 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
360
Benjamin Pastene3bce864e2018-04-14 01:16:32361 testonly = true
362 output_name = target_name
363 write_runtime_deps = _runtime_deps_file
364 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37365 deps += [ ":$_gen_runner_target" ]
Benjamin Pastene3bce864e2018-04-14 01:16:32366 }
qsrfb5251d12015-01-21 15:57:22367 } else {
368 executable(target_name) {
brettwa0902982015-08-04 19:50:33369 forward_variables_from(invoker, "*")
Abhishek Arya2f5f7342018-06-13 16:59:44370 if (!defined(deps)) {
Tom Andersonce772fa2018-05-30 22:20:37371 deps = []
372 }
qsrfb5251d12015-01-21 15:57:22373
Bruce Dawson3cad68fa2019-04-18 20:30:17374 if (is_win) {
375 # Initializing CFG data during process creation is a significant
376 # bottleneck for large test binaries, and CFG is not needed for tests,
377 # so disable it. See https://crbug.com/950923 for details.
378 configs -= [ "//build/config/win:cfi_linker" ]
379 }
qsrfb5251d12015-01-21 15:57:22380 testonly = true
brettw2e2220c2015-07-21 18:56:35381 deps += [
brettw2e2220c2015-07-21 18:56:35382 # Give tests the default manifest on Windows (a no-op elsewhere).
383 "//build/win:default_exe_manifest",
384 ]
qsrfb5251d12015-01-21 15:57:22385 }
386 }
387}
brettwedb6ecc2016-07-14 23:37:03388
389# Test defaults.
390set_defaults("test") {
391 if (is_android) {
392 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41393 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:59394 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03395 } else {
396 configs = default_executable_configs
397 }
398}