test 1.99 KB
Newer Older
Enrico Pozzobon committed
1 2 3 4
#!/usr/bin/env python3

import os
import sys
5
import pylink
6
import serial.tools.list_ports
7 8
from test_common import (
    DeviceUnderTestAeadUARTP,
lwc-tester committed
9
    eprint,
10
    FileMutex,
lwc-tester committed
11
    run_nist_lws_aead_test,
12
)
Enrico Pozzobon committed
13 14


15 16 17 18 19
def get_serial():
    ports = serial.tools.list_ports.comports()
    devices = [
        p.device
        for p in ports
lwc-tester committed
20
        if p.serial_number == '00000000'
21 22
    ]
    devices.sort()
23
    return devices[0]
24 25


26 27
class F7(DeviceUnderTestAeadUARTP):
    RAM_SIZE = 0x50000
lwc-tester committed
28

29 30 31 32 33
    def __init__(self, build_dir):
        DeviceUnderTestAeadUARTP.__init__(self)

        self.uart_device = get_serial()
        devname = os.path.basename(self.uart_device)
34 35 36 37
        self.ser = serial.Serial(
            self.uart_device,
            baudrate=115200,
            timeout=5)
38 39
        self.lock = FileMutex('/var/lock/lwc-compare.%s.lock' % devname)
        self.build_dir = build_dir
lwc-tester committed
40
        self.template_path = os.path.dirname(sys.argv[0])
41

42 43
        self.jlink = pylink.JLink()
        self.jlink.open(779340002)
44

lwc-tester committed
45 46 47 48
        self.firmware_path = os.path.join(
            build_dir, 'f7.bin')
        self.ram_pattern_path = os.path.join(
            self.template_path, 'ram_pattern.bin')
49

50 51 52
    def firmware_size(self):
        return os.stat(self.firmware_path).st_size

53 54 55
    def flash(self):
        jlink = self.jlink
        jlink.connect('STM32F746ZG')
lwc-tester committed
56 57 58 59
        jlink.flash_file(self.firmware_path, 0x8000000)
        eprint("Firmware flashed.")
        jlink.flash_file(self.ram_pattern_path, 0x20000000)
        eprint("RAM flashed.")
60 61
        jlink.reset()
        jlink.restart()
62

63 64 65
    def dump_ram(self):
        jlink = self.jlink
        return bytes(jlink.memory_read8(0x20000000, F7.RAM_SIZE))
66

Enrico Pozzobon committed
67

68
def main(argv):
lwc-tester committed
69 70
    if len(argv) != 2:
        print("Usage: test build_dir")
71
        return 1
Enrico Pozzobon committed
72

lwc-tester committed
73 74 75
    build_dir = argv[1]
    kat_path = os.path.join(build_dir, 'LWC_AEAD_KAT.txt')

76 77
    dut = F7(build_dir)
    run_nist_lws_aead_test(dut, kat_path, build_dir, 0x0008)
lwc-tester committed
78
    return 0
Enrico Pozzobon committed
79 80 81 82


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