Commit 8af9d9f6 by Enrico Pozzobon

moved some reused code in test_common.py

parent a5fb9cb2
......@@ -6,6 +6,7 @@ import serial.tools.list_ports
from test_common import (
DeviceUnderTestAeadUARTP,
eprint,
test_main,
OpenOcd,
FileMutex,
run_nist_lws_aead_test
......@@ -110,18 +111,5 @@ class BluePill(DeviceUnderTestAeadUARTP):
return ram
def main(argv):
if len(argv) != 2:
print("Usage: test build_dir")
return 1
build_dir = argv[1]
kat_path = os.path.join(build_dir, 'LWC_AEAD_KAT.txt')
dut = BluePill(build_dir)
run_nist_lws_aead_test(dut, kat_path, build_dir, 0x0002)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))
sys.exit(test_main(BluePill, 0x0002, sys.argv))
......@@ -8,6 +8,7 @@ import serial.tools.list_ports
from test_common import (
DeviceUnderTestAeadUARTP,
eprint,
test_main,
FileMutex,
run_nist_lws_aead_test,
)
......@@ -97,18 +98,5 @@ class ESP32(DeviceUnderTestAeadUARTP):
return None
def main(argv):
if len(argv) != 2:
print("Usage: test build_dir")
return 1
build_dir = argv[1]
kat_path = os.path.join(build_dir, 'LWC_AEAD_KAT.txt')
dut = ESP32(build_dir)
run_nist_lws_aead_test(dut, kat_path, build_dir, 0x0020)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))
sys.exit(test_main(ESP32, 0x0020, sys.argv))
......@@ -6,6 +6,7 @@ import serial.tools.list_ports
from test_common import (
DeviceUnderTestAeadUARTP,
eprint,
test_main,
OpenOcd,
FileMutex,
run_nist_lws_aead_test
......@@ -110,18 +111,5 @@ class BluePill(DeviceUnderTestAeadUARTP):
return ram
def main(argv):
if len(argv) != 2:
print("Usage: test build_dir")
return 1
build_dir = argv[1]
kat_path = os.path.join(build_dir, 'LWC_AEAD_KAT.txt')
dut = BluePill(build_dir)
run_nist_lws_aead_test(dut, kat_path, build_dir, 0x0002)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))
sys.exit(test_main(BluePill, 0x0002, sys.argv))
......@@ -7,6 +7,7 @@ import serial.tools.list_ports
from test_common import (
DeviceUnderTestAeadUARTP,
eprint,
test_main,
FileMutex,
run_nist_lws_aead_test,
)
......@@ -65,18 +66,5 @@ class F7(DeviceUnderTestAeadUARTP):
return bytes(jlink.memory_read8(0x20000000, F7.RAM_SIZE))
def main(argv):
if len(argv) != 2:
print("Usage: test build_dir")
return 1
build_dir = argv[1]
kat_path = os.path.join(build_dir, 'LWC_AEAD_KAT.txt')
dut = F7(build_dir)
run_nist_lws_aead_test(dut, kat_path, build_dir, 0x0008)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))
sys.exit(test_main(F7, 0x0008, sys.argv))
......@@ -9,6 +9,7 @@ from test_common import (
DeviceUnderTestAeadUARTP,
FileMutex,
eprint,
test_main,
run_nist_lws_aead_test,
)
......@@ -78,18 +79,5 @@ class Maixduino(DeviceUnderTestAeadUARTP):
return None
def main(argv):
if len(argv) != 2:
print("Usage: test build_dir")
return 1
build_dir = argv[1]
kat_path = os.path.join(build_dir, 'LWC_AEAD_KAT.txt')
dut = Maixduino(build_dir)
run_nist_lws_aead_test(dut, kat_path, build_dir, 0x0080)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))
sys.exit(test_main(Maixduino, 0x0080, sys.argv))
......@@ -9,6 +9,7 @@ import serial.tools.list_ports
from test_common import (
DeviceUnderTestAeadUARTP,
eprint,
test_main,
FileMutex,
run_nist_lws_aead_test,
)
......@@ -95,18 +96,5 @@ class Uno(DeviceUnderTestAeadUARTP):
return None
def main(argv):
if len(argv) != 2:
print("Usage: test build_dir")
return 1
build_dir = argv[1]
kat_path = os.path.join(build_dir, 'LWC_AEAD_KAT.txt')
dut = Uno(build_dir)
run_nist_lws_aead_test(dut, kat_path, build_dir, 0x0800)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))
sys.exit(test_main(Uno, 0x0800, sys.argv))
......@@ -730,3 +730,46 @@ def run_nist_lws_aead_test(dut, vectors_file, build_dir,
print("TIME,VALUE", file=f)
for t, v in logic_trace:
print("%.10f,0x%x" % (t, v), file=f)
def test_main(dut_ctor, logic_mux_mask, argv):
if len(argv) != 2:
print("Usage: test build_dir")
return 1
build_dir = argv[1]
kat_path = os.path.join(build_dir, 'LWC_AEAD_KAT.txt')
dut = dut_ctor(build_dir)
run_nist_lws_aead_test(dut, kat_path, build_dir, logic_mux_mask)
return 0
if __name__ == '__main__':
import serial
import argparse
# Parse the arguments
argparser = argparse.ArgumentParser(
description='Execute a single test over UART - useful for debugging')
argparser.add_argument('-t', '--tty', required=True)
argparser.add_argument('-b', '--baud', default=115200)
argparser.add_argument('-m', '--message', required=True)
argparser.add_argument('-a', '--ad', default="")
argparser.add_argument('-k', '--key', required=True)
argparser.add_argument('-n', '--nonce', required=True)
argparser.add_argument('-c', '--ciphertext', default=None)
args = argparser.parse_args(sys.argv[1:])
ser = serial.Serial(args.tty, args.baud, timeout=1)
dut = DeviceUnderTestAeadUARTP(ser)
dut.uartp = UARTP(ser)
run_nist_aead_test_line(
dut, 0,
bytes.fromhex(args.message),
bytes.fromhex(args.ad),
bytes.fromhex(args.key),
bytes.fromhex(args.nonce),
bytes.fromhex(args.ciphertext) if args.ciphertext is not None
else None)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment