From 41c25da696db0c52dc92f03a9039b3ef8a6ce063 Mon Sep 17 00:00:00 2001 From: Artur Tynecki <77382963+ATmobica@users.noreply.github.com> Date: Mon, 15 Nov 2021 22:57:36 +0100 Subject: [PATCH] [Mbed] Unit tests improvements (#11589) * Reduce unit test coverage for mbed - remove dnssd testing * Fix TestConfigurationMgr_GetPrimaryMACAddress for Mbed platform * Add TestKeyValueStoreMgr for Mbed platform Fix ReadConfigValueBin function for Mbed platform - check buffer size * Move CloseIOCTLSocket() function to the right place * Fix InetEndPoint test - skip InterfaceNameToId checking for Mbed * Fix condtion in TestKeyValueStoreMgr * Changes restyle * Add note to skip tests for Mbed platform --- src/BUILD.gn | 14 ++++++++++---- src/inet/InetInterface.cpp | 6 +++--- src/inet/tests/TestInetEndPoint.cpp | 3 +++ src/platform/mbed/MbedConfig.cpp | 14 +++++++++++++- src/platform/tests/BUILD.gn | 3 ++- src/platform/tests/TestConfigurationMgr.cpp | 2 ++ src/platform/tests/TestKeyValueStoreMgr.cpp | 4 ++-- 7 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/BUILD.gn b/src/BUILD.gn index 648b70a9f2028c..7fc30141f8018b 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -49,16 +49,22 @@ if (chip_build_tests) { "${chip_root}/src/inet/tests", "${chip_root}/src/lib/asn1/tests", "${chip_root}/src/lib/core/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", - "${chip_root}/src/lib/dnssd/tests", "${chip_root}/src/messaging/tests", "${chip_root}/src/protocols/bdx/tests", "${chip_root}/src/protocols/user_directed_commissioning/tests", "${chip_root}/src/transport/retransmit/tests", ] + # Skip DNSSD tests for Mbed platform due to flash memory size limitations + if (current_os != "mbed") { + deps += [ + "${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", + "${chip_root}/src/lib/dnssd/tests", + ] + } + if (current_os != "zephyr" && current_os != "mbed") { deps += [ "${chip_root}/src/lib/dnssd/minimal_mdns/records/tests" ] } diff --git a/src/inet/InetInterface.cpp b/src/inet/InetInterface.cpp index e769a0b369c8e2..ed6ce664cb6a8b 100644 --- a/src/inet/InetInterface.cpp +++ b/src/inet/InetInterface.cpp @@ -616,6 +616,9 @@ short InterfaceIterator::GetFlags() mIntfFlags = intfData.ifr_flags; mIntfFlagsCached = true; } +#if __MBED__ + CloseIOCTLSocket(); +#endif } return mIntfFlags; @@ -807,9 +810,6 @@ CHIP_ERROR InterfaceId::InterfaceNameToId(const char * intfName, InterfaceId & i interface = InterfaceId(currentId); return CHIP_NO_ERROR; } -#if __MBED__ - CloseIOCTLSocket(); -#endif } interface = InterfaceId::Null(); return INET_ERROR_UNKNOWN_INTERFACE; diff --git a/src/inet/tests/TestInetEndPoint.cpp b/src/inet/tests/TestInetEndPoint.cpp index 25c7b8bf8e5dbb..b3248d7f488db2 100644 --- a/src/inet/tests/TestInetEndPoint.cpp +++ b/src/inet/tests/TestInetEndPoint.cpp @@ -133,8 +133,11 @@ static void TestInetInterface(nlTestSuite * inSuite, void * inContext) IPPrefix addrWithPrefix; CHIP_ERROR err; +#ifndef __MBED__ + // Mbed interface name has different format err = InterfaceId::InterfaceNameToId("0", intId); NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR); +#endif err = InterfaceId::Null().GetInterfaceName(intName, 0); NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL); diff --git a/src/platform/mbed/MbedConfig.cpp b/src/platform/mbed/MbedConfig.cpp index 1bd769ed94187b..89a57234d0d70b 100644 --- a/src/platform/mbed/MbedConfig.cpp +++ b/src/platform/mbed/MbedConfig.cpp @@ -174,13 +174,25 @@ CHIP_ERROR MbedConfig::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; } - int err = kv_get(key, reinterpret_cast(buf), bufSize, &outLen); + kv_info_t info; + + int err = kv_get_info(key, &info); + if (err != MBED_SUCCESS) + { + return CHIP_ERROR_INTERNAL; + } + err = kv_get(key, reinterpret_cast(buf), bufSize, &outLen); if (err != MBED_SUCCESS) { return CHIP_ERROR_INTERNAL; } + if (bufSize < info.size) + { + return CHIP_ERROR_BUFFER_TOO_SMALL; + } + return CHIP_NO_ERROR; } diff --git a/src/platform/tests/BUILD.gn b/src/platform/tests/BUILD.gn index dcc61c3ef0cc45..f56ea9ce816700 100644 --- a/src/platform/tests/BUILD.gn +++ b/src/platform/tests/BUILD.gn @@ -75,7 +75,8 @@ if (chip_device_platform != "none" && chip_device_platform != "fake") { tests = [ "TestCHIPoBLEStackMgr" ] } - if (current_os == "zephyr" || current_os == "android") { + if (current_os == "zephyr" || current_os == "android" || + current_os == "mbed") { test_sources += [ "TestKeyValueStoreMgr.cpp" ] } diff --git a/src/platform/tests/TestConfigurationMgr.cpp b/src/platform/tests/TestConfigurationMgr.cpp index d8d883f0937e60..1d0b6398f86e68 100644 --- a/src/platform/tests/TestConfigurationMgr.cpp +++ b/src/platform/tests/TestConfigurationMgr.cpp @@ -232,10 +232,12 @@ static void TestConfigurationMgr_GetPrimaryMACAddress(nlTestSuite * inSuite, voi { NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); +#ifndef __MBED__ // Verify default MAC address value NL_TEST_ASSERT(inSuite, strncmp(reinterpret_cast(mac6Bytes.data()), reinterpret_cast(defaultMacAddress), mac6Bytes.size()) == 0); +#endif } } diff --git a/src/platform/tests/TestKeyValueStoreMgr.cpp b/src/platform/tests/TestKeyValueStoreMgr.cpp index 6c1efa54445666..938e6b476c2f00 100644 --- a/src/platform/tests/TestKeyValueStoreMgr.cpp +++ b/src/platform/tests/TestKeyValueStoreMgr.cpp @@ -230,8 +230,8 @@ static const nlTest sTests[] = { NL_TEST_DEF("Test KeyValueStoreMgr_EmptyStringK NL_TEST_DEF("Test KeyValueStoreMgr_StructKey", TestKeyValueStoreMgr_StructKey), NL_TEST_DEF("Test KeyValueStoreMgr_UpdateKeyValue", TestKeyValueStoreMgr_UpdateKeyValue), NL_TEST_DEF("Test KeyValueStoreMgr_TooSmallBufferRead", TestKeyValueStoreMgr_TooSmallBufferRead), -#ifndef __ZEPHYR__ - // Zephyr platform does not support partial or offset reads yet. +#if !defined(__ZEPHYR__) && !defined(__MBED__) + // Zephyr and Mbed platforms do not support partial or offset reads yet. NL_TEST_DEF("Test KeyValueStoreMgr_MultiReadKey", TestKeyValueStoreMgr_MultiReadKey), #endif #ifdef __ZEPHYR__