2016-03-05 15:59:35 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
# 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
|
|
|
|
#
|
|
|
|
# This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
# General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
# directory for more details.
|
|
|
|
|
|
|
|
import os, signal, sys, subprocess
|
|
|
|
from pexpect import spawnu, TIMEOUT, EOF
|
2016-04-08 22:39:49 +02:00
|
|
|
from traceback import print_tb
|
2017-10-24 14:55:15 +02:00
|
|
|
import time
|
2016-03-05 15:59:35 +01:00
|
|
|
|
2016-04-08 22:39:49 +02:00
|
|
|
def run(testfunc, timeout=10, echo=True, traceback=False):
|
2016-03-05 15:59:35 +01:00
|
|
|
env = os.environ.copy()
|
|
|
|
child = spawnu("make term", env=env, timeout=timeout)
|
2017-10-24 14:55:15 +02:00
|
|
|
|
|
|
|
# on many platforms, the termprog needs a short while to be ready...
|
|
|
|
time.sleep(3)
|
|
|
|
|
2016-03-05 15:59:35 +01:00
|
|
|
if echo:
|
|
|
|
child.logfile = sys.stdout
|
|
|
|
|
|
|
|
try:
|
|
|
|
subprocess.check_output(('make', 'reset'), env=env,
|
|
|
|
stderr=subprocess.PIPE)
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
# make reset yields error on some boards even if successful
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
testfunc(child)
|
|
|
|
except TIMEOUT:
|
|
|
|
print("Timeout in expect script")
|
2016-04-08 22:39:49 +02:00
|
|
|
if traceback:
|
|
|
|
print_tb(sys.exc_info()[2])
|
2016-03-05 15:59:35 +01:00
|
|
|
return 1
|
|
|
|
finally:
|
|
|
|
print("")
|
2016-03-05 20:47:51 +01:00
|
|
|
os.killpg(os.getpgid(child.pid), signal.SIGKILL)
|
2016-03-05 15:59:35 +01:00
|
|
|
child.close()
|
|
|
|
|
|
|
|
return 0
|