GCC Code Coverage Report


Directory: ./
File: unit_tests/tests/sent/test_sent.cpp
Date: 2025-10-03 00:57:22
Warnings: 1 unchecked decisions!
Coverage Exec Excl Total
Lines: 100.0% 139 0 139
Functions: 100.0% 28 0 28
Branches: 39.2% 115 0 293
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
1/1
✓ Branch 1 taken 15432 times.
15432 printf("%d: SENT status 0x%01x, signals: 0x%03x, 0x%03x: %d\n", msgCount, stat, sig0, sig1, ret);
59 15432 msgCount++;
60 }
61 }
62 }
63
64
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) {
65 9 uint8_t stat;
66 9 uint16_t sig0, sig1;
67
68
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 printf("Unit time %f uS\n", TicksToUs(channel.getTickTime()));
69
70
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) {
71
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);
72 }
73
74
1/1
✓ Branch 1 taken 9 times.
9 printf("Slow channels:\n");
75 /* run for all possible slow channel IDs (8 bit) */
76
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++) {
77 int value;
78
1/1
✓ Branch 1 taken 2304 times.
2304 value = channel.GetSlowChannelValue(i);
79
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)
80 2273 continue;
81
1/1
✓ Branch 1 taken 31 times.
31 printf(" ID %d: %d\n", i, value);
82 }
83
84 #if SENT_STATISTIC_COUNTERS
85 9 sent_channel_stat &statistic = channel.statistic;
86
1/1
✓ Branch 1 taken 9 times.
9 printf("Restarts %d\n", statistic.RestartCnt);
87
1/1
✓ Branch 1 taken 9 times.
9 printf("Pause pulses %d\n", statistic.PauseCnt);
88
1/1
✓ Branch 1 taken 9 times.
9 printf("Interval errors %d short, %d long\n", statistic.ShortIntervalErr, statistic.LongIntervalErr);
89
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);
90
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);
91
1/1
✓ Branch 1 taken 9 times.
9 printf("Sync errors %d\n", statistic.SyncErr);
92 #endif
93 }
94
95 9 return lineCount;
96 9 }
97
98 4 TEST(sent, testFordIdle) {
99
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;
100 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/ford-sent-idle.csv");
101
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);
102 #if SENT_STATISTIC_COUNTERS
103 1 sent_channel_stat &statistic = channel.statistic;
104
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);
105 #endif
106 }
107
108 4 TEST(sent, testFordClosed) {
109
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;
110 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/ford-sent-closed.csv");
111
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);
112 1 bool isError = channel.GetMsg(nullptr) != 0;
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_FALSE(isError);
114 #if SENT_STATISTIC_COUNTERS
115 1 sent_channel_stat &statistic = channel.statistic;
116 /* TODO: bad captured data or real problem? */
117
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);
118 #endif
119 }
120
121 4 TEST(sent, testOpelIdle) {
122
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;
123 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/opel-throttle-idle.csv");
124
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);
125 1 bool isError = channel.GetMsg(nullptr) != 0;
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_FALSE(isError);
127 #if SENT_STATISTIC_COUNTERS
128 1 sent_channel_stat &statistic = channel.statistic;
129 /* TODO: bad captured data or real problem? */
130
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);
131 #endif
132 }
133
134 4 TEST(sent, testOpelMove) {
135
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;
136 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/opel-throttle-move.csv");
137
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);
138 1 bool isError = channel.GetMsg(nullptr) != 0;
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_FALSE(isError);
140 #if SENT_STATISTIC_COUNTERS
141 1 sent_channel_stat &statistic = channel.statistic;
142 /* TODO: bad captured data or real problem? */
143
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);
144 #endif
145 }
146
147 4 TEST(sent, testFuelPressure) {
148
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;
149 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/SENT-fuel-pressure.csv");
150
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);
151 1 bool isError = channel.GetMsg(nullptr) != 0;
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_FALSE(isError);
153 #if SENT_STATISTIC_COUNTERS
154 1 sent_channel_stat &statistic = channel.statistic;
155
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);
156 /* TODO: add more checks? Check data? */
157 #endif
158 }
159
160 4 TEST(sent, testVagMap) {
161
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;
162 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/vag_04e.906.051.csv");
163
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);
164 1 bool isError = channel.GetMsg(nullptr) != 0;
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_FALSE(isError);
166 #if SENT_STATISTIC_COUNTERS
167 1 sent_channel_stat &statistic = channel.statistic;
168 /* TODO: bad captured data or real problem? */
169
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);
170 #endif
171 }
172
173 // Mercedes A 000 905 31 01 EGT sensor
174 4 TEST(sent, testMbEgt) {
175
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;
176 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/mb_A_000_905_31_01-ambient.csv");
177
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);
178 1 bool isError = channel.GetMsg(nullptr) != 0;
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_FALSE(isError);
180 #if SENT_STATISTIC_COUNTERS
181 1 sent_channel_stat &statistic = channel.statistic;
182 /* TODO: bad captured data or real problem? */
183
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);
184 #endif
185 }
186
187 4 TEST(sent, testMbEgtCold) {
188
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;
189 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/mb_A_000_905_31_01-water-ice.csv");
190
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);
191 1 bool isError = channel.GetMsg(nullptr) != 0;
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_FALSE(isError);
193 #if SENT_STATISTIC_COUNTERS
194 1 sent_channel_stat &statistic = channel.statistic;
195 /* TODO: bad captured data or real problem? */
196
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);
197 #endif
198 }
199
200 4 TEST(sent, testMbEgtHot) {
201
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;
202 1 int lineCount = sentTest_feedWithFile(channel, "tests/sent/resources/mb_A_000_905_31_01-boiling-water.csv");
203
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);
204 1 bool isError = channel.GetMsg(nullptr) != 0;
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_FALSE(isError);
206 #if SENT_STATISTIC_COUNTERS
207 1 sent_channel_stat &statistic = channel.statistic;
208 /* TODO: bad captured data or real problem? */
209
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);
210 #endif
211 }
212
213 TEST(sent, testNoMessages) {
214 static sent_channel channel;
215 bool isError = channel.GetMsg(nullptr) != 0;
216 ASSERT_TRUE(isError);
217 }
218