From 344c9073e254d86693e368c1c400eec2278097d9 Mon Sep 17 00:00:00 2001 From: Scott Smith Date: Mon, 15 Nov 2021 21:23:14 -0800 Subject: [PATCH] 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. --- firmware/controllers/algo/engine.h | 2 +- .../controllers/algo/engine_configuration.h | 4 +- firmware/controllers/core/engine_ptr.h | 34 +++++----------- firmware/controllers/engine_controller.cpp | 4 ++ .../controllers/engine_cycle/aux_valves.cpp | 11 ----- .../engine_cycle/main_trigger_callback.cpp | 13 ------ .../engine_cycle/map_averaging.cpp | 5 --- .../controllers/engine_cycle/spark_logic.cpp | 21 ---------- firmware/controllers/lua/lua_hooks.cpp | 25 ------------ firmware/controllers/persistent_store.cpp | 5 +++ unit_tests/engine_test_helper.cpp | 40 ++++++++++++------- unit_tests/engine_test_helper.h | 4 +- unit_tests/global.h | 4 +- .../ignition_injection/test_fuel_map.cpp | 22 +++++----- .../test_turbocharger_speed_converter.cpp | 6 +-- .../sensor/test_vehicle_speed_converter.cpp | 6 +-- unit_tests/tests/test_etb.cpp | 2 +- unit_tests/tests/test_stft.cpp | 10 ++--- .../tests/trigger/test_all_triggers.cpp | 4 +- .../tests/trigger/test_trigger_decoder.cpp | 10 ++--- .../tests/trigger/test_trigger_noiseless.cpp | 2 +- 21 files changed, 81 insertions(+), 153 deletions(-) diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 70cc64014a..f376a3d571 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -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; diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index dfd69cdb02..15c3013e3c 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -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) diff --git a/firmware/controllers/core/engine_ptr.h b/firmware/controllers/core/engine_ptr.h index 7997dbb9e1..36bebd427d 100644 --- a/firmware/controllers/core/engine_ptr.h +++ b/firmware/controllers/core/engine_ptr.h @@ -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 diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 046376d740..e401f57082 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -100,6 +100,10 @@ Engine ___engine CCM_OPTIONAL; Engine * engine = &___engine; +#else // EFI_UNIT_TEST + +Engine * engine; + #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/engine_cycle/aux_valves.cpp b/firmware/controllers/engine_cycle/aux_valves.cpp index aa63a5bb56..0055292adf 100644 --- a/firmware/controllers/engine_cycle/aux_valves.cpp +++ b/firmware/controllers/engine_cycle/aux_valves.cpp @@ -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; diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index ebfd23e8b4..ff3d04e200 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -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; diff --git a/firmware/controllers/engine_cycle/map_averaging.cpp b/firmware/controllers/engine_cycle/map_averaging.cpp index 21a48e2530..2288694c96 100644 --- a/firmware/controllers/engine_cycle/map_averaging.cpp +++ b/firmware/controllers/engine_cycle/map_averaging.cpp @@ -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), diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index e3c7535319..c5a65235fc 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -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; diff --git a/firmware/controllers/lua/lua_hooks.cpp b/firmware/controllers/lua/lua_hooks.cpp index b5b06308d9..98ea38072a 100644 --- a/firmware/controllers/lua/lua_hooks.cpp +++ b/firmware/controllers/lua/lua_hooks.cpp @@ -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; diff --git a/firmware/controllers/persistent_store.cpp b/firmware/controllers/persistent_store.cpp index dacc27a45c..d845e3b6ed 100644 --- a/firmware/controllers/persistent_store.cpp +++ b/firmware/controllers/persistent_store.cpp @@ -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 */ diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index bfa0e4d76b..a3b3683a14 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -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& 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& 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(); } diff --git a/unit_tests/engine_test_helper.h b/unit_tests/engine_test_helper.h index e9972ebfa8..2386d0f64c 100644 --- a/unit_tests/engine_test_helper.h +++ b/unit_tests/engine_test_helper.h @@ -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& sensorValues); EngineTestHelper(engine_type_e engineType, configuration_callback_t boardCallback); EngineTestHelper(engine_type_e engineType, configuration_callback_t boardCallback, const std::unordered_map& sensorValues); diff --git a/unit_tests/global.h b/unit_tests/global.h index af439b2b19..f16c3a35eb 100644 --- a/unit_tests/global.h +++ b/unit_tests/global.h @@ -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{}); \ EXPAND_EngineTestHelper; -#define CONFIG_PARAM(x) (x) +#define CONFIG_PARAM(x) CONFIG(x) #ifdef __cplusplus namespace chibios_rt { diff --git a/unit_tests/tests/ignition_injection/test_fuel_map.cpp b/unit_tests/tests/ignition_injection/test_fuel_map.cpp index f4cd0621d5..4c1e289008 100644 --- a/unit_tests/tests/ignition_injection/test_fuel_map.cpp +++ b/unit_tests/tests/ignition_injection/test_fuel_map.cpp @@ -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); diff --git a/unit_tests/tests/sensor/test_turbocharger_speed_converter.cpp b/unit_tests/tests/sensor/test_turbocharger_speed_converter.cpp index 9b270fb6d4..55b1db99b4 100644 --- a/unit_tests/tests/sensor/test_turbocharger_speed_converter.cpp +++ b/unit_tests/tests/sensor/test_turbocharger_speed_converter.cpp @@ -9,17 +9,15 @@ public: EngineTestHelper eth; TurbochargerSpeedConverter dut; - TurbochargerSpeedConverterTest() - : eth(ENGINE_TEST_HELPER, std::unordered_map{}) { + 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) { diff --git a/unit_tests/tests/sensor/test_vehicle_speed_converter.cpp b/unit_tests/tests/sensor/test_vehicle_speed_converter.cpp index 7166238800..7595dce579 100644 --- a/unit_tests/tests/sensor/test_vehicle_speed_converter.cpp +++ b/unit_tests/tests/sensor/test_vehicle_speed_converter.cpp @@ -9,17 +9,15 @@ public: EngineTestHelper eth; VehicleSpeedConverter dut; - VehicleSpeedConverterTest() - : eth(ENGINE_TEST_HELPER, std::unordered_map{}) { + 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) { diff --git a/unit_tests/tests/test_etb.cpp b/unit_tests/tests/test_etb.cpp index dfedb2ee88..d4417a881c 100644 --- a/unit_tests/tests/test_etb.cpp +++ b/unit_tests/tests/test_etb.cpp @@ -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); diff --git a/unit_tests/tests/test_stft.cpp b/unit_tests/tests/test_stft.cpp index 1f84934ca3..ecb8cbc45b 100644 --- a/unit_tests/tests/test_stft.cpp +++ b/unit_tests/tests/test_stft.cpp @@ -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 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 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 diff --git a/unit_tests/tests/trigger/test_all_triggers.cpp b/unit_tests/tests/trigger/test_all_triggers.cpp index ef0c907dff..f20585f6a7 100644 --- a/unit_tests/tests/trigger/test_all_triggers.cpp +++ b/unit_tests/tests/trigger/test_all_triggers.cpp @@ -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; diff --git a/unit_tests/tests/trigger/test_trigger_decoder.cpp b/unit_tests/tests/trigger/test_trigger_decoder.cpp index 601a060931..db8bf617f2 100644 --- a/unit_tests/tests/trigger/test_trigger_decoder.cpp +++ b/unit_tests/tests/trigger/test_trigger_decoder.cpp @@ -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; diff --git a/unit_tests/tests/trigger/test_trigger_noiseless.cpp b/unit_tests/tests/trigger/test_trigger_noiseless.cpp index d24a99af00..6d1e2da9bf 100644 --- a/unit_tests/tests/trigger/test_trigger_noiseless.cpp +++ b/unit_tests/tests/trigger/test_trigger_noiseless.cpp @@ -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(); }