/*\r
- * FreeRTOS Kernel V10.0.1\r
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
+ * FreeRTOS Kernel V10.2.1\r
+ * Copyright (C) 2019 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
/* Demo includes. */\r
#include "QueueSet.h"\r
\r
+\r
+#if( configUSE_QUEUE_SETS == 1 ) /* Remove the tests if queue sets are not defined. */\r
+\r
+\r
/* The number of queues that are created and added to the queue set. */\r
#define queuesetNUM_QUEUES_IN_SET 3\r
\r
*/\r
static void prvTestQueueOverwriteWithQueueSet( void );\r
\r
+/*\r
+ * Test the case where two queues within a set are written to with\r
+ * xQueueOverwrite().\r
+ */\r
+static void prvTestQueueOverwriteOnTwoQueusInQueueSet( void );\r
+static void prvTestQueueOverwriteFromISROnTwoQueusInQueueSet( void );\r
+\r
/*\r
* Local pseudo random number seed and return functions. Used to avoid calls\r
* to the standard library.\r
/* Create a queue that has a length of one - a requirement in order to call\r
xQueueOverwrite. This will get deleted again when this test completes. */\r
xQueueHandle = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );\r
+ configASSERT( xQueueHandle );\r
\r
if( xQueueHandle != NULL )\r
{\r
xQueueAddToSet( xQueueHandle, xQueueSet );\r
\r
/* Add an item to the queue then ensure the queue set correctly\r
- indicates that one item is available, and that that item is indeed the\r
+ indicates that one item is available, and that item is indeed the\r
queue written to. */\r
xQueueOverwrite( xQueueHandle, ( void * ) &ulValueToSend );\r
if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )\r
xQueueReceive( xQueueHandle, &ulValueReceived, queuesetDONT_BLOCK );\r
if( ulValueReceived != ulValueToSend )\r
{\r
- /* Unexpected value recevied from the queue. */\r
+ /* Unexpected value received from the queue. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+ /* Should be anything in the queue set now. */\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 0 )\r
+ {\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
+ if( xReceivedHandle != NULL )\r
+ {\r
xQueueSetTasksStatus = pdFAIL;\r
}\r
\r
}\r
/*-----------------------------------------------------------*/\r
\r
+static void prvTestQueueOverwriteOnTwoQueusInQueueSet( void )\r
+{\r
+uint32_t ulValueToSend1 = 1, ulValueToSend2 = 2UL, ulValueReceived = 0;\r
+QueueHandle_t xQueueHandle1 = NULL, xQueueHandle2 = NULL, xReceivedHandle = NULL;\r
+const UBaseType_t xLengthOfOne = ( UBaseType_t ) 1;\r
+\r
+ /* Create two queues that have a length of one - a requirement in order to call\r
+ xQueueOverwrite. These will get deleted again when this test completes. */\r
+ xQueueHandle1 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );\r
+ configASSERT( xQueueHandle1 );\r
+ xQueueHandle2 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );\r
+ configASSERT( xQueueHandle2 );\r
+\r
+ if( ( xQueueHandle1 != NULL ) && ( xQueueHandle2 != NULL ) )\r
+ {\r
+ /* Add both queues to the queue set. */\r
+ xQueueAddToSet( xQueueHandle1, xQueueSet );\r
+ xQueueAddToSet( xQueueHandle2, xQueueSet );\r
+\r
+ /* Add an item using the first queue. */\r
+ xQueueOverwrite( xQueueHandle1, ( void * ) &ulValueToSend1 );\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )\r
+ {\r
+ /* Expected one item in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+ xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );\r
+ if( xReceivedHandle != xQueueHandle1 )\r
+ {\r
+ /* Wrote to xQueueHandle so expected xQueueHandle to be the handle\r
+ held in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+\r
+ /* Next add an item to the second queue. */\r
+ xQueueOverwrite( xQueueHandle2, ( void * ) &ulValueToSend2 );\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
+ {\r
+ /* Expected two items in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+ /* The head of the queue set should not have changed though. */\r
+ xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );\r
+ if( xReceivedHandle != xQueueHandle1 )\r
+ {\r
+ /* Wrote to xQueueHandle so expected xQueueHandle to be the handle\r
+ held in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+\r
+\r
+\r
+ /* Now overwrite the value in the queue and ensure the queue set state\r
+ doesn't change as the number of items in the queues within the set have\r
+ not changed. NOTE: after this queue 1 should hold ulValueToSend2 and queue\r
+ 2 should hold the value ulValueToSend1. */\r
+ xQueueOverwrite( xQueueHandle1, ( void * ) &ulValueToSend2 );\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
+ {\r
+ /* Still expected two items in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+ xQueueOverwrite( xQueueHandle2, ( void * ) &ulValueToSend1 );\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
+ {\r
+ /* Still expected two items in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+\r
+ /* Repeat the above to ensure the queue set state doesn't change. */\r
+ xQueueOverwrite( xQueueHandle1, ( void * ) &ulValueToSend2 );\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
+ {\r
+ /* Still expected two items in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+ xQueueOverwrite( xQueueHandle2, ( void * ) &ulValueToSend1 );\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
+ {\r
+ /* Still expected two items in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+\r
+ /* Now when reading from the queue set we expect the handle to the first\r
+ queue to be received first, and for that queue to hold ulValueToSend2 as the\r
+ originally written value was overwritten. Likewise the second handle received\r
+ from the set should be that of the second queue, and that queue should hold\r
+ ulValueToSend1 as the originally written value was overwritten. */\r
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
+ if( xReceivedHandle != xQueueHandle1 )\r
+ {\r
+ /* Wrote to xQueueHandle1 first so expected that handle to be read from\r
+ the set first. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )\r
+ {\r
+ /* One value was read from the set, so now only expect a single value\r
+ in the set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+ xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );\r
+ if( ulValueReceived != ulValueToSend2 )\r
+ {\r
+ /* Unexpected value received from the queue. ulValueToSend1 was written\r
+ first, but then overwritten with ulValueToSend2; */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
+ if( xReceivedHandle != xQueueHandle2 )\r
+ {\r
+ /* xQueueHandle1 has already been removed from the set so expect only\r
+ xQueueHandle2 to be left. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 0 )\r
+ {\r
+ /* The last value was read from the set so don't expect any more. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+ xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );\r
+ if( ulValueReceived != ulValueToSend1 )\r
+ {\r
+ /* Unexpected value received from the queue. ulValueToSend2 was written\r
+ first, but then overwritten with ulValueToSend1. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+\r
+\r
+\r
+ /* Should be anything in the queue set now. */\r
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
+ if( xReceivedHandle != NULL )\r
+ {\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+ /* Clean up. */\r
+ xQueueRemoveFromSet( xQueueHandle1, xQueueSet );\r
+ xQueueRemoveFromSet( xQueueHandle2, xQueueSet );\r
+ vQueueDelete( xQueueHandle1 );\r
+ vQueueDelete( xQueueHandle2 );\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvTestQueueOverwriteFromISROnTwoQueusInQueueSet( void )\r
+{\r
+uint32_t ulValueToSend1 = 1, ulValueToSend2 = 2UL, ulValueReceived = 0;\r
+QueueHandle_t xQueueHandle1 = NULL, xQueueHandle2 = NULL, xReceivedHandle = NULL;\r
+const UBaseType_t xLengthOfOne = ( UBaseType_t ) 1;\r
+\r
+ /* Create two queues that have a length of one - a requirement in order to call\r
+ xQueueOverwrite. These will get deleted again when this test completes. */\r
+ xQueueHandle1 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );\r
+ configASSERT( xQueueHandle1 );\r
+ xQueueHandle2 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );\r
+ configASSERT( xQueueHandle2 );\r
+\r
+ if( ( xQueueHandle1 != NULL ) && ( xQueueHandle2 != NULL ) )\r
+ {\r
+ /* Add both queues to the queue set. */\r
+ xQueueAddToSet( xQueueHandle1, xQueueSet );\r
+ xQueueAddToSet( xQueueHandle2, xQueueSet );\r
+\r
+ /* Add an item using the first queue using the 'FromISR' version of the\r
+ overwrite function. */\r
+ xQueueOverwriteFromISR( xQueueHandle1, ( void * ) &ulValueToSend1, NULL );\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )\r
+ {\r
+ /* Expected one item in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+ xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );\r
+ if( xReceivedHandle != xQueueHandle1 )\r
+ {\r
+ /* Wrote to xQueueHandle so expected xQueueHandle to be the handle\r
+ held in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+\r
+ /* Next add an item to the second queue using the 'FromISR' version of the\r
+ overwrite function. */\r
+ xQueueOverwriteFromISR( xQueueHandle2, ( void * ) &ulValueToSend2, NULL );\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
+ {\r
+ /* Expected two items in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+ /* The head of the queue set should not have changed though. */\r
+ xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );\r
+ if( xReceivedHandle != xQueueHandle1 )\r
+ {\r
+ /* Wrote to xQueueHandle so expected xQueueHandle to be the handle\r
+ held in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+\r
+\r
+\r
+ /* Now overwrite the value in the queue and ensure the queue set state\r
+ doesn't change as the number of items in the queues within the set have\r
+ not changed. NOTE: after this queue 1 should hold ulValueToSend2 and queue\r
+ 2 should hold the value ulValueToSend1. */\r
+ xQueueOverwriteFromISR( xQueueHandle1, ( void * ) &ulValueToSend2, NULL );\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
+ {\r
+ /* Still expected two items in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+ xQueueOverwriteFromISR( xQueueHandle2, ( void * ) &ulValueToSend1, NULL );\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
+ {\r
+ /* Still expected two items in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+\r
+ /* Repeat the above to ensure the queue set state doesn't change. */\r
+ xQueueOverwriteFromISR( xQueueHandle1, ( void * ) &ulValueToSend2, NULL );\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
+ {\r
+ /* Still expected two items in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+ xQueueOverwriteFromISR( xQueueHandle2, ( void * ) &ulValueToSend1, NULL );\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
+ {\r
+ /* Still expected two items in the queue set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+\r
+ /* Now when reading from the queue set we expect the handle to the first\r
+ queue to be received first, and for that queue to hold ulValueToSend2 as the\r
+ originally written value was overwritten. Likewise the second handle received\r
+ from the set should be that of the second queue, and that queue should hold\r
+ ulValueToSend1 as the originally written value was overwritten. */\r
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
+ if( xReceivedHandle != xQueueHandle1 )\r
+ {\r
+ /* Wrote to xQueueHandle1 first so expected that handle to be read from\r
+ the set first. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )\r
+ {\r
+ /* One value was read from the set, so now only expect a single value\r
+ in the set. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+ xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );\r
+ if( ulValueReceived != ulValueToSend2 )\r
+ {\r
+ /* Unexpected value received from the queue. ulValueToSend1 was written\r
+ first, but then overwritten with ulValueToSend2; */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
+ if( xReceivedHandle != xQueueHandle2 )\r
+ {\r
+ /* xQueueHandle1 has already been removed from the set so expect only\r
+ xQueueHandle2 to be left. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 0 )\r
+ {\r
+ /* The last value was read from the set so don't expect any more. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+ xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );\r
+ if( ulValueReceived != ulValueToSend1 )\r
+ {\r
+ /* Unexpected value received from the queue. ulValueToSend2 was written\r
+ first, but then overwritten with ulValueToSend1. */\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+\r
+\r
+\r
+ /* Should be anything in the queue set now. */\r
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
+ if( xReceivedHandle != NULL )\r
+ {\r
+ xQueueSetTasksStatus = pdFAIL;\r
+ }\r
+\r
+ /* Clean up. */\r
+ xQueueRemoveFromSet( xQueueHandle1, xQueueSet );\r
+ xQueueRemoveFromSet( xQueueHandle2, xQueueSet );\r
+ vQueueDelete( xQueueHandle1 );\r
+ vQueueDelete( xQueueHandle2 );\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
static void prvSetupTest( void )\r
{\r
BaseType_t x;\r
be performed on queues that have a length of 1. */\r
prvTestQueueOverwriteWithQueueSet();\r
\r
+ /* Test the case where two queues within a set are written to with\r
+ xQueueOverwrite(). */\r
+ prvTestQueueOverwriteOnTwoQueusInQueueSet();\r
+ prvTestQueueOverwriteFromISROnTwoQueusInQueueSet();\r
+\r
+ /* In case any of the above have already indicated a failure. */\r
+ configASSERT( xQueueSetTasksStatus != pdFAIL );\r
+\r
/* Resume the task that writes to the queues. */\r
vTaskResume( xQueueSetSendingTask );\r
\r
uxNextRand = uxSeed;\r
}\r
\r
+#endif /* ( configUSE_QUEUE_SETS == 1 ) */\r