]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/Common/Minimal/StreamBufferDemo.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / Common / Minimal / StreamBufferDemo.c
index 0c812ac8afa618bee57e312885a778984cdb85cf..49546ce96a3ae72ae6952818dae43138bccb4213 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
- * FreeRTOS Kernel V10.0.1\r
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ * FreeRTOS Kernel V10.3.0\r
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
  *\r
  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
  * this software and associated documentation files (the "Software"), to deal in\r
@@ -40,6 +40,9 @@
 /* The number of bytes of storage in the stream buffers used in this test. */\r
 #define sbSTREAM_BUFFER_LENGTH_BYTES   ( ( size_t ) 30 )\r
 \r
+/* Stream buffer length one. */\r
+#define sbSTREAM_BUFFER_LENGTH_ONE             ( ( size_t ) 1 )\r
+\r
 /* Start and end ASCII characters used in data sent to the buffers. */\r
 #define sbASCII_SPACE                                  32\r
 #define sbASCII_TILDA                                  126\r
@@ -92,6 +95,10 @@ static void prvEchoServer( void *pvParameters );
 static void prvNonBlockingReceiverTask( void *pvParameters );\r
 static void prvNonBlockingSenderTask( void *pvParameters );\r
 \r
+/* Performs an assert() like check in a way that won't get removed when\r
+performing a code coverage analysis. */\r
+static void prvCheckExpectedState( BaseType_t xState );\r
+\r
 /*\r
  * A task that creates a stream buffer with a specific trigger level, then\r
  * receives a string from an interrupt (the RTOS tick hook) byte by byte to\r
@@ -151,6 +158,10 @@ accidentally read out of the buffer. */
 static const char *pc55ByteString = "One two three four five six seven eight nine ten eleven";\r
 static const char *pc54ByteString = "01234567891abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ";\r
 \r
+/* Used to log the status of the tests contained within this file for reporting\r
+to a monitoring task ('check' task). */\r
+static BaseType_t xErrorStatus = pdPASS;\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 void vStartStreamBufferTasks( void )\r
@@ -188,6 +199,16 @@ StreamBufferHandle_t xStreamBuffer;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+static void prvCheckExpectedState( BaseType_t xState )\r
+{\r
+       configASSERT( xState );\r
+       if( xState == pdFAIL )\r
+       {\r
+               xErrorStatus = pdFAIL;\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 static void prvSingleTaskTests( StreamBufferHandle_t xStreamBuffer )\r
 {\r
 size_t xReturned, xItem, xExpectedSpace;\r
@@ -213,15 +234,15 @@ UBaseType_t uxOriginalPriority;
        /* Nothing has been added or removed yet, so expect the free space to be\r
        exactly as created. */\r
        xExpectedSpace = xStreamBufferSpacesAvailable( xStreamBuffer );\r
-       configASSERT( xExpectedSpace == sbSTREAM_BUFFER_LENGTH_BYTES );\r
-       configASSERT( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );\r
+       prvCheckExpectedState( xExpectedSpace == sbSTREAM_BUFFER_LENGTH_BYTES );\r
+       prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );\r
 \r
 \r
        /* The buffer is 30 bytes long.  6 5 byte messages should fit before the\r
        buffer is completely full. */\r
        for( xItem = 0; xItem < xMax6ByteMessages; xItem++ )\r
        {\r
-               configASSERT( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );\r
+               prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );\r
 \r
                /* Generate recognisable data to write to the buffer.  This is just\r
                ascii characters that shows which loop iteration the data was written\r
@@ -235,27 +256,23 @@ UBaseType_t uxOriginalPriority;
                        xReturned = xStreamBufferSendFromISR( xStreamBuffer, ( void * ) pucData, x6ByteLength, NULL );\r
                }\r
                taskEXIT_CRITICAL();\r
-               configASSERT( xReturned == x6ByteLength );\r
-               ( void ) xReturned; /* In case configASSERT() is not defined. */\r
+               prvCheckExpectedState( xReturned == x6ByteLength );\r
 \r
                /* The space in the buffer will have reduced by the amount of user data\r
                written into the buffer. */\r
                xExpectedSpace -= x6ByteLength;\r
                xReturned = xStreamBufferSpacesAvailable( xStreamBuffer );\r
-               configASSERT( xReturned == xExpectedSpace );\r
-               ( void ) xReturned; /* In case configASSERT() is not defined. */\r
+               prvCheckExpectedState( xReturned == xExpectedSpace );\r
                xReturned = xStreamBufferBytesAvailable( xStreamBuffer );\r
                /* +1 as it is zero indexed. */\r
-               configASSERT( xReturned == ( ( xItem + 1 ) * x6ByteLength ) );\r
-               ( void ) xReturned; /* In case configASSERT() is not defined. */\r
+               prvCheckExpectedState( xReturned == ( ( xItem + 1 ) * x6ByteLength ) );\r
        }\r
 \r
        /* Now the buffer should be full, and attempting to add anything will should\r
        fail. */\r
-       configASSERT( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );\r
+       prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );\r
        xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, sizeof( pucData[ 0 ] ), sbDONT_BLOCK );\r
