unit tests should not have global context, including mock values

This commit is contained in:
rusefi 2019-05-27 15:56:12 -04:00
parent 31faecf491
commit 5f642ac254
17 changed files with 47 additions and 51 deletions

View File

@ -210,7 +210,7 @@ static void printSensors(Logging *log, bool fileFormat) {
}
#if EFI_ANALOG_SENSORS
if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
reportSensorF(log, fileFormat, "MAP", "kPa", getMap(), 2);
reportSensorF(log, fileFormat, "MAP", "kPa", getMap(PASS_ENGINE_PARAMETER_SIGNATURE), 2);
// reportSensorF(log, fileFormat, "map_r", "V", getRawMap(), 2);
}
#endif /* EFI_ANALOG_SENSORS */
@ -318,7 +318,7 @@ static void printSensors(Logging *log, bool fileFormat) {
reportSensorF(log, fileFormat, "f: el delta", "v", engine->engineLoadAccelEnrichment.getMaxDelta(), 2);
if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
reportSensorF(log, fileFormat, "f: el fuel", "v", engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE) * 100 / getMap(), 2);
reportSensorF(log, fileFormat, "f: el fuel", "v", engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE) * 100 / getMap(PASS_ENGINE_PARAMETER_SIGNATURE), 2);
}
reportSensorF(log, fileFormat, GAUGE_NAME_FUEL_INJ_DUTY, "%", getInjectorDutyCycle(rpm PASS_ENGINE_PARAMETER_SUFFIX), 2);
@ -704,7 +704,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
tsOutputChannels->accelerationY = engine->sensors.accelerometer.y;
if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
float mapValue = getMap();
float mapValue = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
tsOutputChannels->veValue = engine->engineState.currentBaroCorrectedVE * PERCENT_MULT;
// todo: bug here? target afr could work based on real MAF?
tsOutputChannels->currentTargetAfr = afrMap.getValue(rpm, mapValue);
@ -874,7 +874,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
tsOutputChannels->tpsAccelFuel = engine->engineState.tpsAccelEnrich;
// engine load acceleration
if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
tsOutputChannels->engineLoadAccelExtra = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE) * 100 / getMap();
tsOutputChannels->engineLoadAccelExtra = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE) * 100 / getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
}
tsOutputChannels->engineLoadDelta = engine->engineLoadAccelEnrichment.getMaxDelta();

View File

@ -285,7 +285,7 @@ static void showLine(lcd_line_e line, int screenY) {
return;
case LL_MAP:
if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
lcdPrintf("MAP %.2f", getMap());
lcdPrintf("MAP %.2f", getMap(PASS_ENGINE_PARAMETER_SIGNATURE));
} else {
lcdPrintf("MAP: none");
}

View File

