Skip to content

Commit 0dac591

Browse files
projectgusdpgeorge
authored andcommitted
tests/run-multitests.py: Improve error handling for communication error.
Fixes fatal crash if serial port access returns an error (for example: port is native USB-CDC and the host hard faults during the test run). Instead of crashing, have the runner mark this as a test run error and continue. It's not certain the next test will run successfully, but this provides the context of output showing what was happening when the communication error occurred. Without this change, that output is lost when the fatal exception terminates the runner process. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent e08e3d7 commit 0dac591

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

tests/run-multitests.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -276,19 +276,22 @@ def stop(self):
276276
def readline(self):
277277
if self.finished:
278278
return None, None
279-
if self.pyb.serial.inWaiting() == 0:
280-
return None, None
281-
out = self.pyb.read_until(1, (b"\r\n", b"\x04"))
282-
if out.endswith(b"\x04"):
283-
self.finished = True
284-
out = out[:-1]
285-
err = decode(self.pyb.read_until(1, b"\x04"))
286-
err = err[:-1]
287-
if not out and not err:
279+
try:
280+
if self.pyb.serial.inWaiting() == 0:
288281
return None, None
289-
else:
290-
err = None
291-
return decode(out.rstrip()), err
282+
out = self.pyb.read_until(1, (b"\r\n", b"\x04"))
283+
if out.endswith(b"\x04"):
284+
self.finished = True
285+
out = out[:-1]
286+
err = decode(self.pyb.read_until(1, b"\x04"))
287+
err = err[:-1]
288+
if not out and not err:
289+
return None, None
290+
else:
291+
err = None
292+
return decode(out.rstrip()), err
293+
except OSError as e:
294+
return None, "Failed to read from instance: {}".format(e)
292295

293296
def write(self, data):
294297
self.pyb.serial.write(data)
@@ -434,7 +437,10 @@ def run_test_on_instances(test_file, num_instances, instances):
434437

435438
# Stop all instances
436439
for idx in range(num_instances):
437-
instances[idx].stop()
440+
try:
441+
instances[idx].stop()
442+
except OSError as e:
443+
output[idx].append("Runner failed to stop instance: {}".format(e))
438444

439445
output_str = ""
440446
for idx, lines in enumerate(output):

0 commit comments

Comments
 (0)