-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
executable file
·85 lines (74 loc) · 2.72 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
80
81
82
83
84
85
#!/usr/bin/env python3
import datetime
import subprocess
import sys
import serial
import numpy as np
from config import Settings
import os.path
def run_test(scheme_path, scheme_name):
subprocess.check_call(f"make clean", shell=True)
subprocess.check_call(f"make -j 12 IMPLEMENTATION_PATH={scheme_path} bin/{scheme_name}_test.bin", shell=True)
binary = f"bin/{scheme_name}_test.bin"
print(binary)
if os.path.isfile(binary) is False:
print("Binary does not exist")
exit()
try:
subprocess.check_call(f"st-flash --reset write {binary} 0x8000000", shell=True)
except:
print("st-flash failed --> retry")
subprocess.check_call(
f"st-flash erase && st-flash reset", shell=True)
return run_test(scheme_path, scheme_name)
# get serial output and wait for '#'
with serial.Serial(Settings.SERIAL_DEVICE, 115200, timeout=10) as dev:
logs = b""
log = b""
device_output = b''
while device_output != b'#':
device_output = dev.read()
if device_output == b'':
print("timeout --> retry")
return run_test(scheme_path, scheme_name)
log += device_output
if device_output == b'#':
logs += (log)
log = b""
return logs
def test(scheme_path, scheme_name, ignoreErrors=False):
logs = run_test(scheme_path, scheme_name)
print(logs)
if (logs.decode("utf-8")).count("OK") == 30:
print("Success!")
else:
print("Failure! Did not receive 30 OKs")
now = datetime.datetime.now(datetime.timezone.utc)
print(f"% Testing implementation(s) {now}\n")
# uncomment the scheme variants that should be build and evaluated
for scheme_path in [
# "crypto_kem/kyber512/old",
# "crypto_kem/kyber512/m4fstack",
# "crypto_kem/kyber512/m4fspeed",
# "crypto_kem/kyber512-90s/m4fstack",
# "crypto_kem/kyber512-90s/m4fspeed",
# "crypto_kem/kyber768/old",
# "crypto_kem/kyber768/m4fstack",
# "crypto_kem/kyber768/m4fspeed",
# "crypto_kem/kyber768-90s/m4fstack",
# "crypto_kem/kyber768-90s/m4fspeed",
# "crypto_kem/kyber1024/old",
# "crypto_kem/kyber1024/m4fstack",
# "crypto_kem/kyber1024/m4fspeed",
# "crypto_kem/kyber1024-90s/m4fstack",
# "crypto_kem/kyber1024-90s/m4fspeed",
# "crypto_kem/nttru",
# "crypto_sign/dilithium2/old",
"crypto_sign/dilithium2/new",
# "crypto_sign/dilithium3/old",
# "crypto_sign/dilithium3/new",
# "crypto_sign/dilithium5/old",
# "crypto_sign/dilithium5/new"
]:
scheme_name = scheme_path.replace("/", "_")
test(scheme_path, scheme_name)