-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·79 lines (64 loc) · 2.18 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
import serial
import sys
import os
import subprocess
from utils import m4ignore
dev = serial.Serial("/dev/ttyUSB0", 115200, timeout=10)
try:
binaries = [x for x in os.listdir('bin') if 'test.bin' in x]
except FileNotFoundError:
print("There is no bin/ folder. Please first make binaries.")
sys.exit(1)
def doTest(binary):
binpath = os.path.join("bin", binary)
info = binary.split('_')
primitive = '_'.join(info[:2])
scheme = '_'.join(info[2:-2])
implementation = info[-2]
if m4ignore(primitive, scheme, implementation):
return
if len(sys.argv) > 1 and scheme not in sys.argv[1:]:
return
print("Flashing {}..".format(binpath))
subprocess.run(["st-flash", "write", binpath, "0x8000000"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
print("Flashed, now running tests...")
state = 'waiting'
marker = b''
# This parses test vector output starting with a number of leading '=',
# and expects a hashtag '#' after the test vector output.
while True:
x = dev.read()
if x == b'' and state == 'waiting':
print("timed out while waiting for the markers")
doTest(binary)
return
if state == 'waiting':
if x == b'=':
marker += x
continue
# If we saw at least 5 equal signs, assume we've probably started
elif marker.count(b'=') > 5:
state = 'beginning'
vector = []
print(" .. found output marker..")
if state == 'beginning':
if x == b'=':
continue
else:
state = 'reading'
elif state == 'reading':
if x == b'#':
break
else:
vector.append(x)
print("Testing if tests were successful..")
contents = b''.join(vector).decode('utf-8').strip()
# can we find a nicer way of checking if tests ran correctly?
if contents.count("ERROR") != 0 or contents.count("OK") != 30:
print("FAILED!")
else:
print("passed.")
for binary in binaries:
doTest(binary)