-       configASSERT( xReturned == 0 );\r
-       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
+       prvCheckExpectedState( xReturned == 0 );\r
 \r
        /* Adding with a timeout should also fail after the appropriate time.  The\r
        priority is temporarily boosted in this part of the test to keep the\r
@@ -266,12 +283,9 @@ UBaseType_t uxOriginalPriority;
        xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, sizeof( pucData[ 0 ] ), xBlockTime );\r
        xTimeAfterCall = xTaskGetTickCount();\r
        vTaskPrioritySet( NULL, uxOriginalPriority );\r
-       configASSERT( ( xTimeAfterCall - xTimeBeforeCall ) >= xBlockTime );\r
-       configASSERT( ( xTimeAfterCall - xTimeBeforeCall ) < ( xBlockTime + xAllowableMargin ) );\r
-       configASSERT( xReturned == 0 ); /* In case configASSERT() is not defined. */\r
-       ( void ) xTimeAfterCall;\r
-       ( void ) xTimeBeforeCall;\r
-\r
+       prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) >= xBlockTime );\r
+       prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) < ( xBlockTime + xAllowableMargin ) );\r
+       prvCheckExpectedState( xReturned == 0 );\r
 \r
        /* The buffer is now full of data in the form "000000", "111111", etc.  Make\r
        sure the data is read out as expected. */\r
@@ -290,24 +304,24 @@ UBaseType_t uxOriginalPriority;
                        xReturned = xStreamBufferReceiveFromISR( xStreamBuffer, ( void * ) pucReadData, x6ByteLength, NULL );\r
                }\r
                taskEXIT_CRITICAL();\r
-               configASSERT( xReturned == x6ByteLength );\r
+               prvCheckExpectedState( xReturned == x6ByteLength );\r
 \r
                /* Does the data read out match that expected? */\r
-               configASSERT( memcmp( ( void * ) pucData, ( void * ) pucReadData, x6ByteLength ) == 0 );\r
+               prvCheckExpectedState( memcmp( ( void * ) pucData, ( void * ) pucReadData, x6ByteLength ) == 0 );\r
 \r
                /* The space in the buffer will have increased by the amount of user\r
                data removed from the buffer. */\r
                xExpectedSpace += x6ByteLength;\r
                xReturned = xStreamBufferSpacesAvailable( xStreamBuffer );\r
-               configASSERT( xReturned == xExpectedSpace );\r
+               prvCheckExpectedState( xReturned == xExpectedSpace );\r
                xReturned = xStreamBufferBytesAvailable( xStreamBuffer );\r
-               configASSERT( xReturned == ( sbSTREAM_BUFFER_LENGTH_BYTES - xExpectedSpace ) );\r
+               prvCheckExpectedState( xReturned == ( sbSTREAM_BUFFER_LENGTH_BYTES - xExpectedSpace ) );\r
        }\r
 \r
        /* The buffer should be empty again. */\r
-       configASSERT( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );\r
+       prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );\r
        xExpectedSpace = xStreamBufferSpacesAvailable( xStreamBuffer );\r
