Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions esp32-flash-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

<properties>
<basepom.deploy.skip>true</basepom.deploy.skip>
<basepom.check.skip-license>true</basepom.check.skip-license>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.file.Path;

import org.dkaukov.esp32.io.ProgressCallback;
import org.dkaukov.esp32.test.SlipLogPlayer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

import lombok.extern.slf4j.Slf4j;

Expand All @@ -41,6 +45,16 @@ public void onInfo(String value) {
return res;
}

@BeforeEach
void logTestInfo(TestInfo testInfo) {
log.info("Running test: {} [{}()]", testInfo.getDisplayName(), testInfo.getTestMethod().map(Method::getName).orElse("unknown"));
}

@AfterEach
void logTestEnd() {
log.info("--------------------------------------------------------------------");
}

@Test
@DisplayName("Test the sync operation of the protocol.")
void sync() throws IOException {
Expand Down Expand Up @@ -140,4 +154,133 @@ void writeDeflFlash() throws IOException {
protocol.reset();
assertTrue(player.isFinished());
}

@Test
@DisplayName("Test erasing a specific region of the flash memory of the ESP32.")
void eraseFlashRegion() throws IOException {
protocol = getProtocol("erase-flash-region.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.loadStub();
protocol.eraseFlashRegion(0x0000, 0x400);
protocol.reset();
assertTrue(player.isFinished());
}

@Test
@DisplayName("Test reading a specific region of the flash memory of the ESP32.")
void readFlashRegion() throws IOException {
byte [] data = new byte[1024];
protocol = getProtocol("read-flash-region.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.loadStub();
protocol.readFlash(data, 0x0000, 0x400);
protocol.reset();
assertTrue(player.isFinished());
}

@Test
@DisplayName("Test running user code on the ESP32.")
void runUserCode() throws IOException {
protocol = getProtocol("run-user-code.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.loadStub();
protocol.runUserCode();
protocol.reset();
assertTrue(player.isFinished());
}

@Test
@DisplayName("Test updating a specific register on the ESP32.")
void updateReg() throws IOException {
protocol = getProtocol("update-reg.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.loadStub();
protocol.updateReg(0x0000, 0xFFFFF, 0x1234);
protocol.reset();
assertTrue(player.isFinished());
}

@Test
@DisplayName("Test ending the flash operation on the ESP32.")
void endFlash() throws IOException {
protocol = getProtocol("end-flash.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.loadStub();
protocol.endFlash(true);
protocol.reset();
assertTrue(player.isFinished());
}

@Test
@DisplayName("Test ending the deflate flash operation on the ESP32.")
void endDeflFlash() throws IOException {
protocol = getProtocol("end-defl-flash.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.loadStub();
protocol.endDeflFlash(true);
protocol.reset();
assertTrue(player.isFinished());
}

@Test
@DisplayName("Test writing data to the flash memory of the ESP32 without using a stub.")
void writeFlashNoStub() throws IOException {
byte [] data = new byte[1024];
protocol = getProtocol("write-flash-no-stub.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.espSpiAttach();
protocol.flashWrite(data, 0x400, 0x0000);
protocol.reset();
assertTrue(player.isFinished());
}

@Test
@DisplayName("Test writing compressed data to the flash memory of the ESP32 without using a stub.")
void writeDeflFlashNoStub() throws IOException {
byte [] data = new byte[1024];
protocol = getProtocol("write-defl-flash-no-stub.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.espSpiAttach();
protocol.flashDeflWrite(data, 0x400, 0x0000);
protocol.reset();
assertTrue(player.isFinished());
}

@Test
@DisplayName("Test changing the baud rate of the ESP32.")
void changeBaudRate() throws IOException {
protocol = getProtocol("change-baud-rate.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.changeBaudRate(115200);
protocol.reset();
assertTrue(player.isFinished());
}

@Test
@DisplayName("Test setting the flash size of the ESP32.")
void setFlashSize() throws IOException {
protocol = getProtocol("set-flash-size.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.setFlashSize(1024 * 1024 * 4);
protocol.reset();
assertTrue(player.isFinished());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ static void setUp() {
comPort.openPort();
}

private static EspFlasherProtocol getProtocol(String first) throws IOException {
return new EspFlasherProtocol(new SlipLoggingSerialTransport(new TestTransport(comPort), Path.of(first)));
private static EspFlasherProtocol getProtocol(String file) throws IOException {
return new EspFlasherProtocol(new SlipLoggingSerialTransport(new TestTransport(comPort), Path.of("src/test/resources/" + file)));
}

@Test
void sync() throws IOException {
protocol = getProtocol("src/test/resources/sync.txt");
protocol = getProtocol("sync.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.reset();
}

@Test
void detectChip() throws IOException {
protocol = getProtocol("src/test/resources/detect-chip.txt");
protocol = getProtocol("detect-chip.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
Expand All @@ -94,7 +94,7 @@ void detectChip() throws IOException {

@Test
void loadStub() throws IOException {
protocol = getProtocol("src/test/resources/load-stub.txt");
protocol = getProtocol("load-stub.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
Expand All @@ -105,7 +105,7 @@ void loadStub() throws IOException {
@Test
void writeFlash() throws IOException {
byte [] data = new byte[1024];
protocol = getProtocol("src/test/resources/write-flash.txt");
protocol = getProtocol("write-flash.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
Expand All @@ -116,7 +116,7 @@ void writeFlash() throws IOException {

@Test
void eraseFlash() throws IOException {
protocol = getProtocol("src/test/resources/erase-flash.txt");
protocol = getProtocol("erase-flash.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
Expand All @@ -128,7 +128,7 @@ void eraseFlash() throws IOException {
@Test
void writeMem() throws IOException {
byte [] data = new byte[1024];
protocol = getProtocol("src/test/resources/write-mem.txt");
protocol = getProtocol("write-mem.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.memWrite(data, 0x1800, 0x0000);
Expand All @@ -138,7 +138,7 @@ void writeMem() throws IOException {
@Test
void verifyFlash() throws IOException {
byte [] data = new byte[1024];
protocol = getProtocol("src/test/resources/verify-flash.txt");
protocol = getProtocol("verify-flash.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
Expand All @@ -150,12 +150,121 @@ void verifyFlash() throws IOException {
@Test
void writeDeflFlash() throws IOException {
byte [] data = new byte[1024];
protocol = getProtocol("src/test/resources/write-defl-flash.txt");
protocol = getProtocol("write-defl-flash.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.loadStub();
protocol.flashDeflWrite(data, 0x400, 0x0000);
protocol.reset();
}

@Test
void eraseFlashRegion() throws IOException {
protocol = getProtocol("erase-flash-region.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.loadStub();
protocol.eraseFlashRegion(0x0000, 0x400);
protocol.reset();
}

@Test
void readFlashRegion() throws IOException {
byte [] data = new byte[1024];
protocol = getProtocol("read-flash-region.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.loadStub();
protocol.readFlash(data, 0x0000, 0x400);
protocol.reset();
}

@Test
void runUserCode() throws IOException {
protocol = getProtocol("run-user-code.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.loadStub();
protocol.runUserCode();
protocol.reset();
}

@Test
void updateReg() throws IOException {
protocol = getProtocol("update-reg.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.loadStub();
protocol.updateReg(0x0000, 0xFFFFF, 0x1234);
protocol.reset();
}

@Test
void endFlash() throws IOException {
protocol = getProtocol("end-flash.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.loadStub();
protocol.endFlash(true);
protocol.reset();
}

@Test
void endDeflFlash() throws IOException {
protocol = getProtocol("end-defl-flash.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.loadStub();
protocol.endDeflFlash(true);
protocol.reset();
}

@Test
void writeFlashNoStub() throws IOException {
byte [] data = new byte[1024];
protocol = getProtocol("write-flash-no-stub.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.espSpiAttach();
protocol.flashWrite(data, 0x400, 0x0000);
protocol.reset();
}

@Test
void writeDeflFlashNoStub() throws IOException {
byte [] data = new byte[1024];
protocol = getProtocol("write-defl-flash-no-stub.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.detectChip();
protocol.espSpiAttach();
protocol.flashDeflWrite(data, 0x400, 0x0000);
protocol.reset();
}

@Test
void changeBaudRate() throws IOException {
protocol = getProtocol("change-baud-rate.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.changeBaudRate(115200);
protocol.reset();
}

@Test
void setFlashSize() throws IOException {
protocol = getProtocol("set-flash-size.txt");
protocol.enterBootLoader();
protocol.sync();
protocol.setFlashSize(1024 * 1024 * 4);
protocol.reset();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public int read(byte[] buffer, int length) {
if (entry.direction != Direction.READ)
throw new AssertionError("Expected READ entry but got: " + entry.direction);
currentReadBuffer = new ByteArrayInputStream(entry.data);
readDelay = (int) Math.round((nextTimestamp - entry.timestamp) * 1000.0);
readDelay = (int) Math.round((nextTimestamp - entry.timestamp) * 1100.0);
}
return currentReadBuffer.read(buffer, 0, length);
}
Expand Down
17 changes: 17 additions & 0 deletions esp32-flash-lib/src/test/resources/change-baud-rate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[0.004] SET_CONTROL_LINES DTR=true RTS=false
[0.119] SET_CONTROL_LINES DTR=false RTS=true
[0.226] SET_CONTROL_LINES DTR=true RTS=false
[0.228] >>>> ( 42): C0 00 08 20 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
[0.234] <<<< ( 14): C0 01 08 04 00 07 07 12 20 00 00 00 00 C0
[0.234] <<<< ( 14): C0 01 08 04 00 07 07 12 20 00 00 00 00 C0
[0.234] <<<< ( 14): C0 01 08 04 00 07 07 12 20 00 00 00 00 C0
[0.234] <<<< ( 14): C0 01 08 04 00 07 07 12 20 00 00 00 00 C0
[0.238] <<<< ( 14): C0 01 08 04 00 07 07 12 20 00 00 00 00 C0
[0.238] <<<< ( 14): C0 01 08 04 00 07 07 12 20 00 00 00 00 C0
[0.238] <<<< ( 14): C0 01 08 04 00 07 07 12 20 00 00 00 00 C0
[0.238] <<<< ( 14): C0 01 08 04 00 07 07 12 20 00 00 00 00 C0
[0.341] >>>> ( 18): C0 00 0F 08 00 00 00 00 00 00 C2 01 00 00 00 00 00 C0
[0.341] <<<< ( 14): C0 01 0F 04 00 00 00 00 00 00 00 00 00 C0
[0.342] SET_CONTROL_LINES DTR=false RTS=false
[0.447] SET_CONTROL_LINES DTR=false RTS=true
[0.552] SET_CONTROL_LINES DTR=false RTS=false
Loading