Branch data MC/DC data Line data Source code
1 : : : // Necessary libraries
2 : : : #include "unity.h"
3 : : : #include "constants.h"
4 : : : #include "sensors_input.h"
5 : : : #include "dbc.h"
6 : : : #include <mqueue.h>
7 : : : #include "ttc_control.h"
8 : : :
9 : : : /**
10 : : : * @brief Enumeration of AEB controller states.
11 : : : */
12 : : : typedef enum {
13 : : : AEB_STATE_ACTIVE, /**< AEB is active and functioning normally */
14 : : : AEB_STATE_ALARM, /**< AEB system is in alarm state due to a potential collision */
15 : : : AEB_STATE_BRAKE, /**< AEB system is in brake state to avoid a collision */
16 : : : AEB_STATE_STANDBY /**< AEB system is in standby mode, awaiting activation */
17 : : : } aeb_controller_state;
18 : : :
19 : : : /** External declaration of global variables */
20 : : : extern sensors_input_data aeb_internal_state; /**< Internal AEB system state data */
21 : : : extern can_msg captured_can_frame; /**< Captured CAN message */
22 : : : extern can_msg out_can_frame; /**< Output CAN message */
23 : : : extern can_msg empty_msg; /**< Empty CAN message */
24 : : :
25 : : : void translateAndCallCanMsg(can_msg captured_frame);
26 : : : void updateInternalPedalsState(can_msg captured_frame);
27 : : : void updateInternalSpeedState(can_msg captured_frame);
28 : : : void updateInternalObstacleState(can_msg captured_frame);
29 : : : void updateInternalCarCState(can_msg captured_frame);
30 : : : can_msg updateCanMsgOutput(aeb_controller_state state);
31 : : : aeb_controller_state getAEBState(sensors_input_data aeb_internal_state, double ttc);
32 : : :
33 : : : /**
34 : : : * @brief Mock function to simulate opening a message queue.
35 : : : *
36 : : : * @param mq_name The name of the message queue to open.
37 : : : * @return mqd_t The mock message queue descriptor.
38 : : : */
39 : : 0 : mqd_t open_mq(char *mq_name) {
40 : : 0 : printf("Opening message queue: %s\n\n", mq_name);
41 : : 0 : return 1; // Return a mock handle for the message queue
42 : : : }
43 : : :
44 : : : /**
45 : : : * @brief Mock function to simulate writing a message to a message queue.
46 : : : *
47 : : : * @param mq_sender The message queue descriptor.
48 : : : * @param msg The CAN message to be written.
49 : : : * @return int The status of the write operation (0 for success).
50 : : : */
51 : : 0 : int write_mq(mqd_t mq_sender, can_msg *msg) {
52 : : : //printf("Writing message to MQ: Identifier: %d, Data: %02X %02X %02X %02X %02X %02X %02X %02X\n\n",
53 : : : // msg->identifier, msg->dataFrame[0], msg->dataFrame[1], msg->dataFrame[2],
54 : : : // msg->dataFrame[3], msg->dataFrame[4], msg->dataFrame[5], msg->dataFrame[6], msg->dataFrame[7]);
55 : : 0 : return 0; // Simulate success in writing to the message queue
56 : : : }
57 : : :
58 : : : /**
59 : : : * @brief Mock function to simulate reading a message from a message queue.
60 : : : *
61 : : : * @param mq The message queue descriptor.
62 : : : * @param msg The CAN message to store the read data.
63 : : : * @return int The status of the read operation (0 for success).
64 : : : */
65 : : 0 : int read_mq(mqd_t mq, can_msg *msg) {
66 : : 0 : return 0; // Simulate success in reading the message
67 : : : }
68 : : :
69 : : : /**
70 : : : * @brief Setup function to initialize AEB input state before each test.
71 : : : */
72 : : 53 : void setUp(void) {
73 : : 53 : aeb_internal_state.relative_velocity = 0.0;
74 : : 53 : aeb_internal_state.has_obstacle = false;
75 : : 53 : aeb_internal_state.obstacle_distance = 0.0;
76 : : 53 : aeb_internal_state.brake_pedal = false;
77 : : 53 : aeb_internal_state.accelerator_pedal = false;
78 : : 53 : aeb_internal_state.aeb_system_enabled = true;
79 : : 53 : aeb_internal_state.reverse_enabled = false;
80 : : 53 : }
81 : : :
82 : : : /**
83 : : : * @brief Teardown function to clean up after each test.
84 : : : */
85 : : 53 : void tearDown(void) {
86 : : : // No cleanup required for now
87 : : 53 : }
88 : : :
89 : : : //////////////////////////////////////////////////////////////////////////////////////////////////
90 : : : /**
91 : : : * @note The naming convention for test cases is as follows:
92 : : : * test_<test_case_name><number_suffix>
93 : : : *
94 : : : * Where:
95 : : : * <test_case_name> is the name of the test case
96 : : : *
97 : : : * <number_suffix> is a number suffix to differentiate between test cases, if begin with an "X",
98 : : : * it means that the test case is not a part of the sheet test built for check the
99 : : : * compliance with software requirements and is used for increase the coverage.
100 : : : */
101 : : : //////////////////////////////////////////////////////////////////////////////////////////////////
102 : : :
103 : : : /**
104 : : : * @brief Helper function to check the pedal state.
105 : : : *
106 : : : * This function verifies the internal state of the accelerator and brake pedals
107 : : : * in the AEB system by comparing the actual state with the expected values.
108 : : : * It asserts that the internal states of both the accelerator pedal and the brake
109 : : : * pedal are correctly set based on the expected values.
110 : : : *
111 : : : * @param expected_accelerator Expected state of the accelerator pedal (true for ON, false for OFF).
112 : : : * @param expected_brake Expected state of the brake pedal (true for ON, false for OFF).
113 : : : *
114 : : : * @details
115 : : : * This helper function checks the states of the accelerator and brake pedals in
116 : : : * the internal AEB system state (`aeb_internal_state`). It compares the actual state
117 : : : * of each pedal with the expected state and asserts that the values match.
118 : : : * If the expected state is `true`, the corresponding pedal should be ON; if `false`,
119 : : : * it should be OFF.
120 : : : *
121 : : : * @pre The internal state of the AEB system has been updated with new pedal data.
122 : : : * @post The test verifies that the internal state reflects the expected pedal states.
123 : : : */
124 : : 6 : void checkPedalState(bool expected_accelerator, bool expected_brake) {
125 [ + + ]: [ T F ]: 6 : if (expected_accelerator){
126 [ - + ]: [ T f ]: 4 : TEST_ASSERT_TRUE(aeb_internal_state.accelerator_pedal);
127 : : : } else {
128 [ - + ]: [ T f ]: 2 : TEST_ASSERT_FALSE(aeb_internal_state.accelerator_pedal);
129 : : : }
130 : : :
131 [ + + ]: [ T F ]: 6 : if (expected_brake){
132 [ - + ]: [ T f ]: 4 : TEST_ASSERT_TRUE(aeb_internal_state.brake_pedal);
133 : : : } else {
134 [ - + ]: [ T f ]: 2 : TEST_ASSERT_FALSE(aeb_internal_state.brake_pedal);
135 : : : }
136 : : 6 : }
137 : : :
138 : : : /**
139 : : : * @brief Test Case TC_AEB_CTRL_001: Accelerator pedal ON, Brake pedal OFF.
140 : : : *
141 : : : * This test case verifies that when the accelerator pedal is ON and the brake pedal is OFF,
142 : : : * the internal state of the AEB system is updated accordingly. Specifically, the function
143 : : : * `updateInternalPedalsState` is called with the given CAN message, and the expected behavior
144 : : : * is that the accelerator pedal state is set to ON and the brake pedal state is set to OFF.
145 : : : *
146 : : : * @details
147 : : : * The CAN message data used in this test is:
148 : : : * - Accelerator pedal: ON (0x01)
149 : : : * - Brake pedal: OFF (0x00)
150 : : : * The test asserts that the internal AEB system state reflects these conditions correctly.
151 : : : *
152 : : : * @pre The internal state of the AEB system is initialized.
153 : : : * @post The internal state of the AEB system reflects the changes: accelerator ON, brake OFF.
154 : : : *
155 : : : * @anchor TC_AEB_CTRL_001
156 : : : */
157 : : 1 : void test_TC_AEB_CTRL_001(void) {
158 : : 1 : can_msg captured_frame = { .identifier = ID_PEDALS, .dataFrame = {0x01, 0x00} };
159 : : :
160 : : 1 : updateInternalPedalsState(captured_frame);
161 : : :
162 : : : // Test: Accelerator pedal should be ON, Brake pedal should be OFF
163 : : 1 : checkPedalState(true, false);
164 : : 1 : }
165 : : :
166 : : : /**
167 : : : * @brief Test Case TC_AEB_CTRL_002: Accelerator pedal ON, Brake pedal ON.
168 : : : *
169 : : : * This test case verifies that when both the accelerator pedal and brake pedal are ON,
170 : : : * the internal state of the AEB system is updated accordingly. Specifically, the function
171 : : : * `updateInternalPedalsState` is called with the given CAN message, and the expected behavior
172 : : : * is that both the accelerator pedal state and the brake pedal state are set to ON.
173 : : : *
174 : : : * @details
175 : : : * The CAN message data used in this test is:
176 : : : * - Accelerator pedal: ON (0x01)
177 : : : * - Brake pedal: ON (0x01)
178 : : : * The test asserts that the internal AEB system state reflects these conditions correctly.
179 : : : *
180 : : : * @pre The internal state of the AEB system is initialized.
181 : : : * @post The internal state of the AEB system reflects the changes: accelerator ON, brake ON.
182 : : : *
183 : : : * @anchor TC_AEB_CTRL_002
184 : : : */
185 : : 1 : void test_TC_AEB_CTRL_002(void) {
186 : : 1 : can_msg captured_frame = { .identifier = ID_PEDALS, .dataFrame = {0x01, 0x01} };
187 : : :
188 : : 1 : updateInternalPedalsState(captured_frame);
189 : : :
190 : : : // Test: Accelerator pedal should be ON, Brake pedal should be ON
191 : : 1 : checkPedalState(true, true);
192 : : 1 : }
193 : : :
194 : : : /**
195 : : : * @brief Test Case TC_AEB_CTRL_003: Accelerator pedal OFF, Brake pedal OFF.
196 : : : *
197 : : : * This test case verifies that when both the accelerator pedal and the brake pedal are OFF,
198 : : : * the internal state of the AEB system is updated accordingly. Specifically, the function
199 : : : * `updateInternalPedalsState` is called with the given CAN message, and the expected behavior
200 : : : * is that both the accelerator pedal state and the brake pedal state are set to OFF.
201 : : : *
202 : : : * @details
203 : : : * The CAN message data used in this test is:
204 : : : * - Accelerator pedal: OFF (0x00)
205 : : : * - Brake pedal: OFF (0x00)
206 : : : * The test asserts that the internal AEB system state reflects these conditions correctly.
207 : : : *
208 : : : * @pre The internal state of the AEB system is initialized.
209 : : : * @post The internal state of the AEB system reflects the changes: accelerator OFF, brake OFF.
210 : : : *
211 : : : * @anchor TC_AEB_CTRL_003
212 : : : */
213 : : 1 : void test_TC_AEB_CTRL_003(void) {
214 : : 1 : can_msg captured_frame = { .identifier = ID_PEDALS, .dataFrame = {0x00, 0x00} };
215 : : :
216 : : 1 : updateInternalPedalsState(captured_frame);
217 : : :
218 : : : // Test: Accelerator pedal should be OFF, Brake pedal should be OFF
219 : : 1 : checkPedalState(false, false);
220 : : 1 : }
221 : : :
222 : : : /**
223 : : : * @brief Test Case TC_AEB_CTRL_004: Accelerator pedal OFF, Brake pedal ON.
224 : : : *
225 : : : * This test case verifies that when the accelerator pedal is OFF and the brake pedal is ON,
226 : : : * the internal state of the AEB system is updated accordingly. Specifically, the function
227 : : : * `updateInternalPedalsState` is called with the given CAN message, and the expected behavior
228 : : : * is that the accelerator pedal state is set to OFF and the brake pedal state is set to ON.
229 : : : *
230 : : : * @details
231 : : : * The CAN message data used in this test is:
232 : : : * - Accelerator pedal: OFF (0x00)
233 : : : * - Brake pedal: ON (0x01)
234 : : : * The test asserts that the internal AEB system state reflects these conditions correctly.
235 : : : *
236 : : : * @pre The internal state of the AEB system is initialized.
237 : : : * @post The internal state of the AEB system reflects the changes: accelerator OFF, brake ON.
238 : : : *
239 : : : * @anchor TC_AEB_CTRL_004
240 : : : */
241 : : 1 : void test_TC_AEB_CTRL_004(void) {
242 : : 1 : can_msg captured_frame = { .identifier = ID_PEDALS, .dataFrame = {0x00, 0x01} };
243 : : :
244 : : 1 : updateInternalPedalsState(captured_frame);
245 : : :
246 : : : // Test: Accelerator pedal should be OFF, Brake pedal should be ON
247 : : 1 : checkPedalState(false, true);
248 : : 1 : }
249 : : :
250 : : : /**
251 : : : * @brief Helper function to check the relative velocity and reverse_enabled state.
252 : : : *
253 : : : * This function verifies the internal state of the relative velocity and the reverse_enabled
254 : : : * flag in the AEB system by comparing the actual state with the expected values. It asserts
255 : : : * that the internal state for both the relative velocity and the reverse_enabled flag is
256 : : : * correctly set based on the expected values.
257 : : : *
258 : : : * @param expected_velocity Expected relative velocity of the vehicle.
259 : : : * @param expected_reverse_enabled Expected state of reverse_enabled (true for enabled, false for disabled).
260 : : : *
261 : : : * @details
262 : : : * This helper function compares the actual internal states of the relative velocity and
263 : : : * reverse_enabled in the AEB system (`aeb_internal_state`) with the expected values. It checks
264 : : : * if the reverse_enabled state matches the expected state (ON/OFF) and if the relative velocity
265 : : : * matches the expected value. The relative velocity is verified using the `TEST_ASSERT_EQUAL_FLOAT`
266 : : : * assertion, and the reverse_enabled state is verified using `TEST_ASSERT_TRUE` or `TEST_ASSERT_FALSE`,
267 : : : * depending on the expected value.
268 : : : *
269 : : : * @pre The internal state of the AEB system has been updated with the latest speed and reverse data.
270 : : : * @post The test verifies that the internal state reflects the expected relative velocity and reverse_enabled state.
271 : : : */
272 : : 6 : void checkSpeedState(float expected_velocity, bool expected_reverse_enabled) {
273 [ + + ]: [ T F ]: 6 : if (expected_reverse_enabled){
274 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(aeb_internal_state.reverse_enabled);
275 : : : } else{
276 [ - + ]: [ T f ]: 5 : TEST_ASSERT_FALSE(aeb_internal_state.reverse_enabled);
277 : : : }
278 : : 6 : TEST_ASSERT_EQUAL_FLOAT(expected_velocity, aeb_internal_state.relative_velocity);
279 : : 6 : }
280 : : :
281 : : : /**
282 : : : * @brief Test Case TC_AEB_CTRL_005: Normal case where the speed is updated correctly.
283 : : : *
284 : : : * This test case simulates the reception of a CAN message for speed with the
285 : : : * data frame `{0x00, 0x64, 0x00}`. It tests the behavior of the AEB system
286 : : : * when the speed is updated correctly, ensuring that the relative velocity
287 : : : * is computed and stored properly based on the received CAN message.
288 : : : *
289 : : : * The speed is calculated as `(0x64 + (0x00 << 8)) * RES_SPEED_S`, which
290 : : : * should result in a relative velocity of `100.0`.
291 : : : *
292 : : : * @details
293 : : : * The test simulates a scenario where the vehicle's speed is received through a CAN message,
294 : : : * and the internal speed state is updated accordingly. The test verifies that the speed value
295 : : : * is correctly computed and stored in the AEB system's internal state. The expected outcome
296 : : : * is that the relative velocity should be `100.0` km/h, and the reverse flag (`reverse_enabled`)
297 : : : * should be `false`.
298 : : : *
299 : : : * @pre The AEB system is in an initialized state with default values.
300 : : : * @post The relative velocity in the internal state is updated to the expected value,
301 : : : * and the reverse flag remains false.
302 : : : *
303 : : : * @anchor TC_AEB_CTRL_005
304 : : : */
305 : : 1 : void test_TC_AEB_CTRL_005(void) {
306 : : 1 : can_msg captured_frame = { .identifier = ID_SPEED_S, .dataFrame = {0x00, 0x64, 0x00} };
307 : : :
308 : : 1 : updateInternalSpeedState(captured_frame);
309 : : :
310 : : : // Test: Speed should be updated correctly (0x64 + (0x00 << 8)) * RES_SPEED_S = 100.0
311 : : 1 : checkSpeedState(100.0, false);
312 : : 1 : }
313 : : :
314 : : : /**
315 : : : * @brief Test Case TC_AEB_CTRL_006: Case where the CAN data is set to clear data (0xFE, 0xFF).
316 : : : *
317 : : : * This test case simulates the reception of a CAN message with the data frame
318 : : : * `{0xFE, 0xFF, 0x00}`. It tests the behavior of the AEB system when the
319 : : : * CAN data is set to clear data (0xFE, 0xFF), which should trigger the system
320 : : : * to reset the speed to `0.0` and disable the reverse flag (`reverse_enabled`).
321 : : : *
322 : : : * @details
323 : : : * The test ensures that when the CAN message with the clear data flag (`0xFE, 0xFF`)
324 : : : * is received, the internal state of the AEB system resets the relative velocity to `0.0`
325 : : : * and sets the reverse_enabled flag to `false`. This is essential for ensuring that the
326 : : : * system behaves correctly when invalid or reset data is received.
327 : : : *
328 : : : * @pre The AEB system is initialized and the internal state has a valid velocity and reverse flag.
329 : : : * @post The relative velocity in the internal state is reset to `0.0`, and the reverse flag
330 : : : * is set to `false`, as expected when the clear data signal is detected.
331 : : : *
332 : : : * @anchor TC_AEB_CTRL_006
333 : : : */
334 : : 1 : void test_TC_AEB_CTRL_006(void) {
335 : : 1 : can_msg captured_frame = { .identifier = ID_SPEED_S, .dataFrame = {0xFE, 0xFF, 0x00} };
336 : : :
337 : : 1 : updateInternalSpeedState(captured_frame);
338 : : :
339 : : : // Test: Speed should reset to 0.0, and reverse_enabled should be false
340 : : 1 : checkSpeedState(0.0, false);
341 : : 1 : }
342 : : :
343 : : : /**
344 : : : * @brief Test Case TC_AEB_CTRL_007: Case where the CAN data is set to indicate
345 : : : * reverse (0x01 in dataFrame[2]).
346 : : : *
347 : : : * This test case simulates the reception of a CAN message with the data frame
348 : : : * `{0x00, 0x14, 0x01}`. It tests the behavior of the AEB system when the
349 : : : * CAN data indicates reverse operation (0x01 in `dataFrame[2]`). The expected
350 : : : * outcome is that the system should enable the reverse flag (`reverse_enabled = true`),
351 : : : * and the speed should be calculated as `(0x00 + (0x14 << 8)) * RES_SPEED_S`,
352 : : : * resulting in a relative velocity of `20.0`.
353 : : : *
354 : : : * @details
355 : : : * The test ensures that when the CAN message indicates reverse operation by setting
356 : : : * `dataFrame[2]` to `0x01`, the system correctly updates the reverse_enabled flag
357 : : : * and calculates the relative velocity based on the data in `dataFrame[0]` and `dataFrame[1]`.
358 : : : * The speed calculation is based on the formula `(0x00 + (0x14 << 8)) * RES_SPEED_S`,
359 : : : * which results in `20.0` km/h.
360 : : : *
361 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
362 : : : * @post The relative velocity is updated to `20.0`, and the reverse flag is enabled (`reverse_enabled = true`).
363 : : : *
364 : : : * @anchor TC_AEB_CTRL_007
365 : : : */
366 : : 1 : void test_TC_AEB_CTRL_007(void) {
367 : : 1 : can_msg captured_frame = { .identifier = ID_SPEED_S, .dataFrame = {0x00, 0x14, 0x01} };
368 : : :
369 : : 1 : updateInternalSpeedState(captured_frame);
370 : : :
371 : : : // Test: Reverse should be enabled (0x00 + (0x14 << 8)) * RES_SPEED_S = 20.0
372 : : 1 : checkSpeedState(20.0, true);
373 : : 1 : }
374 : : :
375 : : : /**
376 : : : * @brief Test Case TC_AEB_CTRL_008: Max speed value constraint (should be capped at 251.0).
377 : : : *
378 : : : * This test case simulates the reception of a CAN message with the data frame
379 : : : * `{0xFF, 0xFD, 0x00}`, which corresponds to the maximum possible speed value
380 : : : * according to the CAN protocol. The test verifies that the AEB system correctly
381 : : : * applies a speed cap, limiting the relative velocity to a maximum of `251.0` km/h.
382 : : : *
383 : : : * @details
384 : : : * The CAN message has the data frame `{0xFF, 0xFD, 0x00}`, where the first two
385 : : : * bytes are used to represent the speed value in the system. The speed calculation
386 : : : * will result in a value that exceeds the predefined maximum limit for speed.
387 : : : * The system should apply a constraint and cap the speed at `251.0`, ensuring that
388 : : : * the calculated relative velocity does not exceed this limit.
389 : : : *
390 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
391 : : : * @post The relative velocity is capped at `251.0`, as the calculated value exceeds the max limit.
392 : : : *
393 : : : * @anchor TC_AEB_CTRL_008
394 : : : */
395 : : 1 : void test_TC_AEB_CTRL_008(void) {
396 : : 1 : can_msg captured_frame = { .identifier = ID_SPEED_S, .dataFrame = {0xFF, 0xFD, 0x00} };
397 : : :
398 : : 1 : updateInternalSpeedState(captured_frame);
399 : : :
400 : : : // Test: Speed should be capped at 251.0
401 : : 1 : checkSpeedState(251.0, false);
402 : : 1 : }
403 : : :
404 : : : /**
405 : : : * @brief Test Case TC_AEB_CTRL_009: Test when the CAN frame data doesn't require any
406 : : : * action (0xFF, 0xFF in dataFrame[0] and dataFrame[1]).
407 : : : *
408 : : : * This test case simulates the reception of a CAN message with the data frame
409 : : : * `{0xFF, 0xFF, 0x00}`, which represents a situation where the CAN message does
410 : : : * not require any action or change in the internal state of the AEB system.
411 : : : * The test ensures that the system correctly handles this scenario by keeping the
412 : : : * relative velocity at `0.0` and leaving the `reverse_enabled` state unchanged (false).
413 : : : *
414 : : : * @details
415 : : : * The data frame `{0xFF, 0xFF, 0x00}` indicates that there is no meaningful update
416 : : : * required for the AEB system. The system should not modify the relative velocity
417 : : : * or enable reverse mode based on this input. The expected outcome is that the
418 : : : * relative velocity remains at `0.0` and `reverse_enabled` remains false.
419 : : : *
420 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
421 : : : * @post The relative velocity should remain `0.0`, and `reverse_enabled` should remain false.
422 : : : *
423 : : : * @anchor TC_AEB_CTRL_009
424 : : : */
425 : : 1 : void test_TC_AEB_CTRL_009(void) {
426 : : 1 : can_msg captured_frame = { .identifier = ID_SPEED_S, .dataFrame = {0xFF, 0xFF, 0x00} };
427 : : :
428 : : 1 : updateInternalSpeedState(captured_frame);
429 : : :
430 : : : // Test: Speed should be 0.0, reverse_enabled should remain false
431 : : 1 : checkSpeedState(0.0, false);
432 : : 1 : }
433 : : :
434 : : : /**
435 : : : * @brief Test Case: Ensure that reverse_enabled remains false for non-reverse signals.
436 : : : *
437 : : : * This test case simulates the reception of a CAN message with the data frame
438 : : : * `{0x00, 0x64, 0x03}`, where the third byte (dataFrame[2]) contains a non-reverse
439 : : : * signal. The test verifies that the `reverse_enabled` flag remains false, even if
440 : : : * the other data values indicate the vehicle's speed (100.0).
441 : : : *
442 : : : * @details
443 : : : * The CAN data `{0x00, 0x64, 0x03}` indicates that the vehicle is moving at a speed
444 : : : * of 100.0 km/h, but the signal in `dataFrame[2]` (with a value of `0x03`) is not a
445 : : : * reverse signal. As a result, the system should ensure that the `reverse_enabled`
446 : : : * flag remains false and only updates the speed as calculated from the first two
447 : : : * bytes of the data frame.
448 : : : *
449 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
450 : : : * @post The relative velocity should be 100.0, and `reverse_enabled` should remain false.
451 : : : *
452 : : : * @anchor TC_AEB_CTRL_X01
453 : : : */
454 : : 1 : void test_TC_AEB_CTRL_X01(void) {
455 : : 1 : can_msg captured_frame = { .identifier = ID_SPEED_S, .dataFrame = {0x00, 0x64, 0x03} };
456 : : :
457 : : 1 : updateInternalSpeedState(captured_frame);
458 : : :
459 : : : // Test: Reverse should not be enabled for non-reverse signals
460 : : 1 : checkSpeedState(100.0, false);
461 : : 1 : }
462 : : :
463 : : : /**
464 : : : * @brief Helper function to check the obstacle state.
465 : : : *
466 : : : * This helper function checks the state of the `has_obstacle` flag and the calculated
467 : : : * distance to the obstacle. It compares the actual internal state of the AEB system
468 : : : * with the expected values passed as arguments.
469 : : : *
470 : : : * @param expected_has_obstacle Expected state of the `has_obstacle` flag (true if obstacle detected, false otherwise).
471 : : : * @param expected_distance Expected distance to the obstacle (in meters).
472 : : : *
473 : : : * @pre The `aeb_internal_state` must be initialized.
474 : : : * @post The function will assert that the `has_obstacle` flag matches the expected value
475 : : : * and that the `obstacle_distance` is equal to the expected distance.
476 : : : */
477 : : 8 : void checkObstacleState(bool expected_has_obstacle, float expected_distance) {
478 [ + + ]: [ T F ]: 8 : if (expected_has_obstacle){
479 [ - + ]: [ T f ]: 4 : TEST_ASSERT_TRUE(aeb_internal_state.has_obstacle);
480 : : : } else {
481 [ - + ]: [ T f ]: 4 : TEST_ASSERT_FALSE(aeb_internal_state.has_obstacle);
482 : : : }
483 : : 8 : TEST_ASSERT_EQUAL_FLOAT(expected_distance, aeb_internal_state.obstacle_distance);
484 : : 8 : }
485 : : :
486 : : : /**
487 : : : * @brief Test Case TC_AEB_CTRL_010: Obstacle detected and distance calculated correctly.
488 : : : *
489 : : : * This test case simulates a situation where an obstacle is detected, and the system
490 : : : * correctly calculates the distance to the obstacle using the CAN data.
491 : : : * The expected obstacle distance is calculated as:
492 : : : *
493 : : : * @code
494 : : : * Expected distance = (0xD0 + (0x07 << 8)) * RES_OBSTACLE = 100.0
495 : : : * @endcode
496 : : : *
497 : : : * @details
498 : : : * The data frame `{0xD0, 0x07, 0x01}` represents an obstacle detected at a distance
499 : : : * of 100 meters. The test ensures that the AEB system correctly calculates the distance
500 : : : * and updates the internal state to reflect the presence of an obstacle.
501 : : : *
502 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
503 : : : * @post The `has_obstacle` flag should be true, and `obstacle_distance` should be 100.0.
504 : : : *
505 : : : * @anchor TC_AEB_CTRL_010
506 : : : */
507 : : 1 : void test_TC_AEB_CTRL_010(void) {
508 : : 1 : can_msg captured_frame = { .identifier = ID_OBSTACLE_S, .dataFrame = {0xD0, 0x07, 0x01} };
509 : : :
510 : : 1 : updateInternalObstacleState(captured_frame);
511 : : :
512 : : : // Test: Expected distance = (0xD0 + (0x07 << 8)) * RES_OBSTACLE = 100.0
513 : : 1 : checkObstacleState(true, 100.0);
514 : : 1 : }
515 : : :
516 : : : /**
517 : : : * @brief Test Case TC_AEB_CTRL_011: No obstacle (0x00 in dataFrame[2]).
518 : : : *
519 : : : * This test case simulates a situation where no obstacle is detected, and the system
520 : : : * should reset the obstacle distance to the maximum value (300.0 meters).
521 : : : *
522 : : : * @details
523 : : : * The data frame `{0xD0, 0x07, 0x00}` indicates that there is no obstacle detected (since
524 : : : * `dataFrame[2] == 0x00`). The test ensures that the AEB system correctly handles the
525 : : : * absence of an obstacle by setting the `has_obstacle` flag to false and the obstacle
526 : : : * distance to the maximum value of 300.0 meters.
527 : : : *
528 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
529 : : : * @post The `has_obstacle` flag should be false, and `obstacle_distance` should be 300.0.
530 : : : *
531 : : : * @anchor TC_AEB_CTRL_011
532 : : : */
533 : : 1 : void test_TC_AEB_CTRL_011(void) {
534 : : 1 : can_msg captured_frame = { .identifier = ID_OBSTACLE_S, .dataFrame = {0xD0, 0x07, 0x00} };
535 : : :
536 : : 1 : updateInternalObstacleState(captured_frame);
537 : : :
538 : : : // Test: No obstacle detected, distance should remain the same (max distance)
539 : : 1 : checkObstacleState(false, 300.0); // Max distance when no obstacle is detected
540 : : 1 : }
541 : : :
542 : : : /**
543 : : : * @brief Test Case TC_AEB_CTRL_012: Data reset with 0xFE, 0xFF.
544 : : : *
545 : : : * This test case simulates a situation where the CAN data indicates a reset action,
546 : : : * represented by the data frame `{0xFE, 0xFF, 0x00}`. When this data is received,
547 : : : * the obstacle detection system should reset the obstacle distance to the maximum
548 : : : * value (300.0 meters) and mark the obstacle as not detected.
549 : : : *
550 : : : * @details
551 : : : * The data frame `{0xFE, 0xFF, 0x00}` is used to trigger the reset of the obstacle
552 : : : * detection system. The test ensures that the system correctly handles this case by
553 : : : * resetting the obstacle distance and setting `has_obstacle` to false.
554 : : : *
555 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
556 : : : * @post The `has_obstacle` flag should be false, and `obstacle_distance` should be 300.0.
557 : : : *
558 : : : * @anchor TC_AEB_CTRL_012
559 : : : */
560 : : 1 : void test_TC_AEB_CTRL_012(void) {
561 : : 1 : can_msg captured_frame = { .identifier = ID_OBSTACLE_S, .dataFrame = {0xFE, 0xFF, 0x00} };
562 : : :
563 : : 1 : updateInternalObstacleState(captured_frame);
564 : : :
565 : : : // Test: Obstacle not detected, reset distance to max value (300.0)
566 : : 1 : checkObstacleState(false, 300.0);
567 : : 1 : }
568 : : :
569 : : : /**
570 : : : * @brief Test Case TC_AEB_CTRL_X02: Case where data doesn't need action (0xFF, 0xFF).
571 : : : *
572 : : : * This test case checks the scenario where the CAN data contains `{0xFF, 0xFF, 0x00}`,
573 : : : * which indicates that no action needs to be taken by the system. The obstacle detection
574 : : : * system should keep the current state, and the obstacle distance should remain at the
575 : : : * maximum value (300.0 meters) with no obstacle detected.
576 : : : *
577 : : : * @details
578 : : : * The data frame `{0xFF, 0xFF, 0x00}` indicates that no updates are required for the
579 : : : * obstacle detection system. The test ensures that the system does not alter its state
580 : : : * and that the distance remains set to 300.0 meters when no obstacle is detected.
581 : : : *
582 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
583 : : : * @post The `has_obstacle` flag should be false, and `obstacle_distance` should remain 300.0.
584 : : : *
585 : : : * @anchor TC_AEB_CTRL_X02
586 : : : */
587 : : 1 : void test_TC_AEB_CTRL_X02(void) {
588 : : 1 : can_msg captured_frame = { .identifier = ID_OBSTACLE_S, .dataFrame = {0xFF, 0xFF, 0x00} };
589 : : :
590 : : 1 : updateInternalObstacleState(captured_frame);
591 : : :
592 : : : // Test: Obstacle not detected, distance should be reset to 300.0
593 : : 1 : checkObstacleState(false, 300.0);
594 : : 1 : }
595 : : :
596 : : : /**
597 : : : * @brief Test Case TC_AEB_CTRL_X03: Calculated distance from CAN data.
598 : : : *
599 : : : * This test case simulates a situation where the obstacle data is received from the
600 : : : * CAN bus and the distance is correctly calculated based on the data in the frame.
601 : : : * The data frame `{0xD0, 0x07, 0x01}` represents an obstacle detected at a calculated
602 : : : * distance of 100 meters.
603 : : : *
604 : : : * @details
605 : : : * The data frame `{0xD0, 0x07, 0x01}` represents an obstacle detected at a distance
606 : : : * of 100 meters. The test ensures that the system correctly calculates the distance
607 : : : * based on the CAN data and updates the internal state to reflect the presence of an
608 : : : * obstacle at the correct distance.
609 : : : *
610 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
611 : : : * @post The `has_obstacle` flag should be true, and `obstacle_distance` should be 100.0.
612 : : : *
613 : : : * @anchor TC_AEB_CTRL_X03
614 : : : */
615 : : 1 : void test_TC_AEB_CTRL_X03(void) {
616 : : 1 : can_msg captured_frame = { .identifier = ID_OBSTACLE_S, .dataFrame = {0xD0, 0x07, 0x01} };
617 : : :
618 : : 1 : updateInternalObstacleState(captured_frame);
619 : : :
620 : : : // Test: Obstacle detected, distance should be correctly calculated
621 : : 1 : checkObstacleState(true, 100.0);
622 : : 1 : }
623 : : :
624 : : : /**
625 : : : * @brief Test Case TC_AEB_CTRL_013: Maximum distance capped at 300.0.
626 : : : *
627 : : : * This test case simulates a scenario where the CAN data exceeds the maximum allowed
628 : : : * distance value. The system should cap the obstacle distance to 300.0 meters when
629 : : : * the received data exceeds this limit.
630 : : : *
631 : : : * @details
632 : : : * The test case uses the data frame `{0xFF, 0xFD, 0x00}` to simulate a situation where
633 : : : * the obstacle distance exceeds the allowed maximum value. The expected behavior is that
634 : : : * the system should cap the distance at 300.0 meters.
635 : : : *
636 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
637 : : : * @post The `has_obstacle` flag should be false, and the `obstacle_distance` should be capped at 300.0.
638 : : : *
639 : : : * @anchor TC_AEB_CTRL_013
640 : : : */
641 : : 1 : void test_TC_AEB_CTRL_013(void) {
642 : : 1 : can_msg captured_frame = { .identifier = ID_OBSTACLE_S, .dataFrame = {0xFF, 0xFD, 0x00} };
643 : : :
644 : : 1 : updateInternalObstacleState(captured_frame);
645 : : :
646 : : : // Test: Distance should be capped at 300.0 when CAN data exceeds max
647 : : 1 : checkObstacleState(false, 300.0);
648 : : 1 : }
649 : : :
650 : : : /**
651 : : : * @brief Helper function to check the AEB system state.
652 : : : *
653 : : : * This helper function verifies whether the AEB system is turned ON or OFF by
654 : : : * checking the `aeb_system_enabled` flag in the internal AEB state.
655 : : : *
656 : : : * @param expected_state Expected state of the AEB system (ON/OFF).
657 : : : *
658 : : : * @details
659 : : : * This function compares the expected state of the AEB system (ON/OFF) with the
660 : : : * actual state held in the `aeb_internal_state.aeb_system_enabled` flag. It asserts
661 : : : * whether the state matches the expected state.
662 : : : *
663 : : : * @pre The AEB system's internal state must be initialized.
664 : : : * @post If the expected state matches the actual state, the test will pass.
665 : : : */
666 : : 4 : void checkAEBSystemState(bool expected_state) {
667 [ + + ]: [ T F ]: 4 : if (expected_state){
668 [ - + ]: [ T f ]: 2 : TEST_ASSERT_TRUE(aeb_internal_state.aeb_system_enabled);
669 : : : } else {
670 [ - + ]: [ T f ]: 2 : TEST_ASSERT_FALSE(aeb_internal_state.aeb_system_enabled);
671 : : : }
672 : : 4 : }
673 : : :
674 : : : /**
675 : : : * @brief Test Case TC_AEB_CTRL_014: AEB system ON (dataFrame[0] == 0x01).
676 : : : *
677 : : : * This test case checks the functionality of the AEB system when it is turned ON.
678 : : : * It simulates the reception of a CAN message where the `dataFrame[0]` is set to
679 : : : * `0x01`, which indicates that the AEB system should be activated.
680 : : : *
681 : : : * @details
682 : : : * The test case uses the data frame `{0x01}` to indicate that the AEB system is
683 : : : * turned ON. The expected behavior is that the `aeb_system_enabled` flag in the
684 : : : * `aeb_internal_state` should be set to `true`, indicating the system is active.
685 : : : *
686 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
687 : : : * @post The `aeb_system_enabled` flag should be set to true, indicating that the AEB system is ON.
688 : : : *
689 : : : * @anchor TC_AEB_CTRL_014
690 : : : */
691 : : 1 : void test_TC_AEB_CTRL_014(void) {
692 : : 1 : can_msg captured_frame = { .identifier = ID_CAR_C, .dataFrame = {0x01} };
693 : : :
694 : : 1 : updateInternalCarCState(captured_frame);
695 : : :
696 : : : // Test: AEB system should be ON when dataFrame[0] is 0x01
697 : : 1 : checkAEBSystemState(true);
698 : : 1 : }
699 : : :
700 : : : /**
701 : : : * @brief Test Case TC_AEB_CTRL_015: AEB system OFF (dataFrame[0] == 0x00).
702 : : : *
703 : : : * This test case simulates a scenario where the AEB system is turned OFF by setting
704 : : : * `dataFrame[0]` to `0x00`. The system should deactivate the AEB system by setting
705 : : : * the `aeb_system_enabled` flag to `false`.
706 : : : *
707 : : : * @details
708 : : : * The test case uses the data frame `{0x00}` to indicate that the AEB system should be
709 : : : * turned OFF. The expected behavior is that the `aeb_system_enabled` flag in the
710 : : : * `aeb_internal_state` should be set to `false`.
711 : : : *
712 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
713 : : : * @post The `aeb_system_enabled` flag should be set to false, indicating that the AEB system is OFF.
714 : : : *
715 : : : * @anchor TC_AEB_CTRL_015
716 : : : */
717 : : 1 : void test_TC_AEB_CTRL_015(void) {
718 : : 1 : can_msg captured_frame = { .identifier = ID_CAR_C, .dataFrame = {0x00} };
719 : : :
720 : : 1 : updateInternalCarCState(captured_frame);
721 : : :
722 : : : // Test: AEB system should be OFF when dataFrame[0] is 0x00
723 : : 1 : checkAEBSystemState(false);
724 : : 1 : }
725 : : :
726 : : : /**
727 : : : * @brief Test Case: AEB system remains OFF for any value other than 0x01.
728 : : : *
729 : : : * This test case ensures that the AEB system remains OFF for any value other than `0x01`
730 : : : * in the `dataFrame[0]` field. If a value other than `0x01` is received, the system should
731 : : : * not activate the AEB system and the `aeb_system_enabled` flag should remain `false`.
732 : : : *
733 : : : * @details
734 : : : * The test case uses an arbitrary value (`0x02`) in the `dataFrame[0]` to simulate a
735 : : : * non-activation condition. The expected behavior is that the `aeb_system_enabled` flag
736 : : : * remains `false`.
737 : : : *
738 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
739 : : : * @post The `aeb_system_enabled` flag should remain false for any value other than 0x01.
740 : : : *
741 : : : * @anchor TC_AEB_CTRL_X04
742 : : : */
743 : : 1 : void test_TC_AEB_CTRL_X04(void) {
744 : : 1 : can_msg captured_frame = { .identifier = ID_CAR_C, .dataFrame = {0x02} }; // Arbitrary value different from 0x01
745 : : :
746 : : 1 : updateInternalCarCState(captured_frame);
747 : : :
748 : : : // Test: AEB system should remain OFF for any value other than 0x01
749 : : 1 : checkAEBSystemState(false);
750 : : 1 : }
751 : : :
752 : : : /**
753 : : : * @brief Test Case: AEB system turns back ON when dataFrame[0] is 0x01 again.
754 : : : *
755 : : : * This test case ensures that the AEB system can be turned ON again when the
756 : : : * `dataFrame[0]` is set to `0x01`. This test simulates a scenario where the AEB
757 : : : * system is initially turned off and then re-enabled by receiving the correct
758 : : : * `dataFrame` value.
759 : : : *
760 : : : * @details
761 : : : * The test case uses the data frame `{0x01}` to simulate the reactivation of the AEB system.
762 : : : * The expected behavior is that the `aeb_system_enabled` flag in the `aeb_internal_state`
763 : : : * should be set to `true`, indicating that the AEB system is turned ON.
764 : : : *
765 : : : * @pre The AEB system is initialized and ready to receive CAN messages.
766 : : : * @post The `aeb_system_enabled` flag should be set to true, indicating that the AEB system is back ON.
767 : : : *
768 : : : * @anchor TC_AEB_CTRL_X05
769 : : : */
770 : : 1 : void test_TC_AEB_CTRL_X05(void) {
771 : : 1 : can_msg captured_frame = { .identifier = ID_CAR_C, .dataFrame = {0x01} };
772 : : :
773 : : 1 : updateInternalCarCState(captured_frame);
774 : : :
775 : : : // Test: AEB system should be back ON when dataFrame[0] is 0x01 again
776 : : 1 : checkAEBSystemState(true);
777 : : 1 : }
778 : : :
779 : : : /**
780 : : : * @brief Helper function to check the AEB state.
781 : : : *
782 : : : * This function compares the expected state of the AEB system with the actual state
783 : : : * returned by the `getAEBState` function. It is used in test cases to verify that
784 : : : * the AEB system is in the expected state.
785 : : : *
786 : : : * @param expected_state The expected state of the AEB system, which should be one of
787 : : : * the values in the `aeb_controller_state` enumeration.
788 : : : * @param state The actual state returned by `getAEBState`, which will be compared
789 : : : * to the expected state.
790 : : : */
791 : : 14 : void checkAEBState(aeb_controller_state expected_state, aeb_controller_state state) {
792 : : 14 : TEST_ASSERT_EQUAL_INT(expected_state, state);
793 : : 14 : }
794 : : :
795 : : : /**
796 : : : * @brief Test Case: AEB system active and TTC indicating alarm state.
797 : : : *
798 : : : * This test case simulates a scenario where the AEB system is active, an obstacle
799 : : : * is detected, and the Time to Collision (TTC) value indicates that the AEB system
800 : : : * should enter the ALARM state. The expected behavior is that the AEB system will
801 : : : * activate the alarm but not yet apply the brakes.
802 : : : *
803 : : : * @details
804 : : : * The test uses the following inputs:
805 : : : * - `relative_velocity` set to the maximum speed enabled (`MAX_SPD_ENABLED`).
806 : : : * - `has_obstacle` set to true, indicating that an obstacle is detected.
807 : : : * - `obstacle_distance` set to 10.0 meters.
808 : : : * - `aeb_system_enabled` set to true, ensuring the AEB system is active.
809 : : : * - `reverse_enabled` set to false, indicating the vehicle is not in reverse.
810 : : : *
811 : : : * The TTC value of `1.9` will be used to simulate a scenario where the AEB system
812 : : : * should enter the ALARM state.
813 : : : *
814 : : : * @pre The AEB system is initialized and active, and the sensor data is provided.
815 : : : * @post The AEB system should be in the ALARM state.
816 : : : *
817 : : : * @anchor TC_AEB_CTRL_X06
818 : : : */
819 : : 1 : void test_TC_AEB_CTRL_X06(void) {
820 : : 1 : aeb_internal_state.relative_velocity = MAX_SPD_ENABLED;
821 : : 1 : aeb_internal_state.has_obstacle = true;
822 : : 1 : aeb_internal_state.obstacle_distance = 10.0;
823 : : 1 : aeb_internal_state.aeb_system_enabled = true;
824 : : 1 : aeb_internal_state.reverse_enabled = false;
825 : : :
826 : : 1 : double ttc = 1.9;
827 : : 1 : aeb_controller_state state = getAEBState(aeb_internal_state, ttc);
828 : : :
829 : : : // Test: AEB system should be in ALARM state
830 : : 1 : checkAEBState(AEB_STATE_ALARM, state);
831 : : 1 : }
832 : : :
833 : : : /**
834 : : : * @brief Test Case: AEB system active, but TTC too low (should go to brake state).
835 : : : *
836 : : : * This test case simulates a scenario where the AEB system is active, an obstacle
837 : : : * is detected, but the Time to Collision (TTC) value is too low, indicating that
838 : : : * the AEB system should apply the brakes. The expected behavior is that the AEB system
839 : : : * should transition to the BRAKE state.
840 : : : *
841 : : : * @details
842 : : : * The test uses the following inputs:
843 : : : * - `relative_velocity` set to the maximum speed enabled (`MAX_SPD_ENABLED`).
844 : : : * - `has_obstacle` set to true, indicating that an obstacle is detected.
845 : : : * - `obstacle_distance` set to 10.0 meters.
846 : : : * - `aeb_system_enabled` set to true, ensuring the AEB system is active.
847 : : : * - `reverse_enabled` set to false, indicating the vehicle is not in reverse.
848 : : : *
849 : : : * The TTC value of `0.9` is used to simulate a scenario where the TTC is too low
850 : : : * to avoid a collision, so the AEB system should go into the BRAKE state.
851 : : : *
852 : : : * @pre The AEB system is initialized and active, and the sensor data is provided.
853 : : : * @post The AEB system should be in the BRAKE state.
854 : : : *
855 : : : * @anchor TC_AEB_CTRL_X07
856 : : : */
857 : : 1 : void test_TC_AEB_CTRL_X07(void) {
858 : : 1 : aeb_internal_state.relative_velocity = MAX_SPD_ENABLED;
859 : : 1 : aeb_internal_state.has_obstacle = true;
860 : : 1 : aeb_internal_state.obstacle_distance = 10.0;
861 : : 1 : aeb_internal_state.aeb_system_enabled = true;
862 : : 1 : aeb_internal_state.reverse_enabled = false;
863 : : :
864 : : 1 : double ttc = 0.9;
865 : : 1 : aeb_controller_state state = getAEBState(aeb_internal_state, ttc);
866 : : :
867 : : : // Test: AEB system should go to BRAKE state if speed is high and TTC low
868 : : 1 : checkAEBState(AEB_STATE_BRAKE, state);
869 : : 1 : }
870 : : :
871 : : : /**
872 : : : * @brief Test Case: AEB system OFF (aeb_system_enabled == false, high speed).
873 : : : *
874 : : : * This test case simulates a scenario where the AEB system is turned OFF,
875 : : : * and the vehicle is traveling at high speed. The expected behavior is that
876 : : : * the AEB system will not engage, and the system should remain in the STANDBY state.
877 : : : *
878 : : : * @details
879 : : : * The test uses the following inputs:
880 : : : * - `relative_velocity` set to 80.0 (high speed).
881 : : : * - `has_obstacle` set to true, indicating that an obstacle is detected.
882 : : : * - `obstacle_distance` set to 10.0 meters.
883 : : : * - `aeb_system_enabled` set to false, deactivating the AEB system.
884 : : : * - `reverse_enabled` set to false, indicating the vehicle is not in reverse.
885 : : : *
886 : : : * The TTC value of `1.9` will be used to simulate a situation where the AEB system is inactive,
887 : : : * and the system should remain in the STANDBY state.
888 : : : *
889 : : : * @pre The AEB system is initialized with the specified values and the sensor data is provided.
890 : : : * @post The AEB system should be in the STANDBY state.
891 : : : *
892 : : : * @anchor TC_AEB_CTRL_X08
893 : : : */
894 : : 1 : void test_TC_AEB_CTRL_X08(void) {
895 : : 1 : aeb_internal_state.relative_velocity = 80.0;
896 : : 1 : aeb_internal_state.has_obstacle = true;
897 : : 1 : aeb_internal_state.obstacle_distance = 10.0;
898 : : 1 : aeb_internal_state.aeb_system_enabled = false;
899 : : 1 : aeb_internal_state.reverse_enabled = false;
900 : : :
901 : : 1 : double ttc = 1.9;
902 : : 1 : aeb_controller_state state = getAEBState(aeb_internal_state, ttc);
903 : : :
904 : : : // Test: AEB system should be in STANDBY state
905 : : 1 : checkAEBState(AEB_STATE_STANDBY, state);
906 : : 1 : }
907 : : :
908 : : : /**
909 : : : * @brief Test Case: Speed below MIN_SPD_ENABLED and no reverse enabled (should go to STANDBY).
910 : : : *
911 : : : * This test case simulates a scenario where the vehicle's speed is below the minimum
912 : : : * allowed speed (`MIN_SPD_ENABLED`), and the AEB system is active but the vehicle is
913 : : : * not in reverse. The expected behavior is that the AEB system will enter the STANDBY state.
914 : : : *
915 : : : * @details
916 : : : * The test uses the following inputs:
917 : : : * - `relative_velocity` set to a value below `MIN_SPD_ENABLED` (speed below the minimum).
918 : : : * - `has_obstacle` set to true, indicating that an obstacle is detected.
919 : : : * - `obstacle_distance` set to 10.0 meters.
920 : : : * - `aeb_system_enabled` set to true, ensuring the AEB system is active.
921 : : : * - `reverse_enabled` set to false, indicating the vehicle is not in reverse.
922 : : : *
923 : : : * The TTC value of `1.9` is used to simulate a situation where the vehicle is moving at low speed,
924 : : : * so the AEB system should go into the STANDBY state.
925 : : : *
926 : : : * @pre The AEB system is initialized and active, with sensor data provided.
927 : : : * @post The AEB system should be in the STANDBY state due to low speed.
928 : : : *
929 : : : * @anchor TC_AEB_CTRL_X09
930 : : : */
931 : : 1 : void test_TC_AEB_CTRL_X09(void) {
932 : : 1 : aeb_internal_state.relative_velocity = MIN_SPD_ENABLED - 1;
933 : : 1 : aeb_internal_state.has_obstacle = true;
934 : : 1 : aeb_internal_state.obstacle_distance = 10.0;
935 : : 1 : aeb_internal_state.aeb_system_enabled = true;
936 : : 1 : aeb_internal_state.reverse_enabled = false;
937 : : :
938 : : 1 : double ttc = 1.9;
939 : : 1 : aeb_controller_state state = getAEBState(aeb_internal_state, ttc);
940 : : :
941 : : : // Test: AEB system should go to ALARM state, but never to BRAKE state, so that the driver has control of the vehicle
942 : : 1 : checkAEBState(AEB_STATE_ALARM, state);
943 : : :
944 : : 1 : ttc = 0.9;
945 : : 1 : state = getAEBState(aeb_internal_state, ttc);
946 : : 1 : checkAEBState(AEB_STATE_ALARM, state);
947 : : 1 : }
948 : : :
949 : : : /**
950 : : : * @brief Test Case: Speed above MAX_SPD_ENABLED and no reverse enabled (should go to STANDBY).
951 : : : *
952 : : : * This test case simulates a scenario where the vehicle's speed is above the maximum
953 : : : * allowed speed (`MAX_SPD_ENABLED`), and the AEB system is active but the vehicle is
954 : : : * not in reverse. The expected behavior is that the AEB system will enter the STANDBY state.
955 : : : *
956 : : : * @details
957 : : : * The test uses the following inputs:
958 : : : * - `relative_velocity` set to a value above `MAX_SPD_ENABLED` (speed above the maximum).
959 : : : * - `has_obstacle` set to true, indicating that an obstacle is detected.
960 : : : * - `obstacle_distance` set to 10.0 meters.
961 : : : * - `aeb_system_enabled` set to true, ensuring the AEB system is active.
962 : : : * - `reverse_enabled` set to false, indicating the vehicle is not in reverse.
963 : : : *
964 : : : * The TTC value of `1.9` is used to simulate a situation where the vehicle is moving at a speed
965 : : : * above the allowed limit, so the AEB system should go into the STANDBY state.
966 : : : *
967 : : : * @pre The AEB system is initialized and active, with sensor data provided.
968 : : : * @post The AEB system should be in the STANDBY state due to high speed.
969 : : : *
970 : : : * @anchor TC_AEB_CTRL_X10
971 : : : */
972 : : 1 : void test_TC_AEB_CTRL_X10(void) {
973 : : 1 : aeb_internal_state.relative_velocity = MAX_SPD_ENABLED + 1;
974 : : 1 : aeb_internal_state.has_obstacle = true;
975 : : 1 : aeb_internal_state.obstacle_distance = 10.0;
976 : : 1 : aeb_internal_state.aeb_system_enabled = true;
977 : : 1 : aeb_internal_state.reverse_enabled = false;
978 : : :
979 : : 1 : double ttc = 1.9;
980 : : 1 : aeb_controller_state state = getAEBState(aeb_internal_state, ttc);
981 : : :
982 : : : // Test: AEB system should go to ALARM state, but never to BRAKE state, so that the driver has control of the vehicle
983 : : 1 : checkAEBState(AEB_STATE_ALARM, state);
984 : : :
985 : : 1 : ttc = 0.9;
986 : : 1 : state = getAEBState(aeb_internal_state, ttc);
987 : : 1 : checkAEBState(AEB_STATE_ALARM, state);
988 : : 1 : }
989 : : :
990 : : : /**
991 : : : * @brief Test Case TC_AEB_CTRL_016: Pedals deactivated with low TTC (should go to BRAKE state).
992 : : : *
993 : : : * This test case simulates a situation where the accelerator and brake pedals are deactivated,
994 : : : * and the Time to Collision (TTC) is below the braking threshold. The expected behavior is that
995 : : : * the AEB system will activate the brakes to avoid a potential collision.
996 : : : *
997 : : : * @details
998 : : : * The test uses the following inputs:
999 : : : * - `relative_velocity` set to 60.0 (normal driving speed).
1000 : : : * - `has_obstacle` set to true, indicating that an obstacle is detected.
1001 : : : * - `obstacle_distance` set to 10.0 meters.
1002 : : : * - `aeb_system_enabled` set to true, activating the AEB system.
1003 : : : * - `reverse_enabled` set to false, indicating that the vehicle is not in reverse.
1004 : : : * - `accelerator_pedal` set to false and `brake_pedal` set to false, simulating deactivated pedals.
1005 : : : * - `ttc` set to 0.8, which is lower than the braking threshold.
1006 : : : *
1007 : : : * The AEB system should transition to the BRAKE state because the TTC value is below the threshold.
1008 : : : *
1009 : : : * @pre The AEB system is active, and sensor data is provided with low TTC.
1010 : : : * @post The AEB system should be in the BRAKE state to initiate braking.
1011 : : : *
1012 : : : * @anchor TC_AEB_CTRL_016
1013 : : : */
1014 : : 1 : void test_TC_AEB_CTRL_016(void) {
1015 : : 1 : aeb_internal_state.relative_velocity = 60.0;
1016 : : 1 : aeb_internal_state.has_obstacle = true;
1017 : : 1 : aeb_internal_state.obstacle_distance = 10.0;
1018 : : 1 : aeb_internal_state.aeb_system_enabled = true;
1019 : : 1 : aeb_internal_state.reverse_enabled = false;
1020 : : 1 : aeb_internal_state.accelerator_pedal = false;
1021 : : 1 : aeb_internal_state.brake_pedal = false;
1022 : : :
1023 : : 1 : double ttc = 0.8; // TTC lower than the braking threshold
1024 : : 1 : aeb_controller_state state = getAEBState(aeb_internal_state, ttc);
1025 : : :
1026 : : : // Test: AEB system should go to BRAKE state due to low TTC
1027 : : 1 : checkAEBState(AEB_STATE_BRAKE, state);
1028 : : 1 : }
1029 : : :
1030 : : : /**
1031 : : : * @brief Test Case TC_AEB_CTRL_017: Pedals deactivated with TTC within alarm range (should go to ALARM state).
1032 : : : *
1033 : : : * This test case simulates a situation where the accelerator and brake pedals are deactivated,
1034 : : : * and the Time to Collision (TTC) is within the alarm range. The expected behavior is that the
1035 : : : * AEB system will activate the alarm to warn the driver of a potential collision.
1036 : : : *
1037 : : : * @details
1038 : : : * The test uses the following inputs:
1039 : : : * - `relative_velocity` set to 60.0 (normal driving speed).
1040 : : : * - `has_obstacle` set to true, indicating that an obstacle is detected.
1041 : : : * - `obstacle_distance` set to 10.0 meters.
1042 : : : * - `aeb_system_enabled` set to true, activating the AEB system.
1043 : : : * - `reverse_enabled` set to false, indicating that the vehicle is not in reverse.
1044 : : : * - `accelerator_pedal` set to false and `brake_pedal` set to false, simulating deactivated pedals.
1045 : : : * - `ttc` set to 1.5, which is greater than the braking threshold but less than the alarm threshold.
1046 : : : *
1047 : : : * The AEB system should transition to the ALARM state because the TTC value is within the alarm range.
1048 : : : *
1049 : : : * @pre The AEB system is active, and sensor data is provided with TTC within alarm range.
1050 : : : * @post The AEB system should be in the ALARM state to activate the warning system.
1051 : : : *
1052 : : : * @anchor TC_AEB_CTRL_017
1053 : : : */
1054 : : 1 : void test_TC_AEB_CTRL_017(void) {
1055 : : 1 : aeb_internal_state.relative_velocity = 60.0;
1056 : : 1 : aeb_internal_state.has_obstacle = true;
1057 : : 1 : aeb_internal_state.obstacle_distance = 10.0;
1058 : : 1 : aeb_internal_state.aeb_system_enabled = true;
1059 : : 1 : aeb_internal_state.reverse_enabled = false;
1060 : : 1 : aeb_internal_state.accelerator_pedal = false;
1061 : : 1 : aeb_internal_state.brake_pedal = false;
1062 : : :
1063 : : 1 : double ttc = 1.5; // TTC greater than the braking threshold but less than the alarm threshold
1064 : : 1 : aeb_controller_state state = getAEBState(aeb_internal_state, ttc);
1065 : : :
1066 : : : // Test: AEB system should go to ALARM state
1067 : : 1 : checkAEBState(AEB_STATE_ALARM, state);
1068 : : 1 : }
1069 : : :
1070 : : : /**
1071 : : : * @brief Test Case TC_AEB_CTRL_018: Pedals deactivated with TTC greater than alarm threshold (should go to ACTIVE state).
1072 : : : *
1073 : : : * This test case simulates a situation where the accelerator and brake pedals are deactivated,
1074 : : : * and the Time to Collision (TTC) is greater than the alarm threshold. The expected behavior is that
1075 : : : * the AEB system will remain in the ACTIVE state, indicating normal operation.
1076 : : : *
1077 : : : * @details
1078 : : : * The test uses the following inputs:
1079 : : : * - `relative_velocity` set to 60.0 (normal driving speed).
1080 : : : * - `has_obstacle` set to true, indicating that an obstacle is detected.
1081 : : : * - `obstacle_distance` set to 10.0 meters.
1082 : : : * - `aeb_system_enabled` set to true, activating the AEB system.
1083 : : : * - `reverse_enabled` set to false, indicating that the vehicle is not in reverse.
1084 : : : * - `accelerator_pedal` set to false and `brake_pedal` set to false, simulating deactivated pedals.
1085 : : : * - `ttc` set to `THRESHOLD_ALARM + 0.1`, which is greater than the alarm threshold.
1086 : : : *
1087 : : : * The AEB system should remain in the ACTIVE state because the TTC value is above the alarm threshold.
1088 : : : *
1089 : : : * @pre The AEB system is active, and sensor data is provided with TTC greater than the alarm threshold.
1090 : : : * @post The AEB system should remain in the ACTIVE state.
1091 : : : *
1092 : : : * @anchor TC_AEB_CTRL_018
1093 : : : */
1094 : : 1 : void test_TC_AEB_CTRL_018(void) {
1095 : : 1 : aeb_internal_state.relative_velocity = 60.0;
1096 : : 1 : aeb_internal_state.has_obstacle = true;
1097 : : 1 : aeb_internal_state.obstacle_distance = 10.0;
1098 : : 1 : aeb_internal_state.aeb_system_enabled = true;
1099 : : 1 : aeb_internal_state.reverse_enabled = false;
1100 : : 1 : aeb_internal_state.accelerator_pedal = false;
1101 : : 1 : aeb_internal_state.brake_pedal = false;
1102 : : :
1103 : : 1 : double ttc = THRESHOLD_ALARM + 0.1; // TTC greater than alarm threshold
1104 : : 1 : aeb_controller_state state = getAEBState(aeb_internal_state, ttc);
1105 : : :
1106 : : : // Test: AEB system should go to ACTIVE state
1107 : : 1 : checkAEBState(AEB_STATE_ACTIVE, state);
1108 : : 1 : }
1109 : : :
1110 : : : /**
1111 : : : * @brief Test Case TC_AEB_CTRL_019: Brake pedal pressed (should go to ACTIVE state).
1112 : : : *
1113 : : : * This test case simulates a situation where the brake pedal is pressed while the accelerator
1114 : : : * pedal is off. Despite the presence of an obstacle and a non-zero Time to Collision (TTC),
1115 : : : * the AEB system should go to the ACTIVE state because the brake pedal is pressed, which indicates
1116 : : : * an intentional action by the driver.
1117 : : : *
1118 : : : * @details
1119 : : : * The test uses the following inputs:
1120 : : : * - `relative_velocity` set to 60.0 (normal driving speed).
1121 : : : * - `has_obstacle` set to true, indicating that an obstacle is detected.
1122 : : : * - `obstacle_distance` set to 10.0 meters.
1123 : : : * - `aeb_system_enabled` set to true, activating the AEB system.
1124 : : : * - `reverse_enabled` set to false, indicating that the vehicle is not in reverse.
1125 : : : * - `accelerator_pedal` set to false, indicating that the accelerator is off.
1126 : : : * - `brake_pedal` set to true, indicating that the brake pedal is pressed.
1127 : : : * - `ttc` set to 1.5, which is within the range where the AEB system would normally consider the
1128 : : : * possibility of braking or alarming.
1129 : : : *
1130 : : : * Regardless of the TTC value, the AEB system should transition to the ACTIVE state because the brake
1131 : : : * pedal is pressed.
1132 : : : *
1133 : : : * @pre The AEB system is active, and the brake pedal is pressed.
1134 : : : * @post The AEB system should be in the ACTIVE state, indicating normal operation with the brake pedal engaged.
1135 : : : *
1136 : : : * @anchor TC_AEB_CTRL_019
1137 : : : */
1138 : : 1 : void test_TC_AEB_CTRL_019(void) {
1139 : : 1 : aeb_internal_state.relative_velocity = 60.0;
1140 : : 1 : aeb_internal_state.has_obstacle = true;
1141 : : 1 : aeb_internal_state.obstacle_distance = 10.0;
1142 : : 1 : aeb_internal_state.aeb_system_enabled = true;
1143 : : 1 : aeb_internal_state.reverse_enabled = false;
1144 : : 1 : aeb_internal_state.accelerator_pedal = false;
1145 : : 1 : aeb_internal_state.brake_pedal = true; // Brake pedal pressed
1146 : : :
1147 : : 1 : double ttc = 1.5;
1148 : : 1 : aeb_controller_state state = getAEBState(aeb_internal_state, ttc);
1149 : : :
1150 : : : // Test: AEB system should go to ALARM when TTC is lower than 2, but never to BRAKE
1151 : : : // Since the driver is already activating the accelerator pedal.
1152 : : 1 : checkAEBState(AEB_STATE_ALARM, state);
1153 : : :
1154 : : 1 : ttc = 0.9;
1155 : : 1 : state = getAEBState(aeb_internal_state, ttc);
1156 : : 1 : checkAEBState(AEB_STATE_ALARM, state);
1157 : : 1 : }
1158 : : :
1159 : : : /**
1160 : : : * @brief Test Case TC_AEB_CTRL_020: Accelerator pedal pressed (should go to ACTIVE state).
1161 : : : *
1162 : : : * This test case simulates a situation where the accelerator pedal is pressed while the brake
1163 : : : * pedal is off. The AEB system should go to the ACTIVE state as the accelerator pedal is engaged
1164 : : : * and there is no immediate need for braking (based on the TTC value).
1165 : : : *
1166 : : : * @details
1167 : : : * The test uses the following inputs:
1168 : : : * - `relative_velocity` set to 60.0 (normal driving speed).
1169 : : : * - `has_obstacle` set to true, indicating that an obstacle is detected.
1170 : : : * - `obstacle_distance` set to 10.0 meters.
1171 : : : * - `aeb_system_enabled` set to true, activating the AEB system.
1172 : : : * - `reverse_enabled` set to false, indicating that the vehicle is not in reverse.
1173 : : : * - `accelerator_pedal` set to true, indicating that the accelerator is pressed.
1174 : : : * - `brake_pedal` set to false, indicating that the brake pedal is not pressed.
1175 : : : * - `ttc` set to 1.5, which is within the range where the AEB system would normally consider the
1176 : : : * possibility of braking or alarming.
1177 : : : *
1178 : : : * Since the accelerator pedal is engaged and no critical braking situation is present (based on TTC),
1179 : : : * the AEB system should remain in the ACTIVE state, continuing normal operation.
1180 : : : *
1181 : : : * @pre The AEB system is active, and the accelerator pedal is pressed.
1182 : : : * @post The AEB system should be in the ACTIVE state, indicating normal operation with the accelerator pedal engaged.
1183 : : : *
1184 : : : * @anchor TC_AEB_CTRL_020
1185 : : : */
1186 : : 1 : void test_TC_AEB_CTRL_020(void) {
1187 : : 1 : aeb_internal_state.relative_velocity = 60.0;
1188 : : 1 : aeb_internal_state.has_obstacle = true;
1189 : : 1 : aeb_internal_state.obstacle_distance = 10.0;
1190 : : 1 : aeb_internal_state.aeb_system_enabled = true;
1191 : : 1 : aeb_internal_state.reverse_enabled = false;
1192 : : 1 : aeb_internal_state.accelerator_pedal = true; // Accelerator pedal pressed
1193 : : 1 : aeb_internal_state.brake_pedal = false;
1194 : : :
1195 : : 1 : double ttc = 1.5;
1196 : : 1 : aeb_controller_state state = getAEBState(aeb_internal_state, ttc);
1197 : : :
1198 : : : // Test: AEB system should go to ALARM when TTC is lower than 2, but never to BRAKE
1199 : : : // Since the driver is already activating the brake pedal.
1200 : : 1 : checkAEBState(AEB_STATE_ALARM, state);
1201 : : :
1202 : : 1 : ttc = 0.9;
1203 : : 1 : state = getAEBState(aeb_internal_state, ttc);
1204 : : 1 : checkAEBState(AEB_STATE_ALARM, state);
1205 : : 1 : }
1206 : : :
1207 : : : /**
1208 : : : * @brief Test Case TC_AEB_CTRL_021: Pedal identifier (ID_PEDALS) should call updateInternalPedalsState.
1209 : : : *
1210 : : : * This test case ensures that the `updateInternalPedalsState` function correctly handles the CAN
1211 : : : * messages related to the pedal states. The function should correctly update the internal state of
1212 : : : * the accelerator and brake pedals based on the values received in the CAN message.
1213 : : : *
1214 : : : * @details
1215 : : : * The test uses the following inputs:
1216 : : : * - A CAN message with the identifier `ID_PEDALS` that sets the accelerator pedal to ON (`0x01`)
1217 : : : * and the brake pedal to OFF (`0x00`).
1218 : : : *
1219 : : : * The expected result is that the `accelerator_pedal` state will be set to true (ON), and the
1220 : : : * `brake_pedal` state will be set to false (OFF) in the `aeb_internal_state`.
1221 : : : *
1222 : : : * @pre The CAN message has been received with the correct data for the pedals.
1223 : : : * @post The internal state of the accelerator and brake pedals should be updated correctly.
1224 : : : *
1225 : : : * @anchor TC_AEB_CTRL_021
1226 : : : */
1227 : : 1 : void test_TC_AEB_CTRL_021(void) {
1228 : : : can_msg captured_frame;
1229 : : :
1230 : : 1 : captured_frame.identifier = ID_PEDALS;
1231 : : 1 : captured_frame.dataFrame[0] = 0x01; // Accelerator ON
1232 : : 1 : captured_frame.dataFrame[1] = 0x00; // Brake OFF
1233 : : 1 : translateAndCallCanMsg(captured_frame);
1234 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(aeb_internal_state.accelerator_pedal); // Accelerator pedal should be ON
1235 [ - + ]: [ T f ]: 1 : TEST_ASSERT_FALSE(aeb_internal_state.brake_pedal); // Brake pedal should be OFF
1236 : : 1 : }
1237 : : :
1238 : : : /**
1239 : : : * @brief Test Case: Pedal identifier (ID_PEDALS) should call updateInternalPedalsState with Brake ON
1240 : : : *
1241 : : : * This test case ensures that when the CAN message with the `ID_PEDALS` identifier is received,
1242 : : : * the `updateInternalPedalsState` function correctly updates the state of the pedals in the internal
1243 : : : * AEB system. Specifically, when the brake pedal is ON (`0x01`) and the accelerator is OFF (`0x00`),
1244 : : : * the internal state should reflect these values.
1245 : : : *
1246 : : : * @details
1247 : : : * The test uses the following inputs:
1248 : : : * - `identifier` set to `ID_PEDALS`, which indicates a message related to the pedals.
1249 : : : * - `dataFrame[0]` set to `0x00`, indicating that the accelerator pedal is OFF.
1250 : : : * - `dataFrame[1]` set to `0x01`, indicating that the brake pedal is ON.
1251 : : : *
1252 : : : * The expected result is that:
1253 : : : * - The `accelerator_pedal` in the internal state should be OFF (false).
1254 : : : * - The `brake_pedal` in the internal state should be ON (true).
1255 : : : *
1256 : : : * @pre The CAN message is correctly formatted with `ID_PEDALS` and pedal states.
1257 : : : * @post The internal state of the accelerator and brake pedals should be updated as expected.
1258 : : : *
1259 : : : * @anchor TC_AEB_CTRL_X11
1260 : : : */
1261 : : 1 : void test_TC_AEB_CTRL_X11(void) {
1262 : : : can_msg captured_frame;
1263 : : :
1264 : : 1 : captured_frame.identifier = ID_PEDALS;
1265 : : 1 : captured_frame.dataFrame[0] = 0x00; // Accelerator OFF
1266 : : 1 : captured_frame.dataFrame[1] = 0x01; // Brake ON
1267 : : 1 : translateAndCallCanMsg(captured_frame);
1268 [ - + ]: [ T f ]: 1 : TEST_ASSERT_FALSE(aeb_internal_state.accelerator_pedal); // Accelerator pedal should be OFF
1269 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(aeb_internal_state.brake_pedal); // Brake pedal should be ON
1270 : : 1 : }
1271 : : :
1272 : : : /**
1273 : : : * @brief Test Case TC_AEB_CTRL_022: Speed identifier (ID_SPEED_S) should call updateInternalSpeedState
1274 : : : *
1275 : : : * This test case verifies that the `updateInternalSpeedState` function is correctly called and updates
1276 : : : * the internal state of the vehicle's relative velocity when a CAN message with the `ID_SPEED_S` identifier
1277 : : : * is received. The message should correctly reflect the vehicle's speed in km/h, based on the data in
1278 : : : * `dataFrame[0]` and `dataFrame[1]`.
1279 : : : *
1280 : : : * @details
1281 : : : * The test uses the following inputs:
1282 : : : * - `identifier` set to `ID_SPEED_S`, indicating a message related to the vehicle's speed.
1283 : : : * - `dataFrame[0]` set to `0x00`, and `dataFrame[1]` set to `0x64`, which together represent the value `0x0064` (100 in decimal) for the vehicle's speed.
1284 : : : * - `dataFrame[2]` set to `0x00`, which is not used for this test case.
1285 : : : *
1286 : : : * The expected result is that the `relative_velocity` in the internal state is updated to `100.0`, which
1287 : : : * corresponds to the vehicle's speed in km/h.
1288 : : : *
1289 : : : * @pre The CAN message is correctly formatted with `ID_SPEED_S` and the correct speed data.
1290 : : : * @post The internal state `relative_velocity` should be updated to 100.0 km/h.
1291 : : : *
1292 : : : * @anchor TC_AEB_CTRL_022
1293 : : : */
1294 : : 1 : void test_TC_AEB_CTRL_022(void) {
1295 : : : can_msg captured_frame;
1296 : : :
1297 : : 1 : captured_frame.identifier = ID_SPEED_S;
1298 : : 1 : captured_frame.dataFrame[0] = 0x00;
1299 : : 1 : captured_frame.dataFrame[1] = 0x64;
1300 : : 1 : captured_frame.dataFrame[2] = 0x00;
1301 : : 1 : translateAndCallCanMsg(captured_frame);
1302 : : 1 : TEST_ASSERT_EQUAL_FLOAT(aeb_internal_state.relative_velocity, 100.0); // Speed should be 100 km/h
1303 : : 1 : }
1304 : : :
1305 : : : /**
1306 : : : * @brief Test Case TC_AEB_CTRL_023: Obstacle identifier (ID_OBSTACLE_S) should call updateInternalObstacleState
1307 : : : *
1308 : : : * This test case ensures that when the CAN message with the `ID_OBSTACLE_S` identifier is received,
1309 : : : * the `updateInternalObstacleState` function correctly updates the internal state of the AEB system with
1310 : : : * the presence of an obstacle and the corresponding distance to it.
1311 : : : *
1312 : : : * @details
1313 : : : * The test uses the following inputs:
1314 : : : * - `identifier` set to `ID_OBSTACLE_S`, indicating a message related to obstacle detection.
1315 : : : * - `dataFrame[0]` set to `0xD0`, and `dataFrame[1]` set to `0x07`, together representing the obstacle distance of 100 meters.
1316 : : : * - `dataFrame[2]` set to `0x01`, indicating that an obstacle is detected.
1317 : : : *
1318 : : : * The expected result is that:
1319 : : : * - The `has_obstacle` in the internal state should be true, indicating that an obstacle is detected.
1320 : : : * - The `obstacle_distance` in the internal state should be updated to `100.0` meters.
1321 : : : *
1322 : : : * @pre The CAN message is correctly formatted with `ID_OBSTACLE_S` and obstacle data.
1323 : : : * @post The internal state `has_obstacle` should be true, and `obstacle_distance` should be 100.0 meters.
1324 : : : *
1325 : : : * @anchor TC_AEB_CTRL_023
1326 : : : */
1327 : : 1 : void test_TC_AEB_CTRL_023(void)
1328 : : : {
1329 : : : can_msg captured_frame;
1330 : : :
1331 : : 1 : captured_frame.identifier = ID_OBSTACLE_S;
1332 : : 1 : captured_frame.dataFrame[0] = 0xD0; // Distance part 1
1333 : : 1 : captured_frame.dataFrame[1] = 0x07; // Distance part 2 (Total 100 meters)
1334 : : 1 : captured_frame.dataFrame[2] = 0x01; // Obstacle detected
1335 : : 1 : translateAndCallCanMsg(captured_frame);
1336 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(aeb_internal_state.has_obstacle); // Obstacle should be detected
1337 : : 1 : TEST_ASSERT_EQUAL_FLOAT(aeb_internal_state.obstacle_distance, 100.0); // Distance should be 100 meters
1338 : : 1 : }
1339 : : :
1340 : : : /**
1341 : : : * @brief Test Case TC_AEB_CTRL_024: Car identifier (ID_CAR_C) should call updateInternalCarCState
1342 : : : *
1343 : : : * This test case verifies that when a CAN message with the `ID_CAR_C` identifier is received,
1344 : : : * the `updateInternalCarCState` function correctly updates the internal state of the AEB system,
1345 : : : * specifically turning the AEB system ON or OFF based on the received data.
1346 : : : *
1347 : : : * @details
1348 : : : * The test uses the following inputs:
1349 : : : * - `identifier` set to `ID_CAR_C`, indicating a message related to the AEB system state.
1350 : : : * - `dataFrame[0]` set to `0x01`, indicating that the AEB system should be ON.
1351 : : : *
1352 : : : * The expected result is that:
1353 : : : * - The `aeb_system_enabled` in the internal state should be set to `true`, indicating that the AEB system is ON.
1354 : : : *
1355 : : : * @pre The CAN message is correctly formatted with `ID_CAR_C` and the AEB system state.
1356 : : : * @post The internal state `aeb_system_enabled` should be updated to `true` (AEB system ON).
1357 : : : *
1358 : : : * @anchor TC_AEB_CTRL_024
1359 : : : */
1360 : : 1 : void test_TC_AEB_CTRL_024(void)
1361 : : : {
1362 : : : can_msg captured_frame;
1363 : : :
1364 : : 1 : captured_frame.identifier = ID_CAR_C;
1365 : : 1 : captured_frame.dataFrame[0] = 0x01; // AEB system ON
1366 : : 1 : translateAndCallCanMsg(captured_frame);
1367 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(aeb_internal_state.aeb_system_enabled); // AEB system should be ON
1368 : : 1 : }
1369 : : :
1370 : : : /**
1371 : : : * @brief Test Case: Unknown identifier should print "CAN Identifier unknown"
1372 : : : *
1373 : : : * This test case verifies that when a CAN message with an unknown identifier is received,
1374 : : : * the system correctly handles the invalid identifier by printing the message "CAN Identifier unknown".
1375 : : : *
1376 : : : * @details
1377 : : : * The test uses the following inputs:
1378 : : : * - `identifier` set to `ID_EMPTY`, which is an unknown identifier that is not recognized by the system.
1379 : : : *
1380 : : : * The expected result is that the system should print the message "CAN Identifier unknown" to indicate
1381 : : : * that the received identifier is invalid.
1382 : : : *
1383 : : : * @pre The CAN message is correctly formatted with `ID_EMPTY`, representing an unknown identifier.
1384 : : : * @post The system should print "CAN Identifier unknown" to handle the unrecognized identifier.
1385 : : : *
1386 : : : * @note This test currently ignores the check for printed output. It can be modified to capture
1387 : : : * and verify the printed output if necessary.
1388 : : : *
1389 : : : * @anchor TC_AEB_CTRL_X12
1390 : : : */
1391 : : 1 : void test_TC_AEB_CTRL_X12(void)
1392 : : : {
1393 : : : can_msg captured_frame;
1394 : : :
1395 : : 1 : TEST_IGNORE_MESSAGE("Test case for unknown identifier");
1396 : : :
1397 : : : captured_frame.identifier = ID_EMPTY; // Unknown ID
1398 : : : // The test could capture the printf output and verify the printed message.
1399 : : : translateAndCallCanMsg(captured_frame);
1400 : : : // TEST_ASSERT_EQUAL_STRING("CAN Identifier unknown\n", capture_stdout());
1401 : : : }
1402 : : :
1403 : : : /**
1404 : : : * @brief Test Case: Test reverse flag handling in Speed message
1405 : : : *
1406 : : : * This test case verifies that when the CAN message with the `ID_SPEED_S` identifier is received
1407 : : : * and includes the reverse flag, the internal state correctly updates the `reverse_enabled` flag
1408 : : : * based on the value in `dataFrame[2]`.
1409 : : : *
1410 : : : * @details
1411 : : : * The test uses the following inputs:
1412 : : : * - `identifier` set to `ID_SPEED_S`, indicating a message related to the vehicle's speed.
1413 : : : * - `dataFrame[0]` set to `0x00` and `dataFrame[1]` set to `0x64`, indicating a speed of 100 km/h.
1414 : : : * - `dataFrame[2]` set to `0x01`, indicating that reverse is enabled.
1415 : : : *
1416 : : : * The expected result is that:
1417 : : : * - The `reverse_enabled` in the internal state should be set to `true`, indicating that the vehicle is in reverse.
1418 : : : *
1419 : : : * @pre The CAN message is correctly formatted with `ID_SPEED_S` and the reverse flag data.
1420 : : : * @post The internal state `reverse_enabled` should be updated to `true`.
1421 : : : *
1422 : : : * @anchor TC_AEB_CTRL_X13
1423 : : : */
1424 : : 1 : void test_TC_AEB_CTRL_X13(void)
1425 : : : {
1426 : : : can_msg captured_frame;
1427 : : :
1428 : : 1 : captured_frame.identifier = ID_SPEED_S;
1429 : : 1 : captured_frame.dataFrame[0] = 0x00;
1430 : : 1 : captured_frame.dataFrame[1] = 0x64; // Speed = 100
1431 : : 1 : captured_frame.dataFrame[2] = 0x01; // Reverse enabled
1432 : : 1 : translateAndCallCanMsg(captured_frame);
1433 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(aeb_internal_state.reverse_enabled); // Reverse should be enabled
1434 : : 1 : }
1435 : : :
1436 : : : /**
1437 : : : * @brief Test Case: Test the behavior when receiving clear data for speed
1438 : : : *
1439 : : : * This test case verifies the behavior of the system when receiving a CAN message
1440 : : : * that clears the speed data. The `dataFrame` values are set to `0xFE` and `0xFF`,
1441 : : : * which should indicate that the speed data should be reset.
1442 : : : *
1443 : : : * @details
1444 : : : * The test uses the following inputs:
1445 : : : * - `dataFrame[0]` set to `0xFE`, which indicates that the speed data should be cleared.
1446 : : : * - `dataFrame[1]` set to `0xFF` and `dataFrame[2]` set to `0x00`, which are used as part of the clear command.
1447 : : : *
1448 : : : * The expected result is that:
1449 : : : * - The internal state `relative_velocity` should be reset to `0.0`.
1450 : : : * - The internal state `reverse_enabled` should be set to `false`, as no reverse signal is provided.
1451 : : : *
1452 : : : * @pre The CAN message is correctly formatted with the clear data command for speed.
1453 : : : * @post The internal state `relative_velocity` should be set to `0.0`, and `reverse_enabled` should be `false`.
1454 : : : *
1455 : : : * @anchor TC_AEB_CTRL_X14
1456 : : : */
1457 : : 1 : void test_TC_AEB_CTRL_X14(void)
1458 : : : {
1459 : : : can_msg captured_frame;
1460 : : :
1461 : : 1 : captured_frame.dataFrame[0] = 0xFE; // Clear data for speed
1462 : : 1 : captured_frame.dataFrame[1] = 0xFF;
1463 : : 1 : captured_frame.dataFrame[2] = 0x00;
1464 : : 1 : translateAndCallCanMsg(captured_frame);
1465 : : 1 : TEST_ASSERT_EQUAL_FLOAT(aeb_internal_state.relative_velocity, 0.0); // Speed should reset to 0
1466 [ - + ]: [ T f ]: 1 : TEST_ASSERT_FALSE(aeb_internal_state.reverse_enabled); // Reverse should be disabled
1467 : : 1 : }
1468 : : :
1469 : : : /**
1470 : : : * @brief Test Case: Test the behavior when receiving invalid data for obstacle
1471 : : : *
1472 : : : * This test case verifies the behavior of the system when receiving a CAN message
1473 : : : * with invalid data for the obstacle. The data is set to `0xFF`, indicating that
1474 : : : * no obstacle is detected.
1475 : : : *
1476 : : : * @details
1477 : : : * The test uses the following inputs:
1478 : : : * - `identifier` set to `ID_OBSTACLE_S`, indicating a message related to obstacle detection.
1479 : : : * - `dataFrame[0]` and `dataFrame[1]` are set to `0xFF`, which represent invalid or no obstacle data.
1480 : : : * - `dataFrame[2]` is set to `0xFF`, signaling that no obstacle is detected.
1481 : : : *
1482 : : : * The expected result is that:
1483 : : : * - The internal state `has_obstacle` should be set to `false`, indicating no obstacle is detected.
1484 : : : * - The internal state `obstacle_distance` should be reset to `0.0`, as no valid obstacle data is provided.
1485 : : : *
1486 : : : * @pre The CAN message is correctly formatted with invalid obstacle data.
1487 : : : * @post The internal state `has_obstacle` should be set to `false`, and `obstacle_distance` should be set to `0.0`.
1488 : : : *
1489 : : : * @anchor TC_AEB_CTRL_X15
1490 : : : */
1491 : : 1 : void test_TC_AEB_CTRL_X15(void)
1492 : : : {
1493 : : : can_msg captured_frame;
1494 : : :
1495 : : 1 : captured_frame.identifier = ID_OBSTACLE_S;
1496 : : 1 : captured_frame.dataFrame[0] = 0xFF; // Invalid obstacle data
1497 : : 1 : captured_frame.dataFrame[1] = 0xFF;
1498 : : 1 : captured_frame.dataFrame[2] = 0xFF; // No obstacle
1499 : : 1 : translateAndCallCanMsg(captured_frame);
1500 [ - + ]: [ T f ]: 1 : TEST_ASSERT_FALSE(aeb_internal_state.has_obstacle); // No obstacle detected
1501 : : 1 : TEST_ASSERT_EQUAL_FLOAT(aeb_internal_state.obstacle_distance, 0.0); // Distance should be reset to 0
1502 : : 1 : }
1503 : : :
1504 : : : /**
1505 : : : * @brief Helper function to check the CAN message output for specific warning and brake values.
1506 : : : *
1507 : : : * This function verifies that the CAN message contains the expected values for the
1508 : : : * warning system and braking system based on the provided parameters.
1509 : : : *
1510 : : : * @param expected_warning Expected state for the warning system (0x00 or 0x01).
1511 : : : * @param expected_brake Expected state for the braking system (0x00 or 0x01).
1512 : : : * @param msg The actual CAN message to be checked.
1513 : : : *
1514 : : : * @pre The `msg` is a valid CAN message with the expected values for the warning and braking system.
1515 : : : * @post The function checks if the warning and braking system values match the expected values.
1516 : : : */
1517 : : 5 : void checkCanMsgOutput(int expected_warning, int expected_brake, can_msg msg) {
1518 : : 5 : TEST_ASSERT_EQUAL_HEX8(expected_warning, msg.dataFrame[0]);
1519 : : 5 : TEST_ASSERT_EQUAL_HEX8(expected_brake, msg.dataFrame[1]);
1520 : : 5 : }
1521 : : :
1522 : : : /**
1523 : : : * @brief Test for the AEB_STATE_BRAKE state in the CAN message output.
1524 : : : *
1525 : : : * This test case verifies that when the AEB system is in the BRAKE state,
1526 : : : * the corresponding CAN message values for the warning system and braking system
1527 : : : * are set correctly.
1528 : : : *
1529 : : : * @details
1530 : : : * In this case, the AEB system is in the BRAKE state, which indicates that
1531 : : : * the braking system should be activated while the warning system is also
1532 : : : * triggered. The expected values in the CAN message are:
1533 : : : * - `dataFrame[0]` should be `0x01` to activate the warning system.
1534 : : : * - `dataFrame[1]` should be `0x01` to activate the braking system.
1535 : : : *
1536 : : : * @pre The AEB system state is set to `AEB_STATE_BRAKE`.
1537 : : : * @post The CAN message will have the warning system and braking system set to `0x01`.
1538 : : : *
1539 : : : * @anchor TC_AEB_CTRL_X16
1540 : : : */
1541 : : 1 : void test_TC_AEB_CTRL_X16(void) {
1542 : : 1 : aeb_controller_state state = AEB_STATE_BRAKE;
1543 : : 1 : can_msg result = updateCanMsgOutput(state);
1544 : : :
1545 : : 1 : checkCanMsgOutput(0x01, 0x01, result);
1546 : : 1 : }
1547 : : :
1548 : : : /**
1549 : : : * @brief Test for the AEB_STATE_ALARM state in the CAN message output.
1550 : : : *
1551 : : : * This test case verifies that when the AEB system is in the ALARM state,
1552 : : : * the corresponding CAN message values for the warning system and braking system
1553 : : : * are set correctly.
1554 : : : *
1555 : : : * @details
1556 : : : * In this case, the AEB system is in the ALARM state, which indicates that
1557 : : : * a potential collision has been detected, and the warning system is activated.
1558 : : : * However, the braking system should not be activated yet. The expected values in
1559 : : : * the CAN message are:
1560 : : : * - `dataFrame[0]` should be `0x01` to activate the warning system.
1561 : : : * - `dataFrame[1]` should be `0x00` to deactivate the braking system.
1562 : : : *
1563 : : : * @pre The AEB system state is set to `AEB_STATE_ALARM`.
1564 : : : * @post The CAN message will have the warning system activated and the braking system deactivated.
1565 : : : *
1566 : : : * @anchor TC_AEB_CTRL_X17
1567 : : : */
1568 : : 1 : void test_TC_AEB_CTRL_X17(void) {
1569 : : 1 : aeb_controller_state state = AEB_STATE_ALARM;
1570 : : 1 : can_msg result = updateCanMsgOutput(state);
1571 : : :
1572 : : 1 : checkCanMsgOutput(0x01, 0x00, result);
1573 : : 1 : }
1574 : : :
1575 : : : /**
1576 : : : * @brief Test for the AEB_STATE_ACTIVE state in the CAN message output.
1577 : : : *
1578 : : : * This test case verifies that when the AEB system is in the ACTIVE state,
1579 : : : * the corresponding CAN message values for the warning system and braking system
1580 : : : * are set correctly.
1581 : : : *
1582 : : : * @details
1583 : : : * In this case, the AEB system is in the ACTIVE state, which means that the
1584 : : : * system is not in alarm and the warning system and braking system should
1585 : : : * be deactivated. The expected values in the CAN message are:
1586 : : : * - `dataFrame[0]` should be `0x00` to deactivate the warning system.
1587 : : : * - `dataFrame[1]` should be `0x00` to deactivate the braking system.
1588 : : : *
1589 : : : * @pre The AEB system state is set to `AEB_STATE_ACTIVE`.
1590 : : : * @post The CAN message will have both the warning system and braking system deactivated (`0x00`).
1591 : : : *
1592 : : : * @anchor TC_AEB_CTRL_X18
1593 : : : */
1594 : : 1 : void test_TC_AEB_CTRL_X18(void) {
1595 : : 1 : aeb_controller_state state = AEB_STATE_ACTIVE;
1596 : : 1 : can_msg result = updateCanMsgOutput(state);
1597 : : :
1598 : : 1 : checkCanMsgOutput(0x00, 0x00, result);
1599 : : 1 : }
1600 : : :
1601 : : : /**
1602 : : : * @brief Test for the AEB_STATE_STANDBY state in the CAN message output.
1603 : : : *
1604 : : : * This test verifies that when the AEB system is in the STANDBY state,
1605 : : : * the corresponding CAN message values for the warning system and braking system
1606 : : : * are set correctly.
1607 : : : *
1608 : : : * @details
1609 : : : * In this case, the AEB system is in the STANDBY state, which indicates that
1610 : : : * the system is idle and not actively engaged in monitoring or braking.
1611 : : : * Both the warning system and the braking system should be inactive.
1612 : : : * The expected values in the CAN message are:
1613 : : : * - `dataFrame[0]` should be `0x00` to deactivate the warning system.
1614 : : : * - `dataFrame[1]` should be `0x00` to deactivate the braking system.
1615 : : : *
1616 : : : * @pre The AEB system state is set to `AEB_STATE_STANDBY`.
1617 : : : * @post The CAN message will have both the warning system and braking system deactivated (`0x00`).
1618 : : : *
1619 : : : * @anchor TC_AEB_CTRL_X19
1620 : : : */
1621 : : 1 : void test_TC_AEB_CTRL_X19(void) {
1622 : : 1 : aeb_controller_state state = AEB_STATE_STANDBY;
1623 : : 1 : can_msg result = updateCanMsgOutput(state);
1624 : : :
1625 : : 1 : checkCanMsgOutput(0x00, 0x00, result);
1626 : : 1 : }
1627 : : :
1628 : : : /**
1629 : : : * @brief Test for an invalid AEB system state (out of the defined enumeration range).
1630 : : : *
1631 : : : * This test verifies that when an invalid AEB state (e.g., 999) is provided,
1632 : : : * the corresponding CAN message retains the default values.
1633 : : : *
1634 : : : * @details
1635 : : : * This test simulates the scenario where an invalid or undefined AEB state
1636 : : : * is provided to the system. In such cases, the system should not change the
1637 : : : * default values of the CAN message. The expected values in the CAN message
1638 : : : * are the default values defined in the system, which are:
1639 : : : * - `dataFrame[0]` should be `0xFF` (default value).
1640 : : : * - `dataFrame[1]` should be `0xFF` (default value).
1641 : : : *
1642 : : : * @pre The AEB system state is set to an invalid value (e.g., `999`).
1643 : : : * @post The CAN message will retain the default values (`0xFF`).
1644 : : : *
1645 : : : * @anchor TC_AEB_CTRL_X20
1646 : : : */
1647 : : 1 : void test_TC_AEB_CTRL_X20(void) {
1648 : : 1 : aeb_controller_state state = (aeb_controller_state)999; // Invalid value
1649 : : 1 : can_msg result = updateCanMsgOutput(state);
1650 : : :
1651 : : 1 : checkCanMsgOutput(0xFF, 0xFF, result);
1652 : : 1 : }
1653 : : :
1654 : : : /**
1655 : : : * @brief Test for valid and invalid pedal states.
1656 : : : *
1657 : : : * This test verifies that the internal pedal states (accelerator and brake) are correctly
1658 : : : * updated based on the received CAN message. The test checks both valid and invalid input
1659 : : : * values for the pedal states.
1660 : : : *
1661 : : : * @details
1662 : : : * This test simulates two scenarios:
1663 : : : * 1. When the received CAN message contains valid data (`0x01` for both accelerator and
1664 : : : * brake pedals), both pedals should be turned ON.
1665 : : : * 2. When the received CAN message contains invalid data (`0x02` for both pedals), the
1666 : : : * internal pedal states should remain unchanged (still ON), as the data is not processed
1667 : : : * as valid.
1668 : : : *
1669 : : : * @pre The CAN message is initialized with valid data (`0x01` for both pedals) and then
1670 : : : * modified to invalid data (`0x02` for both pedals).
1671 : : : * @post The internal pedal states will reflect the expected values for valid input and
1672 : : : * remain unchanged for invalid input.
1673 : : : *
1674 : : : * @anchor TC_AEB_CTRL_X21
1675 : : : */
1676 : : 1 : void test_TC_AEB_CTRL_X21(void) {
1677 : : 1 : can_msg captured_frame = { .identifier = ID_PEDALS, .dataFrame = {0x01, 0x01} };
1678 : : :
1679 : : 1 : updateInternalPedalsState(captured_frame);
1680 : : :
1681 : : : // Test: Accelerator pedal should be ON, Brake pedal should be ON
1682 : : 1 : checkPedalState(true, true);
1683 : : :
1684 : : 1 : captured_frame.dataFrame[0] = 0x02;
1685 : : 1 : captured_frame.dataFrame[1] = 0x02;
1686 : : 1 : updateInternalPedalsState(captured_frame);
1687 : : :
1688 : : : // Test: Accelerator and Brake Pedal should be on yet, since this dataFrame isn't valid
1689 : : 1 : checkPedalState(true, true);
1690 : : 1 : }
1691 : : :
1692 : : : /**
1693 : : : * @brief Test Case: Update internal obstacle state with specific CAN data.
1694 : : : *
1695 : : : * This test case verifies the behavior when a CAN message with the identifier
1696 : : : * `ID_OBSTACLE_S` is received with specific data values that should update the
1697 : : : * internal obstacle state. The data frame `{0xFE, 0xFF, 0x01}` is used to
1698 : : : * simulate a scenario where an obstacle is detected at a preset distance.
1699 : : : *
1700 : : : * @details
1701 : : : * This test ensures that the `updateInternalObstacleState` function handles
1702 : : : * the given data correctly, updating the internal state to indicate an obstacle
1703 : : : * is present. The test checks that the obstacle detection flag is set to `true`
1704 : : : * and the obstacle distance is maintained at 300.0 meters.
1705 : : : *
1706 : : : * @pre The AEB system is initialized and ready to process CAN messages.
1707 : : : * @post The internal state should reflect the presence of an obstacle with
1708 : : : * a distance of 300.0 meters.
1709 : : : *
1710 : : : * @anchor TC_AEB_CTRL_X22
1711 : : : */
1712 : : :
1713 : : 1 : void test_TC_AEB_CTRL_X22()
1714 : : : {
1715 : : 1 : can_msg captured_frame = { .identifier = ID_OBSTACLE_S, .dataFrame = {0xFE, 0xFF, 0x01} };
1716 : : 1 : updateInternalObstacleState(captured_frame);
1717 : : 1 : checkObstacleState(true, 300.0);
1718 : : 1 : }
1719 : : :
1720 : : : /**
1721 : : : * @brief Test Case: Update internal obstacle state with specific CAN data.
1722 : : : *
1723 : : : * This test case verifies the behavior when a CAN message with the identifier
1724 : : : * `ID_OBSTACLE_S` is received with specific data values that should update the
1725 : : : * internal obstacle state. The data frame `{0xFD, 0xFF, 0x01}` is used to
1726 : : : * simulate a scenario where an obstacle is detected at a preset distance.
1727 : : : *
1728 : : : * @details
1729 : : : * This test ensures that the `updateInternalObstacleState` function handles
1730 : : : * the given data correctly, updating the internal state to indicate an obstacle
1731 : : : * is present. The test checks that the obstacle detection flag is set to `true`
1732 : : : * and the obstacle distance is maintained at 300.0 meters.
1733 : : : *
1734 : : : * @pre The AEB system is initialized and ready to process CAN messages.
1735 : : : * @post The internal state should reflect the presence of an obstacle with
1736 : : : * a distance of 300.0 meters.
1737 : : : *
1738 : : : * @anchor TC_AEB_CTRL_X23
1739 : : : */
1740 : : 1 : void test_TC_AEB_CTRL_X23()
1741 : : : {
1742 : : 1 : can_msg captured_frame = { .identifier = ID_OBSTACLE_S, .dataFrame = {0xFD, 0xFF, 0x01} };
1743 : : 1 : updateInternalObstacleState(captured_frame);
1744 : : 1 : checkObstacleState(true, 300.0);
1745 : : 1 : }
1746 : : :
1747 : : : /**
1748 : : : * @brief Test Case: Clear acceleration data (0xFE, 0xFF).
1749 : : : *
1750 : : : * @details This test verifies the behavior of the system when the acceleration
1751 : : : * portion of the CAN frame is set to the "clear data" values.
1752 : : : *
1753 : : : * @pre The input CAN frame must have dataFrame[3] == 0xFE and dataFrame[4] == 0xFF.
1754 : : : *
1755 : : : * @post The internal acceleration value (aeb_internal_state.relative_acceleration)
1756 : : : * is expected to be reset to 0.0.
1757 : : : *
1758 : : : * @anchor TC_AEB_CTRL_X24
1759 : : : */
1760 : : 1 : void test_TC_AEB_CTRL_X24(void) {
1761 : : 1 : can_msg frame = {.dataFrame = {0x00, 0x00, 0x00, 0xFE, 0xFF}};
1762 : : 1 : updateInternalSpeedState(frame);
1763 : : 1 : TEST_ASSERT_EQUAL_FLOAT(0.0, aeb_internal_state.relative_acceleration);
1764 : : 1 : }
1765 : : :
1766 : : : /**
1767 : : : * @brief Test Case: Acceleration update skipped when set to ignore (0xFF, 0xFF).
1768 : : : *
1769 : : : * @details This test ensures that the system does not update the internal acceleration value
1770 : : : * when the acceleration bytes in the CAN frame are set to 0xFF, 0xFF — a condition
1771 : : : * defined to indicate "ignore update."
1772 : : : *
1773 : : : * @pre The CAN message must have dataFrame[3] == 0xFF and dataFrame[4] == 0xFF.
1774 : : : *
1775 : : : * @post The internal acceleration value should remain at the default (0.0).
1776 : : : *
1777 : : : * @anchor TC_AEB_CTRL_X25
1778 : : : */
1779 : : 1 : void test_TC_AEB_CTRL_X25(void) {
1780 : : 1 : can_msg frame = {.dataFrame = {0x00, 0x00, 0x00, 0xFF, 0xFF}};
1781 : : 1 : updateInternalSpeedState(frame);
1782 : : 1 : TEST_ASSERT_EQUAL_FLOAT(0.0, aeb_internal_state.relative_acceleration);
1783 : : 1 : }
1784 : : :
1785 : : : /**
1786 : : : * @brief Test Case: Maximum allowed acceleration (positive).
1787 : : : *
1788 : : : * @details This test verifies that the computed acceleration is capped at the maximum
1789 : : : * limit (12.5 m/s²) when the raw CAN value would exceed it.
1790 : : : *
1791 : : : * @pre The acceleration bytes must decode to a value greater than MAX_ACCELERATION_S.
1792 : : : *
1793 : : : * @post The stored internal acceleration should be limited to 12.5.
1794 : : : *
1795 : : : * @anchor TC_AEB_CTRL_X26
1796 : : : */
1797 : : 1 : void test_TC_AEB_CTRL_X26(void) {
1798 : : 1 : can_msg frame = {
1799 : : : .identifier = ID_SPEED_S,
1800 : : : .dataFrame = {0x00, 0x00, 0x00, 0xA8, 0x61, 0x00} // 25000 → (25000 - 12500) * 0.001 = 12.5
1801 : : : };
1802 : : 1 : updateInternalSpeedState(frame);
1803 : : 1 : TEST_ASSERT_EQUAL_FLOAT(12.5, aeb_internal_state.relative_acceleration);
1804 : : 1 : }
1805 : : :
1806 : : : /**
1807 : : : * @brief Test Case: Maximum allowed deceleration (negative).
1808 : : : *
1809 : : : * @details This test validates that the system handles negative acceleration properly
1810 : : : * using the direction flag, and ensures it respects the -12.5 m/s² minimum limit.
1811 : : : *
1812 : : : * @pre CAN frame must include a direction flag set to reverse (dataFrame[5] == 0x01).
1813 : : : *
1814 : : : * @post The internal acceleration should be capped at -12.5.
1815 : : : *
1816 : : : * @anchor TC_AEB_CTRL_X27
1817 : : : */
1818 : : 1 : void test_TC_AEB_CTRL_X27(void) {
1819 : : 1 : can_msg frame = {
1820 : : : .identifier = ID_SPEED_S,
1821 : : : .dataFrame = {0x00, 0x00, 0x00, 0xA8, 0x61, 0x01} // direction = reverse
1822 : : : };
1823 : : 1 : updateInternalSpeedState(frame);
1824 : : 1 : TEST_ASSERT_EQUAL_FLOAT(-12.5, aeb_internal_state.relative_acceleration);
1825 : : 1 : }
1826 : : :
1827 : : : /**
1828 : : : * @brief Test Case: Acceleration exceeding max limit is clamped.
1829 : : : *
1830 : : : * @details This test ensures that even when the decoded value is above the valid maximum,
1831 : : : * the internal system clamps it to 12.5 m/s².
1832 : : : *
1833 : : : * @pre Acceleration bytes must convert to a float above 12.5.
1834 : : : *
1835 : : : * @post Acceleration value stored must not exceed 12.5.
1836 : : : *
1837 : : : * @anchor TC_AEB_CTRL_X28
1838 : : : */
1839 : : 1 : void test_TC_AEB_CTRL_X28(void) {
1840 : : 1 : can_msg frame = {
1841 : : : .identifier = ID_SPEED_S,
1842 : : : .dataFrame = {0x00, 0x00, 0x00, 0x30, 0x75, 0x00} // 30000 → (30000 - 12500) * 0.001 = 17.5 → clamp to 12.5
1843 : : : };
1844 : : 1 : updateInternalSpeedState(frame);
1845 : : 1 : TEST_ASSERT_EQUAL_FLOAT(12.5, aeb_internal_state.relative_acceleration);
1846 : : 1 : }
1847 : : :
1848 : : : /**
1849 : : : * @brief Test Case: Acceleration below min limit is clamped (reverse direction).
1850 : : : *
1851 : : : * @details This test verifies that when a negative acceleration value exceeds the minimum
1852 : : : * allowed threshold, it is clamped to -12.5 m/s².
1853 : : : *
1854 : : : * @pre The raw decoded acceleration must be below -12.5 and the direction flag must be active.
1855 : : : *
1856 : : : * @post The internal acceleration is limited to -12.5.
1857 : : : *
1858 : : : * @anchor TC_AEB_CTRL_X29
1859 : : : */
1860 : : 1 : void test_TC_AEB_CTRL_X29(void) {
1861 : : 1 : can_msg frame = {
1862 : : : .identifier = ID_SPEED_S,
1863 : : : .dataFrame = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01} // raw = 0 → (-12500) * 0.001 = -12.5
1864 : : : };
1865 : : 1 : updateInternalSpeedState(frame);
1866 : : 1 : TEST_ASSERT_EQUAL_FLOAT(-12.5, aeb_internal_state.relative_acceleration);
1867 : : 1 : }
1868 : : :
1869 : : : /**
1870 : : : * @brief Main function to run the tests.
1871 : : : *
1872 : : : * @return int The result of the test run.
1873 : : : */
1874 : : 1 : int main(void) {
1875 : : 1 : UNITY_BEGIN();
1876 : : : // The following tests comply with [SwR-6], [SwR-9] and [SwR-11].
1877 : : 1 : RUN_TEST(test_TC_AEB_CTRL_001);
1878 : : 1 : RUN_TEST(test_TC_AEB_CTRL_002);
1879 : : 1 : RUN_TEST(test_TC_AEB_CTRL_003);
1880 : : 1 : RUN_TEST(test_TC_AEB_CTRL_004);
1881 : : :
1882 : : : // The following tests comply with [SwR-6], [SwR-9] and [SwR-11].
1883 : : 1 : RUN_TEST(test_TC_AEB_CTRL_005);
1884 : : 1 : RUN_TEST(test_TC_AEB_CTRL_006);
1885 : : 1 : RUN_TEST(test_TC_AEB_CTRL_007);
1886 : : 1 : RUN_TEST(test_TC_AEB_CTRL_008);
1887 : : 1 : RUN_TEST(test_TC_AEB_CTRL_009);
1888 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X01);
1889 : : :
1890 : : : // The following tests comply with [SwR-3], [SwR-6], [SwR-7], [SwR-8], [SwR-9], [SwR-11] and [SwR-15]
1891 : : 1 : RUN_TEST(test_TC_AEB_CTRL_010);
1892 : : 1 : RUN_TEST(test_TC_AEB_CTRL_011);
1893 : : 1 : RUN_TEST(test_TC_AEB_CTRL_012);
1894 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X02);
1895 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X03);
1896 : : 1 : RUN_TEST(test_TC_AEB_CTRL_013);
1897 : : :
1898 : : : // The following tests comply with [SwR-2], [SwR-3], [SwR-7], [SwR-8], [SwR-11], [SwR-12] and [SwR-16]
1899 : : 1 : RUN_TEST(test_TC_AEB_CTRL_014);
1900 : : 1 : RUN_TEST(test_TC_AEB_CTRL_015);
1901 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X04);
1902 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X05);
1903 : : :
1904 : : : // The following tests comply with [SwR-2], [SwR-3], [SwR-6], [SwR-7], [SwR-8], [SwR-9], [SwR-11],
1905 : : : // [SwR-12], [SwR-15] and [SwR-16].
1906 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X06);
1907 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X07);
1908 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X08);
1909 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X09);
1910 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X10);
1911 : : 1 : RUN_TEST(test_TC_AEB_CTRL_016);
1912 : : 1 : RUN_TEST(test_TC_AEB_CTRL_017);
1913 : : 1 : RUN_TEST(test_TC_AEB_CTRL_018);
1914 : : 1 : RUN_TEST(test_TC_AEB_CTRL_019);
1915 : : 1 : RUN_TEST(test_TC_AEB_CTRL_020);
1916 : : :
1917 : : : // The following tests comply with [SwR-9].
1918 : : 1 : RUN_TEST(test_TC_AEB_CTRL_021);
1919 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X11);
1920 : : 1 : RUN_TEST(test_TC_AEB_CTRL_022);
1921 : : 1 : RUN_TEST(test_TC_AEB_CTRL_023);
1922 : : 1 : RUN_TEST(test_TC_AEB_CTRL_024);
1923 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X12);
1924 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X13);
1925 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X14);
1926 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X15);
1927 : : :
1928 : : : // Tests to verify the Output of CAN Messages
1929 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X16);
1930 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X17);
1931 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X18);
1932 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X19);
1933 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X20);
1934 : : :
1935 : : : // Tests for enhancements of MC/DC coverage
1936 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X21);
1937 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X22);
1938 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X23);
1939 : : :
1940 : : : // Tests for acceleration and deceleration
1941 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X24);
1942 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X25);
1943 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X26);
1944 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X27);
1945 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X28);
1946 : : 1 : RUN_TEST(test_TC_AEB_CTRL_X29);
1947 : : 1 : return UNITY_END();
1948 : : : }
|