[go: nahoru, domu]

blob: 150c0d86b1204a7f7faecd58f104e545e7e452dc [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.
31 forward_variables_from(invoker,
32 [
33 "all_dependent_configs",
34 "allow_circular_includes_from",
35 "cflags",
36 "cflags_c",
37 "cflags_cc",
38 "check_includes",
39 "data",
40 "data_deps",
41 "datadeps",
42 "defines",
brettwa0902982015-08-04 19:50:3343 "include_dirs",
44 "ldflags",
45 "lib_dirs",
46 "libs",
47 "output_extension",
48 "output_name",
49 "public",
50 "public_configs",
51 "public_deps",
52 "sources",
53 "visibility",
54 ])
55
qsrfb5251d12015-01-21 15:57:2256 deps = []
57 if (!defined(invoker.use_launcher) || invoker.use_launcher) {
jbudorick6ab224952015-04-09 21:51:5558 deps += [ "//testing/android/native_test:native_test_native_code" ]
qsrfb5251d12015-01-21 15:57:2259 }
60 if (defined(invoker.deps)) {
61 deps += invoker.deps
qsrfb5251d12015-01-21 15:57:2262 }
63 }
64
65 unittest_apk(apk_name) {
66 unittests_dep = ":$library_name"
67 apk_name = main_target_name
68 if (defined(invoker.output_name)) {
mswef55bcf2015-05-06 22:06:5869 apk_name = invoker.output_name
70 unittests_binary = "lib${apk_name}.so"
qsrfb5251d12015-01-21 15:57:2271 }
72 deps = [
73 ":$library_name",
74 ]
75 if (defined(invoker.apk_deps)) {
76 deps += invoker.apk_deps
77 }
Benjamin Lerman45c02272015-01-22 10:05:0478 if (defined(invoker.apk_asset_location)) {
79 asset_location = invoker.apk_asset_location
80 }
qsrfb5251d12015-01-21 15:57:2281 }
82
agrieve1a02e582015-10-15 21:35:3983 _test_name = main_target_name
mikecase56d80d72015-06-03 00:57:2684 if (defined(invoker.output_name)) {
agrieve1a02e582015-10-15 21:35:3985 _test_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:2686 }
agrieve1a02e582015-10-15 21:35:3987 test_runner_script_name = "${_test_name}__test_runner_script"
mikecase56d80d72015-06-03 00:57:2688 test_runner_script(test_runner_script_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) {
99 test_name = "${_test_name}_incremental"
100 test_type = "gtest"
101 test_suite = _test_name
102 incremental_install = true
mikecase56d80d72015-06-03 00:57:26103 if (defined(invoker.isolate_file)) {
104 isolate_file = invoker.isolate_file
105 }
106 }
107
qsrfb5251d12015-01-21 15:57:22108 group(target_name) {
109 testonly = true
mikecase56d80d72015-06-03 00:57:26110 datadeps = [
111 ":$test_runner_script_name",
112 ]
qsrfb5251d12015-01-21 15:57:22113 deps = [
qsrfb5251d12015-01-21 15:57:22114 ":$apk_name",
115 ]
116 }
agrieve1a02e582015-10-15 21:35:39117 group("${target_name}_incremental") {
118 testonly = true
119 datadeps = [
120 ":$incremental_test_runner_script_name",
121 ]
122 deps = [
123 ":${apk_name}_incremental",
124 ]
125 }
dpranke2a294622015-08-07 05:23:01126 } else if (is_ios) {
127 if (is_ios) {
128 import("//build/config/ios/rules.gni")
129 }
130
dpranke2a294622015-08-07 05:23:01131 ios_app(target_name) {
132 # TODO(GYP): Make this configurable and only provide a default
133 # that can be overridden.
134 info_plist = "//testing/gtest_ios/unittest-Info.plist"
135 app_name = target_name
136 entitlements_path = "//testing/gtest_ios"
137 code_signing_identity = ""
138 testonly = true
139
140 # See above call.
141 set_sources_assignment_filter([])
142
143 forward_variables_from(invoker,
144 [
145 "all_dependent_configs",
146 "allow_circular_includes_from",
147 "cflags",
148 "cflags_c",
149 "cflags_cc",
150 "cflags_objc",
151 "cflags_objcc",
152 "check_includes",
dpranke4bcc95b2015-09-10 22:37:25153 "configs",
154 "data",
155 "data_deps",
156 "defines",
dpranke4bcc95b2015-09-10 22:37:25157 "include_dirs",
dpranke2a294622015-08-07 05:23:01158 "ldflags",
159 "libs",
160 "output_extension",
161 "output_name",
162 "public",
163 "public_configs",
164 "public_deps",
dpranke4bcc95b2015-09-10 22:37:25165 "sources",
dpranke2a294622015-08-07 05:23:01166 "visibility",
167 ])
168
169 if (defined(invoker.deps)) {
170 deps = invoker.deps
171 } else {
172 deps = []
173 }
174 deps += [
175 # All shared libraries must have the sanitizer deps to properly link in
176 # asan mode (this target will be empty in other cases).
177 "//build/config/sanitizers:deps",
178 ]
dpranke2a294622015-08-07 05:23:01179 }
qsrfb5251d12015-01-21 15:57:22180 } else {
181 executable(target_name) {
brettwa0902982015-08-04 19:50:33182 forward_variables_from(invoker, "*")
qsrfb5251d12015-01-21 15:57:22183
184 testonly = true
185
brettwa0902982015-08-04 19:50:33186 if (!defined(invoker.deps)) {
brettw2e2220c2015-07-21 18:56:35187 deps = []
qsrfb5251d12015-01-21 15:57:22188 }
brettw2e2220c2015-07-21 18:56:35189 deps += [
190 # All shared libraries must have the sanitizer deps to properly link in
191 # asan mode (this target will be empty in other cases).
192 "//build/config/sanitizers:deps",
193
194 # Give tests the default manifest on Windows (a no-op elsewhere).
195 "//build/win:default_exe_manifest",
196 ]
qsrfb5251d12015-01-21 15:57:22197 }
198 }
199}