Skip to content

Commit dd1f80b

Browse files
committed
Fix Unit Tests
1 parent d5474ee commit dd1f80b

File tree

6 files changed

+81
-6
lines changed

6 files changed

+81
-6
lines changed

source/FreeRTOS_ARP.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@
521521
const IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader );
522522
const IPV4Parameters_t * pxIPv4Settings = &( pxNetworkBuffer->pxEndPoint->ipv4_settings );
523523

524+
/* configASSERT( ( pxIPPacket->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ) || ( pxIPPacket->xEthernetHeader.usFrameType == ipARP_FRAME_TYPE ) ); */
525+
524526
if( ( pxIPHeader->ulSourceIPAddress & pxIPv4Settings->ulNetMask ) == ( pxIPv4Settings->ulIPAddress & pxIPv4Settings->ulNetMask ) )
525527
{
526528
/* If the IP is on the same subnet and we do not have an ARP entry already,
@@ -908,7 +910,6 @@
908910
/* Get the lowest 23 bits of the IP-address. */
909911
vSetMultiCastIPv4MacAddress( ulAddressToLookup, pxMACAddress );
910912

911-
eReturn = eResolutionFailed;
912913
pxEndPoint = FreeRTOS_FirstEndPoint( NULL );
913914

914915
for( ;
@@ -1329,8 +1330,6 @@
13291330
}
13301331
/*-----------------------------------------------------------*/
13311332

1332-
1333-
13341333
/**
13351334
* @brief Generate an ARP request packet by copying various constant details to
13361335
* the buffer.

source/FreeRTOS_IP.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
17781778
case eWaitingResolution:
17791779

17801780
#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )
1781-
if( pxEthernetHeader->usFrameType == ipIPv4_FRAME_TYPE )
1781+
if( ( pxEthernetHeader->usFrameType == ipIPv4_FRAME_TYPE ) || ( pxEthernetHeader->usFrameType == ipARP_FRAME_TYPE ) )
17821782
{
17831783
if( pxARPWaitingNetworkBuffer == NULL )
17841784
{

source/FreeRTOS_ND.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,8 @@
13561356
IPv6_Address_t * pxIPAddress = &( pxIPHeader->xSourceAddress );
13571357
uint8_t ucNextHeader = pxIPHeader->ucNextHeader;
13581358

1359+
configASSERT( pxIPPacket->xEthernetHeader.usFrameType == ipIPv6_FRAME_TYPE );
1360+
13591361
if( ( ucNextHeader == ipPROTOCOL_TCP ) ||
13601362
( ucNextHeader == ipPROTOCOL_UDP ) )
13611363
{

test.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# This script should be run from the root directory of the FreeRTOS+TCP repo.
3+
4+
if [[ ! -d source ]]; then
5+
echo "Please run this script from the root directory of the FreeRTOS+TCP repo."
6+
exit 1
7+
fi
8+
9+
clear
10+
11+
UNIT_TEST_DIR="test/unit-test"
12+
BUILD_DIR="${UNIT_TEST_DIR}/build/"
13+
14+
# Create the build directory using CMake:
15+
rm -rf ${BUILD_DIR}
16+
cmake -S ${UNIT_TEST_DIR} -B ${BUILD_DIR} -G Ninja
17+
18+
# Create the executables:
19+
ninja -C ${BUILD_DIR} all
20+
21+
pushd ${BUILD_DIR}
22+
# Run the tests for all units
23+
ctest -E system --output-on-failure
24+
popd
25+
26+
# Calculate the coverage
27+
# ninja -C ${BUILD_DIR} coverage
28+
# lcov --list --rc lcov_branch_coverage=1 ${BUILD_DIR}coverage.info

test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ void test_prvIPTask( void )
492492
/* In prvIPTask_Initialise. */
493493
vTCPTimerReload_ExpectAnyArgs();
494494
vIPSetARPResolutionTimerEnableState_Expect( pdFALSE );
495+
vIPSetNDResolutionTimerEnableState_Expect( pdFALSE );
495496
vDNSInitialise_Ignore();
496497
FreeRTOS_dnsclear_Ignore();
497498

@@ -533,6 +534,7 @@ void test_prvIPTask_NetworkDown( void )
533534
/* In prvIPTask_Initialise. */
534535
vTCPTimerReload_ExpectAnyArgs();
535536
vIPSetARPResolutionTimerEnableState_Expect( pdFALSE );
537+
vIPSetNDResolutionTimerEnableState_Expect( pdFALSE );
536538
vDNSInitialise_Ignore();
537539
FreeRTOS_dnsclear_Ignore();
538540

@@ -731,7 +733,7 @@ void test_prvProcessIPEventsAndTimers_eNetworkRxEvent_NullEndPoint( void )
731733

732734
/**
733735
* @brief test_prvProcessIPEventsAndTimers_eARPTimerEvent
734-
* Check if prvProcessIPEventsAndTimers() updates the cache for ARP/ND when timeout event triggered.
736+
* Check if prvProcessIPEventsAndTimers() updates the cache for ARP when timeout event triggered.
735737
*/
736738
void test_prvProcessIPEventsAndTimers_eARPTimerEvent( void )
737739
{
@@ -746,6 +748,26 @@ void test_prvProcessIPEventsAndTimers_eARPTimerEvent( void )
746748
xQueueReceive_ExpectAnyArgsAndReturn( pdTRUE );
747749
xQueueReceive_ReturnMemThruPtr_pvBuffer( &xReceivedEvent, sizeof( xReceivedEvent ) );
748750
vARPAgeCache_Expect();
751+
752+
prvProcessIPEventsAndTimers();
753+
}
754+
755+
/**
756+
* @brief test_prvProcessIPEventsAndTimers_eNDTimerEvent
757+
* Check if prvProcessIPEventsAndTimers() updates the cache for ND when timeout event triggered.
758+
*/
759+
void test_prvProcessIPEventsAndTimers_eNDTimerEvent( void )
760+
{
761+
IPStackEvent_t xReceivedEvent;
762+
763+
xReceivedEvent.eEventType = eNDTimerEvent;
764+
xReceivedEvent.pvData = NULL;
765+
766+
/* prvProcessIPEventsAndTimers */
767+
vCheckNetworkTimers_Expect();
768+
xCalculateSleepTime_ExpectAndReturn( 0 );
769+
xQueueReceive_ExpectAnyArgsAndReturn( pdTRUE );
770+
xQueueReceive_ReturnMemThruPtr_pvBuffer( &xReceivedEvent, sizeof( xReceivedEvent ) );
749771
vNDAgeCache_Expect();
750772

751773
prvProcessIPEventsAndTimers();
@@ -4232,7 +4254,14 @@ static void prvIPNetworkUpCalls_Generic( const uint8_t * pucAddress,
42324254

42334255
vApplicationIPNetworkEventHook_Multi_Expect( eNetworkUp, &xEndPoint );
42344256
vDNSInitialise_Expect();
4235-
vARPTimerReload_Expect( pdMS_TO_TICKS( 10000 ) );
4257+
if( xEndPoint.bits.bIPv6 == pdTRUE_UNSIGNED )
4258+
{
4259+
vNDTimerReload_Expect( pdMS_TO_TICKS( 10000 ) );
4260+
}
4261+
else
4262+
{
4263+
vARPTimerReload_Expect( pdMS_TO_TICKS( 10000 ) );
4264+
}
42364265

42374266
vIPNetworkUpCalls( &xEndPoint );
42384267

test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "mock_FreeRTOS_IP_Private.h"
4848
#include "mock_FreeRTOS_IP_Timers.h"
4949
#include "mock_FreeRTOS_ARP.h"
50+
#include "mock_FreeRTOS_ND.h"
5051
#include "mock_FreeRTOS_DHCP.h"
5152
#include "mock_FreeRTOS_DHCPv6.h"
5253
#include "mock_FreeRTOS_Routing.h"
@@ -489,11 +490,13 @@ void test_prvProcessNetworkDownEvent_Pass( void )
489490
xEndPoint.bits.bCallDownHook = pdFALSE_UNSIGNED;
490491

491492
vIPSetARPTimerEnableState_Expect( pdFALSE );
493+
vIPSetNDTimerEnableState_Expect( pdFALSE );
492494

493495
FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint );
494496
FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL );
495497

496498
FreeRTOS_ClearARP_ExpectAnyArgs();
499+
FreeRTOS_ClearND_ExpectAnyArgs();
497500

498501
vDHCPStop_Expect( &xEndPoint );
499502

@@ -504,13 +507,15 @@ void test_prvProcessNetworkDownEvent_Pass( void )
504507
/* Run again to trigger a different path in the code. */
505508

506509
vIPSetARPTimerEnableState_Expect( pdFALSE );
510+
vIPSetNDTimerEnableState_Expect( pdFALSE );
507511

508512
FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint );
509513
FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL );
510514

