Skip to content

Commit

Permalink
testability: bench test commands should have automated coverage usin…
Browse files Browse the repository at this point in the history
…g simulator #5562

 trying to improve multi-threading
  • Loading branch information
rusefillc committed Sep 13, 2023
1 parent 879fc64 commit debea23
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-simulator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion firmware/controllers/algo/engine_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ enum class engine_type_e : uint16_t {

PROTEUS_HONDA_OBD2A = 91,

UNUSED_92 = 92,
SIMULATOR_CONFIG = 92,

PROTEUS_N73 = 93,

Expand Down
1 change: 1 addition & 0 deletions firmware/integration/rusefi_config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion java_console/autotest/src/main/java/com/rusefi/IoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public static void changeRpm(CommandQueue commandQueue, final int rpm) {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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;

Expand All @@ -28,7 +30,7 @@ private static String getSimulatorBinary() {
/**
* 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...");

Expand All @@ -39,7 +41,7 @@ private static void runSimulator() {
simulatorProcess = Runtime.getRuntime().exec(SIMULATOR_BINARY);
FileLog.MAIN.logLine("simulatorProcess: " + simulatorProcess);

dumpProcessOutput(simulatorProcess);
dumpProcessOutput(simulatorProcess, simulatorStarted);

FileLog.MAIN.logLine("exitValue: " + simulatorProcess.exitValue());

Expand All @@ -53,7 +55,7 @@ private static void runSimulator() {
}
}

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));
Expand All @@ -62,6 +64,7 @@ public static void dumpProcessOutput(Process process) throws IOException {
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);
Expand Down Expand Up @@ -104,10 +107,14 @@ static void destroy() {
}
}

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);
}
}
3 changes: 2 additions & 1 deletion java_console/io/src/main/java/com/rusefi/io/LinkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,11 @@ public void start(String port, ConnectionFailedListener stateListener) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -36,7 +37,7 @@ public void run() {
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);
}
Expand Down

0 comments on commit debea23

Please sign in to comment.