Commit c5e65005 by lwc-tester

generalizing the flash/test algorithm a bit

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