]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/Minimal/QueueSet.c
Increase test coverage for queue sets.
[freertos] / FreeRTOS / Demo / Common / Minimal / QueueSet.c
1 /*\r
2  * FreeRTOS Kernel V10.2.1\r
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /*\r
29  * Tests the use of queue sets.\r
30  *\r
31  * A receive task creates a number of queues and adds them to a queue set before\r
32  * blocking on the queue set receive.  A transmit task and (optionally) an\r
33  * interrupt repeatedly unblocks the receive task by sending messages to the\r
34  * queues in a pseudo random order.  The receive task removes the messages from\r
35  * the queues and flags an error if the received message does not match that\r
36  * expected.  The task sends values in the range 0 to\r
37  * queuesetINITIAL_ISR_TX_VALUE, and the ISR sends value in the range\r
38  * queuesetINITIAL_ISR_TX_VALUE to ULONG_MAX.\r
39  */\r
40 \r
41 \r
42 /* Standard includes. */\r
43 #include <stdlib.h>\r
44 #include <limits.h>\r
45 \r
46 /* Kernel includes. */\r
47 #include "FreeRTOS.h"\r
48 #include "task.h"\r
49 #include "queue.h"\r
50 \r
51 /* Demo includes. */\r
52 #include "QueueSet.h"\r
53 \r
54 \r
55 #if( configUSE_QUEUE_SETS == 1 ) /* Remove the tests if queue sets are not defined. */\r
56 \r
57 \r
58 /* The number of queues that are created and added to the queue set. */\r
59 #define queuesetNUM_QUEUES_IN_SET 3\r
60 \r
61 /* The length of each created queue. */\r
62 #define queuesetQUEUE_LENGTH    3\r
63 \r
64 /* Block times used in this demo.  A block time or 0 means "don't block". */\r
65 #define queuesetSHORT_DELAY     200\r
66 #define queuesetDONT_BLOCK 0\r
67 \r
68 /* Messages are sent in incrementing order from both a task and an interrupt.\r
69 The task sends values in the range 0 to 0xfffe, and the interrupt sends values\r
70 in the range of 0xffff to ULONG_MAX. */\r
71 #define queuesetINITIAL_ISR_TX_VALUE 0xffffUL\r
72 \r
73 /* The priorities used in this demo. */\r
74 #define queuesetLOW_PRIORITY    ( tskIDLE_PRIORITY )\r
75 #define queuesetMEDIUM_PRIORITY ( queuesetLOW_PRIORITY + 1 )\r
76 \r
77 /* For test purposes the priority of the sending task is changed after every\r
78 queuesetPRIORITY_CHANGE_LOOPS number of values are sent to a queue. */\r
79 #define queuesetPRIORITY_CHANGE_LOOPS   ( ( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH ) * 2 )\r
80 \r
81 /* The ISR sends to the queue every queuesetISR_TX_PERIOD ticks. */\r
82 #define queuesetISR_TX_PERIOD   ( 100UL )\r
83 \r
84 /* A delay inserted when the Tx task changes its priority to be above the idle\r
85 task priority to ensure the idle priority tasks get some CPU time before the\r
86 next iteration of the queue set Tx task. */\r
87 #define queuesetTX_LOOP_DELAY   pdMS_TO_TICKS( ( TickType_t ) 200 )\r
88 \r
89 /* The allowable maximum deviation between a received value and the expected\r
90 received value.  A deviation will occur when data is received from a queue\r
91 inside an ISR in between a task receiving from a queue and the task checking\r
92 the received value. */\r
93 #define queuesetALLOWABLE_RX_DEVIATION 3\r
94 \r
95 /* Ignore values that are at the boundaries of allowable values to make the\r
96 testing of limits easier (don't have to deal with wrapping values). */\r
97 #define queuesetIGNORED_BOUNDARY        ( queuesetALLOWABLE_RX_DEVIATION * 2 )\r
98 \r
99 typedef enum\r
100 {\r
101         eEqualPriority = 0,     /* Tx and Rx tasks have the same priority. */\r
102         eTxHigherPriority,      /* The priority of the Tx task is above that of the Rx task. */\r
103         eTxLowerPriority        /* The priority of the Tx task is below that of the Rx task. */\r
104 } eRelativePriorities;\r
105 \r
106 /*\r
107  * The task that periodically sends to the queue set.\r
108  */\r
109 static void prvQueueSetSendingTask( void *pvParameters );\r
110 \r
111 /*\r
112  * The task that reads from the queue set.\r
113  */\r
114 static void prvQueueSetReceivingTask( void *pvParameters );\r
115 \r
116 /*\r
117  * Check the value received from a queue is the expected value.  Some values\r
118  * originate from the send task, some values originate from the ISR, with the\r
119  * range of the value being used to distinguish between the two message\r
120  * sources.\r
121  */\r
122 static void prvCheckReceivedValue( uint32_t ulReceived );\r
123 \r
124 /*\r
125  * For purposes of test coverage, functions that read from and write to a\r
126  * queue set from an ISR respectively.\r
127  */\r
128 static void prvReceiveFromQueueInSetFromISR( void );\r
129 static void prvSendToQueueInSetFromISR( void );\r
130 \r
131 /*\r
132  * Create the queues and add them to a queue set before resuming the Tx\r
133  * task.\r
134  */\r
135 static void prvSetupTest( void );\r
136 \r
137 /*\r
138  * Checks a value received from a queue falls within the range of expected\r
139  * values.\r
140  */\r
141 static BaseType_t prvCheckReceivedValueWithinExpectedRange( uint32_t ulReceived, uint32_t ulExpectedReceived );\r
142 \r
143 /*\r
144  * Increase test coverage by occasionally change the priorities of the two tasks\r
145  * relative to each other.\r
146  */\r
147 static void prvChangeRelativePriorities( void );\r
148 \r
149 /*\r
150  * Queue overwrites can only be performed on queues of length of one, requiring\r
151  * a special test function so a queue of length 1 can temporarily be added to a\r
152  * set.\r
153  */\r
154 static void prvTestQueueOverwriteWithQueueSet( void );\r
155 \r
156 /*\r
157  * Test the case where two queues within a set are written to with\r
158  * xQueueOverwrite().\r
159  */\r
160 static void prvTestQueueOverwriteOnTwoQueusInQueueSet( void );\r
161 static void prvTestQueueOverwriteFromISROnTwoQueusInQueueSet( void );\r
162 \r
163 /*\r
164  * Local pseudo random number seed and return functions.  Used to avoid calls\r
165  * to the standard library.\r
166  */\r
167 static size_t prvRand( void );\r
168 static void prvSRand( size_t uxSeed );\r
169 \r
170 /*-----------------------------------------------------------*/\r
171 \r
172 /* The queues that are added to the set. */\r
173 static QueueHandle_t xQueues[ queuesetNUM_QUEUES_IN_SET ] = { 0 };\r
174 \r
175 /* Counts how many times each queue in the set is used to ensure all the\r
176 queues are used. */\r
177 static uint32_t ulQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };\r
178 \r
179 /* The handle of the queue set to which the queues are added. */\r
180 static QueueSetHandle_t xQueueSet;\r
181 \r
182 /* If the prvQueueSetReceivingTask() task has not detected any errors then\r
183 it increments ulCycleCounter on each iteration.\r
184 xAreQueueSetTasksStillRunning() returns pdPASS if the value of\r
185 ulCycleCounter has changed between consecutive calls, and pdFALSE if\r
186 ulCycleCounter has stopped incrementing (indicating an error condition). */\r
187 static volatile uint32_t ulCycleCounter = 0UL;\r
188 \r
189 /* Set to pdFAIL if an error is detected by any queue set task.\r
190 ulCycleCounter will only be incremented if xQueueSetTasksSatus equals pdPASS. */\r
191 static volatile BaseType_t xQueueSetTasksStatus = pdPASS;\r
192 \r
193 /* Just a flag to let the function that writes to a queue from an ISR know that\r
194 the queues are setup and can be used. */\r
195 static volatile BaseType_t xSetupComplete = pdFALSE;\r
196 \r
197 /* The value sent to the queue from the ISR is file scope so the\r
198 xAreQueeuSetTasksStillRunning() function can check it is incrementing as\r
199 expected. */\r
200 static volatile uint32_t ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;\r
201 \r
202 /* Used by the pseudo random number generator. */\r
203 static size_t uxNextRand = 0;\r
204 \r
205 /* The task handles are stored so their priorities can be changed. */\r
206 TaskHandle_t xQueueSetSendingTask, xQueueSetReceivingTask;\r
207 \r
208 /*-----------------------------------------------------------*/\r
209 \r
210 void vStartQueueSetTasks( void )\r
211 {\r
212         /* Create the tasks. */\r
213         xTaskCreate( prvQueueSetSendingTask, "SetTx", configMINIMAL_STACK_SIZE, NULL, queuesetMEDIUM_PRIORITY, &xQueueSetSendingTask );\r
214 \r
215         if( xQueueSetSendingTask != NULL )\r
216         {\r
217                 xTaskCreate( prvQueueSetReceivingTask, "SetRx", configMINIMAL_STACK_SIZE, ( void * ) xQueueSetSendingTask, queuesetMEDIUM_PRIORITY, &xQueueSetReceivingTask );\r
218 \r
219                 /* It is important that the sending task does not attempt to write to a\r
220                 queue before the queue has been created.  It is therefore placed into\r
221                 the suspended state before the scheduler has started.  It is resumed by\r
222                 the receiving task after the receiving task has created the queues and\r
223                 added the queues to the queue set. */\r
224                 vTaskSuspend( xQueueSetSendingTask );\r
225         }\r
226 }\r
227 /*-----------------------------------------------------------*/\r
228 \r
229 BaseType_t xAreQueueSetTasksStillRunning( void )\r
230 {\r
231 static uint32_t ulLastCycleCounter, ulLastISRTxValue = 0;\r
232 static uint32_t ulLastQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };\r
233 BaseType_t xReturn = pdPASS, x;\r
234 \r
235         if( ulLastCycleCounter == ulCycleCounter )\r
236         {\r
237                 /* The cycle counter is no longer being incremented.  Either one of the\r
238                 tasks is stalled or an error has been detected. */\r
239                 xReturn = pdFAIL;\r
240         }\r
241 \r
242         ulLastCycleCounter = ulCycleCounter;\r
243 \r
244         /* Ensure that all the queues in the set have been used.  This ensures the\r
245         test is working as intended and guards against the rand() in the Tx task\r
246         missing some values. */\r
247         for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )\r
248         {\r
249                 if( ulLastQueueUsedCounter[ x ] == ulQueueUsedCounter[ x ] )\r
250                 {\r
251                         xReturn = pdFAIL;\r
252                 }\r
253 \r
254                 ulLastQueueUsedCounter[ x ] = ulQueueUsedCounter[ x ];\r
255         }\r
256 \r
257         /* Check the global status flag. */\r
258         if( xQueueSetTasksStatus != pdPASS )\r
259         {\r
260                 xReturn = pdFAIL;\r
261         }\r
262 \r
263         /* Check that the ISR is still sending values to the queues too. */\r
264         if( ulISRTxValue == ulLastISRTxValue )\r
265         {\r
266                 xReturn = pdFAIL;\r
267         }\r
268         else\r
269         {\r
270                 ulLastISRTxValue = ulISRTxValue;\r
271         }\r
272 \r
273         return xReturn;\r
274 }\r
275 /*-----------------------------------------------------------*/\r
276 \r
277 static void prvQueueSetSendingTask( void *pvParameters )\r
278 {\r
279 uint32_t ulTaskTxValue = 0;\r
280 size_t uxQueueToWriteTo;\r
281 QueueHandle_t xQueueInUse;\r
282 \r
283         /* Remove compiler warning about the unused parameter. */\r
284         ( void ) pvParameters;\r
285 \r
286         /* Seed mini pseudo random number generator. */\r
287         prvSRand( ( size_t ) &ulTaskTxValue );\r
288 \r
289         for( ;; )\r
290         {\r
291                 /* Generate the index for the queue to which a value is to be sent. */\r
292                 uxQueueToWriteTo = prvRand() % queuesetNUM_QUEUES_IN_SET;\r
293                 xQueueInUse = xQueues[ uxQueueToWriteTo ];\r
294 \r
295                 /* Note which index is being written to to ensure all the queues are\r
296                 used. */\r
297                 ( ulQueueUsedCounter[ uxQueueToWriteTo ] )++;\r
298 \r
299                 /* Send to the queue to unblock the task that is waiting for data to\r
300                 arrive on a queue within the queue set to which this queue belongs. */\r
301                 if( xQueueSendToBack( xQueueInUse, &ulTaskTxValue, portMAX_DELAY ) != pdPASS )\r
302                 {\r
303                         /* The send should always pass as an infinite block time was\r
304                         used. */\r
305                         xQueueSetTasksStatus = pdFAIL;\r
306                 }\r
307 \r
308                 #if( configUSE_PREEMPTION == 0 )\r
309                         taskYIELD();\r
310                 #endif\r
311 \r
312                 ulTaskTxValue++;\r
313 \r
314                 /* If the Tx value has reached the range used by the ISR then set it\r
315                 back to 0. */\r
316                 if( ulTaskTxValue == queuesetINITIAL_ISR_TX_VALUE )\r
317                 {\r
318                         ulTaskTxValue = 0;\r
319                 }\r
320 \r
321                 /* Increase test coverage by occasionally change the priorities of the\r
322                 two tasks relative to each other. */\r
323                 prvChangeRelativePriorities();\r
324         }\r
325 }\r
326 /*-----------------------------------------------------------*/\r
327 \r
328 static void prvChangeRelativePriorities( void )\r
329 {\r
330 static UBaseType_t ulLoops = 0;\r
331 static eRelativePriorities ePriorities = eEqualPriority;\r
332 \r
333         /* Occasionally change the task priority relative to the priority of\r
334         the receiving task. */\r
335         ulLoops++;\r
336         if( ulLoops >= queuesetPRIORITY_CHANGE_LOOPS )\r
337         {\r
338                 ulLoops = 0;\r
339 \r
340                 switch( ePriorities )\r
341                 {\r
342                         case eEqualPriority:\r
343                                 /* Both tasks are running with medium priority.  Now lower the\r
344                                 priority of the receiving task so the Tx task has the higher\r
345                                 relative priority. */\r
346                                 vTaskPrioritySet( xQueueSetReceivingTask, queuesetLOW_PRIORITY );\r
347                                 ePriorities = eTxHigherPriority;\r
348                                 break;\r
349 \r
350                         case eTxHigherPriority:\r
351                                 /* The Tx task is running with a higher priority than the Rx\r
352                                 task.  Switch the priorities around so the Rx task has the\r
353                                 higher relative priority. */\r
354                                 vTaskPrioritySet( xQueueSetReceivingTask, queuesetMEDIUM_PRIORITY );\r
355                                 vTaskPrioritySet( xQueueSetSendingTask, queuesetLOW_PRIORITY );\r
356                                 ePriorities = eTxLowerPriority;\r
357                                 break;\r
358 \r
359                         case eTxLowerPriority:\r
360                                 /* The Tx task is running with a lower priority than the Rx\r
361                                 task.  Make the priorities equal again. */\r
362                                 vTaskPrioritySet( xQueueSetSendingTask, queuesetMEDIUM_PRIORITY );\r
363                                 ePriorities = eEqualPriority;\r
364 \r
365                                 /* When both tasks are using a non-idle priority the queue set\r
366                                 tasks will starve idle priority tasks of execution time - so\r
367                                 relax a bit before the next iteration to minimise the impact. */\r
368                                 vTaskDelay( queuesetTX_LOOP_DELAY );\r
369 \r
370                                 break;\r
371                 }\r
372         }\r
373 }\r
374 /*-----------------------------------------------------------*/\r
375 \r
376 static void prvQueueSetReceivingTask( void *pvParameters )\r
377 {\r
378 uint32_t ulReceived;\r
379 QueueHandle_t xActivatedQueue;\r
380 TickType_t xBlockTime;\r
381 \r
382         /* Remove compiler warnings. */\r
383         ( void ) pvParameters;\r
384 \r
385         /* Create the queues and add them to the queue set before resuming the Tx\r
386         task. */\r
387         prvSetupTest();\r
388 \r
389         for( ;; )\r
390         {\r
391                 /* For test coverage reasons, the block time is dependent on the\r
392                 priority of this task - which changes during the test.  When the task\r
393                 is at the idle priority it polls the queue set. */\r
394                 if( uxTaskPriorityGet( NULL ) == tskIDLE_PRIORITY )\r
395                 {\r
396                         xBlockTime = 0;\r
397                 }\r
398                 else\r
399                 {\r
400                         xBlockTime = portMAX_DELAY;\r
401                 }\r
402 \r
403                 /* Wait for a message to arrive on one of the queues in the set. */\r
404                 xActivatedQueue = xQueueSelectFromSet( xQueueSet, portMAX_DELAY );\r
405 \r
406                 if( xActivatedQueue == NULL )\r
407                 {\r
408                         if( xBlockTime != 0 )\r
409                         {\r
410                                 /* This should not happen as an infinite delay was used. */\r
411                                 xQueueSetTasksStatus = pdFAIL;\r
412                         }\r
413                 }\r
414                 else\r
415                 {\r
416                         /* Reading from the queue should pass with a zero block time as\r
417                         this task will only run when something has been posted to a task\r
418                         in the queue set. */\r
419                         if( xQueueReceive( xActivatedQueue, &ulReceived, queuesetDONT_BLOCK ) != pdPASS )\r
420                         {\r
421                                 xQueueSetTasksStatus = pdFAIL;\r
422                         }\r
423 \r
424                         /* Ensure the value received was the value expected.  This function\r
425                         manipulates file scope data and is also called from an ISR, hence\r
426                         the critical section. */\r
427                         taskENTER_CRITICAL();\r
428                         {\r
429                                 prvCheckReceivedValue( ulReceived );\r
430                         }\r
431                         taskEXIT_CRITICAL();\r
432 \r
433                         if( xQueueSetTasksStatus == pdPASS )\r
434                         {\r
435                                 ulCycleCounter++;\r
436                         }\r
437                 }\r
438         }\r
439 }\r
440 /*-----------------------------------------------------------*/\r
441 \r
442 void vQueueSetAccessQueueSetFromISR( void )\r
443 {\r
444 static uint32_t ulCallCount = 0;\r
445 \r
446         /* xSetupComplete is set to pdTRUE when the queues have been created and\r
447         are available for use. */\r
448         if( xSetupComplete == pdTRUE )\r
449         {\r
450                 /* It is intended that this function is called from the tick hook\r
451                 function, so each call is one tick period apart. */\r
452                 ulCallCount++;\r
453                 if( ulCallCount > queuesetISR_TX_PERIOD )\r
454                 {\r
455                         ulCallCount = 0;\r
456 \r
457                         /* First attempt to read from the queue set. */\r
458                         prvReceiveFromQueueInSetFromISR();\r
459 \r
460                         /* Then write to the queue set. */\r
461                         prvSendToQueueInSetFromISR();\r
462                 }\r
463         }\r
464 }\r
465 /*-----------------------------------------------------------*/\r
466 \r
467 static void prvCheckReceivedValue( uint32_t ulReceived )\r
468 {\r
469 static uint32_t ulExpectedReceivedFromTask = 0, ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;\r
470 \r
471         /* Values are received in tasks and interrupts.  It is likely that the\r
472         receiving task will sometimes get preempted by the receiving interrupt\r
473         between reading a value from the queue and calling this function.  When\r
474         that happens, if the receiving interrupt calls this function the values\r
475         will get passed into this function slightly out of order.  For that\r
476         reason the value passed in is tested against a small range of expected\r
477         values, rather than a single absolute value.  To make the range testing\r
478         easier values in the range limits are ignored. */\r
479 \r
480         /* If the received value is equal to or greater than\r
481         queuesetINITIAL_ISR_TX_VALUE then it was sent by an ISR. */\r
482         if( ulReceived >= queuesetINITIAL_ISR_TX_VALUE )\r
483         {\r
484                 /* The value was sent from the ISR. */\r
485                 if( ( ulReceived - queuesetINITIAL_ISR_TX_VALUE ) < queuesetIGNORED_BOUNDARY )\r
486                 {\r
487                         /* The value received is at the lower limit of the expected range.\r
488                         Don't test it and expect to receive one higher next time. */\r
489                 }\r
490                 else if( ( ULONG_MAX - ulReceived ) <= queuesetIGNORED_BOUNDARY )\r
491                 {\r
492                         /* The value received is at the higher limit of the expected range.\r
493                         Don't test it and expect to wrap soon. */\r
494                 }\r
495                 else\r
496                 {\r
497                         /* Check the value against its expected value range. */\r
498                         if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromISR ) != pdPASS )\r
499                         {\r
500                                 xQueueSetTasksStatus = pdFAIL;\r
501                         }\r
502                 }\r
503 \r
504                 configASSERT( xQueueSetTasksStatus );\r
505 \r
506                 /* It is expected to receive an incrementing number. */\r
507                 ulExpectedReceivedFromISR++;\r
508                 if( ulExpectedReceivedFromISR == 0 )\r
509                 {\r
510                         ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;\r
511                 }\r
512         }\r
513         else\r
514         {\r
515                 /* The value was sent from the Tx task. */\r
516                 if( ulReceived < queuesetIGNORED_BOUNDARY )\r
517                 {\r
518                         /* The value received is at the lower limit of the expected range.\r
519                         Don't test it, and expect to receive one higher next time. */\r
520                 }\r
521                 else if( ( ( queuesetINITIAL_ISR_TX_VALUE - 1 ) - ulReceived ) <= queuesetIGNORED_BOUNDARY )\r
522                 {\r
523                         /* The value received is at the higher limit of the expected range.\r
524                         Don't test it and expect to wrap soon. */\r
525                 }\r
526                 else\r
527                 {\r
528                         /* Check the value against its expected value range. */\r
529                         if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromTask ) != pdPASS )\r
530                         {\r
531                                 xQueueSetTasksStatus = pdFAIL;\r
532                         }\r
533                 }\r
534 \r
535                 configASSERT( xQueueSetTasksStatus );\r
536 \r
537                 /* It is expected to receive an incrementing number. */\r
538                 ulExpectedReceivedFromTask++;\r
539                 if( ulExpectedReceivedFromTask >= queuesetINITIAL_ISR_TX_VALUE )\r
540                 {\r
541                         ulExpectedReceivedFromTask = 0;\r
542                 }\r
543         }\r
544 }\r
545 /*-----------------------------------------------------------*/\r
546 \r
547 static BaseType_t prvCheckReceivedValueWithinExpectedRange( uint32_t ulReceived, uint32_t ulExpectedReceived )\r
548 {\r
549 BaseType_t xReturn = pdPASS;\r
550 \r
551         if( ulReceived > ulExpectedReceived )\r
552         {\r
553                 configASSERT( ( ulReceived - ulExpectedReceived ) <= queuesetALLOWABLE_RX_DEVIATION );\r
554                 if( ( ulReceived - ulExpectedReceived ) > queuesetALLOWABLE_RX_DEVIATION )\r
555                 {\r
556                         xReturn = pdFALSE;\r
557                 }\r
558         }\r
559         else\r
560         {\r
561                 configASSERT( ( ulExpectedReceived - ulReceived ) <= queuesetALLOWABLE_RX_DEVIATION );\r
562                 if( ( ulExpectedReceived - ulReceived ) > queuesetALLOWABLE_RX_DEVIATION )\r
563                 {\r
564                         xReturn = pdFALSE;\r
565                 }\r
566         }\r
567 \r
568         return xReturn;\r
569 }\r
570 /*-----------------------------------------------------------*/\r
571 \r
572 static void prvReceiveFromQueueInSetFromISR( void )\r
573 {\r
574 QueueSetMemberHandle_t xActivatedQueue;\r
575 uint32_t ulReceived;\r
576 \r
577         /* See if any of the queues in the set contain data. */\r
578         xActivatedQueue = xQueueSelectFromSetFromISR( xQueueSet );\r
579 \r
580         if( xActivatedQueue != NULL )\r
581         {\r
582                 /* Reading from the queue for test purposes only. */\r
583                 if( xQueueReceiveFromISR( xActivatedQueue, &ulReceived, NULL ) != pdPASS )\r
584                 {\r
585                         /* Data should have been available as the handle was returned from\r
586                         xQueueSelectFromSetFromISR(). */\r
587                         xQueueSetTasksStatus = pdFAIL;\r
588                 }\r
589 \r
590                 /* Ensure the value received was the value expected. */\r
591                 prvCheckReceivedValue( ulReceived );\r
592         }\r
593 }\r
594 /*-----------------------------------------------------------*/\r
595 \r
596 static void prvSendToQueueInSetFromISR( void )\r
597 {\r
598 static BaseType_t xQueueToWriteTo = 0;\r
599 uint32_t ulTxValueSnapshot = ulISRTxValue;\r
600 \r
601         if( xQueueSendFromISR( xQueues[ xQueueToWriteTo ], ( void * ) &ulTxValueSnapshot, NULL ) == pdPASS )\r
602         {\r
603                 ulISRTxValue++;\r
604 \r
605                 /* If the Tx value has wrapped then set it back to its initial value. */\r
606                 if( ulISRTxValue == 0UL )\r
607                 {\r
608                         ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;\r
609                 }\r
610 \r
611                 /* Use a different queue next time. */\r
612                 xQueueToWriteTo++;\r
613                 if( xQueueToWriteTo >= queuesetNUM_QUEUES_IN_SET )\r
614                 {\r
615                         xQueueToWriteTo = 0;\r
616                 }\r
617         }\r
618 }\r
619 /*-----------------------------------------------------------*/\r
620 \r
621 static void prvTestQueueOverwriteWithQueueSet( void )\r
622 {\r
623 uint32_t ulValueToSend = 0, ulValueReceived = 0;\r
624 QueueHandle_t xQueueHandle = NULL, xReceivedHandle = NULL;\r
625 const UBaseType_t xLengthOfOne = ( UBaseType_t ) 1;\r
626 \r
627         /* Create a queue that has a length of one - a requirement in order to call\r
628         xQueueOverwrite.  This will get deleted again when this test completes. */\r
629         xQueueHandle = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );\r
630         configASSERT( xQueueHandle );\r
631 \r
632         if( xQueueHandle != NULL )\r
633         {\r
634                 xQueueAddToSet( xQueueHandle, xQueueSet );\r
635 \r
636                 /* Add an item to the queue then ensure the queue set correctly\r
637                 indicates that one item is available, and that item is indeed the\r
638                 queue written to. */\r
639                 xQueueOverwrite( xQueueHandle, ( void * ) &ulValueToSend );\r
640                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )\r
641                 {\r
642                         /* Expected one item in the queue set. */\r
643                         xQueueSetTasksStatus = pdFAIL;\r
644                 }\r
645                 xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );\r
646                 if( xReceivedHandle != xQueueHandle )\r
647                 {\r
648                         /* Wrote to xQueueHandle so expected xQueueHandle to be the handle\r
649                         held in the queue set. */\r
650                         xQueueSetTasksStatus = pdFAIL;\r
651                 }\r
652 \r
653                 /* Now overwrite the value in the queue and ensure the queue set state\r
654                 doesn't change as the number of items in the queues within the set have\r
655                 not changed. */\r
656                 ulValueToSend++;\r
657                 xQueueOverwrite( xQueueHandle, ( void * ) &ulValueToSend );\r
658                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )\r
659                 {\r
660                         /* Still expected one item in the queue set. */\r
661                         xQueueSetTasksStatus = pdFAIL;\r
662                 }\r
663                 xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
664                 if( xReceivedHandle != xQueueHandle )\r
665                 {\r
666                         /* Wrote to xQueueHandle so expected xQueueHandle to be the handle\r
667                         held in the queue set. */\r
668                         xQueueSetTasksStatus = pdFAIL;\r
669                 }\r
670 \r
671                 /* Also ensure the value received from the queue is the overwritten\r
672                 value, not the value originally written. */\r
673                 xQueueReceive( xQueueHandle, &ulValueReceived, queuesetDONT_BLOCK );\r
674                 if( ulValueReceived != ulValueToSend )\r
675                 {\r
676                         /* Unexpected value received from the queue. */\r
677                         xQueueSetTasksStatus = pdFAIL;\r
678                 }\r
679 \r
680                 /* Should be anything in the queue set now. */\r
681                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 0 )\r
682                 {\r
683                         xQueueSetTasksStatus = pdFAIL;\r
684                 }\r
685                 xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
686                 if( xReceivedHandle != NULL )\r
687                 {\r
688                         xQueueSetTasksStatus = pdFAIL;\r
689                 }\r
690 \r
691                 /* Clean up. */\r
692                 xQueueRemoveFromSet( xQueueHandle, xQueueSet );\r
693                 vQueueDelete( xQueueHandle );\r
694         }\r
695 }\r
696 /*-----------------------------------------------------------*/\r
697 \r
698 static void prvTestQueueOverwriteOnTwoQueusInQueueSet( void )\r
699 {\r
700 uint32_t ulValueToSend1 = 1, ulValueToSend2 = 2UL, ulValueReceived = 0;\r
701 QueueHandle_t xQueueHandle1 = NULL, xQueueHandle2 = NULL, xReceivedHandle = NULL;\r
702 const UBaseType_t xLengthOfOne = ( UBaseType_t ) 1;\r
703 \r
704         /* Create two queues that have a length of one - a requirement in order to call\r
705         xQueueOverwrite.  These will get deleted again when this test completes. */\r
706         xQueueHandle1 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );\r
707         configASSERT( xQueueHandle1 );\r
708         xQueueHandle2 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );\r
709         configASSERT( xQueueHandle2 );\r
710 \r
711         if( ( xQueueHandle1 != NULL ) && ( xQueueHandle2 != NULL ) )\r
712         {\r
713                 /* Add both queues to the queue set. */\r
714                 xQueueAddToSet( xQueueHandle1, xQueueSet );\r
715                 xQueueAddToSet( xQueueHandle2, xQueueSet );\r
716 \r
717                 /* Add an item using the first queue. */\r
718                 xQueueOverwrite( xQueueHandle1, ( void * ) &ulValueToSend1 );\r
719                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )\r
720                 {\r
721                         /* Expected one item in the queue set. */\r
722                         xQueueSetTasksStatus = pdFAIL;\r
723                 }\r
724 \r
725                 xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );\r
726                 if( xReceivedHandle != xQueueHandle1 )\r
727                 {\r
728                         /* Wrote to xQueueHandle so expected xQueueHandle to be the handle\r
729                         held in the queue set. */\r
730                         xQueueSetTasksStatus = pdFAIL;\r
731                 }\r
732 \r
733 \r
734                 /* Next add an item to the second queue. */\r
735                 xQueueOverwrite( xQueueHandle2, ( void * ) &ulValueToSend2 );\r
736                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
737                 {\r
738                         /* Expected two items in the queue set. */\r
739                         xQueueSetTasksStatus = pdFAIL;\r
740                 }\r
741 \r
742                 /* The head of the queue set should not have changed though. */\r
743                 xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );\r
744                 if( xReceivedHandle != xQueueHandle1 )\r
745                 {\r
746                         /* Wrote to xQueueHandle so expected xQueueHandle to be the handle\r
747                         held in the queue set. */\r
748                         xQueueSetTasksStatus = pdFAIL;\r
749                 }\r
750 \r
751 \r
752 \r
753 \r
754                 /* Now overwrite the value in the queue and ensure the queue set state\r
755                 doesn't change as the number of items in the queues within the set have\r
756                 not changed.  NOTE:  after this queue 1 should hold ulValueToSend2 and queue\r
757                 2 should hold the value ulValueToSend1. */\r
758                 xQueueOverwrite( xQueueHandle1, ( void * ) &ulValueToSend2 );\r
759                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
760                 {\r
761                         /* Still expected two items in the queue set. */\r
762                         xQueueSetTasksStatus = pdFAIL;\r
763                 }\r
764                 xQueueOverwrite( xQueueHandle2, ( void * ) &ulValueToSend1 );\r
765                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
766                 {\r
767                         /* Still expected two items in the queue set. */\r
768                         xQueueSetTasksStatus = pdFAIL;\r
769                 }\r
770 \r
771 \r
772                 /* Repeat the above to ensure the queue set state doesn't change. */\r
773                 xQueueOverwrite( xQueueHandle1, ( void * ) &ulValueToSend2 );\r
774                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
775                 {\r
776                         /* Still expected two items in the queue set. */\r
777                         xQueueSetTasksStatus = pdFAIL;\r
778                 }\r
779                 xQueueOverwrite( xQueueHandle2, ( void * ) &ulValueToSend1 );\r
780                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
781                 {\r
782                         /* Still expected two items in the queue set. */\r
783                         xQueueSetTasksStatus = pdFAIL;\r
784                 }\r
785 \r
786 \r
787                 /* Now when reading from the queue set we expect the handle to the first\r
788                 queue to be received first, and for that queue to hold ulValueToSend2 as the\r
789                 originally written value was overwritten.  Likewise the second handle received\r
790                 from the set should be that of the second queue, and that queue should hold\r
791                 ulValueToSend1 as the originally written value was overwritten. */\r
792                 xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
793                 if( xReceivedHandle != xQueueHandle1 )\r
794                 {\r
795                         /* Wrote to xQueueHandle1 first so expected that handle to be read from\r
796                         the set first. */\r
797                         xQueueSetTasksStatus = pdFAIL;\r
798                 }\r
799                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )\r
800                 {\r
801                         /* One value was read from the set, so now only expect a single value\r
802                         in the set. */\r
803                         xQueueSetTasksStatus = pdFAIL;\r
804                 }\r
805                 xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );\r
806                 if( ulValueReceived != ulValueToSend2 )\r
807                 {\r
808                         /* Unexpected value received from the queue.  ulValueToSend1 was written\r
809                         first, but then overwritten with ulValueToSend2; */\r
810                         xQueueSetTasksStatus = pdFAIL;\r
811                 }\r
812 \r
813                 xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
814                 if( xReceivedHandle != xQueueHandle2 )\r
815                 {\r
816                         /* xQueueHandle1 has already been removed from the set so expect only\r
817                         xQueueHandle2 to be left. */\r
818                         xQueueSetTasksStatus = pdFAIL;\r
819                 }\r
820                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 0 )\r
821                 {\r
822                         /* The last value was read from the set so don't expect any more. */\r
823                         xQueueSetTasksStatus = pdFAIL;\r
824                 }\r
825                 xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );\r
826                 if( ulValueReceived != ulValueToSend1 )\r
827                 {\r
828                         /* Unexpected value received from the queue.  ulValueToSend2 was written\r
829                         first, but then overwritten with ulValueToSend1. */\r
830                         xQueueSetTasksStatus = pdFAIL;\r
831                 }\r
832 \r
833 \r
834 \r
835 \r
836                 /* Should be anything in the queue set now. */\r
837                 xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
838                 if( xReceivedHandle != NULL )\r
839                 {\r
840                         xQueueSetTasksStatus = pdFAIL;\r
841                 }\r
842 \r
843                 /* Clean up. */\r
844                 xQueueRemoveFromSet( xQueueHandle1, xQueueSet );\r
845                 xQueueRemoveFromSet( xQueueHandle2, xQueueSet );\r
846                 vQueueDelete( xQueueHandle1 );\r
847                 vQueueDelete( xQueueHandle2 );\r
848         }\r
849 }\r
850 /*-----------------------------------------------------------*/\r
851 \r
852 static void prvTestQueueOverwriteFromISROnTwoQueusInQueueSet( void )\r
853 {\r
854 uint32_t ulValueToSend1 = 1, ulValueToSend2 = 2UL, ulValueReceived = 0;\r
855 QueueHandle_t xQueueHandle1 = NULL, xQueueHandle2 = NULL, xReceivedHandle = NULL;\r
856 const UBaseType_t xLengthOfOne = ( UBaseType_t ) 1;\r
857 \r
858         /* Create two queues that have a length of one - a requirement in order to call\r
859         xQueueOverwrite.  These will get deleted again when this test completes. */\r
860         xQueueHandle1 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );\r
861         configASSERT( xQueueHandle1 );\r
862         xQueueHandle2 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );\r
863         configASSERT( xQueueHandle2 );\r
864 \r
865         if( ( xQueueHandle1 != NULL ) && ( xQueueHandle2 != NULL ) )\r
866         {\r
867                 /* Add both queues to the queue set. */\r
868                 xQueueAddToSet( xQueueHandle1, xQueueSet );\r
869                 xQueueAddToSet( xQueueHandle2, xQueueSet );\r
870 \r
871                 /* Add an item using the first queue using the 'FromISR' version of the\r
872                 overwrite function. */\r
873                 xQueueOverwriteFromISR( xQueueHandle1, ( void * ) &ulValueToSend1, NULL );\r
874                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )\r
875                 {\r
876                         /* Expected one item in the queue set. */\r
877                         xQueueSetTasksStatus = pdFAIL;\r
878                 }\r
879 \r
880                 xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );\r
881                 if( xReceivedHandle != xQueueHandle1 )\r
882                 {\r
883                         /* Wrote to xQueueHandle so expected xQueueHandle to be the handle\r
884                         held in the queue set. */\r
885                         xQueueSetTasksStatus = pdFAIL;\r
886                 }\r
887 \r
888 \r
889                 /* Next add an item to the second queue using the 'FromISR' version of the\r
890                 overwrite function. */\r
891                 xQueueOverwriteFromISR( xQueueHandle2, ( void * ) &ulValueToSend2, NULL );\r
892                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
893                 {\r
894                         /* Expected two items in the queue set. */\r
895                         xQueueSetTasksStatus = pdFAIL;\r
896                 }\r
897 \r
898                 /* The head of the queue set should not have changed though. */\r
899                 xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );\r
900                 if( xReceivedHandle != xQueueHandle1 )\r
901                 {\r
902                         /* Wrote to xQueueHandle so expected xQueueHandle to be the handle\r
903                         held in the queue set. */\r
904                         xQueueSetTasksStatus = pdFAIL;\r
905                 }\r
906 \r
907 \r
908 \r
909 \r
910                 /* Now overwrite the value in the queue and ensure the queue set state\r
911                 doesn't change as the number of items in the queues within the set have\r
912                 not changed.  NOTE:  after this queue 1 should hold ulValueToSend2 and queue\r
913                 2 should hold the value ulValueToSend1. */\r
914                 xQueueOverwriteFromISR( xQueueHandle1, ( void * ) &ulValueToSend2, NULL );\r
915                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
916                 {\r
917                         /* Still expected two items in the queue set. */\r
918                         xQueueSetTasksStatus = pdFAIL;\r
919                 }\r
920                 xQueueOverwriteFromISR( xQueueHandle2, ( void * ) &ulValueToSend1, NULL );\r
921                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
922                 {\r
923                         /* Still expected two items in the queue set. */\r
924                         xQueueSetTasksStatus = pdFAIL;\r
925                 }\r
926 \r
927 \r
928                 /* Repeat the above to ensure the queue set state doesn't change. */\r
929                 xQueueOverwriteFromISR( xQueueHandle1, ( void * ) &ulValueToSend2, NULL );\r
930                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
931                 {\r
932                         /* Still expected two items in the queue set. */\r
933                         xQueueSetTasksStatus = pdFAIL;\r
934                 }\r
935                 xQueueOverwriteFromISR( xQueueHandle2, ( void * ) &ulValueToSend1, NULL );\r
936                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )\r
937                 {\r
938                         /* Still expected two items in the queue set. */\r
939                         xQueueSetTasksStatus = pdFAIL;\r
940                 }\r
941 \r
942 \r
943                 /* Now when reading from the queue set we expect the handle to the first\r
944                 queue to be received first, and for that queue to hold ulValueToSend2 as the\r
945                 originally written value was overwritten.  Likewise the second handle received\r
946                 from the set should be that of the second queue, and that queue should hold\r
947                 ulValueToSend1 as the originally written value was overwritten. */\r
948                 xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
949                 if( xReceivedHandle != xQueueHandle1 )\r
950                 {\r
951                         /* Wrote to xQueueHandle1 first so expected that handle to be read from\r
952                         the set first. */\r
953                         xQueueSetTasksStatus = pdFAIL;\r
954                 }\r
955                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )\r
956                 {\r
957                         /* One value was read from the set, so now only expect a single value\r
958                         in the set. */\r
959                         xQueueSetTasksStatus = pdFAIL;\r
960                 }\r
961                 xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );\r
962                 if( ulValueReceived != ulValueToSend2 )\r
963                 {\r
964                         /* Unexpected value received from the queue.  ulValueToSend1 was written\r
965                         first, but then overwritten with ulValueToSend2; */\r
966                         xQueueSetTasksStatus = pdFAIL;\r
967                 }\r
968 \r
969                 xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
970                 if( xReceivedHandle != xQueueHandle2 )\r
971                 {\r
972                         /* xQueueHandle1 has already been removed from the set so expect only\r
973                         xQueueHandle2 to be left. */\r
974                         xQueueSetTasksStatus = pdFAIL;\r
975                 }\r
976                 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 0 )\r
977                 {\r
978                         /* The last value was read from the set so don't expect any more. */\r
979                         xQueueSetTasksStatus = pdFAIL;\r
980                 }\r
981                 xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );\r
982                 if( ulValueReceived != ulValueToSend1 )\r
983                 {\r
984                         /* Unexpected value received from the queue.  ulValueToSend2 was written\r
985                         first, but then overwritten with ulValueToSend1. */\r
986                         xQueueSetTasksStatus = pdFAIL;\r
987                 }\r
988 \r
989 \r
990 \r
991 \r
992                 /* Should be anything in the queue set now. */\r
993                 xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
994                 if( xReceivedHandle != NULL )\r
995                 {\r
996                         xQueueSetTasksStatus = pdFAIL;\r
997                 }\r
998 \r
999                 /* Clean up. */\r
1000                 xQueueRemoveFromSet( xQueueHandle1, xQueueSet );\r
1001                 xQueueRemoveFromSet( xQueueHandle2, xQueueSet );\r
1002                 vQueueDelete( xQueueHandle1 );\r
1003                 vQueueDelete( xQueueHandle2 );\r
1004         }\r
1005 }\r
1006 /*-----------------------------------------------------------*/\r
1007 \r
1008 static void prvSetupTest( void )\r
1009 {\r
1010 BaseType_t x;\r
1011 uint32_t ulValueToSend = 0;\r
1012 \r
1013         /* Ensure the queues are created and the queue set configured before the\r
1014         sending task is unsuspended.\r
1015 \r
1016         First Create the queue set such that it will be able to hold a message for\r
1017         every space in every queue in the set. */\r
1018         xQueueSet = xQueueCreateSet( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH );\r
1019 \r
1020         for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )\r
1021         {\r
1022                 /* Create the queue and add it to the set.  The queue is just holding\r
1023                 uint32_t value. */\r
1024                 xQueues[ x ] = xQueueCreate( queuesetQUEUE_LENGTH, sizeof( uint32_t ) );\r
1025                 configASSERT( xQueues[ x ] );\r
1026                 if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdPASS )\r
1027                 {\r
1028                         xQueueSetTasksStatus = pdFAIL;\r
1029                 }\r
1030                 else\r
1031                 {\r
1032                         /* The queue has now been added to the queue set and cannot be added to\r
1033                         another. */\r
1034                         if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdFAIL )\r
1035                         {\r
1036                                 xQueueSetTasksStatus = pdFAIL;\r
1037                         }\r
1038                 }\r
1039         }\r
1040 \r
1041         /* Attempt to remove a queue from a queue set it does not belong\r
1042         to (NULL being passed as the queue set in this case). */\r
1043         if( xQueueRemoveFromSet( xQueues[ 0 ], NULL ) != pdFAIL )\r
1044         {\r
1045                 /* It is not possible to successfully remove a queue from a queue\r
1046                 set it does not belong to. */\r
1047                 xQueueSetTasksStatus = pdFAIL;\r
1048         }\r
1049 \r
1050         /* Attempt to remove a queue from the queue set it does belong to. */\r
1051         if( xQueueRemoveFromSet( xQueues[ 0 ], xQueueSet ) != pdPASS )\r
1052         {\r
1053                 /* It should be possible to remove the queue from the queue set it\r
1054                 does belong to. */\r
1055                 xQueueSetTasksStatus = pdFAIL;\r
1056         }\r
1057 \r
1058         /* Add an item to the queue before attempting to add it back into the\r
1059         set. */\r
1060         xQueueSend( xQueues[ 0 ], ( void * ) &ulValueToSend, 0 );\r
1061         if( xQueueAddToSet( xQueues[ 0 ], xQueueSet ) != pdFAIL )\r
1062         {\r
1063                 /* Should not be able to add a non-empty queue to a set. */\r
1064                 xQueueSetTasksStatus = pdFAIL;\r
1065         }\r
1066 \r
1067         /* Remove the item from the queue before adding the queue back into the\r
1068         set so the dynamic tests can begin. */\r
1069         xQueueReceive( xQueues[ 0 ], &ulValueToSend, 0 );\r
1070         if( xQueueAddToSet( xQueues[ 0 ], xQueueSet ) != pdPASS )\r
1071         {\r
1072                 /* If the queue was successfully removed from the queue set then it\r
1073                 should be possible to add it back in again. */\r
1074                 xQueueSetTasksStatus = pdFAIL;\r
1075         }\r
1076 \r
1077         /* The task that sends to the queues is not running yet, so attempting to\r
1078         read from the queue set should fail. */\r
1079         if( xQueueSelectFromSet( xQueueSet, queuesetSHORT_DELAY ) != NULL )\r
1080         {\r
1081                 xQueueSetTasksStatus = pdFAIL;\r
1082         }\r
1083 \r
1084         /* Testing the behaviour of queue sets when a queue overwrite operation is\r
1085         performed on a set member requires a special test as overwrites can only\r
1086         be performed on queues that have a length of 1. */\r
1087         prvTestQueueOverwriteWithQueueSet();\r
1088 \r
1089         /* Test the case where two queues within a set are written to with\r
1090         xQueueOverwrite(). */\r
1091         prvTestQueueOverwriteOnTwoQueusInQueueSet();\r
1092         prvTestQueueOverwriteFromISROnTwoQueusInQueueSet();\r
1093 \r
1094         /* In case any of the above have already indicated a failure. */\r
1095         configASSERT( xQueueSetTasksStatus != pdFAIL );\r
1096 \r
1097         /* Resume the task that writes to the queues. */\r
1098         vTaskResume( xQueueSetSendingTask );\r
1099 \r
1100         /* Let the ISR access the queues also. */\r
1101         xSetupComplete = pdTRUE;\r
1102 }\r
1103 /*-----------------------------------------------------------*/\r
1104 \r
1105 static size_t prvRand( void )\r
1106 {\r
1107         uxNextRand = ( uxNextRand * ( size_t ) 1103515245 ) + ( size_t ) 12345;\r
1108         return ( uxNextRand / ( size_t ) 65536 ) % ( size_t ) 32768;\r
1109 }\r
1110 /*-----------------------------------------------------------*/\r
1111 \r
1112 static void prvSRand( size_t uxSeed )\r
1113 {\r
1114         uxNextRand = uxSeed;\r
1115 }\r
1116 \r
1117 #endif /* ( configUSE_QUEUE_SETS == 1 ) */\r