Skip to content

Commit

Permalink
Xxx (#5567)
Browse files Browse the repository at this point in the history
* testability: bench test commands should have automated coverage using simulator #5562

* testability: bench test commands should have automated coverage using simulator #5562
  • Loading branch information
rusefillc committed Sep 16, 2023
1 parent 0650898 commit d558a46
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
9 changes: 9 additions & 0 deletions firmware/console/binary/tunerstudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ static bool isKnownCommand(char command) {
|| command == TS_PAGE_COMMAND || command == TS_BURN_COMMAND || command == TS_SINGLE_WRITE_COMMAND
|| command == TS_CHUNK_WRITE_COMMAND || command == TS_EXECUTE
|| command == TS_IO_TEST_COMMAND
#if EFI_SIMULATOR
|| command == TS_SIMULATE_CAN
#endif // EFI_SIMULATOR
|| command == TS_GET_SCATTERED_GET_COMMAND
|| command == TS_SET_LOGGER_SWITCH
|| command == TS_GET_COMPOSITE_BUFFER_DONE_DIFFERENTLY
Expand Down Expand Up @@ -717,6 +720,12 @@ int TunerStudio::handleCrcCommand(TsChannelBase* tsChannel, char *data, int inco
case 'T':
handleTestCommand(tsChannel);
break;
#if EFI_SIMULATOR
case TS_SIMULATE_CAN:
void handleWrapCan(TsChannelBase* tsChannel);
handleWrapCan(tsChannel);
break;
#endif // EFI_SIMULATOR
case TS_IO_TEST_COMMAND:
{
uint16_t subsystem = SWAP_UINT16(data16[0]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rusefi;

import com.rusefi.io.LinkManager;
import com.rusefi.simulator.SimulatorFunctionalTest;

/**
* this class runs rusEFI functional tests against rusEFI simulator
Expand All @@ -23,8 +24,7 @@ public static void main(String[] args) {
try {
LinkManager linkManager = new LinkManager();
IoUtil.connectToSimulator(linkManager, startSimulator);
// todo: new implementation for unit tests?
// new FunctionalTest(linkManager, linkManager.getCommandQueue()).mainTestBody();
new SimulatorFunctionalTest(linkManager).mainTestBody();
} catch (Throwable e) {
e.printStackTrace();
failed = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.rusefi.simulator;

import com.rusefi.io.LinkManager;
import etch.util.CircularByteBuffer;

import java.io.EOFException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static com.rusefi.binaryprotocol.IoHelper.swap16;
import static com.rusefi.config.generated.Fields.TS_SIMULATE_CAN;

public class SimulatorFunctionalTest {
private final LinkManager linkManager;

public SimulatorFunctionalTest(LinkManager linkManager) {
this.linkManager = linkManager;
}

public void mainTestBody() throws InterruptedException {
CountDownLatch gotCan = new CountDownLatch(1);
linkManager.submit(new Runnable() {
@Override
public void run() {
byte[] response = linkManager.getBinaryProtocol().executeCommand(TS_SIMULATE_CAN, "TS_SIMULATE_CAN");

if (response == null) {
return;
}
CircularByteBuffer c = new CircularByteBuffer(response);
try {
int count = swap16(c.getShort());

c.get();
int dataLength = c.get();
c.get();
int ide = c.get();
int eid = c.getInt();

System.out.println("Got " + count + " packets");
System.out.println(response);
gotCan.countDown();

} catch (EOFException e) {
throw new IllegalStateException(e);
}


}
});
gotCan.await(1, TimeUnit.MINUTES);


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public CircularByteBuffer(int size) {
buf = new byte[size];
}

/**
* creates buffer FILLED with specified content
*/
public CircularByteBuffer(byte[] buf) {
length = size = buf.length;
this.buf = buf;
}

@Override
public void clear() {
length = 0;
Expand Down
21 changes: 21 additions & 0 deletions simulator/simulator/rusEfiFunctionalTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include "rusefi_lua.h"
#include "can_hw.h"
#include "flash_main.h"
#include "can_msg_tx.h"
#include "fifo_buffer.h"
extern fifo_buffer<CANTxFrame, 1024> txCanBuffer;

#define DEFAULT_SIM_RPM 1200
#define DEFAULT_SNIFFER_THR 2500
Expand Down Expand Up @@ -224,3 +227,21 @@ CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx) {

void setBoardConfigOverrides() {
}

static uint8_t wrapOutBuffer[BLOCKING_FACTOR + 100];

void handleWrapCan(TsChannelBase* tsChannel) {
int size = minI(txCanBuffer.getSize(), BLOCKING_FACTOR / sizeof(CANTxFrame));

memcpy(wrapOutBuffer, &size, 2);
int outputSize = 2;

for (int i = 0;i < size;i++) {
CANTxFrame f = txCanBuffer.get();
void *frame = (void *)&f;
memcpy(((void*)wrapOutBuffer) + outputSize, frame, sizeof(CANTxFrame));
outputSize += sizeof(CANTxFrame);
}
tsChannel->sendResponse(TS_CRC, wrapOutBuffer, outputSize, true);

}

0 comments on commit d558a46

Please sign in to comment.