Start the process of using a global engine ptr for unit tests. (#3551)
* Start the process of using a global engine ptr for unit tests. Passing around the engine, config, and persistent state wasn't buying anything. Instead, use EngineTestHelper(Base) to correctly set and clear the global variables. Add a dummy check in case some test tries to set them manually. * Fix OSX build * Adapt PR to recently added code.
This commit is contained in:
parent
868c07a303
commit
344c9073e2
|
@ -398,5 +398,5 @@ void doScheduleStopEngine(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
|||
// These externs aren't needed for unit tests - everything is injected instead
|
||||
#if !EFI_UNIT_TEST
|
||||
extern Engine ___engine;
|
||||
extern Engine *engine;
|
||||
#endif // EFI_UNIT_TEST
|
||||
extern Engine *engine;
|
||||
|
|
|
@ -64,10 +64,10 @@ void setBoardDefaultConfiguration(void);
|
|||
void setBoardConfigOverrides(void);
|
||||
|
||||
#if !EFI_UNIT_TEST
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
extern persistent_config_container_s persistentState;
|
||||
extern persistent_config_s *config;
|
||||
#endif // EFI_UNIT_TEST
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
extern persistent_config_s *config;
|
||||
|
||||
/**
|
||||
* & is reference in C++ (not C)
|
||||
|
|
|
@ -25,43 +25,31 @@ struct persistent_config_s;
|
|||
#if EFI_UNIT_TEST
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define DECLARE_CONFIG_PARAMETER_SIGNATURE engine_configuration_s *engineConfiguration, persistent_config_s *config
|
||||
#define DECLARE_CONFIG_PARAMETER_SUFFIX , DECLARE_CONFIG_PARAMETER_SIGNATURE
|
||||
#define PASS_CONFIG_PARAMETER_SIGNATURE engineConfiguration, config
|
||||
#define PASS_CONFIG_PARAMETER_SUFFIX , PASS_CONFIG_PARAMETER_SIGNATURE
|
||||
#define DECLARE_CONFIG_PARAMETER_SIGNATURE void
|
||||
#define DECLARE_CONFIG_PARAMETER_SUFFIX
|
||||
#define PASS_CONFIG_PARAMETER_SIGNATURE
|
||||
#define PASS_CONFIG_PARAMETER_SUFFIX
|
||||
|
||||
/**
|
||||
* @see firmware/global.h for explanation
|
||||
*/
|
||||
#define DECLARE_ENGINE_PARAMETER_SIGNATURE Engine *engine, DECLARE_CONFIG_PARAMETER_SIGNATURE
|
||||
#define DECLARE_ENGINE_PARAMETER_SUFFIX , DECLARE_ENGINE_PARAMETER_SIGNATURE
|
||||
#define PASS_ENGINE_PARAMETER_SIGNATURE engine, PASS_CONFIG_PARAMETER_SIGNATURE
|
||||
#define PASS_ENGINE_PARAMETER_SUFFIX , PASS_ENGINE_PARAMETER_SIGNATURE
|
||||
#define DECLARE_ENGINE_PARAMETER_SIGNATURE void
|
||||
#define DECLARE_ENGINE_PARAMETER_SUFFIX
|
||||
#define PASS_ENGINE_PARAMETER_SIGNATURE
|
||||
#define PASS_ENGINE_PARAMETER_SUFFIX
|
||||
|
||||
#define EXTERN_ENGINE extern engine_configuration_s & activeConfiguration
|
||||
|
||||
struct EnginePtr {
|
||||
Engine* engine = nullptr;
|
||||
engine_configuration_s* engineConfiguration = nullptr;
|
||||
persistent_config_s* config = nullptr;
|
||||
|
||||
void inject(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
this->engine = engine;
|
||||
this->engineConfiguration = engineConfiguration;
|
||||
this->config = config;
|
||||
}
|
||||
};
|
||||
#endif // def __cplusplus
|
||||
|
||||
#define DEFINE_CONFIG_PARAM(x, y) , x y
|
||||
#define PASS_CONFIG_PARAM(x) , x
|
||||
#define DEFINE_CONFIG_PARAM(x, y)
|
||||
#define PASS_CONFIG_PARAM(x)
|
||||
|
||||
#define EXPAND_Engine \
|
||||
if (engine == nullptr) { firmwareError(OBD_PCM_Processor_Fault, "EXPAND_Engine engine ptr missing"); } \
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration; \
|
||||
persistent_config_s *config = engine->config; \
|
||||
(void)engineConfiguration; \
|
||||
(void)config;
|
||||
#define EXPAND_Engine
|
||||
|
||||
#define CONFIG(x) engineConfiguration->x
|
||||
#define ENGINE(x) engine->x
|
||||
|
|
|
@ -100,6 +100,10 @@
|
|||
Engine ___engine CCM_OPTIONAL;
|
||||
Engine * engine = &___engine;
|
||||
|
||||
#else // EFI_UNIT_TEST
|
||||
|
||||
Engine * engine;
|
||||
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
|
||||
|
||||
|
|
|
@ -25,12 +25,6 @@ static void plainPinTurnOff(NamedOutputPin *output) {
|
|||
|
||||
|
||||
static void scheduleOpen(AuxActor *current) {
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = current->engine;
|
||||
EXPAND_Engine;
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
|
||||
scheduleOrQueue(¤t->open,
|
||||
TRIGGER_EVENT_UNDEFINED,
|
||||
getTimeNowNt(),
|
||||
|
@ -44,11 +38,6 @@ void auxPlainPinTurnOn(AuxActor *current) {
|
|||
NamedOutputPin *output = &enginePins.auxValve[current->valveIndex];
|
||||
output->setHigh();
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = current->engine;
|
||||
EXPAND_Engine;
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
|
||||
scheduleOpen(current);
|
||||
|
||||
angle_t duration = engine->engineState.auxValveEnd - engine->engineState.auxValveStart;
|
||||
|
|
|
@ -77,10 +77,6 @@ static void endSimultaniousInjectionOnlyTogglePins(Engine *engine) {
|
|||
}
|
||||
|
||||
void endSimultaniousInjection(InjectionEvent *event) {
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = event->engine;
|
||||
EXPAND_Engine;
|
||||
#endif
|
||||
event->isScheduled = false;
|
||||
endSimultaniousInjectionOnlyTogglePins(engine);
|
||||
engine->injectionEvents.addFuelEventsForCylinder(event->ownIndex PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
@ -115,10 +111,6 @@ void InjectorOutputPin::open(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
}
|
||||
|
||||
void turnInjectionPinHigh(InjectionEvent *event) {
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = event->engine;
|
||||
EXPAND_Engine;
|
||||
#endif // EFI_UNIT_TEST
|
||||
efitick_t nowNt = getTimeNowNt();
|
||||
for (int i = 0;i < MAX_WIRES_COUNT;i++) {
|
||||
InjectorOutputPin *output = event->outputs[i];
|
||||
|
@ -159,11 +151,6 @@ void InjectorOutputPin::close(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
void turnInjectionPinLow(InjectionEvent *event) {
|
||||
efitick_t nowNt = getTimeNowNt();
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = event->engine;
|
||||
EXPAND_Engine;
|
||||
#endif
|
||||
|
||||
engine->mostRecentTimeBetweenIgnitionEvents = nowNt - engine->mostRecentIgnitionEvent;
|
||||
engine->mostRecentIgnitionEvent = nowNt;
|
||||
|
||||
|
|
|
@ -96,11 +96,6 @@ static void startAveraging(scheduling_s *endAveragingScheduling) {
|
|||
isAveraging = true;
|
||||
}
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = endAveragingScheduling->engine;
|
||||
EXPAND_Engine;
|
||||
#endif
|
||||
|
||||
mapAveragingPin.setHigh();
|
||||
|
||||
scheduleByAngle(endAveragingScheduling, getTimeNowNt(), ENGINE(engineState.mapAveragingDuration),
|
||||
|
|
|
@ -35,10 +35,6 @@ int isIgnitionTimingError(void) {
|
|||
}
|
||||
|
||||
static void fireSparkBySettingPinLow(IgnitionEvent *event, IgnitionOutputPin *output) {
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = event->engine;
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
|
||||
efitick_t nowNt = getTimeNowNt();
|
||||
engine->mostRecentTimeBetweenSparkEvents = nowNt - engine->mostRecentSparkEvent;
|
||||
engine->mostRecentSparkEvent = nowNt;
|
||||
|
@ -154,11 +150,6 @@ void fireSparkAndPrepareNextSchedule(IgnitionEvent *event) {
|
|||
|
||||
efitick_t nowNt = getTimeNowNt();
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = event->engine;
|
||||
EXPAND_Engine;
|
||||
#endif // EFI_UNIT_TEST
|
||||
|
||||
#if EFI_TOOTH_LOGGER
|
||||
LogTriggerCoilState(nowNt, false PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
#endif // EFI_TOOTH_LOGGER
|
||||
|
@ -235,11 +226,6 @@ if (engineConfiguration->debugMode == DBG_DWELL_METRIC) {
|
|||
}
|
||||
|
||||
static void startDwellByTurningSparkPinHigh(IgnitionEvent *event, IgnitionOutputPin *output) {
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = event->engine;
|
||||
EXPAND_Engine;
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
|
||||
// todo: no reason for this to be disabled in unit_test mode?!
|
||||
#if ! EFI_UNIT_TEST
|
||||
|
||||
|
@ -276,10 +262,6 @@ void turnSparkPinHigh(IgnitionEvent *event) {
|
|||
efitick_t nowNt = getTimeNowNt();
|
||||
|
||||
#if EFI_TOOTH_LOGGER
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = event->engine;
|
||||
EXPAND_Engine;
|
||||
#endif // EFI_UNIT_TEST
|
||||
LogTriggerCoilState(nowNt, true PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
#endif // EFI_TOOTH_LOGGER
|
||||
|
||||
|
@ -455,9 +437,6 @@ void initializeIgnitionActions(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
|
||||
for (size_t cylinderIndex = 0; cylinderIndex < CONFIG(specs.cylindersCount); cylinderIndex++) {
|
||||
list->elements[cylinderIndex].cylinderIndex = cylinderIndex;
|
||||
#if EFI_UNIT_TEST
|
||||
list->elements[cylinderIndex].engine = engine;
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
prepareCylinderIgnitionSchedule(dwellAngle, sparkDwell, &list->elements[cylinderIndex] PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
list->isReady = true;
|
||||
|
|
|
@ -19,10 +19,6 @@ using namespace luaaa;
|
|||
// Some functions lean on existing FSIO implementation
|
||||
#include "fsio_impl.h"
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engineForLuaUnitTests;
|
||||
#endif
|
||||
|
||||
static int lua_readpin(lua_State* l) {
|
||||
auto msg = luaL_checkstring(l, 1);
|
||||
#if EFI_PROD_CODE
|
||||
|
@ -104,11 +100,6 @@ static int lua_curve2d(lua_State* l) {
|
|||
auto humanCurveIdx = luaL_checkinteger(l, 1);
|
||||
auto x = luaL_checknumber(l, 2);
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = engineForLuaUnitTests;
|
||||
EXPAND_Engine;
|
||||
#endif
|
||||
|
||||
auto result = getCurveValue(humanCurveIdx - HUMAN_OFFSET, x PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
lua_pushnumber(l, result);
|
||||
|
@ -116,10 +107,6 @@ static int lua_curve2d(lua_State* l) {
|
|||
}
|
||||
|
||||
static int lua_findCurveIndex(lua_State* l) {
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = engineForLuaUnitTests;
|
||||
EXPAND_Engine;
|
||||
#endif
|
||||
auto name = luaL_checklstring(l, 1, nullptr);
|
||||
auto result = getCurveIndexByName(name PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
if (result == EFI_ERROR_CODE) {
|
||||
|
@ -473,10 +460,6 @@ void configureRusefiLuaHooks(lua_State* l) {
|
|||
|
||||
lua_register(l, "findTableIndex",
|
||||
[](lua_State* l) {
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = engineForLuaUnitTests;
|
||||
EXPAND_Engine;
|
||||
#endif
|
||||
auto name = luaL_checklstring(l, 1, nullptr);
|
||||
auto index = getTableIndexByName(name PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
if (index == EFI_ERROR_CODE) {
|
||||
|
@ -490,10 +473,6 @@ void configureRusefiLuaHooks(lua_State* l) {
|
|||
|
||||
lua_register(l, "findSetting",
|
||||
[](lua_State* l) {
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = engineForLuaUnitTests;
|
||||
EXPAND_Engine;
|
||||
#endif
|
||||
auto name = luaL_checklstring(l, 1, nullptr);
|
||||
auto defaultValue = luaL_checknumber(l, 2);
|
||||
|
||||
|
@ -527,10 +506,6 @@ void configureRusefiLuaHooks(lua_State* l) {
|
|||
lua_register(l, "setFuelMult", lua_setFuelMult);
|
||||
|
||||
lua_register(l, "getTimeSinceTriggerEventMs", [](lua_State* l) {
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = engineForLuaUnitTests;
|
||||
EXPAND_Engine;
|
||||
#endif
|
||||
int result = engine->triggerCentral.m_lastEventTimer.getElapsedUs() / 1000;
|
||||
lua_pushnumber(l, result);
|
||||
return 1;
|
||||
|
|
|
@ -38,4 +38,9 @@ persistent_config_s *config = &persistentState.persistentConfiguration;
|
|||
*/
|
||||
engine_configuration_s *engineConfiguration = &persistentState.persistentConfiguration.engineConfiguration;
|
||||
|
||||
#else // EFI_UNIT_TEST
|
||||
|
||||
persistent_config_s * config;
|
||||
engine_configuration_s * engineConfiguration;
|
||||
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
|
|
|
@ -29,13 +29,29 @@ extern bool printTriggerDebug;
|
|||
extern bool printTriggerTrace;
|
||||
extern bool printFuelDebug;
|
||||
extern int minCrankingRpm;
|
||||
extern Engine *engineForLuaUnitTests;
|
||||
|
||||
EngineTestHelperBase::EngineTestHelperBase() {
|
||||
EngineTestHelperBase::EngineTestHelperBase(Engine * eng, engine_configuration_s * econfig, persistent_config_s * pers) {
|
||||
// todo: make this not a global variable, we need currentTimeProvider interface on engine
|
||||
timeNowUs = 0;
|
||||
minCrankingRpm = 0;
|
||||
EnableToothLogger();
|
||||
if (engine || engineConfiguration || config) {
|
||||
firmwareError(OBD_PCM_Processor_Fault,
|
||||
"Engine configuration not cleaned up by previous test");
|
||||
}
|
||||
engine = eng;
|
||||
engineConfiguration = econfig;
|
||||
config = pers;
|
||||
}
|
||||
|
||||
EngineTestHelperBase::~EngineTestHelperBase() {
|
||||
engine = nullptr;
|
||||
engineConfiguration = nullptr;
|
||||
config = nullptr;
|
||||
}
|
||||
|
||||
EngineTestHelper::EngineTestHelper(engine_type_e engineType)
|
||||
: EngineTestHelper(engineType, &emptyCallbackWithConfiguration) {
|
||||
}
|
||||
|
||||
EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callback_t configurationCallback)
|
||||
|
@ -54,12 +70,10 @@ int EngineTestHelper::getWarningCounter() {
|
|||
return unitTestWarningCodeState.warningCounter;
|
||||
}
|
||||
|
||||
EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callback_t configurationCallback, const std::unordered_map<SensorType, float>& sensorValues) {
|
||||
Engine *engine = &this->engine;
|
||||
engine->setConfig(engine, &persistentConfig.engineConfiguration, &persistentConfig);
|
||||
EXPAND_Engine;
|
||||
|
||||
engineForLuaUnitTests = engine;
|
||||
EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callback_t configurationCallback, const std::unordered_map<SensorType, float>& sensorValues) :
|
||||
EngineTestHelperBase(&engine, &persistentConfig.engineConfiguration, &persistentConfig)
|
||||
{
|
||||
memset(&persistentConfig, 0, sizeof(persistentConfig));
|
||||
|
||||
Sensor::setMockValue(SensorType::Clt, 70);
|
||||
Sensor::setMockValue(SensorType::Iat, 30);
|
||||
|
@ -103,15 +117,15 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callb
|
|||
commonInitEngineController(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
engineConfiguration->mafAdcChannel = EFI_ADC_10;
|
||||
engine->engineState.mockAdcState.setMockVoltage(EFI_ADC_10, 0 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
engine.engineState.mockAdcState.setMockVoltage(EFI_ADC_10, 0 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
// this is needed to have valid CLT and IAT.
|
||||
//todo: reuse initPeriodicEvents(PASS_ENGINE_PARAMETER_SIGNATURE) method
|
||||
engine->periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
engine.periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
// Setup running in mock airmass mode
|
||||
engineConfiguration->fuelAlgorithm = LM_MOCK;
|
||||
engine->mockAirmassModel = &mockAirmass;
|
||||
engine.mockAirmassModel = &mockAirmass;
|
||||
|
||||
memset(mockPinStates, 0, sizeof(mockPinStates));
|
||||
|
||||
|
@ -120,8 +134,6 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callb
|
|||
}
|
||||
|
||||
EngineTestHelper::~EngineTestHelper() {
|
||||
Engine *engine = &this->engine;
|
||||
EXPAND_Engine;
|
||||
// Write history to file
|
||||
std::stringstream filePath;
|
||||
filePath << "unittest_" << ::testing::UnitTest::GetInstance()->current_test_info()->name() << ".logicdata";
|
||||
|
@ -381,7 +393,7 @@ void setupSimpleTestEngineWithMaf(EngineTestHelper *eth, injection_mode_e inject
|
|||
void EngineTestHelper::setTriggerType(trigger_type_e trigger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
engineConfiguration->trigger.type = trigger;
|
||||
incrementGlobalConfigurationVersion(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
ASSERT_EQ( 1, engine->triggerCentral.isTriggerConfigChanged(PASS_ENGINE_PARAMETER_SIGNATURE)) << "trigger #2";
|
||||
ASSERT_EQ( 1, engine.triggerCentral.isTriggerConfigChanged(PASS_ENGINE_PARAMETER_SIGNATURE)) << "trigger #2";
|
||||
applyTriggerWaveform();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ class EngineTestHelperBase
|
|||
public:
|
||||
// we have the base method and base constructor in order to better control order if initialization
|
||||
// base constructor contains things which need to be executed first
|
||||
EngineTestHelperBase();
|
||||
EngineTestHelperBase(Engine * eng, engine_configuration_s * config, persistent_config_s * pers);
|
||||
~EngineTestHelperBase();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -29,6 +30,7 @@ public:
|
|||
*/
|
||||
class EngineTestHelper : public EngineTestHelperBase {
|
||||
public:
|
||||
explicit EngineTestHelper(engine_type_e engineType);
|
||||
EngineTestHelper(engine_type_e engineType, const std::unordered_map<SensorType, float>& sensorValues);
|
||||
EngineTestHelper(engine_type_e engineType, configuration_callback_t boardCallback);
|
||||
EngineTestHelper(engine_type_e engineType, configuration_callback_t boardCallback, const std::unordered_map<SensorType, float>& sensorValues);
|
||||
|
|
|
@ -66,8 +66,6 @@ void chDbgAssert(int c, char *msg, void *arg);
|
|||
* this macro provides references to engine from EngineTestHelper
|
||||
*/
|
||||
#define EXPAND_EngineTestHelper \
|
||||
Engine *engine = ð.engine; \
|
||||
EXPAND_Engine
|
||||
|
||||
#define WITH_ENGINE_TEST_HELPER_SENS(x, sensorvals) \
|
||||
EngineTestHelper eth(x, sensorvals); \
|
||||
|
@ -81,7 +79,7 @@ void chDbgAssert(int c, char *msg, void *arg);
|
|||
EngineTestHelper eth(x, callback, std::unordered_map<SensorType, float>{}); \
|
||||
EXPAND_EngineTestHelper;
|
||||
|
||||
#define CONFIG_PARAM(x) (x)
|
||||
#define CONFIG_PARAM(x) CONFIG(x)
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace chibios_rt {
|
||||
|
|
|
@ -35,15 +35,15 @@ TEST(misc, testFuelMap) {
|
|||
|
||||
printf("*************************************************** setting IAT table\r\n");
|
||||
for (int i = 0; i < IAT_CURVE_SIZE; i++) {
|
||||
eth.engine.config->iatFuelCorrBins[i] = i * 10;
|
||||
eth.engine.config->iatFuelCorr[i] = 2 * i;
|
||||
config->iatFuelCorrBins[i] = i * 10;
|
||||
config->iatFuelCorr[i] = 2 * i;
|
||||
}
|
||||
eth.engine.config->iatFuelCorr[0] = 2;
|
||||
config->iatFuelCorr[0] = 2;
|
||||
|
||||
printf("*************************************************** setting CLT table\r\n");
|
||||
for (int i = 0; i < CLT_CURVE_SIZE; i++) {
|
||||
eth.engine.config->cltFuelCorrBins[i] = i * 10;
|
||||
eth.engine.config->cltFuelCorr[i] = i;
|
||||
config->cltFuelCorrBins[i] = i * 10;
|
||||
config->cltFuelCorr[i] = i;
|
||||
}
|
||||
|
||||
Sensor::setMockValue(SensorType::Clt, 70.0f);
|
||||
|
@ -153,32 +153,32 @@ TEST(misc, testAngleResolver) {
|
|||
event_trigger_position_s injectionStart;
|
||||
|
||||
printf("*************************************************** testAngleResolver 0\r\n");
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape), &ENGINE(triggerCentral.triggerFormDetails),&injectionStart, -122, engineConfiguration->globalTriggerAngleOffset);
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape), &ENGINE(triggerCentral.triggerFormDetails),&injectionStart, -122);
|
||||
ASSERT_EQ( 2, injectionStart.triggerEventIndex) << "eventIndex@0";
|
||||
ASSERT_NEAR(0.24, injectionStart.angleOffsetFromTriggerEvent, EPS5D);
|
||||
|
||||
printf("*************************************************** testAngleResolver 0.1\r\n");
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape), &ENGINE(triggerCentral.triggerFormDetails),&injectionStart, -80, engineConfiguration->globalTriggerAngleOffset);
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape), &ENGINE(triggerCentral.triggerFormDetails),&injectionStart, -80);
|
||||
ASSERT_EQ( 2, injectionStart.triggerEventIndex) << "eventIndex@0";
|
||||
ASSERT_FLOAT_EQ(42.24, injectionStart.angleOffsetFromTriggerEvent);
|
||||
|
||||
printf("*************************************************** testAngleResolver 0.2\r\n");
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape), &ENGINE(triggerCentral.triggerFormDetails),&injectionStart, -54, engineConfiguration->globalTriggerAngleOffset);
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape), &ENGINE(triggerCentral.triggerFormDetails),&injectionStart, -54);
|
||||
ASSERT_EQ( 2, injectionStart.triggerEventIndex) << "eventIndex@0";
|
||||
ASSERT_FLOAT_EQ(68.2400, injectionStart.angleOffsetFromTriggerEvent);
|
||||
|
||||
printf("*************************************************** testAngleResolver 0.3\r\n");
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape), &ENGINE(triggerCentral.triggerFormDetails),&injectionStart, -53, engineConfiguration->globalTriggerAngleOffset);
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape), &ENGINE(triggerCentral.triggerFormDetails),&injectionStart, -53);
|
||||
ASSERT_EQ(2, injectionStart.triggerEventIndex);
|
||||
ASSERT_FLOAT_EQ(69.24, injectionStart.angleOffsetFromTriggerEvent);
|
||||
|
||||
printf("*************************************************** testAngleResolver 1\r\n");
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape), &ENGINE(triggerCentral.triggerFormDetails),&injectionStart, 0, engineConfiguration->globalTriggerAngleOffset);
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape), &ENGINE(triggerCentral.triggerFormDetails),&injectionStart, 0);
|
||||
ASSERT_EQ(2, injectionStart.triggerEventIndex);
|
||||
ASSERT_FLOAT_EQ(122.24, injectionStart.angleOffsetFromTriggerEvent);
|
||||
|
||||
printf("*************************************************** testAngleResolver 2\r\n");
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape), &ENGINE(triggerCentral.triggerFormDetails),&injectionStart, 56, engineConfiguration->globalTriggerAngleOffset);
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape), &ENGINE(triggerCentral.triggerFormDetails),&injectionStart, 56);
|
||||
ASSERT_EQ(2, injectionStart.triggerEventIndex);
|
||||
ASSERT_FLOAT_EQ(178.24, injectionStart.angleOffsetFromTriggerEvent);
|
||||
|
||||
|
|
|
@ -9,17 +9,15 @@ public:
|
|||
EngineTestHelper eth;
|
||||
TurbochargerSpeedConverter dut;
|
||||
|
||||
TurbochargerSpeedConverterTest()
|
||||
: eth(ENGINE_TEST_HELPER, std::unordered_map<SensorType, float>{}) {
|
||||
TurbochargerSpeedConverterTest() : eth(ENGINE_TEST_HELPER) {
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
EXPAND_EngineTestHelper;
|
||||
dut.inject(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
}
|
||||
|
||||
void SetCoef(float new_coef) {
|
||||
dut.engineConfiguration->turboSpeedSensorMultiplier = new_coef;
|
||||
engineConfiguration->turboSpeedSensorMultiplier = new_coef;
|
||||
}
|
||||
|
||||
float GetFrequencyBySpeedAndCoef(float speed, float coef) {
|
||||
|
|
|
@ -9,17 +9,15 @@ public:
|
|||
EngineTestHelper eth;
|
||||
VehicleSpeedConverter dut;
|
||||
|
||||
VehicleSpeedConverterTest()
|
||||
: eth(ENGINE_TEST_HELPER, std::unordered_map<SensorType, float>{}) {
|
||||
VehicleSpeedConverterTest() : eth(ENGINE_TEST_HELPER) {
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
EXPAND_EngineTestHelper;
|
||||
dut.inject(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
}
|
||||
|
||||
void SetCoef(float new_coef) {
|
||||
dut.engineConfiguration->vehicleSpeedCoef = new_coef;
|
||||
engineConfiguration->vehicleSpeedCoef = new_coef;
|
||||
}
|
||||
|
||||
float GetFrequencyBySpeedAndCoef(float speed, float coef) {
|
||||
|
|
|
@ -680,8 +680,8 @@ TEST(etb, closedLoopPid) {
|
|||
|
||||
// Disable autotune for now
|
||||
Engine e;
|
||||
EngineTestHelperBase base(&e, nullptr, nullptr);
|
||||
e.etbAutoTune = false;
|
||||
etb.engine = &e;
|
||||
|
||||
// Setpoint greater than actual, should be positive output
|
||||
EXPECT_FLOAT_EQ(etb.getClosedLoop(50, 40).value_or(-1), 50);
|
||||
|
|
|
@ -9,7 +9,7 @@ using ::testing::StrictMock;
|
|||
|
||||
class MockClCell : public ClosedLoopFuelCellBase {
|
||||
public:
|
||||
MOCK_METHOD(float, getLambdaError, (DECLARE_ENGINE_PARAMETER_SIGNATURE), (const));
|
||||
MOCK_METHOD(float, getLambdaError, (), (const));
|
||||
MOCK_METHOD(float, getMaxAdjustment, (), (const));
|
||||
MOCK_METHOD(float, getMinAdjustment, (), (const));
|
||||
MOCK_METHOD(float, getIntegratorGain, (), (const));
|
||||
|
@ -19,10 +19,10 @@ TEST(ClosedLoopCell, TestDeadband) {
|
|||
StrictMock<MockClCell> cl;
|
||||
|
||||
// Error is more than deadtime, so nothing else should be called
|
||||
EXPECT_CALL(cl, getLambdaError(_, _, _))
|
||||
EXPECT_CALL(cl, getLambdaError())
|
||||
.WillOnce(Return(0.05f));
|
||||
|
||||
cl.update(0.1f, true, nullptr, nullptr, nullptr);
|
||||
cl.update(0.1f, true);
|
||||
|
||||
// Should be zero adjustment
|
||||
EXPECT_FLOAT_EQ(cl.getAdjustment(), 1.0f);
|
||||
|
@ -31,7 +31,7 @@ TEST(ClosedLoopCell, TestDeadband) {
|
|||
TEST(ClosedLoopFuelCell, AdjustRate) {
|
||||
StrictMock<MockClCell> cl;
|
||||
|
||||
EXPECT_CALL(cl, getLambdaError(_, _, _))
|
||||
EXPECT_CALL(cl, getLambdaError())
|
||||
.WillOnce(Return(0.1f));
|
||||
EXPECT_CALL(cl, getMinAdjustment())
|
||||
.WillOnce(Return(-0.2f));
|
||||
|
@ -40,7 +40,7 @@ TEST(ClosedLoopFuelCell, AdjustRate) {
|
|||
EXPECT_CALL(cl, getIntegratorGain())
|
||||
.WillOnce(Return(2.0f));
|
||||
|
||||
cl.update(0.0f, false, nullptr, nullptr, nullptr);
|
||||
cl.update(0.0f, false);
|
||||
|
||||
// Should have integrated 0.2 * dt
|
||||
// dt = 1000.0f / FAST_CALLBACK_PERIOD_MS
|
||||
|
|
|
@ -52,10 +52,10 @@ TEST_P(AllTriggersFixture, TestTrigger) {
|
|||
printf("Exporting %s\r\n", getTrigger_type_e(tt));
|
||||
|
||||
persistent_config_s pc;
|
||||
memset(&pc, 0, sizeof(pc));
|
||||
Engine e;
|
||||
Engine* engine = &e;
|
||||
engine->setConfig(engine, &pc.engineConfiguration, &pc);
|
||||
EXPAND_Engine;
|
||||
EngineTestHelperBase base(engine, &pc.engineConfiguration, &pc);
|
||||
|
||||
engineConfiguration->trigger.type = tt;
|
||||
engineConfiguration->ambiguousOperationMode = FOUR_STROKE_CAM_SENSOR;
|
||||
|
|
|
@ -161,17 +161,17 @@ TEST(misc, test1995FordInline6TriggerDecoder) {
|
|||
ASSERT_EQ( 0, engineConfiguration->globalTriggerAngleOffset) << "globalTriggerAngleOffset";
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape),
|
||||
&ENGINE(triggerCentral.triggerFormDetails),
|
||||
&position, 0, engineConfiguration->globalTriggerAngleOffset);
|
||||
&position, 0);
|
||||
assertTriggerPosition(&position, 0, 0);
|
||||
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape),
|
||||
&ENGINE(triggerCentral.triggerFormDetails),
|
||||
&position, 200, engineConfiguration->globalTriggerAngleOffset);
|
||||
&position, 200);
|
||||
assertTriggerPosition(&position, 3, 20);
|
||||
|
||||
findTriggerPosition(&ENGINE(triggerCentral.triggerShape),
|
||||
&ENGINE(triggerCentral.triggerFormDetails),
|
||||
&position, 360, engineConfiguration->globalTriggerAngleOffset);
|
||||
&position, 360);
|
||||
assertTriggerPosition(&position, 6, 0);
|
||||
|
||||
eth.applyTriggerWaveform();
|
||||
|
@ -460,9 +460,7 @@ TEST(misc, testTriggerDecoder) {
|
|||
{
|
||||
persistent_config_s c;
|
||||
Engine e;
|
||||
e.setConfig(&e, &c.engineConfiguration, &c);
|
||||
Engine* engine = &e;
|
||||
EXPAND_Engine;
|
||||
EngineTestHelperBase base(&e, &c.engineConfiguration, &c);
|
||||
TriggerWaveform * s = &e.triggerCentral.triggerShape;
|
||||
|
||||
s->useOnlyRisingEdgeForTriggerTemp = false;
|
||||
|
|
|
@ -23,7 +23,7 @@ static void fireEvent(EngineTestHelper *eth, bool isRise) {
|
|||
// but for noise filtering, both edges should be processed, so we fire falling events too
|
||||
if (isRise)
|
||||
eth->firePrimaryTriggerRise();
|
||||
else if (eth->engine.engineConfiguration->useNoiselessTriggerDecoder)
|
||||
else if (engineConfiguration->useNoiselessTriggerDecoder)
|
||||
eth->firePrimaryTriggerFall();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue