messing with TPS mocking

This commit is contained in:
rusefi 2019-05-27 14:21:12 -04:00
parent d0644c3841
commit 7b36fc951f
5 changed files with 30 additions and 19 deletions

View File

@ -12,7 +12,9 @@
EXTERN_ENGINE; EXTERN_ENGINE;
#if !EFI_PROD_CODE #if !EFI_PROD_CODE
static int mockTps; // for historical reasons we have options to mock TPS on different layers :(
static int mockTpsAdcValue;
static float mockTpsValue = NAN;
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
/** /**
@ -21,16 +23,19 @@ EXTERN_ENGINE;
*/ */
percent_t mockPedalPosition = MOCK_UNDEFINED; percent_t mockPedalPosition = MOCK_UNDEFINED;
#if !EFI_PROD_CODE
/** /**
* this allows unit tests to simulate TPS position * this allows unit tests to simulate TPS position
*/ */
void setMockTpsPosition(percent_t tpsPosition) { void setMockTpsAdc(percent_t tpsPosition) {
UNUSED(tpsPosition); mockTpsAdcValue = TPS_TS_CONVERSION * tpsPosition;
#if !EFI_PROD_CODE
mockTps = TPS_TS_CONVERSION * tpsPosition;
#endif
} }
void setMockTpsValue(percent_t tpsPosition) {
mockTpsValue = tpsPosition;
}
#endif /* EFI_PROD_CODE */
void setMockPedalPosition(percent_t value) { void setMockPedalPosition(percent_t value) {
mockPedalPosition = value; mockPedalPosition = value;
} }
@ -115,8 +120,8 @@ float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
*/ */
int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if !EFI_PROD_CODE #if !EFI_PROD_CODE
if (mockTps != MOCK_UNDEFINED) { if (mockTpsAdcValue != MOCK_UNDEFINED) {
return mockTps; return mockTpsAdcValue;
} }
#endif #endif
if (engineConfiguration->tps1_1AdcChannel == EFI_ADC_NONE) if (engineConfiguration->tps1_1AdcChannel == EFI_ADC_NONE)
@ -188,6 +193,11 @@ bool hasTpsSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
} }
percent_t getTPS(DECLARE_ENGINE_PARAMETER_SIGNATURE) { percent_t getTPS(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if !EFI_PROD_CODE
if (!cisnan(mockTpsValue)) {
return mockTpsValue;
}
#endif /* EFI_PROD_CODE */
if (!hasTpsSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) if (!hasTpsSensor(PASS_ENGINE_PARAMETER_SIGNATURE))
return NO_TPS_MAGIC_VALUE; return NO_TPS_MAGIC_VALUE;
// todo: if (config->isDualTps) // todo: if (config->isDualTps)

View File

@ -31,7 +31,8 @@ int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE);
float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE); float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE);
percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_SUFFIX); percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_SUFFIX);
void setBosch0280750009(DECLARE_ENGINE_PARAMETER_SIGNATURE); void setBosch0280750009(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void setMockTpsPosition(percent_t tpsPosition); void setMockTpsAdc(percent_t tpsPosition);
void setMockTpsValue(percent_t tpsPosition);
void setMockPedalPosition(percent_t value); void setMockPedalPosition(percent_t value);
void grabTPSIsClosed(); void grabTPSIsClosed();
void grabTPSIsWideOpen(); void grabTPSIsWideOpen();

View File

@ -34,7 +34,7 @@ TEST(fuelCut, coasting) {
// mock CLT - just above threshold ('hot engine') // mock CLT - just above threshold ('hot engine')
float hotClt = engine->sensors.clt = engineConfiguration->coastingFuelCutClt + 1; float hotClt = engine->sensors.clt = engineConfiguration->coastingFuelCutClt + 1;
// mock TPS - throttle is opened // mock TPS - throttle is opened
setMockTpsPosition(6); setMockTpsAdc(6);
// set 'running' RPM - just above RpmHigh threshold // set 'running' RPM - just above RpmHigh threshold
engine->rpmCalculator.mockRpm = engineConfiguration->coastingFuelCutRpmHigh + 1; engine->rpmCalculator.mockRpm = engineConfiguration->coastingFuelCutRpmHigh + 1;
// 'advance' time (amount doesn't matter) // 'advance' time (amount doesn't matter)
@ -52,7 +52,7 @@ TEST(fuelCut, coasting) {
assertEqualsM("inj dur#1 norm", normalInjDuration, ENGINE(injectionDuration)); assertEqualsM("inj dur#1 norm", normalInjDuration, ENGINE(injectionDuration));
// 'releasing' the throttle // 'releasing' the throttle
setMockTpsPosition(0); setMockTpsAdc(0);
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE); eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
// Fuel cut-off is enabled now // Fuel cut-off is enabled now

View File

@ -101,7 +101,7 @@ TEST(idle, timingPid) {
engineConfiguration->tpsMin = 0; engineConfiguration->tpsMin = 0;
engineConfiguration->tpsMax = 100; engineConfiguration->tpsMax = 100;
engineConfiguration->bc.idlePidDeactivationTpsThreshold = 10; engineConfiguration->bc.idlePidDeactivationTpsThreshold = 10;
setMockTpsPosition(0); setMockTpsAdc(0);
// disable temperature sensors // disable temperature sensors
eth.engine.sensors.clt = NAN; eth.engine.sensors.clt = NAN;
@ -135,12 +135,12 @@ TEST(idle, timingPid) {
ASSERT_FLOAT_EQ(-5.75f, corr) << "getAdvanceCorrections#5"; ASSERT_FLOAT_EQ(-5.75f, corr) << "getAdvanceCorrections#5";
// check if PID correction is disabled in running mode (tps > threshold): // check if PID correction is disabled in running mode (tps > threshold):
setMockTpsPosition(engineConfiguration->bc.idlePidDeactivationTpsThreshold + 1); setMockTpsAdc(engineConfiguration->bc.idlePidDeactivationTpsThreshold + 1);
corr = getAdvanceCorrections(idleRpmTarget PASS_ENGINE_PARAMETER_SUFFIX); corr = getAdvanceCorrections(idleRpmTarget PASS_ENGINE_PARAMETER_SUFFIX);
ASSERT_EQ(0, corr) << "getAdvanceCorrections#6"; ASSERT_EQ(0, corr) << "getAdvanceCorrections#6";
// check if PID correction is interpolated for transient idle-running TPS positions // check if PID correction is interpolated for transient idle-running TPS positions
setMockTpsPosition(engineConfiguration->bc.idlePidDeactivationTpsThreshold / 2); setMockTpsAdc(engineConfiguration->bc.idlePidDeactivationTpsThreshold / 2);
corr = getAdvanceCorrections(baseTestRpm PASS_ENGINE_PARAMETER_SUFFIX); corr = getAdvanceCorrections(baseTestRpm PASS_ENGINE_PARAMETER_SUFFIX);
ASSERT_FLOAT_EQ(-5.0f, corr) << "getAdvanceCorrections#7"; ASSERT_FLOAT_EQ(-5.0f, corr) << "getAdvanceCorrections#7";

View File

@ -246,11 +246,11 @@ TEST(misc, testStartupFuelPumping) {
engineConfiguration->tpsMin = 0; engineConfiguration->tpsMin = 0;
engineConfiguration->tpsMax = 10; engineConfiguration->tpsMax = 10;
setMockTpsPosition(6); setMockTpsAdc(6);
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ( 1, sf.pumpsCounter) << "pc#1"; ASSERT_EQ( 1, sf.pumpsCounter) << "pc#1";
setMockTpsPosition(3); setMockTpsAdc(3);
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ( 1, sf.pumpsCounter) << "pumpsCounter#2"; ASSERT_EQ( 1, sf.pumpsCounter) << "pumpsCounter#2";
@ -261,16 +261,16 @@ TEST(misc, testStartupFuelPumping) {
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ( 0, sf.pumpsCounter) << "pc#4"; ASSERT_EQ( 0, sf.pumpsCounter) << "pc#4";
setMockTpsPosition(7); setMockTpsAdc(7);
engine->rpmCalculator.mockRpm = 0; engine->rpmCalculator.mockRpm = 0;
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ( 1, sf.pumpsCounter) << "pc#5"; ASSERT_EQ( 1, sf.pumpsCounter) << "pc#5";
setMockTpsPosition(3); setMockTpsAdc(3);
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ( 1, sf.pumpsCounter) << "pc#6"; ASSERT_EQ( 1, sf.pumpsCounter) << "pc#6";
setMockTpsPosition(7); setMockTpsAdc(7);
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ( 2, sf.pumpsCounter) << "pc#7"; ASSERT_EQ( 2, sf.pumpsCounter) << "pc#7";
} }