From 6af00a30b7e996525924cba5cadd0509e8e6592e Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Sun, 3 Mar 2024 12:49:34 -0500 Subject: [PATCH] Fix to build efr32 test driver with openthread Inet endpoint instead of lwip (so it uses the same config as our sample apps). Add to implement additional InetInterface method that were missing for the openthread inet endpoint interface. Make TestInetAddress.cpp work for CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT --- src/inet/InetInterface.cpp | 35 +++++++++++++++++++ src/inet/tests/TestInetAddress.cpp | 55 ++++++++++++++++++++++++------ src/test_driver/efr32/args.gni | 5 --- 3 files changed, 79 insertions(+), 16 deletions(-) diff --git a/src/inet/InetInterface.cpp b/src/inet/InetInterface.cpp index 4a404a29db177c..a893f80f4d605b 100644 --- a/src/inet/InetInterface.cpp +++ b/src/inet/InetInterface.cpp @@ -113,6 +113,23 @@ bool InterfaceIterator::Next() return false; } +CHIP_ERROR InterfaceIterator::GetInterfaceName(char * nameBuf, size_t nameBufSize) +{ + VerifyOrReturnError(HasCurrent(), CHIP_ERROR_INCORRECT_STATE); + return InterfaceId(1).GetInterfaceName(nameBuf, nameBufSize); +} + +InterfaceId InterfaceIterator::GetInterfaceId() +{ + // only 1 interface is supported + return HasCurrent() ? InterfaceId(1) : InterfaceId::Null(); +} + +bool InterfaceIterator::IsUp() +{ + return HasCurrent() && (otThreadGetDeviceRole(Inet::globalOtInstance) != OT_DEVICE_ROLE_DISABLED); +} + InterfaceAddressIterator::InterfaceAddressIterator() { mNetifAddrList = nullptr; @@ -128,6 +145,8 @@ bool InterfaceAddressIterator::Next() { if (mNetifAddrList == nullptr) { + if (Inet::globalOtInstance == nullptr) + return false; mNetifAddrList = otIp6GetUnicastAddresses(Inet::globalOtInstance); mCurAddr = mNetifAddrList; } @@ -155,6 +174,22 @@ uint8_t InterfaceAddressIterator::GetPrefixLength() return 64; } +bool InterfaceAddressIterator::IsUp() +{ + return HasCurrent() && (otThreadGetDeviceRole(Inet::globalOtInstance) != OT_DEVICE_ROLE_DISABLED); +} + +InterfaceId InterfaceAddressIterator::GetInterfaceId() +{ + // only 1 interface is supported + return HasCurrent() ? InterfaceId(1) : InterfaceId::Null(); +} + +bool InterfaceAddressIterator::HasBroadcastAddress() +{ + return HasCurrent() && (otIp6GetMulticastAddresses(Inet::globalOtInstance) != nullptr); +} + #endif #if CHIP_SYSTEM_CONFIG_USE_LWIP && !CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT diff --git a/src/inet/tests/TestInetAddress.cpp b/src/inet/tests/TestInetAddress.cpp index 7e796ca05fc340..426d6b7141753c 100644 --- a/src/inet/tests/TestInetAddress.cpp +++ b/src/inet/tests/TestInetAddress.cpp @@ -35,6 +35,11 @@ #include +#elif CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT +#include +#include +#include + #else #include #include @@ -718,12 +723,6 @@ void CheckAddress(nlTestSuite * inSuite, const IPAddressContext & inContext, con CheckAddressQuartets(inSuite, inContext, inAddress); - // Convert the address to a string and compare it to the control string. - - inAddress.ToString(lAddressBuffer); - - CheckAddressString(inSuite, lAddressBuffer, inContext.mAddrString); - // Convert the control string to an address and compare the parsed address to the created address. lResult = IPAddress::FromString(inContext.mAddrString, lParsedAddress); @@ -735,6 +734,21 @@ void CheckAddress(nlTestSuite * inSuite, const IPAddressContext & inContext, con { fprintf(stdout, "Address parse mismatch for %s\n", inContext.mAddrString); } + + // Convert the address to a string and compare it to the control string. + + inAddress.ToString(lAddressBuffer); +#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT + // Embedded openthread stack otIp6AddressFromString format the string as a uncompressed IPV6 + // example ff01::1 is formatted has ff01:0:0:0:0:0:0:1 + // But the IPV6 address From string API (otIp6AddressFromString) handle both compressed and uncompressed format. + char uncompressedAddrStr[INET6_ADDRSTRLEN]; + // Reconvert the previously parsed control string to an uncompressed string format + lParsedAddress.ToString(uncompressedAddrStr); + CheckAddressString(inSuite, lAddressBuffer, uncompressedAddrStr); +#else + CheckAddressString(inSuite, lAddressBuffer, inContext.mAddrString); +#endif } // Test functions invoked from the suite. @@ -786,9 +800,22 @@ void CheckToString(nlTestSuite * inSuite, void * inContext) SetupIPAddress(lAddress, lCurrent); lAddress.ToString(lAddressBuffer); - +#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT + // Embedded openthread stack otIp6AddressFromString format the string as a uncompressed IPV6 + // So ff01::1 is formatted has ff01:0:0:0:0:0:0:1 + // But the IPV6 address From string API (otIp6AddressFromString) handle both compressed and uncompressed format. + // For this test, pass the expected, compressed, string throught the opentread stack address format API + // so the final check evaluates uncompressed IPV6 strings. + char uncompressedAddrStr[INET6_ADDRSTRLEN]; + IPAddress tempIpAddr; + // Set Expected compressed IPV6 String as otIpv6 Address + IPAddress::FromString(lCurrent->mAddr.mAddrString, strlen(lCurrent->mAddr.mAddrString), tempIpAddr); + // Reconvert the expected IPV6 String to an uncompressed string format + tempIpAddr.ToString(uncompressedAddrStr); + CheckAddressString(inSuite, lAddressBuffer, uncompressedAddrStr); +#else CheckAddressString(inSuite, lAddressBuffer, lCurrent->mAddr.mAddrString); - +#endif // CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT ++lCurrent; } } @@ -1015,6 +1042,9 @@ void CheckToIPv6(nlTestSuite * inSuite, void * inContext) #if LWIP_IPV6_SCOPES ip_addr_1.zone = 0; #endif +#elif CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT + otIp6Address ip_addr_1 = { 0 }, ip_addr_2 = { 0 }; + memcpy(ip_addr_1.mFields.m32, addr, sizeof(addr)); #else struct in6_addr ip_addr_1, ip_addr_2; ip_addr_1 = *reinterpret_cast(addr); @@ -1052,6 +1082,9 @@ void CheckFromIPv6(nlTestSuite * inSuite, void * inContext) #if CHIP_SYSTEM_CONFIG_USE_LWIP ip6_addr_t ip_addr; memcpy(ip_addr.addr, addr, sizeof(addr)); +#elif CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT + otIp6Address ip_addr; + memcpy(ip_addr.mFields.m32, addr, sizeof(addr)); #else struct in6_addr ip_addr; ip_addr = *reinterpret_cast(addr); @@ -1203,9 +1236,9 @@ void CheckFromIPv4(nlTestSuite * inSuite, void * inContext) */ void CheckFromSocket(nlTestSuite * inSuite, void * inContext) { -#if CHIP_SYSTEM_CONFIG_USE_LWIP +#if CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT (void) inSuite; - // This test is only supported for non LWIP stack. + // This test is not supported LWIP or OPEN_THREAD_ENDPOINT stacks. #else // CHIP_SYSTEM_CONFIG_USE_LWIP const struct TestContext * lContext = static_cast(inContext); IPAddressExpandedContextIterator lCurrent = lContext->mIPAddressExpandedContextRange.mBegin; @@ -1261,7 +1294,7 @@ void CheckFromSocket(nlTestSuite * inSuite, void * inContext) ++lCurrent; } -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP +#endif // CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT } /** diff --git a/src/test_driver/efr32/args.gni b/src/test_driver/efr32/args.gni index a8d442d5c2140e..eaace30f8c3d75 100644 --- a/src/test_driver/efr32/args.gni +++ b/src/test_driver/efr32/args.gni @@ -29,9 +29,4 @@ chip_monolithic_tests = true openthread_external_platform = "${chip_root}/third_party/openthread/platforms/efr32:libopenthread-efr32" -#Fix me : Test driver should use same config as examples -# Problem : Linker issue if set to true -chip_system_config_use_open_thread_inet_endpoints = false -chip_with_lwip = true - pw_rpc_CONFIG = "$dir_pw_rpc:disable_global_mutex"