diff --git a/java_console/autotest/src/com/rusefi/AutoTest.java b/java_console/autotest/src/com/rusefi/AutoTest.java index 2145f6cf7b..d1f84c824a 100644 --- a/java_console/autotest/src/com/rusefi/AutoTest.java +++ b/java_console/autotest/src/com/rusefi/AutoTest.java @@ -4,7 +4,7 @@ package com.rusefi; import com.rusefi.waves.WaveChart; import com.rusefi.waves.WaveReport; -import static com.rusefi.IoUtil.nextChart; +import static com.rusefi.TestingUtils.nextChart; import static com.rusefi.IoUtil.sendCommand; import static com.rusefi.IoUtil.sleep; import static com.rusefi.TestingUtils.*; @@ -18,6 +18,8 @@ import static com.rusefi.TestingUtils.*; * 3/5/14 */ public class AutoTest { + static int currentEngineType; + static void mainTestBody() { testCitroenBerlingo(); testMazda626(); @@ -36,6 +38,7 @@ public class AutoTest { } private static void setEngineType(int type) { + currentEngineType = type; sendCommand("set_engine_type " + type, 10000); sleep(5); sendCommand("enable self_stimulation"); diff --git a/java_console/autotest/src/com/rusefi/IoUtil.java b/java_console/autotest/src/com/rusefi/IoUtil.java index 2fe64a7337..3f79e50362 100644 --- a/java_console/autotest/src/com/rusefi/IoUtil.java +++ b/java_console/autotest/src/com/rusefi/IoUtil.java @@ -52,7 +52,7 @@ public class IoUtil { FileLog.MAIN.logLine("Command [" + command + "] executed in " + (System.currentTimeMillis() - time)); } - private static void wait(CountDownLatch responseLatch, int seconds) { + static void wait(CountDownLatch responseLatch, int seconds) { try { responseLatch.await(seconds, TimeUnit.SECONDS); } catch (InterruptedException e) { @@ -60,48 +60,6 @@ public class IoUtil { } } - static String getNextWaveChart() { - // we need to skip TWO because spark could have been scheduled a while ago and happen now - // todo: improve this logic, compare times - getWaveChart(); - // we want to wait for the 2nd chart to see same same RPM across the whole chart - String result = getWaveChart(); - FileLog.MAIN.logLine("current chart: " + result); - return result; - } - - /** - * This method is blocking and waits for the next wave chart to arrive - * - * @return next wave chart in the I/O pipeline - */ - private static String getWaveChart() { - final CountDownLatch waveChartLatch = new CountDownLatch(1); - - final AtomicReference result = new AtomicReference<>(); - - FileLog.MAIN.logLine("waiting for next chart"); - LinkManager.engineState.replaceStringValueAction(WaveReport.WAVE_CHART, new EngineState.ValueCallback() { - @Override - public void onUpdate(String value) { - waveChartLatch.countDown(); - result.set(value); - } - }); - int timeout = 60; - long waitStartTime = System.currentTimeMillis(); - wait(waveChartLatch, timeout); - FileLog.MAIN.logLine("got next chart in " + (System.currentTimeMillis() - waitStartTime) + "ms"); - LinkManager.engineState.replaceStringValueAction(WaveReport.WAVE_CHART, (EngineState.ValueCallback) EngineState.ValueCallback.VOID); - if (result.get() == null) - throw new IllegalStateException("Chart timeout: " + timeout); - return result.get(); - } - - static WaveChart nextChart() { - return WaveChartParser.unpackToMap(getNextWaveChart()); - } - static void changeRpm(final int rpm) { sendCommand("rpm " + rpm); long time = System.currentTimeMillis(); diff --git a/java_console/autotest/src/com/rusefi/TestingUtils.java b/java_console/autotest/src/com/rusefi/TestingUtils.java index 2dddede4b8..17e234f863 100644 --- a/java_console/autotest/src/com/rusefi/TestingUtils.java +++ b/java_console/autotest/src/com/rusefi/TestingUtils.java @@ -1,11 +1,16 @@ package com.rusefi; +import com.rusefi.core.EngineState; +import com.rusefi.io.LinkManager; import com.rusefi.waves.RevolutionLog; import com.rusefi.waves.WaveChart; +import com.rusefi.waves.WaveChartParser; import com.rusefi.waves.WaveReport; import java.util.Arrays; import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; import static com.rusefi.waves.WaveReport.isCloseEnough; @@ -86,4 +91,46 @@ public class TestingUtils { static void assertNull(String msg, Object value) { assertTrue(msg, value == null); } + + static WaveChart nextChart() { + return WaveChartParser.unpackToMap(getNextWaveChart()); + } + + static String getNextWaveChart() { + // we need to skip TWO because spark could have been scheduled a while ago and happen now + // todo: improve this logic, compare times + getWaveChart(); + // we want to wait for the 2nd chart to see same same RPM across the whole chart + String result = getWaveChart(); + FileLog.MAIN.logLine("current chart: " + result); + return result; + } + + /** + * This method is blocking and waits for the next wave chart to arrive + * + * @return next wave chart in the I/O pipeline + */ + private static String getWaveChart() { + final CountDownLatch waveChartLatch = new CountDownLatch(1); + + final AtomicReference result = new AtomicReference<>(); + + FileLog.MAIN.logLine("waiting for next chart"); + LinkManager.engineState.replaceStringValueAction(WaveReport.WAVE_CHART, new EngineState.ValueCallback() { + @Override + public void onUpdate(String value) { + waveChartLatch.countDown(); + result.set(value); + } + }); + int timeout = 60; + long waitStartTime = System.currentTimeMillis(); + IoUtil.wait(waveChartLatch, timeout); + FileLog.MAIN.logLine("got next chart in " + (System.currentTimeMillis() - waitStartTime) + "ms for engine_type " + AutoTest.currentEngineType); + LinkManager.engineState.replaceStringValueAction(WaveReport.WAVE_CHART, (EngineState.ValueCallback) EngineState.ValueCallback.VOID); + if (result.get() == null) + throw new IllegalStateException("Chart timeout: " + timeout); + return result.get(); + } }