From 4fb7939ab931cc3a60895fa51b9749f5edbf9809 Mon Sep 17 00:00:00 2001
From: Martine Lenders <mlenders@inf.fu-berlin.de>
Date: Fri, 3 Jul 2015 14:50:52 +0200
Subject: [PATCH] unittests: add new test runner script

---
 tests/unittests/Makefile        |  5 +----
 tests/unittests/tests/01-run.py | 37 +++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 4 deletions(-)
 create mode 100755 tests/unittests/tests/01-run.py

diff --git a/tests/unittests/Makefile b/tests/unittests/Makefile
index f3f31dc5c2..59e86f643b 100644
--- a/tests/unittests/Makefile
+++ b/tests/unittests/Makefile
@@ -78,8 +78,5 @@ else
     CFLAGS += -DTEST_SUITES='$(subst $() $(),$(charCOMMA),$(UNIT_TESTS:tests-%=%))'
 endif
 
-test: SHELL=bash
 test:
-	@exec 5>&1 && \
-	LOG=$$("$(MAKE)" -s term | tee >(cat - >&5)) && \
-	grep 'OK ([1-9][0-9]* tests)' <<< $${LOG} > /dev/null
+	./tests/01-run.py
diff --git a/tests/unittests/tests/01-run.py b/tests/unittests/tests/01-run.py
new file mode 100755
index 0000000000..19456a8fc2
--- /dev/null
+++ b/tests/unittests/tests/01-run.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+# Copyright (C) 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 spawn, TIMEOUT, EOF
+
+DEFAULT_TIMEOUT = 5
+
+def main():
+    env = os.environ.copy()
+    child = spawn("make term", env=env, timeout=DEFAULT_TIMEOUT)
+    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:
+        child.expect(r"OK \([0-9]+ tests\)")
+    except TIMEOUT:
+        print("There where errors in the unittests")
+        return 1
+    finally:
+        print("")
+        child.close()
+
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main())
-- 
GitLab