Skip to content

Commit

Permalink
Prepare test devices in parallel.
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch committed Feb 5, 2025
1 parent 4e09612 commit 2e45dfa
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
9 changes: 7 additions & 2 deletions tests/hw/esp-tester/mini-jag.toit
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ install-new-test:
writer := containers.ContainerImageWriter size
written-size := 0
while written-size < size:
data := reader.read
data := reader.read --max-size=(size - written-size)
summer.add data
writer.write data
written-size += data.size
Expand All @@ -56,11 +56,16 @@ install-new-test:
throw"CRC MISMATCH"
return
writer.commit
print "INSTALLED CONTAINER"
print "WAITING FOR RUN-SIGNAL"
run-message := reader.read-string RUN-TEST.size
if run-message != RUN-TEST:
throw"RUN-SIGNAL MISMATCH"
return
reader.close
socket.close
server-socket.close
network.close
print "INSTALLED CONTAINER"

run-test:
print "RUNNING INSTALLED CONTAINER"
Expand Down
1 change: 1 addition & 0 deletions tests/hw/esp-tester/shared.toit
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
// be found in the tests/LICENSE file.
MINI-JAG-LISTENING ::= "MINI-JAG LISTENING"
RUN-TEST ::= "RUN TEST"
63 changes: 50 additions & 13 deletions tests/hw/esp-tester/tester.toit
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import crypto.crc
import fs
import host.directory
import host.file
import host.os
import host.pipe
import monitor
import net
import net.tcp
import system
import uart
import .shared
Expand Down Expand Up @@ -107,11 +109,22 @@ run-test invocation/cli.Invocation:
board2/TestDevice? := null

try:
board1.run-test test-path
board1-ready := monitor.Latch

task::
board1.connect-network
board1.install-test test-path
board1-ready.set true

if port-board2:
board2 = TestDevice --name="board2" --port-path=port-board2 --ui=ui --toit-exe=toit-exe
board2.run-test test2-path
board2.connect-network
board2.install-test test2-path

board1-ready.get
board1.run-test
if port-board2:
board2.run-test

ui.emit --verbose "Waiting for all tests to be done"
board1.all-tests-done.get
Expand All @@ -134,17 +147,29 @@ class TestDevice:
ui/cli.Ui
tmp-dir/string

network_/net.Client? := null
socket_/tcp.Socket? := null

constructor --.name --.toit-exe --port-path/string --.ui:
port = uart.HostPort port-path --baud-rate=115200
tmp-dir = directory.mkdtemp "/tmp/esp-tester"
read-task = task --background::
try:
reader := port.in
stdout := pipe.stdout
at-new-line := true
while data/ByteArray? := reader.read:
if not is-active: continue
stdout.write data
collected-output += data.to-string-non-throwing
data-str := data.to-string-non-throwing
if at-new-line: data-str = "\n$data-str"
if data-str.ends-with "\n":
at-new-line = true
data-str = data-str[.. data-str.size - 1]
else:
at-new-line = false
std-out := data-str.replace --all "\n" "\n$name: "
stdout.write std-out
collected-output += data-str
if not ready-latch.has-value and collected-output.contains "\n$MINI-JAG-LISTENING":
ready-latch.set true
if not all-tests-done.has-value and collected-output.contains ALL-TESTS-DONE:
Expand Down Expand Up @@ -173,11 +198,12 @@ class TestDevice:
read-task.cancel
if file.is-directory tmp-dir:
directory.rmdir --recursive tmp-dir
disconnect-network

toit_ args/List:
run-toit toit-exe args --ui=ui

run-test test-path:
connect-network:
// Reset the device.
ui.emit --verbose "Resetting $name"
port.set-control-flag uart.HostPort.CONTROL-FLAG-DTR false
Expand All @@ -194,8 +220,18 @@ class TestDevice:
lines.map --in-place: it.trim
listening-line-index := lines.index-of --last MINI-JAG-LISTENING
host-port-line := lines[listening-line-index - 1]
ui.emit --info "Running test on $host-port-line"
parts := host-port-line.split ":"
network_ = net.open
socket_ = network_.tcp-connect parts[0] (int.parse parts[1])
ui.emit --info "Connected to $host-port-line"

disconnect-network:
if socket_: socket_.close
socket_ = null
if network_: network_.close
network_ = null

install-test test-path:
snapshot-path := "$tmp-dir/$SNAPSHOT-NAME"
toit_ [
"compile",
Expand All @@ -215,17 +251,18 @@ class TestDevice:
]
image := file.read-contents image-path

network := net.open
parts := host-port-line.split ":"
socket := network.tcp-connect parts[0] (int.parse parts[1])
socket.out.little-endian.write-int32 image.size
socket_.out.little-endian.write-int32 image.size
summer := crc.Crc32
summer.add image
socket.out.write summer.get
socket.out.write image
socket.close
socket_.out.write summer.get
socket_.out.write image

run-test -> none:
socket_.out.write RUN-TEST

setup-tester invocation/cli.Invocation:
if os.env.get "TOIT_SKIP_SETUP": return

ui := invocation.cli.ui
toit-exe := invocation["toit-exe"]
port-path := invocation["port"]
Expand Down

0 comments on commit 2e45dfa

Please sign in to comment.