@@ -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+
822911BaseType_t xAreMessageBufferTasksStillRunning ( void )
823912{
824913static 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/*-----------------------------------------------------------*/
0 commit comments