From 819dfacccc4d18e00401c3aa14e3ddb4025e10d9 Mon Sep 17 00:00:00 2001 From: test Date: Sat, 5 Mar 2016 15:59:35 +0100 Subject: [PATCH] dist: add testrunner shared pexpect code --- dist/tools/testrunner/testrunner.py | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 dist/tools/testrunner/testrunner.py diff --git a/dist/tools/testrunner/testrunner.py b/dist/tools/testrunner/testrunner.py new file mode 100755 index 0000000000..09e1dbf3a4 --- /dev/null +++ b/dist/tools/testrunner/testrunner.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2016 Kaspar Schleiser +# 2014 Martine Lenders +# +# 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 + +def run(testfunc, timeout=5, echo=True): + env = os.environ.copy() + child = spawnu("make term", env=env, timeout=timeout) + 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") + return 1 + finally: + print("") + child.kill(signal.SIGKILL) + child.close() + + return 0