From 2235063a13b5026c00894806c3f5b91116496ec1 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 8 Dec 2018 18:11:28 -0500 Subject: [PATCH] reducing clutter --- unit_tests/global.h | 3 +- unit_tests/global_execution_queue.cpp | 34 +++++++++++++++ unit_tests/test.mk | 2 + unit_tests/test_fasterEngineSpinningUp.cpp | 1 - unit_tests/test_pwm_generator.cpp | 41 ++++++++++++++++++ unit_tests/test_signal_executor.cpp | 50 ++-------------------- 6 files changed, 81 insertions(+), 50 deletions(-) create mode 100644 unit_tests/global_execution_queue.cpp create mode 100644 unit_tests/test_pwm_generator.cpp diff --git a/unit_tests/global.h b/unit_tests/global.h index c447d1a5f6..e601e6143b 100644 --- a/unit_tests/global.h +++ b/unit_tests/global.h @@ -20,6 +20,7 @@ #include "boards.h" #ifdef __cplusplus +// todo: include it right here? #include "unit_test_framework.h" extern "C" { #endif /* __cplusplus */ @@ -52,8 +53,6 @@ void print(const char *fmt, ...); #define INLINE inline -typedef int bool_t; - #define EFI_ERROR_CODE 0xffffffff #define CCM_OPTIONAL diff --git a/unit_tests/global_execution_queue.cpp b/unit_tests/global_execution_queue.cpp new file mode 100644 index 0000000000..fb4a706f21 --- /dev/null +++ b/unit_tests/global_execution_queue.cpp @@ -0,0 +1,34 @@ +/* + * global_execution_queue.cpp + * + * @date Dec 8, 2018 + * @author Andrey Belomutskiy, (c) 2012-2018 + */ + +#include "signal_executor.h" +#include "event_queue.h" + +// this global instance is used by integration tests via 'scheduleByTimestamp' global methods below +EventQueue schedulingQueue; + +bool_t debugSignalExecutor = false; + +void scheduleForLater(scheduling_s *scheduling, int delayUs, + schfunc_t callback, void *param) { + if (debugSignalExecutor) { + printf("scheduleTask %d\r\n", delayUs); + } + scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param); +} + +void scheduleByTimestamp(scheduling_s *scheduling, + efitimeus_t time, schfunc_t callback, void *param) { + if (debugSignalExecutor) { + printf("scheduleByTime %d\r\n", time); + } + schedulingQueue.insertTask(scheduling, time, callback, param); +} + +void initSignalExecutorImpl(void) { +} + diff --git a/unit_tests/test.mk b/unit_tests/test.mk index 9592ae3b1f..99442e48f9 100644 --- a/unit_tests/test.mk +++ b/unit_tests/test.mk @@ -1,6 +1,7 @@ TEST_SRC_CPP = test_util.cpp \ unit_test_framework.cpp \ boards.cpp \ + global_execution_queue.cpp \ test_basic_math/test_find_index.cpp \ test_basic_math/test_interpolation_3d.cpp \ test_data_structures/test_engine_math.cpp \ @@ -12,6 +13,7 @@ TEST_SRC_CPP = test_util.cpp \ test_fuel_map.cpp \ test_fuelCut.cpp \ engine_test_helper.cpp \ + test_pwm_generator.cpp \ test_logic_expression.cpp \ test_speed_density.cpp \ test_signal_executor.cpp \ diff --git a/unit_tests/test_fasterEngineSpinningUp.cpp b/unit_tests/test_fasterEngineSpinningUp.cpp index 48ba133e0f..b4944d1814 100644 --- a/unit_tests/test_fasterEngineSpinningUp.cpp +++ b/unit_tests/test_fasterEngineSpinningUp.cpp @@ -12,7 +12,6 @@ extern EventQueue schedulingQueue; extern int timeNowUs; -extern EnginePins enginePins; void testFasterEngineSpinningUp() { // this is just a reference unit test implementation diff --git a/unit_tests/test_pwm_generator.cpp b/unit_tests/test_pwm_generator.cpp new file mode 100644 index 0000000000..a93ee34a26 --- /dev/null +++ b/unit_tests/test_pwm_generator.cpp @@ -0,0 +1,41 @@ +/* + * test_pwm_generator.cpp + * + * @date Dec 8, 2018 + * Author: user + */ + +#include "global.h" +#include "unit_test_framework.h" +#include "event_queue.h" +#include "pwm_generator_logic.h" + +extern EventQueue schedulingQueue; +extern int timeNowUs; + +void testApplyPinState(PwmConfig *state, int stateIndex) { + +} + +void testPwmGenerator() { + print("*************************************** testPwmGenerator\r\n"); + + SimplePwm pwm; + + OutputPin pin; + + //pwm.setFrequency(600); + + schedulingQueue.clear(); + + startSimplePwm(&pwm, "unit_test", + &pin, + 600 /* frequency */, + 0.80 /* duty cycle */, + &testApplyPinState); + + assertEquals(1, schedulingQueue.size()); + +} + + diff --git a/unit_tests/test_signal_executor.cpp b/unit_tests/test_signal_executor.cpp index 1cccc837a5..868ffdd786 100644 --- a/unit_tests/test_signal_executor.cpp +++ b/unit_tests/test_signal_executor.cpp @@ -5,40 +5,17 @@ * @author Andrey Belomutskiy, (c) 2012-2018 */ -#include #include "global.h" +#include #include "signal_executor.h" #include "test_signal_executor.h" #include "io_pins.h" -#include "utlist.h" #include "event_queue.h" -#include "unit_test_framework.h" #include "pwm_generator_logic.h" +#include "unit_test_framework.h" -EventQueue schedulingQueue; - -bool_t debugSignalExecutor = false; - -void scheduleForLater(scheduling_s *scheduling, int delayUs, - schfunc_t callback, void *param) { - if (debugSignalExecutor) { - printf("scheduleTask %d\r\n", delayUs); - } - scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param); -} - -void scheduleByTimestamp(scheduling_s *scheduling, - efitimeus_t time, schfunc_t callback, void *param) { - if (debugSignalExecutor) { - printf("scheduleByTime %d\r\n", time); - } - schedulingQueue.insertTask(scheduling, time, callback, param); -} - -void initSignalExecutorImpl(void) { -} - +// this instance is used by some unit tests here which reference it directly static EventQueue eq; static int callbackCounter = 0; @@ -114,27 +91,6 @@ static void testSignalExecutor3(void) { eq.executeAll(100); } -void testApplyPinState(PwmConfig *state, int stateIndex) { - -} - -void testPwmGenerator() { - print("*************************************** testPwmGenerator\r\n"); - - SimplePwm pwm; - - OutputPin pin; - - //pwm.setFrequency(600); - - startSimplePwm(&pwm, "unit_test", - &pin, - 600 /* frequency */, - 0.80 /* duty cycle */, - &testApplyPinState); - -} - void testSignalExecutor(void) { testSignalExecutor3(); print("*************************************** testSignalExecutor\r\n");