Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | // | |||
2 | // Created by FDSoftware on 10/04/25. | |||
3 | // | |||
4 | ||||
5 | #include "pch.h" | |||
6 | #include "ignition_state.h" | |||
7 | ||||
8 | using ::testing::_; | |||
9 | ||||
10 | 4 | TEST(ignition_state, getRunningAdvanceSimple) { | ||
11 |
1/1✓ Branch 2 taken 1 time.
|
1 | EngineTestHelper eth(engine_type_e::TEST_ENGINE); | |
12 | 1 | const float rpm = 4500; | ||
13 | 1 | const float load = 50; | ||
14 | ||||
15 |
1/1✓ Branch 1 taken 1 time.
|
1 | setWholeTimingTable(10); | |
16 |
1/1✓ Branch 1 taken 1 time.
|
1 | initIgnitionAdvanceControl(); | |
17 | ||||
18 | // invalid load, should return NAN | |||
19 |
1/1✓ Branch 1 taken 1 time.
|
1 | auto correction = getRunningAdvance(rpm, NAN); | |
20 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(std::isnan(correction)); | |
21 | ||||
22 | // valid load, all secondary conditions off == 10° | |||
23 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::Clt, 35); | |
24 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::VehicleSpeed, 50); | |
25 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::WheelSlipRatio, 0); | |
26 | ||||
27 | // coverage on: test_ignition_angle_advance.cpp | |||
28 | 1 | engineConfiguration->launchControlEnabled = false; | ||
29 | // to cover: (on test_antilag.cpp) | |||
30 | 1 | engineConfiguration->antiLagEnabled = false; | ||
31 | // coverage on: test_shift_torque_reduction_spark_skip_ratio.cpp | |||
32 | 1 | engineConfiguration->torqueReductionEnabled = false; | ||
33 | // coverage on: test_nitrous_ignition_retard.cpp | |||
34 | 1 | engineConfiguration->nitrousControlEnabled = false; | ||
35 | // to cover (this same file) | |||
36 | 1 | engineConfiguration->useSeparateAdvanceForIdle = false; | ||
37 | ||||
38 |
1/1✓ Branch 1 taken 1 time.
|
1 | correction = getRunningAdvance(rpm, load); | |
39 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_NEAR(10, getRunningAdvance(rpm, load), EPS2D); | |
40 | 2 | } | ||
41 | ||||
42 | struct MockIdle : public MockIdleController { | |||
43 | bool isIdling = true; | |||
44 | ||||
45 | ✗ | bool isIdlingOrTaper() const override { | ||
46 | ✗ | return isIdling; | ||
47 | } | |||
48 | }; | |||
49 | ||||
50 | 4 | TEST(ignition_state, getRunningAdvanceIdleTable) { | ||
51 |
1/1✓ Branch 2 taken 1 time.
|
1 | EngineTestHelper eth(engine_type_e::TEST_ENGINE); | |
52 | 1 | const float rpm = 900; | ||
53 | 1 | const float load = 30; | ||
54 |
1/1✓ Branch 1 taken 1 time.
|
1 | setWholeTimingTable(10); | |
55 | 1 | setArrayValues(config->idleAdvance, 5); | ||
56 | ||||
57 |
1/1✓ Branch 2 taken 1 time.
|
1 | MockIdle idler; | |
58 |
1/1✓ Branch 1 taken 1 time.
|
1 | engine->engineModules.get<IdleController>().set(&idler); | |
59 | ||||
60 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::DriverThrottleIntent, 0); | |
61 | ||||
62 | 1 | engineConfiguration->useSeparateAdvanceForIdle = true; | ||
63 | 1 | engineConfiguration->idlePidDeactivationTpsThreshold = 2; | ||
64 | ||||
65 | // no TPS === running advance | |||
66 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_NEAR(10, getRunningAdvance(rpm, load), EPS2D); | |
67 | ||||
68 | 1 | idler.isIdling = true; | ||
69 |
3/8✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 time.
✗ Branch 16 not taken.
✗ Branch 21 not taken.
✗ Branch 25 not taken.
✗ Branch 28 not taken.
|
1 | EXPECT_TRUE(engine->module<IdleController>()->isIdlingOrTaper()); | |
70 | ||||
71 | // 0% of idle threshold -> idle table | |||
72 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::DriverThrottleIntent, 0.001); | |
73 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_NEAR(5, getRunningAdvance(rpm, load), EPS2D); | |
74 | ||||
75 | // 50% of idle threshold -> idle table | |||
76 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::DriverThrottleIntent, 1); | |
77 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_NEAR(5, getRunningAdvance(rpm, load), EPS2D); | |
78 | ||||
79 | // 75% of idle threshold -> idle table | |||
80 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::DriverThrottleIntent, 1.5); | |
81 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_NEAR(7.5, getRunningAdvance(rpm, load), EPS2D); | |
82 | ||||
83 | // idle threshold -> normal table | |||
84 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::DriverThrottleIntent, 2); | |
85 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_NEAR(10, getRunningAdvance(rpm, load), EPS2D); | |
86 | 2 | } | ||
87 | ||||
88 | 4 | TEST(ignition_state, getRunningAdvanceTractionDrop) { | ||
89 |
1/1✓ Branch 2 taken 1 time.
|
1 | EngineTestHelper eth(engine_type_e::TEST_ENGINE); | |
90 | 1 | engineConfiguration->torqueReductionEnabled = true; | ||
91 | 1 | const float rpm = 4500; | ||
92 | 1 | const float load = 50; | ||
93 | ||||
94 |
1/1✓ Branch 1 taken 1 time.
|
1 | setWholeTimingTable(10); | |
95 |
1/1✓ Branch 1 taken 1 time.
|
1 | initIgnitionAdvanceControl(); | |
96 | ||||
97 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::Clt, 35); | |
98 | 1 | setTable(engineConfiguration->tractionControlTimingDrop, 0); | ||
99 | 1 | engineConfiguration->tractionControlTimingDrop[0][0] = -15; | ||
100 | 1 | engineConfiguration->tractionControlTimingDrop[0][1] = -15; | ||
101 | ||||
102 | 1 | size_t lastYIndex = TRACTION_CONTROL_ETB_DROP_SLIP_SIZE - 1; | ||
103 | 1 | size_t lastXIndex = TRACTION_CONTROL_ETB_DROP_SPEED_SIZE - 1; | ||
104 | ||||
105 | 1 | engineConfiguration->tractionControlTimingDrop[lastYIndex - 1][lastXIndex - 1] = 15; | ||
106 | 1 | engineConfiguration->tractionControlTimingDrop[lastYIndex][lastXIndex] = 15; | ||
107 | ||||
108 | // test correct X/Y on table | |||
109 | // we expect here that the first values are -5 (10° base - 15° from traction table), | |||
110 | // and the last on the rigth side of the table are 25 (10° base + 15° from traction table) | |||
111 | ||||
112 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::VehicleSpeed, 10.0); | |
113 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::WheelSlipRatio, 0); | |
114 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_NEAR(-5, getRunningAdvance(rpm, load), EPS2D); | |
115 | ||||
116 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::VehicleSpeed, 120.0); | |
117 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::WheelSlipRatio, 1.2); | |
118 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_NEAR(25, getRunningAdvance(rpm, load), EPS2D); | |
119 | 2 | } | ||
120 | ||||
121 | 4 | TEST(ignition_state, getRunningAdvanceTractionSparkSkip) { | ||
122 |
1/1✓ Branch 2 taken 1 time.
|
1 | EngineTestHelper eth(engine_type_e::TEST_ENGINE); | |
123 | 1 | engineConfiguration->torqueReductionEnabled = true; | ||
124 | 1 | const float rpm = 4500; | ||
125 | 1 | const float load = 50; | ||
126 | ||||
127 |
1/1✓ Branch 1 taken 1 time.
|
1 | setWholeTimingTable(10); | |
128 |
1/1✓ Branch 1 taken 1 time.
|
1 | initIgnitionAdvanceControl(); | |
129 | ||||
130 | // invalid load, should return NAN | |||
131 |
1/1✓ Branch 1 taken 1 time.
|
1 | auto correction = getRunningAdvance(rpm, NAN); | |
132 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(std::isnan(correction)); | |
133 | ||||
134 | // valid load, all secondary conditions off == 10° | |||
135 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::Clt, 35); | |
136 | 1 | setTable(engineConfiguration->tractionControlIgnitionSkip, 5); | ||
137 | 1 | engineConfiguration->tractionControlIgnitionSkip[0][0] = 0; | ||
138 | 1 | engineConfiguration->tractionControlIgnitionSkip[0][1] = 0; | ||
139 | ||||
140 | 1 | size_t lastYIndex = TRACTION_CONTROL_ETB_DROP_SLIP_SIZE - 1; | ||
141 | 1 | size_t lastXIndex = TRACTION_CONTROL_ETB_DROP_SPEED_SIZE - 1; | ||
142 | ||||
143 | 1 | engineConfiguration->tractionControlIgnitionSkip[lastYIndex - 1][lastXIndex - 1] = 50; | ||
144 | 1 | engineConfiguration->tractionControlIgnitionSkip[lastYIndex][lastXIndex] = 50; | ||
145 | ||||
146 | // test correct X/Y on table | |||
147 | // we expect here that the first values are 0, and the last on the rigth side of the table are 50 | |||
148 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::VehicleSpeed, 10.0); | |
149 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::WheelSlipRatio, 0); | |
150 |
1/1✓ Branch 1 taken 1 time.
|
1 | getRunningAdvance(rpm, load); | |
151 |
2/6✓ Branch 2 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
|
1 | EXPECT_NEAR(0, engine->engineState.tractionControlSparkSkip, EPS2D); | |
152 | ||||
153 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::VehicleSpeed, 120.0); | |
154 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::WheelSlipRatio, 1.2); | |
155 |
1/1✓ Branch 1 taken 1 time.
|
1 | getRunningAdvance(rpm, load); | |
156 |
2/6✓ Branch 2 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
|
1 | EXPECT_NEAR(50, engine->engineState.tractionControlSparkSkip, EPS2D); | |
157 | 2 | } | ||
158 | ||||
159 | 4 | TEST(ignition_state, tsAdvanceIndicators) { | ||
160 |
1/1✓ Branch 2 taken 1 time.
|
1 | EngineTestHelper eth(engine_type_e::TEST_ENGINE); | |
161 | 1 | const float rpm = 900; | ||
162 | 1 | const float load = 30; | ||
163 |
1/1✓ Branch 1 taken 1 time.
|
1 | setWholeTimingTable(10); | |
164 | 1 | setArrayValues(config->idleAdvance, 5); | ||
165 | ||||
166 |
1/1✓ Branch 2 taken 1 time.
|
1 | MockIdle idler; | |
167 |
1/1✓ Branch 1 taken 1 time.
|
1 | engine->engineModules.get<IdleController>().set(&idler); | |
168 | ||||
169 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::DriverThrottleIntent, 0); | |
170 | ||||
171 | 1 | engineConfiguration->useSeparateAdvanceForIdle = true; | ||
172 | 1 | engineConfiguration->idlePidDeactivationTpsThreshold = 2; | ||
173 | ||||
174 | 1 | idler.isIdling = true; | ||
175 |
3/8✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 time.
✗ Branch 16 not taken.
✗ Branch 21 not taken.
✗ Branch 25 not taken.
✗ Branch 28 not taken.
|
1 | EXPECT_TRUE(engine->module<IdleController>()->isIdlingOrTaper()); | |
176 | ||||
177 | // 0% of idle threshold -> idle table | |||
178 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::DriverThrottleIntent, 0.001); | |
179 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_NEAR(5, getRunningAdvance(rpm, load), EPS2D); | |
180 |
2/6✓ 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.
|
1 | EXPECT_EQ(-1, engine->ignitionState.rpmForIgnitionTableDot); | |
181 |
2/6✓ 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.
|
1 | EXPECT_EQ(-1, engine->ignitionState.loadForIgnitionTableDot); | |
182 |
2/6✓ Branch 2 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
|
1 | EXPECT_EQ(rpm, engine->ignitionState.rpmForIgnitionIdleTableDot); | |
183 | ||||
184 | 1 | idler.isIdling = false; | ||
185 | // idle threshold -> normal table | |||
186 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::DriverThrottleIntent, 2); | |
187 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_NEAR(10, getRunningAdvance(rpm, load), EPS2D); | |
188 |
2/6✓ Branch 2 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
|
1 | EXPECT_EQ(rpm, engine->ignitionState.rpmForIgnitionTableDot); | |
189 |
2/6✓ Branch 2 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
|
1 | EXPECT_EQ(load, engine->ignitionState.loadForIgnitionTableDot); | |
190 |
2/6✓ 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.
|
1 | EXPECT_EQ(-1, engine->ignitionState.rpmForIgnitionIdleTableDot); | |
191 | 2 | } | ||
192 |