diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 94f39aba97..dab13f5e38 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -550,77 +550,6 @@ static void triggerShapeInfo(void) { #endif } -#if EFI_UNIT_TEST -#include - -extern trigger_type_e focusOnTrigger; - -/** - * This is used to generate trigger info which is later used by TriggerImage java class - * to generate images for documentation - */ -extern bool printTriggerDebug; -void exportAllTriggers() { - - FILE * fp = fopen (TRIGGERS_FILE_NAME, "w+"); - - fprintf(fp, "# Generated by rusEfi unit test suite\n"); - fprintf(fp, "# This file is used by TriggerImage tool\n"); - fprintf(fp, "# See 'gen_trigger_images.bat'\n"); - - //printTriggerDebug = true; - for (int triggerId = 1; triggerId < TT_UNUSED; triggerId++) { - trigger_type_e tt = (trigger_type_e) triggerId; - - if (focusOnTrigger != TT_UNUSED && tt != focusOnTrigger) { - continue; - } - - printf("Exporting %s\r\n", getTrigger_type_e(tt)); - - persistent_config_s pc; - Engine e(&pc); - Engine *engine = &e; - persistent_config_s *config = &pc; - engine_configuration_s *engineConfiguration = &pc.engineConfiguration; - - - engineConfiguration->trigger.type = tt; - engineConfiguration->ambiguousOperationMode = FOUR_STROKE_CAM_SENSOR; - - TriggerWaveform *shape = &engine->triggerCentral.triggerShape; - TriggerFormDetails *triggerFormDetails = &engine->triggerCentral.triggerFormDetails; - engine->initializeTriggerWaveform(NULL PASS_ENGINE_PARAMETER_SUFFIX); - - if (shape->shapeDefinitionError) { - printf("Trigger shapeDefinitionError %d\r\n", triggerId); - exit(-1); - } - - fprintf(fp, "TRIGGERTYPE %d %d %s %.2f\n", triggerId, shape->getLength(), getTrigger_type_e(tt), shape->tdcPosition); - - fprintf(fp, "# duty %.2f %.2f\n", shape->expectedDutyCycle[0], shape->expectedDutyCycle[1]); - - for (size_t i = 0; i < shape->getLength(); i++) { - - int triggerDefinitionCoordinate = (shape->getTriggerWaveformSynchPointIndex() + i) % shape->getSize(); - - - fprintf(fp, "event %d %d %d %.2f\n", - i, - shape->triggerSignalIndeces[triggerDefinitionCoordinate], - shape->triggerSignalStates[triggerDefinitionCoordinate], - triggerFormDetails->eventAngles[i]); - } - - } - fclose(fp); - printf("All triggers exported to %s\n", TRIGGERS_FILE_NAME); -} - -#endif - - #if EFI_PROD_CODE extern PwmConfig triggerSignal; #endif /* #if EFI_PROD_CODE */ diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index bac0417bce..5395a596d3 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -82,11 +82,6 @@ void hwHandleShaftSignal(trigger_event_e signal, efitick_t timestamp); void hwHandleVvtCamSignal(trigger_value_e front, efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX); void initTriggerCentral(Logging *sharedLogger); -/** - * this method is invoked by 'unit tests' project on PC to write triggers.txt representation of all rusEFI triggers - * That triggers.txt is later consumed by TriggerImage.java to render trigger images - */ -void exportAllTriggers(); int isSignalDecoderError(void); void resetMaxValues(); diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index d7e916b706..45232b38e1 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -31,25 +31,9 @@ efitick_t getTimeNowNt(void) { LoggingWithStorage sharedLogger("main"); -extern bool printTriggerDebug; -extern bool printTriggerTrace; bool verboseMode = false; -trigger_type_e focusOnTrigger = TT_UNUSED; - GTEST_API_ int main(int argc, char **argv) { - if (focusOnTrigger != TT_UNUSED) { - printTriggerDebug = true; - printTriggerTrace = true; - } - - // resizeMap(); - printf("Success 20201203\r\n"); - exportAllTriggers(); - if (focusOnTrigger != TT_UNUSED) { - return -1; - } - testing::InitGoogleTest(&argc, argv); // uncomment if you only want to run selected tests //::testing::GTEST_FLAG(filter) = "*testFasterEngineSpinningUp*"; diff --git a/unit_tests/tests/test_all_triggers.cpp b/unit_tests/tests/test_all_triggers.cpp new file mode 100644 index 0000000000..565fb05be4 --- /dev/null +++ b/unit_tests/tests/test_all_triggers.cpp @@ -0,0 +1,78 @@ +#include "engine.h" + +#include + + +struct TriggerExportHelper +{ + FILE* fp; + + TriggerExportHelper() { + fp = fopen (TRIGGERS_FILE_NAME, "w+"); + + fprintf(fp, "# Generated by rusEfi unit test suite\n"); + fprintf(fp, "# This file is used by TriggerImage tool\n"); + fprintf(fp, "# See 'gen_trigger_images.bat'\n"); + } + + ~TriggerExportHelper() { + fclose(fp); + printf("All triggers exported to %s\n", TRIGGERS_FILE_NAME); + } +}; + +static TriggerExportHelper exportHelper; + +class AllTriggersFixture : public ::testing::TestWithParam { +}; + +INSTANTIATE_TEST_SUITE_P( + Triggers, + AllTriggersFixture, + // Test all triggers from the first valid trigger thru the last + // (Skip index 0, that's custom toothed wheel which is covered by others) + ::testing::Range((trigger_type_e)1, TT_UNUSED) +); + +extern bool printTriggerDebug; +extern bool printTriggerTrace; + +TEST_P(AllTriggersFixture, TestTrigger) { + // handy debugging options + //printTriggerDebug = true; + //printTriggerTrace = true; + + auto tt = GetParam(); + auto fp = exportHelper.fp; + + printf("Exporting %s\r\n", getTrigger_type_e(tt)); + + persistent_config_s pc; + Engine e(&pc); + Engine *engine = &e; + persistent_config_s *config = &pc; + engine_configuration_s *engineConfiguration = &pc.engineConfiguration; + + engineConfiguration->trigger.type = tt; + engineConfiguration->ambiguousOperationMode = FOUR_STROKE_CAM_SENSOR; + + TriggerWaveform *shape = &engine->triggerCentral.triggerShape; + TriggerFormDetails *triggerFormDetails = &engine->triggerCentral.triggerFormDetails; + engine->initializeTriggerWaveform(NULL PASS_ENGINE_PARAMETER_SUFFIX); + + ASSERT_FALSE(shape->shapeDefinitionError) << "Trigger shapeDefinitionError"; + + fprintf(fp, "TRIGGERTYPE %d %d %s %.2f\n", tt, shape->getLength(), getTrigger_type_e(tt), shape->tdcPosition); + + fprintf(fp, "# duty %.2f %.2f\n", shape->expectedDutyCycle[0], shape->expectedDutyCycle[1]); + + for (size_t i = 0; i < shape->getLength(); i++) { + int triggerDefinitionCoordinate = (shape->getTriggerWaveformSynchPointIndex() + i) % shape->getSize(); + + fprintf(fp, "event %d %d %d %.2f\n", + i, + shape->triggerSignalIndeces[triggerDefinitionCoordinate], + shape->triggerSignalStates[triggerDefinitionCoordinate], + triggerFormDetails->eventAngles[i]); + } +} diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index abf0461973..b65b2817f0 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -65,4 +65,5 @@ TESTS_SRC_CPP = \ tests/test_dynoview.cpp \ tests/test_gpio.cpp \ tests/test_limp.cpp \ + tests/test_all_triggers.cpp \