From b2cb46d724c424959f3ae0a5dfe7690dc13f5e8b Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sat, 26 Dec 2020 14:14:04 -0800 Subject: [PATCH] HW CI: rev limiter (#2141) * test rev limit * comment, format * make test work * check that it goes back to normal Co-authored-by: Matthew Kennedy --- .../src/com/rusefi/FunctionalTest.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/java_console/autotest/src/com/rusefi/FunctionalTest.java b/java_console/autotest/src/com/rusefi/FunctionalTest.java index 2a67a77798..c5f62ad089 100644 --- a/java_console/autotest/src/com/rusefi/FunctionalTest.java +++ b/java_console/autotest/src/com/rusefi/FunctionalTest.java @@ -13,6 +13,7 @@ import org.junit.Test; import static com.rusefi.IoUtil.getEnableCommand; import static com.rusefi.TestingUtils.*; import static com.rusefi.config.generated.Fields.*; +import static org.junit.Assert.assertFalse; /** * rusEfi firmware simulator functional test suite @@ -93,6 +94,52 @@ public class FunctionalTest extends RusefiTestBase { } } + @Test + public void testRevLimiter() { + String msg = "rev limiter"; + + ecu.setEngineType(ET_FORD_ASPIRE); + ecu.changeRpm(2000); + + // Alpha-N mode so that we actually inject some fuel (without mocking tons of sensors) + ecu.sendCommand("set algorithm 5"); + // Set tps to 25% - make alpha-n happy + ecu.sendCommand("set_sensor_mock 10 25"); + ecu.sendCommand("set rpm_hard_limit 2500"); + + { + // Check that neither ignition nor injection is cut + EngineChart chart = nextChart(); + + assertWaveNotNull(chart, EngineChart.SPARK_1); + assertWaveNotNull(chart, EngineChart.INJECTOR_1); + } + + // Now go above the hard limiter + ecu.changeRpm(3000); + + { + // Check that both ignition and injection are cut + EngineChart chart = nextChart(); + + // These channels are allowed to have falling edges - aka closing injectors and firing coils + // but not allowed to have rising edges - aka opening injectors and charging coils + assertWaveNoRises(chart, EngineChart.SPARK_1); + assertWaveNoRises(chart, EngineChart.INJECTOR_1); + } + + // Check that it recovers when we go back under the limit + ecu.changeRpm(2000); + + { + // Check that neither ignition nor injection is cut + EngineChart chart = nextChart(); + + assertWaveNotNull(chart, EngineChart.SPARK_1); + assertWaveNotNull(chart, EngineChart.INJECTOR_1); + } + } + @Test public void testCustomEngine() { ecu.setEngineType(ET_DEFAULT_FRANKENSO); @@ -421,6 +468,18 @@ public class FunctionalTest extends RusefiTestBase { assertTrue(chart.get(key) != null); } + private static void assertWaveNoRises(EngineChart chart, String key) { + StringBuilder events = chart.get(key); + + // if no events of this type at all, return since this passes the test + if (events == null) { + return; + } + + // Assert that there are no up (rise) events in the channel's sequence + assertFalse(events.toString().contains("u")); + } + private EngineChart nextChart() { return TestingUtils.nextChart(ecu.commandQueue); }