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 semaphore_common_utest.c */
28 #include "../queue_utest_common.h"
32 #include "FreeRTOSConfig.h"
36 /* ============================ GLOBAL VARIABLES =========================== */
38 /* ========================== CALLBACK FUNCTIONS =========================== */
40 /* ============================= Unity Fixtures ============================= */
57 int suiteTearDown( int numFailures )
59 return commonSuiteTearDown( numFailures );
62 /* =========================== Helper functions ============================ */
64 /* ============================== Test Cases =============================== */
67 * @brief Test xSemaphoreTake with an invalid (NULL) handle
68 * @coverage xQueueSemaphoreTake
70 void test_macro_xSemaphoreTake_invalid_handle( void )
72 EXPECT_ASSERT_BREAK( xSemaphoreTake( NULL, 0 ) );
76 * @brief Test xSemaphoreTake with a QueueHandle rather than a SemaphoreHandle
77 * @coverage xQueueSemaphoreTake
79 void test_macro_xSemaphoreTake_queue_handle( void )
81 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
83 uint32_t testVal = getNextMonotonicTestValue();
85 xQueueSend( xQueue, &testVal, 0 );
87 /* Expect that xSemaphoreTake will assert because xQueue is not a semaphore */
88 fakeAssertExpectFail();
90 TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xQueue, 0 ) );
92 /* verify that configASSERT was called */
93 TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
95 vQueueDelete( xQueue );
99 * @brief Test xSemaphoreGive with an invalid (NULL) handle
100 * @coverage xQueueGenericSend
102 void test_macro_xSemaphoreGive_invalid_handle( void )
104 EXPECT_ASSERT_BREAK( xSemaphoreGive( NULL ) );
108 * @brief Test xSemaphoreGive with a QueueHandle rather than a SemaphoreHandle
109 * @coverage xQueueGenericSend
111 void test_macro_xSemaphoreGive_queue_handle( void )
113 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
115 EXPECT_ASSERT_BREAK( xSemaphoreGive( xQueue ) );
117 vQueueDelete( xQueue );
121 * @brief Test xSemaphoreTakeFromISR with an invalid (NULL) handle
122 * @coverage xQueueReceiveFromISR
124 void test_macro_xSemaphoreTakeFromISR_invalid_handle( void )
126 EXPECT_ASSERT_BREAK( xSemaphoreTakeFromISR( NULL, NULL ) );
130 * @brief Test xSemaphoreTakeFromISR with a QueueHandle rather than a SemaphoreHandle
131 * @coverage xQueueReceiveFromISR
133 void test_macro_xSemaphoreTakeFromISR_queue_handle( void )
135 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
137 /* Expect that xSemaphoreTake will assert because xQueue is not a semaphore */
138 fakeAssertExpectFail();
140 uint32_t testVal = getNextMonotonicTestValue();
142 xQueueSend( xQueue, &testVal, 0 );
144 EXPECT_ASSERT_BREAK( xSemaphoreTakeFromISR( xQueue, NULL ) );
146 vQueueDelete( xQueue );
150 * @brief Test xSemaphoreGiveFromISR with an invalid (NULL) handle
151 * @coverage xQueueGiveFromISR
153 void test_macro_xSemaphoreGiveFromISR_invalid_handle( void )
155 EXPECT_ASSERT_BREAK( xSemaphoreGiveFromISR( NULL, NULL ) );
159 * @brief Test xSemaphoreGiveFromISR with a QueueHandle rather than a SemaphoreHandle
160 * @coverage xQueueGiveFromISR
162 void test_macro_xSemaphoreGiveFromISR_queue_handle( void )
164 QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
166 EXPECT_ASSERT_BREAK( xSemaphoreGiveFromISR( xQueue, NULL ) );
168 vQueueDelete( xQueue );