Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/doxygen/code_examples/backoff_algorithm_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int main()
BackoffAlgorithmStatus_t retryStatus = BackoffAlgorithmSuccess;
BackoffAlgorithmContext_t retryParams;
char serverAddress[] = "amazon.com";
uint16_t nextRetryBackoff = 0;
uint32_t nextRetryBackoff = 0;

/* Initialize reconnect attempts and interval. */
BackoffAlgorithm_InitializeParams( &retryParams,
Expand Down
12 changes: 6 additions & 6 deletions source/backoff_algorithm.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

BackoffAlgorithmStatus_t BackoffAlgorithm_GetNextBackoff( BackoffAlgorithmContext_t * pRetryContext,
uint32_t randomValue,
uint16_t * pNextBackOff )
uint32_t * pNextBackOff )
{
BackoffAlgorithmStatus_t status = BackoffAlgorithmSuccess;

Expand All @@ -50,11 +50,11 @@ BackoffAlgorithmStatus_t BackoffAlgorithm_GetNextBackoff( BackoffAlgorithmContex
if( ( pRetryContext->maxRetryAttempts == BACKOFF_ALGORITHM_RETRY_FOREVER ) ||
( pRetryContext->attemptsDone < pRetryContext->maxRetryAttempts ) )
{
/* The next backoff value is a random value between 0 and the maximum jitter value
/* The next backoff value is a random value between 1 and the maximum jitter value
* for the retry attempt. */

/* Choose a random value for back-off time between 0 and the max jitter value. */
*pNextBackOff = ( uint16_t ) ( randomValue % ( pRetryContext->nextJitterMax + ( uint32_t ) 1U ) );
/* Choose a random value for back-off time between 1 and the max jitter value. */
*pNextBackOff = ( randomValue % pRetryContext->nextJitterMax ) + 1U;

/* Increment the retry attempt. */
pRetryContext->attemptsDone++;
Expand Down Expand Up @@ -84,8 +84,8 @@ BackoffAlgorithmStatus_t BackoffAlgorithm_GetNextBackoff( BackoffAlgorithmContex
/*-----------------------------------------------------------*/

void BackoffAlgorithm_InitializeParams( BackoffAlgorithmContext_t * pContext,
uint16_t backOffBase,
uint16_t maxBackOff,
uint32_t backOffBase,
uint32_t maxBackOff,
uint32_t maxAttempts )
{
assert( pContext != NULL );
Expand Down
14 changes: 7 additions & 7 deletions source/include/backoff_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ typedef struct BackoffAlgorithmContext
/**
* @brief The maximum backoff delay (in milliseconds) between consecutive retry attempts.
*/
uint16_t maxBackoffDelay;
uint32_t maxBackoffDelay;

/**
* @brief The total number of retry attempts completed.
Expand All @@ -81,7 +81,7 @@ typedef struct BackoffAlgorithmContext
/**
* @brief The maximum backoff value (in milliseconds) for the next retry attempt.
*/
uint16_t nextJitterMax;
uint32_t nextJitterMax;

/**
* @brief The maximum number of retry attempts.
Expand All @@ -99,14 +99,14 @@ typedef struct BackoffAlgorithmContext
* @param[in] maxBackOff The maximum backoff delay (in milliseconds) between
* consecutive retry attempts.
* @param[in] backOffBase The base value (in milliseconds) of backoff delay to
* use in the exponential backoff and jitter model.
* use in the exponential backoff and jitter model. Must be non-zero.
* @param[in] maxAttempts The maximum number of retry attempts. Set the value to
* #BACKOFF_ALGORITHM_RETRY_FOREVER to retry for ever.
*/
/* @[define_backoffalgorithm_initializeparams] */
void BackoffAlgorithm_InitializeParams( BackoffAlgorithmContext_t * pContext,
uint16_t backOffBase,
uint16_t maxBackOff,
uint32_t backOffBase,
uint32_t maxBackOff,
uint32_t maxAttempts );
/* @[define_backoffalgorithm_initializeparams] */

Expand All @@ -125,7 +125,7 @@ void BackoffAlgorithm_InitializeParams( BackoffAlgorithmContext_t * pContext,
* for the next retry attempt. The value does not exceed the maximum backoff delay
* configured in the context.
*
* @note For generating a random number, it is recommended to use a Random Number Generator
* @note For generating a random number, it is recommended to use a random number generator
* that is seeded with a device-specific entropy source so that possibility of collisions
* between multiple devices retrying the network operations can be mitigated.
*
Expand All @@ -135,7 +135,7 @@ void BackoffAlgorithm_InitializeParams( BackoffAlgorithmContext_t * pContext,
/* @[define_backoffalgorithm_getnextbackoff] */
BackoffAlgorithmStatus_t BackoffAlgorithm_GetNextBackoff( BackoffAlgorithmContext_t * pRetryContext,
uint32_t randomValue,
uint16_t * pNextBackOff );
uint32_t * pNextBackOff );
/* @[define_backoffalgorithm_getnextbackoff] */

/* *INDENT-OFF* */
Expand Down
26 changes: 13 additions & 13 deletions test/unit-test/backoff_algorithm_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
static BackoffAlgorithmContext_t retryParams;
/* Return value of #BackoffAlgorithm_GetNextBackoff. */
static BackoffAlgorithmStatus_t BackoffAlgorithmStatus;
static uint16_t nextBackoff;
static uint32_t nextBackoff;
static uint32_t testRandomVal;

/* ============================ UNITY FIXTURES ============================ */
Expand Down Expand Up @@ -83,8 +83,8 @@ int suiteTearDown( int numFailures )
*/
static void verifyContextData( BackoffAlgorithmContext_t * pContext,
uint32_t expectedAttemptsDone,
uint16_t expectedNextJitterMax,
uint16_t expectedMaxBackoff,
uint32_t expectedNextJitterMax,
uint32_t expectedMaxBackoff,
uint32_t expectedMaxAttempts )
{
TEST_ASSERT_EQUAL( expectedNextJitterMax, pContext->nextJitterMax );
Expand Down Expand Up @@ -133,9 +133,9 @@ void test_BackoffAlgorithm_InitializeParams_Sets_Jitter_Correctly( void )
void test_BackoffAlgorithm_GetNextBackoff_Success_RandVal_Less_Than_Jitter_Max( void )
{
int iter = 1;
uint16_t expectedAttemptsDone = 0;
uint16_t expectedNextJitterMax = TEST_BACKOFF_BASE_VALUE;
uint16_t expectedNextBackoff = 0;
uint32_t expectedAttemptsDone = 0;
uint32_t expectedNextJitterMax = TEST_BACKOFF_BASE_VALUE;
uint32_t expectedNextBackoff = 0;

for( ; iter < 2; iter++ )
{
Expand All @@ -145,7 +145,7 @@ void test_BackoffAlgorithm_GetNextBackoff_Success_RandVal_Less_Than_Jitter_Max(

/* As the random value is less than the max jitter value, the expected
* next backoff value should remain the same as the random value. */
expectedNextBackoff = testRandomVal;
expectedNextBackoff = ( testRandomVal % retryParams.nextJitterMax ) + 1U;

/* The jitter max value should double with the above call for use in next call. */
expectedNextJitterMax *= 2;
Expand Down Expand Up @@ -180,8 +180,8 @@ void test_BackoffAlgorithm_GetNextBackoff_Success_RandVal_Less_Than_Jitter_Max(
void test_BackoffAlgorithm_GetNextBackoff_Success_RandVal_More_Than_Jitter_Max( void )
{
int iter = 1;
uint16_t expectedAttemptsDone = 0;
uint16_t expectedNextJitterMax = TEST_BACKOFF_BASE_VALUE;
uint32_t expectedAttemptsDone = 0;
uint32_t expectedNextJitterMax = TEST_BACKOFF_BASE_VALUE;

for( ; iter < 2; iter++ )
{
Expand All @@ -199,7 +199,7 @@ void test_BackoffAlgorithm_GetNextBackoff_Success_RandVal_More_Than_Jitter_Max(
/* As the random value is greater than the jitter max value, the expected
* next backoff value should be truncated to a value within the jitter window
* for the retry attempt. */
uint16_t expectedNextBackoff = ( testRandomVal % ( retryParams.nextJitterMax + 1U ) );
uint32_t expectedNextBackoff = ( testRandomVal % retryParams.nextJitterMax ) + 1U;

/* Call the BackoffAlgorithm_GetNextBackoff API a couple times. */
TEST_ASSERT_EQUAL( BackoffAlgorithmSuccess,
Expand Down Expand Up @@ -258,7 +258,7 @@ void test_BackoffAlgorithm_GetNextBackoff_Returns_Cap_Backoff( void )
* Thus, the BackoffAlgorithm_GetNextBackoff API should return the random value as
* the next back-off value. */
testRandomVal = retryParams.nextJitterMax;
uint16_t expectedBackoffVal = testRandomVal;
uint16_t expectedBackoffVal = ( testRandomVal % retryParams.nextJitterMax ) + 1U;

/* Call the BackoffAlgorithm_GetNextBackoff API. */
TEST_ASSERT_EQUAL( BackoffAlgorithmSuccess,
Expand All @@ -278,7 +278,7 @@ void test_BackoffAlgorithm_GetNextBackoff_Returns_Cap_Backoff( void )
/* Now, set the random value as the maximum back-off value to
* expect that the next back-off value returned by the API is the maximum
* back-off value.*/
testRandomVal = TEST_BACKOFF_MAX_VALUE;
testRandomVal = TEST_BACKOFF_MAX_VALUE - 1;

/* Call BackoffAlgorithm_GetNextBackoff API again to verify that it now returns the
* cap value as the next back-off value. */
Expand Down Expand Up @@ -326,7 +326,7 @@ void test_BackoffAlgorithm_GetNextBackoff_NextJitterMax_Below_Cap_Backoff( void
TEST_ASSERT_EQUAL( BackoffAlgorithmSuccess,
BackoffAlgorithm_GetNextBackoff( &retryParams, testRandomVal, &nextBackoff ) );
/* Make sure that zero is returned as the next backoff value . */
TEST_ASSERT_EQUAL( 0, nextBackoff );
TEST_ASSERT_EQUAL( 1, nextBackoff );

/* Verify that the context data for expected data after the API call. */
verifyContextData( &retryParams,
Expand Down
3 changes: 1 addition & 2 deletions tools/unity/coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ execute_process(
--output-file ${CMAKE_BINARY_DIR}/second_coverage.info
)

# combile baseline results (zeros) with the one after running the tests
# Skip baseline capture and use only test coverage
execute_process(
COMMAND lcov --base-directory ${CMAKE_BINARY_DIR}
--directory ${CMAKE_BINARY_DIR}
--add-tracefile ${CMAKE_BINARY_DIR}/base_coverage.info
--add-tracefile ${CMAKE_BINARY_DIR}/second_coverage.info
--output-file ${CMAKE_BINARY_DIR}/coverage.info
--no-external
Expand Down
Loading