diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index 9f4a5a91fc..b2a133886d 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -6,12 +6,12 @@ TESTS_SRC_CPP = \ tests/trigger/test_cam_vvt_input.cpp \ tests/trigger/test_2jz_vvt.cpp \ tests/trigger/test_real_cranking_miata_NA.cpp \ + tests/trigger/test_real_cranking_miata_na6.cpp \ tests/trigger/test_quad_cam.cpp \ tests/trigger/test_override_gaps.cpp \ tests/trigger/test_injection_scheduling.cpp \ tests/ignition_injection/injection_mode_transition.cpp \ tests/ignition_injection/test_startOfCrankingPrimingPulse.cpp \ - tests/ignition_injection/test_miata_na6_real_cranking.cpp \ tests/ignition_injection/test_multispark.cpp \ tests/ignition_injection/test_ignition_scheduling.cpp \ tests/ignition_injection/test_fuelCut.cpp \ diff --git a/unit_tests/tests/trigger/test_real_cranking_miata_NA.cpp b/unit_tests/tests/trigger/test_real_cranking_miata_NA.cpp index 80fbb2e781..3fb3c472a8 100644 --- a/unit_tests/tests/trigger/test_real_cranking_miata_NA.cpp +++ b/unit_tests/tests/trigger/test_real_cranking_miata_NA.cpp @@ -5,17 +5,31 @@ * @author Andrey Belomutskiy, (c) 2012-2021 */ -#define _POSIX_C_SOURCE 200809L -#define _GNU_SOURCE #include "engine_test_helper.h" +#include -TEST(cranking, realNA) { +static constexpr trigger_event_e riseEvents[] = { SHAFT_PRIMARY_RISING, SHAFT_SECONDARY_RISING, SHAFT_3RD_RISING }; +static constexpr trigger_event_e fallEvents[] = { SHAFT_PRIMARY_FALLING, SHAFT_SECONDARY_FALLING, SHAFT_3RD_FALLING }; + +static char* trim(char*str) { + while (str != nullptr && str[0] == ' ') { + str++; + } + return str; +} + +TEST(cranking, realCrankingFromFile) { FILE *fp = fopen("tests/trigger/recourses/cranking_na_3.csv", "r"); + ASSERT_TRUE(fp != nullptr); + + WITH_ENGINE_TEST_HELPER(MIATA_NA6_MAP); ssize_t read; char buffer[255]; + bool currentState[2]; + int index = -1; while (fgets(buffer, sizeof(buffer), fp)) { index++; @@ -26,19 +40,26 @@ TEST(cranking, realNA) { const char s[2] = ","; char *line = buffer; - char *token; + char *timeStampstr = trim(strtok(line, s)); + bool newState[2]; + newState[0] = trim(strtok(NULL, s))[0] == '1'; + newState[1] = trim(strtok(NULL, s))[0] == '1'; - /* get the first token */ - token = strtok(line, s); + double timeStamp = std::stod(timeStampstr); - /* walk through other tokens */ - while (token != NULL) { -// printf(" %s\n", token); + eth.setTimeAndInvokeEventsUs(1'000'000 * timeStamp); + for (int index = 0;index <2;index ++) { + if (currentState[index] == newState[index]) { + continue; + } + trigger_event_e event = (newState[index] ? riseEvents : fallEvents)[index]; + efitick_t nowNt = getTimeNowNt(); +// engine->triggerCentral.handleShaftSignal(event, nowNt PASS_ENGINE_PARAMETER_SUFFIX); - token = strtok(NULL, s); + currentState[index] = newState[index]; } + } - ASSERT_TRUE(fp != nullptr); } diff --git a/unit_tests/tests/ignition_injection/test_miata_na6_real_cranking.cpp b/unit_tests/tests/trigger/test_real_cranking_miata_na6.cpp similarity index 98% rename from unit_tests/tests/ignition_injection/test_miata_na6_real_cranking.cpp rename to unit_tests/tests/trigger/test_real_cranking_miata_na6.cpp index 5981d57fd6..66d44230f6 100644 --- a/unit_tests/tests/ignition_injection/test_miata_na6_real_cranking.cpp +++ b/unit_tests/tests/trigger/test_real_cranking_miata_na6.cpp @@ -1,5 +1,5 @@ /* - * test_miata_na6_real_cranking.cpp + * test_real_cranking_miata_na6.cpp * * @date May 11, 2019 * @author Andrey Belomutskiy, (c) 2012-2020 @@ -32,14 +32,14 @@ static void fireTriggerEvent(EngineTestHelper*eth, double timestampS, int channe engine->triggerCentral.handleShaftSignal(event, getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX); } -TEST(miataNA6, realCranking) { +TEST(cranking, hardcodedRealCranking) { WITH_ENGINE_TEST_HELPER(MIATA_NA6_VAF); + unitTestWarningCodeState.clear(); #define EVENT(timestamp, channel, value) { fireTriggerEvent(ð, timestamp, channel, value); } /* - * generates using logicdata2c tool - * + * Generated using logicdata2c tool */ /* 3 */ EVENT(/* timestamp*/0.597303, /*index*/0, /*value*/false);