summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCobus van Eeden <35851496+cobusve@users.noreply.github.com>2021-03-20 11:50:16 -0700
committerGitHub <noreply@github.com>2021-03-20 11:50:16 -0700
commit26478d721f87d4c78bb86bc2733fe6488f4fbb58 (patch)
treee93c9dad9bdf4c4ce80d8020ce2c2d04641742db
parentf39765be2226889510a1237f3b2fa1cf1ed4a652 (diff)
downloadfreertos-git-26478d721f87d4c78bb86bc2733fe6488f4fbb58.tar.gz
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>
-rw-r--r--FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/FreeRTOSConfig.h4
-rw-r--r--FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/main.c8
-rw-r--r--FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c104
-rw-r--r--FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h4
-rw-r--r--FreeRTOS/Demo/WIN32-MSVC/main.c4
5 files changed, 118 insertions, 6 deletions
diff --git a/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/FreeRTOSConfig.h b/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/FreeRTOSConfig.h
index ac34ce7e3..7a5b4134d 100644
--- a/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/FreeRTOSConfig.h
+++ b/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/FreeRTOSConfig.h
@@ -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). */
diff --git a/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/main.c b/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/main.c
index 14a47bd1b..0f1fd6e0c 100644
--- a/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/main.c
+++ b/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/main.c
@@ -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();
{
diff --git a/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c b/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c
index 57f69fbe5..d6d770bb8 100644
--- a/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c
+++ b/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c
@@ -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;
}
/*-----------------------------------------------------------*/
diff --git a/FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h b/FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h
index 0912eee51..d45a8195c 100644
--- a/FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h
+++ b/FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h
@@ -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 );
diff --git a/FreeRTOS/Demo/WIN32-MSVC/main.c b/FreeRTOS/Demo/WIN32-MSVC/main.c
index a721a099f..81676f119 100644
--- a/FreeRTOS/Demo/WIN32-MSVC/main.c
+++ b/FreeRTOS/Demo/WIN32-MSVC/main.c
@@ -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
/*-----------------------------------------------------------*/