Skip to content

Commit

Permalink
Fix UTs and CBMC
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-josi-aws committed Jun 7, 2024
1 parent e9c92e3 commit 36bcde0
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

void vDNSInitialise( void );

void vDNSSetCallBack( const char * pcHostName,
BaseType_t xDNSSetCallBack( const char * pcHostName,
void * pvSearchID,
FOnDNSEvent pCallbackFunction,
TickType_t xTimeout,
Expand Down Expand Up @@ -59,6 +59,7 @@ void harness()
TickType_t xIdentifier;
BaseType_t xIsIPv6;
size_t len;
BaseType_t xReturn;

__CPROVER_assume( len >= 0 && len <= MAX_HOSTNAME_LEN );
char * pcHostName = safeMalloc( len );
Expand All @@ -68,6 +69,6 @@ void harness()
pcHostName[ len - 1 ] = NULL;
}

vDNSSetCallBack( pcHostName, &pvSearchID, pCallback, xTimeout, xIdentifier, xIsIPv6 ); /* Add an item to be able to check the cancel function if the list is non-empty. */
xReturn = xDNSSetCallBack( pcHostName, &pvSearchID, pCallback, xTimeout, xIdentifier, xIsIPv6 ); /* Add an item to be able to check the cancel function if the list is non-empty. */
FreeRTOS_gethostbyname_cancel( &pvSearchID );
}
76 changes: 55 additions & 21 deletions test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ void test_FreeRTOS_gethostbyname_a_SetCallback( void )
FreeRTOS_inet_addr_ExpectAndReturn( GOOD_ADDRESS, 0 );
Prepare_CacheLookup_ExpectAnyArgsAndReturn( 0 );
xApplicationGetRandomNumber_IgnoreAndReturn( pdTRUE );
vDNSSetCallBack_ExpectAnyArgs();
xDNSSetCallBack_ExpectAnyArgsAndReturn( pdPASS );
DNS_CreateSocket_ExpectAnyArgsAndReturn( NULL );

ret = FreeRTOS_gethostbyname_a( GOOD_ADDRESS,
Expand Down Expand Up @@ -665,7 +665,7 @@ void test_FreeRTOS_gethostbyname_a_Callback( void )
}

/**
* @brief Ensures that if vDNSSetCallBack is called the client is put in
* @brief Ensures that if xDNSSetCallBack is called the client is put in
* asynchronous mode, and only one retry is performed by calling
* prvGetHostByNameOp instead of prvGetHostByNameOp_WithRetry
*/
Expand Down Expand Up @@ -700,7 +700,7 @@ void test_FreeRTOS_gethostbyname_a_NoCallbackRetryOnce( void )
Prepare_CacheLookup_ExpectAnyArgsAndReturn( 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnThruPtr_pulNumber( &ulNumber );
vDNSSetCallBack_ExpectAnyArgs();
xDNSSetCallBack_ExpectAnyArgsAndReturn( pdPASS );

/* in prvGetHostByName */
DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket );
Expand Down Expand Up @@ -893,7 +893,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4DomainCacheMiss_Random( void )
Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE );
xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS );
DNS_CreateSocket_ExpectAndReturn( 0U, NULL );

xReturn = FreeRTOS_getaddrinfo_a( GOOD_ADDRESS, "Service", NULL, &pxAddress, dns_callback, NULL, 0U );
Expand Down Expand Up @@ -921,7 +921,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6DomainCacheMiss_Random( void )
Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE );
xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS );
DNS_CreateSocket_ExpectAndReturn( 0U, NULL );

xReturn = FreeRTOS_getaddrinfo_a( GOOD_ADDRESS, "Service", pxHint, &pxAddress, dns_callback, NULL, 0U );
Expand Down Expand Up @@ -955,7 +955,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_EndPointNotFound( void )
Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE );
xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket );
Expand All @@ -970,6 +970,40 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_EndPointNotFound( void )
TEST_ASSERT_EQUAL( -pdFREERTOS_ERRNO_ENOENT, xReturn );
}

/**
* @brief Try to get IP address through network but malloc fails while setting
* callback
*/
void test_FreeRTOS_getaddrinfo_a_IPv6Random_SetCallBackFails( void )
{
BaseType_t xReturn;
struct freertos_addrinfo xAddress, * pxAddress = &xAddress;
struct freertos_addrinfo xHint, * pxHint = &xHint;
uint32_t ulRandom = 0x1234U;
struct xSOCKET xDNSSocket;
NetworkEndPoint_t xEndPoint;

memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) );
memset( &xHint, 0, sizeof( struct freertos_addrinfo ) );
memset( &xDNSSocket, 0, sizeof( struct xSOCKET ) );
memset( &xEndPoint, 0, sizeof( xEndPoint ) );

xEndPoint.bits.bIPv6 = pdFALSE;

xHint.ai_family = FREERTOS_AF_INET6;

FreeRTOS_inet_pton6_ExpectAndReturn( GOOD_ADDRESS, NULL, 0 );
FreeRTOS_inet_pton6_IgnoreArg_pvDestination();
Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdFAIL );

xReturn = FreeRTOS_getaddrinfo_a( GOOD_ADDRESS, "Service", pxHint, &pxAddress, dns_callback, NULL, 0U );

