@@ -1235,6 +1235,49 @@ void test_vDHCPProcess_eLeasedAddress_CorrectState_ValidBytesInMessage( void )
12351235 TEST_ASSERT_EQUAL ( eLeasedAddress , pxEndPoint -> xDHCPData .eDHCPState );
12361236}
12371237
1238+ /**
1239+ *@brief This test function ensures that when the DHCP states are mismatching after
1240+ * initial parsing of response from DHCP server, if a new response from a different DHCP
1241+ * server will cause a infinite loop inside the vDHCPProcess.
1242+ */
1243+ void test_vDHCPProcess_eLeasedAddress_InCorrectState_Loop ( void )
1244+ {
1245+ struct xSOCKET xTestSocket ;
1246+ NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = & xEndPoint ;
1247+ uint8_t * pucUDPPayload ;
1248+
1249+ /* This should remain unchanged. */
1250+ xDHCPv4Socket = & xTestSocket ;
1251+ xDHCPSocketUserCount = 1 ;
1252+ pxEndPoint -> xDHCPData .xDHCPSocket = & xTestSocket ;
1253+ /* Put the required state. */
1254+ pxEndPoint -> xDHCPData .eDHCPState = eLeasedAddress ;
1255+ pxEndPoint -> xDHCPData .eExpectedState = eLeasedAddress ;
1256+ pxEndPoint -> xDHCPData .ulTransactionId = 0x01ABCDEF ;
1257+
1258+ /* Make sure that the local IP address is uninitialised. */
1259+ pxEndPoint -> ipv4_settings .ulIPAddress = 0 ;
1260+ /* Put a verifiable value. */
1261+ memset ( & pxEndPoint -> ipv4_settings , 0xAA , sizeof ( IPV4Parameters_t ) );
1262+ /* Put a verifiable value. */
1263+ memset ( & pxEndPoint -> ipv4_defaults , 0xBB , sizeof ( IPV4Parameters_t ) );
1264+
1265+ pxNetworkEndPoints = pxEndPoint ;
1266+
1267+ /* Expect these arguments. */
1268+ FreeRTOS_recvfrom_Stub ( FreeRTOS_recvfrom_LoopedCall );
1269+
1270+ FreeRTOS_ReleaseUDPPayloadBuffer_Expect ( pucUDPBuffer );
1271+
1272+ FreeRTOS_IsEndPointUp_IgnoreAndReturn ( pdFALSE );
1273+
1274+ FreeRTOS_ReleaseUDPPayloadBuffer_Ignore ();
1275+
1276+ vDHCPProcess ( pdFALSE , pxEndPoint );
1277+
1278+ TEST_ASSERT_EQUAL ( eInitialWait , pxEndPoint -> xDHCPData .eDHCPState );
1279+ }
1280+
12381281void test_vDHCPProcess_eLeasedAddress_CorrectState_ValidBytesInMessage_TransactionIDMismatch ( void )
12391282{
12401283 struct xSOCKET xTestSocket ;
0 commit comments