@ -358,6 +358,12 @@ public:
int globalSparkIdCoutner = 0;
#if !EFI_PROD_CODE
float mockMapValue = 0;
// for historical reasons we have options to mock TPS on different layers :(
int mockTpsAdcValue = 0;
float mockTpsValue = NAN;
#endif
int getGlobalConfigurationVersion(void) const;
/**

View File

@ -210,7 +210,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (engineConfiguration->fuelAlgorithm == LM_SPEED_DENSITY) {
float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
updateTChargeK(rpm, tps PASS_ENGINE_PARAMETER_SUFFIX);
float map = getMap();
float map = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
/**
* *0.01 because of https://sourceforge.net/p/rusefi/tickets/153/

View File

@ -83,7 +83,7 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
floatms_t baseFuel;
if (CONFIG(fuelAlgorithm) == LM_SPEED_DENSITY) {
baseFuel = getSpeedDensityFuel(getMap() PASS_ENGINE_PARAMETER_SUFFIX);
baseFuel = getSpeedDensityFuel(getMap(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX);
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(baseFuel), "NaN sd baseFuel", 0);
} else if (engineConfiguration->fuelAlgorithm == LM_REAL_MAF) {
float maf = getRealMaf(PASS_ENGINE_PARAMETER_SIGNATURE) + engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE);
@ -268,7 +268,7 @@ float getFuelCutOffCorrection(efitick_t nowNt, int rpm DECLARE_ENGINE_PARAMETER_
// coasting fuel cut-off correction
if (CONFIGB(coastingFuelCutEnabled)) {
percent_t tpsPos = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
float map = getMap();
float map = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
// gather events
bool mapDeactivate = (map >= CONFIG(coastingFuelCutMap));

View File

@ -125,7 +125,7 @@ float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) {
case LE_METHOD_MAF:
return getMaf(PASS_ENGINE_PARAMETER_SIGNATURE);
case LE_METHOD_MAP:
return getMap();
return getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
case LE_METHOD_INTAKE_VVT:
case LE_METHOD_EXHAUST_VVT:
return engine->triggerCentral.vvtPosition;

View File

@ -64,7 +64,7 @@ float getEngineLoadT(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
case LM_SPEED_DENSITY:
// SD engine load is used for timing lookup but not for fuel calculation
case LM_MAP:
return getMap();
return getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
case LM_ALPHA_N:
return getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
case LM_REAL_MAF: {

View File

@ -146,7 +146,7 @@ static void handleGetDataRequest(CANRxFrame *rx) {
break;
case PID_INTAKE_MAP:
scheduleMsg(&logger, "Got MAP request");
obdSendValue(1, pid, 1, getMap());
obdSendValue(1, pid, 1, getMap(PASS_ENGINE_PARAMETER_SIGNATURE));
break;
case PID_RPM:
scheduleMsg(&logger, "Got RPM request");

View File

@ -22,7 +22,7 @@ bool hasMapSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE);
/**
* @return MAP value averaged within a window of measurement
*/
float getMap(void);
float getMap(DECLARE_ENGINE_PARAMETER_SIGNATURE);
float getMapByVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
float decodePressure(float voltage, air_pressure_sensor_config_s * mapConfig DECLARE_ENGINE_PARAMETER_SUFFIX);
float validateMap(float mapKPa DECLARE_ENGINE_PARAMETER_SUFFIX);

View File