TEST_ASSERT_EQUAL( -pdFREERTOS_ERRNO_ENOENT, xReturn );
}

/**
* @brief IPv4 socket bind fail with domain name containing dot
*/
Expand Down Expand Up @@ -1010,7 +1044,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_BindFailWithDot( void )
Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE );
xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket );
Expand Down Expand Up @@ -1079,7 +1113,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_BindFailWithDot( void )
Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE );
xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket );
Expand Down Expand Up @@ -1128,7 +1162,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_BindFailWODot( void )
Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE );
xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket );
Expand Down Expand Up @@ -1176,7 +1210,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_BindFailWODot( void )
Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE );
xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket );
Expand Down Expand Up @@ -1218,7 +1252,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_InvalidDNSServerIndex( void )
Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE );
xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket );
Expand Down Expand Up @@ -1258,7 +1292,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_InvalidDNSServerIndex( void )
Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE );
xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket );
Expand Down Expand Up @@ -1297,7 +1331,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_UnknownPreference( void )
Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE );
xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket );
Expand Down Expand Up @@ -1363,7 +1397,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_DNSReplySuccess( void )
Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE );
xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket );
Expand Down Expand Up @@ -1532,7 +1566,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_LocalDNSSuccess( void )
Prepare_CacheLookup_ExpectAndReturn( LOCAL_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE );
xDNSSetCallBack_ExpectAndReturn( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket );
Expand Down Expand Up @@ -1620,7 +1654,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_LocalDNSSuccess( void )
Prepare_CacheLookup_ExpectAndReturn( LOCAL_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE );
xDNSSetCallBack_ExpectAndReturn( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket );
Expand Down Expand Up @@ -1708,7 +1742,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_LocalDNSUnknownPreference( void )
Prepare_CacheLookup_ExpectAndReturn( LOCAL_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE );
xDNSSetCallBack_ExpectAndReturn( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket );
Expand Down Expand Up @@ -1780,7 +1814,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_LLMNRDNSSuccess( void )
Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE );
xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket );
Expand Down Expand Up @@ -1859,7 +1893,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_LLMNRDNSNoEndPoint( void )
Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE );
xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket );
Expand Down Expand Up @@ -1926,7 +1960,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_LLMNRDNSUnknownPreference( void )
Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE );
xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket );
Expand Down Expand Up @@ -2179,7 +2213,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_PortSpecified( void )
Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) );
vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE );
xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS );

/* In prvGetHostByName */
DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket );
Expand Down
19 changes: 13 additions & 6 deletions test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,10 @@ void test_xDNSDoCallback_success_equal_identifier_set_timer( void )
/**
* @brief Happy Path!
*/
void test_vDNSSetCallback_success( void )
void test_xDNSSetCallBack_success( void )
{
void * pvSearchID = NULL;
BaseType_t xReturn;

/* Expectations */
pvPortMalloc_ExpectAnyArgsAndReturn( &dnsCallback );
Expand All @@ -218,21 +219,23 @@ void test_vDNSSetCallback_success( void )
xTaskResumeAll_ExpectAndReturn( pdFALSE );

/* API Call */
vDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE );
xReturn = xDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE );

/* Validations */
TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback.pcName, "hostname" ) );
TEST_ASSERT_EQUAL( dns_callback, dnsCallback.pCallbackFunction );
TEST_ASSERT_EQUAL( pvSearchID, dnsCallback.pvSearchID );
TEST_ASSERT_EQUAL( 56, dnsCallback.uxRemainingTime );
TEST_ASSERT_EQUAL( pdPASS, xReturn );
}

/**
* @brief Happy Path!
*/
void test_vDNSSetCallback_success_empty_list( void )
void test_xDNSSetCallBack_success_empty_list( void )
{
void * pvSearchID = NULL;
BaseType_t xReturn;

/* Expectations */
pvPortMalloc_ExpectAnyArgsAndReturn( &dnsCallback );
Expand All @@ -247,27 +250,31 @@ void test_vDNSSetCallback_success_empty_list( void )
xTaskResumeAll_ExpectAndReturn( pdFALSE );

/* API Call */
vDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE );
xReturn = xDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE );

/* Validations */
TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback.pcName, "hostname" ) );
TEST_ASSERT_EQUAL( dns_callback, dnsCallback.pCallbackFunction );
TEST_ASSERT_EQUAL( pvSearchID, dnsCallback.pvSearchID );
TEST_ASSERT_EQUAL( 56, dnsCallback.uxRemainingTime );
TEST_ASSERT_EQUAL( pdPASS, xReturn );
}

/**
* @brief Memory Allocation failed
*/
void test_vDNSSetCallback_malloc_failed( void )
void test_xDNSSetCallBack_malloc_failed( void )
{
void * pvSearchID = NULL;
BaseType_t xReturn;

/* Expectations */
pvPortMalloc_ExpectAnyArgsAndReturn( NULL );

/* API Call */
vDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE );
xReturn = xDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE );
TEST_ASSERT_EQUAL( pdFAIL, xReturn );

}


Expand Down

0 comments on commit 36bcde0

Please sign in to comment.