diff --git a/.github/.cSpellWords.txt b/.github/.cSpellWords.txt index d192c57c5..ed12e1e9c 100644 --- a/.github/.cSpellWords.txt +++ b/.github/.cSpellWords.txt @@ -454,6 +454,7 @@ FPSP FRAMERX FRMFILTER frms +fsanitize FSDMA FTSR FUDUP diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ff3e72a4..4a1de02ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,27 +38,56 @@ jobs: echo "::endgroup::" echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" + # Separate builds for sanitizers and coverage: + # These can currently not be combined without branch coverage dilution. - env: - stepName: Build Unit Tests + stepName: Build Unit Tests (aubsan build) name: ${{ env.stepName }} run: | # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" - cmake -S test/unit-test -B test/unit-test/build/ -G Ninja - cmake --build test/unit-test/build/ --target all + cmake --fresh -G Ninja -S test/unit-test -B test/unit-test/build/ -DSANITIZE=address,undefined + ninja -C test/unit-test/build/ echo "::endgroup::" echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" - env: - stepName: Run Unit Tests + stepName: Run Unit Tests (aubsan build) name: ${{ env.stepName }} shell: bash run: | # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" + env ASAN_OPTIONS=detect_odr_violation=0 ctest --test-dir test/unit-test/build/ -E system --output-on-failure + + echo "::endgroup::" + echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" + + - env: + stepName: Build Unit Tests (coverage build) + name: ${{ env.stepName }} + run: | + # ${{ env.stepName }} + echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" + + cmake --fresh -G Ninja -S test/unit-test -B test/unit-test/build/ -DSANITIZE= + ninja -C test/unit-test/build/ + + echo "::endgroup::" + echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" + + - env: + stepName: Run Unit Tests (coverage build) + name: ${{ env.stepName }} + shell: bash + run: | + # ${{ env.stepName }} + echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" + + find test/unit-test/build/ -name '*.gcda' -delete ctest --test-dir test/unit-test/build/ -E system --output-on-failure echo "::endgroup::" diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index 0bc202954..b29eb0cfe 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -656,7 +656,7 @@ if( ulIPAddress != 0UL ) { #if ( ipconfigUSE_IPv6 != 0 ) - if( ( ppxAddressInfo != NULL ) && ( ( *ppxAddressInfo )->ai_family == FREERTOS_AF_INET6 ) ) + if( ( ppxAddressInfo != NULL ) && ( *ppxAddressInfo != NULL ) && ( ( *ppxAddressInfo )->ai_family == FREERTOS_AF_INET6 ) ) { FreeRTOS_printf( ( "prvPrepareLookup: found '%s' in cache: %pip\n", pcHostName, ( void * ) ( *ppxAddressInfo )->xPrivateStorage.sockaddr.sin_address.xIP_IPv6.ucBytes ) ); diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index de9e14dff..528224b40 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -627,7 +627,14 @@ * active connect(). */ if( pxSocket->u.xTCP.ucRepCount < 3U ) { - ulDelayMs = ( ( ( uint32_t ) 3000U ) << ( pxSocket->u.xTCP.ucRepCount - 1U ) ); + if( pxSocket->u.xTCP.ucRepCount == 0U ) + { + ulDelayMs = 0U; + } + else + { + ulDelayMs = ( ( uint32_t ) 3000U ) << ( pxSocket->u.xTCP.ucRepCount - 1U ); + } } else { diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index 253cf45b2..cac757688 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -18,6 +18,12 @@ if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} ) message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." ) endif() +set(SANITIZE "" CACHE STRING "Comma-separated list of compiler sanitizers to enable; empty string disables.") +if(NOT ${SANITIZE} STREQUAL "") + add_compile_options(-fsanitize=${SANITIZE} -fno-sanitize-recover) + add_link_options(-fsanitize=${SANITIZE} -fno-sanitize-recover) +endif() + # Set global path variables. get_filename_component( __MODULE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE ) set( MODULE_ROOT_DIR ${__MODULE_ROOT_DIR} CACHE INTERNAL "FreeRTOS-Plus-TCP repository root." ) diff --git a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c index 3d733142e..dcb4e13dd 100644 --- a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c +++ b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c @@ -2034,29 +2034,34 @@ void test_eARPGetCacheEntryByMac_OneMatchingEntry( void ) eARPLookupResult_t eResult; MACAddress_t xMACAddress = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }; int i; - struct xNetworkInterface * xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; + NetworkInterface_t xInterface, * pxInterface = NULL; + + xNetworkEndPoint.pxNetworkInterface = &xInterface; /* =================================================== */ /* Make sure one entry matches. */ for( i = 0; i < ipconfigARP_CACHE_ENTRIES; i++ ) { xARPCache[ i ].ulIPAddress = 0xAABBCCDD; + xARPCache[ i ].pxEndPoint = &xNetworkEndPoint; memset( xARPCache[ i ].xMACAddress.ucBytes, 0x11, sizeof( xMACAddress.ucBytes ) ); } ulEntryToTest = 1; memset( xARPCache[ ulEntryToTest ].xMACAddress.ucBytes, 0x22, sizeof( xMACAddress.ucBytes ) ); xARPCache[ ulEntryToTest ].ulIPAddress = 0xAABBCCEE; - eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, &xInterface ); + eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, &pxInterface ); TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); TEST_ASSERT_EQUAL( xARPCache[ ulEntryToTest ].ulIPAddress, ulIPAddress ); + TEST_ASSERT_EQUAL( &xInterface, pxInterface ); /* =================================================== */ eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, NULL ); TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); TEST_ASSERT_EQUAL( xARPCache[ ulEntryToTest ].ulIPAddress, ulIPAddress ); /* =================================================== */ xARPCache[ ulEntryToTest ].pxEndPoint = NULL; - eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, &xInterface ); + eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, &pxInterface ); TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); TEST_ASSERT_EQUAL( xARPCache[ ulEntryToTest ].ulIPAddress, ulIPAddress ); /* =================================================== */ @@ -2305,6 +2310,7 @@ void test_eARPGetCacheEntry_NoCacheHit( void ) { xARPCache[ i ].ulIPAddress = 0; xARPCache[ i ].ucValid = ( uint8_t ) pdTRUE; + xARPCache[ i ].pxEndPoint = NULL; } ulSavedGatewayAddress = xNetworkAddressing.ulGatewayAddress; diff --git a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c index 055650710..350372d89 100644 --- a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c +++ b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c @@ -12,6 +12,11 @@ #include "FreeRTOS_IP.h" #include "FreeRTOS_IP_Private.h" +#define prvROUND_UP_TO( SIZE, ALIGNMENT ) ( ( ( SIZE ) + ( ALIGNMENT ) -1 ) / ( ALIGNMENT ) *( ALIGNMENT ) ) + +/* FIXME: Consider instead fixing ipBUFFER_PADDING if it's supposed to be pointer aligned. */ +#define prvALIGNED_BUFFER_PADDING prvROUND_UP_TO( ipBUFFER_PADDING, sizeof( void * ) ) + struct xNetworkEndPoint * pxNetworkEndPoints = NULL; NetworkInterface_t xInterfaces[ 1 ]; @@ -212,9 +217,9 @@ static NetworkBufferDescriptor_t * GetNetworkBuffer( size_t SizeOfEthBuf, long unsigned int xTimeToBlock, int callbacks ) { - NetworkBufferDescriptor_t * pxNetworkBuffer = malloc( sizeof( NetworkBufferDescriptor_t ) + ipBUFFER_PADDING ) + ipBUFFER_PADDING; + NetworkBufferDescriptor_t * pxNetworkBuffer = malloc( sizeof( NetworkBufferDescriptor_t ) + prvALIGNED_BUFFER_PADDING ) + prvALIGNED_BUFFER_PADDING; - pxNetworkBuffer->pucEthernetBuffer = malloc( SizeOfEthBuf + ipBUFFER_PADDING ) + ipBUFFER_PADDING; + pxNetworkBuffer->pucEthernetBuffer = malloc( SizeOfEthBuf + prvALIGNED_BUFFER_PADDING ) + prvALIGNED_BUFFER_PADDING; /* Ignore the callback count. */ ( void ) callbacks; @@ -230,9 +235,9 @@ static NetworkBufferDescriptor_t * GetNetworkBuffer( size_t SizeOfEthBuf, static void ReleaseNetworkBuffer( void ) { /* Free the ethernet buffer. */ - free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ --GlobalBufferCounter ]->pucEthernetBuffer ) - ipBUFFER_PADDING ); + free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ --GlobalBufferCounter ]->pucEthernetBuffer ) - prvALIGNED_BUFFER_PADDING ); /* Free the network buffer. */ - free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ GlobalBufferCounter ] ) - ipBUFFER_PADDING ); + free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ GlobalBufferCounter ] ) - prvALIGNED_BUFFER_PADDING ); } static void ReleaseUDPBuffer( const void * temp, @@ -289,19 +294,19 @@ static int32_t FreeRTOS_recvfrom_Generic( const ConstSocket_t xSocket, return ulGenericLength; } -static int32_t FreeRTOS_recvfrom_Generic_NullBuffer( const ConstSocket_t xSocket, - void * pvBuffer, - size_t uxBufferLength, - BaseType_t xFlags, - struct freertos_sockaddr * pxSourceAddress, - socklen_t * pxSourceAddressLength, - int callbacks ) +static int32_t FreeRTOS_recvfrom_Small_NullBuffer( const ConstSocket_t xSocket, + void * pvBuffer, + size_t uxBufferLength, + BaseType_t xFlags, + struct freertos_sockaddr * pxSourceAddress, + socklen_t * pxSourceAddressLength, + int callbacks ) { - pvBuffer = NULL; - return xSizeofUDPBuffer; + /* Admittedly, returning a (NULL, 1) slice is contrived, but coverage speaks. */ + *( ( uint8_t ** ) pvBuffer ) = NULL; + return 1; } - static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromLessBytesNoTimeout( const ConstSocket_t xSocket, void * pvBuffer, size_t uxBufferLength, @@ -336,7 +341,7 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_ pxIterator = pxIterator->pxNext; } - if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK ) + if( ( xFlags & FREERTOS_ZERO_COPY ) != 0 ) { *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer; } diff --git a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c index 7da21e358..dfe97e403 100644 --- a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c +++ b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c @@ -53,6 +53,38 @@ extern uint8_t pucUDPBuffer[]; extern uint8_t DHCP_header[]; +/*-------------------------------------Helpers--------------------------------*/ + +static void prvWriteDHCPOption( uint8_t ** ppucBuf, + uint8_t ucOp, + const void * pvPayload, + uint8_t ucLen ) +{ + uint8_t * pucBuf = *ppucBuf; + + *pucBuf++ = ucOp; + *pucBuf++ = ucLen; + memcpy( pucBuf, pvPayload, ucLen ); + pucBuf += ucLen; + + *ppucBuf = pucBuf; +} + +static void prvWriteDHCPOptionU8( uint8_t ** ppucBuf, + uint8_t ucOp, + uint8_t ucPayload ) +{ + prvWriteDHCPOption( ppucBuf, ucOp, &ucPayload, sizeof( ucPayload ) ); +} + +static void prvWriteDHCPOptionU32( uint8_t ** ppucBuf, + uint8_t ucOp, + uint32_t ulPayload ) +{ + /* TBD: htonl(ulPayload)? */ + prvWriteDHCPOption( ppucBuf, ucOp, &ulPayload, sizeof( ulPayload ) ); +} + /*---------------------------------------Test Cases--------------------------*/ void test_xIsDHCPSocket( void ) { @@ -1554,9 +1586,7 @@ void test_vDHCPProcessEndPoint_eWaitingOfferNullUDPBuffer( void ) pxNetworkEndPoints = pxEndPoint; - FreeRTOS_recvfrom_ExpectAndReturn( xDHCPv4Socket, NULL, 0UL, FREERTOS_ZERO_COPY, NULL, NULL, 1 ); - /* Ignore the buffer argument though. */ - FreeRTOS_recvfrom_IgnoreArg_pvBuffer(); + FreeRTOS_recvfrom_Stub( FreeRTOS_recvfrom_Small_NullBuffer ); vDHCPProcessEndPoint( pdFALSE, pdTRUE, pxEndPoint ); } @@ -2654,7 +2684,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsSendFails( void /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -2751,7 +2781,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsSendSucceeds( vo /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -2853,7 +2883,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsDHCPHookReturnDe /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -2952,7 +2982,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsDHCPHookReturnEr /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3052,7 +3082,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerNoTimeout( vo /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -3137,7 +3167,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutGNBfai /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -3227,7 +3257,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutGNBSuc /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3322,7 +3352,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutPeriod /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3407,7 +3437,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutPeriod /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3493,7 +3523,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsCorrectServerLeaseTimeZero( /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3594,7 +3624,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsCorrectServerLeaseTimeLessTh /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3693,7 +3723,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_CorrectServer_AptLeaseTime /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3791,7 +3821,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_NACK( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3878,7 +3908,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_OFFER( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3980,7 +4010,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -3988,7 +4018,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + memcpy( &DHCPOption[ 2 ], &ulSubnetMask, sizeof( ulSubnetMask ) ); DHCPOption += 6; /* Add Message type code. */ @@ -3996,7 +4026,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4004,7 +4034,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + memcpy( &DHCPOption[ 2 ], &ulLeaseTime, sizeof( ulLeaseTime ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4012,7 +4042,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulDNSServer; + memcpy( &DHCPOption[ 2 ], &ulDNSServer, sizeof( ulDNSServer ) ); /* Put the information in global variables to be returned by @@ -4126,7 +4156,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4134,7 +4164,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + memcpy( &DHCPOption[ 2 ], &ulSubnetMask, sizeof( ulSubnetMask ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4142,7 +4172,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4150,7 +4180,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + memcpy( &DHCPOption[ 2 ], &ulLeaseTime, sizeof( ulLeaseTime ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4158,7 +4188,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulDNSServer; + memcpy( &DHCPOption[ 2 ], &ulDNSServer, sizeof( ulDNSServer ) ); /* Put the information in global variables to be returned by @@ -4273,7 +4303,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4281,7 +4311,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + memcpy( &DHCPOption[ 2 ], &ulSubnetMask, sizeof( ulSubnetMask ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4289,7 +4319,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4297,7 +4327,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + memcpy( &DHCPOption[ 2 ], &ulLeaseTime, sizeof( ulLeaseTime ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4305,7 +4335,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 3; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulDNSServer; + memcpy( &DHCPOption[ 2 ], &ulDNSServer, sizeof( ulDNSServer ) ); /* Put the information in global variables to be returned by @@ -4363,33 +4393,29 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) TEST_ASSERT_EQUAL( xIPv4Addressing->ulNetMask, ulSubnetMask ); } -void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) +void test_vDHCPProcess_eWaitingAcknowledge_DNSServerOverabundance( void ) { struct xSOCKET xTestSocket; - TickType_t xTimeValue = 1234; - /* Create a bit longer DHCP message but keep it empty. */ - const BaseType_t xTotalLength = sizeof( struct xDHCPMessage_IPv4 ) + 1U /* Padding */ - + 3U /* DHCP offer */ - + 6U /* Server IP address */ - + 6U /* Subnet Mask */ - + 6U /* Gateway */ - + 6U /* Lease time */ - + 24U /* DNS server */ - + 1U /* End */; - uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulClientIPAddress = 0xC0A8000A; /* 192.168.0.10 */ uint32_t ulSubnetMask = 0xFFFFF100; /* 255.255.241.0 */ uint32_t ulGateway = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulLeaseTime = 0x00000096; /* 150 seconds */ uint32_t ulDNSServer = 0xC0010101; /* 192.1.1.1 */ + uint8_t DHCPMsg[ + sizeof( DHCPMessage_IPv4_t ) + + 2U + sizeof( ( uint8_t ) dhcpMESSAGE_TYPE_ACK ) + + 2U + sizeof( DHCPServerAddress ) + + 2U + sizeof( ulSubnetMask ) + + 2U + sizeof( ulGateway ) + + 2U + sizeof( ulLeaseTime ) + + 2U + sizeof( ulDNSServer ) * ( ipconfigENDPOINT_DNS_ADDRESS_COUNT + 1 ) + ]; DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; IPV4Parameters_t * xIPv4Addressing = &( pxEndPoint->ipv4_settings ); - - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - + size_t xDNSServersToAdd = ipconfigENDPOINT_DNS_ADDRESS_COUNT + 1; /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); @@ -4404,8 +4430,8 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Set the client IP address. */ pxDHCPMessage->ulYourIPAddress_yiaddr = ulClientIPAddress; - /* Leave one byte for the padding. */ - uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; + uint8_t * DHCPOption = &DHCPMsg[ sizeof( DHCPMessage_IPv4_t ) ]; + /* Add Message type code. */ DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; /* Add length. */ @@ -4413,13 +4439,13 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Add the offer byte. */ DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - DHCPOption += 4; + DHCPOption += 3; /* Add Message type code. */ DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4427,7 +4453,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + memcpy( &DHCPOption[ 2 ], &ulSubnetMask, sizeof( ulSubnetMask ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4435,7 +4461,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4443,21 +4469,29 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + memcpy( &DHCPOption[ 2 ], &ulLeaseTime, sizeof( ulLeaseTime ) ); DHCPOption += 6; /* Add Message type code. */ DHCPOption[ 0 ] = dhcpIPv4_DNS_SERVER_OPTIONS_CODE; /* Add length. */ - DHCPOption[ 1 ] = 24; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulDNSServer; + DHCPOption[ 1 ] = xDNSServersToAdd * sizeof( ulDNSServer ); + DHCPOption += 2; + while( xDNSServersToAdd-- > 0U ) + { + memcpy( DHCPOption, &ulDNSServer, sizeof( ulDNSServer ) ); + DHCPOption += sizeof( ulDNSServer ); + } + + /* A stop byte shall not be necessary to prevent the DHCP option parser from running off the end of the buffer. */ + /* *DHCPOption++ = 0xFF; */ + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, sizeof( DHCPMsg ) ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ ucGenericPtr = DHCPMsg; - ulGenericLength = sizeof( DHCPMsg ) + 100; /* ulGenericLength is incremented by 100 to have uxDNSCount > ipconfigENDPOINT_DNS_ADDRESS_COUNT scenario */ + ulGenericLength = sizeof( DHCPMsg ); /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; @@ -4534,9 +4568,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress( void ) NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; IPV4Parameters_t * xIPv4Addressing = &( pxEndPoint->ipv4_settings ); - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -4552,53 +4583,16 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_LEASE_TIME_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_DNS_SERVER_OPTIONS_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = FREERTOS_INADDR_ANY; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_GATEWAY_OPTION_CODE, ulGateway ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_LEASE_TIME_OPTION_CODE, ulLeaseTime ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_DNS_SERVER_OPTIONS_CODE, FREERTOS_INADDR_ANY ); + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -4680,9 +4674,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress2( void ) NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; IPV4Parameters_t * xIPv4Addressing = &( pxEndPoint->ipv4_settings ); - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -4698,53 +4689,16 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress2( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_LEASE_TIME_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_DNS_SERVER_OPTIONS_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ipBROADCAST_IP_ADDRESS; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_GATEWAY_OPTION_CODE, ulGateway ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_LEASE_TIME_OPTION_CODE, ulLeaseTime ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_DNS_SERVER_OPTIONS_CODE, ipBROADCAST_IP_ADDRESS ); + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -4817,9 +4771,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_IPv4ServerIncorrectLength( void ) uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulClientIPAddress = 0xC0A8000A; /* 192.168.0.10 */ - uint32_t ulSubnetMask = 0xFFFFF100; /* 255.255.241.0 */ - uint32_t ulGateway = 0xC0A80001; /* 192.168.0.1 */ - uint32_t ulLeaseTime = 0x00000096; /* 150 seconds */ DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; @@ -4854,7 +4805,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IPv4ServerIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4862,7 +4813,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IPv4ServerIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 3; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -4927,22 +4878,15 @@ void test_vDHCPProcess_eWaitingAcknowledge_SubnetMaskIncorrectLength( void ) const BaseType_t xTotalLength = sizeof( struct xDHCPMessage_IPv4 ) + 1U /* Padding */ + 3U /* DHCP offer */ + 6U /* Server IP address */ - + 6U /* Subnet Mask */ - + 6U /* Gateway */ - + 6U /* Lease time */ + + 5U /* Subnet Mask, truncated */ + 1U /* End */; uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulClientIPAddress = 0xC0A8000A; /* 192.168.0.10 */ uint32_t ulSubnetMask = 0xFFFFF100; /* 255.255.241.0 */ - uint32_t ulGateway = 0xC0A80001; /* 192.168.0.1 */ - uint32_t ulLeaseTime = 0x00000096; /* 150 seconds */ DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -4958,28 +4902,13 @@ void test_vDHCPProcess_eWaitingAcknowledge_SubnetMaskIncorrectLength( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOption( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, &ulSubnetMask, 3 ); - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add incorrect length. */ - DHCPOption[ 1 ] = 3; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -5045,20 +4974,15 @@ void test_vDHCPProcess_eWaitingAcknowledge_GatewayIncorrectLength( void ) + 6U /* Server IP address */ + 6U /* Subnet Mask */ + 6U /* Gateway */ - + 6U /* Lease time */ + 1U /* End */; uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulClientIPAddress = 0xC0A8000A; /* 192.168.0.10 */ uint32_t ulSubnetMask = 0xFFFFF100; /* 255.255.241.0 */ uint32_t ulGateway = 0xC0A80001; /* 192.168.0.1 */ - uint32_t ulLeaseTime = 0x00000096; /* 150 seconds */ DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -5074,36 +4998,21 @@ void test_vDHCPProcess_eWaitingAcknowledge_GatewayIncorrectLength( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; /* Add Message type code. */ DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; /* Add incorrect length. */ DHCPOption[ 1 ] = 2; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); + DHCPOption += 6; + + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -5170,7 +5079,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength( void ) + 6U /* Server IP address */ + 6U /* Subnet Mask */ + 6U /* Gateway */ - + 6U /* Lease time */ + + 5U /* Lease time, truncated */ + 1U /* End */; uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ @@ -5181,9 +5090,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength( void ) DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -5199,45 +5105,15 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_LEASE_TIME_OPTION_CODE; - /* Add incorrect length. */ - DHCPOption[ 1 ] = 3; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_GATEWAY_OPTION_CODE, ulGateway ); + prvWriteDHCPOption( &DHCPOption, dhcpIPv4_LEASE_TIME_OPTION_CODE, &ulLeaseTime, 3 ); + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -5303,7 +5179,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength2( void ) + 6U /* Server IP address */ + 6U /* Subnet Mask */ + 6U /* Gateway */ - + 6U /* Lease time */ + + 5U /* Lease time */ + 1U /* End */; uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ @@ -5314,9 +5190,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength2( void ) DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -5332,45 +5205,15 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength2( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress + 0x1234; - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_LEASE_TIME_OPTION_CODE; - /* Add incorrect length. */ - DHCPOption[ 1 ] = 3; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress + 0x1234 ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_GATEWAY_OPTION_CODE, ulGateway ); + prvWriteDHCPOption( &DHCPOption, dhcpIPv4_LEASE_TIME_OPTION_CODE, &ulLeaseTime, 3 ); + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -5903,7 +5746,7 @@ void test_xProcessCheckOption_LengthByteZero( void ) BaseType_t xResult; ProcessSet_t xSet; - uint8_t ucUDPPayload[ 1 ]; + uint8_t ucUDPPayload[ 2 ]; memset( &( ucUDPPayload ), 0, sizeof( ucUDPPayload ) ); @@ -5912,7 +5755,7 @@ void test_xProcessCheckOption_LengthByteZero( void ) xSet.ucOptionCode = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; xSet.pucByte = ucUDPPayload; xSet.uxIndex = 0; - xSet.uxPayloadDataLength = 2; + xSet.uxPayloadDataLength = sizeof( ucUDPPayload ); xResult = xProcessCheckOption( &xSet ); diff --git a/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c b/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c index 86e6a7f00..29a049233 100644 --- a/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c +++ b/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c @@ -1388,6 +1388,7 @@ void test_vDHCPv6Process_ResetFromInit() vDHCP_RATimerReload_Expect( &xEndPoint, dhcpINITIAL_TIMER_PERIOD ); vDHCPv6Process( pdTRUE, &xEndPoint ); + vPortFree( xEndPoint.pxDHCPMessage ); /* Make LeakSanitizer happy. */ /* The endpoint sends the DHCPv6 Solicitation message to find the DHCPv6 server. * Then change the state to eWaitingSendFirstDiscover. */ diff --git a/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c b/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c index 73d656af1..6daae41e4 100644 --- a/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c +++ b/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c @@ -149,10 +149,10 @@ void test_FreeRTOS_gethostbyname_FailNullAddress( void ) void test_FreeRTOS_gethostbyname_FailLongAddress( void ) { uint32_t ret; - char address[ ipconfigDNS_CACHE_NAME_LENGTH + 3 ]; + char address[ ipconfigDNS_CACHE_NAME_LENGTH + 1 ]; memset( address, 'a', ipconfigDNS_CACHE_NAME_LENGTH ); - address[ ipconfigDNS_CACHE_NAME_LENGTH + 3 ] = '\0'; + address[ ipconfigDNS_CACHE_NAME_LENGTH ] = '\0'; ret = FreeRTOS_gethostbyname( address ); @@ -776,10 +776,9 @@ void test_FreeRTOS_getaddrinfo_a_UnknownHintFamily( void ) void test_FreeRTOS_getaddrinfo_a_IPv4AddressFound( void ) { BaseType_t xReturn; - struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo * pxAddress; struct freertos_addrinfo xHint, * pxHint = &xHint; - memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); xHint.ai_family = FREERTOS_AF_INET4; @@ -794,6 +793,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv4AddressFound( void ) TEST_ASSERT_EQUAL( FREERTOS_AF_INET4, pxAddress->ai_family ); TEST_ASSERT_EQUAL( DOTTED_IPV4_ADDRESS_UINT32, FreeRTOS_htonl( pxAddress->ai_addr->sin_address.ulIP_IPv4 ) ); TEST_ASSERT_EQUAL( ipSIZE_OF_IPv4_ADDRESS, pxAddress->ai_addrlen ); + + vPortFree( pxAddress ); /* Make LeakSanitizer happy. */ } /** @@ -802,10 +803,9 @@ void test_FreeRTOS_getaddrinfo_a_IPv4AddressFound( void ) void test_FreeRTOS_getaddrinfo_a_IPv6AddressFound( void ) { BaseType_t xReturn; - struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo * pxAddress; struct freertos_addrinfo xHint, * pxHint = &xHint; - memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); xHint.ai_family = FREERTOS_AF_INET6; @@ -821,6 +821,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv6AddressFound( void ) TEST_ASSERT_EQUAL( FREERTOS_AF_INET6, pxAddress->ai_family ); TEST_ASSERT_EQUAL_MEMORY( xIPv6Address.ucBytes, pxAddress->ai_addr->sin_address.xIP_IPv6.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); TEST_ASSERT_EQUAL( ipSIZE_OF_IPv6_ADDRESS, pxAddress->ai_addrlen ); + + vPortFree( pxAddress ); /* Make LeakSanitizer happy. */ } /** @@ -829,17 +831,16 @@ void test_FreeRTOS_getaddrinfo_a_IPv6AddressFound( void ) void test_FreeRTOS_getaddrinfo_a_IPv4DomainCacheFound( void ) { BaseType_t xReturn; - struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo * pxAddress; struct freertos_addrinfo xExpectedAddress, * pxExpectedAddress = &xExpectedAddress; - memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xExpectedAddress, 0, sizeof( struct freertos_addrinfo ) ); xExpectedAddress.ai_family = FREERTOS_AF_INET4; FreeRTOS_inet_addr_ExpectAndReturn( GOOD_ADDRESS, 0 ); Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, DOTTED_IPV4_ADDRESS_UINT32 ); - Prepare_CacheLookup_ReturnMemThruPtr_ppxAddressInfo( &pxExpectedAddress, sizeof( struct freertos_addrinfo ) ); + Prepare_CacheLookup_ReturnMemThruPtr_ppxAddressInfo( &pxExpectedAddress, sizeof( struct freertos_addrinfo * ) ); xReturn = FreeRTOS_getaddrinfo_a( GOOD_ADDRESS, "Service", NULL, &pxAddress, dns_callback, NULL, 0U ); diff --git a/test/unit-test/FreeRTOS_DNS/ut.cmake b/test/unit-test/FreeRTOS_DNS/ut.cmake index f9d25a146..4e0db6bff 100644 --- a/test/unit-test/FreeRTOS_DNS/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS/ut.cmake @@ -42,7 +42,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c b/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c index 1994b128d..89c9aeb4f 100644 --- a/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c @@ -495,15 +495,12 @@ void test_prepare_DNSLookup( void ) void test_prepare_DNSLookup2( void ) { - BaseType_t x = 0U; - BaseType_t xFamily; + BaseType_t x; struct freertos_addrinfo * pxAddressInfo = NULL; - struct freertos_addrinfo ** ppxAddressInfo; IPv46_Address_t xAddress; - xFamily = FREERTOS_AF_INET; xAddress.xIs_IPv6 = pdFALSE; - ppxAddressInfo = &pxAddressInfo; + xAddress.xIPAddress.ulIP_IPv4 = ~0U; xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */ FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -516,7 +513,7 @@ void test_prepare_DNSLookup2( void ) pxNew_AddrInfo_ExpectAnyArgsAndReturn( NULL ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); - x = Prepare_CacheLookup( "helloman", xFamily, ppxAddressInfo ); + x = Prepare_CacheLookup( "helloman", FREERTOS_AF_INET, &pxAddressInfo ); TEST_ASSERT_EQUAL( 0, x ); } @@ -525,13 +522,11 @@ void test_prepare_DNSLookup2( void ) */ void test_prepare_DNSLookup3( void ) { - BaseType_t x = 0U; - BaseType_t xFamily; - struct freertos_addrinfo ** ppxAddressInfo = NULL; + BaseType_t x; IPv46_Address_t xAddress; - xFamily = FREERTOS_AF_INET; xAddress.xIs_IPv6 = pdFALSE; + xAddress.xIPAddress.ulIP_IPv4 = ~0U; xTaskGetTickCount_ExpectAndReturn( 3000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -543,7 +538,7 @@ void test_prepare_DNSLookup3( void ) xTaskGetTickCount_ExpectAndReturn( 5000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); - x = Prepare_CacheLookup( "helloman", xFamily, ppxAddressInfo ); + x = Prepare_CacheLookup( "helloman", FREERTOS_AF_INET, NULL ); TEST_ASSERT_EQUAL( 0, x ); } @@ -552,13 +547,11 @@ void test_prepare_DNSLookup3( void ) */ void test_prepare_DNSLookup4( void ) { - BaseType_t x = 0U; - BaseType_t xFamily; - struct freertos_addrinfo ** ppxAddressInfo = NULL; + BaseType_t x; IPv46_Address_t xAddress; - xFamily = FREERTOS_AF_INET; xAddress.xIs_IPv6 = pdFALSE; + xAddress.xIPAddress.ulIP_IPv4 = ~0U; xTaskGetTickCount_ExpectAndReturn( 3000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -570,7 +563,7 @@ void test_prepare_DNSLookup4( void ) xTaskGetTickCount_ExpectAndReturn( 5000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); - x = Prepare_CacheLookup( "hello", xFamily, ppxAddressInfo ); + x = Prepare_CacheLookup( "hello", FREERTOS_AF_INET, NULL ); TEST_ASSERT_EQUAL( 0, x ); } @@ -629,14 +622,14 @@ void test_prepare_DNSLookup6( void ) */ void test_prepare_DNSLookup_IPv6( void ) { - BaseType_t x = 0U; - BaseType_t xFamily; + BaseType_t x; + BaseType_t xFamily = FREERTOS_AF_INET6; struct freertos_addrinfo * pxAddressInfo = &pucAddrBuffer[ 0 ]; - struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pucAddrBuffer; + struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pxAddressInfo; IPv46_Address_t xAddress; - xFamily = FREERTOS_AF_INET6; xAddress.xIs_IPv6 = pdTRUE; + memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 ); *ppxAddressInfo = pxAddressInfo; @@ -680,6 +673,7 @@ void test_prepare_DNSLookup2_IPv6( void ) xFamily = FREERTOS_AF_INET6; xAddress.xIs_IPv6 = pdTRUE; + memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 ); ppxAddressInfo = &pxAddressInfo; xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */ @@ -709,6 +703,7 @@ void test_prepare_DNSLookup3_IPv6( void ) xFamily = FREERTOS_AF_INET6; xAddress.xIs_IPv6 = pdTRUE; + memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 ); xTaskGetTickCount_ExpectAndReturn( 3000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -737,6 +732,7 @@ void test_prepare_DNSLookup4_IPv6( void ) xFamily = FREERTOS_AF_INET6; xAddress.xIs_IPv6 = pdTRUE; + memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 ); xTaskGetTickCount_ExpectAndReturn( 3000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); diff --git a/test/unit-test/FreeRTOS_DNS_Cache/ut.cmake b/test/unit-test/FreeRTOS_DNS_Cache/ut.cmake index 6c20e1210..b9c5e9e61 100755 --- a/test/unit-test/FreeRTOS_DNS_Cache/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_Cache/ut.cmake @@ -39,7 +39,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "" ) diff --git a/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c b/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c index 816a19944..3a0380784 100644 --- a/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c @@ -65,6 +65,10 @@ typedef void (* FOnDNSEvent ) ( const char * /* pcName */, /* =========================== GLOBAL VARIABLES =========================== */ static int callback_called = 0; +/* The second element is for the flexible array member + * /* when pvPortMalloc is mocked to return this object. + */ +static DNSCallback_t dnsCallback[ 2 ]; /* =========================== STATIC FUNCTIONS =========================== */ static void dns_callback( const char * pcName, @@ -74,8 +78,6 @@ static void dns_callback( const char * pcName, callback_called = 1; } - -static DNSCallback_t dnsCallback; /* ============================ TEST FIXTURES ============================= */ /** @@ -86,7 +88,7 @@ void setUp( void ) vListInitialise_ExpectAnyArgs(); vDNSCallbackInitialise(); callback_called = 0; - memset( &dnsCallback, 0x00, sizeof( DNSCallback_t ) ); + memset( dnsCallback, 0x00, sizeof( dnsCallback ) ); } /** @@ -142,14 +144,14 @@ void test_xDNSDoCallback_success_equal_identifier( void ) char pc_name[] = "test"; strcpy( pxSet.pcName, pc_name ); - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 ); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 123 ); uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -176,14 +178,14 @@ void test_xDNSDoCallback_success_equal_identifier_set_timer( void ) pxSet.pxDNSMessageHeader->usIdentifier = 123; char pc_name[] = "test"; strcpy( pxSet.pcName, pc_name ); - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pCallbackFunction = dns_callback; /* Expectations */ listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 ); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 123 ); uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -208,7 +210,7 @@ void test_vDNSSetCallback_success( void ) void * pvSearchID = NULL; /* Expectations */ - pvPortMalloc_ExpectAnyArgsAndReturn( &dnsCallback ); + pvPortMalloc_ExpectAnyArgsAndReturn( dnsCallback ); listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE ); vTaskSetTimeOutState_ExpectAnyArgs(); listSET_LIST_ITEM_OWNER_ExpectAnyArgs(); @@ -221,10 +223,10 @@ void test_vDNSSetCallback_success( void ) vDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); /* Validations */ - TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback.pcName, "hostname" ) ); - TEST_ASSERT_EQUAL( dns_callback, dnsCallback.pCallbackFunction ); - TEST_ASSERT_EQUAL( pvSearchID, dnsCallback.pvSearchID ); - TEST_ASSERT_EQUAL( 56, dnsCallback.uxRemainingTime ); + TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback->pcName, "hostname" ) ); + TEST_ASSERT_EQUAL( dns_callback, dnsCallback->pCallbackFunction ); + TEST_ASSERT_EQUAL( pvSearchID, dnsCallback->pvSearchID ); + TEST_ASSERT_EQUAL( 56, dnsCallback->uxRemainingTime ); } /** @@ -235,7 +237,7 @@ void test_vDNSSetCallback_success_empty_list( void ) void * pvSearchID = NULL; /* Expectations */ - pvPortMalloc_ExpectAnyArgsAndReturn( &dnsCallback ); + pvPortMalloc_ExpectAnyArgsAndReturn( dnsCallback ); listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE ); FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 0 ); vDNSTimerReload_ExpectAnyArgs(); @@ -250,10 +252,10 @@ void test_vDNSSetCallback_success_empty_list( void ) vDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); /* Validations */ - TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback.pcName, "hostname" ) ); - TEST_ASSERT_EQUAL( dns_callback, dnsCallback.pCallbackFunction ); - TEST_ASSERT_EQUAL( pvSearchID, dnsCallback.pvSearchID ); - TEST_ASSERT_EQUAL( 56, dnsCallback.uxRemainingTime ); + TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback->pcName, "hostname" ) ); + TEST_ASSERT_EQUAL( dns_callback, dnsCallback->pCallbackFunction ); + TEST_ASSERT_EQUAL( pvSearchID, dnsCallback->pvSearchID ); + TEST_ASSERT_EQUAL( 56, dnsCallback->uxRemainingTime ); } /** @@ -278,13 +280,13 @@ void test_vDNSCheckCallback_success_search_id_not_null( void ) { void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; + dnsCallback->pvSearchID = pvSearchID; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdFALSE ); vPortFree_ExpectAnyArgs(); @@ -306,13 +308,13 @@ void test_vDNSCheckCallback_success_search_id_not_null_list_empty( void ) { void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; + dnsCallback->pvSearchID = pvSearchID; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdFALSE ); vPortFree_ExpectAnyArgs(); @@ -333,13 +335,13 @@ void test_vDNSCheckCallback_success_search_id_null( void ) { void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; + dnsCallback->pvSearchID = pvSearchID; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdFALSE ); @@ -363,15 +365,15 @@ void test_vDNSCheckCallback_success_search_id_null_timeout( void ) List_t xTempList; void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; - dnsCallback.xIsIPv6 = 0; - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pvSearchID = pvSearchID; + dnsCallback->xIsIPv6 = 0; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE ); @@ -383,7 +385,7 @@ void test_vDNSCheckCallback_success_search_id_null_timeout( void ) listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -407,15 +409,15 @@ void test_vDNSCheckCallback_success_search_id_null_timeout_IPv6( void ) List_t xTempList; void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; - dnsCallback.xIsIPv6 = 1; - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pvSearchID = pvSearchID; + dnsCallback->xIsIPv6 = 1; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE ); @@ -427,7 +429,7 @@ void test_vDNSCheckCallback_success_search_id_null_timeout_IPv6( void ) listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -451,15 +453,15 @@ void test_vDNSCheckCallback_success_search_id_null_timeout2( void ) void * pvSearchID = ( void * ) 456; void * pvSearchID2 = ( void * ) 457; - dnsCallback.pvSearchID = pvSearchID2; - dnsCallback.xIsIPv6 = 0; - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pvSearchID = pvSearchID2; + dnsCallback->xIsIPv6 = 0; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE ); @@ -471,7 +473,7 @@ void test_vDNSCheckCallback_success_search_id_null_timeout2( void ) listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -495,15 +497,15 @@ void test_vDNSCheckCallback_success_search_id_null_timeout2_IPv6( void ) void * pvSearchID = ( void * ) 456; void * pvSearchID2 = ( void * ) 457; - dnsCallback.pvSearchID = pvSearchID2; - dnsCallback.xIsIPv6 = 1; - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pvSearchID = pvSearchID2; + dnsCallback->xIsIPv6 = 1; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE ); @@ -515,7 +517,7 @@ void test_vDNSCheckCallback_success_search_id_null_timeout2_IPv6( void ) listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); diff --git a/test/unit-test/FreeRTOS_DNS_Callback/ut.cmake b/test/unit-test/FreeRTOS_DNS_Callback/ut.cmake index e1962eaaa..6d0688f6e 100644 --- a/test/unit-test/FreeRTOS_DNS_Callback/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_Callback/ut.cmake @@ -41,7 +41,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/FreeRTOS_DNS_ConfigNoCallback_utest.c b/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/FreeRTOS_DNS_ConfigNoCallback_utest.c index 74ed71c80..b00f4970e 100644 --- a/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/FreeRTOS_DNS_ConfigNoCallback_utest.c +++ b/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/FreeRTOS_DNS_ConfigNoCallback_utest.c @@ -90,10 +90,9 @@ void setUp( void ) void test_FreeRTOS_getaddrinfo_IPv4AddressFound( void ) { BaseType_t xReturn; - struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo * pxAddress; struct freertos_addrinfo xHint, * pxHint = &xHint; - memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); xHint.ai_family = FREERTOS_AF_INET4; @@ -107,6 +106,8 @@ void test_FreeRTOS_getaddrinfo_IPv4AddressFound( void ) TEST_ASSERT_EQUAL( FREERTOS_AF_INET4, pxAddress->ai_family ); TEST_ASSERT_EQUAL( DOTTED_IPV4_ADDRESS_UINT32, FreeRTOS_htonl( pxAddress->ai_addr->sin_address.ulIP_IPv4 ) ); TEST_ASSERT_EQUAL( ipSIZE_OF_IPv4_ADDRESS, pxAddress->ai_addrlen ); + + vPortFree( pxAddress ); /* Make LeakSanitizer happy. */ } /** diff --git a/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/ut.cmake b/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/ut.cmake index 9e63fd66e..6146679ff 100644 --- a/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/ut.cmake @@ -41,7 +41,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_utest.c b/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_utest.c index 8419e537f..f109cd662 100644 --- a/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_utest.c @@ -195,7 +195,8 @@ void test_SendRequest_fail( void ) struct freertos_sockaddr xAddress; struct xDNSBuffer pxDNSBuf; - FreeRTOS_sendto_ExpectAnyArgsAndReturn( pdFALSE ); + pxDNSBuf.uxPayloadLength = 1024; + FreeRTOS_sendto_ExpectAnyArgsAndReturn( 1023 ); ret = DNS_SendRequest( s, &xAddress, &pxDNSBuf ); diff --git a/test/unit-test/FreeRTOS_DNS_Networking/ut.cmake b/test/unit-test/FreeRTOS_DNS_Networking/ut.cmake index 36328c338..083ffaf02 100644 --- a/test/unit-test/FreeRTOS_DNS_Networking/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_Networking/ut.cmake @@ -35,7 +35,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "" ) diff --git a/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c b/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c index e31fb23fb..61d2babca 100644 --- a/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c @@ -57,6 +57,10 @@ #define BAD_ADDRESS "this is a bad address" #define DOTTED_ADDRESS "192.268.0.1" +#define prvROUND_UP_TO( SIZE, ALIGNMENT ) ( ( ( SIZE ) + ( ALIGNMENT ) -1 ) / ( ALIGNMENT ) *( ALIGNMENT ) ) + +#define prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 prvROUND_UP_TO( ipUDP_PAYLOAD_OFFSET_IPv4, sizeof( void * ) ) + typedef void (* FOnDNSEvent ) ( const char * /* pcName */, void * /* pvSearchID */, struct freertos_addrinfo * /* pxAddressInfo */ ); @@ -1629,8 +1633,8 @@ void test_DNS_ParseDNSReply_InvalidEndpointIP( void ) void test_DNS_ParseDNSReply_InvalidEndpointType( void ) { uint32_t ret; - uint8_t udp_buffer[ 250 + ipUDP_PAYLOAD_OFFSET_IPv4 ] = { 0 }; - uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4; + uint8_t udp_buffer[ prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 + 250 ] = { 0 }; + uint8_t * pucUDPPayloadBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4; size_t uxBufferLength = 250; struct freertos_addrinfo * pxAddressInfo; uint16_t usPort; @@ -1642,11 +1646,11 @@ void test_DNS_ParseDNSReply_InvalidEndpointType( void ) memset( pucUDPPayloadBuffer, 0x00, uxBufferLength ); NetworkBufferDescriptor_t pxNetworkBuffer = { 0 }; - pxNetworkBuffer.pucEthernetBuffer = udp_buffer; + pxNetworkBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNetworkBuffer.xDataLength = uxBufferLength; NetworkBufferDescriptor_t pxNewBuffer; - pxNewBuffer.pucEthernetBuffer = udp_buffer; + pxNewBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNewBuffer.xDataLength = uxBufferLength; pxNetworkBuffer.pxEndPoint = &xEndPoint; xEndPoint.bits.bIPv6 = pdTRUE; @@ -1768,8 +1772,8 @@ void test_DNS_ParseDNSReply_answer_record_too_many_answers( void ) void test_DNS_ParseDNSReply_answer_lmmnr_reply_xBufferAllocFixedsize( void ) { uint32_t ret; - uint8_t udp_buffer[ 250 + ipUDP_PAYLOAD_OFFSET_IPv4 ] = { 0 }; - uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4; + uint8_t udp_buffer[ prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 + 250 ] = { 0 }; + uint8_t * pucUDPPayloadBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4; size_t uxBufferLength = 250; struct freertos_addrinfo * pxAddressInfo; uint16_t usPort; @@ -1781,11 +1785,11 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_xBufferAllocFixedsize( void ) memset( pucUDPPayloadBuffer, 0x00, uxBufferLength ); NetworkBufferDescriptor_t pxNetworkBuffer = { 0 }; - pxNetworkBuffer.pucEthernetBuffer = udp_buffer; + pxNetworkBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNetworkBuffer.xDataLength = uxBufferLength; NetworkBufferDescriptor_t pxNewBuffer; - pxNewBuffer.pucEthernetBuffer = udp_buffer; + pxNewBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNewBuffer.xDataLength = uxBufferLength; char dns[ 64 ]; @@ -1846,8 +1850,8 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_xBufferAllocFixedsize( void ) void test_DNS_ParseDNSReply_answer_lmmnr_reply( void ) { uint32_t ret; - uint8_t udp_buffer[ 250 + ipUDP_PAYLOAD_OFFSET_IPv4 ] = { 0 }; - uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4; + uint8_t udp_buffer[ prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 + 250 ] = { 0 }; + uint8_t * pucUDPPayloadBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4; size_t uxBufferLength = 250; struct freertos_addrinfo * pxAddressInfo; uint16_t usPort; @@ -1856,7 +1860,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply( void ) memset( pucUDPPayloadBuffer, 0x00, uxBufferLength ); NetworkBufferDescriptor_t pxNetworkBuffer = { 0 }; - pxNetworkBuffer.pucEthernetBuffer = udp_buffer; + pxNetworkBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNetworkBuffer.xDataLength = uxBufferLength; char dns[ 64 ]; @@ -1991,7 +1995,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply2( void ) */ void test_DNS_ParseDNSReply_answer_lmmnr_reply3( void ) { - uint32_t ret; + uint32_t ret = 0xDEADC0DE; uint8_t udp_buffer[ 250 + ipUDP_PAYLOAD_OFFSET_IPv4 ] = { 0 }; uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4 - 1; size_t uxBufferLength = 250; @@ -2054,7 +2058,8 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply3( void ) xExpected, usPort ) ); - TEST_ASSERT_EQUAL( pdFALSE, ret ); + /* ret is not reassigned, because the function asserts. */ + TEST_ASSERT_EQUAL( 0xDEADC0DE, ret ); ASSERT_DNS_QUERY_HOOK_NOT_CALLED(); } @@ -2938,6 +2943,7 @@ void test_parseDNSAnswer_recordstored_gt_count( void ) char pcName[ 300 ]; DNSAnswerRecord_t * pxDNSAnswerRecord; IPv46_Address_t ip_address; + const uint32_t ulTestAddress = 0xABCD1234; ip_address.xIPAddress.ulIP_IPv4 = 1234; ip_address.xIs_IPv6 = pdFALSE; @@ -2962,8 +2968,7 @@ void test_parseDNSAnswer_recordstored_gt_count( void ) pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_A_HOST ); - uint32_t * pulTestAddress = ( uint32_t * ) ( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ) ); - *pulTestAddress = 0xABCD1234; + memcpy( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ), &ulTestAddress, sizeof( ulTestAddress ) ); usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddressInfo ); @@ -3178,7 +3183,7 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_success( void ) memset( &( ip_address.xIPAddress.xIP_IPv6 ), 1, ipSIZE_OF_IPv6_ADDRESS ); ip_address.xIs_IPv6 = pdTRUE; ParseSet_t xSet = { 0 }; - struct freertos_addrinfo * pxAddressInfo, * pxAddressInfo_2; + struct freertos_addrinfo xAddressInfo = { 0 }, * pxAddressInfo, * pxAddressInfo_2; xSet.pxDNSMessageHeader = &pxDNSMessageHeader; xSet.pucByte = pucByte; @@ -3200,7 +3205,7 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_success( void ) pxDNSAnswerRecord->usType = ( dnsTYPE_AAAA_HOST ); usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_AAAA_HOST ); /* usType */ - pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddressInfo ); + pxNew_AddrInfo_ExpectAnyArgsAndReturn( &xAddressInfo ); xDNSDoCallback_ExpectAnyArgsAndReturn( pdTRUE ); FreeRTOS_dns_update_ExpectAnyArgsAndReturn( pdTRUE ); FreeRTOS_dns_update_ReturnThruPtr_pxIP( &ip_address ); @@ -3329,6 +3334,7 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_fail_nullLinkedListForDNSAns char pcName[ 300 ]; DNSAnswerRecord_t * pxDNSAnswerRecord; IPv46_Address_t ip_address; + const uint32_t ulTestAddress = 0xABCD1234; memset( &( ip_address.xIPAddress.xIP_IPv6 ), 1, ipSIZE_OF_IPv6_ADDRESS ); ip_address.xIs_IPv6 = pdTRUE; @@ -3354,8 +3360,7 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_fail_nullLinkedListForDNSAns pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_A_HOST ); - uint32_t * pulTestAddress = ( uint32_t * ) ( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ) ); - *pulTestAddress = 0xABCD1234; + memcpy( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ), &ulTestAddress, sizeof( ulTestAddress ) ); usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ xDNSDoCallback_ExpectAnyArgsAndReturn( pdTRUE ); @@ -3466,11 +3471,12 @@ void test_parseDNSAnswer_dns_nocallback_false( void ) BaseType_t xDoStore = pdTRUE; DNSAnswerRecord_t * pxDNSAnswerRecord; IPv46_Address_t ip_address; + const uint32_t ulTestAddress = 0xABCD1234; ip_address.xIPAddress.ulIP_IPv4 = 5678; ip_address.xIs_IPv6 = pdFALSE; ParseSet_t xSet = { 0 }; - struct freertos_addrinfo * pxAddressInfo; + struct freertos_addrinfo xAddressInfo = { 0 }; struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pucAddrBuffer; *ppxAddressInfo = NULL; @@ -3485,8 +3491,7 @@ void test_parseDNSAnswer_dns_nocallback_false( void ) pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_A_HOST ); - uint32_t * pulTestAddress = ( uint32_t * ) ( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ) ); - *pulTestAddress = 0xABCD1234; + memcpy( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ), &ulTestAddress, sizeof( ulTestAddress ) ); xSet.pucByte = pucByte; xSet.usNumARecordsStored = 0; @@ -3497,7 +3502,7 @@ void test_parseDNSAnswer_dns_nocallback_false( void ) xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + 1; usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ - pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddressInfo ); + pxNew_AddrInfo_ExpectAnyArgsAndReturn( &xAddressInfo ); xDNSDoCallback_ExpectAnyArgsAndReturn( pdFALSE ); FreeRTOS_dns_update_ExpectAnyArgsAndReturn( pdTRUE ); FreeRTOS_dns_update_ReturnThruPtr_pxIP( &ip_address ); @@ -3526,6 +3531,7 @@ void test_parseDNSAnswer_do_store_false( void ) ParseSet_t xSet = { 0 }; struct freertos_addrinfo * pxAddressInfo; struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pucAddrBuffer; + const uint32_t ulTestAddress = 0xABCD1234; memset( pucByte, 0x00, 300 ); memset( pcName, 0x00, 300 ); @@ -3544,7 +3550,7 @@ void test_parseDNSAnswer_do_store_false( void ) xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + 1; usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ - pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddressInfo ); + pxNew_AddrInfo_ExpectAnyArgsAndReturn( NULL ); xDNSDoCallback_ExpectAnyArgsAndReturn( pdFALSE ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( "ignored" ); @@ -3552,8 +3558,7 @@ void test_parseDNSAnswer_do_store_false( void ) pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_A_HOST ); - uint32_t * pulTestAddress = ( uint32_t * ) ( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ) ); - *pulTestAddress = 0xABCD1234; + memcpy( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ), &ulTestAddress, sizeof( ulTestAddress ) ); ret = parseDNSAnswer( &xSet, &pxAddressInfo, &uxBytesRead ); diff --git a/test/unit-test/FreeRTOS_DNS_Parser/ut.cmake b/test/unit-test/FreeRTOS_DNS_Parser/ut.cmake index d8520accd..5356fb1be 100755 --- a/test/unit-test/FreeRTOS_DNS_Parser/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_Parser/ut.cmake @@ -36,7 +36,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "" ) diff --git a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c index d7c5af405..2bc281d81 100644 --- a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c +++ b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c @@ -267,7 +267,7 @@ void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeEqualToConfig( void ) uint8_t pucEthernetBuffer[ 1500 ]; /* Put the ethernet buffer in place. */ - pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, uxBlockTimeTicks, pxNetworkBuffer ); @@ -291,7 +291,7 @@ void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeLessThanConfig( void ) uint8_t pucEthernetBuffer[ 1500 ]; /* Put the ethernet buffer in place. */ - pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, uxBlockTimeTicks, pxNetworkBuffer ); @@ -316,7 +316,7 @@ void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeMoreThanConfig( void ) uint8_t pucEthernetBuffer[ 1500 ]; /* Put the ethernet buffer in place. */ - pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS, pxNetworkBuffer ); @@ -1989,10 +1989,12 @@ void test_prvProcessEthernetPacket_ARPFrameType_eFrameConsumed( void ) uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; EthernetHeader_t * pxEthernetHeader; struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; @@ -2017,10 +2019,12 @@ void test_prvProcessEthernetPacket_ARPFrameType_SmallerDataLength( void ) uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; EthernetHeader_t * pxEthernetHeader; struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; pxNetworkBuffer->xDataLength = sizeof( EthernetHeader_t ); pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; @@ -2045,10 +2049,12 @@ void test_prvProcessEthernetPacket_IPv4FrameType_LessData( void ) uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; EthernetHeader_t * pxEthernetHeader; struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; pxNetworkBuffer->xDataLength = sizeof( EthernetHeader_t ); pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; @@ -2070,17 +2076,17 @@ void test_prvProcessEthernetPacket_IPv4FrameType_AptData( void ) { NetworkBufferDescriptor_t xNetworkBuffer; NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffer; - uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ] = { 0 }; EthernetHeader_t * pxEthernetHeader; IPPacket_t * pxIPPacket; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - - memset( pxNetworkBuffer->pucEthernetBuffer, 0, ipconfigTCP_MSS ); + NetworkEndPoint_t xNetworkEndPoint = { 0 }; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; - pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; @@ -2103,16 +2109,14 @@ void test_prvProcessEthernetPacket_InterfaceNull( void ) { NetworkBufferDescriptor_t xNetworkBuffer; NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffer; - uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ] = { 0 }; EthernetHeader_t * pxEthernetHeader; IPPacket_t * pxIPPacket; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( pxNetworkBuffer->pucEthernetBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; - pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; pxNetworkBuffer->pxInterface = NULL; vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer ); @@ -2221,15 +2225,13 @@ void test_prvProcessIPPacket_ValidHeader_ARPResolutionReqd( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->pxInterface = &xInterface; /* Initialize ethernet layer. */ @@ -2258,15 +2260,13 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_InvalidProt( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; /* Initialize ethernet layer. */ @@ -2299,15 +2299,13 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_ICMPRelease( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2341,15 +2339,13 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_ICMPProcess( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2383,16 +2379,14 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_UDPZeroLength( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2428,16 +2422,14 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_UDPLengthGreaterThanIPHeader( eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2473,16 +2465,14 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_UDPHappyPath( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; UDPPacket_t * pxUDPPacket; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2518,16 +2508,14 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_UDPProcessFail( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2566,17 +2554,15 @@ void test_prvProcessIPPacket_ARPResolutionReqd_UDP( void ) IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2619,17 +2605,15 @@ void test_prvProcessIPPacket_ARPResolutionReqd_UDP1( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = sizeof( UDPPacket_t ); pxNetworkBuffer->pxInterface = &xInterface; @@ -2670,16 +2654,15 @@ void test_prvProcessIPPacket_TCP( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = sizeof( UDPPacket_t ); pxNetworkBuffer->pxInterface = &xInterface; @@ -2714,17 +2697,15 @@ void test_prvProcessIPPacket_TCPProcessFail( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; BaseType_t xReturnValue = pdTRUE; NetworkEndPoint_t xEndPoint = { 0 }; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = sizeof( UDPPacket_t ); pxNetworkBuffer->pxInterface = &xInterface; @@ -2759,15 +2740,13 @@ void test_prvProcessIPPacket_UDP_ExternalLoopback( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2799,15 +2778,13 @@ void test_prvProcessIPPacket_UDP_GreaterLoopbackAddress( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxNetworkBuffer->pxInterface = &xInterface; @@ -2839,15 +2816,13 @@ void test_prvProcessIPPacket_UDP_LessLoopbackAddress( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxNetworkBuffer->pxInterface = &xInterface; @@ -2879,15 +2854,13 @@ void test_prvProcessIPPacket_UDP_IPHeaderLengthTooLarge( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER; pxNetworkBuffer->pxInterface = &xInterface; @@ -2915,17 +2888,15 @@ void test_prvProcessIPPacket_UDP_IPv6_HappyPath( void ) eFrameProcessingResult_t eResult; IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; UDPPacket_IPv6_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2962,17 +2933,15 @@ void test_prvProcessIPPacket_UDP_IPv6_ExtensionHappyPath( void ) eFrameProcessingResult_t eResult; IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; UDPPacket_IPv6_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3017,16 +2986,14 @@ void test_prvProcessIPPacket_UDP_IPv6_ExtensionHandleFail( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; UDPPacket_IPv6_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3068,16 +3035,14 @@ void test_prvProcessIPPacket_TCP_IPv6_HappyPath( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; TCPPacket_IPv6_t * pxTCPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3120,16 +3085,14 @@ void test_prvProcessIPPacket_TCP_IPv6_ARPResolution( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; TCPPacket_IPv6_t * pxTCPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3169,16 +3132,14 @@ void test_prvProcessIPPacket_ICMP_IPv6_HappyPath( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; ICMPPacket_IPv6_t * pxICMPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3220,15 +3181,13 @@ void test_prvProcessIPPacket_IPv6_LessPacketSize( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; struct xNetworkInterface xInterface; BaseType_t xReturnValue = pdTRUE; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = sizeof( IPPacket_IPv6_t ) - 1; pxNetworkBuffer->pxInterface = &xInterface; diff --git a/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_utest.c b/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_utest.c index f420447d6..c103cd264 100644 --- a/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_utest.c +++ b/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_utest.c @@ -441,7 +441,7 @@ void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeEqualToConfigBackwardCompatible( uint8_t pucEthernetBuffer[ 1500 ]; /* Put the ethernet buffer in place. */ - pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, uxBlockTimeTicks, pxNetworkBuffer ); diff --git a/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_stubs.c b/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_stubs.c index 03ba1b2c3..5767d82ac 100644 --- a/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_stubs.c +++ b/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_stubs.c @@ -109,7 +109,11 @@ static NetworkBufferDescriptor_t * prvInitializeNetworkDescriptorWithExtensionHe { static NetworkBufferDescriptor_t xNetworkBuffer; /* Ethernet header + IPv6 header + Maximum protocol header + IPv6 Extension Headers + 1 payload */ - static uint8_t pcNetworkBuffer[ sizeof( EthernetHeader_t ) + sizeof( IPHeader_IPv6_t ) + TEST_IPv6_DEFAULT_EXTENSION_HEADERS_LENGTH + sizeof( ICMPHeader_IPv6_t ) + 1U ]; + static uint8_t pcNetworkBuffer[ + sizeof( EthernetHeader_t ) + sizeof( IPHeader_IPv6_t ) + TEST_IPv6_DEFAULT_EXTENSION_HEADERS_LENGTH + + configMAX( sizeof( ICMPHeader_IPv6_t ), sizeof( TCPHeader_t ) ) + + 1U + ]; EthernetHeader_t * pxEthHeader = ( EthernetHeader_t * ) pcNetworkBuffer; IPHeader_IPv6_t * pxIPv6Header = ( IPHeader_IPv6_t * ) &( pcNetworkBuffer[ sizeof( EthernetHeader_t ) ] ); uint8_t * pxIPv6ExtHeader = ( uint8_t * ) &( pcNetworkBuffer[ sizeof( EthernetHeader_t ) + sizeof( IPHeader_IPv6_t ) ] ); diff --git a/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_utest.c b/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_utest.c index b869cef09..edcfab765 100644 --- a/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_utest.c +++ b/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_utest.c @@ -310,10 +310,10 @@ void test_eHandleIPv6ExtensionHeaders_TCPHappyPath() uint8_t ucExtHeaderNum = 7U; uint8_t ucProtocol = ipPROTOCOL_TCP; NetworkBufferDescriptor_t * pxNetworkBuffer = prvInitializeNetworkDescriptorWithExtensionHeader( ucProtocol ); - TCPHeader_t * pxProtocolHeader = ( TCPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + TEST_IPv6_DEFAULT_EXTENSION_HEADERS_LENGTH ] ); - uint8_t * pxPayload; + uint8_t * pxPayload = &( pxNetworkBuffer->pucEthernetBuffer[ + ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + TEST_IPv6_DEFAULT_EXTENSION_HEADERS_LENGTH + sizeof( TCPHeader_t ) + ] ); - pxPayload = ( uint8_t * ) ( pxProtocolHeader + 1 ); *pxPayload = 'a'; usGetExtensionHeaderLength_ExpectAndReturn( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength, NULL, ucExtHeaderNum * 8U ); diff --git a/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c b/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c index 6cdb37dec..2bd43461b 100644 --- a/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c +++ b/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c @@ -455,7 +455,6 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_Gateway( void ) void test_eNDGetCacheEntry_NDCacheLookupMiss_NoEP( void ) { MACAddress_t xMACAddress; - IPv6_Address_t xIPAddress; NetworkEndPoint_t * pxEndPoint, xEndPoint; eARPLookupResult_t eResult; BaseType_t xUseEntry = 0; @@ -472,7 +471,8 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_NoEP( void ) FreeRTOS_FindGateWay_ExpectAnyArgsAndReturn( NULL ); - eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, &pxEndPoint ); + /* TODO: This function should take a const pointer; remove const cast when it does. */ + eResult = eNDGetCacheEntry( ( IPv6_Address_t * ) &xSiteLocalIPAddress, &xMACAddress, &pxEndPoint ); TEST_ASSERT_EQUAL( eARPCacheMiss, eResult ); } @@ -1039,13 +1039,16 @@ void test_SendPingRequestIPv6_NULL_Buffer( void ) */ void test_SendPingRequestIPv6_Assert( void ) { - NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; - NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; - IPv6_Address_t xIPAddress; + NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; + NetworkBufferDescriptor_t xNetworkBuffer = { 0 }; + uint8_t ucEthernetBuffer[ 1500 ] = { 0 }; + IPv6_Address_t xIPAddress = { 0 }; size_t uxNumberOfBytesToSend = 100; BaseType_t xReturn; uint16_t usSequenceNumber = 1; + xNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; + xNetworkBuffer.xDataLength = sizeof( ucEthernetBuffer ); ( void ) memcpy( xIPAddress.ucBytes, xDefaultIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); pxEndPoint->bits.bIPv6 = 1; @@ -1057,7 +1060,7 @@ void test_SendPingRequestIPv6_Assert( void ) uxGetNumberOfFreeNetworkBuffers_ExpectAndReturn( 4U ); - pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( pxNetworkBuffer ); + pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( &xNetworkBuffer ); xSendEventStructToIPTask_IgnoreAndReturn( pdPASS ); xReturn = FreeRTOS_SendPingRequestIPv6( &xIPAddress, uxNumberOfBytesToSend, 0 ); @@ -1073,12 +1076,15 @@ void test_SendPingRequestIPv6_Assert( void ) void test_SendPingRequestIPv6_SendToIP_Pass( void ) { NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; - NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; + NetworkBufferDescriptor_t xNetworkBuffer = { 0 }, * pxNetworkBuffer = &xNetworkBuffer; + uint8_t ucEthernetBuffer[ 1500 ] = { 0 }; IPv6_Address_t xIPAddress; size_t uxNumberOfBytesToSend = 100; BaseType_t xReturn; uint16_t usSequenceNumber = 1; + xNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; + xNetworkBuffer.xDataLength = sizeof( ucEthernetBuffer ); ( void ) memcpy( xIPAddress.ucBytes, xDefaultIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); pxEndPoint->bits.bIPv6 = 1; @@ -1107,11 +1113,13 @@ void test_SendPingRequestIPv6_SendToIP_Fail( void ) { NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; + uint8_t ucEthernetBuffer[ 1500 ] = { 0 }; IPv6_Address_t xIPAddress; size_t uxNumberOfBytesToSend = 100; BaseType_t xReturn; uint16_t usSequenceNumber = 1; + xNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; ( void ) memcpy( xIPAddress.ucBytes, xDefaultIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); pxEndPoint->bits.bIPv6 = 1; @@ -1454,15 +1462,17 @@ void test_prvProcessICMPMessage_IPv6_ipICMP_PING_REPLY_IPv6_eSuccess( void ) */ void test_prvProcessICMPMessage_IPv6_NeighborSolicitationNullEP( void ) { - NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; - ICMPPacket_IPv6_t xICMPPacket; - NetworkEndPoint_t xEndPoint; + NetworkBufferDescriptor_t xNetworkBuffer = { 0 }, * pxNetworkBuffer = &xNetworkBuffer; + ICMPPacket_IPv6_t xICMPPacket = { 0 }; + NetworkEndPoint_t xEndPoint = { 0 }; eFrameProcessingResult_t eReturn; xEndPoint.bits.bIPv6 = pdTRUE_UNSIGNED; + ( void ) memcpy( xEndPoint.ipv6_settings.xIPAddress.ucBytes, xDefaultIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); xICMPPacket.xICMPHeaderIPv6.ucTypeOfMessage = ipICMP_NEIGHBOR_SOLICITATION_IPv6; pxNetworkBuffer->pxEndPoint = &xEndPoint; pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; + pxNetworkBuffer->xDataLength = sizeof( xICMPPacket ); FreeRTOS_InterfaceEPInSameSubnet_IPv6_ExpectAnyArgsAndReturn( NULL ); @@ -1497,34 +1507,6 @@ void test_prvProcessICMPMessage_IPv6_NeighborSolicitationIncorrectLen( void ) TEST_ASSERT_EQUAL( eReturn, eReleaseBuffer ); } - -/** - * @brief This function process ICMP message when message type is - * ipICMP_NEIGHBOR_SOLICITATION_IPv6. - * It handles case where the ICMP header address does not - * match which means the message is not for us, - * ignore it. - */ -void test_prvProcessICMPMessage_IPv6_NeighborSolicitationCorrectLen( void ) -{ - NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; - ICMPPacket_IPv6_t xICMPPacket; - NetworkEndPoint_t xEndPoint; - eFrameProcessingResult_t eReturn; - - xEndPoint.bits.bIPv6 = pdTRUE_UNSIGNED; - xICMPPacket.xICMPHeaderIPv6.ucTypeOfMessage = ipICMP_NEIGHBOR_SOLICITATION_IPv6; - pxNetworkBuffer->pxEndPoint = &xEndPoint; - pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; - pxNetworkBuffer->xDataLength = xHeaderSize + ipBUFFER_PADDING; - - FreeRTOS_InterfaceEPInSameSubnet_IPv6_ExpectAnyArgsAndReturn( &xEndPoint ); - - eReturn = prvProcessICMPMessage_IPv6( pxNetworkBuffer ); - - TEST_ASSERT_EQUAL( eReturn, eReleaseBuffer ); -} - /** * @brief This function process ICMP message when message type is * ipICMP_NEIGHBOR_SOLICITATION_IPv6. diff --git a/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c b/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c index a1dfca94e..b82ae5983 100644 --- a/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c +++ b/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c @@ -52,6 +52,19 @@ #include "FreeRTOS_ND.h" #include "FreeRTOS_RA_stubs.c" +/* ================================ TYPES ================================= */ + +#include "pack_struct_start.h" +struct xEthernetPacketICMPv6RouterAdvertisementPrefixOption +{ + EthernetHeader_t xEthernetHeader; /* 0 + 14 = 14 */ + IPHeader_IPv6_t xIPHeader; /* 14 + 40 = 54 */ + ICMPRouterAdvertisement_IPv6_t xAdvertisement; /* 54 + 16 = 70 */ + ICMPPrefixOption_IPv6_t xPrefixOption; /* 70 + 32 = 102 */ +} +#include "pack_struct_end.h" +typedef struct xEthernetPacketICMPv6RouterAdvertisementPrefixOption EthernetPacketICMPv6RouterAdvertisementPrefixOption_t; + /* =========================== EXTERN VARIABLES =========================== */ /** The default value for the IPv6-field 'ucVersionTrafficClass'. */ @@ -866,17 +879,15 @@ void test_vReceiveRA_ValidICMPPrefix_IncorrectOption( void ) */ void test_vReceiveRA_vRAProccess( void ) { - NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer, xNetworkBuffer2; - ICMPPacket_IPv6_t xICMPPacket; + NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; + EthernetPacketICMPv6RouterAdvertisementPrefixOption_t xICMPPacket; NetworkInterface_t xInterface; - size_t uxIndex = 0U, uxNeededSize, uxOptionsLength; - uint8_t * pucBytes; NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; ICMPPrefixOption_IPv6_t * pxPrefixOption; ICMPRouterAdvertisement_IPv6_t * pxAdvertisement; memset( &xNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) ); - memset( &xICMPPacket, 0, sizeof( ICMPPacket_IPv6_t ) ); + memset( &xICMPPacket, 0, sizeof( xICMPPacket ) ); memset( &xInterface, 0, sizeof( NetworkInterface_t ) ); memset( &xEndPoint, 0, sizeof( NetworkEndPoint_t ) ); @@ -884,11 +895,10 @@ void test_vReceiveRA_vRAProccess( void ) pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; pxNetworkBuffer->pxInterface = &xInterface; pxNetworkBuffer->xDataLength = raHeaderBytesRA + raPrefixOptionlen; - uxNeededSize = raHeaderBytesRA; - pxAdvertisement = ( ( ICMPRouterAdvertisement_IPv6_t * ) &( xICMPPacket.xICMPHeaderIPv6 ) ); + pxAdvertisement = &xICMPPacket.xAdvertisement; pxAdvertisement->usLifetime = pdTRUE_UNSIGNED; - pxPrefixOption = ( ICMPPrefixOption_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxNeededSize ] ); + pxPrefixOption = &xICMPPacket.xPrefixOption; pxPrefixOption->ucType = ndICMP_PREFIX_INFORMATION; /* Only 1 option */ pxPrefixOption->ucLength = 1; @@ -906,17 +916,15 @@ void test_vReceiveRA_vRAProccess( void ) */ void test_vReceiveRA_vRAProcess( void ) { - NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer, xNetworkBuffer2; - ICMPPacket_IPv6_t xICMPPacket; + NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; + EthernetPacketICMPv6RouterAdvertisementPrefixOption_t xICMPPacket; NetworkInterface_t xInterface; - size_t uxIndex = 0U, uxNeededSize, uxOptionsLength; - uint8_t * pucBytes; NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; ICMPPrefixOption_IPv6_t * pxPrefixOption; ICMPRouterAdvertisement_IPv6_t * pxAdvertisement; memset( &xNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) ); - memset( &xICMPPacket, 0, sizeof( ICMPPacket_IPv6_t ) ); + memset( &xICMPPacket, 0, sizeof( xICMPPacket ) ); memset( &xInterface, 0, sizeof( NetworkInterface_t ) ); memset( &xEndPoint, 0, sizeof( NetworkEndPoint_t ) ); @@ -924,11 +932,10 @@ void test_vReceiveRA_vRAProcess( void ) pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; pxNetworkBuffer->pxInterface = &xInterface; pxNetworkBuffer->xDataLength = raHeaderBytesRA + raPrefixOptionlen; - uxNeededSize = raHeaderBytesRA; - pxAdvertisement = ( ( ICMPRouterAdvertisement_IPv6_t * ) &( xICMPPacket.xICMPHeaderIPv6 ) ); + pxAdvertisement = &xICMPPacket.xAdvertisement; pxAdvertisement->usLifetime = pdTRUE_UNSIGNED; - pxPrefixOption = ( ICMPPrefixOption_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxNeededSize ] ); + pxPrefixOption = &xICMPPacket.xPrefixOption; pxPrefixOption->ucType = ndICMP_PREFIX_INFORMATION; /* Only 1 option */ pxPrefixOption->ucLength = 1; diff --git a/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c b/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c index 13525f135..4275506bf 100644 --- a/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c +++ b/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c @@ -2379,8 +2379,8 @@ void test_pcEndpointName_IPv4_HappyPath() { NetworkEndPoint_t xEndPoint; FreeRTOS_Socket_t xSocket; - char cIPString[] = "192.168.123.223"; - int lNameSize = sizeof( cIPString ) + 1; + static const char cIPString[] = "192.168.123.223"; + uint32_t lNameSize = sizeof( cIPString ); char cName[ lNameSize ]; const char * pcName = NULL; @@ -2388,7 +2388,7 @@ void test_pcEndpointName_IPv4_HappyPath() memset( &xEndPoint, 0, sizeof( NetworkEndPoint_t ) ); xEndPoint.ipv4_settings.ulIPAddress = IPV4_DEFAULT_ADDRESS; - memset( &cName, 0, sizeof( cName ) ); + memset( cName, 0, sizeof( cName ) ); xStubFreeRTOS_inet_ntop_TargetFamily = FREERTOS_AF_INET4; pvStubFreeRTOS_inet_ntop_TargetSource = &( xEndPoint.ipv4_settings.ulIPAddress ); @@ -2507,8 +2507,8 @@ void test_pcEndpointName_IPv6_HappyPath() { NetworkEndPoint_t xEndPoint; FreeRTOS_Socket_t xSocket; - const char cIPString[] = "2001::1"; - int lNameSize = sizeof( cIPString ) + 1; + static const char cIPString[] = "2001::1"; + uint32_t lNameSize = sizeof( cIPString ); char cName[ lNameSize ]; const char * pcName; @@ -2517,7 +2517,7 @@ void test_pcEndpointName_IPv6_HappyPath() xEndPoint.bits.bIPv6 = pdTRUE; memcpy( xEndPoint.ipv6_settings.xIPAddress.ucBytes, &xDefaultIPAddress_IPv6.ucBytes, sizeof( IPv6_Address_t ) ); - memset( &cName, 0, sizeof( cName ) ); + memset( cName, 0, sizeof( cName ) ); xStubFreeRTOS_inet_ntop_TargetFamily = FREERTOS_AF_INET6; pvStubFreeRTOS_inet_ntop_TargetSource = xEndPoint.ipv6_settings.xIPAddress.ucBytes; diff --git a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_stubs.c b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_stubs.c index 34fe7a2c2..2ac484752 100644 --- a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_stubs.c +++ b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_stubs.c @@ -54,6 +54,8 @@ BaseType_t xRNGStatus; BaseType_t xLocalReceiveCallback_Return; uint8_t xLocalReceiveCallback_Called = 0; +BaseType_t xTCPWindowLoggingLevel = 0; + /* ======================== Stub Callback Functions ========================= */ EventBits_t xStubForEventGroupWaitBits( EventGroupHandle_t xEventGroup, diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig/FreeRTOS_Sockets_DiffConfig_privates_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig/FreeRTOS_Sockets_DiffConfig_privates_utest.c index 3b612ec21..0c61574b0 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig/FreeRTOS_Sockets_DiffConfig_privates_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig/FreeRTOS_Sockets_DiffConfig_privates_utest.c @@ -56,7 +56,11 @@ #include "catch_assert.h" -/* ============================== Test Cases ============================== */ +/* ============================ EXTERN VARIABLES ============================ */ + +BaseType_t xTCPWindowLoggingLevel = 0; + +/* =============================== Test Cases =============================== */ /** * @brief Binding successful. diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_GenericAPI_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_GenericAPI_utest.c index c20dba919..9b43c4c6e 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_GenericAPI_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_GenericAPI_utest.c @@ -53,7 +53,9 @@ /* ============================ EXTERN VARIABLES ============================ */ /* 2001::1 */ -static IPv6_Address_t xIPv6Address = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; +static const IPv6_Address_t xIPv6Address = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; + +BaseType_t xTCPWindowLoggingLevel = 0; /* ============================== Test Cases ============================== */ @@ -231,7 +233,7 @@ void test_FreeRTOS_connect_SocketValuesNULL_NullDestinationAddress( void ) void test_prvSocketProps_UDPv6() { FreeRTOS_Socket_t xSocket; - IPv6_Address_t * pxIPv6SrcAddress = &xIPv6Address; /* 2001::1 */ + const IPv6_Address_t * pxIPv6SrcAddress = &xIPv6Address; /* 2001::1 */ uint16_t usSrcPort = 1024U; const char * pcReturn; @@ -251,7 +253,7 @@ void test_prvSocketProps_UDPv6() void test_prvSocketProps_TCPv6() { FreeRTOS_Socket_t xSocket; - IPv6_Address_t * pxIPv6SrcAddress = &xIPv6Address; /* 2001::1 */ + const IPv6_Address_t * pxIPv6SrcAddress = &xIPv6Address; /* 2001::1 */ IPv6_Address_t xIPv6RemoteAddress = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 } }; /* 2001::2 */ uint16_t usSrcPort = 1024U; uint16_t usRemotePort = 2048U; diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_TCP_API_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_TCP_API_utest.c index 361b05fa1..03b368752 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_TCP_API_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_TCP_API_utest.c @@ -50,7 +50,9 @@ /* ============================ EXTERN VARIABLES ============================ */ /* 2001::1 */ -static IPv6_Address_t xIPv6Address = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; +static const IPv6_Address_t xIPv6Address = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; + +BaseType_t xTCPWindowLoggingLevel = 0; /* =============================== Test Cases =============================== */ diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_UDP_API_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_UDP_API_utest.c index 7fe936377..af3ee7d8f 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_UDP_API_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_UDP_API_utest.c @@ -46,6 +46,8 @@ #define TEST_MAX_UDPV4_PAYLOAD_LENGTH ipconfigNETWORK_MTU - ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_UDP_HEADER ) +BaseType_t xTCPWindowLoggingLevel = 0; + /* =============================== Test Cases =============================== */ /** diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_privates_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_privates_utest.c index 45e196889..752aef9c0 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_privates_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_privates_utest.c @@ -54,6 +54,8 @@ BaseType_t prvDetermineSocketSize( BaseType_t xDomain, BaseType_t xProtocol, size_t * pxSocketSize ); +BaseType_t xTCPWindowLoggingLevel = 0; + /* ============================== Test Cases ============================== */ /** diff --git a/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c b/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c index 94a972213..7eee3348c 100644 --- a/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c +++ b/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c @@ -1076,7 +1076,12 @@ void test_vTCPStateChange_ClosedWaitState_CallingFromIPTask( void ) xIsCallingFromIPTask_ExpectAndReturn( pdTRUE ); - vSocketClose_ExpectAnyArgsAndReturn( NULL ); + /* FIXME: Different behaviour with -fsanitize=address,undefined. */ + if( xSocketToClose != &xSocket ) + { + vSocketClose_ExpectAnyArgsAndReturn( NULL ); + } + xTaskResumeAll_ExpectAndReturn( 0 ); xTaskGetTickCount_ExpectAndReturn( xTickCountAck ); @@ -1173,6 +1178,12 @@ void test_vTCPStateChange_ClosedWaitState_CallingFromIPTask1( void ) xIsCallingFromIPTask_ExpectAndReturn( pdTRUE ); + /* FIXME: Different behaviour with -fsanitize=address,undefined. */ + if( xSocketToClose != &xSocket ) + { + vSocketClose_ExpectAnyArgsAndReturn( NULL ); + } + xTaskResumeAll_ExpectAndReturn( 0 ); xTaskGetTickCount_ExpectAndReturn( xTickCountAck ); @@ -1809,17 +1820,18 @@ void test_xProcessReceivedTCPPacket_Null_Buffer( void ) void test_xProcessReceivedTCPPacket_IPv6_FrameType( void ) { BaseType_t Return = pdFALSE; - EthernetHeader_t xEthHeader; + uint8_t xEthBuffer[ 1500 ] = { 0 }; - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xEthHeader; + ( ( EthernetHeader_t * ) xEthBuffer )->usFrameType = ipIPv6_FRAME_TYPE; - xEthHeader.usFrameType = ipIPv6_FRAME_TYPE; + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pucEthernetBuffer = xEthBuffer; pxNetworkBuffer->xDataLength = 100; uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( NULL ); + prvTCPSendReset_ExpectAnyArgsAndReturn( pdTRUE ); Return = xProcessReceivedTCPPacket( pxNetworkBuffer ); diff --git a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c index 745dc1a20..99b3bbc39 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c +++ b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c @@ -813,6 +813,7 @@ void test_prvTCPReturnPacket_No_KL( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxSocket->pxEndPoint = &xEndPoint; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -867,6 +868,7 @@ void test_prvTCPReturnPacket_No_KL_LocalIP( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxSocket->pxEndPoint = &xEndPoint; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -927,6 +929,7 @@ void test_prvTCPReturnPacket_No_KL_LocalIP_GT_Eth_Packet_Length( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -966,6 +969,7 @@ void test_prvTCPReturnPacket_No_KL_LocalIP_ARP_Not_Hit( void ) xEndPoint.pxNetworkInterface->pfOutput = &NetworkInterfaceOutputFunction_Stub; NetworkInterfaceOutputFunction_Stub_Called = 0; pxSocket->pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; pxSocket->u.xTCP.rxStream = ( StreamBuffer_t * ) 0x12345678; pxSocket->u.xTCP.uxRxStreamSize = 1500; @@ -1035,6 +1039,7 @@ void test_prvTCPReturnPacket_No_KL_Fin_Suppress_Rx_Stop( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxTCPPacket->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_FIN; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizeSocket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); @@ -1086,6 +1091,7 @@ void test_prvTCPReturnPacket_No_KL_Fin_Not_Suppress_Low_Water( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxTCPPacket->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_FIN; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizeSocket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); @@ -1137,6 +1143,7 @@ void test_prvTCPReturnPacket_No_KL_Fin_Not_Suppress_Big_Win( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxTCPPacket->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_FIN; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizeSocket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); @@ -2151,6 +2158,7 @@ void test_prvSendData_AckMsg_Not_Null_Small_Length( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); vReleaseNetworkBufferAndDescriptor_ExpectAnyArgs(); @@ -2207,7 +2215,7 @@ void test_prvSendData_AckMsg_Not_Null_Same_NetBuffer_Syn_State( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; - + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -2263,6 +2271,7 @@ void test_prvSendData_AckMsg_Not_Null_Same_NetBuffer_Syn_State_Data_To_Send( voi pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -2318,6 +2327,7 @@ void test_prvSendData_AckMsg_Null_Syn_State_Data_To_Send( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -2374,6 +2384,7 @@ void test_prvSendData_AckMsg_Null_Syn_State_Data_To_Send_Log( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -2430,6 +2441,7 @@ void test_prvSendData_AckMsg_Null_Syn_State_Data_To_Send_Rcv_Zero( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); diff --git a/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c b/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c index dfabac374..99e800e41 100644 --- a/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c +++ b/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c @@ -193,12 +193,15 @@ void test_vTCPWindowDestroy_list_length_zero( void ) void test_vTCPWindowDestroy_list_length_not_zero( void ) { TCPWindow_t xWindow = { 0 }; - List_t * pxSegments = &( xWindow.xRxSegments ); + TCPSegment_t xSegment = { 0 }; + + xSegment.xQueueItem.pvContainer = &xWindow.xPriorityQueue; + xSegment.xSegmentItem.pvContainer = &xWindow.xPriorityQueue; listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdFALSE ); listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdTRUE ); listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 1 ); - listGET_OWNER_OF_HEAD_ENTRY_ExpectAnyArgsAndReturn( pxSegments ); + listGET_OWNER_OF_HEAD_ENTRY_ExpectAnyArgsAndReturn( &xSegment ); /* ->vTCPWindowFree */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); @@ -389,11 +392,14 @@ void test_vTCPSegmentCleanup_segment_null( void ) void test_vTCPSegmentCleanup_segment_not_null( void ) { /* will be freed by the function under test */ - xTCPSegments = ( TCPSegment_t * ) malloc( 123 ); + TCPSegment_t * pxTCPSegment = malloc( sizeof( TCPSegment_t ) ); + + xTCPSegments = pxTCPSegment; vPortFree_Expect( xTCPSegments ); vTCPSegmentCleanup(); TEST_ASSERT_NULL( xTCPSegments ); + free( pxTCPSegment ); } void test_lTCPWindowRxCheck_sequence_nums_equal( void ) @@ -1044,13 +1050,14 @@ void test_lTCPWindowTxAdd_nothing_to_do( void ) { int32_t lDone; TCPWindow_t xWindow = { 0 }; + TCPSegment_t xSegment = { 0 }; uint32_t ulLength = 0; int32_t lPosition = 0; int32_t lMax = 0; BaseType_t xBackup = xTCPWindowLoggingLevel; /* in real code, this points to a list of segments */ - xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) ); + xWindow.pxHeadSegment = &xSegment; xTCPWindowLoggingLevel = 3; @@ -1062,7 +1069,6 @@ void test_lTCPWindowTxAdd_nothing_to_do( void ) TEST_ASSERT_EQUAL( 0, lDone ); xTCPWindowLoggingLevel = xBackup; - free( xWindow.pxHeadSegment ); } void test_lTCPWindowTxAdd_null_txSegment( void ) @@ -1230,7 +1236,9 @@ void test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_gt_maxlen( void ) int32_t lMax = 0; /* in real code, this points to a list of segments */ - xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) ); + TCPSegment_t * pxTCPSegment = malloc( sizeof( TCPSegment_t ) ); + + xWindow.pxHeadSegment = pxTCPSegment; xWindow.pxHeadSegment->lMaxLength = 300; xWindow.pxHeadSegment->lDataLength = 200; xWindow.pxHeadSegment->u.bits.bOutstanding = pdTRUE_UNSIGNED; @@ -1262,7 +1270,7 @@ void test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_gt_maxlen( void ) TEST_ASSERT_EQUAL( 25, lDone ); TEST_ASSERT_NULL( xWindow.pxHeadSegment ); - free( xWindow.pxHeadSegment ); + free( pxTCPSegment ); } void test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_lt_maxlen( void ) diff --git a/test/unit-test/FreeRTOS_TCP_WIN/ut.cmake b/test/unit-test/FreeRTOS_TCP_WIN/ut.cmake index b36711c84..309104dc8 100644 --- a/test/unit-test/FreeRTOS_TCP_WIN/ut.cmake +++ b/test/unit-test/FreeRTOS_TCP_WIN/ut.cmake @@ -32,7 +32,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/FreeRTOS_Tiny_TCP/ut.cmake b/test/unit-test/FreeRTOS_Tiny_TCP/ut.cmake index 656973395..959ae9dd9 100644 --- a/test/unit-test/FreeRTOS_Tiny_TCP/ut.cmake +++ b/test/unit-test/FreeRTOS_Tiny_TCP/ut.cmake @@ -29,7 +29,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/cmock/create_test.cmake b/test/unit-test/cmock/create_test.cmake index e44be268c..f8e46c1e6 100644 --- a/test/unit-test/cmock/create_test.cmake +++ b/test/unit-test/cmock/create_test.cmake @@ -19,7 +19,7 @@ function(create_test test_name ) add_executable(${test_name} ${test_src} ${test_name}_runner.c) set_target_properties(${test_name} PROPERTIES - COMPILE_FLAG "-Wall -O0 -ggdb" + COMPILE_FLAG "-Wall -ggdb3" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/tests" INSTALL_RPATH_USE_LINK_PATH TRUE LINK_FLAGS " \