Skip to content

Commit 25d11ca

Browse files
committed
yes executables.gni, cts.gni, args.gni, test_driver build.gn
1 parent b8c957e commit 25d11ca

File tree

3 files changed

+82
-115
lines changed

3 files changed

+82
-115
lines changed

build/chip/chip_test_suite.gni

+58-95
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
17+
import("//build_overrides/pigweed.gni")
1718

18-
import("${chip_root}/build/chip/chip_test.gni")
1919
import("${chip_root}/build/chip/tests.gni")
2020
import("${dir_pw_unit_test}/test.gni")
2121

2222
assert(chip_build_tests)
2323

24+
declare_args() {
25+
# These may be overridden in args.gni to build platform-specific test binaries.
26+
test_executable_output_name = ""
27+
test_executable_output_name_suffix = ""
28+
test_executable_ldflags = []
29+
}
30+
2431
# Define CHIP unit tests
2532
#
2633
# Simple usage
@@ -41,50 +48,23 @@ assert(chip_build_tests)
4148
# "${chip_root}/src/lib/foo", # add dependencies here
4249
# ]
4350
# }
44-
#
45-
#
46-
# Deprecated usage (writing own driver files):
47-
#
48-
# chip_test_suite("tests") {
49-
# output_name = "libFooTests"
50-
#
51-
# sources = [
52-
# "TestDeclarations.h",
53-
# "TestFoo.cpp",
54-
# "TestBar.cpp",
55-
# ]
56-
#
57-
# public_deps = [
58-
# "${chip_root}/src/lib/foo", # add dependencies here
59-
# ]
60-
#
61-
# tests = [
62-
# "TestFoo", # Assumes TestFooDriver.cpp exists
63-
# "TestBar", # Assumes TestBarDriver.cpp exists
64-
# ]
65-
# }
6651

