]> begriffs open source - cmsis-freertos/blob - Test/CMock/queue/tracing/queue_delete_static_utest.c
Update README.md - branch main is now the base branch
[cmsis-freertos] / Test / CMock / queue / tracing / queue_delete_static_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_delete_static_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
40 #include "mock_fake_port.h"
41
42 /* ============================  GLOBAL VARIABLES =========================== */
43
44 /* ==========================  CALLBACK FUNCTIONS =========================== */
45
46 /* ============================= Unity Fixtures ============================= */
47
48 void setUp( void )
49 {
50     commonSetUp();
51 }
52
53 void tearDown( void )
54 {
55     commonTearDown();
56 }
57
58 void suiteSetUp()
59 {
60     commonSuiteSetUp();
61 }
62
63 int suiteTearDown( int numFailures )
64 {
65     return commonSuiteTearDown( numFailures );
66 }
67
68 /* ==========================  Helper functions =========================== */
69
70 /* =============================  Test Cases ============================== */
71
72 /**
73  * @brief Test vQueueDelete with an invalid QueueHandle
74  * @coverage vQueueDelete
75  */
76 void test_vQueueDelete_invalid_handle( void )
77 {
78     EXPECT_ASSERT_BREAK( vQueueDelete( NULL ) );
79 }
80
81 /**
82  * @brief Test vQueueDelete with a statically allocated queue of size 6 x 4 bytes
83  * @coverage vQueueDelete
84  */
85 void test_vQueueDelete_empty( void )
86 {
87     void * queueBuffer = malloc( sizeof( StaticQueue_t ) );
88     void * queueData = malloc( 6 * sizeof( uint32_t ) );
89     QueueHandle_t xQueue = xQueueCreateStatic( 6, sizeof( uint32_t ), queueData, queueBuffer );
90
91     /* Verify that no call to malloc occurred */
92     TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
93
94     vQueueDelete( xQueue );
95     /* Veirfy that free was not called */
96     TEST_ASSERT_EQUAL_PTR( NULL, getLastFreedAddress() );
97     free( queueBuffer );
98     free( queueData );
99 }
100
101 /**
102  * @brief Test vQueueDelete with a half-full queue of size 6 x 4 bytes
103  * @coverage vQueueDelete
104  */
105 void test_vQueueDelete_half_full( void )
106 {
107     void * queueBuffer = malloc( sizeof( StaticQueue_t ) );
108     void * queueData = malloc( 6 * sizeof( uint32_t ) );
109     QueueHandle_t xQueue = xQueueCreateStatic( 6, sizeof( uint32_t ), queueData, queueBuffer );
110
111     /* Verify that no call to malloc occurred */
112     TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
113
114     for( uint32_t i = 0; i < 3; i++ )
115     {
116         xQueueSend( xQueue, &i, 0 );
117     }
118
119     vQueueDelete( xQueue );
120
121     /* Veirfy that free was not called */
122     TEST_ASSERT_EQUAL_PTR( NULL, getLastFreedAddress() );
123     free( queueBuffer );
124     free( queueData );
125 }
126
127 /**
128  * @brief Test vQueueDelete with a full queue of size 6 x 4 bytes
129  * @coverage vQueueDelete
130  */
131 void test_vQueueDelete_full( void )
132 {
133     void * queueBuffer = malloc( sizeof( StaticQueue_t ) );
134     void * queueData = malloc( 6 * sizeof( uint32_t ) );
135     QueueHandle_t xQueue = xQueueCreateStatic( 6, sizeof( uint32_t ), queueData, queueBuffer );
136
137     /* Verify that no call to malloc occurred */
138     TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
139
140     for( uint32_t i = 0; i < 6; i++ )
141     {
142         xQueueSend( xQueue, &i, 0 );
143     }
144
145     vQueueDelete( xQueue );
146
147     /* Veirfy that free was not called */
148     TEST_ASSERT_EQUAL_PTR( NULL, getLastFreedAddress() );
149     free( queueBuffer );
150     free( queueData );
151 }