Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
test_checkupManager.cpp
Go to the documentation of this file.
1#include "unity.h"
5
16
19 CheckupManager checkupManager(&systemData);
20
22 TEST_ASSERT_FALSE(checkupManager.shouldStayManualDriving());
23
26 TEST_ASSERT_FALSE(checkupManager.shouldStayManualDriving());
27
30 TEST_ASSERT_FALSE(checkupManager.shouldStayManualDriving());
31
33 TEST_ASSERT_TRUE(checkupManager.shouldStayManualDriving());
34}
35
36//can only test false since we can't mock the initial sequence :(
40 // default values shouldnt allow to pass test
41 CheckupManager checkupManager(&systemData);
42
43 TEST_ASSERT_TRUE(checkupManager.shouldStayOff(&digitalSender));
44}
45
49 CheckupManager cm(&sd);
50
53
54 sd.digitalData.asms_on = true;
56 // TEST_ASSERT_EQUAL(CheckupManager::CheckupState::START_TOGGLING_WATCHDOG, cm.checkupState);
57
58 // cm.initialCheckupSequence(&digitalSender);
59 // TEST_ASSERT_EQUAL(CheckupManager::CheckupState::WAIT_FOR_WATCHDOG, cm.checkupState);
60
61 // cm.getInitialCheckupTimestamp().reset();
62 // sd.digitalData.watchdog_state = true;
63 // cm.initialCheckupSequence(&digitalSender);
64 // TEST_ASSERT_EQUAL(CheckupManager::CheckupState::STOP_TOGGLING_WATCHDOG, cm.checkupState);
65
66 // cm.initialCheckupSequence(&digitalSender);
67 // TEST_ASSERT_EQUAL(CheckupManager::CheckupState::CHECK_WATCHDOG, cm.checkupState);
68
69 // Metro waitForWatchdogExpiration{1000};
70 // while (!waitForWatchdogExpiration.check()) {
71 // }
72 // sd.digitalData.watchdog_state = false;
73 // cm.initialCheckupSequence(&digitalSender);
75
78
82
86
91
95
100 //todo MISSING INVERSOR ALIVE TIMESTAMP
101
103
104}
105
108 systemData.r2dLogics.r2d = false;
109
110 CheckupManager checkupManager(&systemData);
111
112 TEST_ASSERT_TRUE(checkupManager.shouldStayReady());
113
114 systemData.r2dLogics.r2d = true;
115 TEST_ASSERT_FALSE(checkupManager.shouldStayReady());
116}
117
122 sd.digitalData.asms_on = true;
128 // sd.digitalData.watchdogTimestamp.reset();
131
132 CheckupManager checkupManager(&sd);
133
134 TEST_ASSERT_FALSE(checkupManager.shouldEnterEmergency(State::AS_READY));
136 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
140 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
142 sd.digitalData.asms_on = false;
143 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
144 sd.digitalData.asms_on = true;
145 sd.failureDetection.ts_on = false;
146 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
149 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
152 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
153
158 TEST_ASSERT_FALSE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
160 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
163 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
165 sd.digitalData.asms_on = false;
166 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
167 sd.digitalData.asms_on = true;
168 sd.failureDetection.ts_on = false;
169 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
172 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
175
176 // // Metro wait{WATCHDOG_TIMEOUT};
177 // while (!wait.check()) {
178 // }
179 // TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
181 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
182}
183
218
223
224 CheckupManager checkupManager(&systemData);
225
226 TEST_ASSERT_FALSE(checkupManager.shouldStayDriving());
227
229 TEST_ASSERT_TRUE(checkupManager.shouldStayDriving());
230
233 TEST_ASSERT_TRUE(checkupManager.shouldStayDriving());
234}
235
239
240 CheckupManager checkupManager(&systemData);
241
242 TEST_ASSERT_FALSE(checkupManager.shouldStayMissionFinished());
243
245 TEST_ASSERT_TRUE(checkupManager.shouldStayMissionFinished());
246}
247
251
252 CheckupManager checkupManager(&systemData);
253
254 TEST_ASSERT_FALSE(checkupManager.emergencySequenceComplete());
255
256
258 Metro waitForEbsSound{8500};
259 while (!waitForEbsSound.check()) {
260 }
261 TEST_ASSERT_TRUE(checkupManager.emergencySequenceComplete());
262}
263
267
268 CheckupManager checkupManager(&systemData);
269
270 TEST_ASSERT_TRUE(checkupManager.resTriggered());
271
273 TEST_ASSERT_FALSE(checkupManager.resTriggered());
274}
275
276void setUp(void) {
277}
278
279void tearDown(void) {
280}
281
282int main() {
283 UNITY_BEGIN();
289 RUN_TEST(test_shouldStayReady);
291 RUN_TEST(test_shouldStayDriving);
294 RUN_TEST(test_resTriggered);
295 return UNITY_END();
296}
The CheckupManager class handles various checkup operations.
bool shouldEnterEmergency(State current_state) const
Performs an emergency checkup.
bool emergencySequenceComplete() const
Checks if the emergency sequence is complete and the vehicle can transition to AS_OFF.
bool shouldStayManualDriving() const
Performs a manual driving checkup.
Metro & getInitialCheckupTimestamp()
Provides access to the initial checkup timestamp timer.
bool shouldStayOff(DigitalSender *digitalSender)
Performs an off checkup.
bool resTriggered() const
Checks if the RES has been triggered.
bool shouldStayReady() const
Performs a ready to drive checkup.
bool shouldStayDriving() const
CheckupState checkupState
Current state of the checkup process.
bool shouldStayMissionFinished() const
Performs a mission finished checkup.
CheckupError initialCheckupSequence(DigitalSender *digitalSender)
Performs an initial checkup.
Class responsible for controlling digital outputs in the Master Teensy.
Our own implementation of Metro class.
Definition metro.h:13
void reset()
Resets the timer to the current time.
Definition metro.h:125
bool checkWithoutReset() const
Checks if the interval has passed without resetting the timer.
Definition metro.h:116
constexpr auto HYDRAULIC_BRAKE_THRESHOLD
DigitalSender digitalSender
Definition main.cpp:12
SystemData systemData
Definition main.cpp:9
bool pneumatic_line_pressure
Metro releaseEbsTimestamp
int _hydraulic_line_pressure
Definition sensors.hpp:9
double _left_wheel_rpm
Definition sensors.hpp:8
The whole model of the system: holds all the data necessary.
Sensors sensors
DigitalData digitalData
Mission mission
bool missionFinished
FailureDetection failureDetection
R2DLogics r2dLogics
@ AS_DRIVING
Definition structure.hpp:12
@ AS_READY
Definition structure.hpp:11
@ MANUAL
Definition structure.hpp:18
@ INSPECTION
Definition structure.hpp:24
constexpr unsigned long RELEASE_EBS_TIMEOUT_MS
SystemData sd
void test_shouldStayReady()
void test_shouldStayOff_whenInitialCheckupFails_false()
void test_resTriggered()
void test_shouldEnterEmergencyAsDrivingEBSValves()
void test_shouldEnterEmergency()
void test_shouldStayManualDriving_true()
void test_shouldStayMissionFinished()
void setUp(void)
void test_shouldStayDriving()
void tearDown(void)
void test_initialCheckupSequence_states()
void test_shouldStayManualDriving_false()
void test_emergencySequenceComplete()
int main()