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