1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #13642 from aabadie/pr/tests/check_unittests_func

tests: add check_unittests helper function
This commit is contained in:
Martine Lenders 2020-03-19 12:35:05 +01:00 committed by GitHub
commit 200d091189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 101 additions and 216 deletions

View File

@ -9,6 +9,7 @@
import os
import sys
from functools import partial
from traceback import print_tb
import pexpect
@ -44,3 +45,16 @@ def run(testfunc, timeout=TIMEOUT, echo=True, traceback=False):
print("")
teardown_child(child)
return 0
def check_unittests(child, timeout=TIMEOUT, nb_tests=None):
_tests = r'\d+' if nb_tests is None else int(nb_tests)
child.expect(r'OK \({} tests\)'.format(_tests), timeout=timeout)
def run_check_unittests(timeout=TIMEOUT, echo=True, traceback=False,
nb_tests=None):
_unittests_func = partial(check_unittests,
timeout=timeout, nb_tests=nb_tests)
return run(_unittests_func, timeout, echo, traceback)

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -16,7 +16,7 @@ import time
from scapy.all import Ether, ICMPv6PacketTooBig, IPv6, IPv6ExtHdrFragment, \
UDP, raw, sendp, srp1
from testrunner import run
from testrunner import run, check_unittests
RECV_BUFSIZE = 2 * 1500
@ -319,7 +319,7 @@ def testfunc(child):
tap = get_bridge(os.environ["TAP"])
child.sendline("unittests")
child.expect(r"OK \((\d+) tests\)") # wait for and check result of unittests
check_unittests(child) # wait for and check result of unittests
print("." * int(child.match.group(1)), end="", flush=True)
lladdr_src = get_host_lladdr(tap)

View File

@ -8,12 +8,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r"OK \(\d+ tests\)")
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -8,12 +8,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r"OK \(\d+ tests\)")
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -8,13 +8,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
# 1st 6LoWPAN fragment
child.expect(r"OK \(\d+ tests\)")
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -8,12 +8,12 @@
# directory for more details.
import sys
from testrunner import run
from testrunner import run, check_unittests
def testfunc(child):
# embUnit tests
child.expect(r"OK \(\d+ tests\)")
check_unittests(child)
# output cross-checked hex data with WireShark -> "Import from Hex Dump..."
# test_netapi_send__raw_unicast_ethernet_packet
child.expect("Sending data from Ethernet device:")

View File

@ -18,7 +18,7 @@ from scapy.all import Ether, IPv6, UDP, \
IPv6ExtHdrFragment, IPv6ExtHdrRouting, \
ICMPv6ParamProblem, ICMPv6TimeExceeded, \
sendp, srp1, sniff
from testrunner import run
from testrunner import run, check_unittests
EXT_HDR_NH = {
@ -338,7 +338,7 @@ def testfunc(child):
global sniffer
tap = get_bridge(os.environ["TAP"])
child.sendline("unittests")
child.expect(r"OK \((\d+) tests\)") # wait for and check result of unittests
check_unittests(child) # wait for and check result of unittests
print("." * int(child.match.group(1)), end="", flush=True)
lladdr_src = get_host_lladdr(tap)
child.sendline("ifconfig")

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,7 +7,7 @@
# directory for more details.
import sys
from testrunner import run
from testrunner import run, check_unittests
def testfunc(child):
@ -88,7 +88,7 @@ def testfunc(child):
)
child.expect_exact("Original fragmentation header:")
child.expect_exact("IPHC headers + payload:")
child.expect(r"OK \((\d+) tests\)")
check_unittests(child)
assert int(child.match.group(1)) >= 4

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r"OK \([0-9]+ tests\)")
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -10,17 +10,15 @@
import os
import sys
from testrunner import run_check_unittests
from testrunner import TIMEOUT as DEFAULT_TIMEOUT
def testfunc(child):
board = os.environ['BOARD']
# Increase timeout on "real" hardware
# 170 seconds on `arduino-mega2560`
timeout = 200 if board != 'native' else -1
child.expect(r"OK \(2 tests\)", timeout=timeout)
BOARD = os.environ['BOARD']
# Increase timeout on "real" hardware
# 170 seconds on `arduino-mega2560`
TIMEOUT = 200 if BOARD != 'native' else DEFAULT_TIMEOUT
if __name__ == "__main__":
sys.path.append(os.path.join(os.environ['RIOTBASE'],
'dist/tools/testrunner'))
from testrunner import run
sys.exit(run(testfunc))
sys.exit(run_check_unittests(timeout=TIMEOUT))

