forked from rusefi/rusefi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_limp.cpp
202 lines (152 loc) · 5.39 KB
/
test_limp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "pch.h"
#include "limp_manager.h"
TEST(limp, testFatalError) {
LimpManager dut;
// Everything should work by default
ASSERT_TRUE(dut.allowElectronicThrottle());
ASSERT_TRUE(dut.allowIgnition());
ASSERT_TRUE(dut.allowInjection());
ASSERT_TRUE(dut.allowTriggerInput());
dut.fatalError();
// Fatal error should kill everything
EXPECT_FALSE(dut.allowElectronicThrottle());
EXPECT_FALSE(dut.allowIgnition());
EXPECT_FALSE(dut.allowInjection());
EXPECT_FALSE(dut.allowTriggerInput());
}
TEST(limp, revLimit) {
EngineTestHelper eth(TEST_ENGINE);
engineConfiguration->rpmHardLimit = 2500;
LimpManager dut;
// Under rev limit, inj/ign allowed
dut.updateState(2000, 0);
EXPECT_TRUE(dut.allowIgnition());
EXPECT_TRUE(dut.allowInjection());
// Over rev limit, no injection
dut.updateState(3000, 0);
EXPECT_FALSE(dut.allowIgnition());
EXPECT_FALSE(dut.allowInjection());
// Now recover back to under limit
dut.updateState(2000, 0);
EXPECT_TRUE(dut.allowIgnition());
EXPECT_TRUE(dut.allowInjection());
}
TEST(limp, revLimitCltBased) {
EngineTestHelper eth(TEST_ENGINE);
engineConfiguration->rpmHardLimit = 2500;
// Configure CLT-based rev limit curve
engineConfiguration->useCltBasedRpmLimit = true;
copyArray(engineConfiguration->cltRevLimitRpmBins, { 10, 20, 30, 40 });
copyArray(engineConfiguration->cltRevLimitRpm, { 1000, 2000, 3000, 4000 });
LimpManager dut;
// Check low temperature first
Sensor::setMockValue(SensorType::Clt, 10);
// Under rev limit, inj/ign allowed
dut.updateState(900, 0);
EXPECT_TRUE(dut.allowIgnition());
EXPECT_TRUE(dut.allowInjection());
// Over rev limit, no injection
dut.updateState(1100, 0);
EXPECT_FALSE(dut.allowIgnition());
EXPECT_FALSE(dut.allowInjection());
// Now recover back to under limit
dut.updateState(900, 0);
EXPECT_TRUE(dut.allowIgnition());
EXPECT_TRUE(dut.allowInjection());
// Check middle temperature
Sensor::setMockValue(SensorType::Clt, 35);
// Under rev limit, inj/ign allowed
dut.updateState(3400, 0);
EXPECT_TRUE(dut.allowIgnition());
EXPECT_TRUE(dut.allowInjection());
// Over rev limit, no injection
dut.updateState(3600, 0);
EXPECT_FALSE(dut.allowIgnition());
EXPECT_FALSE(dut.allowInjection());
// Now recover back to under limit
dut.updateState(3400, 0);
EXPECT_TRUE(dut.allowIgnition());
EXPECT_TRUE(dut.allowInjection());
}
TEST(limp, boostCut) {
EngineTestHelper eth(TEST_ENGINE);
// Cut above 100kPa
engineConfiguration->boostCutPressure = 100;
LimpManager dut;
// Below threshold, injection allowed
Sensor::setMockValue(SensorType::Map, 80);
dut.updateState(1000, 0);
EXPECT_TRUE(dut.allowInjection());
// Above rising threshold, injection cut
Sensor::setMockValue(SensorType::Map, 105);
dut.updateState(1000, 0);
EXPECT_FALSE(dut.allowInjection());
// Below rising threshold, but should have hysteresis, so not cut yet
Sensor::setMockValue(SensorType::Map, 95);
dut.updateState(1000, 0);
EXPECT_FALSE(dut.allowInjection());
// Below falling threshold, fuel restored
Sensor::setMockValue(SensorType::Map, 79);
dut.updateState(1000, 0);
EXPECT_TRUE(dut.allowInjection());
// SPECIAL CASE: threshold of 0 means never boost cut
engineConfiguration->boostCutPressure = 0;
Sensor::setMockValue(SensorType::Map, 500);
dut.updateState(1000, 0);
EXPECT_TRUE(dut.allowInjection());
}
extern int timeNowUs;
TEST(limp, oilPressureFailureCase) {
EngineTestHelper eth(TEST_ENGINE);
engineConfiguration->minOilPressureAfterStart = 200;
LimpManager dut;
// Low oil pressure!
Sensor::setMockValue(SensorType::OilPressure, 50);
// Start the engine
engine->rpmCalculator.setRpmValue(1000);
// update & check: injection should be allowed
dut.updateState(1000, getTimeNowNt());
EXPECT_TRUE(dut.allowInjection());
// 4.5 seconds later, should still be allowed (even though pressure is low)
timeNowUs += 4.5e6;
dut.updateState(1000, getTimeNowNt());
EXPECT_TRUE(dut.allowInjection());
// 1 second later (5.5 since start), injection should cut
timeNowUs += 1.0e6;
dut.updateState(1000, getTimeNowNt());
ASSERT_FALSE(dut.allowInjection());
// But then oil pressure arrives!
// Injection still isn't allowed, since now we're late.
Sensor::setMockValue(SensorType::OilPressure, 250);
dut.updateState(1000, getTimeNowNt());
ASSERT_FALSE(dut.allowInjection());
}
TEST(limp, oilPressureSuccessCase) {
EngineTestHelper eth(TEST_ENGINE);
engineConfiguration->minOilPressureAfterStart = 200;
LimpManager dut;
// Low oil pressure!
Sensor::setMockValue(SensorType::OilPressure, 50);
// Start the engine
engine->rpmCalculator.setRpmValue(1000);
// update & check: injection should be allowed
dut.updateState(1000, getTimeNowNt());
EXPECT_TRUE(dut.allowInjection());
// 4.5 seconds later, should still be allowed (even though pressure is low)
timeNowUs += 4.5e6;
dut.updateState(1000, getTimeNowNt());
EXPECT_TRUE(dut.allowInjection());
// But then oil pressure arrives!
Sensor::setMockValue(SensorType::OilPressure, 250);
dut.updateState(1000, getTimeNowNt());
ASSERT_TRUE(dut.allowInjection());
// 1 second later (5.5 since start), injection should be allowed since we saw pressure before the timeout
timeNowUs += 1.0e6;
dut.updateState(1000, getTimeNowNt());
ASSERT_TRUE(dut.allowInjection());
// Later, we lose oil pressure, but engine should stay running
timeNowUs += 10e6;
Sensor::setMockValue(SensorType::OilPressure, 10);
dut.updateState(1000, getTimeNowNt());
ASSERT_TRUE(dut.allowInjection());
}