-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathchip_test_suite.gni
369 lines (317 loc) · 11.3 KB
/
chip_test_suite.gni
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
enable_efr32_build_per_testsource = true #++++ TODO: Figure out how to enable things based on `chip_device_platform == "efr32"` which is not currently in scope.
import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
if (enable_efr32_build_per_testsource) {
import("//build_overrides/efr32_sdk.gni") # Defines efr32_sdk_build_root
import("//build_overrides/nlunit_test.gni") # Defines nlunit_test_root
}
import("${chip_root}/build/chip/chip_test.gni")
import("${chip_root}/build/chip/tests.gni")
import("${dir_pw_unit_test}/test.gni")
if (enable_efr32_build_per_testsource) {
import("${efr32_sdk_build_root}/efr32_sdk.gni")
import("${efr32_sdk_build_root}/silabs_executable.gni")
#import("$dir_pw_protobuf_compiler/proto.gni")
#++++ TODO: Figure out how to get access to these variables from src/test_driver/efr32/BUILD.gn so we don't have to set them explicitly here.
examples_plat_dir = "${chip_root}/examples/platform/silabs/efr32"
examples_common_plat_dir = "${chip_root}/examples/platform/silabs"
#efr32_project_dir = "${chip_root}/src/test_driver/efr32"
}
assert(chip_build_tests)
# Define CHIP unit tests
#
# Simple usage
# chip_test_suite("tests") {
# output_name = "libFooTests"
#
# sources = [
# "Common.h", # add common sources here
# "Common.cpp",
# ]
#
# test_sources = [
# "TestFoo.cpp", # Files are parsed for `CHIP_REGISTER_TEST_SUITE(...)`
# "TestBar.cpp", # and a driver is created automatically
# ]
#
# public_deps = [
# "${chip_root}/src/lib/foo", # add dependencies here
# ]
# }
#
#
# Deprecated usage (writing own driver files):
#
# chip_test_suite("tests") {
# output_name = "libFooTests"
#
# sources = [
# "TestDeclarations.h",
# "TestFoo.cpp",
# "TestBar.cpp",
# ]
#
# public_deps = [
# "${chip_root}/src/lib/foo", # add dependencies here
# ]
#
# tests = [
# "TestFoo", # Assumes TestFooDriver.cpp exists
# "TestBar", # Assumes TestBarDriver.cpp exists
# ]
# }
#
template("chip_test_suite") {
_suite_name = target_name
# Ensures that the common library has sources containing both common
# and individual unit tests.
if (!defined(invoker.sources)) {
invoker.sources = []
}
if (defined(invoker.test_sources)) {
invoker.sources += invoker.test_sources
}
if (chip_build_test_static_libraries) {
_target_type = "static_library"
} else {
_target_type = "source_set"
}
target(_target_type, "${_suite_name}.lib") {
forward_variables_from(invoker, "*", [ "tests" ])
output_dir = "${root_out_dir}/lib"
if (!defined(invoker.public_deps)) {
public_deps = []
}
deps = [ dir_pw_unit_test ]
if (current_os != "zephyr" && current_os != "mbed") {
# Depend on stdio logging, and have it take precedence over the default platform backend
public_deps += [ "${chip_root}/src/platform/logging:force_stdio" ]
}
}
if (chip_link_tests || enable_efr32_build_per_testsource) { #++++ Temporary workaround rather than changing `chip_link_tests` and `chip_build_tests` in `tests.gni`
tests = []
if (defined(invoker.test_sources)) {
foreach(_test, invoker.test_sources) {
_test_name = string_replace(_test, ".cpp", "")
_test_output_dir = "${root_out_dir}/tests"
if (defined(invoker.output_dir)) {
_test_output_dir = invoker.output_dir
}
if (enable_efr32_build_per_testsource) {
# Since target_name is usually "tests", we need a unique name to use in the executable target.
if (defined(invoker.output_name)) {
# Get it from the suite's output_name.
_unique_suite_name = invoker.output_name
} else {
# Some test suites don't have output_name defined. Use the first source file.
_unique_suite_name = string_replace(string_join("-", invoker.test_sources), ".cpp", "")
}
silabs_executable("efr32_device_tests--${_unique_suite_name}--${_test_name}") {
output_name = "matter-silabs-device_tests--${_unique_suite_name}--${_test_name}.out"
defines = [ "PW_RPC_ENABLED" ]
sources = [
"${chip_root}/examples/common/pigweed/RpcService.cpp",
"${chip_root}/examples/common/pigweed/efr32/PigweedLoggerMutex.cpp",
"${chip_root}/src/test_driver/efr32/src/main.cpp", #++++ replace absolute path
"${examples_common_plat_dir}/PigweedLogger.cpp",
"${examples_common_plat_dir}/heap_4_silabs.c",
"${examples_common_plat_dir}/syscalls_stubs.cpp",
"${examples_plat_dir}/uart.cpp",
]
deps = [
#++++ DEBUG: Disabled code that was used for testing an alternative implementaiton.
# "${chip_root}/src/test_driver/efr32:nl_test_service.nanopb_rpc", #++++ replace absolute path
# "${chip_root}/src/test_driver/efr32:sdk", #++++ replace absolute path
#":nl_test_service--${_unique_suite_name}--${_test_name}.nanopb_rpc",
#":sdk--${_unique_suite_name}--${_test_name}",
"$dir_pw_unit_test:rpc_service",
"${chip_root}/config/efr32/lib/pw_rpc:pw_rpc",
"${chip_root}/examples/common/pigweed:system_rpc_server",
"${chip_root}/src/lib",
"${chip_root}/src/lib/support:pw_tests_wrapper",
"${chip_root}/src/lib/support:testing_nlunit",
"${examples_common_plat_dir}/pw_sys_io:pw_sys_io_silabs",
"${nlunit_test_root}:nlunit-test",
]
# OpenThread Settings
if (chip_enable_openthread) {
deps += [
"${chip_root}/third_party/openthread:openthread",
"${chip_root}/third_party/openthread:openthread-platform",
"${examples_plat_dir}:efr-matter-shell",
]
}
# Attestation Credentials
deps += [ "${examples_plat_dir}:efr32-attestation-credentials" ]
# Factory Data Provider
if (use_efr32_factory_data_provider) {
deps += [ "${examples_plat_dir}:silabs-factory-data-provider" ]
}
deps += pw_build_LINK_DEPS
include_dirs = [ "${chip_root}/examples/common/pigweed/efr32" ]
ldscript = "${examples_common_plat_dir}/ldscripts/${silabs_family}.ld"
inputs = [ ldscript ]
ldflags = [
"-T" + rebase_path(ldscript, root_build_dir),
"-Wl,--no-warn-rwx-segment",
]
output_dir = root_out_dir
}
}
pw_test(_test_name) {
forward_variables_from(invoker,
[
"deps",
"public_deps",
"cflags",
"configs",
])
public_deps += [ ":${_suite_name}.lib" ]
sources = [ _test ]
output_dir = _test_output_dir
if (enable_efr32_build_per_testsource) {
deps = [ ":efr32_device_tests--${_unique_suite_name}--${_test_name}" ]
}
}
tests += [ _test_name ]
}
}
if (defined(invoker.tests)) {
foreach(_test, invoker.tests) {
_test_output_dir = "${root_out_dir}/tests"
if (defined(invoker.output_dir)) {
_test_output_dir = invoker.output_dir
}
pw_test(_test) {
forward_variables_from(invoker,
[
"deps",
"public_deps",
"cflags",
"configs",
])
public_deps += [ ":${_suite_name}.lib" ]
test_main = ""
sources = [
"${_test}.cpp",
"${_test}Driver.cpp",
]
output_dir = _test_output_dir
}
tests += [ _test ]
}
}
group(_suite_name) {
deps = []
foreach(_test, tests) {
deps += [ ":${_test}" ]
}
}
if (chip_pw_run_tests) {
group("${_suite_name}_run") {
deps = []
foreach(_test, tests) {
deps += [ ":${_test}.run" ]
}
}
}
} else {
group(_suite_name) {
deps = [ ":${_suite_name}.lib" ]
}
}
}
# TODO [PW_MIGRATION]: remove this once transition away from nlunit-test is completed
template("chip_test_suite_using_nltest") {
_suite_name = target_name
# Ensures that the common library has sources containing both common
# and individual unit tests.
if (!defined(invoker.sources)) {
invoker.sources = []
}
if (defined(invoker.test_sources)) {
invoker.sources += invoker.test_sources
}
if (chip_build_test_static_libraries) {
_target_type = "static_library"
} else {
_target_type = "source_set"
}
target(_target_type, "${_suite_name}.lib") {
forward_variables_from(invoker, "*", [ "tests" ])
output_dir = "${root_out_dir}/lib"
if (!defined(invoker.public_deps)) {
public_deps = []
}
if (current_os != "zephyr" && current_os != "mbed") {
# Depend on stdio logging, and have it take precedence over the default platform backend
public_deps += [ "${chip_root}/src/platform/logging:force_stdio" ]
}
}
if (chip_link_tests) {
tests = []
if (defined(invoker.test_sources)) {
foreach(_test, invoker.test_sources) {
_test_name = string_replace(_test, ".cpp", "")
_driver_name = "${root_gen_dir}/${_test_name}.driver.cpp"
action("${_test_name}_generate_driver") {
script = "${chip_root}/scripts/gen_test_driver.py"
inputs = [ _test ]
outputs = [ _driver_name ]
args = [
"--input_file=" + rebase_path(_test, root_build_dir),
"--output_file=" + rebase_path(_driver_name, root_build_dir),
]
}
chip_test(_test_name) {
sources = [ _driver_name ]
public_deps = [
":${_suite_name}.lib",
":${_test_name}_generate_driver",
]
}
tests += [ _test_name ]
}
}
if (defined(invoker.tests)) {
foreach(_test, invoker.tests) {
chip_test(_test) {
sources = [ "${_test}Driver.cpp" ]
public_deps = [ ":${_suite_name}.lib" ]
}
tests += [ _test ]
}
}
group(_suite_name) {
deps = []
foreach(_test, tests) {
deps += [ ":${_test}" ]
}
}
if (chip_pw_run_tests) {
group("${_suite_name}_run") {
deps = []
foreach(_test, tests) {
deps += [ ":${_test}.run" ]
}
}
}
} else {
group(_suite_name) {
deps = [ ":${_suite_name}.lib" ]
}
}
}