mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-10-17 18:27:47 -04:00
Update unit tests to match changes in queue.c (#614)
This commit is contained in:
parent
ea798d0612
commit
f37753da06
10 changed files with 57 additions and 535 deletions
|
@ -69,145 +69,6 @@ int suiteTearDown( int numFailures )
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Test xSemaphoreTake with an invalid counting semaphore
|
||||
* @details Verify that a call to xSemaphoreTake fails on a counting
|
||||
* semaphore created with uxMaxCount=0 and uxInitialCount=0
|
||||
* @coverage xQueueSemaphoreTake
|
||||
*/
|
||||
void test_macro_xSemaphoreTake_CountingSemaphore_zero_zero_fail( void )
|
||||
{
|
||||
/* Expect that xSemaphoreCreateCounting will assert because uxMaxCount=0 is invalid */
|
||||
fakeAssertExpectFail();
|
||||
|
||||
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 0, 0 );
|
||||
|
||||
fakeAssertGetNumAssertsAndClear();
|
||||
|
||||
/* validate returned semaphore handle */
|
||||
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
|
||||
|
||||
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
|
||||
|
||||
/* Verify that an xSemaphoreTake fails */
|
||||
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, 0 ) );
|
||||
|
||||
vSemaphoreDelete( xSemaphore );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test xSemaphoreGive with an invalid counting semaphore
|
||||
* @details Verify that a call to xSemaphoreGive fails on a counting
|
||||
* semaphore created with uxMaxCount=0 and uxInitialCount=0
|
||||
* @coverage xQueueGenericSend
|
||||
*/
|
||||
void test_macro_xSemaphoreGive_CountingSemaphore_zero_zero_fail( void )
|
||||
{
|
||||
/* Expect that xSemaphoreCreateCounting will assert because uxMaxCount=0 is invalid */
|
||||
fakeAssertExpectFail();
|
||||
|
||||
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 0, 0 );
|
||||
|
||||
fakeAssertGetNumAssertsAndClear();
|
||||
|
||||
/* validate returned semaphore handle */
|
||||
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
|
||||
|
||||
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
|
||||
|
||||
/* Verify that an xSemaphoreGive fails */
|
||||
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
|
||||
|
||||
vSemaphoreDelete( xSemaphore );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test xSemaphoreGive with xSemaphoreCreateCounting( 1, 2 )
|
||||
* @details Test xSemaphoreGive with an invalid counting semaphore where
|
||||
* uxInitialCount > xMaxCount
|
||||
* @coverage xQueueGenericSend
|
||||
*/
|
||||
void test_macro_xSemaphoreGive_with_CountingSemaphore_one_two_fail( void )
|
||||
{
|
||||
/* Expect that xSemaphoreCreateCounting will assert because
|
||||
* uxInitialCount > xMaxCount is invalid */
|
||||
fakeAssertExpectFail();
|
||||
|
||||
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 2 );
|
||||
|
||||
fakeAssertGetFlagAndClear();
|
||||
|
||||
/* validate returned semaphore handle */
|
||||
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
|
||||
|
||||
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
|
||||
|
||||
/* Verify that an xSemaphoreGive fails */
|
||||
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
|
||||
|
||||
vSemaphoreDelete( xSemaphore );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test xSemaphoreTake with xSemaphoreCreateCounting( 1, 2 )
|
||||
* @details Test xSemaphoreTake with an invalid counting semaphore where
|
||||
* uxInitialCount > xMaxCount
|
||||
* @coverage xQueueSemaphoreTake
|
||||
*/
|
||||
void test_macro_xSemaphoreTake_with_CountingSemaphore_one_two_success( void )
|
||||
{
|
||||
/* Expect that xSemaphoreCreateCounting will assert because
|
||||
* uxInitialCount > xMaxCount is invalid */
|
||||
fakeAssertExpectFail();
|
||||
|
||||
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 2 );
|
||||
|
||||
fakeAssertGetFlagAndClear();
|
||||
|
||||
/* validate returned semaphore handle */
|
||||
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
|
||||
|
||||
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
|
||||
|
||||
/* Verify that an xSemaphoreTake succeeds */
|
||||
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
|
||||
|
||||
vSemaphoreDelete( xSemaphore );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test xSemaphoreTake and xSemaphoreGive with xSemaphoreCreateCounting( 1, 2 )
|
||||
* @details Test xSemaphoreTake and xSemaphoreGive with an invalid counting
|
||||
* semaphore where uxInitialCount > xMaxCount.
|
||||
* @coverage xQueueSemaphoreTake xQueueGenericSend
|
||||
*/
|
||||
void test_macro_xSemaphoreTake_xSemaphoreGive_with_CountingSemaphore_one_two_success( void )
|
||||
{
|
||||
/* Expect that xSemaphoreCreateCounting will assert because
|
||||
* uxInitialCount > xMaxCount is invalid */
|
||||
fakeAssertExpectFail();
|
||||
|
||||
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 2 );
|
||||
|
||||
fakeAssertGetFlagAndClear();
|
||||
|
||||
/* validate returned semaphore handle */
|
||||
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
|
||||
|
||||
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
|
||||
|
||||
/* Verify that an xSemaphoreTake succeeds */
|
||||
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
|
||||
|
||||
/* Verify that a second xSemaphoreTake succeeds */
|
||||
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
|
||||
|
||||
/* Verify that an xSemaphoreGive succeeds */
|
||||
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
|
||||
|
||||
vSemaphoreDelete( xSemaphore );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test xSemaphoreTake with xSemaphoreCreateCounting( 1, 0 )
|
||||
* @details Test xSemaphoreTake with a binary semaphore constructed with
|
||||
|
@ -475,91 +336,6 @@ void test_macro_xSemaphoreGive_CountingSemaphore_lower_bound( void )
|
|||
vSemaphoreDelete( xSemaphore );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test xSemaphoreGive with xSemaphoreCreateCounting( UINT64_MAX - 1, UINT64_MAX )
|
||||
* @details Test xSemaphoreGive with a counting semaphore with uxMaxCount=UINT64_MAX-1 and
|
||||
* uxInitialCount=UINT64_MAX
|
||||
* @coverage xQueueGenericSend
|
||||
*/
|
||||
void test_macro_xSemaphoreGive_CountingSemaphore_over_upper_bound( void )
|
||||
{
|
||||
/* Expect that xSemaphoreCreateCounting will configASSERT because
|
||||
* uxInitialCount > xMaxCount is invalid */
|
||||
fakeAssertExpectFail();
|
||||
|
||||
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( UINT64_MAX - 1, UINT64_MAX );
|
||||
|
||||
/* verify that configASSERT was called */
|
||||
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
|
||||
|
||||
/* validate returned semaphore handle */
|
||||
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
|
||||
|
||||
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
|
||||
|
||||
/* Check the count */
|
||||
TEST_ASSERT_EQUAL( UINT64_MAX, uxSemaphoreGetCount( xSemaphore ) );
|
||||
|
||||
/* Verify that an xSemaphoreGive operation fails */
|
||||
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
|
||||
|
||||
/* Check that the count has not changed */
|
||||
TEST_ASSERT_EQUAL( UINT64_MAX, uxSemaphoreGetCount( xSemaphore ) );
|
||||
|
||||
vSemaphoreDelete( xSemaphore );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test xSemaphoreGive with a counting semaphore where uxInitialCount > uxMaxCount
|
||||
* @details Test xSemaphoreGive with a counting semaphore with uxMaxCount=1 and
|
||||
* uxInitialCount=2
|
||||
* @coverage xQueueGenericSend
|
||||
*/
|
||||
void test_macro_xSemaphoreGive_count_higher_than_max( void )
|
||||
{
|
||||
/* Expect that xSemaphoreCreateCounting will assert because
|
||||
* uxInitialCount > xMaxCount is invalid */
|
||||
fakeAssertExpectFail();
|
||||
|
||||
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 2 );
|
||||
|
||||
fakeAssertGetFlagAndClear();
|
||||
|
||||
/* validate returned semaphore handle */
|
||||
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
|
||||
|
||||
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
|
||||
|
||||
/* Check that the count was initialized correctly */
|
||||
TEST_ASSERT_EQUAL( 2, uxSemaphoreGetCount( xSemaphore ) );
|
||||
|
||||
/* Verify that an xSemaphoreGive fails (would cause the count to increase) */
|
||||
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
|
||||
|
||||
/* Verify that an xSemaphoreTake succeeds */
|
||||
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
|
||||
|
||||
/* Check that the count has decreased */
|
||||
TEST_ASSERT_EQUAL( 1, uxSemaphoreGetCount( xSemaphore ) );
|
||||
|
||||
/* Verify that an xSemaphoreGive fails (would cause the count to increase beyond 2) */
|
||||
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
|
||||
|
||||
/* Verify that an xSemaphoreTake succeds */
|
||||
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
|
||||
|
||||
/* Check that the count has decreased */
|
||||
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
|
||||
|
||||
/* Verify that an xSemaphoreGive succeeds */
|
||||
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
|
||||
|
||||
/* Check that the count is now 1 */
|
||||
TEST_ASSERT_EQUAL( 1, uxSemaphoreGetCount( xSemaphore ) );
|
||||
|
||||
vSemaphoreDelete( xSemaphore );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test xSemaphoreTake with taskSCHEDULER_SUSPENDED and timeout=10
|
||||
* @details This should cause xSemaphoreTake to configASSERT because it would
|
||||
|
|
|
@ -114,8 +114,8 @@ void test_macro_xSemaphoreCreateMutexStatic_nullptr( void )
|
|||
|
||||
xSemaphore = xSemaphoreCreateMutexStatic( NULL );
|
||||
|
||||
/* verify that configASSERT was called */
|
||||
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
|
||||
/* Check that configASSERT was called twice */
|
||||
fakeAssertVerifyNumAssertsAndClear( 2 );
|
||||
|
||||
TEST_ASSERT_EQUAL( NULL, xSemaphore );
|
||||
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
|
||||
|
|
|
@ -112,8 +112,8 @@ void test_macro_xSemaphoreCreateRecursiveMutexStatic_nullptr( void )
|
|||
|
||||
xSemaphore = xSemaphoreCreateRecursiveMutexStatic( NULL );
|
||||
|
||||
/* verify that configASSERT was called */
|
||||
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
|
||||
/* Check that configASSERT was called twice */
|
||||
fakeAssertVerifyNumAssertsAndClear( 2 );
|
||||
|
||||
TEST_ASSERT_EQUAL( NULL, xSemaphore );
|
||||
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
|
||||
|
|
|
@ -115,8 +115,8 @@ void test_macro_xSemaphoreCreateBinaryStatic_fail( void )
|
|||
|
||||
xSemaphore = xSemaphoreCreateBinaryStatic( NULL );
|
||||
|
||||
/* verify that configASSERT was called */
|
||||
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
|
||||
/* verify that configASSERT was called twice */
|
||||
fakeAssertVerifyNumAssertsAndClear( 2 );
|
||||
|
||||
TEST_ASSERT_EQUAL( NULL, xSemaphore );
|
||||
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
|
||||
|
@ -216,14 +216,34 @@ void test_macro_xSemaphoreCreateCounting_one_two( void )
|
|||
fakeAssertGetFlagAndClear();
|
||||
|
||||
/* validate returned semaphore handle */
|
||||
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
|
||||
TEST_ASSERT_EQUAL( NULL, xSemaphore );
|
||||
|
||||
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
|
||||
/* Check that no call to malloc occurred */
|
||||
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
|
||||
}
|
||||
|
||||
/* Check that the count was initialized correctly */
|
||||
TEST_ASSERT_EQUAL( 2, uxSemaphoreGetCount( xSemaphore ) );
|
||||
/**
|
||||
* @brief Test xSemaphoreCreateCounting with uxMaxCount=UINT64_MAX - 1 and uxInitialCount=UINT64_MAX
|
||||
* @details This is an invalid initial condition for a counting semaphore since
|
||||
* uxMaxCount >= uxInitialCount.
|
||||
* @coverage xQueueCreateCountingSemaphore
|
||||
*/
|
||||
void test_macro_xSemaphoreCreateCounting_over_upper_bound( void )
|
||||
{
|
||||
/* Expect that xSemaphoreCreateCounting will configASSERT because
|
||||
* uxInitialCount > xMaxCount is invalid */
|
||||
fakeAssertExpectFail();
|
||||
|
||||
vSemaphoreDelete( xSemaphore );
|
||||
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( UINT64_MAX - 1, UINT64_MAX );
|
||||
|
||||
/* verify that configASSERT was called */
|
||||
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
|
||||
|
||||
/* validate returned semaphore handle */
|
||||
TEST_ASSERT_EQUAL( NULL, xSemaphore );
|
||||
|
||||
/* Check that no call to malloc occurred */
|
||||
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -259,16 +279,14 @@ void test_macro_xSemaphoreCreateCounting_zero_zero( void )
|
|||
|
||||
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 0, 0 );
|
||||
|
||||
fakeAssertVerifyNumAssertsAndClear( 2 );
|
||||
/* verify that configASSERT was called */
|
||||
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
|
||||
|
||||
/* validate returned semaphore handle */
|
||||
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
|
||||
TEST_ASSERT_EQUAL( NULL, xSemaphore );
|
||||
|
||||
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
|
||||
|
||||
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
|
||||
|
||||
vSemaphoreDelete( xSemaphore );
|
||||
/* Check that no call to malloc occurred */
|
||||
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -342,8 +360,8 @@ void test_macro_xSemaphoreCreateCountingStatic_null_fail( void )
|
|||
|
||||
xSemaphore = xSemaphoreCreateCountingStatic( 2, 1, NULL );
|
||||
|
||||
/* Verify that configASSERT was called due to the null buffer */
|
||||
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
|
||||
/* verify that configASSERT was called twice */
|
||||
fakeAssertVerifyNumAssertsAndClear( 2 );
|
||||
|
||||
/* Verify that the returned handle is NULL */
|
||||
TEST_ASSERT_EQUAL( NULL, xSemaphore );
|
||||
|
@ -367,18 +385,14 @@ void test_macro_xSemaphoreCreateCountingStatic_zero_zero_fail( void )
|
|||
|
||||
xSemaphore = xSemaphoreCreateCountingStatic( 0, 0, &xSemaphoreBuffer );
|
||||
|
||||
fakeAssertVerifyNumAssertsAndClear( 2 );
|
||||
/* verify that configASSERT was called */
|
||||
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
|
||||
|
||||
/* validate returned semaphore handle */
|
||||
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
|
||||
TEST_ASSERT_EQUAL( NULL, xSemaphore );
|
||||
|
||||
/* Check that no malloc occurred */
|
||||
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
|
||||
|
||||
/* Check that the returned count is zero */
|
||||
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
|
||||
|
||||
vSemaphoreDelete( xSemaphore );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -401,15 +415,10 @@ void test_macro_xSemaphoreCreateCountingStatic_one_two( void )
|
|||
fakeAssertGetFlagAndClear();
|
||||
|
||||
/* validate returned semaphore handle */
|
||||
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
|
||||
TEST_ASSERT_EQUAL( NULL, xSemaphore );
|
||||
|
||||
/* verify that no heap memory allocation occurred */
|
||||
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
|
||||
|
||||
/* Check that the count was initialized correctly */
|
||||
TEST_ASSERT_EQUAL( 2, uxSemaphoreGetCount( xSemaphore ) );
|
||||
|
||||
vSemaphoreDelete( xSemaphore );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue