From d0f51b64da58ec883a250e4617ab7ed43e71dfcf Mon Sep 17 00:00:00 2001 From: lwc-tester Date: Thu, 20 Feb 2020 13:29:09 +0100 Subject: [PATCH] new f7 test --- templates/f7/test | 61 +++++++++++++++++++++++++++++++++++-------------------------- test_common.py | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- 2 files changed, 122 insertions(+), 58 deletions(-) diff --git a/templates/f7/test b/templates/f7/test index 486a1aa..dad42d8 100755 --- a/templates/f7/test +++ b/templates/f7/test @@ -2,23 +2,17 @@ import os import sys -import time -import struct -import serial import pylink -sys.path.insert(0, '.') from test_common import ( - SaleaeTimeMeasurements, + LogicMultiplexerTimeMeasurements, parse_nist_aead_test_vectors, DeviceUnderTestAeadUARTP, - run_nist_aead_test, + compare_dumps, + eprint, + run_nist_aead_test_line, ) -def eprint(*args, **kargs): - print(*args, file=sys.stderr, **kargs) - - def get_serial(): import serial.tools.list_ports ports = serial.tools.list_ports.comports() @@ -38,17 +32,21 @@ def get_serial(): class F7(DeviceUnderTestAeadUARTP): RAM_SIZE = 0x50000 - def __init__(self): + + def __init__(self, firmware_path, ram_pattern_path): DeviceUnderTestAeadUARTP.__init__(self, get_serial()) self.jlink = pylink.JLink() self.jlink.open(779340002) - + self.firmware_path = firmware_path + self.ram_pattern_path = ram_pattern_path def flash(self): jlink = self.jlink jlink.connect('STM32F746ZG') - jlink.flash_file('build/f7.bin', 0x8000000) - jlink.flash_file('ram_pattern.bin', 0x20000000) + jlink.flash_file(self.firmware_path, 0x8000000) + eprint("Firmware flashed.") + jlink.flash_file(self.ram_pattern_path, 0x20000000) + eprint("RAM flashed.") jlink.reset() jlink.restart() @@ -65,27 +63,38 @@ def main(argv): eprint(argv[0]) script_dir = os.path.split(argv[0])[0] - if len(script_dir) > 0: - os.chdir(script_dir) - - dut = F7() - dut.flash() - eprint("Flashed") - dut.prepare() - eprint("Board initialized properly") - sys.stdout.write("Hello, World!\n") - sys.stdout.flush() + dut = F7( + os.path.join(script_dir, 'build', 'f7.bin'), + os.path.join(script_dir, 'ram_pattern.bin')) try: - run_nist_aead_test(dut, kat) - return 0 + tool = LogicMultiplexerTimeMeasurements(0x000c) + tool.begin_measurement() + + dut.flash() + dut.prepare() + sys.stdout.write("Board prepared\n") + sys.stdout.flush() + + dump_a = dut.dump_ram() + + for i, m, ad, k, npub, c in kat: + tool.arm() + run_nist_aead_test_line(dut, i, m, ad, k, npub, c) + tool.unarm() + + if i == 1: + dump_b = dut.dump_ram() + longest = compare_dumps(dump_a, dump_b) + print(" longest chunk of untouched memory = %d" % longest) except Exception as ex: print("TEST FAILED") raise ex finally: + tool.end_measurement() sys.stdout.flush() sys.stderr.flush() diff --git a/test_common.py b/test_common.py index 775a9fc..d20b58f 100644 --- a/test_common.py +++ b/test_common.py @@ -141,23 +141,6 @@ class UARTP: return buf -def run_nist_aead_test(dut, kat): - dump_a = dut.dump_ram() - - tool = SaleaeTimeMeasurements() - tool.begin_measurement() - try: - for i, m, ad, k, npub, c in kat: - run_nist_aead_test_line(dut, i, m, ad, k, npub, c) - - if dump_a is not None and i == 1: - dump_b = dut.dump_ram() - longest = compare_dumps(dump_a, dump_b) - print(" longest chunk of untouched memory = %d" % longest) - finally: - tool.end_measurement() - - def run_nist_aead_test_line(dut, i, m, ad, k, npub, c): eprint() eprint("Count = %d" % i) @@ -268,12 +251,75 @@ def parse_nist_aead_test_vectors(test_file_path): "ERROR: unparsed line in test vectors file: '%s'" % line) -class SaleaeTimeMeasurements: +class TimeMeasurementTool: + def begin_measurement(self): + pass + + def arm(self): + pass + + def unarm(self): + pass + + def end_measurement(self): + pass + + +class LogicMultiplexerTimeMeasurements(TimeMeasurementTool): + + def __init__(self, mask=0xffffffffffffffff): + self.mask = mask + self.sock = None + self.capture = [] + + def recv_samples(self): + import socket + + capture = [] + while 1: + try: + rcvd = self.sock.recv(16) + except socket.timeout: + break + except BlockingIOError: + break + if len(rcvd) != 16: + raise Exception("Could not receive 16 bytes of logic sample!") + + time, value = struct.unpack("