6752
#
6853
template("chip_test_suite") {
6954
_suite_name = target_name
7055

71-
# Ensures that the common library has sources containing both common
72-
# and individual unit tests.
73-
if (!defined(invoker.sources)) {
74-
invoker.sources = []
75-
}
76-
77-
if (defined(invoker.test_sources)) {
78-
invoker.sources += invoker.test_sources
79-
}
80-
8156
if (chip_build_test_static_libraries) {
8257
_target_type = "static_library"
8358
} else {
8459
_target_type = "source_set"
8560
}
8661
target(_target_type, "${_suite_name}.lib") {
87-
forward_variables_from(invoker, "*", [ "tests" ])
62+
forward_variables_from(invoker,
63+
"*",
64+
[
65+
"tests",
66+
"test_sources",
67+
])
8868

8969
output_dir = "${root_out_dir}/lib"
9070

@@ -102,79 +82,62 @@ template("chip_test_suite") {
10282
public_deps += [ "${chip_root}/src/platform/logging:default" ]
10383
}
10484
}
105-
if (chip_link_tests) {
106-
tests = []
10785

108-
if (defined(invoker.test_sources)) {
109-
foreach(_test, invoker.test_sources) {
110-
_test_name = string_replace(_test, ".cpp", "")
86+
tests = []
11187

112-
_test_output_dir = "${root_out_dir}/tests"
113-
if (defined(invoker.output_dir)) {
114-
_test_output_dir = invoker.output_dir
115-
}
88+
if (defined(invoker.test_sources)) {
89+
foreach(_test, invoker.test_sources) {
90+
_test_name = string_replace(_test, ".cpp", "")
11691

117-
pw_test(_test_name) {
118-
forward_variables_from(invoker,
119-
[
120-
"deps",
121-
"public_deps",
122-
"cflags",
123-
"configs",
124-
])
125-
public_deps += [ ":${_suite_name}.lib" ]
126-
sources = [ _test ]
127-
output_dir = _test_output_dir
128-
}
129-
tests += [ _test_name ]
92+
_test_output_dir = "${root_out_dir}/tests"
93+
if (defined(invoker.output_dir)) {
94+
_test_output_dir = invoker.output_dir
13095
}
131-
}
13296

133-
if (defined(invoker.tests)) {
134-
foreach(_test, invoker.tests) {
135-
_test_output_dir = "${root_out_dir}/tests"
136-
if (defined(invoker.output_dir)) {
137-
_test_output_dir = invoker.output_dir
97+
pw_test(_test_name) {
98+
# Forward certain variables from the invoker.
99+
forward_variables_from(invoker,
100+
[
101+
"deps",
102+
"public_deps",
103+
"cflags",
104+
"configs",
105+
])
106+
107+
# Link to the common lib for this suite so we get its `sources`.
108+
public_deps += [ ":${_suite_name}.lib" ]
109+
110+
# Set variables that the platform executable may need.
111+
if (test_executable_output_name != "") {
112+
output_name = test_executable_output_name + _test_name +
113+
test_executable_output_name_suffix
138114
}
115+
ldflags = test_executable_ldflags
139116

140-
pw_test(_test) {
141-
forward_variables_from(invoker,
142-
[
143-
"deps",
144-
"public_deps",
145-
"cflags",
146-
"configs",
147-
])
148-
public_deps += [ ":${_suite_name}.lib" ]
149-
test_main = ""
150-
sources = [
151-
"${_test}.cpp",
152-
"${_test}Driver.cpp",
153-
]
154-
output_dir = _test_output_dir
155-
}
156-
tests += [ _test ]
117+
# Add the individual test source file (e.g. "TestSomething.cpp").
118+
sources = [ _test ]
119+
120+
output_dir = _test_output_dir
157121
}
122+
tests += [ _test_name ]
158123
}
124+
}
159125

160-
group(_suite_name) {
161-
deps = []
162-
foreach(_test, tests) {
163-
deps += [ ":${_test}" ]
164-
}
126+
group(_suite_name) {
127+
deps = []
128+
129+
# Add each individual unit test.
130+
foreach(_test, tests) {
131+
deps += [ ":${_test}" ]
165132
}
133+
}
166134

167-
if (chip_pw_run_tests) {
168-
group("${_suite_name}_run") {
169-
deps = []
170-
foreach(_test, tests) {
171-
deps += [ ":${_test}.run" ]
172-
}
135+
if (chip_pw_run_tests) {
136+
group("${_suite_name}_run") {
137+
deps = []
138+
foreach(_test, tests) {
139+
deps += [ ":${_test}.run" ]
173140
}
174141
}
175-
} else {
176-
group(_suite_name) {
177-
deps = [ ":${_suite_name}.lib" ]
178-
}
179142
}
180-
}
143+
}

src/test_driver/efr32/BUILD.gn

+7-19
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import("//build_overrides/pigweed.gni")
1919

2020
import("${build_root}/config/defaults.gni")
2121
import("${efr32_sdk_build_root}/efr32_sdk.gni")
22-
import("${efr32_sdk_build_root}/silabs_executable.gni")
2322

2423
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
2524
import("${chip_root}/src/platform/device.gni")
@@ -62,9 +61,8 @@ efr32_sdk("sdk") {
6261
]
6362
}
6463

65-
silabs_executable("efr32_device_tests") {
66-
output_name = "matter-silabs-device_tests.out"
67-
64+
# This is the test runner. `pw_test` will dep this for each `silabs_executable` target.
65+
source_set("efr32_test_main") {
6866
defines = [ "PW_RPC_ENABLED" ]
6967
sources = [
7068
"${chip_root}/examples/common/pigweed/RpcService.cpp",
@@ -83,7 +81,6 @@ silabs_executable("efr32_device_tests") {
8381
"$dir_pw_unit_test:rpc_service",
8482
"${chip_root}/config/efr32/lib/pw_rpc:pw_rpc",
8583
"${chip_root}/examples/common/pigweed:system_rpc_server",
86-
"${chip_root}/src:tests",
8784
"${chip_root}/src/lib",
8885
"${chip_root}/src/lib/support:pw_tests_wrapper",
8986
"${chip_root}/src/platform/silabs/provision:provision-headers",
@@ -106,27 +103,18 @@ silabs_executable("efr32_device_tests") {
106103
]
107104

108105
include_dirs = [ "${chip_root}/examples/common/pigweed/efr32" ]
109-
110-
ldscript = "${examples_common_plat_dir}/ldscripts/${silabs_family}.ld"
111-
112-
inputs = [ ldscript ]
113-
114-
ldflags = [
115-
"-T" + rebase_path(ldscript, root_build_dir),
116-
"-Wl,--no-warn-rwx-segment",
117-
]
118-
119-
output_dir = root_out_dir
120106
}
121107

108+
# This target is referred to by BuildRoot in scripts/build/builders/efr32.py, as well as the example in README.md.
109+
# It builds the root target "src:tests", which builds the chip_test_suite target in each test directory, which builds a pw_test target for each test source file, which builds a silabs_executable, which includes the "efr32_test_main" target defined above.
122110
group("efr32") {
123-
deps = [ ":efr32_device_tests" ]
111+
deps = [ "${chip_root}/src:tests" ]
124112
}
125113

126114
group("runner") {
127115
deps = [
128-
"${efr32_project_dir}/py:nl_test_runner.install",
129-
"${efr32_project_dir}/py:nl_test_runner_wheel",
116+
"${efr32_project_dir}/py:pw_test_runner.install",
117+
"${efr32_project_dir}/py:pw_test_runner_wheel",
130118
]
131119
}
132120

src/test_driver/efr32/args.gni

+17-1
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import("//build_overrides/pigweed.gni")
1717
import("${chip_root}/config/efr32/lib/pw_rpc/pw_rpc.gni")
1818
import("${chip_root}/examples/platform/silabs/args.gni")
1919
import("${chip_root}/src/platform/silabs/efr32/args.gni")
20+
import("${chip_root}/third_party/silabs/silabs_board.gni") # silabs_family
2021

2122
silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain")
2223

2324
chip_enable_pw_rpc = true
2425
chip_build_tests = true
2526
chip_enable_openthread = true
2627
chip_openthread_ftd = false # use mtd as it is smaller.
27-
chip_monolithic_tests = true
2828

2929
openthread_external_platform =
3030
"${chip_root}/third_party/openthread/platforms/efr32:libopenthread-efr32"
@@ -35,3 +35,19 @@ pw_assert_BACKEND = "$dir_pw_assert_log"
3535
pw_log_BACKEND = "$dir_pw_log_basic"
3636

3737
pw_unit_test_BACKEND = "$dir_pw_unit_test:light"
38+
39+
# Override the executable type and the test main's target.
40+
pw_unit_test_EXECUTABLE_TARGET_TYPE = "silabs_executable"
41+
pw_unit_test_EXECUTABLE_TARGET_TYPE_FILE =
42+
"${efr32_sdk_build_root}/silabs_executable.gni"
43+
pw_unit_test_MAIN = "//:efr32_test_main"
44+
45+
# Additional variables needed by silabs_executable that must be passed in to pw_test.
46+
test_executable_output_name = "matter-silabs-device_tests-"
47+
test_executable_output_name_suffix = ".out"
48+
_ldscript =
49+
"${chip_root}/examples/platform/silabs/ldscripts/${silabs_family}.ld"
50+
test_executable_ldflags = [
51+
"-T" + rebase_path(_ldscript, root_build_dir),
52+
"-Wl,--no-warn-rwx-segment",
53+
]

0 commit comments

Comments
 (0)