Skip to content

Commit

Permalink
Fix Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Sep 19, 2024
1 parent d5474ee commit f6a7f40
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
3 changes: 0 additions & 3 deletions source/FreeRTOS_ARP.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,6 @@
/* Get the lowest 23 bits of the IP-address. */
vSetMultiCastIPv4MacAddress( ulAddressToLookup, pxMACAddress );

eReturn = eResolutionFailed;
pxEndPoint = FreeRTOS_FirstEndPoint( NULL );

for( ;
Expand Down Expand Up @@ -1329,8 +1328,6 @@
}
/*-----------------------------------------------------------*/



/**
* @brief Generate an ARP request packet by copying various constant details to
* the buffer.
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
33 changes: 31 additions & 2 deletions test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ void test_prvIPTask( void )
/* In prvIPTask_Initialise. */
vTCPTimerReload_ExpectAnyArgs();
vIPSetARPResolutionTimerEnableState_Expect( pdFALSE );
vIPSetNDResolutionTimerEnableState_Expect( pdFALSE );
vDNSInitialise_Ignore();
FreeRTOS_dnsclear_Ignore();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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 )
{
Expand All @@ -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();
Expand Down Expand Up @@ -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 );

Expand Down
17 changes: 17 additions & 0 deletions test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 );

Expand All @@ -504,13 +507,15 @@ 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 );

vApplicationIPNetworkEventHook_Multi_Expect( eNetworkDown, &xEndPoint );

FreeRTOS_ClearARP_Expect( &xEndPoint );
FreeRTOS_ClearND_Expect( &xEndPoint );

vDHCPStop_Expect( &xEndPoint );

Expand All @@ -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 );

Expand Down Expand Up @@ -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 );

Expand All @@ -616,6 +625,7 @@ void test_prvProcessNetworkDownEvent_PassDHCPv6( void )
xEndPoint.bits.bCallDownHook = pdFALSE_UNSIGNED;

vIPSetARPTimerEnableState_Expect( pdFALSE );
vIPSetNDTimerEnableState_Expect( pdFALSE );

FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint );

Expand All @@ -628,6 +638,7 @@ void test_prvProcessNetworkDownEvent_PassDHCPv6( void )
FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL );

FreeRTOS_ClearARP_ExpectAnyArgs();
FreeRTOS_ClearND_ExpectAnyArgs();

vDHCPv6Stop_Expect( &xEndPoint );

Expand All @@ -653,6 +664,7 @@ void test_prvProcessNetworkDownEvent_PassRA( void )
xEndPoint.bits.bCallDownHook = pdFALSE_UNSIGNED;

vIPSetARPTimerEnableState_Expect( pdFALSE );
vIPSetNDTimerEnableState_Expect( pdFALSE );

FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint );

Expand All @@ -665,6 +677,7 @@ void test_prvProcessNetworkDownEvent_PassRA( void )
FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL );

FreeRTOS_ClearARP_ExpectAnyArgs();
FreeRTOS_ClearND_ExpectAnyArgs();

vIPSetDHCP_RATimerEnableState_Expect( &xEndPoint, pdFALSE );

Expand Down Expand Up @@ -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 );

Expand All @@ -704,6 +718,7 @@ void test_prvProcessNetworkDownEvent_PassStaticIP( void )
FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL );

FreeRTOS_ClearARP_ExpectAnyArgs();
FreeRTOS_ClearND_ExpectAnyArgs();

vIPNetworkUpCalls_Expect( &xEndPoint );

Expand Down Expand Up @@ -3128,6 +3143,7 @@ static void prvProcessNetworkDownEvent_Generic( const uint8_t * pucAddress,
}

vIPSetARPTimerEnableState_Expect( pdFALSE );
vIPSetNDTimerEnableState_Expect( pdFALSE );

FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint );

Expand All @@ -3141,6 +3157,7 @@ static void prvProcessNetworkDownEvent_Generic( const uint8_t * pucAddress,


FreeRTOS_ClearARP_Expect( &xEndPoint );
FreeRTOS_ClearND_Expect( &xEndPoint );

vIPNetworkUpCalls_Expect( &xEndPoint );

Expand Down

0 comments on commit f6a7f40

Please sign in to comment.