[go: nahoru, domu]

blob: 96febe0f55e8f7a65668e09ad310e2ebea52034b [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")
11 import("//build/config/android/rules.gni")
12 import("//build/config/sanitizers/sanitizers.gni")
13}
14
qsrfb5251d12015-01-21 15:57:2215# Define a test as an executable (or apk on Android) with the "testonly" flag
16# set.
agrieve62ab00282016-04-05 02:03:4517# Variable:
18# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:5619# use_native_activity: Test implements ANativeActivity_onCreate().
qsrfb5251d12015-01-21 15:57:2220template("test") {
21 if (is_android) {
agrieve62ab00282016-04-05 02:03:4522 _use_raw_android_executable = defined(invoker.use_raw_android_executable) &&
23 invoker.use_raw_android_executable
qsrfb5251d12015-01-21 15:57:2224
agrieve67855de2016-03-30 14:46:0125 # output_name is used to allow targets with the same name but in different
26 # packages to still produce unique runner scripts.
27 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2628 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0129 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2630 }
agrieve62ab00282016-04-05 02:03:4531
agrieveb355ad152016-04-19 03:45:2332 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4233 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:5134 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4235 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:5136 ]
agrieve3ac557f02016-04-12 15:52:0037
jbudorickced2a252016-06-09 16:38:5438 assert(_use_raw_android_executable || enable_java_templates)
39
estevensonce844392016-12-15 19:57:5740 _incremental_apk_only =
41 incremental_apk_by_default && !_use_raw_android_executable
42
agrieve62ab00282016-04-05 02:03:4543 if (_use_raw_android_executable) {
44 _exec_target = "${target_name}__exec"
45 _dist_target = "${target_name}__dist"
46 _exec_output =
47 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
48
49 executable(_exec_target) {
50 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
51 configs = []
52 data_deps = []
jbudorickd29ecfa72016-11-18 22:45:4253 forward_variables_from(invoker,
54 "*",
55 _wrapper_script_vars + [ "extra_dist_files" ])
agrieve62ab00282016-04-05 02:03:4556 testonly = true
57
58 # Thanks to the set_defaults() for test(), configs are initialized with
59 # the default shared_library configs rather than executable configs.
60 configs -= [
61 "//build/config:shared_library_config",
agrievee61084f22017-02-15 17:20:5662 "//build/config/android:hide_all_but_jni_onload",
agrieve62ab00282016-04-05 02:03:4563 ]
64 configs += [ "//build/config:executable_config" ]
65
66 # Don't output to the root or else conflict with the group() below.
67 output_name = rebase_path(_exec_output, root_out_dir)
68 if (is_component_build || is_asan) {
69 data_deps += [ "//build/android:cpplib_stripped" ]
70 }
71 }
72
73 create_native_executable_dist(_dist_target) {
74 testonly = true
75 dist_dir = "$root_out_dir/$target_name"
76 binary = _exec_output
77 deps = [
78 ":$_exec_target",
79 ]
80 if (defined(invoker.extra_dist_files)) {
81 extra_files = invoker.extra_dist_files
82 }
83 }
84 } else {
85 _library_target = "_${target_name}__library"
86 _apk_target = "${target_name}_apk"
87 _apk_specific_vars = [
88 "android_manifest",
agrievec6811b422016-06-23 02:25:0989 "android_manifest_dep",
agrieve62ab00282016-04-05 02:03:4590 "enable_multidex",
huapenglc35ba6e2016-05-25 23:08:0791 "proguard_configs",
92 "proguard_enabled",
agrieve62ab00282016-04-05 02:03:4593 "use_default_launcher",
94 "write_asset_list",
ynovikov389d9e442016-05-27 02:34:5695 "use_native_activity",
agrieve62ab00282016-04-05 02:03:4596 ]
97 shared_library(_library_target) {
98 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
99 configs = [] # Prevent list overwriting warning.
100 configs = invoker.configs
101 testonly = true
102
103 deps = []
jbudorickd29ecfa72016-11-18 22:45:42104 forward_variables_from(
105 invoker,
106 "*",
107 _apk_specific_vars + _wrapper_script_vars + [ "visibility" ])
agrieve62ab00282016-04-05 02:03:45108
109 if (!defined(invoker.use_default_launcher) ||
110 invoker.use_default_launcher) {
111 deps += [ "//testing/android/native_test:native_test_native_code" ]
112 }
113 }
114 unittest_apk(_apk_target) {
115 forward_variables_from(invoker, _apk_specific_vars + [ "deps" ])
agrieve48bd27e2016-06-22 21:04:07116 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45117 apk_name = invoker.target_name
118 if (defined(invoker.output_name)) {
119 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45120 install_script_name = "install_${invoker.output_name}"
121 }
agrieveb355ad152016-04-19 03:45:23122
jcivellif4462a352017-01-10 04:45:59123 # Add the Java classes so that each target does not have to do it.
124 deps += [ "//base/test:test_support_java" ]
125
agrieveb355ad152016-04-19 03:45:23126 # TODO(agrieve): Remove this data_dep once bots don't build the _apk
127 # target (post-GYP).
128 # It's a bit backwards for the apk to depend on the runner script, since
129 # the apk is conceptually a runtime_dep of the script. However, it is
130 # currently necessary because the bots build this _apk target directly
131 # rather than the group() below.
132 data_deps = [
133 ":$_test_runner_target",
134 ]
agrieve62ab00282016-04-05 02:03:45135 }
136
estevensonce844392016-12-15 19:57:57137 _test_runner_target = "${_output_name}__test_runner_script"
138 _incremental_test_name = "${_output_name}_incremental"
agrieve62ab00282016-04-05 02:03:45139 _incremental_test_runner_target =
140 "${_output_name}_incremental__test_runner_script"
estevensonce844392016-12-15 19:57:57141 if (_incremental_apk_only) {
142 _incremental_test_name = _output_name
143 _incremental_test_runner_target = _test_runner_target
144 }
145
146 # Incremental test targets work only for .apks.
agrieve62ab00282016-04-05 02:03:45147 test_runner_script(_incremental_test_runner_target) {
jbudorickd29ecfa72016-11-18 22:45:42148 forward_variables_from(invoker,
149 _wrapper_script_vars + [
150 "data",
151 "data_deps",
152 "deps",
153 "public_deps",
154 ])
agrieve62ab00282016-04-05 02:03:45155 apk_target = ":$_apk_target"
estevensonce844392016-12-15 19:57:57156 test_name = _incremental_test_name
agrieve62ab00282016-04-05 02:03:45157 test_type = "gtest"
158 test_suite = _output_name
159 incremental_install = true
160 }
161 group("${target_name}_incremental") {
162 testonly = true
estevensonce844392016-12-15 19:57:57163 data_deps = [
agrieve62ab00282016-04-05 02:03:45164 ":$_incremental_test_runner_target",
165 ]
166 deps = [
167 ":${_apk_target}_incremental",
168 ]
169 }
170 }
171
estevensonce844392016-12-15 19:57:57172 if (!_incremental_apk_only) {
173 test_runner_script(_test_runner_target) {
174 forward_variables_from(invoker,
175 _wrapper_script_vars + [
176 "data",
177 "data_deps",
178 "deps",
179 "public_deps",
180 ])
agrievee41ae190d2016-04-25 14:12:51181
estevensonce844392016-12-15 19:57:57182 if (_use_raw_android_executable) {
183 executable_dist_dir = "$root_out_dir/$_dist_target"
184 } else {
185 apk_target = ":$_apk_target"
186 }
187 test_name = _output_name
188 test_type = "gtest"
189 test_suite = _output_name
agrieve62ab00282016-04-05 02:03:45190 }
mikecase56d80d72015-06-03 00:57:26191 }
192
qsrfb5251d12015-01-21 15:57:22193 group(target_name) {
194 testonly = true
estevensonce844392016-12-15 19:57:57195 if (_incremental_apk_only) {
196 deps = [
197 ":${target_name}_incremental",
198 ]
agrieve62ab00282016-04-05 02:03:45199 } else {
estevensonce844392016-12-15 19:57:57200 deps = [
201 ":$_test_runner_target",
202 ]
203 if (_use_raw_android_executable) {
204 deps += [ ":$_dist_target" ]
205 } else {
206 deps += [ ":$_apk_target" ]
207 }
agrieve62ab00282016-04-05 02:03:45208 }
agrieve1a02e582015-10-15 21:35:39209 }
jbudoricked0c2082016-02-02 04:30:39210
brettweb7dc6582016-05-24 01:19:43211 # TODO(GYP_GONE): Delete this after we've converted everything to GN.
jbudoricked0c2082016-02-02 04:30:39212 # The _run targets exist only for compatibility w/ GYP.
213 group("${target_name}_apk_run") {
214 testonly = true
215 deps = [
agrieve67855de2016-03-30 14:46:01216 ":${invoker.target_name}",
jbudoricked0c2082016-02-02 04:30:39217 ]
218 }
dpranke2a294622015-08-07 05:23:01219 } else if (is_ios) {
sdefresneeb7eea72017-02-23 17:15:57220 import("//build/config/ios/ios_sdk.gni")
sdefresne012857872016-03-16 10:55:37221 import("//build/config/ios/rules.gni")
222
223 _test_target = target_name
224 _resources_bundle_data = target_name + "_resources_bundle_data"
225
226 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34227 visibility = [ ":$_test_target" ]
sdefresne012857872016-03-16 10:55:37228 sources = [
229 "//testing/gtest_ios/Default.png",
230 ]
231 outputs = [
232 "{{bundle_resources_dir}}/{{source_file_part}}",
233 ]
dpranke2a294622015-08-07 05:23:01234 }
235
sdefresne1a9694422016-04-12 13:53:44236 ios_app_bundle(_test_target) {
dpranke2a294622015-08-07 05:23:01237 testonly = true
sdefresnea828c282016-05-30 18:04:20238
sdefresne9e147e02016-06-07 00:10:13239 # See above call.
240 set_sources_assignment_filter([])
241 forward_variables_from(invoker, "*", [ "testonly" ])
242
243 # Provide sensible defaults in case invoker did not define any of those
244 # required variables.
sdefresne05b97ca2016-06-08 07:19:46245 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13246 info_plist = "//testing/gtest_ios/unittest-Info.plist"
247 }
sdefresne9e147e02016-06-07 00:10:13248
sdefresneeb7eea72017-02-23 17:15:57249 _bundle_id_suffix = ios_generic_test_bundle_id_suffix
250 if (!ios_automatically_manage_certs) {
251 _bundle_id_suffix = "${target_name}"
sdefresneae44722d2016-10-24 13:34:37252 }
sdefresne9e147e02016-06-07 00:10:13253 if (!defined(extra_substitutions)) {
254 extra_substitutions = []
255 }
sdefresneae44722d2016-10-24 13:34:37256 extra_substitutions += [ "GTEST_BUNDLE_ID_SUFFIX=$_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01257
sdefresne012857872016-03-16 10:55:37258 if (!defined(deps)) {
dpranke2a294622015-08-07 05:23:01259 deps = []
260 }
261 deps += [
262 # All shared libraries must have the sanitizer deps to properly link in
263 # asan mode (this target will be empty in other cases).
264 "//build/config/sanitizers:deps",
265 ]
sdefresne047490e2016-07-22 08:49:34266 if (!defined(bundle_deps)) {
267 bundle_deps = []
268 }
269 bundle_deps += [ ":$_resources_bundle_data" ]
dpranke2a294622015-08-07 05:23:01270 }
qsrfb5251d12015-01-21 15:57:22271 } else {
272 executable(target_name) {
agrieve67855de2016-03-30 14:46:01273 deps = []
brettwa0902982015-08-04 19:50:33274 forward_variables_from(invoker, "*")
qsrfb5251d12015-01-21 15:57:22275
276 testonly = true
brettw2e2220c2015-07-21 18:56:35277 deps += [
278 # All shared libraries must have the sanitizer deps to properly link in
279 # asan mode (this target will be empty in other cases).
280 "//build/config/sanitizers:deps",
281
282 # Give tests the default manifest on Windows (a no-op elsewhere).
283 "//build/win:default_exe_manifest",
284 ]
qsrfb5251d12015-01-21 15:57:22285 }
286 }
287}
brettwedb6ecc2016-07-14 23:37:03288
289# Test defaults.
290set_defaults("test") {
291 if (is_android) {
292 configs = default_shared_library_configs
293 } else {
294 configs = default_executable_configs
295 }
296}