@@ -558,6 +558,7 @@ void test_eARPProcessPacket_Request_GratuitousARP( void )
558558 vResetARPClashCounter ();
559559
560560 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( & xEndPoint );
561+ xIsIPv4Loopback_ExpectAndReturn ( ulTargetIP , 0UL );
561562 xIsIPv4Multicast_ExpectAndReturn ( ulTargetIP , 0UL );
562563 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( & xEndPoint );
563564 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( & xEndPoint );
@@ -621,6 +622,7 @@ void test_eARPProcessPacket_Request_GratuitousARP_MACUnchanged( void )
621622 vResetARPClashCounter ();
622623
623624 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( & xEndPoint );
625+ xIsIPv4Loopback_ExpectAndReturn ( ulTargetIP , 0UL );
624626 xIsIPv4Multicast_ExpectAndReturn ( ulTargetIP , 0UL );
625627 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( & xEndPoint );
626628 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( & xEndPoint );
@@ -863,6 +865,7 @@ void test_eARPProcessPacket_Request_GratuitousARP_NonMatchingEndpoint( void )
863865 vResetARPClashCounter ();
864866
865867 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( & xEndPoint );
868+ xIsIPv4Loopback_ExpectAndReturn ( ulTargetIP , 0UL );
866869 xIsIPv4Multicast_ExpectAndReturn ( ulTargetIP , 0UL );
867870 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( & xEndPoint );
868871
@@ -926,6 +929,7 @@ void test_eARPProcessPacket_Request_GratuitousARP_NonMatchingIP( void )
926929 vResetARPClashCounter ();
927930
928931 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( & xEndPoint );
932+ xIsIPv4Loopback_ExpectAndReturn ( ulTargetIP , 0UL );
929933 xIsIPv4Multicast_ExpectAndReturn ( ulTargetIP , 0UL );
930934 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( & xEndPoint );
931935
@@ -2090,6 +2094,7 @@ void test_eARPGetCacheEntry_IPMatchesBroadcastAddr( void )
20902094 ulIPAddress = FreeRTOS_ntohl ( xNetworkAddressing .ulBroadcastAddress );
20912095 /* Not worried about what these functions do. */
20922096 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2097+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
20932098 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
20942099 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( & xEndPoint );
20952100 eResult = eARPGetCacheEntry ( & ulIPAddress , & xMACAddress , & pxEndPoint );
@@ -2112,6 +2117,7 @@ void test_eARPGetCacheEntry_IPMatchesBroadcastAddr_NullEndPointOnNetMask( void )
21122117 ulIPAddress = FreeRTOS_ntohl ( xNetworkAddressing .ulBroadcastAddress );
21132118 /* Not worried about what these functions do. */
21142119 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2120+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
21152121 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
21162122 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( NULL );
21172123 eResult = eARPGetCacheEntry ( & ulIPAddress , & xMACAddress , & pxEndPoint );
@@ -2132,6 +2138,7 @@ void test_eARPGetCacheEntry_MultiCastAddr( void )
21322138 /* =================================================== */
21332139 ulIPAddress = FreeRTOS_ntohl ( xNetworkAddressing .ulBroadcastAddress );
21342140 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2141+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
21352142 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 1UL );
21362143 vSetMultiCastIPv4MacAddress_Ignore ();
21372144 FreeRTOS_FirstEndPoint_ExpectAndReturn ( NULL , NULL );
@@ -2144,6 +2151,7 @@ void test_eARPGetCacheEntry_MultiCastAddr( void )
21442151
21452152 xEndPoint .bits .bIPv6 = 1 ;
21462153 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2154+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
21472155 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 1UL );
21482156 vSetMultiCastIPv4MacAddress_Ignore ();
21492157 FreeRTOS_FirstEndPoint_ExpectAndReturn ( NULL , & xEndPoint );
@@ -2169,6 +2177,7 @@ void test_eARPGetCacheEntry_IPMatchesOtherBroadcastAddr( void )
21692177 ulIPAddress = FreeRTOS_ntohl ( ipBROADCAST_IP_ADDRESS );
21702178 /* Not worried about what these functions do. */
21712179 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2180+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
21722181 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
21732182 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( & xEndPoint );
21742183 eResult = eARPGetCacheEntry ( & ulIPAddress , & xMACAddress , & pxEndPoint );
@@ -2198,6 +2207,7 @@ void test_eARPGetCacheEntry_MatchingInvalidEntry( void )
21982207 /* Not worried about what these functions do. */
21992208 xEndPoint .ipv4_settings .ulGatewayAddress = xNetworkAddressing .ulGatewayAddress ;
22002209 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2210+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
22012211 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
22022212 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( NULL );
22032213 FreeRTOS_FindGateWay_ExpectAnyArgsAndReturn ( & xEndPoint );
@@ -2227,6 +2237,7 @@ void test_eARPGetCacheEntry_MatchingValidEntry( void )
22272237 /* Not worried about what these functions do. */
22282238 xEndPoint .ipv4_settings .ulGatewayAddress = xNetworkAddressing .ulGatewayAddress ;
22292239 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2240+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
22302241 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
22312242 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( NULL );
22322243 FreeRTOS_FindGateWay_ExpectAnyArgsAndReturn ( & xEndPoint );
@@ -2259,6 +2270,7 @@ void test_eARPGetCacheEntry_GatewayAddressZero( void )
22592270 /* Not worried about what these functions do. */
22602271 xEndPoint .ipv4_settings .ulGatewayAddress = 0 ;
22612272 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2273+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
22622274 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
22632275 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( NULL );
22642276 FreeRTOS_FindGateWay_ExpectAnyArgsAndReturn ( NULL );
@@ -2286,6 +2298,7 @@ void test_eARPGetCacheEntry_AddressNotOnLocalAddress( void )
22862298
22872299 /* Not worried about what these functions do. */
22882300 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2301+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
22892302 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
22902303 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( NULL );
22912304 FreeRTOS_FindGateWay_ExpectAnyArgsAndReturn ( NULL );
@@ -2324,6 +2337,7 @@ void test_eARPGetCacheEntry_NoCacheHit( void )
23242337 pxNetworkEndPoints = & xEndPoint ;
23252338 /* Not worried about what these functions do. */
23262339 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2340+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
23272341 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
23282342 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( NULL );
23292343 eResult = eARPGetCacheEntry ( & ulIPAddress , & xMACAddress , & pxEndPoint );
@@ -2333,6 +2347,91 @@ void test_eARPGetCacheEntry_NoCacheHit( void )
23332347 /* =================================================== */
23342348}
23352349
2350+ /**
2351+ * @brief Test the scenario that the address given is a loopback address
2352+ * but there is no loopback endpoint
2353+ */
2354+ void test_eARPGetCacheEntry_LoopbackAddress ( void )
2355+ {
2356+ uint32_t ulIPAddress ;
2357+ MACAddress_t xMACAddress = { 0 };
2358+ MACAddress_t xMACAddressExp = { 0 };
2359+ eARPLookupResult_t eResult ;
2360+ uint32_t ulSavedGatewayAddress ;
2361+ struct xNetworkInterface * xInterface ;
2362+ struct xNetworkEndPoint * pxEndPoint , xEndPoint ;
2363+ int i ;
2364+
2365+ /* =================================================== */
2366+ for ( i = 0 ; i < ipconfigARP_CACHE_ENTRIES ; i ++ )
2367+ {
2368+ xARPCache [ i ].ulIPAddress = 0 ;
2369+ xARPCache [ i ].ucValid = ( uint8_t ) pdTRUE ;
2370+ xARPCache [ i ].pxEndPoint = NULL ;
2371+ }
2372+
2373+ ulSavedGatewayAddress = xNetworkAddressing .ulGatewayAddress ;
2374+ xNetworkAddressing .ulGatewayAddress = 0 ;
2375+ /* Make IP address param == 0 */
2376+ ulIPAddress = 0x7F000000UL ;
2377+
2378+ /* Make both values (IP address and local IP pointer) different
2379+ * and on different net masks. */
2380+ xEndPoint .ipv4_settings .ulIPAddress = 0x1234 ;
2381+ pxNetworkEndPoints = & xEndPoint ;
2382+ /* Not worried about what these functions do. */
2383+ FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2384+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 1UL );
2385+ eResult = eARPGetCacheEntry ( & ulIPAddress , & xMACAddress , & pxEndPoint );
2386+ TEST_ASSERT_EQUAL ( eCantSendPacket , eResult );
2387+ TEST_ASSERT_NOT_EQUAL ( pxEndPoint , & xEndPoint );
2388+ TEST_ASSERT_EQUAL_MEMORY ( xMACAddressExp .ucBytes , xMACAddress .ucBytes , sizeof ( MACAddress_t ) );
2389+ /* =================================================== */
2390+ }
2391+
2392+ /**
2393+ * @brief Test the scenario that the address given is a loopback address
2394+ * and there is a loopback endpoint
2395+ */
2396+ void test_eARPGetCacheEntry_LoopbackAddress_ValidLPEndpoint ( void )
2397+ {
2398+ uint32_t ulIPAddress ;
2399+ MACAddress_t xMACAddress = { 0 };
2400+ MACAddress_t xMACAddressExp = { 0x11 , 0x22 , 0x33 , 0x11 , 0x22 , 0x33 };
2401+ eARPLookupResult_t eResult ;
2402+ uint32_t ulSavedGatewayAddress ;
2403+ struct xNetworkInterface * xInterface ;
2404+ struct xNetworkEndPoint * pxEndPoint , xEndPoint ;
2405+ int i ;
2406+
2407+ /* =================================================== */
2408+ for ( i = 0 ; i < ipconfigARP_CACHE_ENTRIES ; i ++ )
2409+ {
2410+ xARPCache [ i ].ulIPAddress = 0 ;
2411+ xARPCache [ i ].ucValid = ( uint8_t ) pdTRUE ;
2412+ xARPCache [ i ].pxEndPoint = NULL ;
2413+ }
2414+
2415+ ulSavedGatewayAddress = xNetworkAddressing .ulGatewayAddress ;
2416+ xNetworkAddressing .ulGatewayAddress = 0 ;
2417+ /* Make IP address param == 0 */
2418+ ulIPAddress = 0x7F000000UL ;
2419+
2420+ /* Make both values (IP address and local IP pointer) different
2421+ * and on different net masks. */
2422+ xEndPoint .ipv4_settings .ulIPAddress = 0x1234 ;
2423+ memcpy ( xEndPoint .xMACAddress .ucBytes , xMACAddressExp .ucBytes , sizeof ( MACAddress_t ) );
2424+ pxNetworkEndPoints = & xEndPoint ;
2425+ /* Not worried about what these functions do. */
2426+ FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( & xEndPoint );
2427+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 1UL );
2428+ eResult = eARPGetCacheEntry ( & ulIPAddress , & xMACAddress , & pxEndPoint );
2429+ TEST_ASSERT_EQUAL ( eARPCacheHit , eResult );
2430+ TEST_ASSERT_EQUAL ( pxEndPoint , & xEndPoint );
2431+ TEST_ASSERT_EQUAL_MEMORY ( xMACAddressExp .ucBytes , xMACAddress .ucBytes , sizeof ( MACAddress_t ) );
2432+ /* =================================================== */
2433+ }
2434+
23362435void test_vARPAgeCache ( void )
23372436{
23382437 NetworkEndPoint_t xEndPoint = { 0 };
@@ -2641,6 +2740,7 @@ void test_xARPWaitResolution_PrivateFunctionReturnsHit( void )
26412740 xIsCallingFromIPTask_IgnoreAndReturn ( pdFALSE );
26422741 /* Not worried about what these functions do. */
26432742 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2743+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
26442744 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 1UL );
26452745 vSetMultiCastIPv4MacAddress_Ignore ();
26462746 FreeRTOS_FirstEndPoint_ExpectAndReturn ( NULL , & xEndPoint );
@@ -2679,6 +2779,7 @@ void test_xARPWaitResolution_GNWFailsNoTimeout( void )
26792779 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
26802780 xIsCallingFromIPTask_IgnoreAndReturn ( pdFALSE );
26812781 /* Not worried about what these functions do. */
2782+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
26822783 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
26832784 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( ( void * ) 1234 );
26842785
@@ -2691,6 +2792,7 @@ void test_xARPWaitResolution_GNWFailsNoTimeout( void )
26912792 pxGetNetworkBufferWithDescriptor_ExpectAndReturn ( sizeof ( ARPPacket_t ), 0 , NULL );
26922793 vTaskDelay_Expect ( pdMS_TO_TICKS ( 250U ) );
26932794 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2795+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
26942796 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
26952797 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( ( void * ) 1234 );
26962798 xTaskCheckForTimeOut_IgnoreAndReturn ( pdFALSE );
@@ -2730,6 +2832,7 @@ void test_xARPWaitResolution( void )
27302832 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
27312833 xIsCallingFromIPTask_IgnoreAndReturn ( pdFALSE );
27322834 /* Not worried about what these functions do. */
2835+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
27332836 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
27342837 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( ( void * ) 1234 );
27352838
@@ -2742,6 +2845,7 @@ void test_xARPWaitResolution( void )
27422845 pxGetNetworkBufferWithDescriptor_ExpectAndReturn ( sizeof ( ARPPacket_t ), 0 , NULL );
27432846 vTaskDelay_Expect ( pdMS_TO_TICKS ( 250U ) );
27442847 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2848+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
27452849 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
27462850 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( ( void * ) 1234 );
27472851 xTaskCheckForTimeOut_IgnoreAndReturn ( pdFALSE );
@@ -2751,6 +2855,7 @@ void test_xARPWaitResolution( void )
27512855 pxGetNetworkBufferWithDescriptor_ExpectAndReturn ( sizeof ( ARPPacket_t ), 0 , NULL );
27522856 vTaskDelay_Expect ( pdMS_TO_TICKS ( 250U ) );
27532857 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2858+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
27542859 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
27552860 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( ( void * ) 1234 );
27562861 xTaskCheckForTimeOut_IgnoreAndReturn ( pdTRUE );
@@ -2778,6 +2883,7 @@ void test_xARPWaitResolution( void )
27782883 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
27792884 xIsCallingFromIPTask_IgnoreAndReturn ( pdFALSE );
27802885 /* Not worried about what these functions do. */
2886+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
27812887 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
27822888 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( ( void * ) 1234 );
27832889
@@ -2790,6 +2896,7 @@ void test_xARPWaitResolution( void )
27902896 pxGetNetworkBufferWithDescriptor_ExpectAndReturn ( sizeof ( ARPPacket_t ), 0 , NULL );
27912897 vTaskDelay_Expect ( pdMS_TO_TICKS ( 250U ) );
27922898 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2899+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
27932900 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 0UL );
27942901 FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn ( ( void * ) 1234 );
27952902 xTaskCheckForTimeOut_IgnoreAndReturn ( pdFALSE );
@@ -2799,6 +2906,7 @@ void test_xARPWaitResolution( void )
27992906 pxGetNetworkBufferWithDescriptor_ExpectAndReturn ( sizeof ( ARPPacket_t ), 0 , NULL );
28002907 vTaskDelay_Expect ( pdMS_TO_TICKS ( 250U ) );
28012908 FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn ( NULL );
2909+ xIsIPv4Loopback_ExpectAndReturn ( ulIPAddress , 0UL );
28022910 xIsIPv4Multicast_ExpectAndReturn ( ulIPAddress , 1UL );
28032911 vSetMultiCastIPv4MacAddress_Ignore ();
28042912 FreeRTOS_FirstEndPoint_ExpectAndReturn ( NULL , & xEndPoint );
0 commit comments