Branch data MC/DC data Line data Source code
1 : : : #define UNITY_DOUBLE_SUPPORT
2 : : : #include "ttc_control.h"
3 : : : #include <stdio.h>
4 : : : #include <unistd.h>
5 : : : #include <sys/stat.h>
6 : : : #include "unity.h"
7 : : : #include <math.h>
8 : : : #include <stdbool.h>
9 : : :
10 : : : double relspeed_test;
11 : : : double distance_test;
12 : : : //struct timespec wait_time = {0, 1000000}; // 0.001s
13 : : :
14 : : : #define delta 0.0001 // margin of error
15 : : :
16 : : 0 : void mywait(){
17 : : : // struct timespec wait_time = {1, 000000000};
18 : : : // nanosleep(&wait_time, NULL);
19 : : 0 : }
20 : : :
21 : : 8 : void setUp(){
22 : : : // set stuff up here
23 : : : // mywait();
24 : : 8 : }
25 : : :
26 : : 8 : void tearDown(){
27 : : : // clean stuff up here//
28 : : 8 : }
29 : : :
30 : : : /**
31 : : : * @test
32 : : : * @brief Verify if the TTC calculation is in line with the expected papers and patents,
33 : : : * considering the case where the acceleration is zero.
34 : : : *
35 : : : * \anchor test_ttc_when_acel_zero
36 : : : * test ID [TC_TTC_CTRL_001](@ref TC_TTC_CTRL_001)
37 : : : *
38 : : : * @note The calculation must be withing 0.0001 of the correct value in order for the test to be sucessfull.
39 : : : *
40 : : : */
41 : : 1 : void test_ttc_when_acel_zero(){
42 : : : double dist[3], vel[3], acel[3], ttc[3];
43 : : :
44 : : 1 : dist[0] = 100.0; vel[0] = 36.0; acel[0] = 0.0;
45 : : 1 : ttc[0] = ttc_calc(dist[0], vel[0], acel[0]);
46 : : :
47 : : 1 : dist[1] = 90.0; vel[1] = 55.0; acel[1] = 0.0;
48 : : 1 : ttc[1] = ttc_calc(dist[1], vel[1], acel[1]);
49 : : :
50 : : 1 : dist[2] = 41.0; vel[2] = 60.0; acel[2] = 4.5;
51 : : 1 : ttc[2] = ttc_calc(dist[2], vel[2], acel[2]);
52 : : :
53 : : 1 : TEST_ASSERT_FLOAT_WITHIN(delta, 10.0, ttc[0]);
54 : : 1 : TEST_ASSERT_FLOAT_WITHIN(delta, 5.8909, ttc[1]);
55 : : 1 : TEST_ASSERT_FLOAT_WITHIN(delta, 1.9478, ttc[2]);
56 : : 1 : }
57 : : :
58 : : : /**
59 : : : * @test
60 : : : * @brief Verify if the TTC calculation is in line with the expected papers and patents,
61 : : : * considering the case where the acceleration is not zero and the delta from the formula is negative.
62 : : : *
63 : : : * \anchor test_ttc_when_delta_negative
64 : : : * test ID [TC_TTC_CTRL_002](@ref TC_TTC_CTRL_002)
65 : : : *
66 : : : * @note The calculation must be withing 0.0001 of the correct value in order for the test to be sucessfull.
67 : : : *
68 : : : */
69 : : 1 : void test_ttc_when_delta_negative(){
70 : : : // Negative delta -> no real root -> Colision impossible?
71 : : : // Verify this
72 : : :
73 : : : double dist[3], vel[3], acel[3], ttc[3];
74 : : :
75 : : 1 : dist[0] = 50.0; vel[0] = 15.0; acel[0] = -8.0;
76 : : 1 : ttc[0] = ttc_calc(dist[0], vel[0], acel[0]);
77 : : :
78 : : 1 : dist[1] = 90.0; vel[1] = 21.0; acel[1] = -4.0;
79 : : 1 : ttc[1] = ttc_calc(dist[1], vel[1], acel[1]);
80 : : :
81 : : 1 : dist[2] = 41.0; vel[2] = 25.0; acel[2] = -2.87;
82 : : 1 : ttc[2] = ttc_calc(dist[2], vel[2], acel[2]);
83 : : :
84 : : 1 : TEST_ASSERT_FLOAT_WITHIN(delta, 99, ttc[0]);
85 : : 1 : TEST_ASSERT_FLOAT_WITHIN(delta, 99, ttc[1]);
86 : : 1 : TEST_ASSERT_FLOAT_WITHIN(delta, 99, ttc[2]);
87 : : 1 : }
88 : : :
89 : : : /**
90 : : : * @test
91 : : : * @brief Verify if the TTC calculation is in line with the expected papers and patents,
92 : : : * considering the case where the acceleration is not zero and the delta from the formula is zero.
93 : : : *
94 : : : * \anchor test_ttc_when_delta_zero
95 : : : * test ID [TC_TTC_CTRL_003](@ref TC_TTC_CTRL_003)
96 : : : *
97 : : : * @note The calculation must be withing 0.0001 of the correct value in order for the test to be sucessfull.
98 : : : *
99 : : : */
100 : : 1 : void test_ttc_when_delta_zero(){
101 : : : double dist[3], vel[3], acel[3], ttc[3];
102 : : :
103 : : 1 : dist[0] = 10.0; vel[0] = 18.0; acel[0] = -1.25;
104 : : 1 : ttc[0] = ttc_calc(dist[0], vel[0], acel[0]);
105 : : 1 : TEST_ASSERT_FLOAT_WITHIN(delta, 4, ttc[0]);
106 : : :
107 : : 1 : dist[1] = 60.0; vel[1] = 54.0; acel[1] = -1.875;
108 : : 1 : ttc[1] = ttc_calc(dist[1], vel[1], acel[1]);
109 : : 1 : TEST_ASSERT_FLOAT_WITHIN(delta, 8, ttc[1]);
110 : : 1 : }
111 : : :
112 : : : /**
113 : : : * @test
114 : : : * @brief Verify if the TTC calculation is in line with the expected papers and patents,
115 : : : * considering the case where the acceleration is not zero and the delta from the formula is positive.
116 : : : *
117 : : : * \anchor test_ttc_when_delta_positive
118 : : : * test ID [TC_TTC_CTRL_004](@ref TC_TTC_CTRL_004)
119 : : : *
120 : : : * @note The calculation must be withing 0.0001 of the correct value in order for the test to be sucessfull.
121 : : : *
122 : : : */
123 : : 1 : void test_ttc_when_delta_positive(){
124 : : : double dist[3], vel[3], acel[3], ttc[3];
125 : : :
126 : : 1 : dist[0] = 20; vel[0] = 59.5; acel[0] = -3;
127 : : 1 : ttc[0] = ttc_calc(dist[0], vel[0], acel[0]);
128 : : 1 : TEST_ASSERT_FLOAT_WITHIN(delta, 1.3839, ttc[0]);
129 : : :
130 : : 1 : dist[1] = 60.0; vel[1] = 56; acel[1] = -2;
131 : : 1 : ttc[1] = ttc_calc(dist[1], vel[1], acel[1]);
132 : : 1 : TEST_ASSERT_FLOAT_WITHIN(delta, 7.075, ttc[1]);
133 : : :
134 : : 1 : dist[2] = 19.41; vel[2] = 45.3116; acel[2] = -1.29;
135 : : 1 : ttc[2] = ttc_calc(dist[2], vel[2], acel[2]);
136 : : 1 : TEST_ASSERT_FLOAT_WITHIN(delta, 1.6882, ttc[2]);
137 : : 1 : }
138 : : :
139 : : : /**
140 : : : * @test
141 : : : * @brief Verify if the test-version of the AEB controller is is reacting correctly, according to the calculated TTC,
142 : : : * considering the case where the TTC is high enought that no actuator enters the active state.
143 : : : *
144 : : : * \anchor test_aebcontrol_no_actuators_trigger
145 : : : * test ID [TC_TTC_CTRL_005](@ref TC_TTC_CTRL_005)
146 : : : *
147 : : : * @note
148 : : : *
149 : : : */
150 : : 1 : void test_aebcontrol_no_actuators_trigger(){
151 : : : bool enable_aeb, alarm_cluster, enable_breaking, lk_seatbelt, lk_doors;
152 : : : double spd, dist, acel;
153 : : :
154 : : : // Safe situation: TTC high enough so alarm cluster and auto breaking are disabled
155 : : 1 : enable_aeb = true;
156 : : 1 : dist = 90; spd = 20; acel=0.5;
157 : : :
158 : : 1 : aeb_control(&enable_aeb,&alarm_cluster,&enable_breaking,&lk_seatbelt,&lk_doors,
159 : : : &spd, &dist, &acel);
160 : : :
161 [ - + ]: [ T f ]: 1 : TEST_ASSERT_FALSE(alarm_cluster);
162 [ - + ]: [ T f ]: 1 : TEST_ASSERT_FALSE(enable_breaking);
163 : : :
164 : : : // Unsafe situation, but AEB deactivated by user:
165 : : 1 : enable_aeb = false;
166 : : 1 : dist = 7.5; spd = 60; acel=2.5;
167 : : :
168 : : 1 : aeb_control(&enable_aeb,&alarm_cluster,&enable_breaking,&lk_seatbelt,&lk_doors,
169 : : : &spd, &dist, &acel);
170 : : :
171 [ - + ]: [ T f ]: 1 : TEST_ASSERT_FALSE(alarm_cluster);
172 [ - + ]: [ T f ]: 1 : TEST_ASSERT_FALSE(enable_breaking);
173 : : 1 : }
174 : : :
175 : : : /**
176 : : : * @test
177 : : : * @brief Verify if the test-version of the AEB controller is is reacting correctly, according to the calculated TTC,
178 : : : * considering the case where the TTC is low enought that every actuator must enter the active state.
179 : : : *
180 : : : * \anchor test_aeb_worst_situation
181 : : : * test ID [TC_TTC_CTRL_006](@ref TC_TTC_CTRL_006)
182 : : : *
183 : : : * @note
184 : : : *
185 : : : */
186 : : 1 : void test_aeb_worst_situation(){
187 : : : bool enable_aeb, alarm_cluster, enable_breaking, lk_seatbelt, lk_doors;
188 : : : double spd, dist, acel;
189 : : :
190 : : : // Worst situation: TTC low enough that even seatbelts and doors must be
191 : : : // accordingly triggered
192 : : :
193 : : 1 : enable_aeb = true;
194 : : 1 : dist = 5.5; spd = 58.91; acel=2.5;
195 : : 1 : aeb_control(&enable_aeb,&alarm_cluster,&enable_breaking,&lk_seatbelt,&lk_doors,
196 : : : &spd, &dist, &acel);
197 : : :
198 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(alarm_cluster);
199 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(enable_breaking);
200 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(lk_seatbelt);
201 [ - + ]: [ T f ]: 1 : TEST_ASSERT_FALSE(lk_doors);
202 : : 1 : }
203 : : :
204 : : : /**
205 : : : * @test
206 : : : * @brief Verify if the test-version of the AEB controller is is reacting correctly, according to the calculated TTC,
207 : : : * considering the case where the TTC is low enought that the alarm and ABS abstraction must enter the active state.
208 : : : *
209 : : : * \anchor test_aeb_generic_break_situations
210 : : : * test ID [TC_TTC_CTRL_007](@ref TC_TTC_CTRL_007)
211 : : : *
212 : : : * @note
213 : : : *
214 : : : */
215 : : 1 : void test_aeb_generic_break_situations(){
216 : : : bool enable_aeb, alarm_cluster, enable_breaking, lk_seatbelt, lk_doors;
217 : : : double spd, dist, acel;
218 : : :
219 : : 1 : enable_aeb = true;
220 : : 1 : enable_breaking = false;
221 : : 1 : dist = 9.99; spd = 36; acel=0.3;
222 : : 1 : aeb_control(&enable_aeb,&alarm_cluster,&enable_breaking,&lk_seatbelt,&lk_doors,
223 : : : &spd, &dist, &acel);
224 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(alarm_cluster);
225 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(enable_breaking);
226 : : :
227 : : 1 : enable_aeb = true;
228 : : 1 : enable_breaking = true;
229 : : 1 : dist = 9.99; spd = 36; acel=0.3;
230 : : 1 : aeb_control(&enable_aeb,&alarm_cluster,&enable_breaking,&lk_seatbelt,&lk_doors,
231 : : : &spd, &dist, &acel);
232 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(alarm_cluster);
233 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(enable_breaking);
234 : : 1 : }
235 : : :
236 : : : /**
237 : : : * @test
238 : : : * @brief Verify if the test-version of the AEB controller is is reacting correctly, according to the calculated TTC,
239 : : : * considering the case where the TTC is low enought that the alarm must enter the active state, while the ABS remains deactivated.
240 : : : *
241 : : : * \anchor test_aeb_alarm_situation
242 : : : * test ID [TC_TTC_CTRL_008](@ref TC_TTC_CTRL_008)
243 : : : *
244 : : : * @note
245 : : : *
246 : : : */
247 : : 1 : void test_aeb_alarm_situation(){
248 : : : bool enable_aeb, alarm_cluster, enable_breaking, lk_seatbelt, lk_doors;
249 : : : double spd, dist, acel;
250 : : :
251 : : : // Alarm situation: TTC low enought that the alarm state is activated;
252 : : : // But the breaking isn't yet
253 : : :
254 : : 1 : enable_aeb = true;
255 : : 1 : enable_breaking = false;
256 : : 1 : dist = 19.99; spd = 36; acel=0.3;
257 : : 1 : aeb_control(&enable_aeb,&alarm_cluster,&enable_breaking,&lk_seatbelt,&lk_doors,
258 : : : &spd, &dist, &acel);
259 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(alarm_cluster);
260 [ - + ]: [ T f ]: 1 : TEST_ASSERT_FALSE(enable_breaking);
261 : : :
262 : : : // Sensitizes expression 2, line 78 from original file
263 : : 1 : enable_aeb = true;
264 : : 1 : enable_breaking = false;
265 : : 1 : dist = 0.9; spd = 180; acel=0.3;
266 : : 1 : aeb_control(&enable_aeb,&alarm_cluster,&enable_breaking,&lk_seatbelt,&lk_doors,
267 : : : &spd, &dist, &acel);
268 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(alarm_cluster);
269 [ - + ]: [ T f ]: 1 : TEST_ASSERT_FALSE(enable_breaking);
270 : : :
271 : : : // Sensitizes expression 3, line 78 from original file
272 : : 1 : enable_aeb = true;
273 : : 1 : enable_breaking = false;
274 : : 1 : dist = 0.1; spd = 0.5; acel=0.3;
275 : : 1 : aeb_control(&enable_aeb,&alarm_cluster,&enable_breaking,&lk_seatbelt,&lk_doors,
276 : : : &spd, &dist, &acel);
277 [ - + ]: [ T f ]: 1 : TEST_ASSERT_TRUE(alarm_cluster);
278 [ - + ]: [ T f ]: 1 : TEST_ASSERT_FALSE(enable_breaking);
279 : : :
280 : : 1 : }
281 : : :
282 : : 1 : int main(){
283 : : 1 : UNITY_BEGIN();
284 : : :
285 : : 1 : RUN_TEST(test_ttc_when_acel_zero);
286 : : 1 : RUN_TEST(test_ttc_when_delta_negative);
287 : : 1 : RUN_TEST(test_ttc_when_delta_zero);
288 : : 1 : RUN_TEST(test_ttc_when_delta_positive);
289 : : 1 : RUN_TEST(test_aebcontrol_no_actuators_trigger);
290 : : 1 : RUN_TEST(test_aeb_worst_situation);
291 : : 1 : RUN_TEST(test_aeb_generic_break_situations);
292 : : 1 : RUN_TEST(test_aeb_alarm_situation);
293 : : :
294 : : 1 : return UNITY_END();
295 : : : }
|