mirror of https://github.com/rusefi/rusefi-1.git
refactoring: better dependency control
This commit is contained in:
parent
ac051fb916
commit
1956541d35
|
@ -35,7 +35,15 @@ public class AutoTest {
|
||||||
static int currentEngineType;
|
static int currentEngineType;
|
||||||
private static String criticalError;
|
private static String criticalError;
|
||||||
|
|
||||||
static void mainTestBody(LinkManager linkManager) throws Exception {
|
private final LinkManager linkManager;
|
||||||
|
private CommandQueue commandQueue;
|
||||||
|
|
||||||
|
public AutoTest(LinkManager linkManager, CommandQueue commandQueue) {
|
||||||
|
this.linkManager = linkManager;
|
||||||
|
this.commandQueue = commandQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mainTestBody() throws Exception {
|
||||||
MessagesCentral.getInstance().addListener(new MessagesCentral.MessageListener() {
|
MessagesCentral.getInstance().addListener(new MessagesCentral.MessageListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(Class clazz, String message) {
|
public void onMessage(Class clazz, String message) {
|
||||||
|
@ -81,21 +89,21 @@ public class AutoTest {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static void testVW_60_2() {
|
private void testVW_60_2() {
|
||||||
setEngineType(32);
|
setEngineType(32);
|
||||||
changeRpm(900);
|
changeRpm(900);
|
||||||
// first let's get to expected RPM
|
// first let's get to expected RPM
|
||||||
assertRpmDoesNotJump(20000, 15, 30, FAIL);
|
assertRpmDoesNotJump(20000, 15, 30, FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testV12() {
|
private void testV12() {
|
||||||
setEngineType(40);
|
setEngineType(40);
|
||||||
changeRpm(700);
|
changeRpm(700);
|
||||||
// first let's get to expected RPM
|
// first let's get to expected RPM
|
||||||
assertRpmDoesNotJump(15000, 15, 30, FAIL);
|
assertRpmDoesNotJump(15000, 15, 30, FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertRpmDoesNotJump(int rpm, int settleTime, int testDuration, Function<String, Object> callback) {
|
public void assertRpmDoesNotJump(int rpm, int settleTime, int testDuration, Function<String, Object> callback) {
|
||||||
changeRpm(rpm);
|
changeRpm(rpm);
|
||||||
sleepSeconds(settleTime);
|
sleepSeconds(settleTime);
|
||||||
AtomicReference<String> result = new AtomicReference<>();
|
AtomicReference<String> result = new AtomicReference<>();
|
||||||
|
@ -113,7 +121,7 @@ public class AutoTest {
|
||||||
SensorCentral.getInstance().removeListener(Sensor.RPM, listener);
|
SensorCentral.getInstance().removeListener(Sensor.RPM, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testCustomEngine() {
|
private void testCustomEngine() {
|
||||||
setEngineType(0);
|
setEngineType(0);
|
||||||
sendCommand("set_toothed_wheel 4 0");
|
sendCommand("set_toothed_wheel 4 0");
|
||||||
// sendCommand("enable trigger_only_front");
|
// sendCommand("enable trigger_only_front");
|
||||||
|
@ -124,24 +132,24 @@ public class AutoTest {
|
||||||
// changeRpm(1500);
|
// changeRpm(1500);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testMazdaMiata2003() {
|
private void testMazdaMiata2003() {
|
||||||
setEngineType(47);
|
setEngineType(47);
|
||||||
sendCommand("get cranking_dwell"); // just test coverage
|
sendCommand("get cranking_dwell"); // just test coverage
|
||||||
// sendCommand("get nosuchgettersdfsdfsdfsdf"); // just test coverage
|
// sendCommand("get nosuchgettersdfsdfsdfsdf"); // just test coverage
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testCamaro() {
|
private void testCamaro() {
|
||||||
setEngineType(35);
|
setEngineType(35);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testSachs() {
|
private void testSachs() {
|
||||||
setEngineType(29);
|
setEngineType(29);
|
||||||
String msg = "BMW";
|
String msg = "BMW";
|
||||||
IoUtil.changeRpm(1200);
|
IoUtil.changeRpm(1200);
|
||||||
// todo: add more content
|
// todo: add more content
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testBmwE34() {
|
private void testBmwE34() {
|
||||||
setEngineType(25);
|
setEngineType(25);
|
||||||
sendCommand("chart 1");
|
sendCommand("chart 1");
|
||||||
String msg = "BMW";
|
String msg = "BMW";
|
||||||
|
@ -164,24 +172,28 @@ public class AutoTest {
|
||||||
assertWave(msg, chart, EngineChart.MAP_AVERAGING, 0.139, x, x + 120, x + 240, x + 360, x + 480, x + 600);
|
assertWave(msg, chart, EngineChart.MAP_AVERAGING, 0.139, x, x + 120, x + 240, x + 360, x + 480, x + 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testMitsu() {
|
void changeRpm(final int rpm) {
|
||||||
|
IoUtil.changeRpm(rpm);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testMitsu() {
|
||||||
setEngineType(16);
|
setEngineType(16);
|
||||||
sendCommand("disable cylinder_cleanup");
|
sendCommand("disable cylinder_cleanup");
|
||||||
String msg = "Mitsubishi";
|
String msg = "Mitsubishi";
|
||||||
IoUtil.changeRpm(200);
|
changeRpm(200);
|
||||||
|
|
||||||
IoUtil.changeRpm(1200);
|
changeRpm(1200);
|
||||||
// todo: add more content
|
// todo: add more content
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testCitroenBerlingo() {
|
private void testCitroenBerlingo() {
|
||||||
setEngineType(ET_CITROEN_TU3JP);
|
setEngineType(ET_CITROEN_TU3JP);
|
||||||
String msg = "Citroen";
|
String msg = "Citroen";
|
||||||
IoUtil.changeRpm(1200);
|
changeRpm(1200);
|
||||||
// todo: add more content
|
// todo: add more content
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setEngineType(int type) {
|
private void setEngineType(int type) {
|
||||||
FileLog.MAIN.logLine("AUTOTEST setEngineType " + type);
|
FileLog.MAIN.logLine("AUTOTEST setEngineType " + type);
|
||||||
// sendCommand(CMD_PINS);
|
// sendCommand(CMD_PINS);
|
||||||
currentEngineType = type;
|
currentEngineType = type;
|
||||||
|
@ -191,7 +203,7 @@ public class AutoTest {
|
||||||
sendCommand(getEnableCommand("self_stimulation"));
|
sendCommand(getEnableCommand("self_stimulation"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testMazda626() {
|
private void testMazda626() {
|
||||||
setEngineType(28);
|
setEngineType(28);
|
||||||
String msg = "mazda 626 default cranking";
|
String msg = "mazda 626 default cranking";
|
||||||
IoUtil.changeRpm(200);
|
IoUtil.changeRpm(200);
|
||||||
|
@ -202,7 +214,7 @@ public class AutoTest {
|
||||||
assertWave(msg, chart, EngineChart.SPARK_1, 0.1944, x, x + 180, x + 360, x + 540);
|
assertWave(msg, chart, EngineChart.SPARK_1, 0.1944, x, x + 180, x + 360, x + 540);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void test2003DodgeNeon() {
|
private void test2003DodgeNeon() {
|
||||||
setEngineType(23);
|
setEngineType(23);
|
||||||
sendCommand("set wwaeTau 0");
|
sendCommand("set wwaeTau 0");
|
||||||
sendCommand("set wwaeBeta 0");
|
sendCommand("set wwaeBeta 0");
|
||||||
|
@ -268,7 +280,7 @@ public class AutoTest {
|
||||||
assertWave(true, msg, chart, EngineChart.SPARK_1, 0.13299999999999998, EngineReport.RATIO, EngineReport.RATIO, x + 180, x + 540);
|
assertWave(true, msg, chart, EngineChart.SPARK_1, 0.13299999999999998, EngineReport.RATIO, EngineReport.RATIO, x + 180, x + 540);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testMazdaProtege() {
|
private void testMazdaProtege() {
|
||||||
setEngineType(14);
|
setEngineType(14);
|
||||||
EngineChart chart;
|
EngineChart chart;
|
||||||
sendCommand("set mock_vbatt_voltage 1.395");
|
sendCommand("set mock_vbatt_voltage 1.395");
|
||||||
|
@ -295,7 +307,7 @@ public class AutoTest {
|
||||||
assertWaveFall(msg, chart, EngineChart.INJECTOR_2, 0.21433333333333345, x, x + 360);
|
assertWaveFall(msg, chart, EngineChart.INJECTOR_2, 0.21433333333333345, x, x + 360);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void test1995DodgeNeon() {
|
private void test1995DodgeNeon() {
|
||||||
setEngineType(2);
|
setEngineType(2);
|
||||||
EngineChart chart;
|
EngineChart chart;
|
||||||
sendComplexCommand("set_whole_fuel_map 3");
|
sendComplexCommand("set_whole_fuel_map 3");
|
||||||
|
@ -329,11 +341,11 @@ public class AutoTest {
|
||||||
assertWaveFall(msg, chart, EngineChart.INJECTOR_4, 0.493, x + 540);
|
assertWaveFall(msg, chart, EngineChart.INJECTOR_4, 0.493, x + 540);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testRoverV8() {
|
private void testRoverV8() {
|
||||||
setEngineType(10);
|
setEngineType(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testFordFiesta() {
|
private void testFordFiesta() {
|
||||||
setEngineType(4);
|
setEngineType(4);
|
||||||
EngineChart chart;
|
EngineChart chart;
|
||||||
IoUtil.changeRpm(2000);
|
IoUtil.changeRpm(2000);
|
||||||
|
@ -347,7 +359,7 @@ public class AutoTest {
|
||||||
assertWaveNull(msg, chart, EngineChart.SPARK_4);
|
assertWaveNull(msg, chart, EngineChart.SPARK_4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testFord6() {
|
private void testFord6() {
|
||||||
setEngineType(7);
|
setEngineType(7);
|
||||||
EngineChart chart;
|
EngineChart chart;
|
||||||
IoUtil.changeRpm(2000);
|
IoUtil.changeRpm(2000);
|
||||||
|
@ -364,7 +376,7 @@ public class AutoTest {
|
||||||
assertTrue(msg, chart.get(EngineChart.TRIGGER_2) != null);
|
assertTrue(msg, chart.get(EngineChart.TRIGGER_2) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testFordAspire() {
|
private void testFordAspire() {
|
||||||
setEngineType(3);
|
setEngineType(3);
|
||||||
sendCommand("disable cylinder_cleanup");
|
sendCommand("disable cylinder_cleanup");
|
||||||
sendCommand("set mock_map_voltage 1");
|
sendCommand("set mock_map_voltage 1");
|
||||||
|
@ -486,13 +498,13 @@ public class AutoTest {
|
||||||
assertWaveNull("hard limit check", chart, EngineChart.INJECTOR_1);
|
assertWaveNull("hard limit check", chart, EngineChart.INJECTOR_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendCommand(String command) {
|
private void sendCommand(String command) {
|
||||||
sendCommand(command, CommandQueue.DEFAULT_TIMEOUT, Timeouts.CMD_TIMEOUT);
|
sendCommand(command, CommandQueue.DEFAULT_TIMEOUT, Timeouts.CMD_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendCommand(String command, int retryTimeoutMs, int timeoutMs) {
|
private void sendCommand(String command, int retryTimeoutMs, int timeoutMs) {
|
||||||
assertNull("Fatal not expected", criticalError);
|
assertNull("Fatal not expected", criticalError);
|
||||||
IoUtil.sendCommand(command, retryTimeoutMs, timeoutMs);
|
IoUtil.sendCommand(command, retryTimeoutMs, timeoutMs, commandQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertEquals(double expected, double actual) {
|
private static void assertEquals(double expected, double actual) {
|
||||||
|
@ -511,7 +523,7 @@ public class AutoTest {
|
||||||
/**
|
/**
|
||||||
* This method waits for longer then usual.
|
* This method waits for longer then usual.
|
||||||
*/
|
*/
|
||||||
private static void sendComplexCommand(String command) {
|
private void sendComplexCommand(String command) {
|
||||||
sendCommand(command, COMPLEX_COMMAND_RETRY, Timeouts.CMD_TIMEOUT);
|
sendCommand(command, COMPLEX_COMMAND_RETRY, Timeouts.CMD_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,7 +553,7 @@ public class AutoTest {
|
||||||
try {
|
try {
|
||||||
LinkManager linkManager = new LinkManager();
|
LinkManager linkManager = new LinkManager();
|
||||||
IoUtil.connectToSimulator(linkManager, startSimulator);
|
IoUtil.connectToSimulator(linkManager, startSimulator);
|
||||||
mainTestBody(linkManager);
|
new AutoTest(linkManager, CommandQueue.getInstance()).mainTestBody();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
failed = true;
|
failed = true;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.rusefi;
|
package com.rusefi;
|
||||||
|
|
||||||
import com.rusefi.config.generated.Fields;
|
import com.rusefi.config.generated.Fields;
|
||||||
|
import com.rusefi.io.CommandQueue;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
|
|
||||||
import static com.rusefi.IoUtil.*;
|
import static com.rusefi.IoUtil.*;
|
||||||
|
@ -12,6 +13,7 @@ public class EnduranceTest {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
LinkManager linkManager = new LinkManager();
|
LinkManager linkManager = new LinkManager();
|
||||||
|
CommandQueue commandQueue = CommandQueue.getInstance();
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
int count = parseCount(args);
|
int count = parseCount(args);
|
||||||
try {
|
try {
|
||||||
|
@ -27,12 +29,12 @@ public class EnduranceTest {
|
||||||
IoUtil.realHardwareConnect(linkManager, port);
|
IoUtil.realHardwareConnect(linkManager, port);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
AutoTest.currentEngineType = 3;
|
AutoTest.currentEngineType = 3;
|
||||||
sendCommand("set " + Fields.CMD_ENGINE_TYPE + " " + 3, AutoTest.COMPLEX_COMMAND_RETRY, Timeouts.SET_ENGINE_TIMEOUT);
|
sendCommand("set " + Fields.CMD_ENGINE_TYPE + " " + 3, AutoTest.COMPLEX_COMMAND_RETRY, Timeouts.SET_ENGINE_TIMEOUT, commandQueue);
|
||||||
sleepSeconds(2);
|
sleepSeconds(2);
|
||||||
sendCommand(getEnableCommand("self_stimulation"));
|
sendCommand(getEnableCommand("self_stimulation"));
|
||||||
// IoUtil.changeRpm(1200);
|
// IoUtil.changeRpm(1200);
|
||||||
AutoTest.currentEngineType = 28;
|
AutoTest.currentEngineType = 28;
|
||||||
sendCommand("set " + Fields.CMD_ENGINE_TYPE + " " + 28, AutoTest.COMPLEX_COMMAND_RETRY, Timeouts.SET_ENGINE_TIMEOUT);
|
sendCommand("set " + Fields.CMD_ENGINE_TYPE + " " + 28, AutoTest.COMPLEX_COMMAND_RETRY, Timeouts.SET_ENGINE_TIMEOUT, commandQueue);
|
||||||
sleepSeconds(2);
|
sleepSeconds(2);
|
||||||
FileLog.MAIN.logLine("++++++++++++++++++++++++++++++++++++ " + i + " +++++++++++++++");
|
FileLog.MAIN.logLine("++++++++++++++++++++++++++++++++++++ " + i + " +++++++++++++++");
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class IoUtil {
|
||||||
* @throws IllegalStateException if command was not confirmed
|
* @throws IllegalStateException if command was not confirmed
|
||||||
*/
|
*/
|
||||||
static void sendCommand(String command) {
|
static void sendCommand(String command) {
|
||||||
sendCommand(command, CommandQueue.DEFAULT_TIMEOUT, Timeouts.CMD_TIMEOUT);
|
sendCommand(command, CommandQueue.DEFAULT_TIMEOUT, Timeouts.CMD_TIMEOUT, CommandQueue.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getEnableCommand(String settingName) {
|
public static String getEnableCommand(String settingName) {
|
||||||
|
@ -41,12 +41,12 @@ public class IoUtil {
|
||||||
/**
|
/**
|
||||||
* blocking method which would for confirmation from rusEfi
|
* blocking method which would for confirmation from rusEfi
|
||||||
*/
|
*/
|
||||||
static void sendCommand(String command, int retryTimeoutMs, int timeoutMs) {
|
static void sendCommand(String command, int retryTimeoutMs, int timeoutMs, CommandQueue commandQueue) {
|
||||||
final CountDownLatch responseLatch = new CountDownLatch(1);
|
final CountDownLatch responseLatch = new CountDownLatch(1);
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
FileLog.MAIN.logLine("Sending command [" + command + "]");
|
FileLog.MAIN.logLine("Sending command [" + command + "]");
|
||||||
final long begin = System.currentTimeMillis();
|
final long begin = System.currentTimeMillis();
|
||||||
CommandQueue.getInstance().write(command, retryTimeoutMs, new InvocationConfirmationListener() {
|
commandQueue.write(command, retryTimeoutMs, new InvocationConfirmationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCommandConfirmation() {
|
public void onCommandConfirmation() {
|
||||||
responseLatch.countDown();
|
responseLatch.countDown();
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package com.rusefi;
|
package com.rusefi;
|
||||||
|
|
||||||
|
import com.rusefi.io.CommandQueue;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
||||||
import static com.rusefi.AutoTest.mainTestBody;
|
|
||||||
import static com.rusefi.Timeouts.SECOND;
|
import static com.rusefi.Timeouts.SECOND;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,6 +85,6 @@ public class RealHwTest {
|
||||||
private static void runRealHardwareTest(String port) throws Exception {
|
private static void runRealHardwareTest(String port) throws Exception {
|
||||||
LinkManager linkManager = new LinkManager();
|
LinkManager linkManager = new LinkManager();
|
||||||
IoUtil.realHardwareConnect(linkManager, port);
|
IoUtil.realHardwareConnect(linkManager, port);
|
||||||
mainTestBody(linkManager);
|
new AutoTest(linkManager, CommandQueue.getInstance()).mainTestBody();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue