From 25ebd41ac813a3769fef53fbdbafb8ff895d20a1 Mon Sep 17 00:00:00 2001 From: Jeff Feasel Date: Mon, 3 Jun 2024 13:00:24 +0000 Subject: [PATCH 1/7] Updated test runner to support running all tests in a directory --- .../efr32/py/pw_test_runner/pw_test_runner.py | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/test_driver/efr32/py/pw_test_runner/pw_test_runner.py b/src/test_driver/efr32/py/pw_test_runner/pw_test_runner.py index c8fca307f015ff..7ee740983fdb7b 100644 --- a/src/test_driver/efr32/py/pw_test_runner/pw_test_runner.py +++ b/src/test_driver/efr32/py/pw_test_runner/pw_test_runner.py @@ -62,6 +62,11 @@ def _parse_args(): "--flash_image", help="a firmware image which will be flashed berfore runnning the test", ) + parser.add_argument( + "-y", + "--flash_directory", + help="A directory containing image files, each of which will be flashed and then run.", + ) parser.add_argument( "-o", "--output", @@ -96,22 +101,41 @@ def get_hdlc_rpc_client(device: str, baudrate: int, output: Any, **kwargs): ) -def runner(client: rpc.HdlcRpcClient) -> int: - """Run the tests""" +def run(args) -> int: + """Run the tests. Return the number of failed tests.""" + with get_hdlc_rpc_client(**vars(args)) as client: + test_records = run_tests(client.rpcs()) + return len(test_records.failing_tests) - test_records = run_tests(client.rpcs()) - return len(test_records.failing_tests) +def list_images(flash_directory: str, **kwargs) -> list[str]: + filenames: list[str] = os.listdir(flash_directory) + # filenames = filter(lambda x: not x.endswith('.map'), filenames) + return list(map(lambda x: os.path.join(flash_directory, x), filenames)) def main() -> int: args = _parse_args() - if args.flash_image: - flash_device(**vars(args)) - time.sleep(1) # Give time for device to boot - with get_hdlc_rpc_client(**vars(args)) as client: - return runner(client) + images: list[str] = None + if args.flash_directory: + images = list_images(**vars(args)) + if not images: + raise Exception(f"No images found in `{args.flash_directory}`") + elif args.flash_image: + images = [args.flash_image] + + failures: int = 0 + if images: + for image in images: + flash_device(args.device, image) + time.sleep(1) # Give time for device to boot + + failures += run(args) + else: # No image provided. Just run. + failures += run(args) + + return failures if __name__ == "__main__": From 9e1a79e7db2468d7589cdcf0980f7d9dc6aff8d1 Mon Sep 17 00:00:00 2001 From: Jeff Feasel Date: Mon, 3 Jun 2024 19:48:57 +0000 Subject: [PATCH 2/7] Fixed the build process for the test runner, updated the test runner to use glob, and updated the test runner to use the flash_image parameter for directories --- scripts/build/builders/efr32.py | 5 +++ scripts/build/builders/host.py | 1 + src/BUILD.gn | 24 ++++++++----- src/test_driver/efr32/BUILD.gn | 3 ++ src/test_driver/efr32/README.md | 12 +++---- .../efr32/py/pw_test_runner/pw_test_runner.py | 36 +++++++++---------- src/test_driver/efr32/py/setup.cfg | 2 +- 7 files changed, 47 insertions(+), 36 deletions(-) diff --git a/scripts/build/builders/efr32.py b/scripts/build/builders/efr32.py index 1144cfc8c54a16..baa98b76db2b91 100644 --- a/scripts/build/builders/efr32.py +++ b/scripts/build/builders/efr32.py @@ -270,6 +270,11 @@ def build_outputs(self): if self.app == Efr32App.UNIT_TEST: # Include test runner python wheels + for root, dirs, files in os.walk(os.path.join(self.output_dir, 'chip_pw_test_runner_wheels')): + for file in files: + items["chip_pw_test_runner_wheels/" + + file] = os.path.join(root, file) + # TODO [PW_MIGRATION]: remove the nl wheels once transition away from nlunit-test is completed for root, dirs, files in os.walk(os.path.join(self.output_dir, 'chip_nl_test_runner_wheels')): for file in files: items["chip_nl_test_runner_wheels/" + diff --git a/scripts/build/builders/host.py b/scripts/build/builders/host.py index 667cd39d47da99..889c7de85e7878 100644 --- a/scripts/build/builders/host.py +++ b/scripts/build/builders/host.py @@ -215,6 +215,7 @@ def OutputNames(self): elif self == HostApp.PYTHON_BINDINGS: yield 'controller/python' # Directory containing WHL files elif self == HostApp.EFR32_TEST_RUNNER: + yield 'chip_pw_test_runner_wheels' yield 'chip_nl_test_runner_wheels' elif self == HostApp.TV_CASTING: yield 'chip-tv-casting-app' diff --git a/src/BUILD.gn b/src/BUILD.gn index cf15f40ec00629..7c468a017256fe 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -59,17 +59,23 @@ if (chip_build_tests) { "${chip_root}/src/access/tests", "${chip_root}/src/crypto/tests", "${chip_root}/src/inet/tests", - "${chip_root}/src/lib/address_resolve/tests", - "${chip_root}/src/lib/asn1/tests", - "${chip_root}/src/lib/core/tests", - "${chip_root}/src/messaging/tests", - "${chip_root}/src/protocols/bdx/tests", - "${chip_root}/src/protocols/interaction_model/tests", - "${chip_root}/src/protocols/user_directed_commissioning/tests", - "${chip_root}/src/transport/retransmit/tests", - "${chip_root}/src/app/icd/server/tests", ] + # Skip on efr32 due to flash limitations. + if (chip_device_platform != "efr32") { + tests += [ + "${chip_root}/src/lib/address_resolve/tests", + "${chip_root}/src/lib/asn1/tests", + "${chip_root}/src/lib/core/tests", + "${chip_root}/src/messaging/tests", + "${chip_root}/src/protocols/bdx/tests", + "${chip_root}/src/protocols/interaction_model/tests", + "${chip_root}/src/protocols/user_directed_commissioning/tests", + "${chip_root}/src/transport/retransmit/tests", + "${chip_root}/src/app/icd/server/tests", + ] + } + # Skip DNSSD tests for Mbed platform due to flash memory size limitations if (current_os != "mbed") { tests += [ diff --git a/src/test_driver/efr32/BUILD.gn b/src/test_driver/efr32/BUILD.gn index 66676e197c983d..ab3771a2522cb5 100644 --- a/src/test_driver/efr32/BUILD.gn +++ b/src/test_driver/efr32/BUILD.gn @@ -130,6 +130,9 @@ group("efr32") { group("runner") { deps = [ + "${efr32_project_dir}/py:pw_test_runner.install", + "${efr32_project_dir}/py:pw_test_runner_wheel", + # TODO [PW_MIGRATION]: remove the following when transition from nlunit-test is complete. "${efr32_project_dir}/py:nl_test_runner.install", "${efr32_project_dir}/py:nl_test_runner_wheel", ] diff --git a/src/test_driver/efr32/README.md b/src/test_driver/efr32/README.md index 0f4ea0b33176d4..7366eb3e13b810 100644 --- a/src/test_driver/efr32/README.md +++ b/src/test_driver/efr32/README.md @@ -1,6 +1,6 @@ #CHIP EFR32 Test Driver -This builds and runs the NLUnitTest on the efr32 device +This builds and runs the PW Unit Tests on the efr32 device
@@ -14,7 +14,7 @@ This builds and runs the NLUnitTest on the efr32 device ## Introduction -This builds a test binary which contains the NLUnitTests and can be flashed onto +This builds a test binary which contains the pw_unit_test and can be flashed onto a device. The device is controlled using the included RPCs, through the python test runner. @@ -99,7 +99,7 @@ Or build using build script from the root ``` cd - ./scripts/build/build_examples.py --target linux-x64-nl-test-runner build + ./scripts/build/build_examples.py --target linux-x64-pw-test-runner build ``` The runner will be installed into the venv and python wheels will be packaged in @@ -108,7 +108,7 @@ the output folder for deploying. Then the python wheels need to installed using pip3. ``` - pip3 install out/debug/chip_nl_test_runner_wheels/*.whl + pip3 install out/debug/chip_pw_test_runner_wheels/*.whl ``` Other python libraries may need to be installed such as @@ -117,8 +117,8 @@ Other python libraries may need to be installed such as pip3 install pyserial ``` -- To run the tests: +To run all tests: ``` - python -m nl_test_runner.nl_test_runner -d /dev/ttyACM1 -f out/debug/matter-silabs-device_tests.s37 -o out.log + python -m pw_test_runner.pw_test_runner -d /dev/ttyACM1 -f out/debug -o out.log ``` diff --git a/src/test_driver/efr32/py/pw_test_runner/pw_test_runner.py b/src/test_driver/efr32/py/pw_test_runner/pw_test_runner.py index 7ee740983fdb7b..874600d6c3b674 100644 --- a/src/test_driver/efr32/py/pw_test_runner/pw_test_runner.py +++ b/src/test_driver/efr32/py/pw_test_runner/pw_test_runner.py @@ -16,6 +16,7 @@ # import argparse +import glob import logging import os import subprocess @@ -60,12 +61,7 @@ def _parse_args(): parser.add_argument( "-f", "--flash_image", - help="a firmware image which will be flashed berfore runnning the test", - ) - parser.add_argument( - "-y", - "--flash_directory", - help="A directory containing image files, each of which will be flashed and then run.", + help="A firmware image which will be flashed berfore runnning the test. Or a directory containing firmware images, each of which will be flashed and then run.", ) parser.add_argument( "-o", @@ -80,7 +76,7 @@ def _parse_args(): return parser.parse_args() -def flash_device(device: str, flash_image: str, **kwargs): +def flash_device(device: str, flash_image: str): """flashes the EFR32 device using commander""" err = subprocess.call( ["commander", "flash", "--device", "EFR32", flash_image]) @@ -108,31 +104,31 @@ def run(args) -> int: return len(test_records.failing_tests) -def list_images(flash_directory: str, **kwargs) -> list[str]: - filenames: list[str] = os.listdir(flash_directory) - # filenames = filter(lambda x: not x.endswith('.map'), filenames) +def list_images(flash_directory: str) -> list[str]: + filenames: list[str] = glob.glob(os.path.join(flash_directory, "*.s37")) return list(map(lambda x: os.path.join(flash_directory, x), filenames)) def main() -> int: args = _parse_args() - images: list[str] = None - if args.flash_directory: - images = list_images(**vars(args)) - if not images: - raise Exception(f"No images found in `{args.flash_directory}`") - elif args.flash_image: - images = [args.flash_image] + failures = 0 + if args.flash_image: + if os.path.isdir(args.flash_image): + images = list_images(args.flash_image) + if not images: + raise Exception(f"No images found in `{args.flash_image}`") + elif os.path.isdir(args.flash_image): + images = [args.flash_image] + else: + raise Exception(f"File or directory not found `{args.flash_image}`") - failures: int = 0 - if images: for image in images: flash_device(args.device, image) time.sleep(1) # Give time for device to boot failures += run(args) - else: # No image provided. Just run. + else: # No image provided. Just run what's on the device. failures += run(args) return failures diff --git a/src/test_driver/efr32/py/setup.cfg b/src/test_driver/efr32/py/setup.cfg index 77108ab8288747..cb949a38092b07 100644 --- a/src/test_driver/efr32/py/setup.cfg +++ b/src/test_driver/efr32/py/setup.cfg @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. [metadata] -name = nl_test_runner +name = pw_test_runner version = 0.0.1 [options] From 6aea2b2555fe6ac31e8d424af18ccb9547a4c879 Mon Sep 17 00:00:00 2001 From: Jeff Feasel Date: Mon, 3 Jun 2024 20:42:16 +0000 Subject: [PATCH 3/7] added init file to pw_test_runner --- src/test_driver/efr32/py/pw_test_runner/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/test_driver/efr32/py/pw_test_runner/__init__.py diff --git a/src/test_driver/efr32/py/pw_test_runner/__init__.py b/src/test_driver/efr32/py/pw_test_runner/__init__.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 From c26ff7160e771db401a3a294e728c865f0f4fdf0 Mon Sep 17 00:00:00 2001 From: Jeff Feasel Date: Thu, 6 Jun 2024 16:15:16 +0000 Subject: [PATCH 4/7] Proposed changes to generating one efr32 binary per test --- build/chip/chip_test_suite.gni | 202 ++++++++++++++++++++++- build/chip/tests.gni | 3 +- src/test_driver/efr32/BUILD.gn | 67 +------- src/test_driver/efr32/args.gni | 3 +- third_party/silabs/silabs_executable.gni | 2 +- 5 files changed, 209 insertions(+), 68 deletions(-) diff --git a/build/chip/chip_test_suite.gni b/build/chip/chip_test_suite.gni index 46b0b1fb7d4399..0c95557b594601 100644 --- a/build/chip/chip_test_suite.gni +++ b/build/chip/chip_test_suite.gni @@ -12,12 +12,29 @@ # See the License for the specific language governing permissions and # limitations under the License. +enable_efr32_build_per_suite = false #++++ TODO: Figure out how to enable things based on `chip_device_platform == "efr32"` which is not currently in scope. +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_suite || 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_suite || 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) @@ -78,6 +95,115 @@ template("chip_test_suite") { invoker.sources += invoker.test_sources } + if (enable_efr32_build_per_suite || 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", "") + } + } + + print("++++ SUITE ${_unique_suite_name}") + if (enable_efr32_build_per_suite) { + #++++ DEBUG: Disabled code that was used for testing an alternative implementaiton. + # + # pw_proto_library("nl_test_service--${_unique_suite_name}") { + # sources = [ "${efr32_project_dir}/proto/nl_test.proto" ] + # inputs = [ "${efr32_project_dir}/proto/nl_test.options" ] + # deps = [ "$dir_pw_protobuf:common_protos" ] + # strip_prefix = "${efr32_project_dir}/proto" + # prefix = "nl_test_service" + # } + # + # efr32_sdk("sdk--${_unique_suite_name}") { + # sources = [ + # "${efr32_project_dir}/include/CHIPProjectConfig.h", + # "${examples_common_plat_dir}/FreeRTOSConfig.h", + # ] + # + # include_dirs = [ + # "${chip_root}/src/platform/silabs/efr32", + # "${efr32_project_dir}/include", + # "${examples_plat_dir}", + # "${examples_common_plat_dir}", + # ] + # + # defines = [ + # "PW_RPC_ENABLED", + # + # # Thread is built but test driver do not have the NETWORK_COMMISSIONING cluster or zap config. + # "_NO_NETWORK_COMMISSIONING_DRIVER_", + # ] + # } + + silabs_executable("efr32_device_tests--${_unique_suite_name}") { + output_name = "matter-silabs-device_tests--${_unique_suite_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}.nanopb_rpc", + #":sdk--${_unique_suite_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 + } + } + if (chip_build_test_static_libraries) { _target_type = "static_library" } else { @@ -93,13 +219,17 @@ template("chip_test_suite") { } deps = [ dir_pw_unit_test ] + if (enable_efr32_build_per_suite) { + deps += [ ":efr32_device_tests--${_unique_suite_name}" ] + } 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) { + if (chip_link_tests || enable_efr32_build_per_testsource) { #++++ Temporary workaround rather than changing `chip_link_tests` and `chip_build_tests` in `tests.gni` + print(" ++++ LINK ${_unique_suite_name}") tests = [] if (defined(invoker.test_sources)) { @@ -111,6 +241,73 @@ template("chip_test_suite") { _test_output_dir = invoker.output_dir } + print(" ++++ TEST ${_unique_suite_name} -- ${_test_name}") + if (enable_efr32_build_per_testsource) { + 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, [ @@ -122,6 +319,9 @@ template("chip_test_suite") { 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 ] } diff --git a/build/chip/tests.gni b/build/chip/tests.gni index 61a2ad3e685682..3f185f463c3efc 100644 --- a/build/chip/tests.gni +++ b/build/chip/tests.gni @@ -36,7 +36,8 @@ declare_args() { declare_args() { # Use source_set instead of static_lib for tests. - chip_build_test_static_libraries = chip_device_platform != "efr32" + chip_build_test_static_libraries = true #++++ With new test runner this should always be true. + #chip_build_test_static_libraries = chip_device_platform != "efr32" } declare_args() { diff --git a/src/test_driver/efr32/BUILD.gn b/src/test_driver/efr32/BUILD.gn index ab3771a2522cb5..2b4a2ff261d755 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") @@ -63,78 +62,18 @@ efr32_sdk("sdk") { ] } -silabs_executable("efr32_device_tests") { - output_name = "matter-silabs-device_tests.out" - - defines = [ "PW_RPC_ENABLED" ] - sources = [ - "${chip_root}/examples/common/pigweed/RpcService.cpp", - "${chip_root}/examples/common/pigweed/efr32/PigweedLoggerMutex.cpp", - "${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", - "src/main.cpp", - ] - +group("efr32") { deps = [ - ":nl_test_service.nanopb_rpc", - ":sdk", - "$dir_pw_unit_test:rpc_service", - "${chip_root}/config/efr32/lib/pw_rpc:pw_rpc", - "${chip_root}/examples/common/pigweed:system_rpc_server", + ":nl_test_service.nanopb_rpc", #++++ belongs here or in chip_test_suite->silabs_executable? + ":sdk", #++++ belongs here or in chip_test_suite->silabs_executable? "${chip_root}/src:tests", - "${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 -} - -group("efr32") { - deps = [ ":efr32_device_tests" ] } group("runner") { deps = [ "${efr32_project_dir}/py:pw_test_runner.install", "${efr32_project_dir}/py:pw_test_runner_wheel", - # TODO [PW_MIGRATION]: remove the following when transition from nlunit-test is complete. - "${efr32_project_dir}/py:nl_test_runner.install", - "${efr32_project_dir}/py:nl_test_runner_wheel", ] } diff --git a/src/test_driver/efr32/args.gni b/src/test_driver/efr32/args.gni index 71bf093f3e3a16..cf91fc0b2f275b 100644 --- a/src/test_driver/efr32/args.gni +++ b/src/test_driver/efr32/args.gni @@ -24,7 +24,8 @@ 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 +chip_monolithic_tests = false #++++ With new test runner this should always be false. +#chip_monolithic_tests = true openthread_external_platform = "${chip_root}/third_party/openthread/platforms/efr32:libopenthread-efr32" diff --git a/third_party/silabs/silabs_executable.gni b/third_party/silabs/silabs_executable.gni index a639a4d19ae62d..85e88710cc7b18 100644 --- a/third_party/silabs/silabs_executable.gni +++ b/third_party/silabs/silabs_executable.gni @@ -68,7 +68,7 @@ template("silabs_executable") { ] copy(flashing_runtime_target) { sources = flashing_script_inputs - outputs = [ "${root_out_dir}/{{source_file_part}}" ] + outputs = [ "${root_out_dir}/${target_name}--{{source_file_part}}" ] } flashing_script_generator = From 8a40d800dd7969e6aea49ceb3bff2bbf83c11641 Mon Sep 17 00:00:00 2001 From: Jeff Feasel Date: Thu, 6 Jun 2024 17:10:41 +0000 Subject: [PATCH 5/7] enabled more efr32 tests in src/BUILD.gn --- build/chip/chip_test_suite.gni | 1 + src/BUILD.gn | 44 ++++++++++++++-------------------- src/controller/tests/BUILD.gn | 3 +-- src/transport/tests/BUILD.gn | 5 ++-- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/build/chip/chip_test_suite.gni b/build/chip/chip_test_suite.gni index 0c95557b594601..5a9fd4fb2864a3 100644 --- a/build/chip/chip_test_suite.gni +++ b/build/chip/chip_test_suite.gni @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +#++++ DEBUG: These flags control whether we're creating a binary for each test suite or each individual test source. This is a temporary solution while debugging. enable_efr32_build_per_suite = false #++++ TODO: Figure out how to enable things based on `chip_device_platform == "efr32"` which is not currently in scope. 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. diff --git a/src/BUILD.gn b/src/BUILD.gn index 7c468a017256fe..d0479663af061c 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -59,23 +59,23 @@ if (chip_build_tests) { "${chip_root}/src/access/tests", "${chip_root}/src/crypto/tests", "${chip_root}/src/inet/tests", + "${chip_root}/src/lib/address_resolve/tests", + "${chip_root}/src/lib/asn1/tests", + "${chip_root}/src/lib/core/tests", + "${chip_root}/src/messaging/tests", + "${chip_root}/src/protocols/bdx/tests", + "${chip_root}/src/protocols/interaction_model/tests", + "${chip_root}/src/protocols/user_directed_commissioning/tests", + "${chip_root}/src/transport/retransmit/tests", + "${chip_root}/src/app/icd/server/tests", + "${chip_root}/src/app/tests", + "${chip_root}/src/lib/format/tests", + "${chip_root}/src/protocols/secure_channel/tests", + "${chip_root}/src/protocols/secure_channel/tests:tests_nltest", + "${chip_root}/src/system/tests", + "${chip_root}/src/transport/tests", ] - # Skip on efr32 due to flash limitations. - if (chip_device_platform != "efr32") { - tests += [ - "${chip_root}/src/lib/address_resolve/tests", - "${chip_root}/src/lib/asn1/tests", - "${chip_root}/src/lib/core/tests", - "${chip_root}/src/messaging/tests", - "${chip_root}/src/protocols/bdx/tests", - "${chip_root}/src/protocols/interaction_model/tests", - "${chip_root}/src/protocols/user_directed_commissioning/tests", - "${chip_root}/src/transport/retransmit/tests", - "${chip_root}/src/app/icd/server/tests", - ] - } - # Skip DNSSD tests for Mbed platform due to flash memory size limitations if (current_os != "mbed") { tests += [ @@ -90,25 +90,18 @@ if (chip_build_tests) { tests += [ "${chip_root}/src/lib/dnssd/minimal_mdns/records/tests" ] } - if (current_os != "zephyr" && current_os != "mbed" && - chip_device_platform != "efr32") { + if (current_os != "zephyr" && current_os != "mbed") { tests += [ "${chip_root}/src/setup_payload/tests", "${chip_root}/src/transport/raw/tests", ] } - # Skip on efr32 due to flash and/or ram limitations. + # Won't build on efr32. openr.c:(.text._open_r+0x10): warning: _open is not implemented and will always fail due to flash and/or ram limitations. if (chip_device_platform != "efr32") { tests += [ - "${chip_root}/src/app/tests", "${chip_root}/src/credentials/tests", - "${chip_root}/src/lib/format/tests", "${chip_root}/src/lib/support/tests", - "${chip_root}/src/protocols/secure_channel/tests", - "${chip_root}/src/protocols/secure_channel/tests:tests_nltest", - "${chip_root}/src/system/tests", - "${chip_root}/src/transport/tests", ] if (matter_enable_tracing_support && @@ -121,8 +114,7 @@ if (chip_build_tests) { tests += [ "${chip_root}/src/lib/dnssd/minimal_mdns/tests" ] } - if (chip_device_platform != "esp32" && chip_device_platform != "efr32" && - chip_device_platform != "ameba") { + if (chip_device_platform != "esp32" && chip_device_platform != "ameba") { tests += [ "${chip_root}/src/platform/tests" ] } diff --git a/src/controller/tests/BUILD.gn b/src/controller/tests/BUILD.gn index 1e2b15d7778beb..11a661f578891a 100644 --- a/src/controller/tests/BUILD.gn +++ b/src/controller/tests/BUILD.gn @@ -23,8 +23,7 @@ chip_test_suite("tests") { test_sources = [ "TestCommissionableNodeController.cpp" ] - if (chip_device_platform != "mbed" && chip_device_platform != "efr32" && - chip_device_platform != "esp32") { + if (chip_device_platform != "mbed" && chip_device_platform != "esp32") { test_sources += [ "TestServerCommandDispatch.cpp" ] test_sources += [ "TestEventChunking.cpp" ] test_sources += [ "TestEventCaching.cpp" ] diff --git a/src/transport/tests/BUILD.gn b/src/transport/tests/BUILD.gn index 7c38cea5e7e8eb..f1a9e00a36a995 100644 --- a/src/transport/tests/BUILD.gn +++ b/src/transport/tests/BUILD.gn @@ -44,9 +44,8 @@ chip_test_suite("tests") { "TestSessionManagerDispatch.cpp", ] - if (chip_device_platform != "mbed" && chip_device_platform != "efr32" && - chip_device_platform != "esp32" && chip_device_platform != "nrfconnect" && - chip_device_platform != "nxp") { + if (chip_device_platform != "mbed" && chip_device_platform != "esp32" && + chip_device_platform != "nrfconnect" && chip_device_platform != "nxp") { test_sources += [ "TestSecureSessionTable.cpp" ] } From 570763ab9250c6e9bbd76096568b745ffaab36df Mon Sep 17 00:00:00 2001 From: Jeff Feasel Date: Thu, 6 Jun 2024 17:53:10 +0000 Subject: [PATCH 6/7] Cleaned up debug stuff --- build/chip/chip_test_suite.gni | 130 +++------------------------------ src/lib/core/tests/BUILD.gn | 7 +- 2 files changed, 13 insertions(+), 124 deletions(-) diff --git a/build/chip/chip_test_suite.gni b/build/chip/chip_test_suite.gni index 5a9fd4fb2864a3..9343b28ed05f08 100644 --- a/build/chip/chip_test_suite.gni +++ b/build/chip/chip_test_suite.gni @@ -12,13 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -#++++ DEBUG: These flags control whether we're creating a binary for each test suite or each individual test source. This is a temporary solution while debugging. -enable_efr32_build_per_suite = false #++++ TODO: Figure out how to enable things based on `chip_device_platform == "efr32"` which is not currently in scope. 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_suite || enable_efr32_build_per_testsource) { +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 } @@ -26,7 +24,7 @@ if (enable_efr32_build_per_suite || enable_efr32_build_per_testsource) { 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_suite || enable_efr32_build_per_testsource) { +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") @@ -96,115 +94,6 @@ template("chip_test_suite") { invoker.sources += invoker.test_sources } - if (enable_efr32_build_per_suite || 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", "") - } - } - - print("++++ SUITE ${_unique_suite_name}") - if (enable_efr32_build_per_suite) { - #++++ DEBUG: Disabled code that was used for testing an alternative implementaiton. - # - # pw_proto_library("nl_test_service--${_unique_suite_name}") { - # sources = [ "${efr32_project_dir}/proto/nl_test.proto" ] - # inputs = [ "${efr32_project_dir}/proto/nl_test.options" ] - # deps = [ "$dir_pw_protobuf:common_protos" ] - # strip_prefix = "${efr32_project_dir}/proto" - # prefix = "nl_test_service" - # } - # - # efr32_sdk("sdk--${_unique_suite_name}") { - # sources = [ - # "${efr32_project_dir}/include/CHIPProjectConfig.h", - # "${examples_common_plat_dir}/FreeRTOSConfig.h", - # ] - # - # include_dirs = [ - # "${chip_root}/src/platform/silabs/efr32", - # "${efr32_project_dir}/include", - # "${examples_plat_dir}", - # "${examples_common_plat_dir}", - # ] - # - # defines = [ - # "PW_RPC_ENABLED", - # - # # Thread is built but test driver do not have the NETWORK_COMMISSIONING cluster or zap config. - # "_NO_NETWORK_COMMISSIONING_DRIVER_", - # ] - # } - - silabs_executable("efr32_device_tests--${_unique_suite_name}") { - output_name = "matter-silabs-device_tests--${_unique_suite_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}.nanopb_rpc", - #":sdk--${_unique_suite_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 - } - } - if (chip_build_test_static_libraries) { _target_type = "static_library" } else { @@ -220,9 +109,6 @@ template("chip_test_suite") { } deps = [ dir_pw_unit_test ] - if (enable_efr32_build_per_suite) { - deps += [ ":efr32_device_tests--${_unique_suite_name}" ] - } if (current_os != "zephyr" && current_os != "mbed") { # Depend on stdio logging, and have it take precedence over the default platform backend @@ -230,7 +116,6 @@ template("chip_test_suite") { } } if (chip_link_tests || enable_efr32_build_per_testsource) { #++++ Temporary workaround rather than changing `chip_link_tests` and `chip_build_tests` in `tests.gni` - print(" ++++ LINK ${_unique_suite_name}") tests = [] if (defined(invoker.test_sources)) { @@ -242,8 +127,17 @@ template("chip_test_suite") { _test_output_dir = invoker.output_dir } - print(" ++++ TEST ${_unique_suite_name} -- ${_test_name}") 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" diff --git a/src/lib/core/tests/BUILD.gn b/src/lib/core/tests/BUILD.gn index 001078019a7e83..30d50ee9493699 100644 --- a/src/lib/core/tests/BUILD.gn +++ b/src/lib/core/tests/BUILD.gn @@ -30,14 +30,9 @@ chip_test_suite("tests") { "TestOptional.cpp", "TestReferenceCounted.cpp", "TestTLV.cpp", + "TestTLVVectorWriter.cpp", ] - # requires large amount of heap for multiple unfragmented 10k buffers - # skip for efr32 to allow flash space for other tests - if (chip_device_platform != "efr32") { - test_sources += [ "TestTLVVectorWriter.cpp" ] - } - cflags = [ "-Wconversion" ] public_deps = [ From 939e516ae28d39b8c936aaa96e9d9b3291b6b7cc Mon Sep 17 00:00:00 2001 From: Jeff Feasel Date: Thu, 6 Jun 2024 18:56:57 +0000 Subject: [PATCH 7/7] Excluded a test source for efr32 due to lack of dirent.h --- src/credentials/tests/BUILD.gn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/credentials/tests/BUILD.gn b/src/credentials/tests/BUILD.gn index 766557d8126124..09c9238c0a0f99 100644 --- a/src/credentials/tests/BUILD.gn +++ b/src/credentials/tests/BUILD.gn @@ -56,7 +56,8 @@ chip_test_suite("tests") { ] # DUTVectors test requires which is not supported on all platforms - if (chip_device_platform != "openiotsdk" && chip_device_platform != "nxp") { + if (chip_device_platform != "openiotsdk" && chip_device_platform != "nxp" && + chip_device_platform != "efr32") { test_sources += [ "TestCommissionerDUTVectors.cpp" ] }