-       configASSERT( xExpectedSpace == sbSTREAM_BUFFER_LENGTH_BYTES );\r
+       prvCheckExpectedState( xExpectedSpace == sbSTREAM_BUFFER_LENGTH_BYTES );\r
 \r
        /* Reading with a timeout should also fail after the appropriate time.  The\r
        priority is temporarily boosted in this part of the test to keep the\r
@@ -317,9 +331,9 @@ UBaseType_t uxOriginalPriority;
        xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucReadData, x6ByteLength, xBlockTime );\r
        xTimeAfterCall = xTaskGetTickCount();\r
        vTaskPrioritySet( NULL, uxOriginalPriority );\r
-       configASSERT( ( xTimeAfterCall - xTimeBeforeCall ) >= xBlockTime );\r
-       configASSERT( ( xTimeAfterCall - xTimeBeforeCall ) < ( xBlockTime + xAllowableMargin ) );\r
-       configASSERT( xReturned == 0 );\r
+       prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) >= xBlockTime );\r
+       prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) < ( xBlockTime + xAllowableMargin ) );\r
+       prvCheckExpectedState( xReturned == 0 );\r
 \r
 \r
        /* In the next loop 17 bytes are written to then read out on each\r
@@ -333,38 +347,38 @@ UBaseType_t uxOriginalPriority;
                in. */\r
                memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x17ByteLength );\r
                xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, x17ByteLength, sbDONT_BLOCK );\r
-               configASSERT( xReturned == x17ByteLength );\r
+               prvCheckExpectedState( xReturned == x17ByteLength );\r
 \r
                /* The space in the buffer will have reduced by the amount of user data\r
                written into the buffer. */\r
                xReturned = xStreamBufferSpacesAvailable( xStreamBuffer );\r
-               configASSERT( xReturned == xExpectedSpace );\r
+               prvCheckExpectedState( xReturned == xExpectedSpace );\r
                xReturned = xStreamBufferBytesAvailable( xStreamBuffer );\r
-               configASSERT( xReturned == x17ByteLength );\r
-               configASSERT( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );\r
-               configASSERT( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );\r
+               prvCheckExpectedState( xReturned == x17ByteLength );\r
+               prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );\r
+               prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );\r
 \r
                /* Read the 17 bytes out again. */\r
                xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucReadData, x17ByteLength, sbDONT_BLOCK );\r
-               configASSERT( xReturned == x17ByteLength );\r
+               prvCheckExpectedState( xReturned == x17ByteLength );\r
 \r
                /* Does the data read out match that expected? */\r
-               configASSERT( memcmp( ( void * ) pucData, ( void * ) pucReadData, x17ByteLength ) == 0 );\r
+               prvCheckExpectedState( memcmp( ( void * ) pucData, ( void * ) pucReadData, x17ByteLength ) == 0 );\r
 \r
                /* Full buffer space available again. */\r
                xReturned = xStreamBufferSpacesAvailable( xStreamBuffer );\r
-               configASSERT( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );\r
+               prvCheckExpectedState( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );\r
                xReturned = xStreamBufferBytesAvailable( xStreamBuffer );\r
-               configASSERT( xReturned == 0 );\r
-               configASSERT( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );\r
-               configASSERT( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );\r
+               prvCheckExpectedState( xReturned == 0 );\r
+               prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );\r
+               prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );\r
        }\r
 \r
        /* Fill the buffer with one message, check it is full, then read it back\r
        again and check the correct data is received. */\r
        xStreamBufferSend( xStreamBuffer, ( const void * ) pc55ByteString, sbSTREAM_BUFFER_LENGTH_BYTES, sbDONT_BLOCK );\r
        xStreamBufferReceive( xStreamBuffer, ( void * ) pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES, sbDONT_BLOCK );\r
