test 1.97 KB
Newer Older
1 2 3 4
#!/usr/bin/env python3

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


16 17 18 19 20 21 22 23 24
def get_serial():
    ports = serial.tools.list_ports.comports()
    devices = [
        p.device
        for p in ports
        if (p.vid == 4292 and p.pid == 60000)
    ]
    devices.sort()
    return devices[0]
25 26


27
class ESP32(DeviceUnderTestAeadUARTP):
28

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

32 33 34
        self.uart_device = get_serial()
        devname = os.path.basename(self.uart_device)
        self.lock = FileMutex('/var/lock/lwc-compare.%s.lock' % devname)
35 36
        self.build_dir = build_dir

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    def reset(self):
        self.ser.setDTR(False)  # IO0=HIGH
        self.ser.setRTS(True)   # EN=LOW, chip in reset
        time.sleep(0.1)
        self.ser.setDTR(False)  # IO0=HIGH
        self.ser.setRTS(False)  # EN=HIGH, chip out of reset
        time.sleep(1)

    def prepare(self):
        self.ser = serial.Serial(
            self.uart_device,
            baudrate=500000,
            timeout=5)
        self.reset()
        DeviceUnderTestAeadUARTP.prepare(self)

53 54 55 56 57
    def flash(self):
        pipe = subprocess.PIPE
        previous_dir = os.path.abspath(os.curdir)
        os.chdir(self.build_dir)
        cmd = ['platformio', 'run', '-e', 'esp32dev', '--target', 'upload']
58
        cmd.extend(['--upload-port', self.uart_device])
59 60 61
        p = subprocess.Popen(
            cmd, stdout=sys.stderr, stdin=pipe)
        stdout, stderr = p.communicate("")
62
        assert p.returncode == 0
63 64 65 66 67
        eprint("Firmware flashed.")
        os.chdir(previous_dir)

    def dump_ram(self):
        return None
68 69 70


def main(argv):
71 72
    if len(argv) != 3:
        print("Usage: test LWC_AEAD_KAT.txt build_dir")
73
        return 1
74

lwc-tester committed
75 76
    run_nist_lws_aead_test(argv[1], argv[2], 0x0020, ESP32)
    return 0
77

78 79 80

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