View File

@ -8,12 +8,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r"OK \(\d+ tests\)")
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,7 +7,7 @@
# directory for more details.
import sys
from testrunner import run
from testrunner import run_check_unittests
# increase the default timeout to 30s, on samr30-xpro this test takes 20s to
@ -15,9 +15,5 @@ from testrunner import run
TIMEOUT = 30
def testfunc(child):
child.expect(r'OK \(\d+ tests\)', timeout=TIMEOUT)
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests(timeout=TIMEOUT))

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect_exact('OK (2 tests)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests(nb_tests=2))

View File

@ -8,20 +8,15 @@
import os
import sys
from testrunner import run
from testrunner import run_check_unittests
from testrunner import TIMEOUT as DEFAULT_TIMEOUT
BOARD = os.environ['BOARD']
# on real hardware, this test application can take several minutes to
# complete (~4min on microbit)
HW_TIMEOUT = 300
def testfunc(child):
board = os.environ['BOARD']
# Increase timeout on "real" hardware
timeout = HW_TIMEOUT if board != 'native' else -1
child.expect(r'OK \(\d+ tests\)', timeout=timeout)
TIMEOUT = 300 if BOARD != 'native' else DEFAULT_TIMEOUT
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests(timeout=TIMEOUT))

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect_exact('OK (3 tests)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -8,7 +8,7 @@
# directory for more details.
import sys
from testrunner import run
from testrunner import run_check_unittests
# increase the default timeout to 20s, on samr30-xpro this test takes 14s to
@ -16,9 +16,5 @@ from testrunner import run
TIMEOUT = 20
def testfunc(child):
child.expect(r"OK \(2 tests\)", timeout=TIMEOUT)
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests(timeout=TIMEOUT, nb_tests=2))

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,15 +7,11 @@
# directory for more details.
import sys
from testrunner import run
from testrunner import run_check_unittests
# It takes ~11s on nucleo-l152re, so add some margin
TIMEOUT = 15
def testfunc(child):
child.expect(r'OK \(\d+ tests\)', timeout=TIMEOUT)
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests(timeout=TIMEOUT))

View File

@ -7,12 +7,11 @@
# directory for more details.
import sys
from testrunner import run
from testrunner import run_check_unittests
def testfunc(child):
child.expect(r'OK \(\d+ tests\)', timeout=120)
TIMEOUT = 120
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests(timeout=TIMEOUT))

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -8,12 +8,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r"OK \(1 tests\)")
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests(nb_tests=1))

View File

@ -8,14 +8,14 @@
import os
import sys
from testrunner import run
from testrunner import run, check_unittests
def testfunc(child):
board = os.environ['BOARD']
# Increase timeout on "real" hardware
timeout = 120 if board != 'native' else -1
child.expect(r'OK \(\d+ tests\)', timeout=timeout)
check_unittests(child, timeout=timeout)
if __name__ == "__main__":

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r"OK \(\d+ tests\)")
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,12 +7,8 @@
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r'OK \(\d+ tests\)')
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())

View File

@ -7,12 +7,11 @@
# directory for more details.
import sys
from testrunner import run
from testrunner import run_check_unittests
def testfunc(child):
child.expect(u"OK \\([0-9]+ tests\\)")
TIMEOUT = 120
if __name__ == "__main__":
sys.exit(run(testfunc, timeout=120))
sys.exit(run_check_unittests(timeout=TIMEOUT))

View File

@ -7,16 +7,9 @@
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
import os
import sys
def testfunc(child):
child.expect(r"OK \(1 tests\)")
from testrunner import run_check_unittests
if __name__ == "__main__":
sys.path.append(os.path.join(os.environ['RIOTBASE'],
'dist/tools/testrunner'))
from testrunner import run
sys.exit(run(testfunc))
sys.exit(run_check_unittests(nb_tests=1))