From 6043c9337266654bdfd9e821e4531d2784ff56f4 Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 8 Aug 2019 21:27:57 -0400 Subject: [PATCH] WFT is wrong with MRE_miata_na6 config? operationMode complexity #898 fancy smansy unit test with some C++11 --- firmware/controllers/algo/engine.h | 1 - .../controllers/algo/engine_configuration.cpp | 12 ++++++++- .../controllers/algo/engine_configuration.h | 5 ++++ unit_tests/engine_test_helper.cpp | 7 +++-- unit_tests/engine_test_helper.h | 2 ++ unit_tests/main.cpp | 2 +- unit_tests/tests/test_idle_controller.cpp | 2 +- unit_tests/tests/test_ion.cpp | 2 +- unit_tests/tests/test_issue_898.cpp | 27 +++++++++++++++++++ unit_tests/tests/tests.mk | 1 + 10 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 unit_tests/tests/test_issue_898.cpp diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 04689cba8e..d2aed83884 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -313,7 +313,6 @@ private: }; void prepareShapes(DECLARE_ENGINE_PARAMETER_SIGNATURE); -void resetConfigurationExt(Logging * logger, engine_type_e engineType DECLARE_ENGINE_PARAMETER_SUFFIX); void applyNonPersistentConfiguration(Logging * logger DECLARE_ENGINE_PARAMETER_SUFFIX); void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_SIGNATURE); diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index d7b2084245..100cafaeba 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -1022,7 +1022,7 @@ static void setDefaultFrankensoConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) boardConfiguration->is_enabled_spi_3 = true; } -void resetConfigurationExt(Logging * logger, engine_type_e engineType DECLARE_ENGINE_PARAMETER_SUFFIX) { +void resetConfigurationExt(Logging * logger, std::function boardCallback, engine_type_e engineType DECLARE_ENGINE_PARAMETER_SUFFIX) { enginePins.reset(); // that's mostly important for functional tests /** * Let's apply global defaults first @@ -1032,6 +1032,8 @@ void resetConfigurationExt(Logging * logger, engine_type_e engineType DECLARE_EN // set initial pin groups setDefaultBasePins(PASS_CONFIG_PARAMETER_SIGNATURE); + boardCallback(engine); + #if EFI_PROD_CODE // call overrided board-specific configuration setup, if needed (for custom boards only) setBoardConfigurationOverrides(); @@ -1289,6 +1291,14 @@ void resetConfigurationExt(Logging * logger, engine_type_e engineType DECLARE_EN #endif /* EFI_TUNER_STUDIO */ } +void emptyCallbackWithEngine(Engine * engine) { + +} + +void resetConfigurationExt(Logging * logger, engine_type_e engineType DECLARE_ENGINE_PARAMETER_SUFFIX) { + resetConfigurationExt(logger, &emptyCallbackWithEngine, engineType PASS_ENGINE_PARAMETER_SUFFIX); +} + void validateConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { if (engineConfiguration->adcVcc > 5.0f || engineConfiguration->adcVcc < 1.0f) { engineConfiguration->adcVcc = 3.0f; diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index 3d19492e28..52a7bc08f8 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -13,6 +13,7 @@ #include "crc.h" #include "engine_configuration_generated_structures.h" #include "globalaccess.h" +#include #ifndef DEFAULT_ENGINE_TYPE #define DEFAULT_ENGINE_TYPE DEFAULT_FRANKENSO @@ -80,4 +81,8 @@ void copyTargetAfrTable(fuel_table_t const source, afr_table_t destination); void copyFuelTable(fuel_table_t const source, fuel_table_t destination); void copyTimingTable(ignition_table_t const source, ignition_table_t destination); +void resetConfigurationExt(Logging * logger, std::function, engine_type_e engineType DECLARE_ENGINE_PARAMETER_SUFFIX); +void resetConfigurationExt(Logging * logger, engine_type_e engineType DECLARE_ENGINE_PARAMETER_SUFFIX); +void emptyCallbackWithEngine(Engine * engine); + #endif /* ENGINE_CONFIGURATION_H_ */ diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index 45512a8d48..694bbcf2a0 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -29,7 +29,7 @@ EngineTestHelperBase::EngineTestHelperBase() { timeNowUs = 0; } -EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persistentConfig) { +EngineTestHelper::EngineTestHelper(engine_type_e engineType, std::function boardCallback) { unitTestWarningCodeState.clear(); testMafValue = 0; @@ -60,7 +60,7 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persiste mostCommonInitEngineController(NULL PASS_ENGINE_PARAMETER_SUFFIX); - resetConfigurationExt(NULL, engineType PASS_ENGINE_PARAMETER_SUFFIX); + resetConfigurationExt(NULL, boardCallback, engineType PASS_ENGINE_PARAMETER_SUFFIX); prepareShapes(PASS_ENGINE_PARAMETER_SIGNATURE); engine->engineConfigurationPtr->mafAdcChannel = TEST_MAF_CHANNEL; engine->engineConfigurationPtr->clt.adcChannel = TEST_CLT_CHANNEL; @@ -79,6 +79,9 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persiste initMainEventListener(NULL PASS_ENGINE_PARAMETER_SUFFIX); } +EngineTestHelper::EngineTestHelper(engine_type_e engineType) : EngineTestHelper(engineType, &emptyCallbackWithEngine) { +} + /** * mock a change of time and fire single RISE front event */ diff --git a/unit_tests/engine_test_helper.h b/unit_tests/engine_test_helper.h index bca182ebe2..054a1bc4c3 100644 --- a/unit_tests/engine_test_helper.h +++ b/unit_tests/engine_test_helper.h @@ -12,6 +12,7 @@ #include "rpm_calculator.h" #include "main_trigger_callback.h" #include "unit_test_framework.h" +#include class EngineTestHelperBase { @@ -27,6 +28,7 @@ public: class EngineTestHelper : public EngineTestHelperBase { public: EngineTestHelper(engine_type_e engineType); + EngineTestHelper(engine_type_e engineType, std::function); void applyTriggerShape(); void setTriggerType(trigger_type_e trigger DECLARE_ENGINE_PARAMETER_SUFFIX); void fireRise(int delayMs); diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index 4f1c209549..122e1645b7 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -46,7 +46,7 @@ GTEST_API_ int main(int argc, char **argv) { // printTriggerDebug = true; // resizeMap(); - printf("Success 20190713\r\n"); + printf("Success 20190808\r\n"); printAllTriggers(); // printConvertedTable(); testing::InitGoogleTest(&argc, argv); diff --git a/unit_tests/tests/test_idle_controller.cpp b/unit_tests/tests/test_idle_controller.cpp index 2f6b8e02d0..c66a57abb8 100644 --- a/unit_tests/tests/test_idle_controller.cpp +++ b/unit_tests/tests/test_idle_controller.cpp @@ -2,7 +2,7 @@ * @file test_idle_controller.cpp * * @date Oct 17, 2013 - * @author Andrey Belomutskiy, (c) 2012-2018 + * @author Andrey Belomutskiy, (c) 2012-2019 */ #include "engine_test_helper.h" diff --git a/unit_tests/tests/test_ion.cpp b/unit_tests/tests/test_ion.cpp index 4aec1141bf..62d4be6e10 100644 --- a/unit_tests/tests/test_ion.cpp +++ b/unit_tests/tests/test_ion.cpp @@ -2,7 +2,7 @@ * test_ion.cpp * * Created on: Jan 4, 2019 - * Author: user + * @author Andrey Belomutskiy, (c) 2012-2019 */ #ifndef TEST_ION_CPP_ diff --git a/unit_tests/tests/test_issue_898.cpp b/unit_tests/tests/test_issue_898.cpp new file mode 100644 index 0000000000..13ad70ad0c --- /dev/null +++ b/unit_tests/tests/test_issue_898.cpp @@ -0,0 +1,27 @@ +/* + * test_issue_898.cpp + * + * Created on: Aug 8, 2019 + * @author Andrey Belomutskiy, (c) 2012-2019 + */ + +#include "engine_test_helper.h" + +static void boardConfigurationForIssue898(Engine * engine) { + engine_configuration_s *engineConfiguration = engine->engineConfigurationPtr; + + setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR); + engineConfiguration->trigger.type = TT_TOOTHED_WHEEL_60_2; + engineConfiguration->useOnlyRisingEdgeForTrigger = true; +} + +TEST(issues, issue898) { +// works without extra board settings + EngineTestHelper eth(MRE_MIATA_NA6); +// fails like this with self-contradictory trigger definition +// EngineTestHelper eth(MRE_MIATA_NA6, &boardConfigurationForIssue898); + EXPAND_EngineTestHelper; + + + ASSERT_EQ(0, engine->triggerCentral.triggerShape.shapeDefinitionError) << "MRE_MIATA_NA6 shapeDefinitionError"; +} diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index 0db8d82eda..d5e0d60fa2 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -13,6 +13,7 @@ TESTS_SRC_CPP = \ tests/test_idle_controller.cpp \ tests/test_trigger_decoder.cpp \ tests/test_trigger_noiseless.cpp \ + tests/test_issue_898.cpp \ tests/test_fuel_map.cpp \ tests/test_maf2map.cpp \ tests/test_fuelCut.cpp \