From 2bbe92a75a61e65bd9f26bddc26d17081bee05b5 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 8 Aug 2014 20:59:45 +0200 Subject: [PATCH] tests: Fix tests that were defect * I used pexpect instead of when expect script was not working expect, since TCL confuses me * I deleted the thread_exit test since it was completely invalid --- tests/hwtimer/tests/test_hwtimer | 47 ------------------------- tests/hwtimer/tests/test_hwtimer.py | 32 +++++++++++++++++ tests/thread_basic/tests/test_thread.py | 12 ++----- tests/thread_exit/tests/hello-world | 12 ------- 4 files changed, 35 insertions(+), 68 deletions(-) delete mode 100755 tests/hwtimer/tests/test_hwtimer create mode 100755 tests/hwtimer/tests/test_hwtimer.py delete mode 100755 tests/thread_exit/tests/hello-world diff --git a/tests/hwtimer/tests/test_hwtimer b/tests/hwtimer/tests/test_hwtimer deleted file mode 100755 index b746455437..0000000000 --- a/tests/hwtimer/tests/test_hwtimer +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/expect - -set timeout 5 - -spawn pseudoterm $env(PORT) - -expect { - "OK" {} - timeout { exit 1 } -} - -expect { - "set callback 1" {} - timeout { exit 1 } -} - -expect { - "set callback 2" {} - timeout { exit 1 } -} - -expect { - "set callback 3" {} - timeout { exit 1 } -} - -expect { - "callback 1" {} - timeout { exit 1 } -} - -expect { - "callback 3" {} - timeout { exit 1 } -} - -expect { - "callback 2" {} - timeout { exit 1 } -} - -expect { - "hwtimer set." {} - timeout { exit 1 } -} - -puts "\nTest successful!\n" diff --git a/tests/hwtimer/tests/test_hwtimer.py b/tests/hwtimer/tests/test_hwtimer.py new file mode 100755 index 0000000000..a7abc02eee --- /dev/null +++ b/tests/hwtimer/tests/test_hwtimer.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +from pexpect import spawn, TIMEOUT + +DEFAULT_TIMEOUT=5 +hwtimers = 0 + +term = spawn("make term") + +term.expect(r"Setting timers:", timeout=DEFAULT_TIMEOUT) + +try: + while True: + term.expect(r"set callback\s+\d+", timeout=DEFAULT_TIMEOUT) + hwtimers += 1 +except TIMEOUT: + pass + +term.expect(r"All timers set.", timeout=DEFAULT_TIMEOUT) +term.expect(r"callback\s+1", timeout=DEFAULT_TIMEOUT) +print("Got callback 1") + +while hwtimers > 1: + term.expect(r"callback\s+{:d}".format(hwtimers), timeout=DEFAULT_TIMEOUT) + print("Got callback {:d}".format(hwtimers)) + hwtimers -= 1 + +# Setting timers: +# term.expect("OK") +if not term.terminate(): + term.terminate(force=True) + diff --git a/tests/thread_basic/tests/test_thread.py b/tests/thread_basic/tests/test_thread.py index 691d3a640f..fb69ca0c23 100755 --- a/tests/thread_basic/tests/test_thread.py +++ b/tests/thread_basic/tests/test_thread.py @@ -1,14 +1,8 @@ #!/usr/bin/python import pexpect -import os -import subprocess -child = pexpect.spawn("board/msba2/tools/bin/pseudoterm %s" % os.environ["PORT"]) +term = pexpect.spawn("make term") -null = open('/dev/null', 'wb') -subprocess.call(['jam', 'reset'], stdout=null) - -child.expect ('first thread\r\n') -child.expect ('second thread\r\n') -print("Test successful!") +term.expect('first thread\r\n') +term.expect('second thread\r\n') diff --git a/tests/thread_exit/tests/hello-world b/tests/thread_exit/tests/hello-world deleted file mode 100755 index e7ab2a7c31..0000000000 --- a/tests/thread_exit/tests/hello-world +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/expect - -set timeout 5 - -spawn board/msba2/tools/bin/pseudoterm $env(PORT) - -expect { - "Hello World!" {} - timeout { exit 1 } -} - -puts "\nTest successful!\n"