diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index b29eb0cfe..7ebda549a 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -608,6 +608,10 @@ BaseType_t xHasRandom = pdFALSE; TickType_t uxIdentifier = 0U; + #if ( ipconfigDNS_USE_CALLBACKS == 1 ) + BaseType_t xReturnSetCallback = pdPASS; + #endif + #if ( ipconfigUSE_DNS_CACHE != 0 ) BaseType_t xLengthOk = pdFALSE; #endif @@ -690,12 +694,12 @@ if( xHasRandom != pdFALSE ) { uxReadTimeOut_ticks = 0U; - vDNSSetCallBack( pcHostName, - pvSearchID, - pCallbackFunction, - uxTimeout, - ( TickType_t ) uxIdentifier, - ( xFamily == FREERTOS_AF_INET6 ) ? pdTRUE : pdFALSE ); + xReturnSetCallback = xDNSSetCallBack( pcHostName, + pvSearchID, + pCallbackFunction, + uxTimeout, + ( TickType_t ) uxIdentifier, + ( xFamily == FREERTOS_AF_INET6 ) ? pdTRUE : pdFALSE ); } } else /* When ipconfigDNS_USE_CALLBACKS enabled, ppxAddressInfo is always non null. */ @@ -707,7 +711,13 @@ } #endif /* if ( ipconfigDNS_USE_CALLBACKS == 1 ) */ - if( ( ulIPAddress == 0U ) && ( xHasRandom != pdFALSE ) ) + if( ( ulIPAddress == 0U ) && + + #if ( ipconfigDNS_USE_CALLBACKS == 1 ) + ( xReturnSetCallback == pdPASS ) && + #endif + + ( xHasRandom != pdFALSE ) ) { ulIPAddress = prvGetHostByName( pcHostName, uxIdentifier, diff --git a/source/FreeRTOS_DNS_Callback.c b/source/FreeRTOS_DNS_Callback.c index 6aaf7172d..5a040c90b 100644 --- a/source/FreeRTOS_DNS_Callback.c +++ b/source/FreeRTOS_DNS_Callback.c @@ -129,13 +129,14 @@ * @param[in] uxIdentifier Random number used as ID in the DNS message. * @param[in] xIsIPv6 pdTRUE if the address type should be IPv6. */ - void vDNSSetCallBack( const char * pcHostName, - void * pvSearchID, - FOnDNSEvent pCallbackFunction, - TickType_t uxTimeout, - TickType_t uxIdentifier, - BaseType_t xIsIPv6 ) + BaseType_t xDNSSetCallBack( const char * pcHostName, + void * pvSearchID, + FOnDNSEvent pCallbackFunction, + TickType_t uxTimeout, + TickType_t uxIdentifier, + BaseType_t xIsIPv6 ) { + BaseType_t xReturn = pdPASS; size_t lLength = strlen( pcHostName ); /* MISRA Ref 4.12.1 [Use of dynamic memory]. */ @@ -171,9 +172,12 @@ } else { - FreeRTOS_debug_printf( ( " vDNSSetCallBack : Could not allocate memory: %u bytes", + xReturn = pdFAIL; + FreeRTOS_debug_printf( ( " xDNSSetCallBack : Could not allocate memory: %u bytes", ( unsigned ) ( sizeof( *pxCallback ) + lLength ) ) ); } + + return xReturn; } /*-----------------------------------------------------------*/ diff --git a/source/include/FreeRTOS_DNS_Callback.h b/source/include/FreeRTOS_DNS_Callback.h index 81b40960c..94955c925 100644 --- a/source/include/FreeRTOS_DNS_Callback.h +++ b/source/include/FreeRTOS_DNS_Callback.h @@ -53,12 +53,12 @@ BaseType_t xDNSDoCallback( ParseSet_t * pxSet, struct freertos_addrinfo * pxAddress ); - void vDNSSetCallBack( const char * pcHostName, - void * pvSearchID, - FOnDNSEvent pCallbackFunction, - TickType_t uxTimeout, - TickType_t uxIdentifier, - BaseType_t xIsIPv6 ); + BaseType_t xDNSSetCallBack( const char * pcHostName, + void * pvSearchID, + FOnDNSEvent pCallbackFunction, + TickType_t uxTimeout, + TickType_t uxIdentifier, + BaseType_t xIsIPv6 ); void vDNSCheckCallBack( void * pvSearchID ); diff --git a/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/DNSgetHostByName_cancel_harness.c b/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/DNSgetHostByName_cancel_harness.c index 8536a2612..4ece6565b 100644 --- a/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/DNSgetHostByName_cancel_harness.c +++ b/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/DNSgetHostByName_cancel_harness.c @@ -13,12 +13,12 @@ void vDNSInitialise( void ); -void vDNSSetCallBack( const char * pcHostName, - void * pvSearchID, - FOnDNSEvent pCallbackFunction, - TickType_t xTimeout, - TickType_t xIdentifier, - BaseType_t xIsIPv6 ); +BaseType_t xDNSSetCallBack( const char * pcHostName, + void * pvSearchID, + FOnDNSEvent pCallbackFunction, + TickType_t xTimeout, + TickType_t xIdentifier, + BaseType_t xIsIPv6 ); void * safeMalloc( size_t xWantedSize ) /* Returns a NULL pointer if the wanted size is 0. */ { @@ -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 ); @@ -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 ); } diff --git a/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c b/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c index 6daae41e4..69ef050df 100644 --- a/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c +++ b/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c @@ -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, @@ -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 */ @@ -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 ); @@ -894,7 +894,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 ); @@ -922,7 +922,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 ); @@ -956,7 +956,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 ); @@ -971,6 +971,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 */ @@ -1011,7 +1045,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 ); @@ -1080,7 +1114,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 ); @@ -1129,7 +1163,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 ); @@ -1177,7 +1211,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 ); @@ -1219,7 +1253,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 ); @@ -1259,7 +1293,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 ); @@ -1298,7 +1332,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 ); @@ -1364,7 +1398,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 ); @@ -1533,7 +1567,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 ); @@ -1621,7 +1655,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 ); @@ -1709,7 +1743,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 ); @@ -1781,7 +1815,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 ); @@ -1860,7 +1894,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 ); @@ -1927,7 +1961,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 ); @@ -2180,7 +2214,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 ); diff --git a/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c b/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c index 3a0380784..a23ee1ba6 100644 --- a/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c @@ -205,9 +205,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 ); @@ -220,21 +221,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 ); @@ -249,27 +252,30 @@ 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 ); }