1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# ==============================================================================
# TEST SETUP
# ==============================================================================
# Define a test as an executable (or apk on Android) with the "testonly" flag
# set.
template("test") {
if (is_android) {
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
main_target_name = target_name
library_name = "_${target_name}__library"
apk_name = "${target_name}_apk"
shared_library(library_name) {
# Configs will always be defined since we set_defaults for a component
# in the main config. We want to use those rather than whatever came with
# the nested shared/static library inside the component.
configs = [] # Prevent list overwriting warning.
configs = invoker.configs
testonly = true
# Don't use "*" to forward all variables since some (like output_name
# and isolate_file) apply only to the APK below.
forward_variables_from(invoker,
[
"all_dependent_configs",
"allow_circular_includes_from",
"cflags",
"cflags_c",
"cflags_cc",
"check_includes",
"data",
"data_deps",
"datadeps",
"defines",
"forward_dependent_configs_from",
"include_dirs",
"ldflags",
"lib_dirs",
"libs",
"output_extension",
"output_name",
"public",
"public_configs",
"public_deps",
"sources",
"visibility",
])
deps = []
if (!defined(invoker.use_launcher) || invoker.use_launcher) {
deps += [ "//testing/android/native_test:native_test_native_code" ]
}
if (defined(invoker.deps)) {
deps += invoker.deps
}
}
unittest_apk(apk_name) {
unittests_dep = ":$library_name"
apk_name = main_target_name
if (defined(invoker.output_name)) {
apk_name = invoker.output_name
unittests_binary = "lib${apk_name}.so"
}
deps = [
":$library_name",
]
if (defined(invoker.apk_deps)) {
deps += invoker.apk_deps
}
if (defined(invoker.apk_asset_location)) {
asset_location = invoker.apk_asset_location
}
}
test_name = main_target_name
if (defined(invoker.output_name)) {
test_name = invoker.output_name
}
test_runner_script_name = "${test_name}__test_runner_script"
test_runner_script(test_runner_script_name) {
test_name = test_name
test_type = "gtest"
test_suite = test_name
if (defined(invoker.isolate_file)) {
isolate_file = invoker.isolate_file
}
}
group(target_name) {
testonly = true
datadeps = [
":$test_runner_script_name",
]
deps = [
":$library_name",
":$apk_name",
]
}
} else if (is_ios) {
if (is_ios) {
import("//build/config/ios/rules.gni")
}
target__sources_name = "${target_name}__sources"
if (defined(invoker.sources)) {
source_set(target__sources_name) {
sources = invoker.sources
testonly = true
configs = [] # Prevent list overwriting warning.
configs += invoker.configs
forward_variables_from(invoker,
[
"cflags",
"cflags_c",
"cflags_cc",
"cflags_objc",
"cflags_objcc",
"data",
"data_deps",
"datadeps",
"defines",
"deps",
"include_dirs",
"includes",
])
}
}
ios_app(target_name) {
# TODO(GYP): Make this configurable and only provide a default
# that can be overridden.
info_plist = "//testing/gtest_ios/unittest-Info.plist"
app_name = target_name
entitlements_path = "//testing/gtest_ios"
code_signing_identity = ""
testonly = true
# See above call.
set_sources_assignment_filter([])
forward_variables_from(invoker,
[
"all_dependent_configs",
"allow_circular_includes_from",
"cflags",
"cflags_c",
"cflags_cc",
"cflags_objc",
"cflags_objcc",
"check_includes",
"forward_dependent_configs_from",
"ldflags",
"libs",
"output_extension",
"output_name",
"public",
"public_configs",
"public_deps",
"visibility",
])
if (defined(invoker.deps)) {
deps = invoker.deps
} else {
deps = []
}
deps += [
# All shared libraries must have the sanitizer deps to properly link in
# asan mode (this target will be empty in other cases).
"//build/config/sanitizers:deps",
]
if (defined(invoker.sources)) {
deps += [ ":${target__sources_name}" ]
}
}
} else {
executable(target_name) {
forward_variables_from(invoker, "*")
testonly = true
if (!defined(invoker.deps)) {
deps = []
}
deps += [
# All shared libraries must have the sanitizer deps to properly link in
# asan mode (this target will be empty in other cases).
"//build/config/sanitizers:deps",
# Give tests the default manifest on Windows (a no-op elsewhere).
"//build/win:default_exe_manifest",
]
}
}
}
|