trigger and VSS hw integrated testing #1668

This commit is contained in:
rusefi 2020-08-08 11:25:17 -04:00
parent 1d5b4cf187
commit 1238dfb837
10 changed files with 105 additions and 47 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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")) {

View File

@ -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<String, Object> 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);
}

View File

@ -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();
}
}

View File

@ -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 {

View File

@ -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();
}
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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);
}
}