From e6d368d6f7ccddddec941ea9d3317c5d3153dd07 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Mar 2018 21:32:48 -0500 Subject: [PATCH] reducing global state in unit tests --- firmware/controllers/algo/engine_configuration.cpp | 9 +++++++-- firmware/controllers/algo/engine_configuration.h | 2 +- unit_tests/efifeatures.h | 4 ++++ unit_tests/main.cpp | 6 ++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 6302fe6cf1..c6b61a3efb 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -137,7 +137,7 @@ engine_configuration_s activeConfiguration; extern engine_configuration_s *engineConfiguration; -void rememberCurrentConfiguration(void) { +void rememberCurrentConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { memcpy(&activeConfiguration, engineConfiguration, sizeof(engine_configuration_s)); } @@ -149,12 +149,17 @@ int getGlobalConfigurationVersion(void) { return globalConfigurationVersion; } +extern LoggingWithStorage sharedLogger; + /** * this is the top-level method which should be called in case of any changes to engine configuration * online tuning of most values in the maps does not count as configuration change, but 'Burn' command does */ void incrementGlobalConfigurationVersion(DECLARE_ENGINE_PARAMETER_SIGNATURE) { globalConfigurationVersion++; +#if EFI_DEFAILED_LOGGING + scheduleMsg(&sharedLogger, "set globalConfigurationVersion=%d", globalConfigurationVersion); +#endif /* EFI_DEFAILED_LOGGING */ /** * All these callbacks could be implemented as listeners, but these days I am saving RAM */ @@ -182,7 +187,7 @@ void incrementGlobalConfigurationVersion(DECLARE_ENGINE_PARAMETER_SIGNATURE) { onConfigurationChangeFsioCallback(&activeConfiguration PASS_ENGINE_PARAMETER_SUFFIX); - rememberCurrentConfiguration(); + rememberCurrentConfiguration(PASS_ENGINE_PARAMETER_SIGNATURE); } /** diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index 093579e055..35bd3d14f0 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -67,7 +67,7 @@ void setDefaultBasePins(DECLARE_ENGINE_PARAMETER_SIGNATURE); void setDefaultSerialParameters(DECLARE_ENGINE_PARAMETER_SIGNATURE); void setDefaultSdCardParameters(DECLARE_ENGINE_PARAMETER_SIGNATURE); -void rememberCurrentConfiguration(void); +void rememberCurrentConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE); void incrementGlobalConfigurationVersion(DECLARE_ENGINE_PARAMETER_SIGNATURE); int getGlobalConfigurationVersion(void); diff --git a/unit_tests/efifeatures.h b/unit_tests/efifeatures.h index 7afcd20723..f2ae9555fc 100644 --- a/unit_tests/efifeatures.h +++ b/unit_tests/efifeatures.h @@ -14,6 +14,10 @@ #define EFI_GPIO_HARDWARE FALSE +#define FUEL_MATH_EXTREME_LOGGING FALSE + +#define EFI_DEFAILED_LOGGING FALSE + #define EFI_UNIT_TEST TRUE #define EFI_FSIO TRUE diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index f78bc0c660..0d3a78e99c 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -35,15 +35,11 @@ #include "test_engine_math.h" #include "test_trigger_decoder.h" - typedef int32_t msg_t; #include "hal_streams.h" #include "memstreams.h" -static engine_configuration_s ec; -engine_configuration_s *engineConfiguration = &ec; - int timeNowUs = 0; efitimeus_t getTimeNowUs(void) { @@ -54,6 +50,8 @@ efitick_t getTimeNowNt(void) { return getTimeNowUs() * US_TO_NT_MULTIPLIER; } +LoggingWithStorage sharedLogger("main"); + extern int revolutionCounterSinceBootForUnitTest; int getRevolutionCounter(void) {