Skip to content

Commit 43159a8

Browse files
authored
Add pw_unit_test support to build configuration (#29479)
* Add pw_unit_test support to GN * Rename old chip_test_suite template to chip_test_suite_using_nltest It will be removed in the future, when it's no longer needed. * Make new chip_test_suite template, using pw_test instead of chip_test * Rename a few GN targets to be consistent with pigweed Make them end with `.lib` or `.run` instead of `_lib` or `_run`. * Reordered declarations in .gn for readability * Update .gn
1 parent 9dcbbf7 commit 43159a8

File tree

35 files changed

+150
-44
lines changed

35 files changed

+150
-44
lines changed

.gn

+11
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,15 @@ default_args = {
3131

3232
# GN target to use for the default Python build venv.
3333
pw_build_PYTHON_BUILD_VENV = "//:matter_build_venv"
34+
35+
# Required for pw_unit_test
36+
pw_sys_io_BACKEND = "$dir_pw_sys_io_stdio"
37+
pw_assert_BACKEND = "$dir_pw_assert_log"
38+
pw_log_BACKEND = "$dir_pw_log_basic"
39+
40+
# TODO: Make sure only unit tests link against this
41+
pw_build_LINK_DEPS = [
42+
"$dir_pw_assert:impl",
43+
"$dir_pw_log:impl",
44+
]
3445
}

build/chip/chip_test.gni

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ if (chip_link_tests) {
3838
output_dir = _test_output_dir
3939
}
4040

41-
group(_test_name + "_lib") {
41+
group(_test_name + ".lib") {
4242
}
4343

4444
if (chip_pw_run_tests) {
45-
pw_python_action(_test_name + "_run") {
45+
pw_python_action(_test_name + ".run") {
4646
deps = [ ":${_test_name}" ]
4747
inputs = [ pw_unit_test_AUTOMATIC_RUNNER ]
4848
module = "pw_unit_test.test_runner"
@@ -64,7 +64,7 @@ if (chip_link_tests) {
6464
template("chip_test") {
6565
group(target_name) {
6666
}
67-
group(target_name + "_lib") {
67+
group(target_name + ".lib") {
6868
}
6969
not_needed(invoker, "*")
7070
}

build/chip/chip_test_group.gni

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ template("chip_test_group") {
3131
_target_type = "group"
3232
}
3333

34-
_lib_target_name = "${_test_group_name}_lib"
34+
_lib_target_name = "${_test_group_name}.lib"
3535

3636
target(_target_type, _lib_target_name) {
3737
forward_variables_from(invoker,
@@ -43,7 +43,7 @@ template("chip_test_group") {
4343

4444
deps = []
4545
foreach(_test, invoker.deps) {
46-
deps += [ get_label_info(_test, "label_no_toolchain") + "_lib" ]
46+
deps += [ get_label_info(_test, "label_no_toolchain") + ".lib" ]
4747
}
4848

4949
if (_build_monolithic_library && chip_build_test_static_libraries) {

build/chip/chip_test_suite.gni

+102-7
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ template("chip_test_suite") {
8585
} else {
8686
_target_type = "source_set"
8787
}
88-
target(_target_type, "${_suite_name}_lib") {
88+
target(_target_type, "${_suite_name}.lib") {
8989
forward_variables_from(invoker, "*", [ "tests" ])
9090

9191
output_dir = "${root_out_dir}/lib"
@@ -99,7 +99,104 @@ template("chip_test_suite") {
9999
public_deps += [ "${chip_root}/src/platform/logging:force_stdio" ]
100100
}
101101
}
102+
if (chip_link_tests) {
103+
tests = []
104+
105+
if (defined(invoker.test_sources)) {
106+
foreach(_test, invoker.test_sources) {
107+
_test_name = string_replace(_test, ".cpp", "")
108+
109+
pw_test(_test_name) {
110+
forward_variables_from(invoker,
111+
[
112+
"deps",
113+
"public_deps",
114+
"cflags",
115+
"configs",
116+
])
117+
public_deps += [ ":${_suite_name}.lib" ]
118+
sources = [ _test ]
119+
}
120+
tests += [ _test_name ]
121+
}
122+
}
123+
124+
if (defined(invoker.tests)) {
125+
foreach(_test, invoker.tests) {
126+
pw_test(_test) {
127+
forward_variables_from(invoker,
128+
[
129+
"deps",
130+
"public_deps",
131+
"cflags",
132+
"configs",
133+
])
134+
public_deps += [ ":${_suite_name}.lib" ]
135+
test_main = ""
136+
sources = [
137+
"${_test}.cpp",
138+
"${_test}Driver.cpp",
139+
]
140+
}
141+
tests += [ _test ]
142+
}
143+
}
102144

145+
group(_suite_name) {
146+
deps = []
147+
foreach(_test, tests) {
148+
deps += [ ":${_test}" ]
149+
}
150+
}
151+
152+
if (chip_pw_run_tests) {
153+
group("${_suite_name}_run") {
154+
deps = []
155+
foreach(_test, tests) {
156+
deps += [ ":${_test}.run" ]
157+
}
158+
}
159+
}
160+
} else {
161+
group(_suite_name) {
162+
deps = [ ":${_suite_name}.lib" ]
163+
}
164+
}
165+
}
166+
167+
# TODO: remove this once transition away from nlunit-test is completed
168+
template("chip_test_suite_using_nltest") {
169+
_suite_name = target_name
170+
171+
# Ensures that the common library has sources containing both common
172+
# and individual unit tests.
173+
if (!defined(invoker.sources)) {
174+
invoker.sources = []
175+
}
176+
177+
if (defined(invoker.test_sources)) {
178+
invoker.sources += invoker.test_sources
179+
}
180+
181+
if (chip_build_test_static_libraries) {
182+
_target_type = "static_library"
183+
} else {
184+
_target_type = "source_set"
185+
}
186+
target(_target_type, "${_suite_name}.lib") {
187+
forward_variables_from(invoker, "*", [ "tests" ])
188+
189+
output_dir = "${root_out_dir}/lib"
190+
191+
if (!defined(invoker.public_deps)) {
192+
public_deps = []
193+
}
194+
195+
if (current_os != "zephyr" && current_os != "mbed") {
196+
# Depend on stdio logging, and have it take precedence over the default platform backend
197+
public_deps += [ "${chip_root}/src/platform/logging:force_stdio" ]
198+
}
199+
}
103200
if (chip_link_tests) {
104201
tests = []
105202

@@ -123,11 +220,10 @@ template("chip_test_suite") {
123220
chip_test(_test_name) {
124221
sources = [ _driver_name ]
125222
public_deps = [
126-
":${_suite_name}_lib",
223+
":${_suite_name}.lib",
127224
":${_test_name}_generate_driver",
128225
]
129226
}
130-
131227
tests += [ _test_name ]
132228
}
133229
}
@@ -137,9 +233,8 @@ template("chip_test_suite") {
137233
chip_test(_test) {
138234
sources = [ "${_test}Driver.cpp" ]
139235

140-
public_deps = [ ":${_suite_name}_lib" ]
236+
public_deps = [ ":${_suite_name}.lib" ]
141237
}
142-
143238
tests += [ _test ]
144239
}
145240
}
@@ -155,13 +250,13 @@ template("chip_test_suite") {
155250
group("${_suite_name}_run") {
156251
deps = []
157252
foreach(_test, tests) {
158-
deps += [ ":${_test}_run" ]
253+
deps += [ ":${_test}.run" ]
159254
}
160255
}
161256
}
162257
} else {
163258
group(_suite_name) {
164-
deps = [ ":${_suite_name}_lib" ]
259+
deps = [ ":${_suite_name}.lib" ]
165260
}
166261
}
167262
}

src/access/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")
1818

1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020

21-
chip_test_suite("tests") {
21+
chip_test_suite_using_nltest("tests") {
2222
output_name = "libaccesstest"
2323

2424
test_sources = [ "TestAccessControl.cpp" ]

src/app/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ source_set("operational-state-test-srcs") {
117117
]
118118
}
119119

120-
chip_test_suite("tests") {
120+
chip_test_suite_using_nltest("tests") {
121121
output_name = "libAppTests"
122122

123123
test_sources = [

src/ble/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")
1818

1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020

21-
chip_test_suite("tests") {
21+
chip_test_suite_using_nltest("tests") {
2222
output_name = "libBleLayerTests"
2323

2424
test_sources = [

src/controller/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")
1818

1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020

21-
chip_test_suite("tests") {
21+
chip_test_suite_using_nltest("tests") {
2222
output_name = "libControllerTests"
2323

2424
test_sources = [ "TestCommissionableNodeController.cpp" ]

src/controller/tests/data_model/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import("//build_overrides/nlunit_test.gni")
1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020
import("${chip_root}/src/platform/device.gni")
2121

22-
chip_test_suite("data_model") {
22+
chip_test_suite_using_nltest("data_model") {
2323
output_name = "libDataModelTests"
2424

2525
if (chip_device_platform != "mbed" && chip_device_platform != "efr32" &&

src/credentials/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static_library("cert_test_vectors") {
4242
]
4343
}
4444

45-
chip_test_suite("tests") {
45+
chip_test_suite_using_nltest("tests") {
4646
output_name = "libCredentialsTest"
4747
output_dir = "${root_out_dir}/lib"
4848

src/crypto/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import("//build_overrides/nlunit_test.gni")
1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020
import("${chip_root}/src/crypto/crypto.gni")
2121

22-
chip_test_suite("tests") {
22+
chip_test_suite_using_nltest("tests") {
2323
output_name = "libChipCryptoTests"
2424

2525
sources = [

src/inet/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static_library("helpers") {
6060
]
6161
}
6262

63-
chip_test_suite("tests") {
63+
chip_test_suite_using_nltest("tests") {
6464
output_name = "libInetLayerTests"
6565

6666
public_configs = [ ":tests_config" ]

src/lib/address_resolve/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import("${chip_root}/src/lib/address_resolve/address_resolve.gni")
2020

2121
import("${chip_root}/build/chip/chip_test_suite.gni")
2222

23-
chip_test_suite("tests") {
23+
chip_test_suite_using_nltest("tests") {
2424
output_name = "libAddressResolveTests"
2525

2626
if (chip_address_resolve_strategy == "default") {

src/lib/asn1/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")
1818

1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020

21-
chip_test_suite("tests") {
21+
chip_test_suite_using_nltest("tests") {
2222
output_name = "libASN1Tests"
2323

2424
test_sources = [ "TestASN1.cpp" ]

src/lib/core/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import("//build_overrides/nlunit_test.gni")
1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020
import("${chip_root}/build/chip/fuzz_test.gni")
2121

22-
chip_test_suite("tests") {
22+
chip_test_suite_using_nltest("tests") {
2323
output_name = "libCoreTests"
2424

2525
test_sources = [

src/lib/dnssd/minimal_mdns/core/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ source_set("support") {
2727
]
2828
}
2929

30-
chip_test_suite("tests") {
30+
chip_test_suite_using_nltest("tests") {
3131
output_name = "libMinimalMdnsCoreTests"
3232

3333
test_sources = [

src/lib/dnssd/minimal_mdns/records/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")
1818

1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020

21-
chip_test_suite("tests") {
21+
chip_test_suite_using_nltest("tests") {
2222
output_name = "libMinimalMdnsRecordsTests"
2323

2424
test_sources = [

src/lib/dnssd/minimal_mdns/responders/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")
1818

1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020

21-
chip_test_suite("tests") {
21+
chip_test_suite_using_nltest("tests") {
2222
output_name = "libMinimalMdnsRespondersTests"
2323

2424
test_sources = [

src/lib/dnssd/minimal_mdns/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import("//build_overrides/nlunit_test.gni")
1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020
import("${chip_root}/build/chip/fuzz_test.gni")
2121

22-
chip_test_suite("tests") {
22+
chip_test_suite_using_nltest("tests") {
2323
output_name = "libMinimalMdnstests"
2424

2525
test_sources = [

src/lib/dnssd/platform/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")
1818

1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020

21-
chip_test_suite("tests") {
21+
chip_test_suite_using_nltest("tests") {
2222
output_name = "libMdnsFakePlatformTests"
2323
if (chip_device_platform == "fake") {
2424
test_sources = [ "TestPlatform.cpp" ]

src/lib/dnssd/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")
1818

1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020

21-
chip_test_suite("tests") {
21+
chip_test_suite_using_nltest("tests") {
2222
output_name = "libMdnsTests"
2323

2424
test_sources = [

src/lib/format/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import("//build_overrides/nlunit_test.gni")
1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020
import("${chip_root}/build/chip/fuzz_test.gni")
2121

22-
chip_test_suite("tests") {
22+
chip_test_suite_using_nltest("tests") {
2323
output_name = "libFormatTests"
2424

2525
test_sources = [

src/lib/shell/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")
1818

1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020

21-
chip_test_suite("tests") {
21+
chip_test_suite_using_nltest("tests") {
2222
output_name = "libTestShell"
2323

2424
test_sources = [

src/lib/support/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")
1818

1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020

21-
chip_test_suite("tests") {
21+
chip_test_suite_using_nltest("tests") {
2222
output_name = "libSupportTests"
2323

2424
test_sources = [

src/messaging/tests/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static_library("helpers") {
4040
]
4141
}
4242

43-
chip_test_suite("tests") {
43+
chip_test_suite_using_nltest("tests") {
4444
output_name = "libMessagingLayerTests"
4545

4646
test_sources = []

0 commit comments

Comments
 (0)