diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 21b10e15cb..26baf01a57 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -22,7 +22,6 @@ */ #include "global.h" -#if !EFI_UNIT_TEST #if EFI_SENSOR_CHART #include "sensor_chart.h" #endif @@ -80,6 +79,14 @@ #include "cj125.h" #endif +// this method is used by real firmware and simulator and unit test +void mostCommonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { + initSensors(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX); + initAccelEnrichment(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX); +} + +#if !EFI_UNIT_TEST + #if defined(EFI_BOOTLOADER_INCLUDE_CODE) #include "bootloader/bootloader.h" #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ @@ -160,7 +167,7 @@ efitick_t getTimeNowNt(void) { unlockAnyContext(); } return result; -#else +#else /* EFI_PROD_CODE */ // todo: why is this implementation not used? /** * this method is lock-free and thread-safe, that's because the 'update' method @@ -192,7 +199,7 @@ efitick_t getTimeNowNt(void) { } return localH + value; -#endif +#endif /* EFI_PROD_CODE */ } @@ -625,7 +632,7 @@ static void getKnockInfo(void) { engine->printKnockState(); } -// this method is used by real firmware and simulator +// this method is used by real firmware and simulator but not unit tests void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { #if EFI_SIMULATOR printf("commonInitEngineController\n"); @@ -648,19 +655,16 @@ void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S if (engineConfiguration->isTunerStudioEnabled) { startTunerStudioConnectivity(); } -#endif +#endif /* EFI_TUNER_STUDIO */ if (hasFirmwareError()) { return; } - initSensors(sharedLogger PASS_ENGINE_PARAMETER_SIGNATURE); + mostCommonInitEngineController(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX); #if EFI_FSIO initFsioImpl(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX); -#endif - - initAccelEnrichment(sharedLogger); - +#endif /* EFI_FSIO */ } void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { diff --git a/firmware/controllers/engine_controller.h b/firmware/controllers/engine_controller.h index cbbc1ffd5b..470bb85313 100644 --- a/firmware/controllers/engine_controller.h +++ b/firmware/controllers/engine_controller.h @@ -18,6 +18,7 @@ char * getPinNameByAdcChannel(const char *msg, adc_channel_e hwChannel, char *bu void initPeriodicEvents(DECLARE_ENGINE_PARAMETER_SIGNATURE); void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX); void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX); +void mostCommonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX); void setMockVBattVoltage(float voltage); void setMockMapVoltage(float voltage); diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index 540e99e269..45512a8d48 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -12,6 +12,7 @@ #include "fuel_math.h" #include "accel_enrichment.h" #include "allsensors.h" +#include "engine_controller.h" #include "advance_map.h" #include "algo.h" @@ -57,8 +58,7 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persiste initDataStructures(PASS_ENGINE_PARAMETER_SIGNATURE); - initAccelEnrichment(NULL PASS_ENGINE_PARAMETER_SUFFIX); - initSensors(NULL PASS_ENGINE_PARAMETER_SUFFIX); + mostCommonInitEngineController(NULL PASS_ENGINE_PARAMETER_SUFFIX); resetConfigurationExt(NULL, engineType PASS_ENGINE_PARAMETER_SUFFIX); prepareShapes(PASS_ENGINE_PARAMETER_SIGNATURE);