/*\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
/* 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
xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, sizeof( pucData[ 0 ] ), xBlockTime );\r
xTimeAfterCall = xTaskGetTickCount();\r
vTaskPrioritySet( NULL, uxOriginalPriority );\r
- prvCheckExpectedState( ( xTimeAfterCall - xTimeBeforeCall ) >= xBlockTime );\r
- prvCheckExpectedState( ( xTimeAfterCall - xTimeBeforeCall ) < ( xBlockTime + xAllowableMargin ) );\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
xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucReadData, x6ByteLength, xBlockTime );\r
xTimeAfterCall = xTaskGetTickCount();\r
vTaskPrioritySet( NULL, uxOriginalPriority );\r
- prvCheckExpectedState( ( xTimeAfterCall - xTimeBeforeCall ) >= xBlockTime );\r
- prvCheckExpectedState( ( xTimeAfterCall - xTimeBeforeCall ) < ( xBlockTime + xAllowableMargin ) );\r
+ prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) >= xBlockTime );\r
+ prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) < ( xBlockTime + xAllowableMargin ) );\r
prvCheckExpectedState( xReturned == 0 );\r
\r
\r
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
\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
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
/* Don't expect to receive anything yet! */\r
xTimeOnEntering = xTaskGetTickCount();\r
xReceivedLength = xStreamBufferReceive( xStreamBuffers.xEchoClientBuffer, ( void * ) pcReceivedString, sbSTREAM_BUFFER_LENGTH_BYTES, xTicksToBlock );\r
- prvCheckExpectedState( ( xTaskGetTickCount() - xTimeOnEntering ) >= xTicksToBlock );\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
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
+ /* Should always receive data as max delay was used. */\r
prvCheckExpectedState( xReceivedLength > 0 );\r
\r
/* Echo the received data back to the client. */\r
{\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
/* 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