mirror of https://github.com/rusefi/rusefi.git
testability: bench test commands should have automated coverage using simulator #5562
trying to improve multi-threading
This commit is contained in:
parent
879fc64085
commit
debea23523
|
@ -50,14 +50,14 @@ jobs:
|
|||
working-directory: ./simulator/
|
||||
run: ./compile.sh
|
||||
|
||||
- name: Run Linux Simulator for 10 seconds
|
||||
working-directory: ./simulator/
|
||||
run: ./build/rusefi_simulator 10
|
||||
|
||||
- name: Run Simulator Functional Test
|
||||
working-directory: ./simulator/
|
||||
run: java -cp ../java_console/autotest/build/libs/autotest-all.jar com.rusefi.SimulatorFunctionalTestLauncher start
|
||||
|
||||
- name: Run Linux Simulator for 10 seconds
|
||||
working-directory: ./simulator/
|
||||
run: ./build/rusefi_simulator 10
|
||||
|
||||
- name: Reset git
|
||||
run: |
|
||||
git reset --hard
|
||||
|
|
|
@ -206,7 +206,7 @@ enum class engine_type_e : uint16_t {
|
|||
|
||||
PROTEUS_HONDA_OBD2A = 91,
|
||||
|
||||
UNUSED_92 = 92,
|
||||
SIMULATOR_CONFIG = 92,
|
||||
|
||||
PROTEUS_N73 = 93,
|
||||
|
||||
|
|
|
@ -1817,6 +1817,7 @@ end_struct
|
|||
|
||||
#define CMD_SET_SENSOR_MOCK "set_sensor_mock"
|
||||
#define CMD_RESET_SENSOR_MOCKS "reset_sensor_mocks"
|
||||
#define CMD_RESET_SIMULATOR "reset_simulator"
|
||||
|
||||
#define GAUGE_NAME_VERSION "firmware"
|
||||
#define GAUGE_NAME_UPTIME "Uptime"
|
||||
|
|
|
@ -105,7 +105,6 @@ public class IoUtil {
|
|||
}
|
||||
|
||||
private static void waitForFirstResponse() throws InterruptedException {
|
||||
log.info("Let's give it some time to start...");
|
||||
final CountDownLatch startup = new CountDownLatch(1);
|
||||
long waitStart = System.currentTimeMillis();
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import java.io.BufferedReader;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
@ -28,7 +30,7 @@ public class SimulatorExecHelper {
|
|||
/**
|
||||
* This is currently used by auto-tests only. Todo: reuse same code for UI-launched simulator?
|
||||
*/
|
||||
private static void runSimulator() {
|
||||
private static void runSimulator(CountDownLatch simulatorStarted) {
|
||||
Thread.currentThread().setName("Main simulation");
|
||||
FileLog.MAIN.logLine("runSimulator...");
|
||||
|
||||
|
@ -39,7 +41,7 @@ public class SimulatorExecHelper {
|
|||
simulatorProcess = Runtime.getRuntime().exec(SIMULATOR_BINARY);
|
||||
FileLog.MAIN.logLine("simulatorProcess: " + simulatorProcess);
|
||||
|
||||
dumpProcessOutput(simulatorProcess);
|
||||
dumpProcessOutput(simulatorProcess, simulatorStarted);
|
||||
|
||||
FileLog.MAIN.logLine("exitValue: " + simulatorProcess.exitValue());
|
||||
|
||||
|
@ -53,7 +55,7 @@ public class SimulatorExecHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static void dumpProcessOutput(Process process) throws IOException {
|
||||
public static void dumpProcessOutput(Process process, CountDownLatch countDownLatch) throws IOException {
|
||||
BufferedReader input =
|
||||
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
Thread thread = THREAD_FACTORY.newThread(createErrorStreamEcho(process));
|
||||
|
@ -62,6 +64,7 @@ public class SimulatorExecHelper {
|
|||
AtomicInteger counter = new AtomicInteger();
|
||||
String prefix = "from console: ";
|
||||
Consumer<String> PRINT_AND_LOG = string -> {
|
||||
countDownLatch.countDown();
|
||||
// looks like this is a performance issue since so many lines are printed? looks like it's helping to not write this?
|
||||
if (counter.incrementAndGet() < 1000)
|
||||
System.out.println(prefix + string);
|
||||
|
@ -104,10 +107,14 @@ public class SimulatorExecHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static void startSimulator() {
|
||||
public static void startSimulator() throws InterruptedException {
|
||||
if (!new File(SIMULATOR_BINARY).exists())
|
||||
throw new IllegalStateException(SIMULATOR_BINARY + " not found");
|
||||
FileLog.MAIN.logLine("startSimulator...");
|
||||
new Thread(() -> runSimulator(), "simulator process").start();
|
||||
CountDownLatch simulatorStarted = new CountDownLatch(1);
|
||||
new Thread(() -> runSimulator(simulatorStarted), "simulator process").start();
|
||||
simulatorStarted.await(1, TimeUnit.MINUTES);
|
||||
System.out.println("Let's give it some time to start...");
|
||||
Thread.sleep(5);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -256,10 +256,11 @@ public class LinkManager implements Closeable {
|
|||
Callable<IoStream> streamFactory = new Callable<IoStream>() {
|
||||
@Override
|
||||
public IoStream call() {
|
||||
messageListener.postMessage(getClass(), "Opening port: " + port);
|
||||
messageListener.postMessage(getClass(), "Opening TCP port: " + port);
|
||||
try {
|
||||
return TcpIoStream.open(port);
|
||||
} catch (Throwable e) {
|
||||
log.error("TCP error " + e);
|
||||
stateListener.onConnectionFailed("Error " + e);
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.awt.event.ActionEvent;
|
|||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import static com.rusefi.ui.util.UiUtils.setToolTip;
|
||||
|
@ -36,7 +37,7 @@ public class SimulatorHelper {
|
|||
FileLog.SIMULATOR_CONSOLE.start();
|
||||
process = Runtime.getRuntime().exec(BINARY);
|
||||
FileLog.MAIN.logLine("Executing " + BINARY + "=" + process);
|
||||
SimulatorExecHelper.dumpProcessOutput(process);
|
||||
SimulatorExecHelper.dumpProcessOutput(process, new CountDownLatch(1));
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue