Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Mar 20, 2024
1 parent 6cac71e commit f3d960f
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 3 deletions.
1 change: 1 addition & 0 deletions test/unit-test/ConfigFiles/FreeRTOSIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@
#define ipconfigUSE_NBNS ( 1 )

#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigUSE_MDNS ( 1 )

#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
Expand Down
116 changes: 113 additions & 3 deletions test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,87 @@ void test_eConsiderFrameForProcessing_LLMNR_MACMatch( void )
TEST_ASSERT_EQUAL( eProcessBuffer, eResult );
}

/**
* @brief test_eConsiderFrameForProcessing_LLMNR_IPv6_MACMatch
* eConsiderFrameForProcessing must return eProcessBuffer when the MAC address in packet
* matches LLMNR MAC address and the frame type is valid.
*/
void test_eConsiderFrameForProcessing_LLMNR_IPv6_MACMatch( void )
{
eFrameProcessingResult_t eResult;
uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ];
EthernetHeader_t * pxEthernetHeader;

/* eConsiderFrameForProcessing */
FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL );

/* Map the buffer onto Ethernet Header struct for easy access to fields. */
pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer;

memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS );

memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xLLMNR_MacAddressIPv6.ucBytes, sizeof( MACAddress_t ) );
pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE;

eResult = eConsiderFrameForProcessing( ucEthernetBuffer );

TEST_ASSERT_EQUAL( eProcessBuffer, eResult );
}

/**
* @brief test_eConsiderFrameForProcessing_MDNS_MACMatch
* eConsiderFrameForProcessing must return eProcessBuffer when the MAC address in packet
* matches MDNS MAC address and the frame type is valid.
*/
void test_eConsiderFrameForProcessing_MDNS_MACMatch( void )
{
eFrameProcessingResult_t eResult;
uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ];
EthernetHeader_t * pxEthernetHeader;

/* eConsiderFrameForProcessing */
FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL );

/* Map the buffer onto Ethernet Header struct for easy access to fields. */
pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer;

memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS );

memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xMDNS_MacAddress.ucBytes, sizeof( MACAddress_t ) );
pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE;

eResult = eConsiderFrameForProcessing( ucEthernetBuffer );

TEST_ASSERT_EQUAL( eProcessBuffer, eResult );
}

/**
* @brief test_eConsiderFrameForProcessing_MDNS_IPv6_MACMatch
* eConsiderFrameForProcessing must return eProcessBuffer when the MAC address in packet
* matches LLMNR MAC address and the frame type is valid.
*/
void test_eConsiderFrameForProcessing_MDNS_IPv6_MACMatch( void )
{
eFrameProcessingResult_t eResult;
uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ];
EthernetHeader_t * pxEthernetHeader;

/* eConsiderFrameForProcessing */
FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL );

/* Map the buffer onto Ethernet Header struct for easy access to fields. */
pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer;

memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS );

memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xMDNS_MACAddressIPv6.ucBytes, sizeof( MACAddress_t ) );
pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE;

eResult = eConsiderFrameForProcessing( ucEthernetBuffer );

TEST_ASSERT_EQUAL( eProcessBuffer, eResult );
}

/**
* @brief test_eConsiderFrameForProcessing_NotMatch
* eConsiderFrameForProcessing must return eReleaseBuffer when the MAC address
Expand Down Expand Up @@ -1690,11 +1771,40 @@ void test_eConsiderFrameForProcessing_NotMatch( void )
}

/**
* @brief test_eConsiderFrameForProcessing_IPv6BroadCastMACMatch
* @brief test_eConsiderFrameForProcessing_Multicast_MACMatch
* eConsiderFrameForProcessing must return eProcessBuffer when the MAC address in packet
* matches IPv6 Multicast MAC address and the frame type is valid.
*/
void test_eConsiderFrameForProcessing_Multicast_MACMatch( void )
{
eFrameProcessingResult_t eResult;
uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ];
EthernetHeader_t * pxEthernetHeader;

/* eConsiderFrameForProcessing */
FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL );

/* Map the buffer onto Ethernet Header struct for easy access to fields. */
pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer;

memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS );

pxEthernetHeader->xDestinationAddress.ucBytes[ 0 ] = ipMULTICAST_MAC_ADDRESS_IPv4_0;
pxEthernetHeader->xDestinationAddress.ucBytes[ 1 ] = ipMULTICAST_MAC_ADDRESS_IPv4_1;
pxEthernetHeader->xDestinationAddress.ucBytes[ 2 ] = ipMULTICAST_MAC_ADDRESS_IPv4_2;
pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE;

eResult = eConsiderFrameForProcessing( ucEthernetBuffer );

TEST_ASSERT_EQUAL( eProcessBuffer, eResult );
}

/**
* @brief test_eConsiderFrameForProcessing_IPv6_Multicast_MACMatch
* eConsiderFrameForProcessing must return eProcessBuffer when the MAC address in packet
* matches IPv6 broadcast MAC address and the frame type is valid.
* matches IPv6 Multicast MAC address and the frame type is valid.
*/
void test_eConsiderFrameForProcessing_IPv6BroadCastMACMatch( void )
void test_eConsiderFrameForProcessing_IPv6_Multicast_MACMatch( void )
{
eFrameProcessingResult_t eResult;
uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ];
Expand Down

0 comments on commit f3d960f

Please sign in to comment.