-       configASSERT( memcmp( pc55ByteString, pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );\r
+       prvCheckExpectedState( memcmp( pc55ByteString, pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );\r
 \r
        /* Fill the buffer one bytes at a time. */\r
        for( xItem = 0; xItem < sbSTREAM_BUFFER_LENGTH_BYTES; xItem++ )\r
@@ -375,23 +389,23 @@ UBaseType_t uxOriginalPriority;
        }\r
 \r
        /* The buffer should now be full. */\r
-       configASSERT( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );\r
+       prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );\r
 \r
        /* Read the message out in one go, even though it was written in individual\r
        bytes.  Try reading much more data than is actually available to ensure only\r
        the available bytes are returned (otherwise this read will write outside of\r
        the memory allocated anyway!). */\r
        xReturned = xStreamBufferReceive( xStreamBuffer, pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES * ( size_t ) 2, sbRX_TX_BLOCK_TIME );\r
-       configASSERT( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );\r
-       configASSERT( memcmp( ( const void * ) pc54ByteString, ( const void * ) pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );\r
+       prvCheckExpectedState( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );\r
+       prvCheckExpectedState( memcmp( ( const void * ) pc54ByteString, ( const void * ) pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );\r
 \r
        /* Now do the opposite, write in one go and read out in single bytes. */\r
        xReturned = xStreamBufferSend( xStreamBuffer, ( const void * ) pc55ByteString, sbSTREAM_BUFFER_LENGTH_BYTES, sbRX_TX_BLOCK_TIME );\r
-       configASSERT( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );\r
-       configASSERT( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );\r
-       configASSERT( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );\r
-       configASSERT( xStreamBufferBytesAvailable( xStreamBuffer ) == sbSTREAM_BUFFER_LENGTH_BYTES );\r
-       configASSERT( xStreamBufferSpacesAvailable( xStreamBuffer ) == 0 );\r
+       prvCheckExpectedState( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );\r
+       prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );\r
+       prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );\r
+       prvCheckExpectedState( xStreamBufferBytesAvailable( xStreamBuffer ) == sbSTREAM_BUFFER_LENGTH_BYTES );\r
+       prvCheckExpectedState( xStreamBufferSpacesAvailable( xStreamBuffer ) == 0 );\r
 \r
        /* Read from the buffer one byte at a time. */\r
        for( xItem = 0; xItem < sbSTREAM_BUFFER_LENGTH_BYTES; xItem++ )\r
@@ -399,10 +413,10 @@ UBaseType_t uxOriginalPriority;
                /* Block time is only for test coverage, the task should never actually\r
                block here. */\r
                xStreamBufferReceive( xStreamBuffer, ( void * ) pucFullBuffer, sizeof( char ), sbRX_TX_BLOCK_TIME );\r
-               configASSERT( pc55ByteString[ xItem ] == pucFullBuffer[ 0 ] );\r
+               prvCheckExpectedState( pc55ByteString[ xItem ] == pucFullBuffer[ 0 ] );\r
        }\r
-       configASSERT( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );\r
-       configASSERT( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );\r
+       prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );\r
+       prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );\r
 \r
        /* Try writing more bytes than there is space. */\r
        vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );\r
@@ -410,23 +424,23 @@ UBaseType_t uxOriginalPriority;
        xReturned = xStreamBufferSend( xStreamBuffer, ( const void * ) pc54ByteString, sbSTREAM_BUFFER_LENGTH_BYTES * ( size_t ) 2, xMinimalBlockTime );\r
        xTimeAfterCall = xTaskGetTickCount();\r
        vTaskPrioritySet( NULL, uxOriginalPriority );\r
-       configASSERT( ( xTimeAfterCall - xTimeBeforeCall ) >= xMinimalBlockTime );\r
-       configASSERT( ( xTimeAfterCall - xTimeBeforeCall ) < ( xMinimalBlockTime + xAllowableMargin ) );\r
-       configASSERT( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );\r
-       configASSERT( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );\r
-       configASSERT( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );\r
+       prvCheckExpectedState( ( xTimeAfterCall - xTimeBeforeCall ) >= xMinimalBlockTime );\r
+       prvCheckExpectedState( ( xTimeAfterCall - xTimeBeforeCall ) < ( xMinimalBlockTime + xAllowableMargin ) );\r
+       prvCheckExpectedState( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );\r
+       prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );\r
+       prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );\r
 \r
        /* No space now though. */\r
        xReturned = xStreamBufferSend( xStreamBuffer, ( const void * ) pc54ByteString, sbSTREAM_BUFFER_LENGTH_BYTES * ( size_t ) 2, xMinimalBlockTime );\r
