GCC Code Coverage Report


Directory: ./
File: unit_tests/tests/sent/test_sent.cpp
Date: 2025-10-24 14:26:41
Warnings: 1 unchecked decisions!
Coverage Exec Excl Total
Lines: 100.0% 138 0 138
Functions: 100.0% 28 0 28
Branches: 39.0% 114 0 292
Decisions: 75.0% 15 - 20

Line Branch Decision Exec Source
1 #include "pch.h"
2 #include "logicdata_csv_reader.h"
3 #include "sent_decoder.h"
4
5 // On STM32 we are running timer on 1/4 of cpu clock. Cpu clock is 168 MHz
6 #define CORE_CLOCK 168'000'000
7 #define TIMER_CLOCK (CORE_CLOCK / 4)
8 #define TicksToUs(ticks) ((float)(ticks) * 1000.0 * 1000.0 / TIMER_CLOCK)
9
10 #ifndef SENT_STATISTIC_COUNTERS
11 #define SENT_STATISTIC_COUNTERS 0
12 #endif
13
14 9 static int sentTest_feedWithFile(sent_channel &channel, const char *file)
15 {
16 9 int msgCount = 0;
17 9 int lineCount = 0;
18 9 int printDebug = SENT_STATISTIC_COUNTERS;
19
1/1
✓ Branch 2 taken 9 times.
9 CsvReader reader(1, 0);
20
21
1/1
✓ Branch 1 taken 9 times.
9 reader.open(file);
22
23 double prevTimeStamp;
24
25
3/3
✓ Branch 1 taken 295165 times.
✓ Branch 3 taken 295156 times.
✓ Branch 4 taken 9 times.
0/1
? Decision couldn't be analyzed.
295165 while (reader.haveMore()) {
26 295156 int ret = 0;
27 295156 double value = 0;
28
1/1
✓ Branch 1 taken 295156 times.
295156 double stamp = reader.readTimestampAndValues(&value);
29 295156 lineCount++;
30
31
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 295147 times.
2/2
✓ Decision 'true' taken 9 times.
✓ Decision 'false' taken 295147 times.
295156 if (lineCount == 1) {
32 // get first timestamp
33 9 prevTimeStamp = stamp;
34 9 continue;
35 }
36 // we care only about falling edges
37
2/2
✓ Branch 0 taken 147571 times.
✓ Branch 1 taken 147576 times.
2/2
✓ Decision 'true' taken 147571 times.
✓ Decision 'false' taken 147576 times.
295147 if (value < 0.5) {
38 147571 double diff = stamp - prevTimeStamp;
39 147571 uint32_t clocks = diff * TIMER_CLOCK;
40
41
1/1
✓ Branch 1 taken 147571 times.
147571 uint32_t last_tickPerUnit = channel.getTickTime();
42
43
1/1
✓ Branch 1 taken 147571 times.
147571 ret = channel.Decoder(clocks);
44
3/4
✓ Branch 0 taken 317 times.
✓ Branch 1 taken 147254 times.
✓ Branch 2 taken 317 times.
✗ Branch 3 not taken.
2/2
✓ Decision 'true' taken 317 times.
✓ Decision 'false' taken 147254 times.
147571 if ((ret < 0) && (printDebug)) {
45
1/1
✓ Branch 1 taken 317 times.
317 printf("SENT decoder has failed at %f, clocks %d: %d\n", stamp, clocks, ret);
46
1/1
✓ Branch 1 taken 317 times.
317 printf(" last tickPerUnit = %d, current pulse = %d\n", last_tickPerUnit, (clocks + last_tickPerUnit / 2) / last_tickPerUnit);
47 }
48
49 147571 prevTimeStamp = stamp;
50 }
51
52
3/4
✓ Branch 0 taken 15432 times.
✓ Branch 1 taken 279715 times.
✓ Branch 2 taken 15432 times.
✗ Branch 3 not taken.
2/2
✓ Decision 'true' taken 15432 times.
✓ Decision 'false' taken 279715 times.
295147 if ((ret > 0) && (printDebug)) {
53 15432 uint8_t stat;
54 15432 uint16_t sig0, sig1;
55
56
1/1
✓ Branch 1 taken 15432 times.
15432 ret = channel.GetSignals(&stat, &sig0, &sig1);
57
1/2
✓ Branch 0 taken 15432 times.
✗ Branch 1 not taken.
1/2
✓ Decision 'true' taken 15432 times.
✗ Decision 'false' not taken.
15432 if (ret == 0) {
58 #if 0
59 printf("%d: SENT status 0x%01x, signals: 0x%03x, 0x%03x: %d\n", msgCount, stat, sig0, sig1, ret);
60 #endif
61 15432 msgCount++;
62 }
63 }
64 }
65
66
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
1/2
✓ Decision 'true' taken 9 times.
✗ Decision 'false' not taken.
9 if (printDebug) {
67 9 uint8_t stat;
68 9 uint16_t sig0, sig1;
69
70
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 printf("Unit time %f uS\n", TicksToUs(channel.getTickTime()));
71
72
2/3
✓ Branch 1 taken 9 times.
✓ Branch 3 taken 9 times.
✗ Branch 4 not taken.
1/2
✓ Decision 'true' taken 9 times.
✗ Decision 'false' not taken.
9 if (channel.GetSignals(&stat, &sig0, &sig1) == 0) {
73
1/1
✓ Branch 1 taken 9 times.
9 printf("Last valid fast msg Status 0x%01x Sig0 0x%03x Sig1 0x%03x\n", stat, sig0, sig1);
74 }
75
76
1/1
✓ Branch 1 taken 9 times.
9 printf("Slow channels:\n");
77 /* run for all possible slow channel IDs (8 bit) */
78
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2/2
✓ Decision 'true' taken 2304 times.
✓ Decision 'false' taken 9 times.
2313 for (int i = 0; i < 256; i++) {
79 int value;
80
1/1
✓ Branch 1 taken 2304 times.
2304 value = channel.GetSlowChannelValue(i);
81
2/2
✓ Branch 0 taken 2273 times.
✓ Branch 1 taken 31 times.
2/2
✓ Decision 'true' taken 2273 times.
✓ Decision 'false' taken 31 times.
2304 if (value < 0)
82 2273 continue;
83
1/1
✓ Branch 1 taken 31 times.
31 printf(" ID %d: %d\n", i, value);
84 }
85
86 #if SENT_STATISTIC_COUNTERS
87 9 sent_channel_stat &statistic = channel.statistic;
88
1/1
✓ Branch 1 taken 9 times.
9 printf("Restarts %d\n", statistic.RestartCnt);
89
1/1
✓ Branch 1 taken 9 times.
9 printf("Pause pulses %d\n", statistic.PauseCnt);
90
1/1
✓ Branch 1 taken 9 times.
9 printf("Interval errors %d short, %d long\n", statistic.ShortIntervalErr, statistic.LongIntervalErr);
91
1/1
✓ Branch 1 taken 9 times.
9 printf("Total frames %d with CRC error %d (%f%%)\n", statistic.FrameCnt, statistic.CrcErrCnt, statistic.CrcErrCnt * 100.0 / statistic.FrameCnt);
92
3/3
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 9 times.
9 printf("Total slow channel messages %d with crc6 errors %d (%f%%)\n", statistic.sc12 + statistic.sc16, statistic.scCrcErr, (statistic.sc12 + statistic.sc16) ? statistic.scCrcErr * 100.0 / (statistic.sc12 + statistic.sc16) : 0);
93
1/1
✓ Branch 1 taken 9 times.
9 printf("Sync errors %d\n", statistic.SyncErr);
94 #endif
95 }
96
97 9 return lineCount;
98 9 }
99
100 4 TEST(sent, testFordIdle) {
101
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 static sent_channel channel;
102 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/ford-sent-idle.csv");
103
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(lineCount > 100);
104 #if SENT_STATISTIC_COUNTERS
105 1 sent_channel_stat &statistic = channel.statistic;
106
3/8
✓ Branch 3 taken 1 time.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 time.
✗ Branch 11 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✓ Branch 26 taken 1 time.
✗ Branch 27 not taken.
1 ASSERT_EQ(statistic.RestartCnt, 0u);
107 #endif
108 }
109
110 4 TEST(sent, testFordClosed) {
111
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 static sent_channel channel;
112 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/ford-sent-closed.csv");
113
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(lineCount > 100);
114 1 bool isError = channel.GetMsg(nullptr) != 0;
115
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_FALSE(isError);
116 #if SENT_STATISTIC_COUNTERS
117 1 sent_channel_stat &statistic = channel.statistic;
118 /* TODO: bad captured data or real problem? */
119
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(statistic.RestartCnt <= 1u);
120 #endif
121 }
122
123 4 TEST(sent, testOpelIdle) {
124
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 static sent_channel channel;
125 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/opel-throttle-idle.csv");
126
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(lineCount > 100);
127 1 bool isError = channel.GetMsg(nullptr) != 0;
128
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_FALSE(isError);
129 #if SENT_STATISTIC_COUNTERS
130 1 sent_channel_stat &statistic = channel.statistic;
131 /* TODO: bad captured data or real problem? */
132
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(statistic.RestartCnt <= 1u);
133 #endif
134 }
135
136 4 TEST(sent, testOpelMove) {
137
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 static sent_channel channel;
138 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/opel-throttle-move.csv");
139
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(lineCount > 100);
140 1 bool isError = channel.GetMsg(nullptr) != 0;
141
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_FALSE(isError);
142 #if SENT_STATISTIC_COUNTERS
143 1 sent_channel_stat &statistic = channel.statistic;
144 /* TODO: bad captured data or real problem? */
145
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(statistic.RestartCnt <= 1u);
146 #endif
147 }
148
149 4 TEST(sent, testFuelPressure) {
150
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 static sent_channel channel;
151 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/SENT-fuel-pressure.csv");
152
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(lineCount > 100);
153 1 bool isError = channel.GetMsg(nullptr) != 0;
154
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_FALSE(isError);
155 #if SENT_STATISTIC_COUNTERS
156 1 sent_channel_stat &statistic = channel.statistic;
157
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(statistic.RestartCnt == 0u);
158 /* TODO: add more checks? Check data? */
159 #endif
160 }
161
162 4 TEST(sent, testVagMap) {
163
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 static sent_channel channel;
164 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/vag_04e.906.051.csv");
165
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(lineCount > 100);
166 1 bool isError = channel.GetMsg(nullptr) != 0;
167
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_FALSE(isError);
168 #if SENT_STATISTIC_COUNTERS
169 1 sent_channel_stat &statistic = channel.statistic;
170 /* TODO: bad captured data or real problem? */
171
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(statistic.RestartCnt <= 1u);
172 #endif
173 }
174
175 // Mercedes A 000 905 31 01 EGT sensor
176 4 TEST(sent, testMbEgt) {
177
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 static sent_channel channel;
178 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/mb_A_000_905_31_01-ambient.csv");
179
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(lineCount > 100);
180 1 bool isError = channel.GetMsg(nullptr) != 0;
181
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_FALSE(isError);
182 #if SENT_STATISTIC_COUNTERS
183 1 sent_channel_stat &statistic = channel.statistic;
184 /* TODO: bad captured data or real problem? */
185
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(statistic.RestartCnt <= 1u);
186 #endif
187 }
188
189 4 TEST(sent, testMbEgtCold) {
190
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 static sent_channel channel;
191 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/mb_A_000_905_31_01-water-ice.csv");
192
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(lineCount > 100);
193 1 bool isError = channel.GetMsg(nullptr) != 0;
194
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_FALSE(isError);
195 #if SENT_STATISTIC_COUNTERS
196 1 sent_channel_stat &statistic = channel.statistic;
197 /* TODO: bad captured data or real problem? */
198
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(statistic.RestartCnt <= 1u);
199 #endif
200 }
201
202 4 TEST(sent, testMbEgtHot) {
203
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 static sent_channel channel;
204 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/mb_A_000_905_31_01-boiling-water.csv");
205
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(lineCount > 100);
206 1 bool isError = channel.GetMsg(nullptr) != 0;
207
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_FALSE(isError);
208 #if SENT_STATISTIC_COUNTERS
209 1 sent_channel_stat &statistic = channel.statistic;
210 /* TODO: bad captured data or real problem? */
211
2/8
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 31 not taken.
1 ASSERT_TRUE(statistic.RestartCnt <= 1u);
212 #endif
213 }
214
215 TEST(sent, testNoMessages) {
216 static sent_channel channel;
217 bool isError = channel.GetMsg(nullptr) != 0;
218 ASSERT_TRUE(isError);
219 }
220