]> begriffs open source - cmsis-freertos/blob - Test/CMock/queue/generic/queue_receive_blocking_utest.c
Updated pack to FreeRTOS 10.4.6
[cmsis-freertos] / Test / CMock / queue / generic / queue_receive_blocking_utest.c
1 /*
2  * FreeRTOS V202111.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * https://www.FreeRTOS.org
23  * https://github.com/FreeRTOS
24  *
25  */
26 /*! @file queue_receive_blocking_utest.c */
27
28 /* C runtime includes. */
29 #include <stdlib.h>
30 #include <stdbool.h>
31 #include <string.h>
32
33 #include "../queue_utest_common.h"
34
35 /* Queue includes */
36 #include "FreeRTOS.h"
37 #include "FreeRTOSConfig.h"
38 #include "queue.h"
39 #include "mock_fake_port.h"
40 /* ============================  GLOBAL VARIABLES =========================== */
41
42 /* Used to share a QueueHandle_t between a test case and it's callbacks */
43 static QueueHandle_t xQueueHandleStatic;
44
45 /* ==========================  CALLBACK FUNCTIONS =========================== */
46
47 /* ============================= Unity Fixtures ============================= */
48
49 void setUp( void )
50 {
51     commonSetUp();
52     vFakePortAssertIfInterruptPriorityInvalid_Ignore();
53     xQueueHandleStatic = NULL;
54 }
55
56 void tearDown( void )
57 {
58     commonTearDown();
59 }
60
61 void suiteSetUp()
62 {
63     commonSuiteSetUp();
64 }
65
66 int suiteTearDown( int numFailures )
67 {
68     return commonSuiteTearDown( numFailures );
69 }
70
71 /* ==========================  Helper functions =========================== */
72
73 /* =============================  Test Cases ============================== */
74
75 /**
76  *  @brief Callback for test_xQueueReceive_blocking_success_locked_no_pending
77  *  which adds an item to it's test queue.
78  */
79 static BaseType_t xQueueReceive_xTaskCheckForTimeOutCB( TimeOut_t * const pxTimeOut,
80                                                         TickType_t * const pxTicksToWait,
81                                                         int cmock_num_calls )
82 {
83     BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
84
85     if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
86     {
87         uint32_t testVal = getNextMonotonicTestValue();
88         TEST_ASSERT_TRUE( xQueueSendFromISR( xQueueHandleStatic, &testVal, NULL ) );
89         TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueueHandleStatic ) );
90     }
91
92     return xReturnValue;
93 }
94
95 /**
96  *  @brief Test a blocking call to xQueueReceive with a locked queue.
97  *  @details Test a blocking call to xQueueReceive with a locked queue with no
98  *  tasks in the queue WaitingToReceiveFrom event list.
99  *  @coverage xQueueReceive prvUnlockQueue
100  */
101 void test_xQueueReceive_blocking_success_locked_no_pending( void )
102 {
103     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
104
105     /* Export for callbacks */
106     xQueueHandleStatic = xQueue;
107
108     xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
109     xTaskResumeAll_Stub( &td_task_xTaskResumeAllStub );
110
111     uint32_t checkVal = INVALID_UINT32;
112
113     TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
114
115     TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
116
117     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
118
119     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
120
121     TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
122
123     vQueueDelete( xQueue );
124 }
125
126 /**
127  *  @brief Test a blocking call to xQueuePeek with a locked queue.
128  *  @details Test a blocking call to xQueuePeek with a locked queue with no tasks
129  *  in the queue WaitingToReceiveFrom event list.
130  *  @coverage xQueuePeek prvUnlockQueue
131  */
132 void test_xQueuePeek_blocking_success_locked_no_pending( void )
133 {
134     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
135
136     /* Export for callbacks */
137     xQueueHandleStatic = xQueue;
138
139     xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
140     xTaskResumeAll_Stub( &td_task_xTaskResumeAllStub );
141
142     uint32_t checkVal = INVALID_UINT32;
143
144     TEST_ASSERT_EQUAL( pdTRUE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
145
146     TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
147
148     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
149
150     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
151
152     TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
153
154     vQueueDelete( xQueue );
155 }
156
157 /**
158  * @brief Callback for xTaskResumeAll used by tests for blocking calls to
159  * xQueueReceive and xQueuePeek
160  */
161 static BaseType_t xQueueReceive_xTaskResumeAllCallback( int cmock_num_calls )
162 {
163     BaseType_t xReturnValue = td_task_xTaskResumeAllStub( cmock_num_calls );
164
165     /* If td_task_xTaskResumeAllStub returns pdTRUE, a higher priority task is pending
166      * Receive from an ISR to block */
167     if( pdTRUE == xReturnValue )
168     {
169         if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
170         {
171             uint32_t checkValue = INVALID_UINT32;
172             TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueueHandleStatic ) );
173             TEST_ASSERT_TRUE( xQueueReceiveFromISR( xQueueHandleStatic, &checkValue, NULL ) );
174             TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkValue );
175         }
176     }
177
178     return xReturnValue;
179 }
180
181 /**
182  *  @brief Test a blocking call to xQueueReceive with a locked queue.
183  *  @details Test a blocking call to xQueueReceive with a locked queue with a
184  *  higher priority task in the queue WaitingToReceiveFrom event list.
185  *  @coverage xQueueReceive prvUnlockQueue
186  */
187 void test_xQueueReceive_blocking_timeout_locked_high_prio_pending( void )
188 {
189     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
190
191     /* Export for callbacks */
192     xQueueHandleStatic = xQueue;
193
194     xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
195     xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback );
196
197     td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
198
199     td_task_addFakeTaskWaitingToReceiveFromQueue( xQueue );
200
201     uint32_t checkVal = INVALID_UINT32;
202
203     TEST_ASSERT_EQUAL( pdFALSE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
204
205     TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
206
207     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
208
209     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT + 1, td_task_getCount_YieldFromTaskResumeAll() );
210
211     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT - 1, td_task_getCount_vPortYieldWithinAPI() );
212
213     TEST_ASSERT_EQUAL( 1, td_task_getCount_vTaskMissedYield() );
214
215     TEST_ASSERT_EQUAL( INVALID_UINT32, checkVal );
216
217     vQueueDelete( xQueue );
218 }
219
220 /**
221  *  @brief Test a blocking call to xQueuePeek with a locked queue.
222  *  @details Test a blocking call to xQueuePeek with a locked queue with a
223  *  higher priority task in the queue WaitingToReceiveFrom event list.
224  *  @coverage xQueuePeek prvUnlockQueue
225  */
226 void test_xQueuePeek_blocking_timeout_locked_high_prio_pending( void )
227 {
228     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
229
230     /* Export for callbacks */
231     xQueueHandleStatic = xQueue;
232
233     xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
234     xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback );
235
236     td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
237
238     td_task_addFakeTaskWaitingToReceiveFromQueue( xQueue );
239
240     uint32_t checkVal = INVALID_UINT32;
241
242     TEST_ASSERT_EQUAL( pdFALSE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
243
244     TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
245
246     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
247
248     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT + 1, td_task_getCount_YieldFromTaskResumeAll() );
249
250     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT - 1, td_task_getCount_vPortYieldWithinAPI() );
251
252     TEST_ASSERT_EQUAL( 1, td_task_getCount_vTaskMissedYield() );
253
254     TEST_ASSERT_EQUAL( INVALID_UINT32, checkVal );
255
256     vQueueDelete( xQueue );
257 }
258
259 /**
260  *  @brief Test a blocking call to xQueueReceive with a locked queue.
261  *  @details Test a blocking call to xQueueReceive with a locked queue with a
262  *  lower priority task in the queue WaitingToReceiveFrom event list.
263  *  @coverage xQueueReceive prvUnlockQueue
264  */
265 void test_xQueueReceive_blocking_success_locked_low_prio_pending( void )
266 {
267     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
268
269     /* Export for callbacks */
270     xQueueHandleStatic = xQueue;
271
272     xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
273     xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback );
274
275     td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
276
277     td_task_addFakeTaskWaitingToReceiveFromQueue( xQueue );
278
279     uint32_t checkVal = INVALID_UINT32;
280
281     TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
282
283     TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
284
285     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
286
287     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
288
289     TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
290
291     vQueueDelete( xQueue );
292 }
293
294 /**
295  *  @brief Test a blocking call to xQueuePeek with a locked queue.
296  *  @details Test a blocking call to xQueuePeek with a locked queue with a
297  *  lower priority task in the queue WaitingToReceiveFrom event list.
298  *  @coverage xQueuePeek prvUnlockQueue
299  */
300 void test_xQueuePeek_blocking_success_locked_low_prio_pending( void )
301 {
302     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
303
304     /* Export for callbacks */
305     xQueueHandleStatic = xQueue;
306
307     xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
308     xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback );
309
310     td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
311
312     td_task_addFakeTaskWaitingToReceiveFromQueue( xQueue );
313
314     uint32_t checkVal = INVALID_UINT32;
315
316     TEST_ASSERT_EQUAL( pdTRUE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
317
318     TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
319
320     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
321
322     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
323
324     TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
325
326     vQueueDelete( xQueue );
327 }
328
329 /**
330  *  @brief Test xQueuePeek with taskSCHEDULER_SUSPENDED and timeout=10
331  *  @details This should cause xQueuePeek to configASSERT because it would
332  *  block forever when the queue is empty.
333  *  @coverage xQueuePeek
334  */
335 void test_xQueuePeek_blocking_suspended_assert( void )
336 {
337     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
338
339     td_task_setSchedulerState( taskSCHEDULER_SUSPENDED );
340
341     vTaskSuspendAll_Stub( td_task_vTaskSuspendAllStubNoCheck );
342
343     uint32_t checkVal = INVALID_UINT32;
344
345     fakeAssertExpectFail();
346
347     TEST_ASSERT_EQUAL( pdFALSE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
348
349     TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
350
351     TEST_ASSERT_EQUAL( pdTRUE, fakeAssertGetFlagAndClear() );
352
353     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
354
355     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
356
357     td_task_setSchedulerState( taskSCHEDULER_RUNNING );
358
359     vQueueDelete( xQueue );
360 }
361
362 /**
363  *  @brief Callback which adds and item to it's test queue.
364  *  @details Used in test_xQueuePeek_blocking_success and test_xQueueReceive_blocking_success.
365  */
366 static BaseType_t blocking_success_xTaskCheckForTimeOut_cb( TimeOut_t * const pxTimeOut,
367                                                             TickType_t * const pxTicksToWait,
368                                                             int cmock_num_calls )
369 {
370     BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
371
372     if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
373     {
374         uint32_t testVal = getNextMonotonicTestValue();
375         xQueueSend( xQueueHandleStatic, &testVal, 0 );
376         TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueueHandleStatic ) );
377     }
378
379     return xReturnValue;
380 }
381
382 /**
383  * @brief Test xQueuePeek in blocking mode with a queue that is initially empty,
384  * but later becomes full.
385  * @coverage xQueuePeek
386  */
387 void test_xQueuePeek_blocking_success( void )
388 {
389     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
390
391     /* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
392     xQueueHandleStatic = xQueue;
393
394     xTaskCheckForTimeOut_Stub( &blocking_success_xTaskCheckForTimeOut_cb );
395
396     uint32_t checkVal = INVALID_UINT32;
397
398     TEST_ASSERT_EQUAL( pdTRUE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
399
400     TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
401
402     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
403
404     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
405
406     TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
407     vQueueDelete( xQueue );
408 }
409
410 /**
411  *  @brief Callback which adds and item to it's test queue.
412  *  @details used in test_xQueuePeek_blocking_success_last_chance and
413  *  test_xQueueReceive_blocking_success_last_chance.
414  */
415 static BaseType_t blocking_success_last_chance_xTaskCheckForTimeOut_cb( TimeOut_t * const pxTimeOut,
416                                                                         TickType_t * const pxTicksToWait,
417                                                                         int cmock_num_calls )
418 {
419     BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
420
421     if( cmock_num_calls == TICKS_TO_WAIT )
422     {
423         uint32_t testVal = getNextMonotonicTestValue();
424         xQueueSend( xQueueHandleStatic, &testVal, 0 );
425     }
426
427     return xReturnValue;
428 }
429
430 /**
431  * @brief Test xQueuePeek in blocking mode with a queue that is initially empty,
432  * but becomes full right before the last chance to remove data from the queue.
433  * @coverage xQueuePeek
434  */
435 void test_xQueuePeek_blocking_success_last_chance( void )
436 {
437     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
438
439     /* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
440     xQueueHandleStatic = xQueue;
441
442     xTaskCheckForTimeOut_Stub( &blocking_success_last_chance_xTaskCheckForTimeOut_cb );
443
444     uint32_t checkVal = INVALID_UINT32;
445
446     TEST_ASSERT_EQUAL( pdTRUE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
447
448     TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
449
450     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
451
452     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
453
454     TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
455
456     vQueueDelete( xQueue );
457 }
458
459 /**
460  * @brief Test xQueuePeek in blocking mode with an empty queue.
461  * @coverage xQueuePeek
462  */
463 void test_xQueuePeek_blocking_timeout( void )
464 {
465     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
466
467     uint32_t checkVal = INVALID_UINT32;
468
469     TEST_ASSERT_EQUAL( pdFALSE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
470
471     TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
472
473     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
474
475     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
476
477     vQueueDelete( xQueue );
478 }
479
480 /**
481  *  @brief Test xQueueReceive with taskSCHEDULER_SUSPENDED and timeout=10
482  *  @details This should cause xQueueReceive to configASSERT because it would
483  *  block forever when the queue is empty.
484  *  @coverage xQueueReceive
485  */
486 void test_xQueueReceive_blocking_suspended_assert( void )
487 {
488     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
489
490     uint32_t checkVal = INVALID_UINT32;
491
492     fakeAssertExpectFail();
493
494     td_task_setSchedulerState( taskSCHEDULER_SUSPENDED );
495
496     vTaskSuspendAll_Stub( td_task_vTaskSuspendAllStubNoCheck );
497
498     TEST_ASSERT_EQUAL( pdFALSE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
499
500     TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
501
502     TEST_ASSERT_EQUAL( pdTRUE, fakeAssertGetFlagAndClear() );
503
504     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
505
506     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
507
508     td_task_setSchedulerState( taskSCHEDULER_RUNNING );
509
510     vQueueDelete( xQueue );
511 }
512
513 /**
514  * @brief Test xQueueReceive in blocking mode with an occupied queue
515  * @coverage xQueueReceive
516  */
517 void test_xQueueReceive_blocking_success( void )
518 {
519     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
520
521     /* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
522     xQueueHandleStatic = xQueue;
523
524     xTaskCheckForTimeOut_Stub( &blocking_success_xTaskCheckForTimeOut_cb );
525
526     uint32_t checkVal = INVALID_UINT32;
527
528     TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
529
530     TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
531
532     TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
533
534     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
535
536     TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
537
538     vQueueDelete( xQueue );
539 }
540
541
542 /**
543  * @brief Test xQueueReceive in blocking mode with a queue that is initially empty,
544  * but becomes full right before the last chance to remove data from the queue.
545  * @coverage xQueueReceive
546  */
547 void test_xQueueReceive_blocking_success_last_chance( void )
548 {
549     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
550
551     /* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
552     xQueueHandleStatic = xQueue;
553
554     xTaskCheckForTimeOut_Stub( &blocking_success_last_chance_xTaskCheckForTimeOut_cb );
555
556     uint32_t checkVal = INVALID_UINT32;
557
558     TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
559
560     TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
561
562     TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
563
564     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
565
566     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
567
568     vQueueDelete( xQueue );
569 }
570
571 /**
572  * @brief Test xQueueReceive in blocking mode with an empty queue
573  * @coverage xQueueReceive
574  */
575 void test_xQueueReceive_blocking_timeout( void )
576 {
577     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
578
579     uint32_t checkVal = INVALID_UINT32;
580
581     TEST_ASSERT_EQUAL( pdFALSE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
582
583     TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
584
585     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
586
587     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
588
589     vQueueDelete( xQueue );
590 }
591
592 /**
593  * @brief Test xQueueReceive in blocking mode with an empty locked queue.
594  * @details This test case verifies a situation that should never occur
595  * ( xQueueReceive called on a locked queue ).
596  * @coverage xQueueReceive
597  */
598 void test_xQueueReceive_blocking_locked( void )
599 {
600     /* Create a new binary Queue */
601     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
602
603     /* Set private lock counters */
604     vSetQueueRxLock( xQueue, queueLOCKED_UNMODIFIED );
605     vSetQueueTxLock( xQueue, queueLOCKED_UNMODIFIED );
606
607     uint32_t checkVal = INVALID_UINT32;
608
609     /* Run xQueueReceive in blocking mode with the queue locked */
610     TEST_ASSERT_EQUAL( pdFALSE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
611
612     TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
613
614     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
615
616     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
617
618     /* Verify that the queue is now unlocked */
619     TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueRxLock( xQueue ) );
620     TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueTxLock( xQueue ) );
621
622     vQueueDelete( xQueue );
623 }
624
625 /**
626  * @brief Test xQueuePeek in blocking mode with an empty locked queue.
627  * @details This test case verifies a situation that should never occur
628  * ( xQueuePeek called on a locked queue ).
629  * @coverage xQueuePeek
630  */
631 void test_xQueuePeek_blocking_locked( void )
632 {
633     /* Create a new binary Queue */
634     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
635
636     /* Set private lock counters */
637     vSetQueueRxLock( xQueue, queueLOCKED_UNMODIFIED );
638     vSetQueueTxLock( xQueue, queueLOCKED_UNMODIFIED );
639
640     uint32_t checkVal = INVALID_UINT32;
641
642     /* Run xQueueReceive in blocking mode with the queue locked */
643     TEST_ASSERT_EQUAL( pdFALSE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
644
645
646
647     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
648
649     TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
650
651     /* Verify that the queue is now unlocked */
652     TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueRxLock( xQueue ) );
653     TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueTxLock( xQueue ) );
654
655     vQueueDelete( xQueue );
656 }