Skip to content

Commit

Permalink
[Mbed] Unit tests improvements (#11589)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ATmobica authored and pull[bot] committed Jun 13, 2023
1 parent 1477a9f commit 3867155
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
14 changes: 10 additions & 4 deletions src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
Expand Down
6 changes: 3 additions & 3 deletions src/inet/InetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,9 @@ short InterfaceIterator::GetFlags()
mIntfFlags = intfData.ifr_flags;
mIntfFlagsCached = true;
}
#if __MBED__
CloseIOCTLSocket();
#endif
}

return mIntfFlags;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/inet/tests/TestInetEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion src/platform/mbed/MbedConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void *>(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<void *>(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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/platform/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}

Expand Down
2 changes: 2 additions & 0 deletions src/platform/tests/TestConfigurationMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *>(mac6Bytes.data()), reinterpret_cast<const char *>(defaultMacAddress),
mac6Bytes.size()) == 0);
#endif
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/platform/tests/TestKeyValueStoreMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down

0 comments on commit 3867155

Please sign in to comment.