blob: f9f8c911cabbb039daf240ab6da7b8e16596f60c [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) {
Kevin Marshall184e9092018-02-07 21:09:0616 import("//build/config/chromecast_build.gni")
Scott Graham4c4cdc52017-05-29 20:45:0317 import("//build/config/fuchsia/rules.gni")
Kevin Marshallf35fa5f2018-01-29 19:24:4218 import("//build/config/fuchsia/package.gni")
Scott Graham4c4cdc52017-05-29 20:45:0319}
20
qsrfb5251d12015-01-21 15:57:2221# Define a test as an executable (or apk on Android) with the "testonly" flag
22# set.
agrieve62ab00282016-04-05 02:03:4523# Variable:
24# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:5625# use_native_activity: Test implements ANativeActivity_onCreate().
qsrfb5251d12015-01-21 15:57:2226template("test") {
27 if (is_android) {
agrieve62ab00282016-04-05 02:03:4528 _use_raw_android_executable = defined(invoker.use_raw_android_executable) &&
29 invoker.use_raw_android_executable
qsrfb5251d12015-01-21 15:57:2230
agrieve67855de2016-03-30 14:46:0131 # output_name is used to allow targets with the same name but in different
32 # packages to still produce unique runner scripts.
33 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:2634 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:0135 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2636 }
agrieve62ab00282016-04-05 02:03:4537
agrieveb355ad152016-04-19 03:45:2338 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:4239 _wrapper_script_vars = [
agrievee41ae190d2016-04-25 14:12:5140 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:4241 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:5142 ]
agrieve3ac557f02016-04-12 15:52:0043
jbudorickced2a252016-06-09 16:38:5444 assert(_use_raw_android_executable || enable_java_templates)
45
estevensonce8443922016-12-15 19:57:5746 _incremental_apk_only =
47 incremental_apk_by_default && !_use_raw_android_executable
48
agrieve62ab00282016-04-05 02:03:4549 if (_use_raw_android_executable) {
50 _exec_target = "${target_name}__exec"
51 _dist_target = "${target_name}__dist"
52 _exec_output =
53 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
54
55 executable(_exec_target) {
56 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
57 configs = []
58 data_deps = []
jbudorickd29ecfa72016-11-18 22:45:4259 forward_variables_from(invoker,
60 "*",
61 _wrapper_script_vars + [ "extra_dist_files" ])
agrieve62ab00282016-04-05 02:03:4562 testonly = true
63
64 # Thanks to the set_defaults() for test(), configs are initialized with
65 # the default shared_library configs rather than executable configs.
66 configs -= [
67 "//build/config:shared_library_config",
Yipeng Wang158dbc5c2017-06-30 18:16:4168 "//build/config/android:hide_all_but_jni",
agrieve62ab00282016-04-05 02:03:4569 ]
70 configs += [ "//build/config:executable_config" ]
71
72 # Don't output to the root or else conflict with the group() below.
73 output_name = rebase_path(_exec_output, root_out_dir)
74 if (is_component_build || is_asan) {
75 data_deps += [ "//build/android:cpplib_stripped" ]
76 }
77 }
78
79 create_native_executable_dist(_dist_target) {
80 testonly = true
81 dist_dir = "$root_out_dir/$target_name"
82 binary = _exec_output
83 deps = [
84 ":$_exec_target",
85 ]
86 if (defined(invoker.extra_dist_files)) {
87 extra_files = invoker.extra_dist_files
88 }
89 }
90 } else {
91 _library_target = "_${target_name}__library"
92 _apk_target = "${target_name}_apk"
93 _apk_specific_vars = [
94 "android_manifest",
agrievec6811b422016-06-23 02:25:0995 "android_manifest_dep",
agrieve62ab00282016-04-05 02:03:4596 "enable_multidex",
huapenglc35ba6e2016-05-25 23:08:0797 "proguard_configs",
98 "proguard_enabled",
agrieve62ab00282016-04-05 02:03:4599 "use_default_launcher",
100 "write_asset_list",
ynovikov389d9e442016-05-27 02:34:56101 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45102 ]
103 shared_library(_library_target) {
104 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
105 configs = [] # Prevent list overwriting warning.
106 configs = invoker.configs
107 testonly = true
108
109 deps = []
jbudorickd29ecfa72016-11-18 22:45:42110 forward_variables_from(
111 invoker,
112 "*",
113 _apk_specific_vars + _wrapper_script_vars + [ "visibility" ])
agrieve62ab00282016-04-05 02:03:45114
115 if (!defined(invoker.use_default_launcher) ||
116 invoker.use_default_launcher) {
117 deps += [ "//testing/android/native_test:native_test_native_code" ]
118 }
119 }
120 unittest_apk(_apk_target) {
121 forward_variables_from(invoker, _apk_specific_vars + [ "deps" ])
agrieve48bd27e2016-06-22 21:04:07122 shared_library = ":$_library_target"
agrieve62ab00282016-04-05 02:03:45123 apk_name = invoker.target_name
124 if (defined(invoker.output_name)) {
125 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45126 install_script_name = "install_${invoker.output_name}"
127 }
agrieveb355ad152016-04-19 03:45:23128
jcivellif4462a352017-01-10 04:45:59129 # Add the Java classes so that each target does not have to do it.
130 deps += [ "//base/test:test_support_java" ]
131
agrieveb355ad152016-04-19 03:45:23132 # TODO(agrieve): Remove this data_dep once bots don't build the _apk
133 # target (post-GYP).
134 # It's a bit backwards for the apk to depend on the runner script, since
135 # the apk is conceptually a runtime_dep of the script. However, it is
136 # currently necessary because the bots build this _apk target directly
137 # rather than the group() below.
138 data_deps = [
139 ":$_test_runner_target",
140 ]
agrieve62ab00282016-04-05 02:03:45141 }
142
estevensonce8443922016-12-15 19:57:57143 _test_runner_target = "${_output_name}__test_runner_script"
144 _incremental_test_name = "${_output_name}_incremental"
agrieve62ab00282016-04-05 02:03:45145 _incremental_test_runner_target =
146 "${_output_name}_incremental__test_runner_script"
estevensonce8443922016-12-15 19:57:57147 if (_incremental_apk_only) {
148 _incremental_test_name = _output_name
149 _incremental_test_runner_target = _test_runner_target
150 }
151
152 # Incremental test targets work only for .apks.
agrieve62ab00282016-04-05 02:03:45153 test_runner_script(_incremental_test_runner_target) {
jbudorickd29ecfa72016-11-18 22:45:42154 forward_variables_from(invoker,
155 _wrapper_script_vars + [
156 "data",
157 "data_deps",
158 "deps",
159 "public_deps",
160 ])
agrieve62ab00282016-04-05 02:03:45161 apk_target = ":$_apk_target"
estevensonce8443922016-12-15 19:57:57162 test_name = _incremental_test_name
agrieve62ab00282016-04-05 02:03:45163 test_type = "gtest"
164 test_suite = _output_name
165 incremental_install = true
166 }
167 group("${target_name}_incremental") {
168 testonly = true
estevensonce8443922016-12-15 19:57:57169 data_deps = [
agrieve62ab00282016-04-05 02:03:45170 ":$_incremental_test_runner_target",
171 ]
172 deps = [
173 ":${_apk_target}_incremental",
174 ]
175 }
176 }
177
estevensonce8443922016-12-15 19:57:57178 if (!_incremental_apk_only) {
179 test_runner_script(_test_runner_target) {
180 forward_variables_from(invoker,
181 _wrapper_script_vars + [
182 "data",
183 "data_deps",
184 "deps",
185 "public_deps",
186 ])
agrievee41ae190d2016-04-25 14:12:51187
estevensonce8443922016-12-15 19:57:57188 if (_use_raw_android_executable) {
189 executable_dist_dir = "$root_out_dir/$_dist_target"
190 } else {
191 apk_target = ":$_apk_target"
192 }
193 test_name = _output_name
194 test_type = "gtest"
195 test_suite = _output_name
agrieve62ab00282016-04-05 02:03:45196 }
mikecase56d80d72015-06-03 00:57:26197 }
198
jbudorick686094f62017-05-04 21:52:40199 test_runner_script(target_name) {
200 forward_variables_from(invoker,
201 _wrapper_script_vars + [
202 "data",
203 "data_deps",
204 "deps",
205 "public_deps",
206 ])
207
208 if (_use_raw_android_executable) {
209 executable_dist_dir = "$root_out_dir/$_dist_target"
210 deps += [
211 ":$_dist_target",
estevensonce8443922016-12-15 19:57:57212 ":$_test_runner_target",
213 ]
jbudorick686094f62017-05-04 21:52:40214 } else {
215 apk_target = ":$_apk_target"
216 deps += [ ":$_apk_target" ]
217 if (_incremental_apk_only) {
218 deps += [ ":${target_name}_incremental" ]
estevensonce8443922016-12-15 19:57:57219 } else {
jbudorick686094f62017-05-04 21:52:40220 deps += [ ":$_test_runner_target" ]
estevensonce8443922016-12-15 19:57:57221 }
agrieve62ab00282016-04-05 02:03:45222 }
jbudorick686094f62017-05-04 21:52:40223 generated_script = "$root_build_dir/$_output_name"
224 incremental_install = _incremental_apk_only
225 test_name = _output_name
226 test_suite = _output_name
227 test_type = "gtest"
agrieve1a02e582015-10-15 21:35:39228 }
Scott Graham4c4cdc52017-05-29 20:45:03229 } else if (is_fuchsia) {
230 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42231 _pkg_target = "${_output_name}_pkg"
232 _gen_runner_target = "${_output_name}_runner"
233 _exec_target = "${_output_name}__exec"
Scott Graham4c4cdc52017-05-29 20:45:03234
Kevin Marshallf35fa5f2018-01-29 19:24:42235 group(target_name) {
236 testonly = true
237 deps = [
238 ":$_gen_runner_target",
239 ":$_pkg_target",
240 ]
Kevin Marshall184e9092018-02-07 21:09:06241
242 # Disable packaging for Chromecast builds. (https://crbug.com/810069)
243 if (is_chromecast) {
244 deps -= [ ":${_pkg_target}" ]
245 }
Kevin Marshallb2b018c2018-01-23 18:40:17246 }
247
Kevin Marshallf35fa5f2018-01-29 19:24:42248 # Makes the script which invokes the executable.
249 test_runner_script(_gen_runner_target) {
250 forward_variables_from(invoker, [ "use_test_server" ])
251 deps = [
252 ":$_exec_target",
253 ]
254 test_name = _output_name
Kevin Marshall3d0153fb2018-01-31 22:25:53255 exe_path =
256 "$root_out_dir/exe.unstripped/" + get_label_info(_exec_target, "name")
Kevin Marshallc4ec08a2018-01-31 04:30:40257 package_name = _output_name
Kevin Marshallf35fa5f2018-01-29 19:24:42258 }
259
260 executable(_exec_target) {
Scott Graham4c4cdc52017-05-29 20:45:03261 testonly = true
262 forward_variables_from(invoker, "*")
Kevin Marshallf35fa5f2018-01-29 19:24:42263 output_name = _exec_target
Scott Graham05c7a3f22017-08-02 01:57:55264 deps += [ "//build/config:exe_and_shlib_deps" ]
Scott Graham4c4cdc52017-05-29 20:45:03265 }
Kevin Marshallf35fa5f2018-01-29 19:24:42266
267 package(_pkg_target) {
268 testonly = true
269 package_name = _output_name
270 binary = get_label_info(_exec_target, "name")
271 deps = [
272 ":$_exec_target",
273 ]
274 }
dpranke2a294622015-08-07 05:23:01275 } else if (is_ios) {
sdefresneeb7eea72017-02-23 17:15:57276 import("//build/config/ios/ios_sdk.gni")
sdefresne012857872016-03-16 10:55:37277 import("//build/config/ios/rules.gni")
278
279 _test_target = target_name
280 _resources_bundle_data = target_name + "_resources_bundle_data"
281
282 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34283 visibility = [ ":$_test_target" ]
sdefresne012857872016-03-16 10:55:37284 sources = [
285 "//testing/gtest_ios/Default.png",
286 ]
287 outputs = [
288 "{{bundle_resources_dir}}/{{source_file_part}}",
289 ]
dpranke2a294622015-08-07 05:23:01290 }
291
sdefresne1a9694422016-04-12 13:53:44292 ios_app_bundle(_test_target) {
dpranke2a294622015-08-07 05:23:01293 testonly = true
sdefresnea828c282016-05-30 18:04:20294
sdefresne9e147e02016-06-07 00:10:13295 # See above call.
296 set_sources_assignment_filter([])
297 forward_variables_from(invoker, "*", [ "testonly" ])
298
299 # Provide sensible defaults in case invoker did not define any of those
300 # required variables.
sdefresne05b97ca2016-06-08 07:19:46301 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13302 info_plist = "//testing/gtest_ios/unittest-Info.plist"
303 }
sdefresne9e147e02016-06-07 00:10:13304
sdefresneeb7eea72017-02-23 17:15:57305 _bundle_id_suffix = ios_generic_test_bundle_id_suffix
306 if (!ios_automatically_manage_certs) {
307 _bundle_id_suffix = "${target_name}"
sdefresneae44722d2016-10-24 13:34:37308 }
sdefresne9e147e02016-06-07 00:10:13309 if (!defined(extra_substitutions)) {
310 extra_substitutions = []
311 }
sdefresneae44722d2016-10-24 13:34:37312 extra_substitutions += [ "GTEST_BUNDLE_ID_SUFFIX=$_bundle_id_suffix" ]
dpranke2a294622015-08-07 05:23:01313
sdefresne012857872016-03-16 10:55:37314 if (!defined(deps)) {
dpranke2a294622015-08-07 05:23:01315 deps = []
316 }
317 deps += [
318 # All shared libraries must have the sanitizer deps to properly link in
319 # asan mode (this target will be empty in other cases).
thomasanderson84fa8b02017-05-18 23:38:47320 "//build/config:exe_and_shlib_deps",
dpranke2a294622015-08-07 05:23:01321 ]
sdefresne047490e2016-07-22 08:49:34322 if (!defined(bundle_deps)) {
323 bundle_deps = []
324 }
325 bundle_deps += [ ":$_resources_bundle_data" ]
dpranke2a294622015-08-07 05:23:01326 }
qsrfb5251d12015-01-21 15:57:22327 } else {
328 executable(target_name) {
agrieve67855de2016-03-30 14:46:01329 deps = []
brettwa0902982015-08-04 19:50:33330 forward_variables_from(invoker, "*")
qsrfb5251d12015-01-21 15:57:22331
332 testonly = true
brettw2e2220c2015-07-21 18:56:35333 deps += [
334 # All shared libraries must have the sanitizer deps to properly link in
335 # asan mode (this target will be empty in other cases).
thomasanderson84fa8b02017-05-18 23:38:47336 "//build/config:exe_and_shlib_deps",
brettw2e2220c2015-07-21 18:56:35337
338 # Give tests the default manifest on Windows (a no-op elsewhere).
339 "//build/win:default_exe_manifest",
340 ]
qsrfb5251d12015-01-21 15:57:22341 }
342 }
343}
brettwedb6ecc2016-07-14 23:37:03344
345# Test defaults.
346set_defaults("test") {
347 if (is_android) {
348 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:41349 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
350 configs += [ "//build/config/android:hide_all_but_jni" ]
brettwedb6ecc2016-07-14 23:37:03351 } else {
352 configs = default_executable_configs
353 }
354}