diff --git a/build/chip/chip_test_suite.gni b/build/chip/chip_test_suite.gni index 60f29346a48fa6..790919d8aca933 100644 --- a/build/chip/chip_test_suite.gni +++ b/build/chip/chip_test_suite.gni @@ -14,13 +14,20 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") +import("//build_overrides/pigweed.gni") -import("${chip_root}/build/chip/chip_test.gni") import("${chip_root}/build/chip/tests.gni") import("${dir_pw_unit_test}/test.gni") assert(chip_build_tests) +declare_args() { + # These may be overridden in args.gni to build platform-specific test binaries. + test_executable_output_name = "" + test_executable_output_name_suffix = "" + test_executable_ldflags = [] +} + # Define CHIP unit tests # # Simple usage @@ -41,50 +48,23 @@ assert(chip_build_tests) # "${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" ]) + forward_variables_from(invoker, + "*", + [ + "tests", + "test_sources", + ]) output_dir = "${root_out_dir}/lib" @@ -102,79 +82,62 @@ template("chip_test_suite") { public_deps += [ "${chip_root}/src/platform/logging:default" ] } } - if (chip_link_tests) { - tests = [] - if (defined(invoker.test_sources)) { - foreach(_test, invoker.test_sources) { - _test_name = string_replace(_test, ".cpp", "") + tests = [] - _test_output_dir = "${root_out_dir}/tests" - if (defined(invoker.output_dir)) { - _test_output_dir = invoker.output_dir - } + 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 ] - output_dir = _test_output_dir - } - tests += [ _test_name ] + _test_output_dir = "${root_out_dir}/tests" + if (defined(invoker.output_dir)) { + _test_output_dir = invoker.output_dir } - } - 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_name) { + # Forward certain variables from the invoker. + forward_variables_from(invoker, + [ + "deps", + "public_deps", + "cflags", + "configs", + ]) + + # Link to the common lib for this suite so we get its `sources`. + public_deps += [ ":${_suite_name}.lib" ] + + # Set variables that the platform executable may need. + if (test_executable_output_name != "") { + output_name = test_executable_output_name + _test_name + + test_executable_output_name_suffix } + ldflags = test_executable_ldflags - 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 ] + # Add the individual test source file (e.g. "TestSomething.cpp"). + sources = [ _test ] + + output_dir = _test_output_dir } + tests += [ _test_name ] } + } - group(_suite_name) { - deps = [] - foreach(_test, tests) { - deps += [ ":${_test}" ] - } + group(_suite_name) { + deps = [] + + # Add each individual unit test. + foreach(_test, tests) { + deps += [ ":${_test}" ] } + } - if (chip_pw_run_tests) { - group("${_suite_name}_run") { - deps = [] - foreach(_test, tests) { - deps += [ ":${_test}.run" ] - } + if (chip_pw_run_tests) { + group("${_suite_name}_run") { + deps = [] + foreach(_test, tests) { + deps += [ ":${_test}.run" ] } } - } else { - group(_suite_name) { - deps = [ ":${_suite_name}.lib" ] - } } -} +} \ No newline at end of file diff --git a/src/test_driver/efr32/BUILD.gn b/src/test_driver/efr32/BUILD.gn index b15b16864548c9..0d10cb8d76a475 100644 --- a/src/test_driver/efr32/BUILD.gn +++ b/src/test_driver/efr32/BUILD.gn @@ -19,7 +19,6 @@ import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") import("${efr32_sdk_build_root}/efr32_sdk.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") @@ -62,9 +61,8 @@ efr32_sdk("sdk") { ] } -silabs_executable("efr32_device_tests") { - output_name = "matter-silabs-device_tests.out" - +# This is the test runner. `pw_test` will dep this for each `silabs_executable` target. +source_set("efr32_test_main") { defines = [ "PW_RPC_ENABLED" ] sources = [ "${chip_root}/examples/common/pigweed/RpcService.cpp", @@ -83,7 +81,6 @@ silabs_executable("efr32_device_tests") { "$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:tests", "${chip_root}/src/lib", "${chip_root}/src/lib/support:pw_tests_wrapper", "${chip_root}/src/platform/silabs/provision:provision-headers", @@ -106,27 +103,18 @@ silabs_executable("efr32_device_tests") { ] 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 } +# This target is referred to by BuildRoot in scripts/build/builders/efr32.py, as well as the example in README.md. +# 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. group("efr32") { - deps = [ ":efr32_device_tests" ] + deps = [ "${chip_root}/src:tests" ] } group("runner") { deps = [ - "${efr32_project_dir}/py:nl_test_runner.install", - "${efr32_project_dir}/py:nl_test_runner_wheel", + "${efr32_project_dir}/py:pw_test_runner.install", + "${efr32_project_dir}/py:pw_test_runner_wheel", ] } diff --git a/src/test_driver/efr32/args.gni b/src/test_driver/efr32/args.gni index 71bf093f3e3a16..d54ec142bb6ba1 100644 --- a/src/test_driver/efr32/args.gni +++ b/src/test_driver/efr32/args.gni @@ -17,6 +17,7 @@ import("//build_overrides/pigweed.gni") import("${chip_root}/config/efr32/lib/pw_rpc/pw_rpc.gni") import("${chip_root}/examples/platform/silabs/args.gni") import("${chip_root}/src/platform/silabs/efr32/args.gni") +import("${chip_root}/third_party/silabs/silabs_board.gni") # silabs_family silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") @@ -24,7 +25,6 @@ chip_enable_pw_rpc = true chip_build_tests = true chip_enable_openthread = true chip_openthread_ftd = false # use mtd as it is smaller. -chip_monolithic_tests = true openthread_external_platform = "${chip_root}/third_party/openthread/platforms/efr32:libopenthread-efr32" @@ -35,3 +35,19 @@ pw_assert_BACKEND = "$dir_pw_assert_log" pw_log_BACKEND = "$dir_pw_log_basic" pw_unit_test_BACKEND = "$dir_pw_unit_test:light" + +# Override the executable type and the test main's target. +pw_unit_test_EXECUTABLE_TARGET_TYPE = "silabs_executable" +pw_unit_test_EXECUTABLE_TARGET_TYPE_FILE = + "${efr32_sdk_build_root}/silabs_executable.gni" +pw_unit_test_MAIN = "//:efr32_test_main" + +# Additional variables needed by silabs_executable that must be passed in to pw_test. +test_executable_output_name = "matter-silabs-device_tests-" +test_executable_output_name_suffix = ".out" +_ldscript = + "${chip_root}/examples/platform/silabs/ldscripts/${silabs_family}.ld" +test_executable_ldflags = [ + "-T" + rebase_path(_ldscript, root_build_dir), + "-Wl,--no-warn-rwx-segment", +] \ No newline at end of file