From b636d024d2fe950d8dd643c74aa006d1ea88078d Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 13 Apr 2014 13:48:33 +0100 Subject: [PATCH] Make pyboard.py have its own exception; update run-tests for pyboard. --- tests/run-tests | 21 ++++++++++++++------- tools/pyboard.py | 11 +++++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/tests/run-tests b/tests/run-tests index 2866a6c487..33409832ba 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -46,14 +46,21 @@ for test_file in tests: output_expected = b'CPYTHON3 CRASH' # run Micro Python - try: - if test_on_pyboard: - pyb.enter_raw_repl() - output_mupy = pyb.execfile(test_file).replace(b'\r\n', b'\n') - else: + if test_on_pyboard: + pyb.enter_raw_repl() + try: + if test_file == 'basics/math-fun.py': + # this test crashes the pyboard + output_mupy = b'CRASH' + else: + output_mupy = pyb.execfile(test_file).replace(b'\r\n', b'\n') + except pyboard.PyboardError: + output_mupy = b'CRASH\n' + output_mupy + else: + try: output_mupy = subprocess.check_output([MP_PY, '-X', 'emit=bytecode', test_file]) - except subprocess.CalledProcessError: - output_mupy = b'CRASH' + except subprocess.CalledProcessError: + output_mupy = b'CRASH' testcase_count += len(output_expected.splitlines()) diff --git a/tools/pyboard.py b/tools/pyboard.py index 1c5c84f304..902a93c15a 100644 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -22,6 +22,9 @@ To run a script from the local machine on the board and print out the results: import time import serial +class PyboardError(BaseException): + pass + class Pyboard: def __init__(self, serial_device): self.serial = serial.Serial(serial_device) @@ -38,7 +41,7 @@ class Pyboard: time.sleep(0.1) if not data.endswith(b'raw REPL; CTRL-B to exit\r\n>'): print(data) - raise Exception('could not enter raw repl') + raise PyboardError('could not enter raw repl') def exit_raw_repl(self): self.serial.write(b'\r\x02') # ctrl-B: enter friendly REPL @@ -56,7 +59,7 @@ class Pyboard: self.serial.write(b'\x04') data = self.serial.read(2) if data != b'OK': - raise Exception('could not exec command') + raise PyboardError('could not exec command') data = self.serial.read(2) timeout = 0 while True: @@ -72,10 +75,10 @@ class Pyboard: time.sleep(0.1) if not data.endswith(b'\x04>'): print(data) - raise Exception('timeout waiting for EOF reception') + raise PyboardError('timeout waiting for EOF reception') if data.startswith(b'Traceback') or data.startswith(b' File '): print(data) - raise Exception('command failed') + raise PyboardError('command failed') return data[:-2] def execfile(self, filename):