@ -11,12 +11,6 @@
EXTERN_ENGINE;
#if !EFI_PROD_CODE
// for historical reasons we have options to mock TPS on different layers :(
static int mockTpsAdcValue;
static float mockTpsValue = NAN;
#endif /* EFI_PROD_CODE */
/**
* set mock_pedal_position X
* See also directPwmValue
@ -27,16 +21,16 @@ percent_t mockPedalPosition = MOCK_UNDEFINED;
/**
* this allows unit tests to simulate TPS position
*/
void setMockTpsAdc(percent_t tpsPosition) {
mockTpsAdcValue = TPS_TS_CONVERSION * tpsPosition;
void setMockTpsAdc(percent_t tpsPosition DECLARE_ENGINE_PARAMETER_SUFFIX) {
engine->mockTpsAdcValue = TPS_TS_CONVERSION * tpsPosition;
}
void setMockTpsValue(percent_t tpsPosition) {
mockTpsValue = tpsPosition;
void setMockTpsValue(percent_t tpsPosition DECLARE_ENGINE_PARAMETER_SUFFIX) {
engine->mockTpsValue = tpsPosition;
}
#endif /* EFI_PROD_CODE */
void setMockPedalPosition(percent_t value) {
void setMockPedalPosition(percent_t value DECLARE_ENGINE_PARAMETER_SUFFIX) {
mockPedalPosition = value;
}
@ -120,8 +114,8 @@ float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
*/
int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if !EFI_PROD_CODE
if (mockTpsAdcValue != MOCK_UNDEFINED) {
return mockTpsAdcValue;
if (engine->mockTpsAdcValue != MOCK_UNDEFINED) {
return engine->mockTpsAdcValue;
}
#endif
if (engineConfiguration->tps1_1AdcChannel == EFI_ADC_NONE)
@ -194,8 +188,8 @@ bool hasTpsSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
percent_t getTPS(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if !EFI_PROD_CODE
if (!cisnan(mockTpsValue)) {
return mockTpsValue;
if (!cisnan(engine->mockTpsValue)) {
return engine->mockTpsValue;
}
#endif /* EFI_PROD_CODE */
if (!hasTpsSensor(PASS_ENGINE_PARAMETER_SIGNATURE))

View File

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

View File

@ -480,7 +480,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D
bool limitedFuel = rpm > CONFIG(rpmHardLimit);
if (CONFIG(boostCutPressure) !=0) {
if (getMap() > CONFIG(boostCutPressure)) {
if (getMap(PASS_ENGINE_PARAMETER_SIGNATURE) > CONFIG(boostCutPressure)) {
limitedSpark = true;
limitedFuel = true;
}

View File

@ -7,7 +7,7 @@
#include "global.h"
#include "engine_math.h"
#include "engine_configuration.h"
#include "engine.h"
#include "map.h"
#include "speed_density.h"
#include "engine_test_helper.h"
@ -107,8 +107,6 @@ TEST(misc, testMafLookup) {
ASSERT_EQ( 738, engine->mafDecodingLookup[255]) << "@255";
}
float mockMapValue = 0;
float getMap(void) {
return mockMapValue;
float getMap(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return engine->mockMapValue;
}

View File

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

View File

@ -224,7 +224,6 @@ TEST(misc, testPinHelper) {
}
extern fuel_Map3D_t veMap;
extern float mockMapValue;
TEST(fuel, testTpsBasedVeDefect799) {
@ -251,8 +250,8 @@ TEST(fuel, testTpsBasedVeDefect799) {
setLinearCurve(CONFIG(ignitionTpsBins), IGN_TPS_COUNT, 0, 15, 1);
mockMapValue = 107;
setMockTpsValue(7);
engine->mockMapValue = 107;
setMockTpsValue(7 PASS_ENGINE_PARAMETER_SUFFIX);
engine->engineState.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
// we have a problem - we get value on the edge of the MAP axis, not middle of TPS axis

View File

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

View File

@ -31,7 +31,6 @@
#include "spark_logic.h"
#include "trigger_universal.h"
extern float mockMapValue;
extern float testMafValue;
extern WarningCodeState unitTestWarningCodeState;
extern bool printTriggerDebug;
@ -246,11 +245,11 @@ TEST(misc, testStartupFuelPumping) {
engineConfiguration->tpsMin = 0;
engineConfiguration->tpsMax = 10;
setMockTpsAdc(6);
setMockTpsAdc(6 PASS_ENGINE_PARAMETER_SUFFIX);
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ( 1, sf.pumpsCounter) << "pc#1";
setMockTpsAdc(3);
setMockTpsAdc(3 PASS_ENGINE_PARAMETER_SUFFIX);
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ( 1, sf.pumpsCounter) << "pumpsCounter#2";
@ -261,16 +260,16 @@ TEST(misc, testStartupFuelPumping) {
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ( 0, sf.pumpsCounter) << "pc#4";
setMockTpsAdc(7);
setMockTpsAdc(7 PASS_ENGINE_PARAMETER_SUFFIX);
engine->rpmCalculator.mockRpm = 0;
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ( 1, sf.pumpsCounter) << "pc#5";
setMockTpsAdc(3);
setMockTpsAdc(3 PASS_ENGINE_PARAMETER_SUFFIX);
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ( 1, sf.pumpsCounter) << "pc#6";
setMockTpsAdc(7);
setMockTpsAdc(7 PASS_ENGINE_PARAMETER_SUFFIX);
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ( 2, sf.pumpsCounter) << "pc#7";
}
@ -931,7 +930,7 @@ void doTestFuelSchedulerBug299smallAndMedium(int startUpDelayMs) {
eth.executeActions();
mockMapValue = 0;
engine->mockMapValue = 0;
testMafValue = 0;
ASSERT_EQ( 1, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testFuelSchedulerBug299smallAndMedium";
ASSERT_EQ(CUSTOM_OBD_SKIPPED_FUEL, unitTestWarningCodeState.recentWarnings.get(0));