From d537dd609f5aaabc7abcabf1ab0dcdb4540c2bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cenk=20G=C3=BCndo=C4=9Fan?= Date: Sun, 12 Nov 2017 12:59:45 +0100 Subject: [PATCH 1/2] testrunner: refactor exception printing --- dist/tools/testrunner/testrunner.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/dist/tools/testrunner/testrunner.py b/dist/tools/testrunner/testrunner.py index 5b2b73e20c..471c93253d 100755 --- a/dist/tools/testrunner/testrunner.py +++ b/dist/tools/testrunner/testrunner.py @@ -21,6 +21,14 @@ RIOTBASE = os.environ['RIOTBASE'] or \ def list_until(l, cond): return l[:([i for i, e in enumerate(l) if cond(e)][0])] +def find_exc_origin(exc_info): + pos = list_until(extract_tb(exc_info), + lambda frame: frame.filename.startswith(PEXPECT_PATH) + )[-1] + return pos.line, \ + os.path.relpath(os.path.abspath(pos.filename), RIOTBASE), \ + pos.lineno + def run(testfunc, timeout=10, echo=True, traceback=False): env = os.environ.copy() child = pexpect.spawnu("make term", env=env, timeout=timeout) @@ -40,13 +48,9 @@ def run(testfunc, timeout=10, echo=True, traceback=False): try: testfunc(child) except pexpect.TIMEOUT: - timeouted_at = list_until(extract_tb(sys.exc_info()[2]), - lambda frame: - frame.filename.startswith(PEXPECT_PATH))[-1] + line, filename, lineno = find_exc_origin(sys.exc_info()[2]) print("Timeout in expect script at \"%s\" (%s:%d)" % - (timeouted_at.line, - os.path.relpath(os.path.abspath(timeouted_at.filename), RIOTBASE), - timeouted_at.lineno)) + (line, filename, lineno)) if traceback: print_tb(sys.exc_info()[2]) return 1 From e1422bb5e4a510b8f1844f50af0c4f1659b5cdfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cenk=20G=C3=BCndo=C4=9Fan?= Date: Sun, 12 Nov 2017 13:00:08 +0100 Subject: [PATCH 2/2] testrunner: handle EOF and ProcessLookupError --- dist/tools/testrunner/testrunner.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/dist/tools/testrunner/testrunner.py b/dist/tools/testrunner/testrunner.py index 471c93253d..9f11b1148e 100755 --- a/dist/tools/testrunner/testrunner.py +++ b/dist/tools/testrunner/testrunner.py @@ -1,4 +1,5 @@ -# Copyright (C) 2016 Kaspar Schleiser +# Copyright (C) 2017 Cenk Gündoğan +# 2016 Kaspar Schleiser # 2014 Martine Lenders # # This file is subject to the terms and conditions of the GNU Lesser @@ -54,9 +55,19 @@ def run(testfunc, timeout=10, echo=True, traceback=False): if traceback: print_tb(sys.exc_info()[2]) return 1 + except pexpect.EOF: + line, filename, lineno = find_exc_origin(sys.exc_info()[2]) + print("Unexpected end of file in expect script at \"%s\" (%s:%d)" % + (line, filename, lineno)) + if traceback: + print_tb(sys.exc_info()[2]) + return 1 finally: print("") - os.killpg(os.getpgid(child.pid), signal.SIGKILL) - child.close() + try: + os.killpg(os.getpgid(child.pid), signal.SIGKILL) + except ProcessLookupError: + print("Process already stopped") + child.close() return 0