Skip to content

Commit

Permalink
[Silabs]Fix efr32 test driver event loop, run gtests, enable more tes…
Browse files Browse the repository at this point in the history
…t on efr… (#33430)

* Fix efr32 test driver event loop, run gtests, enable more test on efr32 test drivers

* add github issue in comments
  • Loading branch information
jmartinez-silabs committed May 14, 2024
1 parent 0608519 commit cf2d2bd
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ if (chip_build_tests) {
]
}

# Skip on efr32 due to flash and/or ram limitations.
if (chip_device_platform != "efr32") {
tests += [
# TODO(#10447): App test has HF on EFR32.
"${chip_root}/src/app/tests",
"${chip_root}/src/credentials/tests",
"${chip_root}/src/lib/format/tests",
Expand Down Expand Up @@ -128,7 +128,7 @@ if (chip_build_tests) {
# https://github.com/project-chip/connectedhomeip/issues/9630
if (chip_device_platform != "nrfconnect" &&
chip_device_platform != "efr32") {
# TODO(#10447): Controller test has HF on EFR32.
# Doesn't compile on ef32. Multiple definitions issues with attribute storage and overflows flash memory.
tests += [ "${chip_root}/src/controller/tests/data_model" ]

# Skip controller test for Open IoT SDK
Expand Down
7 changes: 6 additions & 1 deletion src/app/icd/server/tests/TestICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,10 +1061,15 @@ TEST_F(TestICDManager, TestICDStateObserverOnTransitionToIdleModeEqualActiveMode

// Expire IdleMode timer
AdvanceClockAndRunEventLoop(1_s);
EXPECT_FALSE(mICDStateObserver.mOnTransitionToIdleCalled);
// In this scenario, The ICD state machine kicked a OnTransitionToIdle timer with a duration of 0 seconds.
// The freeRTOS systemlayer timer calls a 0s timer's callback instantly while on posix it take and 1 addition event loop.
// Thefore, the expect result diverges here based on the systemlayer implementation. Skip this check.
// https://github.com/project-chip/connectedhomeip/issues/33441
// EXPECT_FALSE(mICDStateObserver.mOnTransitionToIdleCalled);

// Expire OnTransitionToIdleMode
AdvanceClockAndRunEventLoop(1_ms32);
// All systems should have called the OnTransitionToIdle callback by now.
EXPECT_TRUE(mICDStateObserver.mOnTransitionToIdleCalled);

// Reset Old durations
Expand Down
12 changes: 6 additions & 6 deletions src/inet/tests/TestInetCommonOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ NetworkOptions::NetworkOptions()
static OptionDef optionDefs[] = {
{ "local-addr", kArgumentRequired, 'a' },
{ "node-addr", kArgumentRequired, kToolCommonOpt_NodeAddr }, /* alias for local-addr */
#if CHIP_SYSTEM_CONFIG_USE_LWIP
#if CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
{ "tap-device", kArgumentRequired, kToolCommonOpt_TapDevice },
{ "ipv4-gateway", kArgumentRequired, kToolCommonOpt_IPv4GatewayAddr },
{ "ipv6-gateway", kArgumentRequired, kToolCommonOpt_IPv6GatewayAddr },
{ "dns-server", kArgumentRequired, 'X' },
{ "debug-lwip", kNoArgument, kToolCommonOpt_DebugLwIP },
{ "event-delay", kArgumentRequired, kToolCommonOpt_EventDelay },
{ "tap-system-config", kNoArgument, kToolCommonOpt_TapInterfaceConfig },
#endif
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
{}
};
OptionDefs = optionDefs;
Expand All @@ -69,7 +69,7 @@ NetworkOptions::NetworkOptions()
OptionHelp = " -a, --local-addr, --node-addr <ip-addr>\n"
" Local address for the node.\n"
"\n"
#if CHIP_SYSTEM_CONFIG_USE_LWIP
#if CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
" --tap-device <tap-dev-name>\n"
" TAP device name for LwIP hosted OS usage. Defaults to chip-dev-<node-id>.\n"
"\n"
Expand All @@ -91,22 +91,22 @@ NetworkOptions::NetworkOptions()
" --tap-system-config\n"
" Use configuration on each of the Linux TAP interfaces to configure LwIP's interfaces.\n"
"\n"
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
;

// Defaults.
LocalIPv4Addr.clear();
LocalIPv6Addr.clear();

#if CHIP_SYSTEM_CONFIG_USE_LWIP
#if CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
TapDeviceName.clear();
LwIPDebugFlags = 0;
EventDelay = 0;
IPv4GatewayAddr.clear();
IPv6GatewayAddr.clear();
DNSServerAddr = Inet::IPAddress::Any;
TapUseSystemConfig = false;
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
}

bool NetworkOptions::HandleOption(const char * progName, OptionSet * optSet, int id, const char * name, const char * arg)
Expand Down
4 changes: 2 additions & 2 deletions src/inet/tests/TestInetCommonOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ class NetworkOptions : public chip::ArgParser::OptionSetBase
std::vector<chip::Inet::IPAddress> LocalIPv4Addr;
std::vector<chip::Inet::IPAddress> LocalIPv6Addr;

#if CHIP_SYSTEM_CONFIG_USE_LWIP
#if CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
std::vector<chip::Inet::IPAddress> IPv4GatewayAddr;
std::vector<chip::Inet::IPAddress> IPv6GatewayAddr;
chip::Inet::IPAddress DNSServerAddr;
std::vector<const char *> TapDeviceName;
uint8_t LwIPDebugFlags;
uint32_t EventDelay;
bool TapUseSystemConfig;
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT

NetworkOptions();

Expand Down
8 changes: 4 additions & 4 deletions src/inet/tests/TestInetCommonPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void InitNetwork()
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
gTCP.Init(gSystemLayer);
#endif
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
#if INET_CONFIG_ENABLE_UDP_ENDPOINT
gUDP.Init(gSystemLayer);
#endif
}
Expand Down Expand Up @@ -368,14 +368,14 @@ void ServiceEvents(uint32_t aSleepTimeMilliseconds)
gSystemLayer.HandleEvents();
#endif

#if CHIP_SYSTEM_CONFIG_USE_LWIP
#if CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
if (gSystemLayer.IsInitialized())
{
static uint32_t sRemainingSystemLayerEventDelay = 0;

if (sRemainingSystemLayerEventDelay == 0)
{
#if CHIP_DEVICE_LAYER_TARGET_OPEN_IOT_SDK
#if CHIP_DEVICE_LAYER_TARGET_OPEN_IOT_SDK || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
// We need to terminate event loop after performance single step.
// Event loop processing work items until StopEventLoopTask is called.
// Scheduling StopEventLoop task guarantees correct operation of the loop.
Expand All @@ -390,7 +390,7 @@ void ServiceEvents(uint32_t aSleepTimeMilliseconds)

gSystemLayer.HandlePlatformTimer();
}
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
}

#if CHIP_SYSTEM_CONFIG_USE_LWIP && !(CHIP_SYSTEM_CONFIG_LWIP_SKIP_INIT)
Expand Down
7 changes: 6 additions & 1 deletion src/lib/core/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ 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 = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/support/UnitTestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ uint64_t TimeMonotonicMillis()

void SleepMillis(uint64_t millisecs)
{
uint32_t ticks = static_cast<uint32_t>(millisecs / portTICK_PERIOD_MS);
uint32_t ticks = pdMS_TO_TICKS(millisecs);
vTaskDelay(ticks == 0 ? 1 : ticks); // delay at least 1 tick
}

Expand Down
31 changes: 12 additions & 19 deletions src/messaging/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,20 @@ static_library("helpers") {
chip_test_suite_using_nltest("tests") {
output_name = "libMessagingLayerTests"

test_sources = []

if (chip_device_platform != "efr32") {
# TODO(#10447): ReliableMessage Test has HF, and ExchangeMgr hangs on EFR32.
# And TestAbortExchangesForFabric does not link on EFR32 for some reason.
# TODO #33372: TestExchange.cpp asserts in ExchangeContext::SendMessage
test_sources += [
"TestAbortExchangesForFabric.cpp",
"TestExchange.cpp",
"TestExchangeMgr.cpp",
"TestReliableMessageProtocol.cpp",
]
test_sources = [
"TestAbortExchangesForFabric.cpp",
"TestExchange.cpp",
"TestExchangeMgr.cpp",
"TestReliableMessageProtocol.cpp",
]

if (chip_device_platform != "esp32" && chip_device_platform != "mbed" &&
chip_device_platform != "nrfconnect" && chip_device_platform != "nxp") {
test_sources += [ "TestExchangeHolder.cpp" ]
}
if (chip_device_platform != "esp32" && chip_device_platform != "mbed" &&
chip_device_platform != "nrfconnect" && chip_device_platform != "nxp") {
test_sources += [ "TestExchangeHolder.cpp" ]
}

if (chip_device_platform == "linux") {
test_sources += [ "TestMessagingLayer.cpp" ]
}
if (chip_device_platform == "linux") {
test_sources += [ "TestMessagingLayer.cpp" ]
}

cflags = [ "-Wconversion" ]
Expand Down
2 changes: 2 additions & 0 deletions src/platform/silabs/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@
#endif /* CHIP_ENABLE_OPENTHREAD */
#endif /* defined(SL_WIFI) */

#ifndef CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1
#endif

#if defined(SL_WIFI)

Expand Down
4 changes: 2 additions & 2 deletions src/system/tests/TestSystemTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LayerEvents<LayerImpl, typename std::enable_if<std::is_base_of<LayerSocket

#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK

#if CHIP_SYSTEM_CONFIG_USE_LWIP
#if CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT

template <class LayerImpl>
class LayerEvents<LayerImpl, typename std::enable_if<std::is_base_of<LayerImplFreeRTOS, LayerImpl>::value>::type>
Expand All @@ -87,7 +87,7 @@ class LayerEvents<LayerImpl, typename std::enable_if<std::is_base_of<LayerImplFr
}
};

#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT

// Test input vector format.
static const uint32_t MAX_NUM_TIMERS = 1000;
Expand Down
2 changes: 1 addition & 1 deletion src/test_driver/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain")
chip_enable_pw_rpc = true
chip_build_tests = true
chip_enable_openthread = true
chip_openthread_ftd = true
chip_openthread_ftd = false # use mtd as it is smaller.
chip_monolithic_tests = true

openthread_external_platform =
Expand Down
2 changes: 1 addition & 1 deletion src/test_driver/efr32/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
*
* Enable support for Chip-over-BLE (CHIPoBLE).
*/
#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1
#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0

/**
* CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER
Expand Down
2 changes: 1 addition & 1 deletion src/test_driver/efr32/include/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ extern "C" {
/* Some of the standard demo test tasks assume a tick rate of 1KHz, even
though that is faster than would normally be warranted by a real
application. */
#define configTICK_RATE_HZ (1000)
#define configTICK_RATE_HZ (1024)

/* Energy saving modes. */
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
Expand Down
15 changes: 13 additions & 2 deletions src/test_driver/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
#include <FreeRTOS.h>
#include <PigweedLogger.h>
#include <PigweedLoggerMutex.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <cstring>
#include <examples/platform/silabs/SilabsDeviceAttestationCreds.h>
#include <lib/support/CHIPMem.h>
#include <lib/support/CHIPPlatformMemory.h>
#include <lib/support/UnitTest.h>
#include <lib/support/UnitTestRegistration.h>
#include <mbedtls/platform.h>
#include <nl_test_service/nl_test.rpc.pb.h>
Expand All @@ -37,6 +40,8 @@
#include <sl_system_kernel.h>
#include <task.h>

#include "SilabsDeviceDataProvider.h"

extern "C" int printf(const char * format, ...)
{
va_list args;
Expand All @@ -56,8 +61,11 @@ class NlTest : public pw_rpc::nanopb::NlTest::Service<NlTest>
stream_writer = &writer;
nlTestSetLogger(&nl_test_logger);

RunRegisteredUnitTests();

printf("--- Running nltest ---");
int status = RunRegisteredUnitTests();
printf("--- Running gtest ---");
status += chip::test::RunAllTests();
printf("Test status: %d", status);
stream_writer = nullptr;
writer.Finish();
}
Expand Down Expand Up @@ -194,6 +202,9 @@ int main(void)
chip::Platform::MemoryInit();

chip::DeviceLayer::PlatformMgr().InitChipStack();
// required for inits tied to the event loop
chip::DeviceLayer::SetDeviceInstanceInfoProvider(&chip::DeviceLayer::Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider());
chip::DeviceLayer::SetCommissionableDataProvider(&chip::DeviceLayer::Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider());

SILABS_LOG("***** CHIP EFR32 device tests *****\r\n");

Expand Down

0 comments on commit cf2d2bd

Please sign in to comment.