]> begriffs open source - cmsis-freertos/blob - Test/CMock/queue/semaphore/semaphore_common_utest.c
Updated pack to FreeRTOS 10.4.6
[cmsis-freertos] / Test / CMock / queue / semaphore / semaphore_common_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 semaphore_common_utest.c */
27
28 #include "../queue_utest_common.h"
29
30 /* Queue includes */
31 #include "FreeRTOS.h"
32 #include "FreeRTOSConfig.h"
33 #include "semphr.h"
34
35
36 /* ============================  GLOBAL VARIABLES =========================== */
37
38 /* ==========================  CALLBACK FUNCTIONS =========================== */
39
40 /* ============================= Unity Fixtures ============================= */
41
42 void setUp( void )
43 {
44     commonSetUp();
45 }
46
47 void tearDown( void )
48 {
49     commonTearDown();
50 }
51
52 void suiteSetUp()
53 {
54     commonSuiteSetUp();
55 }
56
57 int suiteTearDown( int numFailures )
58 {
59     return commonSuiteTearDown( numFailures );
60 }
61
62 /* ===========================  Helper functions ============================ */
63
64 /* ==============================  Test Cases =============================== */
65
66 /**
67  * @brief Test xSemaphoreTake with an invalid (NULL) handle
68  * @coverage xQueueSemaphoreTake
69  */
70 void test_macro_xSemaphoreTake_invalid_handle( void )
71 {
72     EXPECT_ASSERT_BREAK( xSemaphoreTake( NULL, 0 ) );
73 }
74
75 /**
76  * @brief Test xSemaphoreTake with a QueueHandle rather than a SemaphoreHandle
77  * @coverage xQueueSemaphoreTake
78  */
79 void test_macro_xSemaphoreTake_queue_handle( void )
80 {
81     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
82
83     uint32_t testVal = getNextMonotonicTestValue();
84
85     xQueueSend( xQueue, &testVal, 0 );
86
87     /* Expect that xSemaphoreTake will assert because xQueue is not a semaphore */
88     fakeAssertExpectFail();
89
90     TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xQueue, 0 ) );
91
92     /* verify that configASSERT was called */
93     TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
94
95     vQueueDelete( xQueue );
96 }
97
98 /**
99  * @brief Test xSemaphoreGive with an invalid (NULL) handle
100  * @coverage xQueueGenericSend
101  */
102 void test_macro_xSemaphoreGive_invalid_handle( void )
103 {
104     EXPECT_ASSERT_BREAK( xSemaphoreGive( NULL ) );
105 }
106
107 /**
108  * @brief Test xSemaphoreGive with a QueueHandle rather than a SemaphoreHandle
109  * @coverage xQueueGenericSend
110  */
111 void test_macro_xSemaphoreGive_queue_handle( void )
112 {
113     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
114
115     EXPECT_ASSERT_BREAK( xSemaphoreGive( xQueue ) );
116
117     vQueueDelete( xQueue );
118 }
119
120 /**
121  * @brief Test xSemaphoreTakeFromISR with an invalid (NULL) handle
122  * @coverage xQueueReceiveFromISR
123  */
124 void test_macro_xSemaphoreTakeFromISR_invalid_handle( void )
125 {
126     EXPECT_ASSERT_BREAK( xSemaphoreTakeFromISR( NULL, NULL ) );
127 }
128
129 /**
130  * @brief Test xSemaphoreTakeFromISR with a QueueHandle rather than a SemaphoreHandle
131  * @coverage xQueueReceiveFromISR
132  */
133 void test_macro_xSemaphoreTakeFromISR_queue_handle( void )
134 {
135     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
136
137     /* Expect that xSemaphoreTake will assert because xQueue is not a semaphore */
138     fakeAssertExpectFail();
139
140     uint32_t testVal = getNextMonotonicTestValue();
141
142     xQueueSend( xQueue, &testVal, 0 );
143
144     EXPECT_ASSERT_BREAK( xSemaphoreTakeFromISR( xQueue, NULL ) );
145
146     vQueueDelete( xQueue );
147 }
148
149 /**
150  * @brief Test xSemaphoreGiveFromISR with an invalid (NULL) handle
151  * @coverage xQueueGiveFromISR
152  */
153 void test_macro_xSemaphoreGiveFromISR_invalid_handle( void )
154 {
155     EXPECT_ASSERT_BREAK( xSemaphoreGiveFromISR( NULL, NULL ) );
156 }
157
158 /**
159  * @brief Test xSemaphoreGiveFromISR with a QueueHandle rather than a SemaphoreHandle
160  * @coverage xQueueGiveFromISR
161  */
162 void test_macro_xSemaphoreGiveFromISR_queue_handle( void )
163 {
164     QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
165
166     EXPECT_ASSERT_BREAK( xSemaphoreGiveFromISR( xQueue, NULL ) );
167
168     vQueueDelete( xQueue );
169 }