foxBMS - Unit Tests  1.1.1
The foxBMS Unit Tests API Documentation
test_os.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * We kindly request you to use one or more of the following phrases to refer to
34  * foxBMS in your hardware, software, documentation or advertising materials:
35  *
36  * - ″This product uses parts of foxBMS®″
37  * - ″This product includes parts of foxBMS®″
38  * - ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file test_os.c
44  * @author foxBMS Team
45  * @date 2020-03-13 (date of creation)
46  * @updated 2021-07-23 (date of last update)
47  * @ingroup UNIT_TEST_IMPLEMENTATION
48  * @prefix OS
49  *
50  * @brief Test of the os.c module
51  *
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "unity.h"
56 #include "Mockftask.h"
57 #include "Mockftask_cfg.h"
58 #include "Mockportmacro.h"
59 #include "Mocktask.h"
60 
61 #include "os.h"
62 
63 /*========== Definitions and Implementations for Unit Test ==================*/
64 
65 /*========== Setup and Teardown =============================================*/
66 void setUp(void) {
67 }
68 
69 void tearDown(void) {
70 }
71 
72 /*========== Test Cases =====================================================*/
74  FTSK_CreateQueues_Expect();
75  FTSK_CreateTasks_Expect();
76 
78 
79  TEST_ASSERT_EQUAL_INT8(OS_INIT_PRE_OS, os_boot);
80 }
81 
83  FTSK_RunUserCodeIdle_Expect();
84 
86 }
87 
88 void testOS_TriggerTimer(void) {
89  OS_TIMER_s timer = {0};
90  OS_TIMER_s timerExpected = {0};
91 
92  /* First call of function -> expected value afterwards 1ms has passed */
93  OS_TriggerTimer(&timer);
94  timerExpected.timer_1ms = 1; /* Set expected value */
95  TEST_ASSERT_EQUAL_MEMORY(&timerExpected, &timer, sizeof(OS_TIMER_s));
96 
97  /* Call trigger function 9 more times -> 9ms + 1ms have passed: 10ms in total */
98  for (uint8_t i = 0; i < 9; i++) {
99  OS_TriggerTimer(&timer);
100  }
101  timerExpected.timer_1ms = 0; /* Set expected value */
102  timerExpected.timer_10ms = 1;
103  TEST_ASSERT_EQUAL_MEMORY(&timerExpected, &timer, sizeof(OS_TIMER_s));
104 
105  /* Set timer to 99ms and call trigger function one more time -> 100ms passed */
106  timer.timer_1ms = 9;
107  timer.timer_10ms = 9;
108  OS_TriggerTimer(&timer);
109  timerExpected.timer_1ms = 0; /* Set extpected value */
110  timerExpected.timer_10ms = 0;
111  timerExpected.timer_100ms = 1;
112  TEST_ASSERT_EQUAL_MEMORY(&timerExpected, &timer, sizeof(OS_TIMER_s));
113 
114  /* Set timer to 999ms and call trigger function one more time -> 1s passed */
115  timer.timer_1ms = 9;
116  timer.timer_10ms = 9;
117  timer.timer_100ms = 9;
118  timer.timer_sec = 0;
119  timer.timer_min = 0;
120  timer.timer_h = 0;
121  timer.timer_d = 0;
122  OS_TriggerTimer(&timer);
123  timerExpected.timer_1ms = 0; /* Set extpected value */
124  timerExpected.timer_10ms = 0;
125  timerExpected.timer_100ms = 0;
126  timerExpected.timer_sec = 1;
127  timerExpected.timer_min = 0;
128  timerExpected.timer_h = 0;
129  timerExpected.timer_d = 0;
130  TEST_ASSERT_EQUAL_MEMORY(&timerExpected, &timer, sizeof(OS_TIMER_s));
131 
132  /* Set timer to 59.999s and call trigger function one more time -> 1min passed */
133  timer.timer_1ms = 9;
134  timer.timer_10ms = 9;
135  timer.timer_100ms = 9;
136  timer.timer_sec = 59;
137  timer.timer_min = 0;
138  timer.timer_h = 0;
139  timer.timer_d = 0;
140  OS_TriggerTimer(&timer);
141  timerExpected.timer_1ms = 0; /* Set extpected value */
142  timerExpected.timer_10ms = 0;
143  timerExpected.timer_100ms = 0;
144  timerExpected.timer_sec = 0;
145  timerExpected.timer_min = 1;
146  timerExpected.timer_h = 0;
147  timerExpected.timer_d = 0;
148  TEST_ASSERT_EQUAL_MEMORY(&timerExpected, &timer, sizeof(OS_TIMER_s));
149 
150  /* Set timer to 59min 59.999s and call trigger function one more time -> 1h passed */
151  timer.timer_1ms = 9;
152  timer.timer_10ms = 9;
153  timer.timer_100ms = 9;
154  timer.timer_sec = 59;
155  timer.timer_min = 59;
156  timer.timer_h = 0;
157  timer.timer_d = 0;
158  OS_TriggerTimer(&timer);
159  timerExpected.timer_1ms = 0; /* Set extpected value */
160  timerExpected.timer_10ms = 0;
161  timerExpected.timer_100ms = 0;
162  timerExpected.timer_sec = 0;
163  timerExpected.timer_min = 0;
164  timerExpected.timer_h = 1;
165  timerExpected.timer_d = 0;
166  TEST_ASSERT_EQUAL_MEMORY(&timerExpected, &timer, sizeof(OS_TIMER_s));
167 
168  /* Set timer to 59h 59min 59.999s and call trigger function one more time -> 1d passed */
169  timer.timer_1ms = 9;
170  timer.timer_10ms = 9;
171  timer.timer_100ms = 9;
172  timer.timer_sec = 59;
173  timer.timer_min = 59;
174  timer.timer_h = 59;
175  timer.timer_d = 0;
176  OS_TriggerTimer(&timer);
177  timerExpected.timer_1ms = 0; /* Set extpected value */
178  timerExpected.timer_10ms = 0;
179  timerExpected.timer_100ms = 0;
180  timerExpected.timer_sec = 0;
181  timerExpected.timer_min = 0;
182  timerExpected.timer_h = 0;
183  timerExpected.timer_d = 1;
184  TEST_ASSERT_EQUAL_MEMORY(&timerExpected, &timer, sizeof(OS_TIMER_s));
185 }
186 
188  /* checks whether the overflow of the timer is sanely handled. */
189  OS_TIMER_s timer = {0};
190  OS_TIMER_s timerExpected = {0};
191 
192  /* Set timer to last tick before overflow and call trigger function one more time */
193  timer.timer_1ms = 9;
194  timer.timer_10ms = 9;
195  timer.timer_100ms = 9;
196  timer.timer_sec = 59;
197  timer.timer_min = 59;
198  timer.timer_h = 23;
199  timer.timer_d = UINT16_MAX;
200  OS_TriggerTimer(&timer);
201  timerExpected.timer_1ms = 0; /* Set extpected value */
202  timerExpected.timer_10ms = 0;
203  timerExpected.timer_100ms = 0;
204  timerExpected.timer_sec = 0;
205  timerExpected.timer_min = 0;
206  timerExpected.timer_h = 0;
207  timerExpected.timer_d = 0;
208  TEST_ASSERT_EQUAL_MEMORY(&timerExpected, &timer, sizeof(OS_TIMER_s));
209 }
void OS_InitializeOperatingSystem(void)
Initialization the RTOS interface.
Definition: os.c:104
void vApplicationIdleHook(void)
Hook function for the idle task.
Definition: os.c:133
void OS_TriggerTimer(volatile OS_TIMER_s *timer)
Increments the system timer os_timer.
Definition: os.c:141
volatile OS_BOOT_STATE_e os_boot
Definition: os.c:72
Implementation of the tasks used by the system, headers.
@ OS_INIT_PRE_OS
Definition: os.h:94
OS timer.
Definition: os.h:105
uint8_t timer_min
Definition: os.h:110
uint16_t timer_d
Definition: os.h:112
uint8_t timer_h
Definition: os.h:111
uint8_t timer_100ms
Definition: os.h:108
uint8_t timer_sec
Definition: os.h:109
uint8_t timer_1ms
Definition: os.h:106
uint8_t timer_10ms
Definition: os.h:107
void testOS_TriggerTimer(void)
Definition: test_os.c:88
void testvApplicationIdleHookCallsUserCodeIdle(void)
Definition: test_os.c:82
void testOSTaskInitCallsFTSKFunctions(void)
Definition: test_os.c:73
void testOS_TriggerTimerOverflow(void)
Definition: test_os.c:187
void setUp(void)
Definition: test_os.c:66
void tearDown(void)
Definition: test_os.c:69