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_create_static_utest.c */
28 /* C runtime includes. */
33 #include "../queue_utest_common.h"
37 #include "FreeRTOSConfig.h"
40 /* ============================ GLOBAL VARIABLES =========================== */
42 /* ========================== CALLBACK FUNCTIONS =========================== */
44 /* ============================= Unity Fixtures ============================= */
61 int suiteTearDown( int numFailures )
63 return commonSuiteTearDown( numFailures );
66 /* ========================== Helper functions =========================== */
69 static void test_long_queue( QueueHandle_t xQueue,
72 /* Veify that queue is empty */
73 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
75 queue_common_add_sequential_to_queue( xQueue, maxItems );
77 /* Veify that queue is full */
78 TEST_ASSERT_EQUAL( 0, uxQueueSpacesAvailable( xQueue ) );
80 queue_common_receive_sequential_from_queue( xQueue, maxItems, maxItems, 0 );
82 /* Veify that queue is empty */
83 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
87 /* ========================== Test Cases =========================== */
90 * @brief xQueueCreateStatic with a NULL pointer for queueStorage
91 * @coverage xQueueGenericCreateStatic
93 void test_macro_xQueueCreateStatic_null_QueueStorage_fail( void )
95 /* Expect that xQueueCreate will assert */
96 fakeAssertExpectFail();
98 StaticQueue_t queueBuffer;
99 QueueHandle_t xQueue = xQueueCreateStatic( MAX_QUEUE_ITEMS, sizeof( uint32_t ), NULL, &queueBuffer );
101 /* Validate the queue handle */
102 TEST_ASSERT_EQUAL( NULL, xQueue );
104 TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
108 * @brief xQueueCreateStatic with a NULL pointer for queueBuffer
109 * @coverage xQueueGenericCreateStatic
111 void test_macro_xQueueCreateStatic_null_queueBuffer_fail( void )
113 /* Expect that xQueueCreate will assert */
114 fakeAssertExpectFail();
116 uint32_t queueStorage[ MAX_QUEUE_ITEMS ];
117 QueueHandle_t xQueue = INVALID_PTR;
119 xQueue = xQueueCreateStatic( MAX_QUEUE_ITEMS, sizeof( uint32_t ), ( void * ) queueStorage, NULL );
121 /* Validate that the queue handle is NULL */
122 TEST_ASSERT_EQUAL( NULL, xQueue );
124 /* Check that configASSERT was called twice */
125 fakeAssertVerifyNumAssertsAndClear( 2 );
129 * @brief Test xQueueCreateStatic with a NULL buffer, uxQueueLength=1, uxItemSize=0
130 * @details This configuration is equivalent to a binary semaphore.
131 * @coverage xQueueGenericCreateStatic
133 void test_macro_xQueueCreateStatic_nullQueueStorage_oneItem_zeroLength( void )
135 StaticQueue_t queueBuffer;
136 QueueHandle_t xQueue = xQueueCreateStatic( 1, 0, NULL, &queueBuffer );
138 /* validate returned queue handle */
139 TEST_ASSERT_NOT_EQUAL( NULL, xQueue );
141 /* Veify that new queue is empty */
142 TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
144 /* Valdiate that the queue has 1 space remaining */
145 TEST_ASSERT_EQUAL( 1, uxQueueSpacesAvailable( xQueue ) );
147 /* Send a test value */
148 TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, NULL, 0 ) );
151 TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, NULL, 0 ) );
153 vQueueDelete( xQueue );
157 * @brief Test xQueueCreateStatic with uxQueueLength=0, uxItemSize=0
158 * @details This configuration is invalid and causes a configASSERT.
159 * @coverage xQueueGenericCreateStatic
161 void test_macro_xQueueCreateStatic_validQueueStorage_zeroItem_zeroLength( void )
163 StaticQueue_t queueBuffer;
165 /* Expect that xQueueCreateStatic will assert because a zero length queue is invalid */
166 fakeAssertExpectFail();
167 QueueHandle_t xQueue = xQueueCreateStatic( 0, 0, NULL, &queueBuffer );
169 /* verify that configASSERT was called */
170 TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
172 /* validate returned queue handle */
173 TEST_ASSERT_EQUAL( NULL, xQueue );
177 * @brief Test xQueueCreateStatic with a valid buffer, uxQueueLength=1, uxItemSize=0
178 * @details This configuration is invalid and causes a configASSERT.
179 * @coverage xQueueGenericCreateStatic
181 void test_macro_xQueueCreateStatic_validQueueStorage_oneItem_zeroLength( void )
183 StaticQueue_t queueBuffer;
186 /* Expect that xQueueCreateStatic will assert because data storage is
187 * prohibited for a zero itemLength queue */
188 fakeAssertExpectFail();
189 QueueHandle_t xQueue = xQueueCreateStatic( 1, 0, ( void * ) &queueData, &queueBuffer );
191 /* verify that configASSERT was called */
192 TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
194 /* validate returned queue handle */
195 TEST_ASSERT_EQUAL( NULL, xQueue );
199 * @brief xQueueCreateStatic with a large queue.
200 * @coverage xQueueGenericCreateStatic
202 void test_macro_xQueueCreateStatic_large( void )
204 uint32_t queueStorage[ MAX_QUEUE_ITEMS ];
205 StaticQueue_t queueBuffer;
206 QueueHandle_t xQueue = xQueueCreateStatic( MAX_QUEUE_ITEMS, sizeof( uint32_t ), ( void * ) queueStorage, &queueBuffer );
208 test_long_queue( xQueue, MAX_QUEUE_ITEMS );
209 vQueueDelete( xQueue );