From 4bbb5b8762d1dc1a3abf33f2efd6e89f74e0a49b Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 8 Aug 2020 11:25:17 -0400 Subject: [PATCH] trigger and VSS hw integrated testing #1668 --- firmware/controllers/algo/engine.cpp | 2 +- firmware/controllers/algo/engine.h | 2 +- firmware/controllers/settings.cpp | 2 +- .../autotest/src/com/rusefi/AutoTest.java | 35 +++++------------- .../src/com/rusefi/HardwareTests.java | 20 +++++++++++ .../autotest/src/com/rusefi/IoUtil.java | 24 +++++-------- .../autotest/src/com/rusefi/RealHwTest.java | 6 +++- .../autotest/src/com/rusefi/TestingUtils.java | 2 +- .../com/rusefi/functional_tests/BaseTest.java | 36 +++++++++++++++++++ .../rusefi/functional_tests/TestHelper.java | 23 ++++++++++++ 10 files changed, 105 insertions(+), 47 deletions(-) create mode 100644 java_console/autotest/src/com/rusefi/HardwareTests.java create mode 100644 java_console/autotest/src/com/rusefi/functional_tests/BaseTest.java create mode 100644 java_console/autotest/src/com/rusefi/functional_tests/TestHelper.java diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 7f20c1656f..9a9b3d0c9c 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -64,7 +64,7 @@ FsioState::FsioState() { void Engine::resetEngineSnifferIfInTestMode() { #if EFI_ENGINE_SNIFFER - if (isTestMode) { + if (isFunctionalTestMode) { // TODO: what is the exact reasoning for the exact engine sniffer pause time I wonder waveChart.pauseEngineSnifferUntilNt = getTimeNowNt() + MS2NT(300); waveChart.reset(); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index a98c07c254..3ba29b51b5 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -269,7 +269,7 @@ public: * are we running any kind of functional test? this affect * some areas */ - bool isTestMode = false; + bool isFunctionalTestMode = false; bool directSelfStimulation = false; diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 131aac3793..1f1bba310e 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -879,7 +879,7 @@ static void enableOrDisable(const char *param, bool isEnabled) { } else if (strEqualCaseInsensitive(param, "sd")) { engineConfiguration->isSdCardEnabled = isEnabled; } else if (strEqualCaseInsensitive(param, CMD_FUNCTIONAL_TEST_MODE)) { - engine->isTestMode = isEnabled; + engine->isFunctionalTestMode = isEnabled; } else if (strEqualCaseInsensitive(param, "can_read")) { engineConfiguration->canReadEnabled = isEnabled; } else if (strEqualCaseInsensitive(param, "can_write")) { diff --git a/java_console/autotest/src/com/rusefi/AutoTest.java b/java_console/autotest/src/com/rusefi/AutoTest.java index cd1338bf79..e9525a3d93 100644 --- a/java_console/autotest/src/com/rusefi/AutoTest.java +++ b/java_console/autotest/src/com/rusefi/AutoTest.java @@ -6,6 +6,8 @@ import com.rusefi.config.generated.Fields; import com.rusefi.core.MessagesCentral; import com.rusefi.core.Sensor; import com.rusefi.core.SensorCentral; +import com.rusefi.functional_tests.BaseTest; +import com.rusefi.functional_tests.TestHelper; import com.rusefi.io.CommandQueue; import com.rusefi.io.LinkManager; import com.rusefi.waves.EngineChart; @@ -29,32 +31,24 @@ import static com.rusefi.waves.EngineReport.isCloseEnough; * @author Andrey Belomutskiy * 3/5/14 */ -public class AutoTest { +public class AutoTest extends BaseTest { public static final int COMPLEX_COMMAND_RETRY = 10000; static int currentEngineType; - private static String criticalError; private final LinkManager linkManager; - private final CommandQueue commandQueue; public AutoTest(LinkManager linkManager, CommandQueue commandQueue) { + super(commandQueue); this.linkManager = linkManager; - this.commandQueue = commandQueue; } void mainTestBody() { - MessagesCentral.getInstance().addListener((clazz, message) -> { - if (message.startsWith(Fields.CRITICAL_PREFIX)) - criticalError = message; - }); - - BinaryProtocol bp = linkManager.getCurrentStreamState(); // let's make sure 'burn' command works since sometimes it does not bp.burn(); sendCommand(getDisableCommand(Fields.CMD_TRIGGER_HW_INPUT)); - sendCommand(getEnableCommand(Fields.CMD_FUNCTIONAL_TEST_MODE)); + enableFunctionalMode(); testCustomEngine(); testVW_60_2(); testV12(); @@ -86,14 +80,14 @@ public class AutoTest { setEngineType(32); changeRpm(900); // first let's get to expected RPM - assertRpmDoesNotJump(20000, 15, 30, FAIL, linkManager.getCommandQueue()); + assertRpmDoesNotJump(20000, 15, 30, FAIL, commandQueue); } private void testV12() { setEngineType(40); changeRpm(700); // first let's get to expected RPM - assertRpmDoesNotJump(15000, 15, 30, FAIL, linkManager.getCommandQueue()); + assertRpmDoesNotJump(15000, 15, 30, FAIL, commandQueue); } public static void assertRpmDoesNotJump(int rpm, int settleTime, int testDuration, Function callback, CommandQueue commandQueue) { @@ -162,10 +156,6 @@ public class AutoTest { assertWave(msg, chart, EngineChart.MAP_AVERAGING, 0.139, x, x + 120, x + 240, x + 360, x + 480, x + 600); } - void changeRpm(final int rpm) { - IoUtil.changeRpm(linkManager.getCommandQueue(), rpm); - } - private void testMitsu() { setEngineType(16); sendCommand("disable cylinder_cleanup"); @@ -205,7 +195,7 @@ public class AutoTest { } private EngineChart nextChart() { - return TestingUtils.nextChart(linkManager.getCommandQueue()); + return TestingUtils.nextChart(commandQueue); } private void test2003DodgeNeon() { @@ -492,15 +482,6 @@ public class AutoTest { assertWaveNull("hard limit check", chart, EngineChart.INJECTOR_1); } - private void sendCommand(String command) { - sendCommand(command, CommandQueue.DEFAULT_TIMEOUT, Timeouts.CMD_TIMEOUT); - } - - private void sendCommand(String command, int retryTimeoutMs, int timeoutMs) { - assertNull("Fatal not expected", criticalError); - IoUtil.sendCommand(command, retryTimeoutMs, timeoutMs, commandQueue); - } - private static void assertEquals(double expected, double actual) { assertEquals("", expected, actual); } diff --git a/java_console/autotest/src/com/rusefi/HardwareTests.java b/java_console/autotest/src/com/rusefi/HardwareTests.java new file mode 100644 index 0000000000..1a0adf4236 --- /dev/null +++ b/java_console/autotest/src/com/rusefi/HardwareTests.java @@ -0,0 +1,20 @@ +package com.rusefi; + +import com.rusefi.config.generated.Fields; +import com.rusefi.functional_tests.BaseTest; +import com.rusefi.io.CommandQueue; + +import static com.rusefi.IoUtil.getEnableCommand; + +public class HardwareTests extends BaseTest { + + public HardwareTests(CommandQueue commandQueue) { + super(commandQueue); + } + + public void runRealHardwareTests() { + sendCommand(getEnableCommand(Fields.CMD_TRIGGER_HW_INPUT)); + enableFunctionalMode(); + + } +} diff --git a/java_console/autotest/src/com/rusefi/IoUtil.java b/java_console/autotest/src/com/rusefi/IoUtil.java index 6dc4bcfcc4..4a5852b406 100644 --- a/java_console/autotest/src/com/rusefi/IoUtil.java +++ b/java_console/autotest/src/com/rusefi/IoUtil.java @@ -41,17 +41,14 @@ public class IoUtil { /** * blocking method which would for confirmation from rusEfi */ - static void sendCommand(String command, int retryTimeoutMs, int timeoutMs, CommandQueue commandQueue) { + public static void sendCommand(String command, int retryTimeoutMs, int timeoutMs, CommandQueue commandQueue) { final CountDownLatch responseLatch = new CountDownLatch(1); long time = System.currentTimeMillis(); FileLog.MAIN.logLine("Sending command [" + command + "]"); final long begin = System.currentTimeMillis(); - commandQueue.write(command, retryTimeoutMs, new InvocationConfirmationListener() { - @Override - public void onCommandConfirmation() { - responseLatch.countDown(); - FileLog.MAIN.logLine("Got confirmation in " + (System.currentTimeMillis() - begin) + "ms"); - } + commandQueue.write(command, retryTimeoutMs, () -> { + responseLatch.countDown(); + FileLog.MAIN.logLine("Got confirmation in " + (System.currentTimeMillis() - begin) + "ms"); }); wait(responseLatch, timeoutMs); if (responseLatch.getCount() > 0) @@ -67,19 +64,16 @@ public class IoUtil { } } - static void changeRpm(CommandQueue commandQueue, final int rpm) { + public static void changeRpm(CommandQueue commandQueue, final int rpm) { FileLog.MAIN.logLine("AUTOTEST rpm EN " + rpm); sendCommand("rpm " + rpm, commandQueue); long time = System.currentTimeMillis(); final CountDownLatch rpmLatch = new CountDownLatch(1); - SensorCentral.SensorListener listener = new SensorCentral.SensorListener() { - @Override - public void onSensorUpdate(double value) { - double actualRpm = SensorCentral.getInstance().getValue(Sensor.RPM); - if (isCloseEnough(rpm, actualRpm)) - rpmLatch.countDown(); - } + SensorCentral.SensorListener listener = value -> { + double actualRpm = SensorCentral.getInstance().getValue(Sensor.RPM); + if (isCloseEnough(rpm, actualRpm)) + rpmLatch.countDown(); }; SensorCentral.getInstance().addListener(Sensor.RPM, listener); try { diff --git a/java_console/autotest/src/com/rusefi/RealHwTest.java b/java_console/autotest/src/com/rusefi/RealHwTest.java index 4977542b84..2f72d3cc32 100644 --- a/java_console/autotest/src/com/rusefi/RealHwTest.java +++ b/java_console/autotest/src/com/rusefi/RealHwTest.java @@ -81,9 +81,13 @@ public class RealHwTest { return port; } - private static void runRealHardwareTest(String port) throws Exception { + private static void runRealHardwareTest(String port) { LinkManager linkManager = new LinkManager(); IoUtil.realHardwareConnect(linkManager, port); + // first run tests which require real hardware + new HardwareTests(linkManager.getCommandQueue()).runRealHardwareTests(); + + // now run common part of the test which should be same on real hardware and simulator new AutoTest(linkManager, linkManager.getCommandQueue()).mainTestBody(); } } diff --git a/java_console/autotest/src/com/rusefi/TestingUtils.java b/java_console/autotest/src/com/rusefi/TestingUtils.java index cca8e507d3..e90479e188 100644 --- a/java_console/autotest/src/com/rusefi/TestingUtils.java +++ b/java_console/autotest/src/com/rusefi/TestingUtils.java @@ -100,7 +100,7 @@ public class TestingUtils { } } - static void assertNull(String msg, Object value) { + public static void assertNull(String msg, Object value) { assertTrue(msg, value == null); } diff --git a/java_console/autotest/src/com/rusefi/functional_tests/BaseTest.java b/java_console/autotest/src/com/rusefi/functional_tests/BaseTest.java new file mode 100644 index 0000000000..f6422dc45e --- /dev/null +++ b/java_console/autotest/src/com/rusefi/functional_tests/BaseTest.java @@ -0,0 +1,36 @@ +package com.rusefi.functional_tests; + +import com.rusefi.IoUtil; +import com.rusefi.Timeouts; +import com.rusefi.config.generated.Fields; +import com.rusefi.io.CommandQueue; + +import static com.rusefi.IoUtil.getEnableCommand; + +public class BaseTest { + protected final CommandQueue commandQueue; + + public BaseTest(CommandQueue commandQueue) { + this.commandQueue = commandQueue; + } + + protected void sendCommand(String command) { + sendCommand(command, CommandQueue.DEFAULT_TIMEOUT, Timeouts.CMD_TIMEOUT); + } + + protected void sendCommand(String command, int retryTimeoutMs, int timeoutMs) { + TestHelper.INSTANCE.assertNotFatal(); + IoUtil.sendCommand(command, retryTimeoutMs, timeoutMs, commandQueue); + } + + /** + * this seem to adjust engine sniffer behaviour + */ + protected void enableFunctionalMode() { + sendCommand(getEnableCommand(Fields.CMD_FUNCTIONAL_TEST_MODE)); + } + + protected void changeRpm(final int rpm) { + IoUtil.changeRpm(commandQueue, rpm); + } +} diff --git a/java_console/autotest/src/com/rusefi/functional_tests/TestHelper.java b/java_console/autotest/src/com/rusefi/functional_tests/TestHelper.java new file mode 100644 index 0000000000..2d74346818 --- /dev/null +++ b/java_console/autotest/src/com/rusefi/functional_tests/TestHelper.java @@ -0,0 +1,23 @@ +package com.rusefi.functional_tests; + +import com.rusefi.config.generated.Fields; +import com.rusefi.core.MessagesCentral; + +import static com.rusefi.TestingUtils.assertNull; + +public enum TestHelper { + INSTANCE; + + private String criticalError; + + TestHelper() { + MessagesCentral.getInstance().addListener((clazz, message) -> { + if (message.startsWith(Fields.CRITICAL_PREFIX)) + criticalError = message; + }); + } + + public void assertNotFatal() { + assertNull("Fatal not expected", criticalError); + } +}