From 26c472440ef6169d186e9c15382d85c836f124d9 Mon Sep 17 00:00:00 2001 From: lwc-tester Date: Mon, 2 Mar 2020 13:54:42 +0100 Subject: [PATCH] save results as pickle - maybe too big? --- test_common.py | 79 +++++++++++++++++++++---------------------------------------------------------- 1 file changed, 21 insertions(+), 58 deletions(-) diff --git a/test_common.py b/test_common.py index 03c061b..d73e436 100644 --- a/test_common.py +++ b/test_common.py @@ -5,8 +5,8 @@ import re import sys import time import fcntl +import pickle import struct -import serial import socket import subprocess @@ -35,6 +35,7 @@ class DeviceUnderTest: class DeviceUnderTestAeadUARTP(DeviceUnderTest): def __init__(self, ser=None): self.ser = ser + self.firmware_path = None def prepare(self): exp_hello = b"Hello, World!" @@ -450,20 +451,27 @@ class OpenOcd: def run_nist_lws_aead_test(vectors_file, build_dir, logic_mask=0xffff, - basecls=DeviceUnderTestAeadUARTP): + basecls=DeviceUnderTestAeadUARTP, + results_path=None): + results = {} + kat = list(parse_nist_aead_test_vectors(vectors_file)) + results['test_vectors'] = kat dut = basecls(build_dir) + fw_path = dut.firmware_path + if fw_path is not None: + with open(fw_path, 'rb') as fw_file: + firmware = fw_file.read() + results['firmware'] = (fw_path, os.stat(fw_path), firmware) + dut.flash() dut.prepare() sys.stdout.write("Board prepared\n") sys.stdout.flush() dump_a = dut.dump_ram() - time_dips = None - ram_utilization = None - rom_utilization = None try: tool = LogicMultiplexerTimeMeasurements(logic_mask) @@ -476,11 +484,9 @@ def run_nist_lws_aead_test(vectors_file, build_dir, if i == 1 and dump_a is not None: dump_b = dut.dump_ram() + results['ram_dumps'] = [dump_a, dump_b] longest = compare_dumps(dump_a, dump_b) print(" longest chunk of untouched memory = %d" % longest) - ram_utilization = longest - - time_dips = tool.capture except Exception as ex: print("TEST FAILED") @@ -489,55 +495,12 @@ def run_nist_lws_aead_test(vectors_file, build_dir, finally: tool.end_measurement() - return time_dips, ram_utilization, rom_utilization - - -def main(argv): - if len(argv) < 3: - print("Usage: test_common.py port LWC_AEAD_KAT.txt") - - eprint(argv[0]) - script_dir = os.path.split(argv[0])[0] - if len(script_dir) > 0: - os.chdir(script_dir) - - kat = list(parse_nist_aead_test_vectors(argv[2])) - - dev = argv[1] - ser = serial.Serial(dev, baudrate=115200, timeout=5) - dut = DeviceUnderTestAeadUARTP(ser) - - try: - tool = SaleaeTimeMeasurements() - tool.begin_measurement() - dut.flash() - eprint("Flashed") - dut.prepare() - eprint("Prepared") - sys.stdout.write("Hello, World!\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 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) - - except Exception as ex: - print("TEST FAILED") - raise ex - - finally: - tool.end_measurement() - sys.stdout.flush() - sys.stderr.flush() + results['time_dips'] = tool.capture + if results_path is None: + results_path = os.path.join(build_dir, 'results.pickle') + if results_path is not False: + with open(results_path, 'wb') as f: + pickle.dump(results, f, pickle.HIGHEST_PROTOCOL) -if __name__ == "__main__": - sys.exit(main(sys.argv)) + return results -- libgit2 0.26.0