diff --git a/source/FreeRTOS_ARP.c b/source/FreeRTOS_ARP.c index 6ca491203..4484fe177 100644 --- a/source/FreeRTOS_ARP.c +++ b/source/FreeRTOS_ARP.c @@ -521,6 +521,8 @@ const IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); const IPV4Parameters_t * pxIPv4Settings = &( pxNetworkBuffer->pxEndPoint->ipv4_settings ); + /* configASSERT( ( pxIPPacket->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ) || ( pxIPPacket->xEthernetHeader.usFrameType == ipARP_FRAME_TYPE ) ); */ + if( ( pxIPHeader->ulSourceIPAddress & pxIPv4Settings->ulNetMask ) == ( pxIPv4Settings->ulIPAddress & pxIPv4Settings->ulNetMask ) ) { /* If the IP is on the same subnet and we do not have an ARP entry already, @@ -908,7 +910,6 @@ /* Get the lowest 23 bits of the IP-address. */ vSetMultiCastIPv4MacAddress( ulAddressToLookup, pxMACAddress ); - eReturn = eResolutionFailed; pxEndPoint = FreeRTOS_FirstEndPoint( NULL ); for( ; @@ -1329,8 +1330,6 @@ } /*-----------------------------------------------------------*/ - - /** * @brief Generate an ARP request packet by copying various constant details to * the buffer. diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index 484edb18a..bea4970d6 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -1778,7 +1778,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor case eWaitingResolution: #if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) - if( pxEthernetHeader->usFrameType == ipIPv4_FRAME_TYPE ) + if( ( pxEthernetHeader->usFrameType == ipIPv4_FRAME_TYPE ) || ( pxEthernetHeader->usFrameType == ipARP_FRAME_TYPE ) ) { if( pxARPWaitingNetworkBuffer == NULL ) { diff --git a/source/FreeRTOS_ND.c b/source/FreeRTOS_ND.c index 934371882..8c3458e2a 100644 --- a/source/FreeRTOS_ND.c +++ b/source/FreeRTOS_ND.c @@ -1356,6 +1356,8 @@ IPv6_Address_t * pxIPAddress = &( pxIPHeader->xSourceAddress ); uint8_t ucNextHeader = pxIPHeader->ucNextHeader; + configASSERT( pxIPPacket->xEthernetHeader.usFrameType == ipIPv6_FRAME_TYPE ); + if( ( ucNextHeader == ipPROTOCOL_TCP ) || ( ucNextHeader == ipPROTOCOL_UDP ) ) { diff --git a/test.sh b/test.sh new file mode 100755 index 000000000..9e79d0b18 --- /dev/null +++ b/test.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# This script should be run from the root directory of the FreeRTOS+TCP repo. + +if [[ ! -d source ]]; then + echo "Please run this script from the root directory of the FreeRTOS+TCP repo." + exit 1 +fi + +clear + +UNIT_TEST_DIR="test/unit-test" +BUILD_DIR="${UNIT_TEST_DIR}/build/" + +# Create the build directory using CMake: +rm -rf ${BUILD_DIR} +cmake -S ${UNIT_TEST_DIR} -B ${BUILD_DIR} -G Ninja + +# Create the executables: +ninja -C ${BUILD_DIR} all + +pushd ${BUILD_DIR} +# Run the tests for all units +ctest -E system --output-on-failure +popd + +# Calculate the coverage +# ninja -C ${BUILD_DIR} coverage +# lcov --list --rc lcov_branch_coverage=1 ${BUILD_DIR}coverage.info diff --git a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c index 5f2c192c5..9c85f1aeb 100644 --- a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c +++ b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c @@ -492,6 +492,7 @@ void test_prvIPTask( void ) /* In prvIPTask_Initialise. */ vTCPTimerReload_ExpectAnyArgs(); vIPSetARPResolutionTimerEnableState_Expect( pdFALSE ); + vIPSetNDResolutionTimerEnableState_Expect( pdFALSE ); vDNSInitialise_Ignore(); FreeRTOS_dnsclear_Ignore(); @@ -533,6 +534,7 @@ void test_prvIPTask_NetworkDown( void ) /* In prvIPTask_Initialise. */ vTCPTimerReload_ExpectAnyArgs(); vIPSetARPResolutionTimerEnableState_Expect( pdFALSE ); + vIPSetNDResolutionTimerEnableState_Expect( pdFALSE ); vDNSInitialise_Ignore(); FreeRTOS_dnsclear_Ignore(); @@ -731,7 +733,7 @@ void test_prvProcessIPEventsAndTimers_eNetworkRxEvent_NullEndPoint( void ) /** * @brief test_prvProcessIPEventsAndTimers_eARPTimerEvent - * Check if prvProcessIPEventsAndTimers() updates the cache for ARP/ND when timeout event triggered. + * Check if prvProcessIPEventsAndTimers() updates the cache for ARP when timeout event triggered. */ void test_prvProcessIPEventsAndTimers_eARPTimerEvent( void ) { @@ -746,6 +748,26 @@ void test_prvProcessIPEventsAndTimers_eARPTimerEvent( void ) xQueueReceive_ExpectAnyArgsAndReturn( pdTRUE ); xQueueReceive_ReturnMemThruPtr_pvBuffer( &xReceivedEvent, sizeof( xReceivedEvent ) ); vARPAgeCache_Expect(); + + prvProcessIPEventsAndTimers(); +} + +/** + * @brief test_prvProcessIPEventsAndTimers_eNDTimerEvent + * Check if prvProcessIPEventsAndTimers() updates the cache for ND when timeout event triggered. + */ +void test_prvProcessIPEventsAndTimers_eNDTimerEvent( void ) +{ + IPStackEvent_t xReceivedEvent; + + xReceivedEvent.eEventType = eNDTimerEvent; + xReceivedEvent.pvData = NULL; + + /* prvProcessIPEventsAndTimers */ + vCheckNetworkTimers_Expect(); + xCalculateSleepTime_ExpectAndReturn( 0 ); + xQueueReceive_ExpectAnyArgsAndReturn( pdTRUE ); + xQueueReceive_ReturnMemThruPtr_pvBuffer( &xReceivedEvent, sizeof( xReceivedEvent ) ); vNDAgeCache_Expect(); prvProcessIPEventsAndTimers(); @@ -4232,7 +4254,14 @@ static void prvIPNetworkUpCalls_Generic( const uint8_t * pucAddress, vApplicationIPNetworkEventHook_Multi_Expect( eNetworkUp, &xEndPoint ); vDNSInitialise_Expect(); - vARPTimerReload_Expect( pdMS_TO_TICKS( 10000 ) ); + if( xEndPoint.bits.bIPv6 == pdTRUE_UNSIGNED ) + { + vNDTimerReload_Expect( pdMS_TO_TICKS( 10000 ) ); + } + else + { + vARPTimerReload_Expect( pdMS_TO_TICKS( 10000 ) ); + } vIPNetworkUpCalls( &xEndPoint ); diff --git a/test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c b/test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c index aac452fca..cac95bf17 100644 --- a/test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c +++ b/test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c @@ -47,6 +47,7 @@ #include "mock_FreeRTOS_IP_Private.h" #include "mock_FreeRTOS_IP_Timers.h" #include "mock_FreeRTOS_ARP.h" +#include "mock_FreeRTOS_ND.h" #include "mock_FreeRTOS_DHCP.h" #include "mock_FreeRTOS_DHCPv6.h" #include "mock_FreeRTOS_Routing.h" @@ -489,11 +490,13 @@ void test_prvProcessNetworkDownEvent_Pass( void ) xEndPoint.bits.bCallDownHook = pdFALSE_UNSIGNED; vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); FreeRTOS_ClearARP_ExpectAnyArgs(); + FreeRTOS_ClearND_ExpectAnyArgs(); vDHCPStop_Expect( &xEndPoint ); @@ -504,6 +507,7 @@ void test_prvProcessNetworkDownEvent_Pass( void ) /* Run again to trigger a different path in the code. */ vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); @@ -511,6 +515,7 @@ void test_prvProcessNetworkDownEvent_Pass( void ) vApplicationIPNetworkEventHook_Multi_Expect( eNetworkDown, &xEndPoint ); FreeRTOS_ClearARP_Expect( &xEndPoint ); + FreeRTOS_ClearND_Expect( &xEndPoint ); vDHCPStop_Expect( &xEndPoint ); @@ -535,11 +540,13 @@ void test_prvProcessNetworkDownEvent_Fail( void ) xEndPoint.bits.bWantDHCP = pdFALSE_UNSIGNED; vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); FreeRTOS_ClearARP_Expect( &xEndPoint ); + FreeRTOS_ClearND_Expect( &xEndPoint ); vIPNetworkUpCalls_Expect( &xEndPoint ); @@ -586,11 +593,13 @@ void test_prvProcessNetworkDownEvent_InterfaceInitFail( void ) xEndPoint.bits.bCallDownHook = pdFALSE_UNSIGNED; vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); FreeRTOS_ClearARP_ExpectAnyArgs(); + FreeRTOS_ClearND_ExpectAnyArgs(); vDHCPStop_Expect( &xEndPoint ); @@ -616,6 +625,7 @@ void test_prvProcessNetworkDownEvent_PassDHCPv6( void ) xEndPoint.bits.bCallDownHook = pdFALSE_UNSIGNED; vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); @@ -628,6 +638,7 @@ void test_prvProcessNetworkDownEvent_PassDHCPv6( void ) FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); FreeRTOS_ClearARP_ExpectAnyArgs(); + FreeRTOS_ClearND_ExpectAnyArgs(); vDHCPv6Stop_Expect( &xEndPoint ); @@ -653,6 +664,7 @@ void test_prvProcessNetworkDownEvent_PassRA( void ) xEndPoint.bits.bCallDownHook = pdFALSE_UNSIGNED; vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); @@ -665,6 +677,7 @@ void test_prvProcessNetworkDownEvent_PassRA( void ) FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); FreeRTOS_ClearARP_ExpectAnyArgs(); + FreeRTOS_ClearND_ExpectAnyArgs(); vIPSetDHCP_RATimerEnableState_Expect( &xEndPoint, pdFALSE ); @@ -692,6 +705,7 @@ void test_prvProcessNetworkDownEvent_PassStaticIP( void ) memcpy( xEndPoint.ipv6_defaults.xIPAddress.ucBytes, xIPv6Address.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); @@ -704,6 +718,7 @@ void test_prvProcessNetworkDownEvent_PassStaticIP( void ) FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); FreeRTOS_ClearARP_ExpectAnyArgs(); + FreeRTOS_ClearND_ExpectAnyArgs(); vIPNetworkUpCalls_Expect( &xEndPoint ); @@ -3128,6 +3143,7 @@ static void prvProcessNetworkDownEvent_Generic( const uint8_t * pucAddress, } vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); @@ -3141,6 +3157,7 @@ static void prvProcessNetworkDownEvent_Generic( const uint8_t * pucAddress, FreeRTOS_ClearARP_Expect( &xEndPoint ); + FreeRTOS_ClearND_Expect( &xEndPoint ); vIPNetworkUpCalls_Expect( &xEndPoint );