* testability: bench test commands should have automated coverage using simulator #5562

* testability: bench test commands should have automated coverage using simulator #5562
This commit is contained in:
rusefillc 2023-09-16 07:29:53 -07:00 committed by GitHub
parent 0650898798
commit d558a46a11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 2 deletions

View File

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

View File

@ -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
@ -23,8 +24,7 @@ public class SimulatorFunctionalTestLauncher {
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;

View File

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

View File

@ -47,6 +47,14 @@ public class CircularByteBuffer extends ByteBuffer {
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;

View File

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