test 1.95 KB
Newer Older
Enrico Pozzobon committed
1 2 3 4 5 6 7
#!/usr/bin/env python3

import os
import sys
import time
import struct
import serial
8 9 10 11 12 13 14 15
import pylink
sys.path.insert(0, '.')
from test_common import (
    SaleaeTimeMeasurements,
    parse_nist_aead_test_vectors,
    DeviceUnderTestAeadUARTP,
    run_nist_aead_test,
)
Enrico Pozzobon committed
16 17 18 19 20 21


def eprint(*args, **kargs):
    print(*args, file=sys.stderr, **kargs)


22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
def get_serial():
    import serial.tools.list_ports
    ports = serial.tools.list_ports.comports()
    for port in ports:
        print(port.serial_number)
    devices = [
        p.device
        for p in ports
        if p.serial_number == 'FT2XA9MY'
    ]
    devices.sort()
    return serial.Serial(
        devices[0],
        baudrate=115200,
        timeout=5)
37 38


39 40 41 42 43 44
class F7(DeviceUnderTestAeadUARTP):
    RAM_SIZE = 0x50000
    def __init__(self):
        DeviceUnderTestAeadUARTP.__init__(self, get_serial())
        self.jlink = pylink.JLink()
        self.jlink.open(779340002)
45 46


47 48 49 50 51 52 53
    def flash(self):
        jlink = self.jlink
        jlink.connect('STM32F746ZG')
        jlink.flash_file('build/f7.bin', 0x8000000)
        jlink.flash_file('ram_pattern.bin', 0x20000000)
        jlink.reset()
        jlink.restart()
54

55 56 57
    def dump_ram(self):
        jlink = self.jlink
        return bytes(jlink.memory_read8(0x20000000, F7.RAM_SIZE))
58

Enrico Pozzobon committed
59

60 61 62
def main(argv):
    if len(argv) < 2:
        print("Usage: test LWC_AEAD_KAT.txt")
Enrico Pozzobon committed
63

64
    kat = list(parse_nist_aead_test_vectors(argv[1]))
65

Enrico Pozzobon committed
66 67 68 69 70
    eprint(argv[0])
    script_dir = os.path.split(argv[0])[0]
    if len(script_dir) > 0:
        os.chdir(script_dir)

71
    dut = F7()
Enrico Pozzobon committed
72

73
    dut.flash()
Enrico Pozzobon committed
74
    eprint("Flashed")
75
    dut.prepare()
Enrico Pozzobon committed
76 77 78 79
    eprint("Board initialized properly")
    sys.stdout.write("Hello, World!\n")
    sys.stdout.flush()

80 81 82 83 84 85 86 87 88 89 90
    try:
        run_nist_aead_test(dut, kat)
        return 0

    except Exception as ex:
        print("TEST FAILED")
        raise ex

    finally:
        sys.stdout.flush()
        sys.stderr.flush()
Enrico Pozzobon committed
91 92 93 94


if __name__ == "__main__":
    sys.exit(main(sys.argv))