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_reset_utest.c */
28 /* C runtime includes. */
33 #include "../queue_utest_common.h"
37 #include "FreeRTOSConfig.h"
40 #include "mock_fake_port.h"
42 /* ============================ GLOBAL VARIABLES =========================== */
44 /* ========================== CALLBACK FUNCTIONS =========================== */
46 /* ============================= Unity Fixtures ============================= */
63 int suiteTearDown( int numFailures )
65 return commonSuiteTearDown( numFailures );
68 /* ========================== Helper functions =========================== */
70 /* ========================== Test Cases =========================== */
73 * @brief Test xQueueReset with an invalid queue handle
74 * @coverage xQueueGenericReset
76 void test_macro_xQueueReset_invalid_handle( void )
78 EXPECT_ASSERT_BREAK( xQueueReset( NULL ) );
82 * @brief Test xQueueReset with an empty queue of size 6 x 4 bytes
83 * @coverage xQueueGenericReset
85 void test_macro_xQueueReset_empty( void )
87 QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
89 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
91 TEST_ASSERT_EQUAL( pdPASS, xQueueReset( xQueue ) );
93 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
95 vQueueDelete( xQueue );
99 * @brief Test xQueueReset with a half-full queue of size 6 x 4 bytes
100 * @coverage xQueueGenericReset
102 void test_macro_xQueueReset_half_full( void )
104 QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
106 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
108 for( uint32_t i = 0; i < 3; i++ )
110 xQueueSend( xQueue, &i, 0 );
113 TEST_ASSERT_EQUAL( 3, uxQueueMessagesWaiting( xQueue ) );
115 TEST_ASSERT_EQUAL( pdPASS, xQueueReset( xQueue ) );
117 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
119 vQueueDelete( xQueue );
123 * @brief Test xQueueReset with a full queue of size 6 x 4 bytes
124 * @coverage xQueueGenericReset
126 void test_macro_xQueueReset_full( void )
128 QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
130 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
132 for( uint32_t i = 0; i < 6; i++ )
134 xQueueSend( xQueue, &i, 0 );
137 TEST_ASSERT_EQUAL( 6, uxQueueMessagesWaiting( xQueue ) );
139 TEST_ASSERT_EQUAL( pdPASS, xQueueReset( xQueue ) );
141 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
143 vQueueDelete( xQueue );
147 * @brief Test xQueueReset with a queue of size 6 x 4 bytes
148 * and a simulated higher priority task that is blocked waiting send to the queue.
149 * @coverage xQueueGenericReset
151 void test_macro_xQueueReset_tasks_waiting_higher_priority( void )
153 QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
155 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
158 for( uint32_t i = 0; i < 6; i++ )
160 xQueueSend( xQueue, &i, 0 );
163 /* Insert an item into the event list */
164 td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
165 td_task_addFakeTaskWaitingToSendToQueue( xQueue );
167 TEST_ASSERT_EQUAL( pdTRUE, xQueueReset( xQueue ) );
169 TEST_ASSERT_EQUAL( 1, td_task_getYieldCount() );
171 TEST_ASSERT_EQUAL( 1, td_task_getCount_vPortYieldWithinAPI() );
173 vQueueDelete( xQueue );
177 * @brief Test xQueueReset with a queue of size 6 x 4 bytes
178 * and a simulated lower priority task that is blocked waiting to send to the queue.
179 * xTasksWaitingToSend
180 * @coverage xQueueGenericReset
182 void test_macro_xQueueReset_tasks_waiting_lower_priority( void )
184 QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
186 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
189 for( uint32_t i = 0; i < 6; i++ )
191 xQueueSend( xQueue, &i, 0 );
194 /* Insert an item into the event list */
195 td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
196 td_task_addFakeTaskWaitingToSendToQueue( xQueue );
198 TEST_ASSERT_EQUAL( pdTRUE, xQueueReset( xQueue ) );
200 vQueueDelete( xQueue );