Skip to content

Commit

Permalink
Add pw_unit_test support to build configuration (#29479)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mbknust authored Oct 10, 2023
1 parent 9dcbbf7 commit 43159a8
Show file tree
Hide file tree
Showing 35 changed files with 150 additions and 44 deletions.
11 changes: 11 additions & 0 deletions .gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@ default_args = {

# GN target to use for the default Python build venv.
pw_build_PYTHON_BUILD_VENV = "//:matter_build_venv"

# Required for pw_unit_test
pw_sys_io_BACKEND = "$dir_pw_sys_io_stdio"
pw_assert_BACKEND = "$dir_pw_assert_log"
pw_log_BACKEND = "$dir_pw_log_basic"

# TODO: Make sure only unit tests link against this
pw_build_LINK_DEPS = [
"$dir_pw_assert:impl",
"$dir_pw_log:impl",
]
}
6 changes: 3 additions & 3 deletions build/chip/chip_test.gni
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ if (chip_link_tests) {
output_dir = _test_output_dir
}

group(_test_name + "_lib") {
group(_test_name + ".lib") {
}

if (chip_pw_run_tests) {
pw_python_action(_test_name + "_run") {
pw_python_action(_test_name + ".run") {
deps = [ ":${_test_name}" ]
inputs = [ pw_unit_test_AUTOMATIC_RUNNER ]
module = "pw_unit_test.test_runner"
Expand All @@ -64,7 +64,7 @@ if (chip_link_tests) {
template("chip_test") {
group(target_name) {
}
group(target_name + "_lib") {
group(target_name + ".lib") {
}
not_needed(invoker, "*")
}
Expand Down
4 changes: 2 additions & 2 deletions build/chip/chip_test_group.gni
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ template("chip_test_group") {
_target_type = "group"
}

_lib_target_name = "${_test_group_name}_lib"
_lib_target_name = "${_test_group_name}.lib"

target(_target_type, _lib_target_name) {
forward_variables_from(invoker,
Expand All @@ -43,7 +43,7 @@ template("chip_test_group") {

deps = []
foreach(_test, invoker.deps) {
deps += [ get_label_info(_test, "label_no_toolchain") + "_lib" ]
deps += [ get_label_info(_test, "label_no_toolchain") + ".lib" ]
}

if (_build_monolithic_library && chip_build_test_static_libraries) {
Expand Down
109 changes: 102 additions & 7 deletions build/chip/chip_test_suite.gni
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ template("chip_test_suite") {
} else {
_target_type = "source_set"
}
target(_target_type, "${_suite_name}_lib") {
target(_target_type, "${_suite_name}.lib") {
forward_variables_from(invoker, "*", [ "tests" ])

output_dir = "${root_out_dir}/lib"
Expand All @@ -99,7 +99,104 @@ template("chip_test_suite") {
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", "")

pw_test(_test_name) {
forward_variables_from(invoker,
[
"deps",
"public_deps",
"cflags",
"configs",
])
public_deps += [ ":${_suite_name}.lib" ]
sources = [ _test ]
}
tests += [ _test_name ]
}
}

if (defined(invoker.tests)) {
foreach(_test, invoker.tests) {
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",
]
}
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: 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 = []

Expand All @@ -123,11 +220,10 @@ template("chip_test_suite") {
chip_test(_test_name) {
sources = [ _driver_name ]
public_deps = [
":${_suite_name}_lib",
":${_suite_name}.lib",
":${_test_name}_generate_driver",
]
}

tests += [ _test_name ]
}
}
Expand All @@ -137,9 +233,8 @@ template("chip_test_suite") {
chip_test(_test) {
sources = [ "${_test}Driver.cpp" ]

public_deps = [ ":${_suite_name}_lib" ]
public_deps = [ ":${_suite_name}.lib" ]
}

tests += [ _test ]
}
}
Expand All @@ -155,13 +250,13 @@ template("chip_test_suite") {
group("${_suite_name}_run") {
deps = []
foreach(_test, tests) {
deps += [ ":${_test}_run" ]
deps += [ ":${_test}.run" ]
}
}
}
} else {
group(_suite_name) {
deps = [ ":${_suite_name}_lib" ]
deps = [ ":${_suite_name}.lib" ]
}
}
}
2 changes: 1 addition & 1 deletion src/access/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")

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

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libaccesstest"

test_sources = [ "TestAccessControl.cpp" ]
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ source_set("operational-state-test-srcs") {
]
}

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libAppTests"

test_sources = [
Expand Down
2 changes: 1 addition & 1 deletion src/ble/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")

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

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libBleLayerTests"

test_sources = [
Expand Down
2 changes: 1 addition & 1 deletion src/controller/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")

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

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libControllerTests"

test_sources = [ "TestCommissionableNodeController.cpp" ]
Expand Down
2 changes: 1 addition & 1 deletion src/controller/tests/data_model/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import("//build_overrides/nlunit_test.gni")
import("${chip_root}/build/chip/chip_test_suite.gni")
import("${chip_root}/src/platform/device.gni")

chip_test_suite("data_model") {
chip_test_suite_using_nltest("data_model") {
output_name = "libDataModelTests"

if (chip_device_platform != "mbed" && chip_device_platform != "efr32" &&
Expand Down
2 changes: 1 addition & 1 deletion src/credentials/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static_library("cert_test_vectors") {
]
}

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libCredentialsTest"
output_dir = "${root_out_dir}/lib"

Expand Down
2 changes: 1 addition & 1 deletion src/crypto/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import("//build_overrides/nlunit_test.gni")
import("${chip_root}/build/chip/chip_test_suite.gni")
import("${chip_root}/src/crypto/crypto.gni")

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libChipCryptoTests"

sources = [
Expand Down
2 changes: 1 addition & 1 deletion src/inet/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static_library("helpers") {
]
}

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libInetLayerTests"

public_configs = [ ":tests_config" ]
Expand Down
2 changes: 1 addition & 1 deletion src/lib/address_resolve/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import("${chip_root}/src/lib/address_resolve/address_resolve.gni")

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

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libAddressResolveTests"

if (chip_address_resolve_strategy == "default") {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/asn1/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")

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

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libASN1Tests"

test_sources = [ "TestASN1.cpp" ]
Expand Down
2 changes: 1 addition & 1 deletion src/lib/core/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import("//build_overrides/nlunit_test.gni")
import("${chip_root}/build/chip/chip_test_suite.gni")
import("${chip_root}/build/chip/fuzz_test.gni")

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libCoreTests"

test_sources = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dnssd/minimal_mdns/core/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ source_set("support") {
]
}

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libMinimalMdnsCoreTests"

test_sources = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dnssd/minimal_mdns/records/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")

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

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libMinimalMdnsRecordsTests"

test_sources = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dnssd/minimal_mdns/responders/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")

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

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libMinimalMdnsRespondersTests"

test_sources = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dnssd/minimal_mdns/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import("//build_overrides/nlunit_test.gni")
import("${chip_root}/build/chip/chip_test_suite.gni")
import("${chip_root}/build/chip/fuzz_test.gni")

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libMinimalMdnstests"

test_sources = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dnssd/platform/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")

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

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libMdnsFakePlatformTests"
if (chip_device_platform == "fake") {
test_sources = [ "TestPlatform.cpp" ]
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dnssd/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")

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

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libMdnsTests"

test_sources = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/format/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import("//build_overrides/nlunit_test.gni")
import("${chip_root}/build/chip/chip_test_suite.gni")
import("${chip_root}/build/chip/fuzz_test.gni")

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libFormatTests"

test_sources = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/shell/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")

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

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libTestShell"

test_sources = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/support/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")

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

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libSupportTests"

test_sources = [
Expand Down
2 changes: 1 addition & 1 deletion src/messaging/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static_library("helpers") {
]
}

chip_test_suite("tests") {
chip_test_suite_using_nltest("tests") {
output_name = "libMessagingLayerTests"

test_sources = []
Expand Down
Loading

0 comments on commit 43159a8

Please sign in to comment.