Skip to content

Commit

Permalink
Introduce tasks that test the coherency of the reported space availab…
Browse files Browse the repository at this point in the history
…le in a message buffer from two separate tasks. Designed to highlight the issue reported in FreeRTOS/FreeRTOS-Kernel#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 on some register accesses in the same file.
  • Loading branch information
RichardBarry committed Feb 20, 2021
1 parent d4fc257 commit ea51a3b
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 5 deletions.
4 changes: 4 additions & 0 deletions FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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). */
Expand Down
8 changes: 4 additions & 4 deletions FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
{
Expand Down
104 changes: 104 additions & 0 deletions FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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
}
/*-----------------------------------------------------------*/

Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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;
}
/*-----------------------------------------------------------*/
Expand Down
4 changes: 4 additions & 0 deletions FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion FreeRTOS/Demo/WIN32-MSVC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*-----------------------------------------------------------*/

Expand Down

0 comments on commit ea51a3b

Please sign in to comment.