From 0de38c2a6fa5c9fef8e03ac98717e069fe2f9c0c Mon Sep 17 00:00:00 2001 From: PeterKietzmann Date: Wed, 14 Nov 2018 11:04:19 +0100 Subject: [PATCH] tests/puf_sram: add input args to automation script --- tests/puf_sram/tests/example_test.py | 25 +++++++++++++++++++++++-- tests/puf_sram/tests/puf_sram_if.py | 6 +++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/tests/puf_sram/tests/example_test.py b/tests/puf_sram/tests/example_test.py index c932608076ff..ef94a0acb899 100644 --- a/tests/puf_sram/tests/example_test.py +++ b/tests/puf_sram/tests/example_test.py @@ -7,9 +7,16 @@ # General Public License v2.1. See the file LICENSE in the top level # directory for more details. +import argparse import puf_sram_if import numpy +DEFAULT_POWER_CYCLES = 500 +DEFAULT_OFF_TIME = 1 +DEFAULT_BAUDRATE = 115200 +DEFAULT_PORT = '/dev/ttyUSB0' +DEFAULT_INFO = True + def min_erntropy(all_meas): p1 = numpy.zeros(len(all_meas[0])) @@ -32,8 +39,22 @@ def min_erntropy(all_meas): def main_func(): - puf_sram = puf_sram_if.PufSram() - seeds = puf_sram.get_seed_list(n=500, off_time=1, allow_print=True) + p = argparse.ArgumentParser() + p.add_argument("-n", "--number", type=int, default=DEFAULT_POWER_CYCLES, + help="Number of iterations, default: %s" % DEFAULT_POWER_CYCLES) + p.add_argument("-t", "--off_time", type=int, default=DEFAULT_OFF_TIME, + help="Off time, default: %s [s]" % DEFAULT_OFF_TIME) + p.add_argument("-p", "--port", type=str, default=DEFAULT_PORT, + help="Serial port, default: %s" % DEFAULT_PORT) + p.add_argument("-b", "--baudrate", type=int, default=DEFAULT_BAUDRATE, + help="Baudrate of the serial port, default: %d" % DEFAULT_BAUDRATE) + p.add_argument("-d", "--disable_output", default=DEFAULT_INFO, action='store_false', + help="Disable verbose output") + args = p.parse_args() + + puf_sram = puf_sram_if.PufSram(port=args.port, baud=args.baudrate) + seeds = puf_sram.get_seed_list(n=args.number, off_time=args.off_time, + allow_print=args.disable_output) seeds = [format(x, '0>32b') for x in seeds] H_min, H_min_rel = min_erntropy(seeds) diff --git a/tests/puf_sram/tests/puf_sram_if.py b/tests/puf_sram/tests/puf_sram_if.py index 79cf363fe707..e67c64c1d168 100644 --- a/tests/puf_sram/tests/puf_sram_if.py +++ b/tests/puf_sram/tests/puf_sram_if.py @@ -12,12 +12,12 @@ class PufSram: - def __init__(self, port='/dev/ttyUSB0', baud=115200): + def __init__(self, port, baud): self.__dev = serial.Serial(port, baud, timeout=10) if(self.__dev.isOpen() is False): self.__dev.open() - def repower(self, shutdown_time=1): + def repower(self, shutdown_time): self.__dev.setRTS(True) time.sleep(shutdown_time) self.__dev.setRTS(False) @@ -38,7 +38,7 @@ def read_data(self): return data return None - def get_seed_list(self, n=10000, off_time=1, allow_print=False): + def get_seed_list(self, n, off_time, allow_print): data = list() for i in range(0, n): self.repower(off_time)