-       configASSERT( xReturned == 0 );\r
+       prvCheckExpectedState( xReturned == 0 );\r
 \r
        /* Ensure data was written as expected even when there was an attempt to\r
        write more than was available.  This also tries to read more bytes than are\r
        available. */\r
        xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucFullBuffer, xFullBufferSize, xMinimalBlockTime );\r
-       configASSERT( memcmp( ( const void * ) pucFullBuffer, ( const void * ) pc54ByteString, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );\r
-       configASSERT( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );\r
-       configASSERT( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );\r
+       prvCheckExpectedState( memcmp( ( const void * ) pucFullBuffer, ( const void * ) pc54ByteString, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );\r
+       prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );\r
+       prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );\r
 \r
        /* Clean up with data in the buffer to ensure the tests that follow don't\r
        see the data (the data should be discarded). */\r
@@ -458,12 +472,12 @@ const size_t xStringLength = strlen( pc54ByteString );
 \r
                /* Attempt to send right up to the end of the string. */\r
                xBytesActuallySent = xStreamBufferSend( xStreamBuffer, ( const void * ) &( pc54ByteString[ xNextChar ] ), xBytesToSend, sbDONT_BLOCK );\r
-               configASSERT( xBytesActuallySent <= xBytesToSend );\r
+               prvCheckExpectedState( xBytesActuallySent <= xBytesToSend );\r
 \r
                /* Move the index up the string to the next character to be sent,\r
                wrapping if the end of the string has been reached. */\r
                xNextChar += xBytesActuallySent;\r
-               configASSERT( xNextChar <= xStringLength );\r
+               prvCheckExpectedState( xNextChar <= xStringLength );\r
 \r
                if( xNextChar == xStringLength )\r
                {\r
@@ -565,7 +579,7 @@ BaseType_t xNonBlockingReceiveError = pdFALSE;
 \r
                /* Make sure a change in priority does not inadvertently result in an\r
                invalid array index. */\r
-               configASSERT( uxIndex < sbNUMBER_OF_ECHO_CLIENTS );\r
+               prvCheckExpectedState( uxIndex < sbNUMBER_OF_ECHO_CLIENTS );\r
 \r
                /* Avoid compiler warnings about unused parameters. */\r
                ( void ) pvParameters;\r
@@ -600,13 +614,13 @@ BaseType_t xNonBlockingReceiveError = pdFALSE;
                        xBytesToSend = xStringLength - xNextChar;\r
 \r
                        /* Attempt to send right up to the end of the string. */\r
-                       xBytesActuallySent = xStreamBufferSend( xStreamBuffer, ( void * ) &( pc55ByteString[ xNextChar ] ), xBytesToSend, xTicksToWait );\r
-                       configASSERT( xBytesActuallySent <= xBytesToSend );\r
+                       xBytesActuallySent = xStreamBufferSend( xStreamBuffer, ( const void * ) &( pc55ByteString[ xNextChar ] ), xBytesToSend, xTicksToWait );\r
+                       prvCheckExpectedState( xBytesActuallySent <= xBytesToSend );\r
 \r
                        /* Move the index up the string to the next character to be sent,\r
                        wrapping if the end of the string has been reached. */\r
                        xNextChar += xBytesActuallySent;\r
-                       configASSERT( xNextChar <= xStringLength );\r
+                       prvCheckExpectedState( xNextChar <= xStringLength );\r
 \r
                        if( xNextChar == xStringLength )\r
                        {\r
@@ -630,6 +644,7 @@ BaseType_t xNonBlockingReceiveError = pdFALSE;
                        string, but no data is written into the buffer so any valid address\r
                        will do. */\r
                        xTempStreamBuffer = xStreamBufferCreateStatic( sizeof( ucTempBuffer ), sbTRIGGER_LEVEL_1, ucTempBuffer, &xStaticStreamBuffer );\r
+                       xStreamBufferReset( xTempStreamBuffer );\r
                        vStreamBufferDelete( xTempStreamBuffer );\r
                }\r
        }\r
