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:
Cobus van Eeden
2021-03-20 11:50:16 -07:00
committed by GitHub
parent f39765be22
commit 26478d721f
5 changed files with 118 additions and 6 deletions

View File

@ -107,6 +107,10 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
version. */
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
/* The Win32 target is capable of running all the tests tasks at the same
* time. */
#define configRUN_ADDITIONAL_TESTS 1
/* The test that checks the trigger level on stream buffers requires an
allowable margin of error on slower processors (slower than the Win32
machine on which the test is developed). */

View File

@ -65,9 +65,9 @@ implemented and described in main_full.c. */
/* printf() output uses the UART. These constants define the addresses of the
required UART registers. */
#define UART0_ADDRESS ( 0x40004000UL )
#define UART0_DATA ( * ( ( ( uint32_t * )( UART0_ADDRESS + 0UL ) ) ) )
#define UART0_CTRL ( * ( ( ( uint32_t * )( UART0_ADDRESS + 8UL ) ) ) )
#define UART0_BAUDDIV ( * ( ( ( uint32_t * )( UART0_ADDRESS + 16UL ) ) ) )
#define UART0_DATA ( * ( ( ( volatile uint32_t * )( UART0_ADDRESS + 0UL ) ) ) )
#define UART0_CTRL ( * ( ( ( volatile uint32_t * )( UART0_ADDRESS + 8UL ) ) ) )
#define UART0_BAUDDIV ( * ( ( ( volatile uint32_t * )( UART0_ADDRESS + 16UL ) ) ) )
/*
* main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
@ -188,7 +188,7 @@ volatile uint32_t ulSetToNonZeroInDebuggerToContinue = 0;
/* Called if an assertion passed to configASSERT() fails. See
http://www.freertos.org/a00110.html#configASSERT for more information. */
printf( "ASSERT! Line %ld, file %s\r\n", ulLine, pcFileName );
printf( "ASSERT! Line %d, file %s\r\n", ( int ) ulLine, pcFileName );
taskENTER_CRITICAL();
{

View File

@ -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;
}
/*-----------------------------------------------------------*/

View File

@ -112,6 +112,10 @@ functions anyway. */
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
/* The Win32 target is capable of running all the tests tasks at the same
* time. */
#define configRUN_ADDITIONAL_TESTS 1
/* It is a good idea to define configASSERT() while developing. configASSERT()
uses the same semantics as the standard C assert() macro. */
extern void vAssertCalled( unsigned long ulLine, const char * const pcFileName );

View File

@ -71,7 +71,7 @@ The blinky demo is implemented and described in main_blinky.c.
If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is not 1 then the comprehensive test and
demo application will be built. The comprehensive test and demo application is
implemented and described in main_full.c. */
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
/* This demo uses heap_5.c, and these constants define the sizes of the regions
that make up the total heap. heap_5 is only used for test and example purposes
@ -80,7 +80,7 @@ smaller heap regions - in which case heap_4.c would be the more appropriate
choice. See http://www.freertos.org/a00111.html for an explanation. */
#define mainREGION_1_SIZE 8201
#define mainREGION_2_SIZE 29905
#define mainREGION_3_SIZE 7607
#define mainREGION_3_SIZE 7807
/*-----------------------------------------------------------*/