From 9c93583c56e38450a1ee936a10abc9314ad2736e Mon Sep 17 00:00:00 2001 From: Jakub Latusek Date: Tue, 23 Jan 2024 12:55:15 +0100 Subject: [PATCH] Add testing_pw library (#31550) * Add unity test run method * Add if statement with list of supported platform in pigweed * Make Tizen build only targets related to unit tests * Update library name --- build/chip/chip_test_group.gni | 13 ++++++++++--- scripts/build/builders/tizen.py | 1 + src/BUILD.gn | 34 +++++++++++++++++++-------------- src/lib/support/BUILD.gn | 18 +++++++++++++++++ src/lib/support/UnitTest.cpp | 14 ++++++++++++++ src/lib/support/UnitTest.h | 9 +++++++++ src/platform/tests/BUILD.gn | 2 +- 7 files changed, 73 insertions(+), 18 deletions(-) create mode 100644 src/lib/support/UnitTest.cpp create mode 100644 src/lib/support/UnitTest.h diff --git a/build/chip/chip_test_group.gni b/build/chip/chip_test_group.gni index bc092c46ab6bcd..9e26b19235e29c 100644 --- a/build/chip/chip_test_group.gni +++ b/build/chip/chip_test_group.gni @@ -39,10 +39,14 @@ template("chip_test_group") { [ "build_monolithic_library", "deps", + "tests", ]) deps = [] - foreach(_test, invoker.deps) { + if (defined(invoker.deps)) { + deps = invoker.deps + } + foreach(_test, invoker.tests) { deps += [ get_label_info(_test, "label_no_toolchain") + ".lib" ] } @@ -53,7 +57,7 @@ template("chip_test_group") { group("${_test_group_name}") { deps = [] - data_deps = invoker.deps + data_deps = invoker.tests if (_build_monolithic_library) { deps += [ ":${_lib_target_name}" ] @@ -64,7 +68,10 @@ template("chip_test_group") { group("${_test_group_name}_run") { if (chip_link_tests) { deps = [] - foreach(_test, invoker.deps) { + if (defined(invoker.deps)) { + deps = invoker.deps + } + foreach(_test, invoker.tests) { deps += [ get_label_info(_test, "label_no_toolchain") + "_run" ] } } diff --git a/scripts/build/builders/tizen.py b/scripts/build/builders/tizen.py index bc0a454b39222c..6b5cdd90ec77f0 100644 --- a/scripts/build/builders/tizen.py +++ b/scripts/build/builders/tizen.py @@ -116,6 +116,7 @@ def __init__(self, if app == TizenApp.TESTS: self.extra_gn_options.append('chip_build_tests=true') + self.build_command = 'check' if not enable_ble: self.extra_gn_options.append('chip_config_network_layer_ble=false') diff --git a/src/BUILD.gn b/src/BUILD.gn index c074f5e0df1150..ee3fd4d9c7a2ba 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -56,7 +56,8 @@ if (chip_build_tests) { import("${chip_root}/build/chip/chip_test_group.gni") chip_test_group("tests") { - deps = [ + deps = [] + tests = [ "${chip_root}/src/access/tests", "${chip_root}/src/crypto/tests", "${chip_root}/src/inet/tests", @@ -72,7 +73,7 @@ if (chip_build_tests) { # Skip DNSSD tests for Mbed platform due to flash memory size limitations if (current_os != "mbed") { - deps += [ + tests += [ "${chip_root}/src/lib/dnssd/minimal_mdns/core/tests", "${chip_root}/src/lib/dnssd/minimal_mdns/responders/tests", "${chip_root}/src/lib/dnssd/minimal_mdns/tests", @@ -81,19 +82,19 @@ if (chip_build_tests) { } if (current_os != "zephyr" && current_os != "mbed") { - deps += [ "${chip_root}/src/lib/dnssd/minimal_mdns/records/tests" ] + tests += [ "${chip_root}/src/lib/dnssd/minimal_mdns/records/tests" ] } if (current_os != "zephyr" && current_os != "mbed" && chip_device_platform != "efr32") { - deps += [ + tests += [ "${chip_root}/src/setup_payload/tests", "${chip_root}/src/transport/raw/tests", ] } if (chip_device_platform != "efr32") { - deps += [ + tests += [ # TODO(#10447): App test has HF on EFR32. "${chip_root}/src/app/tests", "${chip_root}/src/credentials/tests", @@ -106,21 +107,21 @@ if (chip_build_tests) { if (matter_enable_tracing_support && matter_trace_config == "multiplexed") { - deps += [ "${chip_root}/src/tracing/tests" ] + tests += [ "${chip_root}/src/tracing/tests" ] } } if (chip_device_platform != "none") { - deps += [ "${chip_root}/src/lib/dnssd/minimal_mdns/tests" ] + tests += [ "${chip_root}/src/lib/dnssd/minimal_mdns/tests" ] } if (chip_device_platform != "esp32" && chip_device_platform != "efr32" && chip_device_platform != "ameba") { - deps += [ "${chip_root}/src/platform/tests" ] + tests += [ "${chip_root}/src/platform/tests" ] } if (chip_config_network_layer_ble) { - deps += [ "${chip_root}/src/ble/tests" ] + tests += [ "${chip_root}/src/ble/tests" ] } # On nrfconnect, the controller tests run into @@ -128,21 +129,26 @@ if (chip_build_tests) { if (chip_device_platform != "nrfconnect" && chip_device_platform != "efr32") { # TODO(#10447): Controller test has HF on EFR32. - deps += [ "${chip_root}/src/controller/tests/data_model" ] + tests += [ "${chip_root}/src/controller/tests/data_model" ] # Skip controller test for Open IoT SDK # https://github.com/project-chip/connectedhomeip/issues/23747 if (chip_device_platform != "openiotsdk") { - deps += [ "${chip_root}/src/controller/tests" ] + tests += [ "${chip_root}/src/controller/tests" ] } } if (current_os != "zephyr" && current_os != "mbed" && chip_device_platform != "esp32" && chip_device_platform != "ameba") { - deps += [ "${chip_root}/src/lib/shell/tests" ] + tests += [ "${chip_root}/src/lib/shell/tests" ] } if (chip_monolithic_tests) { + # TODO [PW_MIGRATION] Remove this if after migartion to PW_TEST is completed for all platforms + # TODO [PW_MIGRATION] There will be a list of already migrated platforms + if (false) { + deps += [ "${chip_root}/src/lib/support:pw_tests_wrapper" ] + } build_monolithic_library = true output_name = "libCHIP_tests" output_dir = "${root_out_dir}/lib" @@ -150,12 +156,12 @@ if (chip_build_tests) { } chip_test_group("fake_platform_tests") { - deps = [ "${chip_root}/src/lib/dnssd/platform/tests" ] + tests = [ "${chip_root}/src/lib/dnssd/platform/tests" ] } # Tests to run with each Crypto PAL chip_test_group("crypto_tests") { - deps = [ + tests = [ "${chip_root}/src/credentials/tests", "${chip_root}/src/crypto/tests", ] diff --git a/src/lib/support/BUILD.gn b/src/lib/support/BUILD.gn index b02e4905ff5817..9f71492a5b3877 100644 --- a/src/lib/support/BUILD.gn +++ b/src/lib/support/BUILD.gn @@ -18,7 +18,9 @@ import("//build_overrides/nlassert.gni") import("//build_overrides/nlfaultinjection.gni") import("//build_overrides/nlio.gni") import("//build_overrides/nlunit_test.gni") +import("//build_overrides/pigweed.gni") +import("$dir_pw_build/target_types.gni") import("${chip_root}/build/chip/chip_version.gni") import("${chip_root}/build/chip/java/config.gni") import("${chip_root}/build/chip/tests.gni") @@ -309,6 +311,22 @@ static_library("test_utils") { ] } +pw_static_library("pw_tests_wrapper") { + if (chip_device_platform == "esp32") { + complete_static_lib = true + } + output_name = "libPWTestsWrapper" + output_dir = "${root_out_dir}/lib" + public_deps = [ + "$dir_pw_log:impl", + "$dir_pw_unit_test", + ] + sources = [ + "UnitTest.cpp", + "UnitTest.h", + ] +} + static_library("testing_nlunit") { output_name = "libSupportTesting" output_dir = "${root_out_dir}/lib" diff --git a/src/lib/support/UnitTest.cpp b/src/lib/support/UnitTest.cpp new file mode 100644 index 00000000000000..787898cccd82f2 --- /dev/null +++ b/src/lib/support/UnitTest.cpp @@ -0,0 +1,14 @@ +#include "UnitTest.h" + +#include "pw_unit_test/framework.h" + +namespace chip { +namespace test { + +int RunAllTests() +{ + return RUN_ALL_TESTS(); +} + +} // namespace test +} // namespace chip diff --git a/src/lib/support/UnitTest.h b/src/lib/support/UnitTest.h new file mode 100644 index 00000000000000..0cf8a8ef75356c --- /dev/null +++ b/src/lib/support/UnitTest.h @@ -0,0 +1,9 @@ +#pragma once + +namespace chip { +namespace test { + +int RunAllTests(); + +} // namespace test +} // namespace chip diff --git a/src/platform/tests/BUILD.gn b/src/platform/tests/BUILD.gn index 2a0d34577abd45..9bf03229eb2b68 100644 --- a/src/platform/tests/BUILD.gn +++ b/src/platform/tests/BUILD.gn @@ -98,6 +98,6 @@ if (chip_device_platform != "none" && chip_device_platform != "fake") { } else { import("${chip_root}/build/chip/chip_test_group.gni") chip_test_group("tests") { - deps = [] + tests = [] } }