more tests on OBD2 code, prep tests for map upper limit change (#7059)
This commit is contained in:
parent
fec5193a20
commit
a34bea7bcb
|
@ -308,6 +308,55 @@ TEST(BoostControl, TestClosedLoop) {
|
||||||
EXPECT_FLOAT_EQ(0, bc.getClosedLoop(150, 175).value_or(-1000));
|
EXPECT_FLOAT_EQ(0, bc.getClosedLoop(150, 175).value_or(-1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(BoostControl, TestClosedLoopUint8Overflow) {
|
||||||
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||||
|
|
||||||
|
BoostController bc;
|
||||||
|
|
||||||
|
pid_s pidCfg = {
|
||||||
|
1, 0, 0, // P controller, easier to test
|
||||||
|
0, // no offset
|
||||||
|
5, // 5ms period
|
||||||
|
-100, 100 // min/max output
|
||||||
|
};
|
||||||
|
|
||||||
|
bc.init(
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
testBoostCltCorr,
|
||||||
|
testBoostIatCorr,
|
||||||
|
testBoostCltAdder,
|
||||||
|
testBoostIatAdder,
|
||||||
|
&pidCfg
|
||||||
|
);
|
||||||
|
|
||||||
|
// Enable closed loop
|
||||||
|
engineConfiguration->boostType = CLOSED_LOOP;
|
||||||
|
// Minimum 260kpa
|
||||||
|
engineConfiguration->minimumBoostClosedLoopMap = 260;
|
||||||
|
|
||||||
|
// At 0 RPM, closed loop is disabled
|
||||||
|
Sensor::setMockValue(SensorType::Rpm, 0);
|
||||||
|
EXPECT_EQ(0, bc.getClosedLoop(350, 100).value_or(-1000));
|
||||||
|
|
||||||
|
// too low MAP, disable closed loop
|
||||||
|
Sensor::setMockValue(SensorType::Rpm, 0);
|
||||||
|
EXPECT_EQ(0, bc.getClosedLoop(350, 50).value_or(-1000));
|
||||||
|
|
||||||
|
// With RPM, we should get an output
|
||||||
|
Sensor::setMockValue(SensorType::Rpm, 1000);
|
||||||
|
|
||||||
|
// Actual is above target -> negative output
|
||||||
|
EXPECT_FLOAT_EQ(-53.0f, bc.getClosedLoop(650, 575).value_or(-1000));
|
||||||
|
|
||||||
|
// Disabling closed loop should return 0
|
||||||
|
engineConfiguration->boostType = OPEN_LOOP;
|
||||||
|
EXPECT_FLOAT_EQ(0, bc.getClosedLoop(350, 375).value_or(-1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(BoostControl, SetOutput) {
|
TEST(BoostControl, SetOutput) {
|
||||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||||
|
|
||||||
|
|
|
@ -188,9 +188,9 @@ TEST(CanObd2, handleGetDataRequest_PID_RPM)
|
||||||
EXPECT_EQ(rxFrame.data8[2], PID_RPM); // correct PID
|
EXPECT_EQ(rxFrame.data8[2], PID_RPM); // correct PID
|
||||||
|
|
||||||
int rpm = Sensor::getOrZero(SensorType::Rpm) * ODB_RPM_MULT;
|
int rpm = Sensor::getOrZero(SensorType::Rpm) * ODB_RPM_MULT;
|
||||||
|
|
||||||
EXPECT_EQ(rxFrame.data8[3], (rpm >> 0) & 0xff); // correct value
|
EXPECT_EQ(rxFrame.data8[3], (rpm >> 0) & 0xff); // correct value
|
||||||
EXPECT_EQ(rxFrame.data8[3], (rpm >> 8) & 0xff); // correct value
|
EXPECT_EQ(rxFrame.data8[4], (rpm >> 8) & 0xff); // correct value
|
||||||
|
|
||||||
// clear shared buffer
|
// clear shared buffer
|
||||||
txCanBuffer.clear();
|
txCanBuffer.clear();
|
||||||
|
@ -216,3 +216,95 @@ TEST(CanObd2, handleGetDataRequest_PID_SPEED)
|
||||||
txCanBuffer.clear();
|
txCanBuffer.clear();
|
||||||
EXPECT_FALSE(txCanBuffer.getCount());
|
EXPECT_FALSE(txCanBuffer.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(CanObd2, handleGetDataRequest_PID_INTAKE_TEMP)
|
||||||
|
{
|
||||||
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||||
|
|
||||||
|
CANRxFrame frame;
|
||||||
|
frame.data8[2] = PID_INTAKE_TEMP;
|
||||||
|
|
||||||
|
handleGetDataRequest(frame, 0);
|
||||||
|
CANTxFrame rxFrame = txCanBuffer.get();
|
||||||
|
|
||||||
|
EXPECT_EQ(rxFrame.data8[0], 3); // correct data size
|
||||||
|
EXPECT_EQ(rxFrame.data8[1], 0x41); // correct header
|
||||||
|
EXPECT_EQ(rxFrame.data8[2], PID_INTAKE_TEMP); // correct PID
|
||||||
|
EXPECT_EQ(rxFrame.data8[3], Sensor::getOrZero(SensorType::Iat) + ODB_TEMP_EXTRA); // correct value
|
||||||
|
|
||||||
|
// clear shared buffer
|
||||||
|
txCanBuffer.clear();
|
||||||
|
EXPECT_FALSE(txCanBuffer.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CanObd2, handleGetDataRequest_PID_INTAKE_MAF)
|
||||||
|
{
|
||||||
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||||
|
|
||||||
|
CANRxFrame frame;
|
||||||
|
frame.data8[2] = PID_INTAKE_MAF;
|
||||||
|
|
||||||
|
handleGetDataRequest(frame, 0);
|
||||||
|
CANTxFrame rxFrame = txCanBuffer.get();
|
||||||
|
|
||||||
|
EXPECT_EQ(rxFrame.data8[0], 4); // correct data size
|
||||||
|
EXPECT_EQ(rxFrame.data8[1], 0x41); // correct header
|
||||||
|
EXPECT_EQ(rxFrame.data8[2], PID_INTAKE_MAF); // correct PID
|
||||||
|
|
||||||
|
int maf = Sensor::getOrZero(SensorType::Maf) * 100.0f;
|
||||||
|
|
||||||
|
EXPECT_EQ(rxFrame.data8[3], (maf >> 0) & 0xff); // correct value
|
||||||
|
EXPECT_EQ(rxFrame.data8[4], (maf >> 8) & 0xff); // correct value
|
||||||
|
|
||||||
|
// clear shared buffer
|
||||||
|
txCanBuffer.clear();
|
||||||
|
EXPECT_FALSE(txCanBuffer.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CanObd2, handleGetDataRequest_PID_THROTTLE)
|
||||||
|
{
|
||||||
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||||
|
|
||||||
|
CANRxFrame frame;
|
||||||
|
frame.data8[2] = PID_THROTTLE;
|
||||||
|
|
||||||
|
handleGetDataRequest(frame, 0);
|
||||||
|
CANTxFrame rxFrame = txCanBuffer.get();
|
||||||
|
|
||||||
|
EXPECT_EQ(rxFrame.data8[0], 3); // correct data size
|
||||||
|
EXPECT_EQ(rxFrame.data8[1], 0x41); // correct header
|
||||||
|
EXPECT_EQ(rxFrame.data8[2], PID_THROTTLE); // correct PID
|
||||||
|
EXPECT_EQ(rxFrame.data8[3], Sensor::getOrZero(SensorType::Tps1) * ODB_TPS_BYTE_PERCENT); // correct value
|
||||||
|
|
||||||
|
// clear shared buffer
|
||||||
|
txCanBuffer.clear();
|
||||||
|
EXPECT_FALSE(txCanBuffer.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(CanObd2, handleGetDataRequest_PID_FUEL_AIR_RATIO_1)
|
||||||
|
{
|
||||||
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||||
|
|
||||||
|
CANRxFrame frame;
|
||||||
|
frame.data8[2] = PID_FUEL_AIR_RATIO_1;
|
||||||
|
|
||||||
|
handleGetDataRequest(frame, 0);
|
||||||
|
CANTxFrame rxFrame = txCanBuffer.get();
|
||||||
|
|
||||||
|
EXPECT_EQ(rxFrame.data8[0], 6); // correct data size
|
||||||
|
EXPECT_EQ(rxFrame.data8[1], 0x41); // correct header
|
||||||
|
EXPECT_EQ(rxFrame.data8[2], PID_FUEL_AIR_RATIO_1); // correct PID
|
||||||
|
|
||||||
|
float lambda = clampF(0, Sensor::getOrZero(SensorType::Lambda1), 1.99f);
|
||||||
|
uint16_t scaled = (lambda * 32768);
|
||||||
|
|
||||||
|
EXPECT_EQ(rxFrame.data8[3], ((scaled << 16) >> 0) & 0xff); // correct value
|
||||||
|
EXPECT_EQ(rxFrame.data8[4], ((scaled << 16) >> 8) & 0xff); // correct value
|
||||||
|
|
||||||
|
|
||||||
|
// clear shared buffer
|
||||||
|
txCanBuffer.clear();
|
||||||
|
EXPECT_FALSE(txCanBuffer.getCount());
|
||||||
|
}
|
||||||
|
|
|
@ -210,6 +210,37 @@ TEST(limp, boostCut) {
|
||||||
EXPECT_TRUE(dut.allowInjection());
|
EXPECT_TRUE(dut.allowInjection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(limp, boostCutUint8Overflow) {
|
||||||
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||||
|
|
||||||
|
// Cut above 1500kPa
|
||||||
|
engineConfiguration->boostCutPressure = 1500;
|
||||||
|
engineConfiguration->boostCutPressureHyst = 20;
|
||||||
|
|
||||||
|
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, 1600);
|
||||||
|
dut.updateState(1000, 0);
|
||||||
|
EXPECT_FALSE(dut.allowInjection());
|
||||||
|
|
||||||
|
// Below rising threshold, but should have hysteresis, so not cut yet
|
||||||
|
Sensor::setMockValue(SensorType::Map, 1495);
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(limp, oilPressureStartupFailureCase) {
|
TEST(limp, oilPressureStartupFailureCase) {
|
||||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||||
engineConfiguration->minOilPressureAfterStart = 200;
|
engineConfiguration->minOilPressureAfterStart = 200;
|
||||||
|
|
Loading…
Reference in New Issue