3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
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.
22 * https://www.FreeRTOS.org
23 * https://github.com/FreeRTOS
26 /*! @file queue_receive_blocking_utest.c */
28 /* C runtime includes. */
33 #include "../queue_utest_common.h"
37 #include "FreeRTOSConfig.h"
39 #include "mock_fake_port.h"
40 /* ============================ GLOBAL VARIABLES =========================== */
42 /* Used to share a QueueHandle_t between a test case and it's callbacks */
43 static QueueHandle_t xQueueHandleStatic;
45 /* ========================== CALLBACK FUNCTIONS =========================== */
47 /* ============================= Unity Fixtures ============================= */
52 vFakePortAssertIfInterruptPriorityInvalid_Ignore();
53 xQueueHandleStatic = NULL;
66 int suiteTearDown( int numFailures )
68 return commonSuiteTearDown( numFailures );
71 /* ========================== Helper functions =========================== */
73 /* ============================= Test Cases ============================== */
76 * @brief Callback for test_xQueueReceive_blocking_success_locked_no_pending
77 * which adds an item to it's test queue.
79 static BaseType_t xQueueReceive_xTaskCheckForTimeOutCB( TimeOut_t * const pxTimeOut,
80 TickType_t * const pxTicksToWait,
83 BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
85 if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
87 uint32_t testVal = getNextMonotonicTestValue();
88 TEST_ASSERT_TRUE( xQueueSendFromISR( xQueueHandleStatic, &testVal, NULL ) );
89 TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueueHandleStatic ) );
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
101 void test_xQueueReceive_blocking_success_locked_no_pending( void )
103 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
105 /* Export for callbacks */
106 xQueueHandleStatic = xQueue;
108 xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
109 xTaskResumeAll_Stub( &td_task_xTaskResumeAllStub );
111 uint32_t checkVal = INVALID_UINT32;
113 TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
115 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
117 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
119 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
121 TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
123 vQueueDelete( xQueue );
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
132 void test_xQueuePeek_blocking_success_locked_no_pending( void )
134 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
136 /* Export for callbacks */
137 xQueueHandleStatic = xQueue;
139 xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
140 xTaskResumeAll_Stub( &td_task_xTaskResumeAllStub );
142 uint32_t checkVal = INVALID_UINT32;
144 TEST_ASSERT_EQUAL( pdTRUE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
146 TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
148 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
150 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
152 TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
154 vQueueDelete( xQueue );
158 * @brief Callback for xTaskResumeAll used by tests for blocking calls to
159 * xQueueReceive and xQueuePeek
161 static BaseType_t xQueueReceive_xTaskResumeAllCallback( int cmock_num_calls )
163 BaseType_t xReturnValue = td_task_xTaskResumeAllStub( cmock_num_calls );
165 /* If td_task_xTaskResumeAllStub returns pdTRUE, a higher priority task is pending
166 * Receive from an ISR to block */
167 if( pdTRUE == xReturnValue )
169 if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
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 );
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
187 void test_xQueueReceive_blocking_timeout_locked_high_prio_pending( void )
189 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
191 /* Export for callbacks */
192 xQueueHandleStatic = xQueue;
194 xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
195 xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback );
197 td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
199 td_task_addFakeTaskWaitingToReceiveFromQueue( xQueue );
201 uint32_t checkVal = INVALID_UINT32;
203 TEST_ASSERT_EQUAL( pdFALSE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
205 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
207 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
209 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT + 1, td_task_getCount_YieldFromTaskResumeAll() );
211 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT - 1, td_task_getCount_vPortYieldWithinAPI() );
213 TEST_ASSERT_EQUAL( 1, td_task_getCount_vTaskMissedYield() );
215 TEST_ASSERT_EQUAL( INVALID_UINT32, checkVal );
217 vQueueDelete( xQueue );
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
226 void test_xQueuePeek_blocking_timeout_locked_high_prio_pending( void )
228 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
230 /* Export for callbacks */
231 xQueueHandleStatic = xQueue;
233 xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
234 xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback );
236 td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
238 td_task_addFakeTaskWaitingToReceiveFromQueue( xQueue );
240 uint32_t checkVal = INVALID_UINT32;
242 TEST_ASSERT_EQUAL( pdFALSE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
244 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
246 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
248 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT + 1, td_task_getCount_YieldFromTaskResumeAll() );
250 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT - 1, td_task_getCount_vPortYieldWithinAPI() );
252 TEST_ASSERT_EQUAL( 1, td_task_getCount_vTaskMissedYield() );
254 TEST_ASSERT_EQUAL( INVALID_UINT32, checkVal );
256 vQueueDelete( xQueue );
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
265 void test_xQueueReceive_blocking_success_locked_low_prio_pending( void )
267 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
269 /* Export for callbacks */
270 xQueueHandleStatic = xQueue;
272 xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
273 xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback );
275 td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
277 td_task_addFakeTaskWaitingToReceiveFromQueue( xQueue );
279 uint32_t checkVal = INVALID_UINT32;
281 TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
283 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
285 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
287 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
289 TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
291 vQueueDelete( xQueue );
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
300 void test_xQueuePeek_blocking_success_locked_low_prio_pending( void )
302 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
304 /* Export for callbacks */
305 xQueueHandleStatic = xQueue;
307 xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
308 xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback );
310 td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
312 td_task_addFakeTaskWaitingToReceiveFromQueue( xQueue );
314 uint32_t checkVal = INVALID_UINT32;
316 TEST_ASSERT_EQUAL( pdTRUE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
318 TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
320 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
322 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
324 TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
326 vQueueDelete( xQueue );
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
335 void test_xQueuePeek_blocking_suspended_assert( void )
337 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
339 td_task_setSchedulerState( taskSCHEDULER_SUSPENDED );
341 vTaskSuspendAll_Stub( td_task_vTaskSuspendAllStubNoCheck );
343 uint32_t checkVal = INVALID_UINT32;
345 fakeAssertExpectFail();
347 TEST_ASSERT_EQUAL( pdFALSE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
349 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
351 TEST_ASSERT_EQUAL( pdTRUE, fakeAssertGetFlagAndClear() );
353 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
355 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
357 td_task_setSchedulerState( taskSCHEDULER_RUNNING );
359 vQueueDelete( xQueue );
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.
366 static BaseType_t blocking_success_xTaskCheckForTimeOut_cb( TimeOut_t * const pxTimeOut,
367 TickType_t * const pxTicksToWait,
368 int cmock_num_calls )
370 BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
372 if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
374 uint32_t testVal = getNextMonotonicTestValue();
375 xQueueSend( xQueueHandleStatic, &testVal, 0 );
376 TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueueHandleStatic ) );
383 * @brief Test xQueuePeek in blocking mode with a queue that is initially empty,
384 * but later becomes full.
385 * @coverage xQueuePeek
387 void test_xQueuePeek_blocking_success( void )
389 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
391 /* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
392 xQueueHandleStatic = xQueue;
394 xTaskCheckForTimeOut_Stub( &blocking_success_xTaskCheckForTimeOut_cb );
396 uint32_t checkVal = INVALID_UINT32;
398 TEST_ASSERT_EQUAL( pdTRUE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
400 TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
402 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
404 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
406 TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
407 vQueueDelete( xQueue );
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.
415 static BaseType_t blocking_success_last_chance_xTaskCheckForTimeOut_cb( TimeOut_t * const pxTimeOut,
416 TickType_t * const pxTicksToWait,
417 int cmock_num_calls )
419 BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
421 if( cmock_num_calls == TICKS_TO_WAIT )
423 uint32_t testVal = getNextMonotonicTestValue();
424 xQueueSend( xQueueHandleStatic, &testVal, 0 );
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
435 void test_xQueuePeek_blocking_success_last_chance( void )
437 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
439 /* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
440 xQueueHandleStatic = xQueue;
442 xTaskCheckForTimeOut_Stub( &blocking_success_last_chance_xTaskCheckForTimeOut_cb );
444 uint32_t checkVal = INVALID_UINT32;
446 TEST_ASSERT_EQUAL( pdTRUE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
448 TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
450 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
452 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
454 TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
456 vQueueDelete( xQueue );
460 * @brief Test xQueuePeek in blocking mode with an empty queue.
461 * @coverage xQueuePeek
463 void test_xQueuePeek_blocking_timeout( void )
465 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
467 uint32_t checkVal = INVALID_UINT32;
469 TEST_ASSERT_EQUAL( pdFALSE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
471 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
473 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
475 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
477 vQueueDelete( xQueue );
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
486 void test_xQueueReceive_blocking_suspended_assert( void )
488 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
490 uint32_t checkVal = INVALID_UINT32;
492 fakeAssertExpectFail();
494 td_task_setSchedulerState( taskSCHEDULER_SUSPENDED );
496 vTaskSuspendAll_Stub( td_task_vTaskSuspendAllStubNoCheck );
498 TEST_ASSERT_EQUAL( pdFALSE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
500 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
502 TEST_ASSERT_EQUAL( pdTRUE, fakeAssertGetFlagAndClear() );
504 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
506 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
508 td_task_setSchedulerState( taskSCHEDULER_RUNNING );
510 vQueueDelete( xQueue );
514 * @brief Test xQueueReceive in blocking mode with an occupied queue
515 * @coverage xQueueReceive
517 void test_xQueueReceive_blocking_success( void )
519 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
521 /* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
522 xQueueHandleStatic = xQueue;
524 xTaskCheckForTimeOut_Stub( &blocking_success_xTaskCheckForTimeOut_cb );
526 uint32_t checkVal = INVALID_UINT32;
528 TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
530 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
532 TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
534 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
536 TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
538 vQueueDelete( xQueue );
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
547 void test_xQueueReceive_blocking_success_last_chance( void )
549 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
551 /* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
552 xQueueHandleStatic = xQueue;
554 xTaskCheckForTimeOut_Stub( &blocking_success_last_chance_xTaskCheckForTimeOut_cb );
556 uint32_t checkVal = INVALID_UINT32;
558 TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
560 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
562 TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
564 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
566 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
568 vQueueDelete( xQueue );
572 * @brief Test xQueueReceive in blocking mode with an empty queue
573 * @coverage xQueueReceive
575 void test_xQueueReceive_blocking_timeout( void )
577 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
579 uint32_t checkVal = INVALID_UINT32;
581 TEST_ASSERT_EQUAL( pdFALSE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
583 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
585 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
587 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
589 vQueueDelete( xQueue );
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
598 void test_xQueueReceive_blocking_locked( void )
600 /* Create a new binary Queue */
601 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
603 /* Set private lock counters */
604 vSetQueueRxLock( xQueue, queueLOCKED_UNMODIFIED );
605 vSetQueueTxLock( xQueue, queueLOCKED_UNMODIFIED );
607 uint32_t checkVal = INVALID_UINT32;
609 /* Run xQueueReceive in blocking mode with the queue locked */
610 TEST_ASSERT_EQUAL( pdFALSE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
612 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
614 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
616 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
618 /* Verify that the queue is now unlocked */
619 TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueRxLock( xQueue ) );
620 TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueTxLock( xQueue ) );
622 vQueueDelete( xQueue );
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
631 void test_xQueuePeek_blocking_locked( void )
633 /* Create a new binary Queue */
634 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
636 /* Set private lock counters */
637 vSetQueueRxLock( xQueue, queueLOCKED_UNMODIFIED );
638 vSetQueueTxLock( xQueue, queueLOCKED_UNMODIFIED );
640 uint32_t checkVal = INVALID_UINT32;
642 /* Run xQueueReceive in blocking mode with the queue locked */
643 TEST_ASSERT_EQUAL( pdFALSE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
647 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
649 TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
651 /* Verify that the queue is now unlocked */
652 TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueRxLock( xQueue ) );
653 TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueTxLock( xQueue ) );
655 vQueueDelete( xQueue );