GCC Code Coverage Report


Directory: ./
File: unit_tests/tests/trigger/test_all_triggers.cpp
Date: 2025-10-03 00:57:22
Warnings: 1 unchecked decisions!
Coverage Exec Excl Total
Lines: 100.0% 55 0 55
Functions: 100.0% 7 0 7
Branches: 83.1% 59 0 71
Decisions: 66.7% 4 - 6

Line Branch Decision Exec Source
1 /**
2 * @file test_all_triggers.cpp
3 */
4 #include "pch.h"
5 #include "trigger_meta_generated.h"
6 #include "auto_generated_sync_edge.h"
7
8 // uncomment to test starting from specific trigger
9 //#define TEST_FROM_TRIGGER_ID ((int)trigger_type_e::TT_MAZDA_MIATA_NA)
10 // uncomment to test only newest trigger
11 //#define TEST_FROM_TRIGGER_ID ((int)trigger_type_e::TT_UNUSED - 1)
12 #define TEST_FROM_TRIGGER_ID 1
13
14 #define TEST_TO_TRIGGER_ID trigger_type_e::TT_UNUSED
15 // uncomment to test only one trigger
16 //#define TEST_TO_TRIGGER_ID (TEST_FROM_TRIGGER_ID + 1)
17
18 struct TriggerExportHelper
19 {
20 FILE* fp;
21
22 1 TriggerExportHelper() {
23 1 fp = fopen (TRIGGERS_FILE_NAME, "w+");
24
25 1 fprintf(fp, "# Generated by rusEFI unit test suite\n");
26 1 fprintf(fp, "# This file is used by TriggerImage tool\n");
27 1 fprintf(fp, "# See 'gen_trigger_images.bat'\n");
28 1 }
29
30 1 ~TriggerExportHelper() {
31 1 fclose(fp);
32 1 printf("All triggers exported to %s\n", TRIGGERS_FILE_NAME);
33 1 }
34 };
35
36 static TriggerExportHelper exportHelper;
37
38 class AllTriggersFixture : public ::testing::TestWithParam<int> {
39 };
40
41
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 94 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
95 INSTANTIATE_TEST_SUITE_P(
42 Triggers,
43 AllTriggersFixture,
44 // Test all triggers from the first valid trigger thru the last
45 // (Skip index 0, that's custom toothed wheel which is covered by others)
46 ::testing::Range((int)TEST_FROM_TRIGGER_ID, (int)TEST_TO_TRIGGER_ID)
47 );
48
49 extern bool printTriggerDebug;
50 extern bool printTriggerTrace;
51
52
6/8
✓ Branch 6 taken 1 time.
✓ Branch 12 taken 1 time.
✓ Branch 15 taken 1 time.
✓ Branch 21 taken 1 time.
✓ Branch 25 taken 1 time.
✓ Branch 29 taken 1 time.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
195 TEST_P(AllTriggersFixture, TestTrigger) {
53 // handy debugging options
54 //printTriggerDebug = true;
55 //printTriggerTrace = true;
56
57
1/1
✓ Branch 1 taken 94 times.
94 trigger_type_e tt = (trigger_type_e)GetParam();
58 94 auto fp = exportHelper.fp;
59
60
2/2
✓ Branch 1 taken 94 times.
✓ Branch 4 taken 94 times.
94 printf("Exporting %s\r\n", getTrigger_type_e(tt));
61
62 94 persistent_config_s pc{};
63
1/1
✓ Branch 2 taken 94 times.
94 Engine e;
64 94 Engine* engine = &e;
65
1/1
✓ Branch 2 taken 94 times.
94 EngineTestHelperBase base(engine, &pc.engineConfiguration, &pc);
66
67 #if EFI_UNIT_TEST
68 extern TriggerDecoderBase initState;
69
2/2
✓ Branch 1 taken 157920 times.
✓ Branch 2 taken 94 times.
2/2
✓ Decision 'true' taken 157920 times.
✓ Decision 'false' taken 94 times.
158014 for (size_t i = 0;i<efi::size(initState.gapRatio);i++) {
70 157920 initState.gapRatio[i] = NAN;
71 }
72 #endif // EFI_UNIT_TEST
73
74 94 engineConfiguration->trigger.type = tt;
75
1/1
✓ Branch 1 taken 94 times.
94 setCamOperationMode();
76
77 94 TriggerWaveform *shape = &engine->triggerCentral.triggerShape;
78 94 TriggerFormDetails *triggerFormDetails = &engine->triggerCentral.triggerFormDetails;
79
1/1
✓ Branch 1 taken 94 times.
94 engine->updateTriggerConfiguration();
80
81
2/9
✗ Branch 5 not taken.
✓ Branch 6 taken 94 times.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✓ Branch 33 taken 94 times.
✗ Branch 34 not taken.
94 ASSERT_FALSE(shape->shapeDefinitionError) << "Trigger shapeDefinitionError";
82
83
3/3
✓ Branch 1 taken 94 times.
✓ Branch 4 taken 94 times.
✓ Branch 7 taken 94 times.
94 fprintf(fp, "TRIGGERTYPE %d %d %s %.2f\n", tt, shape->getLength(), getTrigger_type_e(tt), shape->tdcPosition);
84
85
3/3
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 11 times.
✓ Branch 3 taken 94 times.
94 fprintf(fp, "%s=%s\n", TRIGGER_KNOWN_OPERATION_MODE, shape->knownOperationMode ? "true" : "false");
86
1/1
✓ Branch 1 taken 94 times.
94 operation_mode_e mode = shape->getWheelOperationMode();
87
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 4 times.
71 bool isOneOfCrankShapes = mode == FOUR_STROKE_CRANK_SENSOR ||
88
2/2
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 6 times.
67 mode == FOUR_STROKE_THREE_TIMES_CRANK_SENSOR ||
89
4/4
✓ Branch 0 taken 71 times.
✓ Branch 1 taken 23 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 60 times.
165 mode == FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR ||
90 mode == FOUR_STROKE_TWELVE_TIMES_CRANK_SENSOR;
91
3/3
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 60 times.
✓ Branch 3 taken 94 times.
94 fprintf(fp, "%s=%s\n", TRIGGER_IS_CRANK_KEY, isOneOfCrankShapes ? "true" : "false");
92
93
3/3
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 78 times.
✓ Branch 3 taken 94 times.
94 fprintf(fp, "%s=%s\n", TRIGGER_HAS_SECOND_CHANNEL, shape->needSecondTriggerInput ? "true" : "false");
94
3/3
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 90 times.
✓ Branch 3 taken 94 times.
94 fprintf(fp, "%s=%s\n", TRIGGER_IS_SECOND_WHEEL_CAM, shape->isSecondWheelCam ? "true" : "false");
95
2/2
✓ Branch 1 taken 94 times.
✓ Branch 4 taken 94 times.
94 fprintf(fp, "%s=%d\n", TRIGGER_CYCLE_DURATION, (int)shape->getCycleDuration());
96
1/1
✓ Branch 1 taken 94 times.
94 fprintf(fp, "%s=%d\n", TRIGGER_GAPS_COUNT, shape->gapTrackingLength);
97
2/2
✓ Branch 1 taken 94 times.
✓ Branch 4 taken 94 times.
94 fprintf(fp, "%s=%s\n", TRIGGER_SYNC_EDGE, getSyncEdge(shape->syncEdge));
98
1/1
✓ Branch 1 taken 94 times.
94 fprintf(fp, "%s=%d\n", TRIGGER_WITH_SYNC, shape->isSynchronizationNeeded);
99
2/2
✓ Branch 0 taken 223 times.
✓ Branch 1 taken 94 times.
2/2
✓ Decision 'true' taken 223 times.
✓ Decision 'false' taken 94 times.
317 for (int i = 0; i < shape->gapTrackingLength; i++) {
100
1/1
✓ Branch 2 taken 223 times.
223 fprintf(fp, "%s.%d=%f\n", TRIGGER_GAP_FROM, i, shape->synchronizationRatioFrom[i]);
101
1/1
✓ Branch 2 taken 223 times.
223 fprintf(fp, "%s.%d=%f\n", TRIGGER_GAP_TO, i, shape->synchronizationRatioTo[i]);
102 }
103
1/1
✓ Branch 1 taken 94 times.
94 fprintf(fp, "# end of meta section\n");
104
105
3/3
✓ Branch 1 taken 5246 times.
✓ Branch 3 taken 5152 times.
✓ Branch 4 taken 94 times.
0/1
? Decision couldn't be analyzed.
5246 for (size_t i = 0; i < shape->getLength(); i++) {
106
2/2
✓ Branch 1 taken 5152 times.
✓ Branch 4 taken 5152 times.
5152 int triggerDefinitionCoordinate = (shape->getTriggerWaveformSynchPointIndex() + i) % shape->getSize();
107
108
1/1
✓ Branch 1 taken 5152 times.
5152 fprintf(fp, "event %d %d %d %.2f %f\n",
109 i,
110 5152 shape->triggerSignalIndeces[triggerDefinitionCoordinate],
111 5152 shape->triggerSignalStates[triggerDefinitionCoordinate],
112 5152 triggerFormDetails->eventAngles[i],
113 5152 initState.gapRatio[i]
114 );
115 }
116 94 }
117