blob: f50f332cf1bfbd7e2431e5278065a7d131d33606 [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
Scott Graham4c4cdc52017-05-29 20:45:0315if (is_fuchsia) {
16 import("//build/config/fuchsia/rules.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4217 import("//build/config/fuchsia/package.gni")
Scott Graham4c4cdc52017-05-29 20:45:0318}
19
qsrfb5251d12015-01-21 15:57:2220# Define a test as an executable (or apk on Android) with the "testonly" flag
21# set.
agrieve62ab00282016-04-05 02:03:4522# Variable:
23# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:5624# use_native_activity: Test implements ANativeActivity_onCreate().
qsrfb5251d12015-01-21 15:57:2225template("test") {
26 if (is_android) {
agrieve62ab00282016-04-05 02:03:4527 _use_raw_android_executable = defined(invoker.use_raw_android_executable) &&
28 invoker.use_raw_android_executable
qsrfb5251d12015-01-21 15:57:2229
agrieve67855de2016-03-30 14:46:0130 # output_name is used to allow targets with the same name but in different
31 # packages to still produce unique runner scripts.
32 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2633 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0134 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2635 }
agrieve62ab00282016-04-05 02:03:4536
agrieveb355ad152016-04-19 03:45:2337 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4238 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:5139 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4240 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:5141 ]
agrieve3ac557f02016-04-12 15:52:0042
jbudorickced2a252016-06-09 16:38:5443 assert(_use_raw_android_executable || enable_java_templates)
44
estevensonce8443922016-12-15 19:57:5745 _incremental_apk_only =
46 incremental_apk_by_default && !_use_raw_android_executable
47
agrieve62ab00282016-04-05 02:03:4548 if (_use_raw_android_executable) {
49 _exec_target = "${target_name}__exec"
50 _dist_target = "${target_name}__dist"
51 _exec_output =
52 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
53
54 executable(_exec_target) {
55 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
56 configs = []
57 data_deps = []
jbudorickd29ecfa72016-11-18 22:45:4258 forward_variables_from(invoker,
59 "*",
60 _wrapper_script_vars + [ "extra_dist_files" ])
agrieve62ab00282016-04-05 02:03:4561 testonly = true
62
63 # Thanks to the set_defaults() for test(), configs are initialized with
64 # the default shared_library configs rather than executable configs.
65 configs -= [
66 "//build/config:shared_library_config",
Yipeng Wang158dbc5c2017-06-30 18:16:4167 "//build/config/android:hide_all_but_jni",
agrieve62ab00282016-04-05 02:03:4568 ]
69 configs += [ "//build/config:executable_config" ]
70
71 # Don't output to the root or else conflict with the group() below.
72 output_name = rebase_path(_exec_output, root_out_dir)
73 if (is_component_build || is_asan) {
74 data_deps += [ "//build/android:cpplib_stripped" ]
75 }
76 }
77
78 create_native_executable_dist(_dist_target) {
79 testonly = true
80 dist_dir = "$root_out_dir/$target_name"
81 binary = _exec_output
82 deps = [
83 ":$_exec_target",
84 ]
85 if (defined(invoker.extra_dist_files)) {
86 extra_files = invoker.extra_dist_files
87 }
88 }
89 } else {
90 _library_target = "_${target_name}__library"
91 _apk_target = "${target_name}_apk"
92 _apk_specific_vars = [
93 "android_manifest",
agrievec6811b422016-06-23 02:25:0994 "android_manifest_dep",
agrieve62ab00282016-04-05 02:03:4595 "enable_multidex",
huapenglc35ba6e2016-05-25 23:08:0796 "proguard_configs",
97 "proguard_enabled",
agrieve62ab00282016-04-05 02:03:4598 "use_default_launcher",
99 "write_asset_list",
ynovikov389d9e442016-05-27 02:34:56100 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45101 ]
102 shared_library(_library_target) {
103 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
104 configs = [] # Prevent list overwriting warning.
105 configs = invoker.configs
106 testonly = true
107
108 deps = []
jbudorickd29ecfa72016-11-18 22:45:42109 forward_variables_from(
110 invoker,
111 "*",
112 _apk_specific_vars + _wrapper_script_vars + [ "visibility" ])
agrieve62ab00282016-04-05 02:03:45113
114 if (!defined(invoker.use_default_launcher) ||
115 invoker.use_default_launcher) {
116 deps += [ "//testing/android/native_test:native_test_native_code" ]
117 }
118 }
119 unittest_apk(_apk_target) {
120 forward_variables_from(invoker, _apk_specific_vars + [ "deps" ])
agrieve48bd27e2016-06-22 21:04:07121 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45122 apk_name = invoker.target_name
123 if (defined(invoker.output_name)) {
124 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45125 install_script_name = "install_${invoker.output_name}"
126 }
agrieveb355ad152016-04-19 03:45:23127
jcivellif4462a352017-01-10 04:45:59128 # Add the Java classes so that each target does not have to do it.
129 deps += [ "//base/test:test_support_java" ]
130
agrieveb355ad152016-04-19 03:45:23131 # TODO(agrieve): Remove this data_dep once bots don't build the _apk
132 # target (post-GYP).
133 # It's a bit backwards for the apk to depend on the runner script, since
134 # the apk is conceptually a runtime_dep of the script. However, it is
135 # currently necessary because the bots build this _apk target directly
136 # rather than the group() below.
137 data_deps = [
138 ":$_test_runner_target",
139 ]
agrieve62ab00282016-04-05 02:03:45140 }
141
estevensonce8443922016-12-15 19:57:57142 _test_runner_target = "${_output_name}__test_runner_script"
143 _incremental_test_name = "${_output_name}_incremental"
agrieve62ab00282016-04-05 02:03:45144 _incremental_test_runner_target =
145 "${_output_name}_incremental__test_runner_script"
estevensonce8443922016-12-15 19:57:57146 if (_incremental_apk_only) {
147 _incremental_test_name = _output_name
148 _incremental_test_runner_target = _test_runner_target
149 }
150
151 # Incremental test targets work only for .apks.
agrieve62ab00282016-04-05 02:03:45152 test_runner_script(_incremental_test_runner_target) {
jbudorickd29ecfa72016-11-18 22:45:42153 forward_variables_from(invoker,
154 _wrapper_script_vars + [
155 "data",
156 "data_deps",
157 "deps",
158 "public_deps",
159 ])
agrieve62ab00282016-04-05 02:03:45160 apk_target = ":$_apk_target"
estevensonce8443922016-12-15 19:57:57161 test_name = _incremental_test_name
agrieve62ab00282016-04-05 02:03:45162 test_type = "gtest"
163 test_suite = _output_name
164 incremental_install = true
165 }
166 group("${target_name}_incremental") {
167 testonly = true
estevensonce8443922016-12-15 19:57:57168 data_deps = [
agrieve62ab00282016-04-05 02:03:45169 ":$_incremental_test_runner_target",
170 ]
171 deps = [
172 ":${_apk_target}_incremental",
173 ]
174 }
175 }
176
estevensonce8443922016-12-15 19:57:57177 if (!_incremental_apk_only) {
178 test_runner_script(_test_runner_target) {
179 forward_variables_from(invoker,
180 _wrapper_script_vars + [
181 "data",
182 "data_deps",
183 "deps",
184 "public_deps",
185 ])
agrievee41ae190d2016-04-25 14:12:51186
estevensonce8443922016-12-15 19:57:57187 if (_use_raw_android_executable) {
188 executable_dist_dir = "$root_out_dir/$_dist_target"
189 } else {
190 apk_target = ":$_apk_target"
191 }
192 test_name = _output_name
193 test_type = "gtest"
194 test_suite = _output_name
agrieve62ab00282016-04-05 02:03:45195 }
mikecase56d80d72015-06-03 00:57:26196 }
197
jbudorick686094f62017-05-04 21:52:40198 test_runner_script(target_name) {
199 forward_variables_from(invoker,
200 _wrapper_script_vars + [
201 "data",
202 "data_deps",
203 "deps",
204 "public_deps",
205 ])
206
207 if (_use_raw_android_executable) {
208 executable_dist_dir = "$root_out_dir/$_dist_target"
209 deps += [
210 ":$_dist_target",
estevensonce8443922016-12-15 19:57:57211 ":$_test_runner_target",
212 ]
jbudorick686094f62017-05-04 21:52:40213 } else {
214 apk_target = ":$_apk_target"
215 deps += [ ":$_apk_target" ]
216 if (_incremental_apk_only) {
217 deps += [ ":${target_name}_incremental" ]
estevensonce8443922016-12-15 19:57:57218 } else {
jbudorick686094f62017-05-04 21:52:40219 deps += [ ":$_test_runner_target" ]
estevensonce8443922016-12-15 19:57:57220 }
agrieve62ab00282016-04-05 02:03:45221 }
jbudorick686094f62017-05-04 21:52:40222 generated_script = "$root_build_dir/$_output_name"
223 incremental_install = _incremental_apk_only
224 test_name = _output_name
225 test_suite = _output_name
226 test_type = "gtest"
agrieve1a02e582015-10-15 21:35:39227 }
Scott Graham4c4cdc52017-05-29 20:45:03228 } else if (is_fuchsia) {
229 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42230 _pkg_target = "${_output_name}_pkg"
231 _gen_runner_target = "${_output_name}_runner"
232 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03233
Kevin Marshallf35fa5f2018-01-29 19:24:42234 group(target_name) {
235 testonly = true
236 deps = [
237 ":$_gen_runner_target",
238 ":$_pkg_target",
239 ]
Kevin Marshallb2b018c2018-01-23 18:40:17240 }
241
Kevin Marshallf35fa5f2018-01-29 19:24:42242 # Makes the script which invokes the executable.
243 test_runner_script(_gen_runner_target) {
244 forward_variables_from(invoker, [ "use_test_server" ])
245 deps = [
246 ":$_exec_target",
247 ]
248 test_name = _output_name
249 exe_path = "$root_out_dir/" + get_label_info(_exec_target, "name")
Kevin Marshallc4ec08a2018-01-31 04:30:40250 package_name = _output_name
Kevin Marshallf35fa5f2018-01-29 19:24:42251 }
252
253 executable(_exec_target) {
Scott Graham4c4cdc52017-05-29 20:45:03254 testonly = true
255 forward_variables_from(invoker, "*")
Kevin Marshallf35fa5f2018-01-29 19:24:42256 output_name = _exec_target
Scott Graham05c7a3f22017-08-02 01:57:55257 deps += [ "//build/config:exe_and_shlib_deps" ]
Scott Graham4c4cdc52017-05-29 20:45:03258 }
Kevin Marshallf35fa5f2018-01-29 19:24:42259
260 package(_pkg_target) {
261 testonly = true
262 package_name = _output_name
263 binary = get_label_info(_exec_target, "name")
264 deps = [
265 ":$_exec_target",
266 ]
267 }
dpranke2a294622015-08-07 05:23:01268 } else if (is_ios) {
sdefresneeb7eea72017-02-23 17:15:57269 import("//build/config/ios/ios_sdk.gni")
sdefresne012857872016-03-16 10:55:37270 import("//build/config/ios/rules.gni")
271
272 _test_target = target_name
273 _resources_bundle_data = target_name + "_resources_bundle_data"
274
275 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34276 visibility = [ ":$_test_target" ]
sdefresne012857872016-03-16 10:55:37277 sources = [
278 "//testing/gtest_ios/Default.png",
279 ]
280 outputs = [
281 "{{bundle_resources_dir}}/{{source_file_part}}",
282 ]
dpranke2a294622015-08-07 05:23:01283 }
284
sdefresne1a9694422016-04-12 13:53:44285 ios_app_bundle(_test_target) {
dpranke2a294622015-08-07 05:23:01286 testonly = true
sdefresnea828c282016-05-30 18:04:20287
sdefresne9e147e02016-06-07 00:10:13288 # See above call.
289 set_sources_assignment_filter([])
290 forward_variables_from(invoker, "*", [ "testonly" ])
291
292 # Provide sensible defaults in case invoker did not define any of those
293 # required variables.
sdefresne05b97ca2016-06-08 07:19:46294 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13295 info_plist = "//testing/gtest_ios/unittest-Info.plist"
296 }
sdefresne9e147e02016-06-07 00:10:13297
sdefresneeb7eea72017-02-23 17:15:57298 _bundle_id_suffix = ios_generic_test_bundle_id_suffix
299 if (!ios_automatically_manage_certs) {
300 _bundle_id_suffix = "${target_name}"
sdefresneae44722d2016-10-24 13:34:37301 }
sdefresne9e147e02016-06-07 00:10:13302 if (!defined(extra_substitutions)) {
303 extra_substitutions = []
304 }
sdefresneae44722d2016-10-24 13:34:37305 extra_substitutions += [ "GTEST_BUNDLE_ID_SUFFIX=$_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01306
sdefresne012857872016-03-16 10:55:37307 if (!defined(deps)) {
dpranke2a294622015-08-07 05:23:01308 deps = []
309 }
310 deps += [
311 # All shared libraries must have the sanitizer deps to properly link in
312 # asan mode (this target will be empty in other cases).
thomasanderson84fa8b02017-05-18 23:38:47313 "//build/config:exe_and_shlib_deps",
dpranke2a294622015-08-07 05:23:01314 ]
sdefresne047490e2016-07-22 08:49:34315 if (!defined(bundle_deps)) {
316 bundle_deps = []
317 }
318 bundle_deps += [ ":$_resources_bundle_data" ]
dpranke2a294622015-08-07 05:23:01319 }
qsrfb5251d12015-01-21 15:57:22320 } else {
321 executable(target_name) {
agrieve67855de2016-03-30 14:46:01322 deps = []
brettwa0902982015-08-04 19:50:33323 forward_variables_from(invoker, "*")
qsrfb5251d12015-01-21 15:57:22324
325 testonly = true
brettw2e2220c2015-07-21 18:56:35326 deps += [
327 # All shared libraries must have the sanitizer deps to properly link in
328 # asan mode (this target will be empty in other cases).
thomasanderson84fa8b02017-05-18 23:38:47329 "//build/config:exe_and_shlib_deps",
brettw2e2220c2015-07-21 18:56:35330
331 # Give tests the default manifest on Windows (a no-op elsewhere).
332 "//build/win:default_exe_manifest",
333 ]
qsrfb5251d12015-01-21 15:57:22334 }
335 }
336}
brettwedb6ecc2016-07-14 23:37:03337
338# Test defaults.
339set_defaults("test") {
340 if (is_android) {
341 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41342 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
343 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03344 } else {
345 configs = default_executable_configs
346 }
347}