summaryrefslogtreecommitdiff
path: root/FreeRTOS/Test
diff options
context:
space:
mode:
authorGaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>2022-01-05 21:05:11 -0800
committerGitHub <noreply@github.com>2022-01-05 21:05:11 -0800
commit2f5a6333837ae766727266f627440819ab12845f (patch)
tree29cdf3f70e356fc8c4479638103850aefc9fa37d /FreeRTOS/Test
parent89938537bc8121eec29e429e3fd64d93ff52dfa2 (diff)
downloadfreertos-git-2f5a6333837ae766727266f627440819ab12845f.tar.gz
Add tests to increase queue code coverage (#770)
These tests cover the following portion in the queue code: static void prvUnlockQueue( Queue_t * const pxQueue ) { ... if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE ) { /* The queue is a member of a queue set, and posting to * the queue set caused a higher priority task to unblock. * A context switch is required. */ vTaskMissedYield(); } else { mtCOVERAGE_TEST_MARKER(); } ... } Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Diffstat (limited to 'FreeRTOS/Test')
-rw-r--r--FreeRTOS/Test/CMock/queue/sets/queue_in_set_utest.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/FreeRTOS/Test/CMock/queue/sets/queue_in_set_utest.c b/FreeRTOS/Test/CMock/queue/sets/queue_in_set_utest.c
index 6e67e04ce..83562a2e0 100644
--- a/FreeRTOS/Test/CMock/queue/sets/queue_in_set_utest.c
+++ b/FreeRTOS/Test/CMock/queue/sets/queue_in_set_utest.c
@@ -371,6 +371,97 @@ void test_macro_xQueueSendFromISR_in_set_high_priority_pending( void )
}
/**
+ * @brief Test xQueueSendFromISR with a higher priority task waiting on a locked queue in Queue Set.
+ * @details Test xQueueSendFromISR with a higher priority task waiting on a locked queue and
+ * verifies that xTaskResumeAll resumes the high priority task.
+ * @coverage xQueueGenericSendFromISR
+ */
+void test_macro_xQueueSendFromISR_in_set_locked_and_high_priority_pending( void )
+{
+ QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
+ QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 );
+
+ xQueueAddToSet( xQueue, xQueueSet );
+
+ vFakePortAssertIfInterruptPriorityInvalid_Expect();
+
+ /* Insert an item into the event list. */
+ td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
+ td_task_addFakeTaskWaitingToReceiveFromQueue( xQueueSet );
+
+ /* Lock the queue. */
+ vSetQueueTxLock( xQueue, queueLOCKED_UNMODIFIED );
+ uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
+
+ uint32_t testVal = getNextMonotonicTestValue();
+
+ /* Add item to queue. */
+ TEST_ASSERT_EQUAL( pdTRUE, xQueueSendFromISR( xQueue, &testVal, NULL ) );
+ /* This call will trigger unlocking of the queue which eventually calls xTaskResumeAll. */
+ TEST_ASSERT_EQUAL( errQUEUE_FULL, xQueueSend( xQueue, &testVal, 1 ) );
+
+ /* Ensure that the xTaskResumeAll resumes high priority task. */
+ TEST_ASSERT_EQUAL( 1, td_task_getYieldCount() );
+ TEST_ASSERT_EQUAL( 1, td_task_getCount_YieldFromTaskResumeAll() );
+ TEST_ASSERT_EQUAL( 1, td_task_getCount_vTaskMissedYield() );
+
+ QueueHandle_t xQueueTemp = xQueueSelectFromSet( xQueueSet, 0 );
+ uint32_t checkVal = INVALID_UINT32;
+
+ xQueueReceive( xQueueTemp, &checkVal, 0 );
+ TEST_ASSERT_EQUAL( testVal, checkVal );
+
+ vQueueDelete( xQueue );
+ vQueueDelete( xQueueSet );
+}
+
+/**
+ * @brief Test xQueueSendFromISR with a low priority task waiting on a locked queue in Queue Set.
+ * @details Test xQueueSendFromISR with a low priority task waiting on a locked queue and
+ * verifies that xTaskResumeAll does not resume the low priority task.
+ * @coverage xQueueGenericSendFromISR
+ */
+void test_macro_xQueueSendFromISR_in_set_locked_and_low_priority_pending( void )
+{
+ QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
+ QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 );
+
+ xQueueAddToSet( xQueue, xQueueSet );
+
+ vFakePortAssertIfInterruptPriorityInvalid_Expect();
+
+ /* Insert an item into the event list. */
+ td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
+ td_task_addFakeTaskWaitingToReceiveFromQueue( xQueueSet );
+
+ /* Lock the queue. */
+ vSetQueueTxLock( xQueue, queueLOCKED_UNMODIFIED );
+ uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
+
+ uint32_t testVal = getNextMonotonicTestValue();
+
+ /* Add item to queue. */
+ TEST_ASSERT_EQUAL( pdTRUE, xQueueSendFromISR( xQueue, &testVal, NULL ) );
+ /* This call will trigger unlocking of the queue which eventually calls xTaskResumeAll. */
+ TEST_ASSERT_EQUAL( errQUEUE_FULL, xQueueSend( xQueue, &testVal, 1 ) );
+
+ /* Ensure that the xTaskResumeAll does not resume low priority task. */
+ TEST_ASSERT_EQUAL( 0, td_task_getCount_YieldFromTaskResumeAll() );
+ TEST_ASSERT_EQUAL( 0, td_task_getCount_vTaskMissedYield() );
+ TEST_ASSERT_EQUAL( 1, td_task_getYieldCount() );
+ TEST_ASSERT_EQUAL( 1, td_task_getCount_vPortYieldWithinAPI() );
+
+ QueueHandle_t xQueueTemp = xQueueSelectFromSet( xQueueSet, 0 );
+ uint32_t checkVal = INVALID_UINT32;
+
+ xQueueReceive( xQueueTemp, &checkVal, 0 );
+ TEST_ASSERT_EQUAL( testVal, checkVal );
+
+ vQueueDelete( xQueue );
+ vQueueDelete( xQueueSet );
+}
+
+/**
* @brief Test xQueueSendFromISR with a lower priority task waiting on a queue in a Queue Set
* @details Test xQueueSendFromISR on a Queeu in a Queue Set with a lower priority task waiting and
* verify that xHigherPriorityTaskWoken is not modified.