Skip to content

Commit

Permalink
Merge pull request #10385 from PeterKietzmann/pr_tests_puf_args
Browse files Browse the repository at this point in the history
tests/puf_sram: add input args to automation script
  • Loading branch information
MrKevinWeiss authored Nov 19, 2018
2 parents 126f232 + 0de38c2 commit c7894d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
25 changes: 23 additions & 2 deletions tests/puf_sram/tests/example_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions tests/puf_sram/tests/puf_sram_if.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit c7894d2

Please sign in to comment.