]> begriffs open source - cmsis-freertos/blob - Test/CMock/queue/tracing/queue_trace_utest.c
Updated pack to FreeRTOS 10.4.6
[cmsis-freertos] / Test / CMock / queue / tracing / queue_trace_utest.c
1 /*
2  * FreeRTOS V202111.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
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.
21  *
22  * https://www.FreeRTOS.org
23  * https://github.com/FreeRTOS
24  *
25  */
26 /*! @file queue_trace_utest.c */
27
28 /* C runtime includes. */
29 #include <stdlib.h>
30 #include <stdbool.h>
31 #include <string.h>
32
33 #include "../queue_utest_common.h"
34
35 /* Queue includes */
36 #include "FreeRTOS.h"
37 #include "FreeRTOSConfig.h"
38 #include "queue.h"
39 #include "semphr.h"
40
41 /* ============================  GLOBAL VARIABLES =========================== */
42
43 /* ==========================  CALLBACK FUNCTIONS =========================== */
44
45 /* ============================= Unity Fixtures ============================= */
46
47 void setUp( void )
48 {
49     commonSetUp();
50 }
51
52 void tearDown( void )
53 {
54     commonTearDown();
55 }
56
57 void suiteSetUp()
58 {
59     commonSuiteSetUp();
60 }
61
62 int suiteTearDown( int numFailures )
63 {
64     return commonSuiteTearDown( numFailures );
65 }
66
67 /* ==========================  Helper functions =========================== */
68
69 /**
70  * @brief Test vQueueSetQueueNumber and uxQueueGetQueueNumber
71  * @details Verify that the queue number set with vQueueSetQueueNumber is returned
72  *  by a subsequent call to uxQueueGetQueueNumber.
73  * @coverage vQueueSetQueueNumber uxQueueGetQueueNumber
74  */
75 void test_vQueueSetQueueNumber_uxQueueGetQueueNumber( void )
76 {
77     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
78
79     vQueueSetQueueNumber( xQueue, getNextMonotonicTestValue() );
80
81     TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), uxQueueGetQueueNumber( xQueue ) );
82     vQueueDelete( xQueue );
83 }
84
85 /**
86  * @brief Test vQueueSetQueueNumber and uxQueueGetQueueNumber with UINT64_MAX
87  * @details Verify that the queue number of UINT64_MAX set with
88  * vQueueSetQueueNumber is returned by a subsequent call to uxQueueGetQueueNumber.
89  * @coverage vQueueSetQueueNumber uxQueueGetQueueNumber
90  */
91 void test_vQueueSetQueueNumber_uxQueueGetQueueNumber_max( void )
92 {
93     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
94
95     vQueueSetQueueNumber( xQueue, UINT64_MAX );
96
97     TEST_ASSERT_EQUAL( UINT64_MAX, uxQueueGetQueueNumber( xQueue ) );
98     vQueueDelete( xQueue );
99 }
100
101 /**
102  * @brief Test vQueueSetQueueNumber and uxQueueGetQueueNumber with 0
103  * @details Verify that the queue number of 0 set with vQueueSetQueueNumber
104  * is returned by a subsequent call to uxQueueGetQueueNumber.
105  * @coverage vQueueSetQueueNumber uxQueueGetQueueNumber
106  */
107 void test_vQueueSetQueueNumber_uxQueueGetQueueNumber_zero( void )
108 {
109     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
110
111     vQueueSetQueueNumber( xQueue, 0 );
112
113     TEST_ASSERT_EQUAL( 0, uxQueueGetQueueNumber( xQueue ) );
114     vQueueDelete( xQueue );
115 }
116
117 /**
118  * @brief Test ucQueueGetQueueType with a Queue
119  * @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_BASE for a normal queue.
120  * @coverage ucQueueGetQueueType prvInitialiseNewQueue
121  */
122 void test_ucQueueGetQueueType_queue( void )
123 {
124     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
125
126     TEST_ASSERT_EQUAL( queueQUEUE_TYPE_BASE, ucQueueGetQueueType( xQueue ) );
127     vQueueDelete( xQueue );
128 }
129
130 /**
131  * @brief Test ucQueueGetQueueType with a QueueSet
132  * @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_SET for a QueueSet.
133  * @coverage ucQueueGetQueueType prvInitialiseNewQueue
134  */
135 void test_ucQueueGetQueueType_queue_set( void )
136 {
137     QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 );
138
139     TEST_ASSERT_EQUAL( queueQUEUE_TYPE_SET, ucQueueGetQueueType( xQueueSet ) );
140     vQueueDelete( xQueueSet );
141 }
142
143 /**
144  * @brief Test ucQueueGetQueueType with a Mutex
145  * @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_MUTEX for a Mutex.
146  * @coverage ucQueueGetQueueType prvInitialiseNewQueue
147  */
148 void test_ucQueueGetQueueType_mutex( void )
149 {
150     xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
151     SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
152
153     TEST_ASSERT_EQUAL( queueQUEUE_TYPE_MUTEX, ucQueueGetQueueType( xSemaphore ) );
154     vSemaphoreDelete( xSemaphore );
155 }
156
157 /**
158  * @brief Test ucQueueGetQueueType with a Counting Semaphore
159  * @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_COUNTING_SEMAPHORE for a Counting Semaphore.
160  * @coverage ucQueueGetQueueType prvInitialiseNewQueue
161  */
162 void test_ucQueueGetQueueType_counting_semaphore( void )
163 {
164     SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 0 );
165
166     TEST_ASSERT_EQUAL( queueQUEUE_TYPE_COUNTING_SEMAPHORE, ucQueueGetQueueType( xSemaphore ) );
167     vSemaphoreDelete( xSemaphore );
168 }
169
170 /**
171  * @brief Test ucQueueGetQueueType with a Binary Semaphore
172  * @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_BINARY_SEMAPHORE for a Binary Semaphore.
173  * @coverage ucQueueGetQueueType prvInitialiseNewQueue
174  */
175 void test_ucQueueGetQueueType_binary_semaphore( void )
176 {
177     SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
178
179     TEST_ASSERT_EQUAL( queueQUEUE_TYPE_BINARY_SEMAPHORE, ucQueueGetQueueType( xSemaphore ) );
180     vSemaphoreDelete( xSemaphore );
181 }
182
183 /**
184  * @brief Test ucQueueGetQueueType with a Recursive Mutex
185  * @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_RECURSIVE_MUTEX for a Recursive Mutex.
186  * @coverage ucQueueGetQueueType prvInitialiseNewQueue
187  */
188 void test_ucQueueGetQueueType_recursive_mutex( void )
189 {
190     xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
191     SemaphoreHandle_t xSemaphore = xSemaphoreCreateRecursiveMutex();
192
193     TEST_ASSERT_EQUAL( queueQUEUE_TYPE_RECURSIVE_MUTEX, ucQueueGetQueueType( xSemaphore ) );
194     vSemaphoreDelete( xSemaphore );
195 }