Skip to content

Commit ea51a3b

Browse files
committed
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 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.
1 parent d4fc257 commit ea51a3b

File tree

5 files changed

+117
-5
lines changed

5 files changed

+117
-5
lines changed

FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/FreeRTOSConfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
107107
version. */
108108
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
109109

110+
/* The Win32 target is capable of running all the tests tasks at the same
111+
* time. */
112+
#define configRUN_ADDITIONAL_TESTS 1
113+
110114
/* The test that checks the trigger level on stream buffers requires an
111115
allowable margin of error on slower processors (slower than the Win32
112116
machine on which the test is developed). */

FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ implemented and described in main_full.c. */
6565
/* printf() output uses the UART. These constants define the addresses of the
6666
required UART registers. */
6767
#define UART0_ADDRESS ( 0x40004000UL )
68-
#define UART0_DATA ( * ( ( ( uint32_t * )( UART0_ADDRESS + 0UL ) ) ) )
69-
#define UART0_CTRL ( * ( ( ( uint32_t * )( UART0_ADDRESS + 8UL ) ) ) )
70-
#define UART0_BAUDDIV ( * ( ( ( uint32_t * )( UART0_ADDRESS + 16UL ) ) ) )
68+
#define UART0_DATA ( * ( ( ( volatile uint32_t * )( UART0_ADDRESS + 0UL ) ) ) )
69+
#define UART0_CTRL ( * ( ( ( volatile uint32_t * )( UART0_ADDRESS + 8UL ) ) ) )
70+
#define UART0_BAUDDIV ( * ( ( ( volatile uint32_t * )( UART0_ADDRESS + 16UL ) ) ) )
7171

7272
/*
7373
* main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
@@ -188,7 +188,7 @@ volatile uint32_t ulSetToNonZeroInDebuggerToContinue = 0;
188188
/* Called if an assertion passed to configASSERT() fails. See
189189
http://www.freertos.org/a00110.html#configASSERT for more information. */
190190

191-
printf( "ASSERT! Line %ld, file %s\r\n", ulLine, pcFileName );
191+
printf( "ASSERT! Line %d, file %s\r\n", ( int ) ulLine, pcFileName );
192192

193193
taskENTER_CRITICAL();
194194
{

FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ static void prvNonBlockingSenderTask( void *pvParameters );
9898
static uint32_t ulSenderLoopCounters[ mbNUMBER_OF_SENDER_TASKS ] = { 0 };
9999
#endif /* configSUPPORT_STATIC_ALLOCATION */
100100

101+
102+
#if( configRUN_ADDITIONAL_TESTS == 1 )
103+
#define mbCOHERENCE_TEST_BUFFER_SIZE 20
104+
#define mbCOHERENCE_TEST_BYTES_WRITTEN 5
105+
#define mbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) )
106+
#define mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING ( mbCOHERENCE_TEST_BUFFER_SIZE - ( mbCOHERENCE_TEST_BYTES_WRITTEN + mbBYTES_TO_STORE_MESSAGE_LENGTH ) )
107+
108+
static void prvSpaceAvailableCoherenceActor( void *pvParameters );
109+
static void prvSpaceAvailableCoherenceTester( void *pvParameters );
110+
static MessageBufferHandle_t xCoherenceTestMessageBuffer = NULL;
111+
112+
static uint32_t ulSizeCoherencyTestCycles = 0UL;
113+
#endif
114+
101115
/*-----------------------------------------------------------*/
102116

103117
/* The buffers used by the echo client and server tasks. */
@@ -157,6 +171,16 @@ MessageBufferHandle_t xMessageBuffer;
157171
xTaskCreate( prvSenderTask, "2Sender", xBlockingStackSize, NULL, mbLOWER_PRIORITY, NULL );
158172
}
159173
#endif /* configSUPPORT_STATIC_ALLOCATION */
174+
175+
#if( configRUN_ADDITIONAL_TESTS == 1 )
176+
{
177+
xCoherenceTestMessageBuffer = xMessageBufferCreate( mbCOHERENCE_TEST_BUFFER_SIZE );
178+
configASSERT( xCoherenceTestMessageBuffer );
179+
180+
xTaskCreate( prvSpaceAvailableCoherenceActor, "mbsanity1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
181+
xTaskCreate( prvSpaceAvailableCoherenceTester, "mbsanity2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
182+
}
183+
#endif
160184
}
161185
/*-----------------------------------------------------------*/
162186

@@ -819,6 +843,71 @@ const TickType_t xTicksToBlock = pdMS_TO_TICKS( 250UL );
819843
}
820844
/*-----------------------------------------------------------*/
821845

