Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
test_checkupManager.cpp
Go to the documentation of this file.
4#include "unity.h"
5
7 SystemData systemData;
8 systemData.mission_ = Mission::MANUAL;
10 systemData.digital_data_.asms_on_ = false;
11
12 CheckupManager checkupManager(&systemData);
13
14 TEST_ASSERT_TRUE(checkupManager.should_stay_manual_driving());
15}
16
18 SystemData systemData;
19 CheckupManager checkupManager(&systemData);
20
21 systemData.mission_ = Mission::INSPECTION;
22 TEST_ASSERT_FALSE(checkupManager.should_stay_manual_driving());
23
24 systemData.mission_ = Mission::MANUAL;
26 TEST_ASSERT_FALSE(checkupManager.should_stay_manual_driving());
27
28 systemData.digital_data_.pneumatic_line_pressure_ = false;
29 systemData.digital_data_.asms_on_ = true;
30 TEST_ASSERT_FALSE(checkupManager.should_stay_manual_driving());
31
32 systemData.digital_data_.asms_on_ = false;
33 TEST_ASSERT_TRUE(checkupManager.should_stay_manual_driving());
34}
35
36// can only test false since we can't mock the initial sequence :(
38 SystemData systemData;
40 // default values shouldnt allow to pass test
41 CheckupManager checkupManager(&systemData);
42
43 TEST_ASSERT_TRUE(checkupManager.should_stay_off(&digitalSender));
44}
45
49 CheckupManager cm(&sd);
50
52 TEST_ASSERT_EQUAL(CheckupManager::CheckupState::WAIT_FOR_ASMS, cm.checkupState);
53
54 sd.digital_data_.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.digital_data_.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.digital_data_.watchdog_state = false;
73 // cm.initialCheckupSequence(&digitalSender);
74 TEST_ASSERT_EQUAL(CheckupManager::CheckupState::CLOSE_SDC, cm.checkupState);
75
77 TEST_ASSERT_EQUAL(CheckupManager::CheckupState::WAIT_FOR_AATS, cm.checkupState);
78
79 sd.digital_data_.sdc_open_ = false;
81 TEST_ASSERT_EQUAL(CheckupManager::CheckupState::WAIT_FOR_TS, cm.checkupState);
82
83 sd.failure_detection_.ts_on_ = true;
85 TEST_ASSERT_EQUAL(CheckupManager::CheckupState::TOGGLE_VALVE, cm.checkupState);
86
87 sd.digital_data_.pneumatic_line_pressure_ = true;
88 sd.sensors_._hydraulic_line_pressure = HYDRAULIC_BRAKE_THRESHOLD;
90 TEST_ASSERT_EQUAL(CheckupManager::CheckupState::CHECK_PRESSURE, cm.checkupState);
91
92 sd.failure_detection_.emergency_signal_ = false;
93 sd.failure_detection_.inversor_alive_timestamp_.reset();
94 sd.failure_detection_.pc_alive_timestamp_.reset();
95 sd.failure_detection_.steer_alive_timestamp_.reset();
96 // todo MISSING INVERSOR ALIVE TIMESTAMP
97
100}
101
103 SystemData systemData;
104 systemData.r2d_logics_.r2d = false;
105
106 CheckupManager checkupManager(&systemData);
107
108 TEST_ASSERT_TRUE(checkupManager.shouldStayReady());
109
110 systemData.r2d_logics_.r2d = true;
111 TEST_ASSERT_FALSE(checkupManager.shouldStayReady());
112}
113
116 sd.digital_data_.sdc_open_ = false;
117 sd.digital_data_.pneumatic_line_pressure_ = true;
118 sd.digital_data_.asms_on_ = true;
119 sd.sensors_._hydraulic_line_pressure = HYDRAULIC_BRAKE_THRESHOLD + 1;
120 sd.failure_detection_.inversor_alive_timestamp_.reset();
121 sd.failure_detection_.pc_alive_timestamp_.reset();
122 sd.failure_detection_.steer_alive_timestamp_.reset();
123 sd.failure_detection_.res_signal_loss_timestamp_.reset();
124 // sd.digital_data_.watchdogTimestamp.reset();
125 sd.failure_detection_.emergency_signal_ = false;
126 sd.failure_detection_.ts_on_ = true;
127
128 CheckupManager checkupManager(&sd);
129
130 TEST_ASSERT_FALSE(checkupManager.shouldEnterEmergency(State::AS_READY));
131 sd.digital_data_.sdc_open_ = true;
132 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
133 sd.digital_data_.sdc_open_ = false;
134 sd.digital_data_.pneumatic_line_pressure_ = false;
135 while (!sd.r2d_logics_.releaseEbsTimestamp.checkWithoutReset());
136 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
137 sd.digital_data_.pneumatic_line_pressure_ = true;
138 sd.digital_data_.asms_on_ = false;
139 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
140 sd.digital_data_.asms_on_ = true;
141 sd.failure_detection_.ts_on_ = false;
142 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
143 sd.failure_detection_.ts_on_ = true;
144 sd.failure_detection_.emergency_signal_ = true;
145 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
146 sd.failure_detection_.emergency_signal_ = false;
147 sd.sensors_._hydraulic_line_pressure = 1;
148 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
149
150 sd.failure_detection_.inversor_alive_timestamp_.reset();
151 sd.failure_detection_.pc_alive_timestamp_.reset();
152 sd.failure_detection_.steer_alive_timestamp_.reset();
153 sd.failure_detection_.res_signal_loss_timestamp_.reset();
154 TEST_ASSERT_FALSE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
155 sd.digital_data_.sdc_open_ = true;
156 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
157 sd.digital_data_.sdc_open_ = false;
158 sd.digital_data_.pneumatic_line_pressure_ = false;
159 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
160 sd.digital_data_.pneumatic_line_pressure_ = true;
161 sd.digital_data_.asms_on_ = false;
162 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
163 sd.digital_data_.asms_on_ = true;
164 sd.failure_detection_.ts_on_ = false;
165 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
166 sd.failure_detection_.ts_on_ = true;
167 sd.failure_detection_.emergency_signal_ = true;
168 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
169 sd.failure_detection_.emergency_signal_ = false;
170 sd.sensors_._hydraulic_line_pressure = HYDRAULIC_BRAKE_THRESHOLD + 1;
171
172 // // Metro wait{WATCHDOG_TIMEOUT};
173 // while (!wait.check()) {
174 // }
175 // TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_READY));
176 sd.sensors_._hydraulic_line_pressure = HYDRAULIC_BRAKE_THRESHOLD + 1;
177 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
178}
179
182 sd.digital_data_.sdc_open_ = false;
183 sd.digital_data_.pneumatic_line_pressure_ = true;
184 sd.digital_data_.asms_on_ = true;
185 sd.sensors_._hydraulic_line_pressure = 1;
186 sd.failure_detection_.inversor_alive_timestamp_.reset();
187 sd.failure_detection_.pc_alive_timestamp_.reset();
188 sd.failure_detection_.steer_alive_timestamp_.reset();
189 sd.failure_detection_.res_signal_loss_timestamp_.checkWithoutReset();
190 // sd.digital_data_.watchdogTimestamp.reset();
191 sd.r2d_logics_.releaseEbsTimestamp.reset();
192 sd.failure_detection_.emergency_signal_ = false;
193 sd.failure_detection_.ts_on_ = true;
194
195 CheckupManager checkupManager(&sd);
196
197 TEST_ASSERT_FALSE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
198 sd.sensors_._hydraulic_line_pressure = HYDRAULIC_BRAKE_THRESHOLD + 1;
199 TEST_ASSERT_FALSE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
200
201 Metro time3{RELEASE_EBS_TIMEOUT_MS + 10};
202 while (!time3.check()) {
203 sd.failure_detection_.inversor_alive_timestamp_.reset();
204 sd.failure_detection_.pc_alive_timestamp_.reset();
205 sd.failure_detection_.steer_alive_timestamp_.reset();
206 sd.failure_detection_.res_signal_loss_timestamp_.reset();
207 // sd.digital_data_.watchdogTimestamp.reset();
208 }
209
210 TEST_ASSERT_TRUE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
211 sd.sensors_._hydraulic_line_pressure = 1;
212 TEST_ASSERT_FALSE(checkupManager.shouldEnterEmergency(State::AS_DRIVING));
213}
214
216 SystemData systemData;
217 systemData.sensors_._left_wheel_rpm = 0;
218 systemData.mission_finished_ = true;
219
220 CheckupManager checkupManager(&systemData);
221
222 TEST_ASSERT_FALSE(checkupManager.shouldStayDriving());
223
224 systemData.sensors_._left_wheel_rpm = 1;
225 TEST_ASSERT_TRUE(checkupManager.shouldStayDriving());
226
227 systemData.sensors_._left_wheel_rpm = 0;
228 systemData.mission_finished_ = false;
229 TEST_ASSERT_TRUE(checkupManager.shouldStayDriving());
230}
231
233 SystemData systemData;
234 systemData.digital_data_.asms_on_ = false;
235
236 CheckupManager checkupManager(&systemData);
237
238 TEST_ASSERT_FALSE(checkupManager.shouldStayMissionFinished());
239
240 systemData.digital_data_.asms_on_ = true;
241 TEST_ASSERT_TRUE(checkupManager.shouldStayMissionFinished());
242}
243
245 SystemData systemData;
246 systemData.digital_data_.asms_on_ = true;
247
248 CheckupManager checkupManager(&systemData);
249
250 TEST_ASSERT_FALSE(checkupManager.emergencySequenceComplete());
251
252 systemData.digital_data_.asms_on_ = false;
253 Metro waitForEbsSound{8500};
254 while (!waitForEbsSound.check()) {
255 }
256 TEST_ASSERT_TRUE(checkupManager.emergencySequenceComplete());
257}
258
260 SystemData systemData;
261 systemData.failure_detection_.emergency_signal_ = true;
262
263 CheckupManager checkupManager(&systemData);
264
265 TEST_ASSERT_TRUE(checkupManager.resTriggered());
266
267 systemData.failure_detection_.emergency_signal_ = false;
268 TEST_ASSERT_FALSE(checkupManager.resTriggered());
269}
270
271void setUp(void) {}
272
273void tearDown(void) {}
274
275int main() {
276 UNITY_BEGIN();
282 RUN_TEST(test_shouldStayReady);
284 RUN_TEST(test_shouldStayDriving);
287 RUN_TEST(test_resTriggered);
288 return UNITY_END();
289}
The CheckupManager class handles various checkup operations.
bool should_stay_manual_driving() const
Performs a manual driving checkup.
bool should_stay_off(DigitalSender *digital_sender)
Performs an off checkup.
CheckupError initial_checkup_sequence(DigitalSender *digital_sender)
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:124
constexpr auto HYDRAULIC_BRAKE_THRESHOLD
constexpr unsigned long RELEASE_EBS_TIMEOUT_MS
bool pneumatic_line_pressure_
double _left_wheel_rpm
Definition sensors.hpp:8
The whole model of the system: holds all the data necessary.
Mission mission_
DigitalData digital_data_
R2DLogics r2d_logics_
FailureDetection failure_detection_
bool mission_finished_
Sensors sensors_
@ AS_DRIVING
@ AS_READY
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()
DigitalSender digitalSender
SdFat sd