add tests for disabled launch control #6571

This commit is contained in:
kifir 2024-05-30 20:52:57 +03:00 committed by rusefillc
parent 9abf5d15b0
commit fb47bb2bca
1 changed files with 74 additions and 18 deletions

View File

@ -32,7 +32,11 @@ constexpr int TEST_SMOOTH_RETARD_RPM_WINDOW = TEST_SMOOTH_RETARD_RPM_WINDOW_END
constexpr float TEST_LAUNCH_TIMING_RETARD = 17.0f; constexpr float TEST_LAUNCH_TIMING_RETARD = 17.0f;
static void setUpTestParameters() { static void setUpTestParameters(
const std::optional<bool> launchControlEnabled,
const std::optional<bool> enableLaunchRetard,
const std::optional<bool> launchSmoothRetard
) {
for (int loadIdx = 0; loadIdx < IGN_LOAD_COUNT; loadIdx++) { for (int loadIdx = 0; loadIdx < IGN_LOAD_COUNT; loadIdx++) {
config->ignitionTable[loadIdx][0] = TEST_IGNITION_650; config->ignitionTable[loadIdx][0] = TEST_IGNITION_650;
config->ignitionTable[loadIdx][1] = TEST_IGNITION_800; config->ignitionTable[loadIdx][1] = TEST_IGNITION_800;
@ -52,12 +56,38 @@ static void setUpTestParameters() {
config->ignitionTable[loadIdx][15] = TEST_IGNITION_7000; config->ignitionTable[loadIdx][15] = TEST_IGNITION_7000;
} }
engineConfiguration->launchControlEnabled = true; if (launchControlEnabled.has_value()) {
engineConfiguration->launchControlEnabled = launchControlEnabled.value();
} else {
ASSERT_FALSE(engineConfiguration->launchControlEnabled); // check default value
}
engineConfiguration->launchRpm = TEST_LAUNCH_RPM; engineConfiguration->launchRpm = TEST_LAUNCH_RPM;
engineConfiguration->launchRpmWindow = TEST_LAUNCH_RPM_WINDOW; engineConfiguration->launchRpmWindow = TEST_LAUNCH_RPM_WINDOW;
engineConfiguration->launchCorrectionsEndRpm = TEST_SMOOTH_RETARD_END_RPM; engineConfiguration->launchCorrectionsEndRpm = TEST_SMOOTH_RETARD_END_RPM;
engineConfiguration->launchSparkCutEnable = true; engineConfiguration->launchSparkCutEnable = true;
engineConfiguration->launchTimingRetard = TEST_LAUNCH_TIMING_RETARD; engineConfiguration->launchTimingRetard = TEST_LAUNCH_TIMING_RETARD;
if (enableLaunchRetard.has_value()) {
engineConfiguration->enableLaunchRetard = enableLaunchRetard.value();
} else {
ASSERT_FALSE(engineConfiguration->enableLaunchRetard); // check default value
}
if (launchSmoothRetard.has_value()) {
engineConfiguration->launchSmoothRetard = launchSmoothRetard.value();
} else {
ASSERT_FALSE(engineConfiguration->launchSmoothRetard); // check default value
}
}
static void setUpTestParametersWithEnabledLaunchControl(
const std::optional<bool> enableLaunchRetard = {},
const std::optional<bool> launchSmoothRetard = {}
) {
setUpTestParameters(
/* launchControlEnabled = */ { true },
/* enableLaunchRetard = */ enableLaunchRetard,
/* launchSmoothRetard = */ launchSmoothRetard
);
} }
static float getTestAdvance(const float rpm) { static float getTestAdvance(const float rpm) {
@ -70,13 +100,19 @@ static void updateRpm(const int rpm) {
engine->periodicFastCallback(); engine->periodicFastCallback();
} }
TEST(ignitionAngleAdvance, withoutLaunchRetard) { /* Checks that angle advance is not affected by `Launch Control` functionality: */
static void checkAngleAdvanceWithoutLaunchControl(
const std::optional<bool> launchControlEnabled = {},
const std::optional<bool> enableLaunchRetard = {},
const std::optional<bool> launchSmoothRetard = {}
) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE); EngineTestHelper eth(engine_type_e::TEST_ENGINE);
setUpTestParameters(); setUpTestParameters(
/* launchControlEnabled = */ launchControlEnabled,
ASSERT_FALSE(engineConfiguration->enableLaunchRetard); /* enableLaunchRetard = */ enableLaunchRetard,
ASSERT_FALSE(engineConfiguration->launchSmoothRetard); /* launchSmoothRetard = */ launchSmoothRetard
);
updateRpm(650); updateRpm(650);
EXPECT_NEAR(TEST_IGNITION_650, engine->ignitionState.baseIgnitionAdvance, EPS5D); EXPECT_NEAR(TEST_IGNITION_650, engine->ignitionState.baseIgnitionAdvance, EPS5D);
@ -130,13 +166,16 @@ TEST(ignitionAngleAdvance, withoutLaunchRetard) {
EXPECT_NEAR(TEST_IGNITION_7000, engine->ignitionState.baseIgnitionAdvance, EPS5D); EXPECT_NEAR(TEST_IGNITION_7000, engine->ignitionState.baseIgnitionAdvance, EPS5D);
} }
TEST(ignitionAngleAdvance, launchRetardWithoutSmooth) { TEST(ignitionAngleAdvance, withEnabledLaunchControlAndWithoutLaunchRetard) {
checkAngleAdvanceWithoutLaunchControl();
}
TEST(ignitionAngleAdvance, withEnabledLaunchControlAndLaunchRetardWithoutSmooth) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE); EngineTestHelper eth(engine_type_e::TEST_ENGINE);
setUpTestParameters(); setUpTestParametersWithEnabledLaunchControl(
/* enableLaunchRetard = */ std::make_optional<bool>(true)
engineConfiguration->enableLaunchRetard = true; );
ASSERT_FALSE(engineConfiguration->launchSmoothRetard);
updateRpm(650); updateRpm(650);
EXPECT_NEAR(TEST_IGNITION_650, engine->ignitionState.baseIgnitionAdvance, EPS5D); EXPECT_NEAR(TEST_IGNITION_650, engine->ignitionState.baseIgnitionAdvance, EPS5D);
@ -192,14 +231,13 @@ TEST(ignitionAngleAdvance, launchRetardWithoutSmooth) {
EXPECT_NEAR(TEST_LAUNCH_TIMING_RETARD, engine->ignitionState.baseIgnitionAdvance, EPS5D); EXPECT_NEAR(TEST_LAUNCH_TIMING_RETARD, engine->ignitionState.baseIgnitionAdvance, EPS5D);
} }
TEST(ignitionAngleAdvance, withEnabledLaunchControlAndLaunchRetardAndLaunchSmoothRetard) {
TEST(ignitionAngleAdvance, launchSmoothRetard) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE); EngineTestHelper eth(engine_type_e::TEST_ENGINE);
setUpTestParameters(); setUpTestParametersWithEnabledLaunchControl(
/* enableLaunchRetard = */ std::make_optional<bool>(true),
engineConfiguration->enableLaunchRetard = true; /* launchSmoothRetard = */ std::make_optional<bool>(true)
engineConfiguration->launchSmoothRetard = true; );
updateRpm(650); updateRpm(650);
EXPECT_NEAR(TEST_IGNITION_650, engine->ignitionState.baseIgnitionAdvance, EPS5D); EXPECT_NEAR(TEST_IGNITION_650, engine->ignitionState.baseIgnitionAdvance, EPS5D);
@ -267,4 +305,22 @@ TEST(ignitionAngleAdvance, launchSmoothRetard) {
updateRpm(7000); updateRpm(7000);
EXPECT_NEAR(TEST_LAUNCH_TIMING_RETARD, engine->ignitionState.baseIgnitionAdvance, EPS5D); EXPECT_NEAR(TEST_LAUNCH_TIMING_RETARD, engine->ignitionState.baseIgnitionAdvance, EPS5D);
}
/* Tests for https://github.com/rusefi/rusefi/issues/6571: */
TEST(ignitionAngleAdvance, withDisabledLaunchControlAndLaunchRetardWithoutSmooth) {
checkAngleAdvanceWithoutLaunchControl(
/* launchControlEnabled = */ { false },
/* enableLaunchRetard = */ { true },
/* launchSmoothRetard = */ { false }
);
}
TEST(ignitionAngleAdvance, withDisabledLaunchControlAndLaunchRetardAndSmooth) {
checkAngleAdvanceWithoutLaunchControl(
/* launchControlEnabled = */ { false },
/* enableLaunchRetard = */ { true },
/* launchSmoothRetard = */ { true }
);
} }