summaryrefslogtreecommitdiff
path: root/FreeRTOS/Test/CMock/queue/tracing/queue_trace_utest.c
blob: 873f947cbd9b1b13061d83953227873c2d5cdce3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 * FreeRTOS V202012.00
 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * https://www.FreeRTOS.org
 * https://github.com/FreeRTOS
 *
 */
/*! @file queue_trace_utest.c */

/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

#include "../queue_utest_common.h"

/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
#include "semphr.h"

/* ============================  GLOBAL VARIABLES =========================== */

/* ==========================  CALLBACK FUNCTIONS =========================== */

/* ============================= Unity Fixtures ============================= */

void setUp( void )
{
    commonSetUp();
}

void tearDown( void )
{
    commonTearDown();
}

void suiteSetUp()
{
    commonSuiteSetUp();
}

int suiteTearDown( int numFailures )
{
    return commonSuiteTearDown( numFailures );
}

/* ==========================  Helper functions =========================== */

/**
 * @brief Test vQueueSetQueueNumber and uxQueueGetQueueNumber
 * @details Verify that the queue number set with vQueueSetQueueNumber is returned
 *  by a subsequent call to uxQueueGetQueueNumber.
 * @coverage vQueueSetQueueNumber uxQueueGetQueueNumber
 */
void test_vQueueSetQueueNumber_uxQueueGetQueueNumber( void )
{
    QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );

    vQueueSetQueueNumber( xQueue, getNextMonotonicTestValue() );

    TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), uxQueueGetQueueNumber( xQueue ) );
    vQueueDelete( xQueue );
}

/**
 * @brief Test vQueueSetQueueNumber and uxQueueGetQueueNumber with UINT64_MAX
 * @details Verify that the queue number of UINT64_MAX set with
 * vQueueSetQueueNumber is returned by a subsequent call to uxQueueGetQueueNumber.
 * @coverage vQueueSetQueueNumber uxQueueGetQueueNumber
 */
void test_vQueueSetQueueNumber_uxQueueGetQueueNumber_max( void )
{
    QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );

    vQueueSetQueueNumber( xQueue, UINT64_MAX );

    TEST_ASSERT_EQUAL( UINT64_MAX, uxQueueGetQueueNumber( xQueue ) );
    vQueueDelete( xQueue );
}

/**
 * @brief Test vQueueSetQueueNumber and uxQueueGetQueueNumber with 0
 * @details Verify that the queue number of 0 set with vQueueSetQueueNumber
 * is returned by a subsequent call to uxQueueGetQueueNumber.
 * @coverage vQueueSetQueueNumber uxQueueGetQueueNumber
 */
void test_vQueueSetQueueNumber_uxQueueGetQueueNumber_zero( void )
{
    QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );

    vQueueSetQueueNumber( xQueue, 0 );

    TEST_ASSERT_EQUAL( 0, uxQueueGetQueueNumber( xQueue ) );
    vQueueDelete( xQueue );
}

/**
 * @brief Test ucQueueGetQueueType with a Queue
 * @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_BASE for a normal queue.
 * @coverage ucQueueGetQueueType prvInitialiseNewQueue
 */
void test_ucQueueGetQueueType_queue( void )
{
    QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );

    TEST_ASSERT_EQUAL( queueQUEUE_TYPE_BASE, ucQueueGetQueueType( xQueue ) );
    vQueueDelete( xQueue );
}

/**
 * @brief Test ucQueueGetQueueType with a QueueSet
 * @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_SET for a QueueSet.
 * @coverage ucQueueGetQueueType prvInitialiseNewQueue
 */
void test_ucQueueGetQueueType_queue_set( void )
{
    QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 );

    TEST_ASSERT_EQUAL( queueQUEUE_TYPE_SET, ucQueueGetQueueType( xQueueSet ) );
    vQueueDelete( xQueueSet );
}

/**
 * @brief Test ucQueueGetQueueType with a Mutex
 * @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_MUTEX for a Mutex.
 * @coverage ucQueueGetQueueType prvInitialiseNewQueue
 */
void test_ucQueueGetQueueType_mutex( void )
{
    xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
    SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();

    TEST_ASSERT_EQUAL( queueQUEUE_TYPE_MUTEX, ucQueueGetQueueType( xSemaphore ) );
    vSemaphoreDelete( xSemaphore );
}

/**
 * @brief Test ucQueueGetQueueType with a Counting Semaphore
 * @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_COUNTING_SEMAPHORE for a Counting Semaphore.
 * @coverage ucQueueGetQueueType prvInitialiseNewQueue
 */
void test_ucQueueGetQueueType_counting_semaphore( void )
{
    SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 0 );

    TEST_ASSERT_EQUAL( queueQUEUE_TYPE_COUNTING_SEMAPHORE, ucQueueGetQueueType( xSemaphore ) );
    vSemaphoreDelete( xSemaphore );
}

/**
 * @brief Test ucQueueGetQueueType with a Binary Semaphore
 * @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_BINARY_SEMAPHORE for a Binary Semaphore.
 * @coverage ucQueueGetQueueType prvInitialiseNewQueue
 */
void test_ucQueueGetQueueType_binary_semaphore( void )
{
    SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();

    TEST_ASSERT_EQUAL( queueQUEUE_TYPE_BINARY_SEMAPHORE, ucQueueGetQueueType( xSemaphore ) );
    vSemaphoreDelete( xSemaphore );
}

/**
 * @brief Test ucQueueGetQueueType with a Recursive Mutex
 * @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_RECURSIVE_MUTEX for a Recursive Mutex.
 * @coverage ucQueueGetQueueType prvInitialiseNewQueue
 */
void test_ucQueueGetQueueType_recursive_mutex( void )
{
    xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
    SemaphoreHandle_t xSemaphore = xSemaphoreCreateRecursiveMutex();

    TEST_ASSERT_EQUAL( queueQUEUE_TYPE_RECURSIVE_MUTEX, ucQueueGetQueueType( xSemaphore ) );
    vSemaphoreDelete( xSemaphore );
}