GCC Code Coverage Report


Directory: ./
File: unit_tests/tests/trigger/test_real_6g72_3000gt.cpp
Date: 2025-10-03 00:57:22
Warnings: 2 unchecked decisions!
Coverage Exec Excl Total
Lines: 52.3% 46 0 88
Functions: 84.2% 16 0 19
Branches: 20.3% 15 0 74
Decisions: 16.7% 2 - 12

Line Branch Decision Exec Source
1 #include "pch.h"
2
3 #include "logicdata_csv_reader.h"
4
5 static void prepare(EngineTestHelper *eth, trigger_type_e trigger) {
6
7 engineConfiguration->isFasterEngineSpinUpEnabled = true;
8 engineConfiguration->alwaysInstantRpm = true;
9 engineConfiguration->invertPrimaryTriggerSignal = false;
10
11 engineConfiguration->isPhaseSyncRequiredForIgnition = true;
12
13 eth->setTriggerType(trigger);
14
15 ASSERT_FALSE(engine->triggerCentral.triggerShape.shapeDefinitionError);
16
17 engineConfiguration->vvtMode[0] = VVT_INACTIVE;
18 }
19
20 static void constructTriggerFromRecording(CsvReader *reader) {
21 int magic = 20;
22
23 if (reader->lineIndex() == magic) {
24
25 int len = 8;
26 double last = reader->history.get(magic - 1);
27 printf("last=%f\n", last);
28
29 double time360 = last - reader->history.get(magic - 1 - 8);
30
31 float current = 0;
32
33 for (int i=len - 1;i>=0;i--) {
34 double tooth = last - reader->history.get(magic - 1 - i);
35 // printf("index=%d width=%f\n", i, tooth);
36 double angle = 360 - (360 * tooth / time360);
37 //printf("index=%d, to=%f\n", i, angle);
38
39 bool isRise = (i % 2) == 1;
40 const char * front = isRise ? "RISE" : "FALL";
41
42 printf("\ts->addEvent360(%f, TriggerValue::%s);\n", angle, front);
43 current += tooth;
44 }
45
46 // printf("time360=%f\n", time360);
47 }
48 }
49
50 static void runTriggerTest(const char *fileName, uint32_t totalErrors, int syncCounter, float firstRpm) {
51 EngineTestHelper eth(engine_type_e::TEST_ENGINE);
52
53 prepare(&eth, trigger_type_e::TT_VVT_MITSU_6G72);
54
55 bool gotRpm = false;
56
57 CsvReader reader(/*trigger channels count*/1, /* vvtCount */ 0);
58 reader.flipOnRead = true;
59
60 reader.open(fileName);
61 while (reader.haveMore()) {
62 reader.processLine(&eth);
63
64 constructTriggerFromRecording(&reader);
65
66
67 auto rpm = Sensor::getOrZero(SensorType::Rpm);
68 // printf("rpm %f\n", rpm);
69
70 if (!gotRpm && rpm) {
71 gotRpm = true;
72
73 // EXPECT_EQ(eventCount, 7);
74 EXPECT_NEAR(rpm, firstRpm, 0.1);
75 }
76 }
77 ASSERT_TRUE(gotRpm);
78 ASSERT_EQ(totalErrors, engine->triggerCentral.triggerState.totalTriggerErrorCounter);
79 ASSERT_EQ(syncCounter, engine->triggerCentral.triggerState.getSynchronizationCounter());
80 }
81
82
83 /*
84 TEST(real6g72, data1) {
85 runTriggerTest("tests/trigger/resources/3000gt.csv", 0, 15, 195.515f);
86 }
87
88 TEST(real6g72, data2) {
89 runTriggerTest("tests/trigger/resources/3000gt_cranking_cam_first_crank_second_only_cam.csv", 2, 9, 157.843f);
90 }
91 */
92
93 5 void generateLog(const char* filename) {
94
1/1
✓ Branch 2 taken 5 times.
5 CsvReader reader(/*triggerCount*/ 1, /* vvtCount */ 1);
95
96
1/1
✓ Branch 1 taken 5 times.
5 reader.open(filename, NORMAL_ORDER, NORMAL_ORDER);
97
98
1/1
✓ Branch 2 taken 5 times.
5 EngineTestHelper eth(engine_type_e::TEST_ENGINE);
99
1/1
✓ Branch 1 taken 5 times.
5 setVerboseTrigger(true);
100
101 5 engineConfiguration->vvtMode[0] = vvt_mode_e::VVT_MITSUBISHI_6G72;
102
1/1
✓ Branch 1 taken 5 times.
5 eth.setTriggerType(trigger_type_e::TT_3_TOOTH_CRANK);
103
104 5 engineConfiguration->globalTriggerAngleOffset = 125;
105 5 engineConfiguration->isFasterEngineSpinUpEnabled = true;
106 5 engineConfiguration->alwaysInstantRpm = true;
107 5 engineConfiguration->isPhaseSyncRequiredForIgnition = true;
108
109 5 int n = 0;
110 5 bool firstRpm = false;
111
3/3
✓ Branch 1 taken 2731 times.
✓ Branch 3 taken 2726 times.
✓ Branch 4 taken 5 times.
0/1
? Decision couldn't be analyzed.
2731 while (reader.haveMore()) {
112
1/1
✓ Branch 1 taken 2726 times.
2726 reader.processLine(&eth);
113
1/1
✓ Branch 1 taken 2726 times.
2726 auto rpm = Sensor::getOrZero(SensorType::Rpm);
114
4/4
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 206 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2515 times.
2/2
✓ Decision 'true' taken 5 times.
✓ Decision 'false' taken 2721 times.
2726 if ((rpm) && (!firstRpm)) {
115
1/1
✓ Branch 1 taken 5 times.
5 printf("Got first RPM %f, at %d\n", rpm, n);
116 5 firstRpm = true;
117 }
118 2726 n++;
119 }
120 10 }
121
122 4 TEST(real6g72, sync_3000gt_cranking_rusefi) {
123 1 generateLog("tests/trigger/resources/3000gt_cranking_rusefi.csv");
124 1 }
125
126 4 TEST(real6g72, sync_3000gt_cranking_rusefi_2) {
127 1 generateLog("tests/trigger/resources/3000gt_cranking_rusefi_2.csv");
128 1 }
129
130 4 TEST(real6g72, sync_3000gt_crank_cam_cranking) {
131 1 generateLog("tests/trigger/resources/3000gt_crank_cam_cranking.csv");
132 1 }
133
134 4 TEST(real6g72, sync_3000gt_crank_cam_cranking_2) {
135 1 generateLog("tests/trigger/resources/3000gt_crank_cam_cranking_2.csv");
136 1 }
137
138 4 TEST(real6g72, sync_3000gt_crank_cam_cranking_idle) {
139 1 generateLog("tests/trigger/resources/3000gt_crank_cam_cranking_idle.csv");
140 1 }
141