511515
vApplicationIPNetworkEventHook_Multi_Expect( eNetworkDown, &xEndPoint );
512516

513517
FreeRTOS_ClearARP_Expect( &xEndPoint );
518+
FreeRTOS_ClearND_Expect( &xEndPoint );
514519

515520
vDHCPStop_Expect( &xEndPoint );
516521

@@ -535,11 +540,13 @@ void test_prvProcessNetworkDownEvent_Fail( void )
535540
xEndPoint.bits.bWantDHCP = pdFALSE_UNSIGNED;
536541

537542
vIPSetARPTimerEnableState_Expect( pdFALSE );
543+
vIPSetNDTimerEnableState_Expect( pdFALSE );
538544

539545
FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint );
540546
FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL );
541547

542548
FreeRTOS_ClearARP_Expect( &xEndPoint );
549+
FreeRTOS_ClearND_Expect( &xEndPoint );
543550

544551
vIPNetworkUpCalls_Expect( &xEndPoint );
545552

@@ -586,11 +593,13 @@ void test_prvProcessNetworkDownEvent_InterfaceInitFail( void )
586593
xEndPoint.bits.bCallDownHook = pdFALSE_UNSIGNED;
587594

588595
vIPSetARPTimerEnableState_Expect( pdFALSE );
596+
vIPSetNDTimerEnableState_Expect( pdFALSE );
589597