@@ -641,7 +656,7 @@ BaseType_t xNonBlockingReceiveError = pdFALSE;
 \r
        static void prvReceiverTask( void *pvParameters )\r
        {\r
-       StreamBufferHandle_t * const pxStreamBuffer = ( StreamBufferHandle_t * ) pvParameters;\r
+       StreamBufferHandle_t const pxStreamBuffer = ( StreamBufferHandle_t ) pvParameters;\r
        char cRxString[ 12 ]; /* Large enough to hold a 32-bit number in ASCII. */\r
        const TickType_t xTicksToWait = pdMS_TO_TICKS( 5UL );\r
        const size_t xStringLength = strlen( pc55ByteString );\r
@@ -661,7 +676,7 @@ BaseType_t xNonBlockingReceiveError = pdFALSE;
                        } while( xReceivedLength == 0 );\r
 \r
                        /* Ensure the received string matches the expected string. */\r
-                       configASSERT( memcmp( ( void * ) cRxString, ( void * ) &( pc55ByteString[ xNextChar ] ), xReceivedLength ) == 0 );\r
+                       prvCheckExpectedState( memcmp( ( void * ) cRxString, ( const void * ) &( pc55ByteString[ xNextChar ] ), xReceivedLength ) == 0 );\r
 \r
                        /* Move the index into the string up to the end of the bytes\r
                        received so far - wrapping if the end of the string has been\r
@@ -743,7 +758,7 @@ EchoStreamBuffers_t *pxStreamBuffers = ( EchoStreamBuffers_t * ) pvParameters;
                memset( pcStringReceived, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );\r
                xStreamBufferReceive( pxStreamBuffers->xEchoServerBuffer, ( void * ) pcStringReceived, xSendLength, portMAX_DELAY );\r
 \r
-               configASSERT( strcmp( pcStringToSend, pcStringReceived ) == 0 );\r
+               prvCheckExpectedState( strcmp( pcStringToSend, pcStringReceived ) == 0 );\r
 \r
                /* Maintain a count of the number of times this code executes so a\r
                check task can determine if this task is still functioning as\r
@@ -757,6 +772,51 @@ EchoStreamBuffers_t *pxStreamBuffers = ( EchoStreamBuffers_t * ) pvParameters;
                xTempStreamBuffer = xStreamBufferCreate( sbSTREAM_BUFFER_LENGTH_BYTES, sbTRIGGER_LEVEL_1 );\r
                prvSingleTaskTests( xTempStreamBuffer );\r
                vStreamBufferDelete( xTempStreamBuffer );\r
+\r
+               /* The following are tests for a stream buffer of size one. */\r
+               /* Create a buffer of size one. */\r
+               xTempStreamBuffer = xStreamBufferCreate( sbSTREAM_BUFFER_LENGTH_ONE, sbTRIGGER_LEVEL_1 );\r
+               /* Ensure that the buffer was created successfully. */\r
+               configASSERT( xTempStreamBuffer );\r
+\r
+               /* Send one byte to the buffer. */\r
+               ux = xStreamBufferSend( xTempStreamBuffer, ( void * ) pcStringToSend, ( size_t ) 1, sbDONT_BLOCK );\r
+               /* Ensure that the byte was sent successfully. */\r
+               configASSERT( ux == 1 );\r
+               /* Try sending another byte to the buffer. */\r
+               ux = xStreamBufferSend( xTempStreamBuffer, ( void * ) pcStringToSend, ( size_t ) 1, sbDONT_BLOCK );\r
+               /* Make sure that send failed as the buffer is full. */\r
+               configASSERT( ux == 0 );\r
+\r
+               /* Receive one byte from the buffer. */\r
+               memset( pcStringReceived, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );\r
+               ux = xStreamBufferReceive( xTempStreamBuffer, ( void * ) pcStringReceived, ( size_t ) 1, sbDONT_BLOCK );\r
+               /* Ensure that the receive was successful. */\r
+               configASSERT( ux == 1 );\r
+               /* Ensure that the correct data was received. */\r
+               configASSERT( pcStringToSend[ 0 ] == pcStringReceived[ 0 ] );\r
+               /* Try receiving another byte from the buffer. */\r
+               ux = xStreamBufferReceive( xTempStreamBuffer, ( void * ) pcStringReceived, ( size_t ) 1, sbDONT_BLOCK );\r
+               /* Ensure that the receive failed as the buffer is empty. */\r
+               configASSERT( ux == 0 );\r
+\r
+               /* Try sending two bytes to the buffer. Since the size of the\r
+                * buffer is one, we must not be able to send more than one. */\r
+               ux = xStreamBufferSend( xTempStreamBuffer, ( void * ) pcStringToSend, ( size_t ) 2, sbDONT_BLOCK );\r
+               /* Ensure that only one byte was sent. */\r
+               configASSERT( ux == 1 );\r
+\r
+               /* Try receiving two bytes from the buffer. Since the size of the\r
+                * buffer is one, we must not be able to get more than one. */\r
+               memset( pcStringReceived, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );\r
+               ux = xStreamBufferReceive( xTempStreamBuffer, ( void * ) pcStringReceived, ( size_t ) 2, sbDONT_BLOCK );\r
+               /* Ensure that only one byte was received. */\r
+               configASSERT( ux == 1 );\r
+               /* Ensure that the correct data was received. */\r
+               configASSERT( pcStringToSend[ 0 ] == pcStringReceived[ 0 ] );\r
+\r
+               /* Delete the buffer. */\r
+               vStreamBufferDelete( xTempStreamBuffer );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -787,9 +847,8 @@ const TickType_t xTicksToBlock = pdMS_TO_TICKS( 350UL );
        /* Don't expect to receive anything yet! */\r
        xTimeOnEntering = xTaskGetTickCount();\r
        xReceivedLength = xStreamBufferReceive( xStreamBuffers.xEchoClientBuffer, ( void * ) pcReceivedString, sbSTREAM_BUFFER_LENGTH_BYTES, xTicksToBlock );\r
