GCC Code Coverage Report


Directory: ./
File: unit_tests/tests/trigger/test_trigger_sequence_finder.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 100.0% 62 0 62
Functions: 100.0% 4 0 4
Branches: 100.0% 44 0 44
Decisions: 100.0% 20 - 20

Line Branch Decision Exec Source
1 #include "pch.h"
2 #include "trigger_simulator.h"
3 #include "mock_trigger_configuration.h"
4 #include "trigger_gm.h"
5 #include "trigger_universal.h"
6 #include "trigger_mitsubishi.h"
7
8 typedef void (*TriggerWaveformFunctionPtr)(TriggerWaveform*);
9
10 72 static float wrap(float angle, float cycle) {
11
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 66 times.
2/2
✓ Decision 'true' taken 6 times.
✓ Decision 'false' taken 66 times.
72 if (angle < 0)
12 6 angle += cycle;
13 72 return angle;
14 }
15
16 static int toothOffset = 0;
17
18 144 static float getPos(TriggerWaveform *form, int index, size_t step) {
19
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 132 times.
2/2
✓ Decision 'true' taken 12 times.
✓ Decision 'false' taken 132 times.
144 if (index < 0) {
20 12 index += form->getSize() / step;
21 }
22 144 return form->getSwitchAngle(step * index + toothOffset);
23 }
24
25 static float ratios[400];
26 static float ratiosThisTime[400];
27
28 148 static bool tryGapSequence(size_t length, int toothIndex, TriggerWaveform &form,
29 trigger_config_s &triggerConfig, size_t step) {
30
1/1
✓ Branch 1 taken 148 times.
148 int toothCount = form.getSize() / step;
31
32
2/2
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 148 times.
2/2
✓ Decision 'true' taken 456 times.
✓ Decision 'false' taken 148 times.
604 for (size_t gapIndex = 0; gapIndex < length; gapIndex++) {
33
34 456 int ratioIndex = toothIndex - gapIndex;
35
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 364 times.
2/2
✓ Decision 'true' taken 92 times.
✓ Decision 'false' taken 364 times.
456 if (ratioIndex < 0)
36 92 ratioIndex += toothCount;
37 456 float ratio = ratios[ratioIndex];
38 456 ratiosThisTime[ratioIndex] = ratio;
39 // printf("trying %d ratio %f\n", gapIndex, ratio);
40
1/1
✓ Branch 1 taken 456 times.
456 form.setTriggerSynchronizationGap4(gapIndex, ratio);
41 }
42
43
1/1
✓ Branch 2 taken 148 times.
148 TriggerDecoderBase decoder("test");
44
45 148 MockTriggerConfiguration triggerConfiguration(triggerConfig);
46 148 triggerConfiguration.TriggerType = triggerConfig; // technical debt :(
47
48 try {
49
1/1
✓ Branch 1 taken 148 times.
148 form.setShapeDefinitionError(false);
50
1/1
✓ Branch 1 taken 82 times.
148 uint32_t res = decoder.findTriggerZeroEventIndex(form,
51 triggerConfiguration);
52
53
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 2 times.
2/2
✓ Decision 'true' taken 80 times.
✓ Decision 'false' taken 2 times.
82 if (!form.shapeDefinitionError) {
54
2/2
✓ Branch 0 taken 333 times.
✓ Branch 1 taken 80 times.
2/2
✓ Decision 'true' taken 333 times.
✓ Decision 'false' taken 80 times.
413 for (int i = 0; i < (int)length; i++) {
55 333 float ratio = ratiosThisTime[i];
56
1/1
✓ Branch 1 taken 333 times.
333 printf("happy ratio %f @ %d\n", ratio, i);
57 }
58
1/1
✓ Branch 1 taken 80 times.
80 printf("************** GREAT length=%d at tooth index %d\n", length,
59 toothIndex);
60 80 return true;
61 }
62
63 66 } catch (...) {
64
1/1
✓ Branch 1 taken 66 times.
66 printf("Not good sync tooth index %d\n", toothIndex);
65 66 }
66
67 68 return false;
68 }
69
70 3 static size_t findAllSyncSequences(trigger_type_e t, size_t maxLength, size_t step,
71 TriggerWaveformFunctionPtr function) {
72
1/1
✓ Branch 2 taken 3 times.
3 EngineTestHelper eth(engine_type_e::TEST_ENGINE);
73
74 3 size_t happySequenceCounter = 0;
75
76 3 trigger_config_s triggerConfig;
77 3 triggerConfig.type = t;
78
79
1/1
✓ Branch 2 taken 3 times.
3 TriggerWaveform form;
80
1/1
✓ Branch 1 taken 3 times.
3 function(&form);
81
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 1 time.
3 toothOffset = (form.syncEdge == SyncEdge::Rise || form.syncEdge == SyncEdge::Both ? 0 : 1);
82
83
1/1
✓ Branch 1 taken 3 times.
3 operation_mode_e om = form.getWheelOperationMode();
84
1/1
✓ Branch 1 taken 3 times.
3 float cycle = 720 / getCrankDivider(om);
85
86
1/1
✓ Branch 1 taken 3 times.
3 int toothCount = form.getSize() / step;
87
88
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 3 times.
2/2
✓ Decision 'true' taken 36 times.
✓ Decision 'false' taken 3 times.
39 for (int i = 0; i < toothCount; i++) {
89 // printf("%d angle %f\n", i, getPos(&form, i));
90
91
2/2
✓ Branch 1 taken 36 times.
✓ Branch 4 taken 36 times.
36 float duration0 = wrap(getPos(&form, i, step) - getPos(&form, i - 1, step), cycle);
92
2/2
✓ Branch 1 taken 36 times.
✓ Branch 4 taken 36 times.
36 float duration1 = wrap(getPos(&form, i - 1, step) - getPos(&form, i - 2, step),
93 cycle);
94
95 36 float ratio = duration0 / duration1;
96
97
1/1
✓ Branch 1 taken 36 times.
36 printf("%d ratio %f\n", i, ratio);
98 36 ratios[i] = ratio;
99 }
100
101
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 3 times.
2/2
✓ Decision 'true' taken 14 times.
✓ Decision 'false' taken 3 times.
17 for (size_t length = 1; length <= maxLength; length++) {
102
2/2
✓ Branch 0 taken 148 times.
✓ Branch 1 taken 14 times.
2/2
✓ Decision 'true' taken 148 times.
✓ Decision 'false' taken 14 times.
162 for (int sourceIndex = 0; sourceIndex < toothCount; sourceIndex++) {
103
3/3
✓ Branch 1 taken 148 times.
✓ Branch 3 taken 80 times.
✓ Branch 4 taken 68 times.
2/2
✓ Decision 'true' taken 80 times.
✓ Decision 'false' taken 68 times.
148 if (tryGapSequence(length, sourceIndex, form, triggerConfig, step)) {
104 80 happySequenceCounter++;
105 }
106 }
107 }
108 // setVerboseTrigger(true);
109 3 return happySequenceCounter;
110 3 }
111
112 4 TEST(trigger, finder) {
113 // step - 1 - for both, 2 - for rise/fall only
114
115 2 ASSERT_EQ(9u, findAllSyncSequences(trigger_type_e::TT_VVT_BOSCH_QUICK_START, 3, 2, [] (TriggerWaveform* form) {
116 configureQuickStartSenderWheel(form);
117 1 }));
118
119 2 ASSERT_EQ(27u, findAllSyncSequences(trigger_type_e::TT_GM_24x_3, 3, 2, [] (TriggerWaveform* form) {
120 initGmLS24_3deg(form);
121 1 }));
122
123 2 ASSERT_EQ(44u, findAllSyncSequences(trigger_type_e::TT_VVT_MITSU_6G72, 8, 1, [] (TriggerWaveform* form) {
124 initializeVvt6G72(form);
125 1 }));
126 }
127