846+
/* Tests within configRUN_ADDITIONAL_TESTS blocks only execute on larger
847+
* platforms or have been added to pre-existing files that are already in use
848+
* by other test projects without ensuring they don't cause those pre-existing
849+
* projects to run out of program or data memory. */
850+
#if( configRUN_ADDITIONAL_TESTS == 1 )
851+
852+
static void prvSpaceAvailableCoherenceActor( void *pvParameters )
853+
{
854+
static char *cTxString = "12345";
855+
char cRxString[ mbCOHERENCE_TEST_BYTES_WRITTEN + 1 ]; /* +1 for NULL terminator. */
856+
857+
( void ) pvParameters;
858+
859+
for( ;; )
860+
{
861+
/* Add bytes to the buffer so the other task should see
862+
mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING bytes free. */
863+
xMessageBufferSend( xCoherenceTestMessageBuffer, ( void * ) cTxString, strlen( cTxString ), 0 );
864+
configASSERT( xMessageBufferSpacesAvailable( xCoherenceTestMessageBuffer ) == mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING );
865+
866+
/* Read out message again so the other task should read the full
867+
mbCOHERENCE_TEST_BUFFER_SIZE bytes free again. */
868+
memset( ( void * ) cRxString, 0x00, sizeof( cRxString ) );
869+
xMessageBufferReceive( xCoherenceTestMessageBuffer, ( void * ) cRxString, mbCOHERENCE_TEST_BYTES_WRITTEN, 0 );
870+
configASSERT( strcmp( cTxString, cRxString ) == 0 );
871+
}
872+
}
873+
/*-----------------------------------------------------------*/
874+
875+
static void prvSpaceAvailableCoherenceTester( void *pvParameters )
876+
{
877+
size_t xSpaceAvailable;
878+
BaseType_t xErrorFound = pdFALSE;
879+
880+
( void ) pvParameters;
881+
882+
for( ;; )
883+
{
884+
/* This message buffer is only ever empty or contains 5 bytes. So all
885+
queries of its free space should result in one of the two values tested
886+
below. */
887+
xSpaceAvailable = xMessageBufferSpacesAvailable( xCoherenceTestMessageBuffer );
888+
889+
if( ( xSpaceAvailable == mbCOHERENCE_TEST_BUFFER_SIZE ) ||
890+
( xSpaceAvailable == mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING ) )
891+
{
892+
/* Only continue to increment the variable that shows this task
893+
is still executing if no errors have been found. */
894+
if( xErrorFound == pdFALSE )
895+
{
896+
ulSizeCoherencyTestCycles++;
897+
}
898+
}
899+
else
900+
{
901+
xErrorFound = pdTRUE;
902+
}
903+
904+
configASSERT( xErrorFound == pdFALSE );
905+
}
906+
}
907+
908+
#endif /* configRUN_ADDITIONAL_TESTS == 1 */
909+
/*-----------------------------------------------------------*/
910+
822911
BaseType_t xAreMessageBufferTasksStillRunning( void )
823912
{
824913
static uint32_t ulLastEchoLoopCounters[ mbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
@@ -864,6 +953,21 @@ BaseType_t xReturn = pdPASS, x;
864953
}
865954
#endif /* configSUPPORT_STATIC_ALLOCATION */
866955

956+
#if( configRUN_ADDITIONAL_TESTS == 1 )
957+
{
958+
static uint32_t ullastSizeCoherencyTestCycles = 0UL;
959+
960+
if( ullastSizeCoherencyTestCycles == ulSizeCoherencyTestCycles )
961+
{
962+
xReturn = pdFAIL;
963+
}
964+
else
965+
{
966+
ullastSizeCoherencyTestCycles = ulSizeCoherencyTestCycles;
967+
}
968+
}
969+
#endif
970+
867971
return xReturn;
868972
}
869973
/*-----------------------------------------------------------*/

FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ functions anyway. */
112112
#define INCLUDE_xTimerPendFunctionCall 1
113113
#define INCLUDE_xTaskAbortDelay 1
114114

115+
/* The Win32 target is capable of running all the tests tasks at the same
116+
* time. */
117+
#define configRUN_ADDITIONAL_TESTS 1
118+
115119
/* It is a good idea to define configASSERT() while developing. configASSERT()
116120
uses the same semantics as the standard C assert() macro. */
117121
extern void vAssertCalled( unsigned long ulLine, const char * const pcFileName );

FreeRTOS/Demo/WIN32-MSVC/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ smaller heap regions - in which case heap_4.c would be the more appropriate
8080
choice. See http://www.freertos.org/a00111.html for an explanation. */
8181
#define mainREGION_1_SIZE 8201
8282
#define mainREGION_2_SIZE 29905
83-
#define mainREGION_3_SIZE 7607
83+
#define mainREGION_3_SIZE 7807
8484

8585
/*-----------------------------------------------------------*/
8686

0 commit comments

Comments
 (0)