diff --git a/FreeRTOS/Test/CMock/queue/generic/queue_receive_nonblocking_utest.c b/FreeRTOS/Test/CMock/queue/generic/queue_receive_nonblocking_utest.c index f53ec5168..21ae68a3d 100644 --- a/FreeRTOS/Test/CMock/queue/generic/queue_receive_nonblocking_utest.c +++ b/FreeRTOS/Test/CMock/queue/generic/queue_receive_nonblocking_utest.c @@ -994,11 +994,12 @@ void test_xQueueReceiveFromISR_success( void ) void test_xQueueReceiveFromISR_locked( void ) { /* Create a new queue */ - QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) ); + QueueHandle_t xQueue = xQueueCreate( 2, sizeof( uint32_t ) ); /* Send a test value so the queue is not empty */ uint32_t testVal = getNextMonotonicTestValue(); + ( void ) xQueueSend( xQueue, &testVal, 0 ); ( void ) xQueueSend( xQueue, &testVal, 0 ); uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 ); @@ -1007,16 +1008,19 @@ void test_xQueueReceiveFromISR_locked( void ) vSetQueueRxLock( xQueue, queueLOCKED_UNMODIFIED ); vSetQueueTxLock( xQueue, queueLOCKED_UNMODIFIED ); - TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) ); + TEST_ASSERT_EQUAL( 2, uxQueueMessagesWaiting( xQueue ) ); uint32_t checkVal = INVALID_UINT32; /* Run xQueueReceiveFromISR with the queue locked */ TEST_ASSERT_EQUAL( pdTRUE, xQueueReceiveFromISR( xQueue, &checkVal, NULL ) ); + TEST_ASSERT_EQUAL( pdTRUE, xQueueReceiveFromISR( xQueue, &checkVal, NULL ) ); TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) ); - /* Verify that the cRxLock counter has been incremented */ + /* Verify that the cRxLock counter has only been incremented by one + * even after 2 calls to xQueueReceiveFromISR because there is only + * one task in the system as returned from uxTaskGetNumberOfTasks. */ TEST_ASSERT_EQUAL( queueLOCKED_UNMODIFIED + 1, cGetQueueRxLock( xQueue ) ); /* Verify that the cTxLock counter has not changed */ diff --git a/FreeRTOS/Test/CMock/queue/generic/queue_send_nonblocking_utest.c b/FreeRTOS/Test/CMock/queue/generic/queue_send_nonblocking_utest.c index 998dc49d9..1bedf4591 100644 --- a/FreeRTOS/Test/CMock/queue/generic/queue_send_nonblocking_utest.c +++ b/FreeRTOS/Test/CMock/queue/generic/queue_send_nonblocking_utest.c @@ -597,12 +597,13 @@ void test_macro_xQueueSendFromISR_task_waiting_lower_priority_success( void ) */ void test_macro_xQueueSendFromISR_locked( void ) { - QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) ); + QueueHandle_t xQueue = xQueueCreate( 2, sizeof( uint32_t ) ); /* Set private lock counters */ vSetQueueRxLock( xQueue, queueLOCKED_UNMODIFIED ); vSetQueueTxLock( xQueue, queueLOCKED_UNMODIFIED ); + vFakePortAssertIfInterruptPriorityInvalid_Expect(); vFakePortAssertIfInterruptPriorityInvalid_Expect(); uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 ); @@ -610,21 +611,27 @@ void test_macro_xQueueSendFromISR_locked( void ) TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) ); + TEST_ASSERT_EQUAL( pdTRUE, xQueueSendFromISR( xQueue, &testval, NULL ) ); TEST_ASSERT_EQUAL( pdTRUE, xQueueSendFromISR( xQueue, &testval, NULL ) ); - TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) ); + TEST_ASSERT_EQUAL( 2, uxQueueMessagesWaiting( xQueue ) ); /* Verify that the cRxLock counter has not changed */ TEST_ASSERT_EQUAL( queueLOCKED_UNMODIFIED, cGetQueueRxLock( xQueue ) ); - /* Verify that the cTxLock counter has been incremented */ + /* Verify that the cTxLock counter has only been incremented by one + * even after 2 calls to xQueueSendFromISR because there is only + * one task in the system as returned from uxTaskGetNumberOfTasks. */ TEST_ASSERT_EQUAL( queueLOCKED_UNMODIFIED + 1, cGetQueueTxLock( xQueue ) ); uint32_t checkVal = INVALID_UINT32; ( void ) xQueueReceive( xQueue, &checkVal, 0 ); - TEST_ASSERT_EQUAL( testval, checkVal ); + + ( void ) xQueueReceive( xQueue, &checkVal, 0 ); + TEST_ASSERT_EQUAL( testval, checkVal ); + vQueueDelete( xQueue ); } diff --git a/FreeRTOS/Test/CMock/queue/semaphore/counting_semaphore_utest.c b/FreeRTOS/Test/CMock/queue/semaphore/counting_semaphore_utest.c index 212c1cca1..abdd88563 100644 --- a/FreeRTOS/Test/CMock/queue/semaphore/counting_semaphore_utest.c +++ b/FreeRTOS/Test/CMock/queue/semaphore/counting_semaphore_utest.c @@ -673,3 +673,32 @@ void test_xSemaphoreTake_blocking_success_locked_low_prio_pending( void ) vQueueDelete( xSemaphore ); } + +/** + * @brief Test xSemaphoreGiveFromISR on a semaphore that is locked + * @coverage xQueueGiveFromISR + */ +void test_macro_xSemaphoreGiveFromISR_locked( void ) +{ + SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 2, 0 ); + + /* Set private lock counters */ + vSetQueueRxLock( xSemaphore, queueLOCKED_UNMODIFIED ); + vSetQueueTxLock( xSemaphore, queueLOCKED_UNMODIFIED ); + + vFakePortAssertIfInterruptPriorityInvalid_Ignore(); + uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 ); + + TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, NULL ) ); + TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, NULL ) ); + + /* Verify that the cRxLock counter has not changed */ + TEST_ASSERT_EQUAL( queueLOCKED_UNMODIFIED, cGetQueueRxLock( xSemaphore ) ); + + /* Verify that the cTxLock counter has only been incremented by one + * even after 2 calls to xQueueSendFromISR because there is only + * one task in the system as returned from uxTaskGetNumberOfTasks. */ + TEST_ASSERT_EQUAL( queueLOCKED_UNMODIFIED + 1, cGetQueueTxLock( xSemaphore ) ); + + vSemaphoreDelete( xSemaphore ); +}