Skip to content

Commit

Permalink
Fix almost all of DHCP unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bjsowa committed Oct 6, 2023
1 parent 5a70705 commit 21ca710
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
41 changes: 36 additions & 5 deletions test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_
socklen_t * pxSourceAddressLength,
int callbacks )
{
NetworkEndPoint_t * pxIterator = pxNetworkEndPoints;
while ( pxIterator != NULL )
{
pxIterator->xDHCPData.xDHCPSocket = NULL;
pxIterator = pxIterator->pxNext;
}

if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
Expand All @@ -358,7 +365,6 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );

xDHCPv4Socket = NULL;
return xSizeofUDPBuffer;
}

Expand All @@ -371,8 +377,13 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_
int callbacks )
{
int32_t lBytes = 0;
NetworkEndPoint_t * pxIterator = pxNetworkEndPoints;

xDHCPv4Socket = NULL;
while ( pxIterator != NULL )
{
pxIterator->xDHCPData.xDHCPSocket = NULL;
pxIterator = pxIterator->pxNext;
}

if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
{
Expand Down Expand Up @@ -402,7 +413,13 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_
socklen_t * pxSourceAddressLength,
int callbacks )
{
xDHCPv4Socket = NULL;
NetworkEndPoint_t * pxIterator = pxNetworkEndPoints;

while ( pxIterator != NULL )
{
pxIterator->xDHCPData.xDHCPSocket = NULL;
pxIterator = pxIterator->pxNext;
}

if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
{
Expand Down Expand Up @@ -430,6 +447,14 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_
socklen_t * pxSourceAddressLength,
int callbacks )
{
NetworkEndPoint_t * pxIterator = pxNetworkEndPoints;

while ( pxIterator != NULL )
{
pxIterator->xDHCPData.xDHCPSocket = NULL;
pxIterator = pxIterator->pxNext;
}

if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
Expand All @@ -441,7 +466,6 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );

xDHCPv4Socket = NULL;
return xSizeofUDPBuffer;
}

Expand All @@ -453,6 +477,14 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_
socklen_t * pxSourceAddressLength,
int callbacks )
{
NetworkEndPoint_t * pxIterator = pxNetworkEndPoints;

while ( pxIterator != NULL )
{
pxIterator->xDHCPData.xDHCPSocket = NULL;
pxIterator = pxIterator->pxNext;
}

if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
Expand All @@ -464,7 +496,6 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREQUEST_OPCODE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );

xDHCPv4Socket = NULL;
return xSizeofUDPBuffer;
}

Expand Down
5 changes: 5 additions & 0 deletions test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,7 @@ void test_vDHCPProcess_eLeasedAddress_CorrectState_ValidBytesInMessage_TwoFlagOp
/* This should remain unchanged. */
xDHCPv4Socket = &xTestSocket;
xDHCPSocketUserCount = 1;
pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket;
/* Put the required state. */
pxEndPoint->xDHCPData.eDHCPState = eLeasedAddress;
pxEndPoint->xDHCPData.eExpectedState = eLeasedAddress;
Expand Down Expand Up @@ -1339,6 +1340,7 @@ void test_vDHCPProcess_eLeasedAddress_CorrectState_ValidBytesInMessage_TwoFlagOp
/* This should remain unchanged. */
xDHCPv4Socket = &xTestSocket;
xDHCPSocketUserCount = 1;
pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket;
/* Put the required state. */
pxEndPoint->xDHCPData.eDHCPState = eLeasedAddress;
pxEndPoint->xDHCPData.eExpectedState = eLeasedAddress;
Expand Down Expand Up @@ -1461,6 +1463,7 @@ void test_vDHCPProcess_eWaitingOffer_CorrectState_ValidBytesInMessage_MatchingEn
/* This should remain unchanged. */
xDHCPv4Socket = &xTestSocket;
xDHCPSocketUserCount = 1;
pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket;
/* Put the required state. */
pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer;
pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer;
Expand Down Expand Up @@ -1501,6 +1504,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_CorrectState_ValidBytesInMessage_diff
/* This should remain unchanged. */
xDHCPv4Socket = &xTestSocket;
xDHCPSocketUserCount = 1;
pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket;
/* Put the required state. */
pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer;
pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer;
Expand Down Expand Up @@ -1530,6 +1534,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_CorrectState_ValidBytesInMessage_diff
memset( &pxEndPoint_2->ipv4_defaults, 0xAA, sizeof( IPV4Parameters_t ) );

pxNetworkEndPoints = pxEndPoint_2;
pxEndPoint_2->pxNext = pxEndPoint;

pxEndPoint->xDHCPData.xDHCPTxTime = 100;
pxEndPoint->xDHCPData.xDHCPTxPeriod = 100;
Expand Down

0 comments on commit 21ca710

Please sign in to comment.