mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-24 15:28:10 +00:00
tests: add production test
This commit is contained in:
parent
a67be06349
commit
81deb66f29
154
tests/production_tests/main.py
Normal file
154
tests/production_tests/main.py
Normal file
@ -0,0 +1,154 @@
|
||||
import utime
|
||||
|
||||
from trezor import io
|
||||
from trezor import ui
|
||||
|
||||
usb_vcp = io.VCP(
|
||||
iface_num=0x00,
|
||||
data_iface_num=0x01,
|
||||
ep_in=0x81,
|
||||
ep_out=0x01,
|
||||
ep_cmd=0x82,
|
||||
)
|
||||
|
||||
usb = io.USB(
|
||||
vendor_id=0x1209,
|
||||
product_id=0x53C1,
|
||||
release_num=0x0002,
|
||||
manufacturer="SatoshiLabs",
|
||||
product="TREZOR",
|
||||
serial_number="000000000000000000000000",
|
||||
)
|
||||
|
||||
usb.add(usb_vcp)
|
||||
|
||||
usb.open()
|
||||
|
||||
d = ui.display
|
||||
sd = io.SDCard()
|
||||
sbu = io.SBU()
|
||||
|
||||
|
||||
def test_display(colors):
|
||||
d.clear()
|
||||
m = {
|
||||
'R': 0xF800,
|
||||
'G': 0x07E0,
|
||||
'B': 0x001F,
|
||||
'W': 0xFFFF,
|
||||
}
|
||||
w = 240 // len(colors)
|
||||
for i, c in enumerate(colors):
|
||||
c = m.get(c, 0x0000)
|
||||
d.bar(i * w, 0, i * w + w, 240, c)
|
||||
d.refresh()
|
||||
print('OK')
|
||||
|
||||
|
||||
def test_touch(v):
|
||||
d.clear()
|
||||
c, t = int(v[0]), int(v[1])
|
||||
deadline = utime.ticks_add(utime.ticks_us(), t * 1000000)
|
||||
if c == 1:
|
||||
d.bar(0, 0, 120, 120, 0xFFFF)
|
||||
elif c == 2:
|
||||
d.bar(120, 0, 120, 120, 0xFFFF)
|
||||
elif c == 3:
|
||||
d.bar(120, 120, 120, 120, 0xFFFF)
|
||||
else:
|
||||
d.bar(0, 120, 120, 120, 0xFFFF)
|
||||
d.refresh()
|
||||
r = [0, 0]
|
||||
# flush all events
|
||||
while io.poll([io.TOUCH], r, 10000):
|
||||
pass
|
||||
# wait for event
|
||||
while True:
|
||||
if io.poll([io.TOUCH], r, 10000) and r[0] == io.TOUCH and r[1][0] == io.TOUCH_END:
|
||||
print('OK %d %d' % (r[1][1], r[1][2]))
|
||||
break
|
||||
if utime.ticks_us() > deadline:
|
||||
print('ERROR TIMEOUT')
|
||||
break
|
||||
# flush all events
|
||||
while io.poll([io.TOUCH], r, 10000):
|
||||
pass
|
||||
d.clear()
|
||||
d.refresh()
|
||||
|
||||
|
||||
def test_pwm(v):
|
||||
d.backlight(int(v))
|
||||
d.refresh()
|
||||
print('OK')
|
||||
|
||||
|
||||
def test_sd():
|
||||
if sd.present():
|
||||
sd.power(True)
|
||||
buf1 = bytearray(8 * 1024)
|
||||
sd.read(0, buf1)
|
||||
sd.write(0, buf1)
|
||||
buf2 = bytearray(8 * 1024)
|
||||
sd.read(0, buf2)
|
||||
if buf1 == buf2:
|
||||
print('OK')
|
||||
else:
|
||||
print('ERROR DATA MISMATCH')
|
||||
sd.power(False)
|
||||
else:
|
||||
print('ERROR NOCARD')
|
||||
|
||||
|
||||
def test_sbu(v):
|
||||
sbu1 = (v[0] == '1')
|
||||
sbu2 = (v[1] == '1')
|
||||
sbu.set(sbu1, sbu2)
|
||||
print('OK')
|
||||
|
||||
|
||||
def test_otp_read(v):
|
||||
# FIXME: really read
|
||||
otp = '00000'
|
||||
print('OK', otp)
|
||||
|
||||
|
||||
def test_otp_write(v):
|
||||
# FIXME: really write
|
||||
print('OK')
|
||||
|
||||
|
||||
while True:
|
||||
|
||||
try:
|
||||
line = input()
|
||||
|
||||
if line == 'PING':
|
||||
print('OK')
|
||||
|
||||
elif line.startswith('DISP '):
|
||||
test_display(line[5:])
|
||||
|
||||
elif line.startswith('TOUCH '):
|
||||
test_touch(line[6:])
|
||||
|
||||
elif line.startswith('PWM '):
|
||||
test_pwm(line[4:])
|
||||
|
||||
elif line == 'SD':
|
||||
test_sd()
|
||||
|
||||
elif line.startswith('SBU '):
|
||||
test_sbu(line[4:])
|
||||
|
||||
elif line.startswith('OTP READ'):
|
||||
test_otp_read(line[8:])
|
||||
|
||||
elif line.startswith('OTP WRITE '):
|
||||
test_otp_write(line[10:])
|
||||
|
||||
else:
|
||||
print('UNKNOWN')
|
||||
|
||||
except Exception as ex:
|
||||
print('ERROR', ex)
|
Loading…
Reference in New Issue
Block a user