mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-10-13 16:27:43 -04:00
Add message buffer space available coherency test (#515)
* Introduce tasks that test the coherency of the reported space available in a message buffer from two separate tasks. Designed to highlight the issue reported in https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/264 Introduce configRUN_ADDITIONAL_TESTS which must be set to 1 to run the new tests. That is because the new tests got added to an existing standard demo file and smaller platforms may not have the resources to run them. Set configRUN_ADDITIONAL_TESTS to 1 in the MSVC and IAR/QEMU project so both project run the new test. Also add missing 'volatile' qualifier in the IAR/QEMU project on some register accesses. * Update xAreMessageBufferTasksStillRunning() to report errors from the new message buffer size coherency tests. Co-authored-by: RichardBarry <ribarry@amazon.com> Co-authored-by: RichardBarry <3073890+RichardBarry@users.noreply.github.com>
This commit is contained in:
parent
f39765be22
commit
26478d721f
5 changed files with 118 additions and 6 deletions
|
@ -98,6 +98,20 @@ static void prvNonBlockingSenderTask( void *pvParameters );
|
|||
static uint32_t ulSenderLoopCounters[ mbNUMBER_OF_SENDER_TASKS ] = { 0 };
|
||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
|
||||
|
||||
#if( configRUN_ADDITIONAL_TESTS == 1 )
|
||||
#define mbCOHERENCE_TEST_BUFFER_SIZE 20
|
||||
#define mbCOHERENCE_TEST_BYTES_WRITTEN 5
|
||||
#define mbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) )
|
||||
#define mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING ( mbCOHERENCE_TEST_BUFFER_SIZE - ( mbCOHERENCE_TEST_BYTES_WRITTEN + mbBYTES_TO_STORE_MESSAGE_LENGTH ) )
|
||||
|
||||
static void prvSpaceAvailableCoherenceActor( void *pvParameters );
|
||||
static void prvSpaceAvailableCoherenceTester( void *pvParameters );
|
||||
static MessageBufferHandle_t xCoherenceTestMessageBuffer = NULL;
|
||||
|
||||
static uint32_t ulSizeCoherencyTestCycles = 0UL;
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* The buffers used by the echo client and server tasks. */
|
||||
|
@ -157,6 +171,16 @@ MessageBufferHandle_t xMessageBuffer;
|
|||
xTaskCreate( prvSenderTask, "2Sender", xBlockingStackSize, NULL, mbLOWER_PRIORITY, NULL );
|
||||
}
|
||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
|
||||
#if( configRUN_ADDITIONAL_TESTS == 1 )
|
||||
{
|
||||
xCoherenceTestMessageBuffer = xMessageBufferCreate( mbCOHERENCE_TEST_BUFFER_SIZE );
|
||||
configASSERT( xCoherenceTestMessageBuffer );
|
||||
|
||||
xTaskCreate( prvSpaceAvailableCoherenceActor, "mbsanity1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||
xTaskCreate( prvSpaceAvailableCoherenceTester, "mbsanity2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
@ -819,6 +843,71 @@ const TickType_t xTicksToBlock = pdMS_TO_TICKS( 250UL );
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Tests within configRUN_ADDITIONAL_TESTS blocks only execute on larger
|
||||
* platforms or have been added to pre-existing files that are already in use
|
||||
* by other test projects without ensuring they don't cause those pre-existing
|
||||
* projects to run out of program or data memory. */
|
||||
#if( configRUN_ADDITIONAL_TESTS == 1 )
|
||||
|
||||
static void prvSpaceAvailableCoherenceActor( void *pvParameters )
|
||||
{
|
||||
static char *cTxString = "12345";
|
||||
char cRxString[ mbCOHERENCE_TEST_BYTES_WRITTEN + 1 ]; /* +1 for NULL terminator. */
|
||||
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* Add bytes to the buffer so the other task should see
|
||||
mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING bytes free. */
|
||||
xMessageBufferSend( xCoherenceTestMessageBuffer, ( void * ) cTxString, strlen( cTxString ), 0 );
|
||||
configASSERT( xMessageBufferSpacesAvailable( xCoherenceTestMessageBuffer ) == mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING );
|
||||
|
||||
/* Read out message again so the other task should read the full
|
||||
mbCOHERENCE_TEST_BUFFER_SIZE bytes free again. */
|
||||
memset( ( void * ) cRxString, 0x00, sizeof( cRxString ) );
|
||||
xMessageBufferReceive( xCoherenceTestMessageBuffer, ( void * ) cRxString, mbCOHERENCE_TEST_BYTES_WRITTEN, 0 );
|
||||
configASSERT( strcmp( cTxString, cRxString ) == 0 );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvSpaceAvailableCoherenceTester( void *pvParameters )
|
||||
{
|
||||
size_t xSpaceAvailable;
|
||||
BaseType_t xErrorFound = pdFALSE;
|
||||
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* This message buffer is only ever empty or contains 5 bytes. So all
|
||||
queries of its free space should result in one of the two values tested
|
||||
below. */
|
||||
xSpaceAvailable = xMessageBufferSpacesAvailable( xCoherenceTestMessageBuffer );
|
||||
|
||||
if( ( xSpaceAvailable == mbCOHERENCE_TEST_BUFFER_SIZE ) ||
|
||||
( xSpaceAvailable == mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING ) )
|
||||
{
|
||||
/* Only continue to increment the variable that shows this task
|
||||
is still executing if no errors have been found. */
|
||||
if( xErrorFound == pdFALSE )
|
||||
{
|
||||
ulSizeCoherencyTestCycles++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xErrorFound = pdTRUE;
|
||||
}
|
||||
|
||||
configASSERT( xErrorFound == pdFALSE );
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* configRUN_ADDITIONAL_TESTS == 1 */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xAreMessageBufferTasksStillRunning( void )
|
||||
{
|
||||
static uint32_t ulLastEchoLoopCounters[ mbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
|
||||
|
@ -864,6 +953,21 @@ BaseType_t xReturn = pdPASS, x;
|
|||
}
|
||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
|
||||
#if( configRUN_ADDITIONAL_TESTS == 1 )
|
||||
{
|
||||
static uint32_t ullastSizeCoherencyTestCycles = 0UL;
|
||||
|
||||
if( ullastSizeCoherencyTestCycles == ulSizeCoherencyTestCycles )
|
||||
{
|
||||
xReturn = pdFAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ullastSizeCoherencyTestCycles = ulSizeCoherencyTestCycles;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue