1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-26 16:18:22 +00:00

build: when running test, wait until emulator starts properly

This commit is contained in:
matejcik 2018-08-14 14:59:31 +02:00
parent 9a519fb5c0
commit bdbabf5594
2 changed files with 32 additions and 0 deletions

View File

@ -12,6 +12,7 @@ if [ "$EMULATOR" = 1 ]; then
firmware/trezor.elf &
sleep 1
export TREZOR_PATH=udp:127.0.0.1:21324
"${PYTHON:-python}" script/wait_for_emulator.py
fi
export TREZOR_TRANSPORT_V1=1

31
script/wait_for_emulator.py Executable file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python3
import socket
import sys
import time
DEFAULT_ADDR = "127.0.0.1:21324"
if len(sys.argv) > 1:
addr = sys.argv[1]
else:
addr = DEFAULT_ADDR
host, port = addr.split(":")
SOCK_ADDR = (host, int(port))
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect(SOCK_ADDR)
sock.settimeout(0)
start = time.monotonic()
while True:
try:
sock.sendall(b"PINGPING")
r = sock.recv(8)
if r == b"PONGPONG":
break
except Exception:
time.sleep(0.05)
end = time.monotonic()
print("waited for {:.3f}s".format(end - start))