-       configASSERT( ( xTaskGetTickCount() - xTimeOnEntering ) >= xTicksToBlock );\r
-       configASSERT( xReceivedLength == 0 );\r
-       ( void ) xTimeOnEntering;\r
+       prvCheckExpectedState( ( ( TickType_t ) ( xTaskGetTickCount() - xTimeOnEntering ) ) >= xTicksToBlock );\r
+       prvCheckExpectedState( xReceivedLength == 0 );\r
 \r
        /* Now the stream buffers have been created the echo client task can be\r
        created.  If this server task has the higher priority then the client task\r
@@ -812,10 +871,10 @@ const TickType_t xTicksToBlock = pdMS_TO_TICKS( 350UL );
                memset( pcReceivedString, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );\r
 \r
                /* Has any data been sent by the client? */\r
-               xReceivedLength = xStreamBufferReceive( xStreamBuffers.xEchoClientBuffer, ( void * ) pcReceivedString, sbSTREAM_BUFFER_LENGTH_BYTES, xTicksToBlock );\r
+               xReceivedLength = xStreamBufferReceive( xStreamBuffers.xEchoClientBuffer, ( void * ) pcReceivedString, sbSTREAM_BUFFER_LENGTH_BYTES, portMAX_DELAY );\r
 \r
-               /* Should always receive data as a delay was used. */\r
-               configASSERT( xReceivedLength > 0 );\r
+               /* Should always receive data as max delay was used. */\r
+               prvCheckExpectedState( xReceivedLength > 0 );\r
 \r
                /* Echo the received data back to the client. */\r
                xStreamBufferSend( xStreamBuffers.xEchoServerBuffer, ( void * ) pcReceivedString, xReceivedLength, portMAX_DELAY );\r
