Commit c5e65005 by lwc-tester

generalizing the flash/test algorithm a bit

parent eabadd99
......@@ -29,12 +29,14 @@ def get_serial():
class BluePill(DeviceUnderTestAeadUARTP):
RAM_SIZE = 0x5000
LOCK_PATH = '/var/lock/lwc-compare.bluepill.lock'
def __init__(self, build_dir):
DeviceUnderTestAeadUARTP.__init__(self)
self.lock = FileMutex(BluePill.LOCK_PATH)
self.uart_device = get_serial()
devname = os.path.basename(self.uart_device)
self.lock = FileMutex('/var/lock/lwc-compare.%s.lock' % devname)
self.build_dir = build_dir
self.firmware_path = os.path.join(
build_dir, '.pio/build/bluepill_f103c8/firmware.elf')
......@@ -77,6 +79,14 @@ class BluePill(DeviceUnderTestAeadUARTP):
assert res == ''
eprint("Reset!")
def prepare(self):
self.ser = serial.Serial(
self.uart_device,
baudrate=115200,
timeout=5)
self.reset()
DeviceUnderTestAeadUARTP.prepare(self)
def dump_ram(self):
res = self.ocd.send(
'dump_image %s 0x20000000 0x%x' %
......@@ -104,18 +114,7 @@ def main(argv):
dut = BluePill(build_dir)
dut.reset()
dut.flash()
ser = serial.Serial(
get_serial(),
baudrate=115200,
timeout=5)
dut.reset()
dut.ser = ser
dut.prepare()
sys.stdout.write("Board prepared\n")
sys.stdout.flush()
......@@ -131,7 +130,7 @@ def main(argv):
run_nist_aead_test_line(dut, i, m, ad, k, npub, c)
tool.unarm()
if i == 1:
if i == 1 and dump_a is not None:
dump_b = dut.dump_ram()
longest = compare_dumps(dump_a, dump_b)
print(" longest chunk of untouched memory = %d" % longest)
......
......@@ -10,6 +10,7 @@ from test_common import (
parse_nist_aead_test_vectors,
DeviceUnderTestAeadUARTP,
eprint,
FileMutex,
run_nist_aead_test_line,
)
......@@ -30,18 +31,37 @@ class ESP32(DeviceUnderTestAeadUARTP):
def __init__(self, build_dir):
DeviceUnderTestAeadUARTP.__init__(self)
self.uart_device = get_serial()
devname = os.path.basename(self.uart_device)
self.lock = FileMutex('/var/lock/lwc-compare.%s.lock' % devname)
self.build_dir = build_dir
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)
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']
cmd.extend(['--upload-port', get_serial()])
cmd.extend(['--upload-port', get_serial()])
cmd.extend(['--upload-port', self.uart_device])
p = subprocess.Popen(
cmd, stdout=sys.stderr, stdin=pipe)
stdout, stderr = p.communicate("")
assert p.returncode == 0
eprint("Firmware flashed.")
os.chdir(previous_dir)
......@@ -59,30 +79,15 @@ def main(argv):
dut = ESP32(build_dir)
try:
tool = LogicMultiplexerTimeMeasurements(0x0030)
tool.begin_measurement()
dut.flash()
ser = serial.Serial(
get_serial(),
baudrate=500000,
timeout=5)
ser.setDTR(False) # IO0=HIGH
ser.setRTS(True) # EN=LOW, chip in reset
time.sleep(0.1)
ser.setDTR(False) # IO0=HIGH
ser.setRTS(False) # EN=HIGH, chip out of reset
time.sleep(1)
dut.ser = ser
dut.prepare()
sys.stdout.write("Board prepared\n")
sys.stdout.flush()
try:
tool = LogicMultiplexerTimeMeasurements(0x0030)
tool.begin_measurement()
for i, m, ad, k, npub, c in kat:
tool.arm()
run_nist_aead_test_line(dut, i, m, ad, k, npub, c)
......@@ -94,6 +99,7 @@ def main(argv):
finally:
tool.end_measurement()
sys.stdout.flush()
sys.stderr.flush()
......
......@@ -10,6 +10,7 @@ from test_common import (
parse_nist_aead_test_vectors,
DeviceUnderTestAeadUARTP,
eprint,
FileMutex,
run_nist_aead_test_line,
)
......@@ -30,18 +31,35 @@ class Uno(DeviceUnderTestAeadUARTP):
def __init__(self, build_dir):
DeviceUnderTestAeadUARTP.__init__(self)
self.uart_device = get_serial()
devname = os.path.basename(self.uart_device)
self.lock = FileMutex('/var/lock/lwc-compare.%s.lock' % devname)
self.build_dir = build_dir
def reset(self):
self.ser.setDTR(True)
time.sleep(0.01)
self.ser.setDTR(False)
time.sleep(1)
def prepare(self):
self.ser = serial.Serial(
self.uart_device,
baudrate=115200,
timeout=5)
self.reset()
DeviceUnderTestAeadUARTP.prepare(self)
def flash(self):
pipe = subprocess.PIPE
previous_dir = os.path.abspath(os.curdir)
os.chdir(self.build_dir)
cmd = ['platformio', 'run', '-e', 'uno', '--target', 'upload']
cmd.extend(['--upload-port', get_serial()])
cmd.extend(['--upload-port', get_serial()])
cmd.extend(['--upload-port', self.uart_device])
p = subprocess.Popen(
cmd, stdout=sys.stderr, stdin=pipe)
stdout, stderr = p.communicate("")
assert p.returncode == 0
eprint("Firmware flashed.")
os.chdir(previous_dir)
......@@ -59,28 +77,15 @@ def main(argv):
dut = Uno(build_dir)
try:
tool = LogicMultiplexerTimeMeasurements(0x0c00)
tool.begin_measurement()
dut.flash()
ser = serial.Serial(
get_serial(),
baudrate=115200,
timeout=5)
ser.setDTR(True)
time.sleep(0.01)
ser.setDTR(False)
time.sleep(1)
dut.ser = ser
dut.prepare()
sys.stdout.write("Board prepared\n")
sys.stdout.flush()
try:
tool = LogicMultiplexerTimeMeasurements(0x0c00)
tool.begin_measurement()
for i, m, ad, k, npub, c in kat:
tool.arm()
run_nist_aead_test_line(dut, i, m, ad, k, npub, c)
......@@ -92,6 +97,7 @@ def main(argv):
finally:
tool.end_measurement()
sys.stdout.flush()
sys.stderr.flush()
......
......@@ -38,10 +38,12 @@ class DeviceUnderTestAeadUARTP(DeviceUnderTest):
def prepare(self):
exp_hello = b"Hello, World!"
time.sleep(0.1)
if self.ser.in_waiting < 13:
hello = self.ser.read(13)
if hello[-13:] != exp_hello:
time.sleep(2)
hello = self.ser.read(self.ser.in_waiting)
hello += self.ser.read(self.ser.in_waiting)
if hello[-13:] != exp_hello:
raise Exception(
"Improper board initialization message: %s" % hello)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment