blob: aaa8501cabb0b788cde66429d557b3af94ba27a1 [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
9# Define a test as an executable (or apk on Android) with the "testonly" flag
10# set.
11template("test") {
12 if (is_android) {
13 import("//build/config/android/config.gni")
14 import("//build/config/android/rules.gni")
15
16 main_target_name = target_name
17 library_name = "_${target_name}__library"
18 apk_name = "${target_name}_apk"
19
20 shared_library(library_name) {
21 # Configs will always be defined since we set_defaults for a component
22 # in the main config. We want to use those rather than whatever came with
23 # the nested shared/static library inside the component.
24 configs = [] # Prevent list overwriting warning.
25 configs = invoker.configs
26
qsrfb5251d12015-01-21 15:57:2227 testonly = true
28
brettwa0902982015-08-04 19:50:3329 # Don't use "*" to forward all variables since some (like output_name
30 # and isolate_file) apply only to the APK below.
agrieve97176362015-12-01 16:36:1931 deps = []
brettwa0902982015-08-04 19:50:3332 forward_variables_from(invoker,
33 [
34 "all_dependent_configs",
35 "allow_circular_includes_from",
36 "cflags",
37 "cflags_c",
38 "cflags_cc",
39 "check_includes",
40 "data",
41 "data_deps",
42 "datadeps",
43 "defines",
agrieve97176362015-12-01 16:36:1944 "deps",
brettwa0902982015-08-04 19:50:3345 "include_dirs",
46 "ldflags",
47 "lib_dirs",
48 "libs",
49 "output_extension",
50 "output_name",
51 "public",
52 "public_configs",
53 "public_deps",
54 "sources",
55 "visibility",
56 ])
57
pkotwicz93fa232b2015-11-11 17:55:0758 if (!defined(invoker.use_default_launcher) ||
59 invoker.use_default_launcher) {
jbudorick6ab224952015-04-09 21:51:5560 deps += [ "//testing/android/native_test:native_test_native_code" ]
qsrfb5251d12015-01-21 15:57:2261 }
qsrfb5251d12015-01-21 15:57:2262 }
63
64 unittest_apk(apk_name) {
agrievee3f13c3b2015-11-24 16:44:3665 forward_variables_from(invoker,
66 [
67 "android_manifest",
agrieve97176362015-12-01 16:36:1968 "deps",
jbudorick070dd8c42016-01-16 01:21:5169 "enable_multidex",
agrievee3f13c3b2015-11-24 16:44:3670 "use_default_launcher",
71 "write_asset_list",
72 ])
qsrfb5251d12015-01-21 15:57:2273 unittests_dep = ":$library_name"
74 apk_name = main_target_name
75 if (defined(invoker.output_name)) {
mswef55bcf2015-05-06 22:06:5876 apk_name = invoker.output_name
77 unittests_binary = "lib${apk_name}.so"
qsrfb5251d12015-01-21 15:57:2278 }
agrieve97176362015-12-01 16:36:1979 deps += [ ":$library_name" ]
qsrfb5251d12015-01-21 15:57:2280 }
81
agrieve1a02e582015-10-15 21:35:3982 _test_name = main_target_name
mikecase56d80d72015-06-03 00:57:2683 if (defined(invoker.output_name)) {
agrieve1a02e582015-10-15 21:35:3984 _test_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2685 }
agrieve1a02e582015-10-15 21:35:3986 test_runner_script_name = "${_test_name}__test_runner_script"
mikecase56d80d72015-06-03 00:57:2687 test_runner_script(test_runner_script_name) {
agrieve4931af8c2016-02-10 19:25:2688 apk_target = ":$apk_name"
agrieve1a02e582015-10-15 21:35:3989 test_name = _test_name
mikecase56d80d72015-06-03 00:57:2690 test_type = "gtest"
agrieve1a02e582015-10-15 21:35:3991 test_suite = _test_name
92 if (defined(invoker.isolate_file)) {
93 isolate_file = invoker.isolate_file
94 }
95 }
96 incremental_test_runner_script_name =
97 "${_test_name}_incremental__test_runner_script"
98 test_runner_script(incremental_test_runner_script_name) {
agrieve4931af8c2016-02-10 19:25:2699 apk_target = ":$apk_name"
agrieve1a02e582015-10-15 21:35:39100 test_name = "${_test_name}_incremental"
101 test_type = "gtest"
102 test_suite = _test_name
103 incremental_install = true
mikecase56d80d72015-06-03 00:57:26104 if (defined(invoker.isolate_file)) {
105 isolate_file = invoker.isolate_file
106 }
107 }
108
qsrfb5251d12015-01-21 15:57:22109 group(target_name) {
110 testonly = true
mikecase56d80d72015-06-03 00:57:26111 datadeps = [
112 ":$test_runner_script_name",
113 ]
qsrfb5251d12015-01-21 15:57:22114 deps = [
qsrfb5251d12015-01-21 15:57:22115 ":$apk_name",
116 ]
117 }
agrieve1a02e582015-10-15 21:35:39118 group("${target_name}_incremental") {
119 testonly = true
120 datadeps = [
121 ":$incremental_test_runner_script_name",
122 ]
123 deps = [
124 ":${apk_name}_incremental",
125 ]
126 }
jbudoricked0c2082016-02-02 04:30:39127
128 # TODO(GYP): Delete this after we've converted everything to GN.
129 # The _run targets exist only for compatibility w/ GYP.
130 group("${target_name}_apk_run") {
131 testonly = true
132 deps = [
133 ":$main_target_name",
134 ]
135 }
dpranke2a294622015-08-07 05:23:01136 } else if (is_ios) {
sdefresne012857872016-03-16 10:55:37137 import("//build/config/ios/rules.gni")
138
139 _test_target = target_name
140 _resources_bundle_data = target_name + "_resources_bundle_data"
141
142 bundle_data(_resources_bundle_data) {
143 visibility = [ ":$_test_target" ]
144 sources = [
145 "//testing/gtest_ios/Default.png",
146 ]
147 outputs = [
148 "{{bundle_resources_dir}}/{{source_file_part}}",
149 ]
dpranke2a294622015-08-07 05:23:01150 }
151
sdefresne012857872016-03-16 10:55:37152 app(_test_target) {
dpranke2a294622015-08-07 05:23:01153 # TODO(GYP): Make this configurable and only provide a default
154 # that can be overridden.
155 info_plist = "//testing/gtest_ios/unittest-Info.plist"
156 app_name = target_name
157 entitlements_path = "//testing/gtest_ios"
158 code_signing_identity = ""
159 testonly = true
sdefresne012857872016-03-16 10:55:37160 extra_substitutions = [ "BUNDLE_ID_TEST_NAME=$app_name" ]
dpranke2a294622015-08-07 05:23:01161
162 # See above call.
163 set_sources_assignment_filter([])
164
sdefresne012857872016-03-16 10:55:37165 forward_variables_from(invoker, "*")
dpranke2a294622015-08-07 05:23:01166
sdefresne012857872016-03-16 10:55:37167 if (!defined(deps)) {
dpranke2a294622015-08-07 05:23:01168 deps = []
169 }
170 deps += [
171 # All shared libraries must have the sanitizer deps to properly link in
172 # asan mode (this target will be empty in other cases).
173 "//build/config/sanitizers:deps",
174 ]
sdefresne012857872016-03-16 10:55:37175 if (!defined(data_deps)) {
176 data_deps = []
177 }
178 data_deps += [ ":$_resources_bundle_data" ]
dpranke2a294622015-08-07 05:23:01179 }
qsrfb5251d12015-01-21 15:57:22180 } else {
jbudorick3c0ef43092016-02-03 23:40:16181 main_target_name = target_name
182
qsrfb5251d12015-01-21 15:57:22183 executable(target_name) {
brettwa0902982015-08-04 19:50:33184 forward_variables_from(invoker, "*")
qsrfb5251d12015-01-21 15:57:22185
186 testonly = true
187
brettwa0902982015-08-04 19:50:33188 if (!defined(invoker.deps)) {
brettw2e2220c2015-07-21 18:56:35189 deps = []
qsrfb5251d12015-01-21 15:57:22190 }
brettw2e2220c2015-07-21 18:56:35191 deps += [
192 # All shared libraries must have the sanitizer deps to properly link in
193 # asan mode (this target will be empty in other cases).
194 "//build/config/sanitizers:deps",
195
196 # Give tests the default manifest on Windows (a no-op elsewhere).
197 "//build/win:default_exe_manifest",
198 ]
qsrfb5251d12015-01-21 15:57:22199 }
jbudorick3c0ef43092016-02-03 23:40:16200
201 # TODO(GYP): Delete this after we've converted everything to GN.
202 # The _run targets exist only for compatibility with GYP.
203 group("${target_name}_run") {
204 testonly = true
205 deps = [
206 ":$main_target_name",
207 ]
208 }
qsrfb5251d12015-01-21 15:57:22209 }
210}