@@ -874,6 +933,7 @@ BaseType_t xErrorDetected = pdFALSE;
                {\r
                        /* Create the stream buffer that will be used from inside the tick\r
                        interrupt. */\r
+                       memset( ucRxData, 0x00, sizeof( ucRxData ) );\r
                        xStreamBuffer = xStreamBufferCreate( xStreamBufferSizeBytes, xTriggerLevel );\r
                        configASSERT( xStreamBuffer );\r
 \r
@@ -899,21 +959,36 @@ BaseType_t xErrorDetected = pdFALSE;
                        /* Now check the number of bytes received equals the trigger level,\r
                        except in the case that the read timed out before the trigger level\r
                        was reached. */\r
-                       if( xBytesReceived < xTriggerLevel )\r
+                       if( xTriggerLevel > xReadBlockTime )\r
                        {\r
-                               /* This should only happen if the trigger level was greater than\r
-                               the block time. */\r
-                               if( xTriggerLevel < xReadBlockTime )\r
+                               /* Trigger level was greater than the block time so expect to\r
+                               time out having received xReadBlockTime bytes. */\r
+                               if( ( xReadBlockTime - xBytesReceived ) > xAllowableMargin )\r
                                {\r
                                        xErrorDetected = pdTRUE;\r
                                }\r
                        }\r
-                       else if( ( xBytesReceived - xTriggerLevel ) > xAllowableMargin )\r
+                       else if( xTriggerLevel < xReadBlockTime )\r
                        {\r
-                               /* A margin may be required here if there are other high priority\r
-                               tasks prevent the task that reads from the message buffer running\r
-                               immediately. */\r
-                               xErrorDetected = pdTRUE;\r
+                               /* Trigger level was less than the block time so we expect to\r
+                               have received the trigger level number of bytes - could be more\r
+                               though depending on other activity between the task being\r
+                               unblocked and the task reading the number of bytes received. */\r
+                               if( ( xBytesReceived - xTriggerLevel ) > xAllowableMargin )\r
+                               {\r
+                                       xErrorDetected = pdTRUE;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               /* The trigger level equaled the block time, so expect to\r
+                               receive no greater than the block time, but one or two less is\r
+                               ok due to variations in how far through the time slice the\r
+                               functions get executed. */\r
+                               if( ( xBytesReceived - xReadBlockTime ) > xAllowableMargin )\r
+                               {\r
+                                       xErrorDetected = pdTRUE;\r
+                               }\r
                        }\r
 \r
                        if( xBytesReceived > sizeof( ucRxData ) )\r
@@ -946,13 +1021,13 @@ BaseType_t xAreStreamBufferTasksStillRunning( void )
 static uint32_t ulLastEchoLoopCounters[ sbNUMBER_OF_ECHO_CLIENTS ] = { 0 };\r
 static uint32_t ulLastNonBlockingRxCounter = 0;\r
 static uint32_t ulLastInterruptTriggerCounter = 0;\r
-BaseType_t xReturn = pdPASS, x;\r
+BaseType_t x;\r
 \r
        for( x = 0; x < sbNUMBER_OF_ECHO_CLIENTS; x++ )\r
        {\r
                if( ulLastEchoLoopCounters[ x ] == ulEchoLoopCounters[ x ] )\r
                {\r
-                       xReturn = pdFAIL;\r
+                       xErrorStatus = pdFAIL;\r
                }\r
                else\r
                {\r
@@ -962,7 +1037,7 @@ BaseType_t xReturn = pdPASS, x;
 \r
        if( ulNonBlockingRxCounter == ulLastNonBlockingRxCounter )\r
        {\r
-               xReturn = pdFAIL;\r
+               xErrorStatus = pdFAIL;\r
        }\r
        else\r
        {\r
@@ -971,7 +1046,7 @@ BaseType_t xReturn = pdPASS, x;
 \r
        if( ulLastInterruptTriggerCounter == ulInterruptTriggerCounter )\r
        {\r
-               xReturn = pdFAIL;\r
+               xErrorStatus = pdFAIL;\r
        }\r
        else\r
        {\r
@@ -986,7 +1061,7 @@ BaseType_t xReturn = pdPASS, x;
                {\r
                        if( ulLastSenderLoopCounters[ x ] == ulSenderLoopCounters[ x ] )\r
                        {\r
-                               xReturn = pdFAIL;\r
+                               xErrorStatus = pdFAIL;\r
                        }\r
                        else\r
                        {\r
@@ -996,7 +1071,7 @@ BaseType_t xReturn = pdPASS, x;
        }\r
        #endif /* configSUPPORT_STATIC_ALLOCATION */\r
 \r
-       return xReturn;\r
+       return xErrorStatus;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r