From 1245cb79d5d5f97490815578504f84049665e808 Mon Sep 17 00:00:00 2001 From: ActoryOu Date: Fri, 18 Oct 2024 02:40:41 +0000 Subject: [PATCH] 100% UT coverage --- .../unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c b/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c index afb69714e..fb30cb402 100644 --- a/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c +++ b/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c @@ -1920,6 +1920,27 @@ void test_FreeRTOS_CreateIPv6Address_Pass2( void ) TEST_ASSERT_EQUAL( xReturn, pdPASS ); } +/** + * @brief Create an IPv6 address, based on a prefix. + * with the bits after the prefix having random value + * and uxPrefixLength is 128 bites. + */ +void test_FreeRTOS_CreateIPv6Address_Pass3( void ) +{ + IPv6_Address_t xIPAddress, xPrefix; + size_t uxPrefixLength = 128; + BaseType_t xDoRandom = pdTRUE, xReturn, xIndex; + + for( xIndex = 0; xIndex < 4; xIndex++ ) + { + xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); + } + + xReturn = FreeRTOS_CreateIPv6Address( &xIPAddress, &xPrefix, uxPrefixLength, xDoRandom ); + + TEST_ASSERT_EQUAL( xReturn, pdPASS ); +} + /** * @brief Cover all the pcMessageType print * scenario. @@ -2099,6 +2120,28 @@ void test_xCheckRequiresNDResolution_Miss( void ) TEST_ASSERT_EQUAL( pdTRUE, xResult ); } +/** + * @brief Trigger assertion when Ethernet frame type is not IPv6 while calling xCheckRequiresNDResolution. + */ +void test_xCheckRequiresNDResolution_AssertInvalidFrameType( void ) +{ + struct xNetworkEndPoint xEndPoint = { 0 }; + NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer; + uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ]; + BaseType_t xResult; + + ( void ) memset( xNDCache, 0, sizeof( xNDCache ) ); + + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pxEndPoint = &xEndPoint; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); + IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); + pxIPPacket->xEthernetHeader.usFrameType = ipIPv4_FRAME_TYPE; + + catch_assert( xCheckRequiresNDResolution( pxNetworkBuffer ) ); +} + /** * @brief Toggle vNDSendUnsolicited. */