590598
FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint );
591599
FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL );
592600

593601
FreeRTOS_ClearARP_ExpectAnyArgs();
602+
FreeRTOS_ClearND_ExpectAnyArgs();
594603

595604
vDHCPStop_Expect( &xEndPoint );
596605

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

618627
vIPSetARPTimerEnableState_Expect( pdFALSE );
628+
vIPSetNDTimerEnableState_Expect( pdFALSE );
619629

620630
FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint );
621631

@@ -628,6 +638,7 @@ void test_prvProcessNetworkDownEvent_PassDHCPv6( void )
628638
FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL );
629639

630640
FreeRTOS_ClearARP_ExpectAnyArgs();
641+
FreeRTOS_ClearND_ExpectAnyArgs();
631642

632643
vDHCPv6Stop_Expect( &xEndPoint );
633644

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

655666
vIPSetARPTimerEnableState_Expect( pdFALSE );
667+
vIPSetNDTimerEnableState_Expect( pdFALSE );
656668

657669
FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint );
658670

@@ -665,6 +677,7 @@ void test_prvProcessNetworkDownEvent_PassRA( void )
665677
FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL );
666678

667679
FreeRTOS_ClearARP_ExpectAnyArgs();
680+
FreeRTOS_ClearND_ExpectAnyArgs();
668681

669682
vIPSetDHCP_RATimerEnableState_Expect( &xEndPoint, pdFALSE );
670683

@@ -692,6 +705,7 @@ void test_prvProcessNetworkDownEvent_PassStaticIP( void )
692705
memcpy( xEndPoint.ipv6_defaults.xIPAddress.ucBytes, xIPv6Address.ucBytes, ipSIZE_OF_IPv6_ADDRESS );
693706

694707
vIPSetARPTimerEnableState_Expect( pdFALSE );
708+
vIPSetNDTimerEnableState_Expect( pdFALSE );
695709

696710
FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint );
697711

@@ -704,6 +718,7 @@ void test_prvProcessNetworkDownEvent_PassStaticIP( void )
704718
FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL );
705719

706720
FreeRTOS_ClearARP_ExpectAnyArgs();
721+
FreeRTOS_ClearND_ExpectAnyArgs();
707722

708723
vIPNetworkUpCalls_Expect( &xEndPoint );
709724

@@ -3128,6 +3143,7 @@ static void prvProcessNetworkDownEvent_Generic( const uint8_t * pucAddress,
31283143
}
31293144

31303145
vIPSetARPTimerEnableState_Expect( pdFALSE );
3146+
vIPSetNDTimerEnableState_Expect( pdFALSE );
31313147

31323148
FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint );
31333149

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

31423158

31433159
FreeRTOS_ClearARP_Expect( &xEndPoint );
3160+
FreeRTOS_ClearND_Expect( &xEndPoint );
31443161

31453162
vIPNetworkUpCalls_Expect( &xEndPoint );
31463163

0 commit comments

Comments
 (0)