testrunner: refactor exception printing
This commit is contained in:
parent
bd52d33274
commit
d537dd609f
16
dist/tools/testrunner/testrunner.py
vendored
16
dist/tools/testrunner/testrunner.py
vendored
@ -21,6 +21,14 @@ RIOTBASE = os.environ['RIOTBASE'] or \
|
|||||||
def list_until(l, cond):
|
def list_until(l, cond):
|
||||||
return l[:([i for i, e in enumerate(l) if cond(e)][0])]
|
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):
|
def run(testfunc, timeout=10, echo=True, traceback=False):
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
child = pexpect.spawnu("make term", env=env, timeout=timeout)
|
child = pexpect.spawnu("make term", env=env, timeout=timeout)
|
||||||
@ -40,13 +48,9 @@ def run(testfunc, timeout=10, echo=True, traceback=False):
|
|||||||
try:
|
try:
|
||||||
testfunc(child)
|
testfunc(child)
|
||||||
except pexpect.TIMEOUT:
|
except pexpect.TIMEOUT:
|
||||||
timeouted_at = list_until(extract_tb(sys.exc_info()[2]),
|
line, filename, lineno = find_exc_origin(sys.exc_info()[2])
|
||||||
lambda frame:
|
|
||||||
frame.filename.startswith(PEXPECT_PATH))[-1]
|
|
||||||
print("Timeout in expect script at \"%s\" (%s:%d)" %
|
print("Timeout in expect script at \"%s\" (%s:%d)" %
|
||||||
(timeouted_at.line,
|
(line, filename, lineno))
|
||||||
os.path.relpath(os.path.abspath(timeouted_at.filename), RIOTBASE),
|
|
||||||
timeouted_at.lineno))
|
|
||||||
if traceback:
|
if traceback:
|
||||||
print_tb(sys.exc_info()[2])
|
print_tb(sys.exc_info()[2])
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user