Browse Source

tests: make use of testrunner

pr/gpio
test 7 years ago committed by Kaspar Schleiser
parent
commit
a9ef72ff02
  1. 32
      tests/msg_send_receive/tests/01-run.py
  2. 2
      tests/posix_semaphore/Makefile
  3. 30
      tests/posix_semaphore/tests/01-run.py
  4. 3
      tests/thread_basic/Makefile
  5. 22
      tests/thread_basic/tests/test_thread.py
  6. 37
      tests/unittests/tests/01-run.py
  7. 3
      tests/xtimer_msg_receive_timeout/Makefile
  8. 40
      tests/xtimer_msg_receive_timeout/tests/01-run.py

32
tests/msg_send_receive/tests/01-run.py

@ -1,33 +1,19 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
# Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.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
from pexpect import spawn, TIMEOUT, EOF
import os
import sys
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
import testrunner
DEFAULT_TIMEOUT = 5
def main():
p = None
try:
p = spawn("make term", timeout=DEFAULT_TIMEOUT)
p.logfile = sys.stdout
p.expect("Test successful.")
except TIMEOUT as exc:
print(exc)
return 1
finally:
if p and not p.terminate():
os.killpg(p.pid, signal.SIGKILL)
return 0
def testfunc(child):
child.expect(u"Test successful.")
if __name__ == "__main__":
sys.exit(main())
sys.exit(testrunner.run(testfunc))

2
tests/posix_semaphore/Makefile

@ -12,4 +12,4 @@ DISABLE_MODULE += auto_init
include $(RIOTBASE)/Makefile.include
test:
python tests/01-run.py
tests/01-run.py

30
tests/posix_semaphore/tests/01-run.py

@ -1,20 +1,16 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
#!/usr/bin/env python3
# Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.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
import sys
import pexpect
def init():
term = pexpect.spawn("make term", timeout=1.1)
term.logfile = sys.stdout
return term
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
import testrunner
def test1(term):
term.expect_exact("######################### TEST1:")
@ -91,10 +87,12 @@ def test4(term):
term.expect_exact("first: timed out")
term.expect(r"first: waited 1\d{6} usec")
def testfunc(child):
test1(child)
test2(child)
test3(child)
test4(child)
child.expect("######################### DONE")
if __name__ == "__main__":
TERM = init()
test1(TERM)
test2(TERM)
test3(TERM)
test4(TERM)
TERM.expect("######################### DONE")
sys.exit(testrunner.run(testfunc))

3
tests/thread_basic/Makefile

@ -4,3 +4,6 @@ include ../Makefile.tests_common
DISABLE_MODULE += auto_init
include $(RIOTBASE)/Makefile.include
test:
./tests/test_thread.py

22
tests/thread_basic/tests/test_thread.py

@ -1,8 +1,20 @@
#!/usr/bin/python
#!/usr/bin/env python3
import pexpect
# Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.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.
term = pexpect.spawn("make term")
import os
import sys
term.expect('first thread\r\n')
term.expect('second thread\r\n')
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
import testrunner
def testfunc(child):
child.expect('first thread\r\n')
child.expect('second thread\r\n')
if __name__ == "__main__":
sys.exit(testrunner.run(testfunc))

37
tests/unittests/tests/01-run.py

@ -1,38 +1,19 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
# Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.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
import os
import sys
DEFAULT_TIMEOUT = 5
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
import testrunner
def main():
env = os.environ.copy()
child = spawn("make term", env=env, timeout=DEFAULT_TIMEOUT,
encoding="utf-8")
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(u"OK \\([0-9]+ tests\\)")
except TIMEOUT:
print("There where errors in the unittests")
return 1
finally:
print("")
child.close()
return 0
def testfunc(child):
child.expect(u"OK \\([0-9]+ tests\\)")
if __name__ == "__main__":
sys.exit(main())
sys.exit(testrunner.run(testfunc))

3
tests/xtimer_msg_receive_timeout/Makefile

@ -4,4 +4,7 @@ include ../Makefile.tests_common
FEATURES_REQUIRED += periph_timer
USEMODULE += xtimer
test:
tests/01-run.py
include $(RIOTBASE)/Makefile.include

40
tests/xtimer_msg_receive_timeout/tests/01-run.py

@ -1,39 +1,21 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# Copyright (C) 2015 INRIA
# Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.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
from pexpect import TIMEOUT, EOF
if sys.version_info[0] == 2:
from pexpect import spawn
else:
from pexpect import spawnu as spawn
import os
import sys
DEFAULT_TIMEOUT = 2
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
import testrunner
def main():
p = None
try:
p = spawn("make term", timeout=DEFAULT_TIMEOUT)
p.logfile = sys.stdout
for i in range(10):
p.expect("Message received: 44")
p.expect("Timeout")
except TIMEOUT as exc:
print(exc)
return 1
finally:
if p and not p.terminate():
print("SUCCESS")
os.killpg(p.pid, signal.SIGKILL)
return 0
def testfunc(child):
for i in range(5):
child.expect("Message received: 44")
child.expect("Timeout!")
if __name__ == "__main__":
sys.exit(main())
sys.exit(testrunner.run(testfunc))

Loading…
Cancel
Save