Merge pull request #11875 from cladmi/pr/test_utils/sync
test_utils_interactive_sync: add a helper for synchronizing tests
This commit is contained in:
commit
5653004d52
1
dist/pythonlibs/testrunner/__init__.py
vendored
1
dist/pythonlibs/testrunner/__init__.py
vendored
@ -14,6 +14,7 @@ import pexpect
|
|||||||
|
|
||||||
from .spawn import find_exc_origin, setup_child, teardown_child
|
from .spawn import find_exc_origin, setup_child, teardown_child
|
||||||
from .unittest import PexpectTestCase # noqa, F401 expose to users
|
from .unittest import PexpectTestCase # noqa, F401 expose to users
|
||||||
|
from .utils import test_utils_interactive_sync # noqa, F401 expose to users
|
||||||
|
|
||||||
# Timeout for tests can be changed by setting RIOT_TEST_TIMEOUT to the desired
|
# Timeout for tests can be changed by setting RIOT_TEST_TIMEOUT to the desired
|
||||||
# value in the environment variables
|
# value in the environment variables
|
||||||
|
|||||||
27
dist/pythonlibs/testrunner/utils.py
vendored
Normal file
27
dist/pythonlibs/testrunner/utils.py
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Copyright (C) 2019 Freie Universität Berlin
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
"""Utility functions for writing tests."""
|
||||||
|
|
||||||
|
import pexpect
|
||||||
|
|
||||||
|
|
||||||
|
def test_utils_interactive_sync(child, retries=5, delay=1):
|
||||||
|
"""Synchronisation for 'test_utils_interactive_sync' function.
|
||||||
|
|
||||||
|
Interacts through input to wait for node being ready.
|
||||||
|
"""
|
||||||
|
for _ in range(0, retries):
|
||||||
|
child.sendline('r')
|
||||||
|
ret = child.expect_exact(['READY', pexpect.TIMEOUT], timeout=delay)
|
||||||
|
if ret == 0:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# Last call to make it fail her,
|
||||||
|
child.expect_exact('READY', timeout=0)
|
||||||
|
|
||||||
|
child.sendline('s')
|
||||||
|
child.expect_exact('START')
|
||||||
@ -25,6 +25,9 @@ endif
|
|||||||
ifneq (,$(filter shell_commands,$(USEMODULE)))
|
ifneq (,$(filter shell_commands,$(USEMODULE)))
|
||||||
DIRS += shell/commands
|
DIRS += shell/commands
|
||||||
endif
|
endif
|
||||||
|
ifneq (,$(filter test_utils_interactive_sync,$(USEMODULE)))
|
||||||
|
DIRS += test_utils/interactive_sync
|
||||||
|
endif
|
||||||
ifneq (,$(filter net_help,$(USEMODULE)))
|
ifneq (,$(filter net_help,$(USEMODULE)))
|
||||||
DIRS += net/crosslayer/net_help
|
DIRS += net/crosslayer/net_help
|
||||||
endif
|
endif
|
||||||
|
|||||||
@ -9,3 +9,5 @@ endif
|
|||||||
ifneq (,$(filter prng_fortuna,$(USEMODULE)))
|
ifneq (,$(filter prng_fortuna,$(USEMODULE)))
|
||||||
CFLAGS += -DCRYPTO_AES
|
CFLAGS += -DCRYPTO_AES
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
include $(RIOTBASE)/sys/test_utils/Makefile.dep
|
||||||
|
|||||||
42
sys/include/test_utils/interactive_sync.h
Normal file
42
sys/include/test_utils/interactive_sync.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Freie Universität Berlin
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup test_utils_interactive_sync Test interactive synchronization
|
||||||
|
* @ingroup sys
|
||||||
|
* @brief Utility function for synchronizing before a test
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
* @file
|
||||||
|
* @brief Synchronization for normally non interactive tests
|
||||||
|
*
|
||||||
|
* @author Gaëtan Harter <gaetan.harter@fu-berlin.de>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TEST_UTILS_INTERACTIVE_SYNC_H
|
||||||
|
#define TEST_UTILS_INTERACTIVE_SYNC_H
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Wait for the tester to start test
|
||||||
|
*
|
||||||
|
* @details Wait for a 's' character to return
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void test_utils_interactive_sync(void);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif /* TEST_UTILS_INTERACTIVE_SYNC_H */
|
||||||
|
/** @} */
|
||||||
3
sys/test_utils/Makefile.dep
Normal file
3
sys/test_utils/Makefile.dep
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
ifneq (,$(filter test_utils_interactive_sync,$(USEMODULE)))
|
||||||
|
USEMODULE += stdin
|
||||||
|
endif
|
||||||
3
sys/test_utils/interactive_sync/Makefile
Normal file
3
sys/test_utils/interactive_sync/Makefile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
MODULE = test_utils_interactive_sync
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.base
|
||||||
20
sys/test_utils/interactive_sync/interactive_sync.c
Normal file
20
sys/test_utils/interactive_sync/interactive_sync.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "test_utils/interactive_sync.h"
|
||||||
|
|
||||||
|
void test_utils_interactive_sync(void)
|
||||||
|
{
|
||||||
|
char c = '\0'; /* Print help on first loop */
|
||||||
|
do {
|
||||||
|
if (c == 'r') {
|
||||||
|
/* This one should have a different case than the help message
|
||||||
|
* otherwise we match it when using 'expect' */
|
||||||
|
puts("READY");
|
||||||
|
}
|
||||||
|
else if (c != '\n' && c != '\r') {
|
||||||
|
puts("Help: Press s to start test, r to print it is ready");
|
||||||
|
}
|
||||||
|
c = getchar();
|
||||||
|
} while (c != 's');
|
||||||
|
|
||||||
|
puts("START");
|
||||||
|
}
|
||||||
@ -7,4 +7,6 @@ BOARD_INSUFFICIENT_MEMORY := arduino-duemilanove arduino-leonardo arduino-nano \
|
|||||||
nucleo-l031k6 nucleo-l053 nucleo-l053r8 \
|
nucleo-l031k6 nucleo-l053 nucleo-l053r8 \
|
||||||
stm32f0discovery stm32l0538-disco
|
stm32f0discovery stm32l0538-disco
|
||||||
|
|
||||||
|
USEMODULE += test_utils_interactive_sync
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.include
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
#include "cond.h"
|
#include "cond.h"
|
||||||
#include "mutex.h"
|
#include "mutex.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
#include "test_utils/interactive_sync.h"
|
||||||
|
|
||||||
#define THREAD_NUMOF (5U)
|
#define THREAD_NUMOF (5U)
|
||||||
#define THREAD_FIRSTGROUP_NUMOF (3U)
|
#define THREAD_FIRSTGROUP_NUMOF (3U)
|
||||||
@ -62,6 +63,8 @@ int main(void)
|
|||||||
puts("Condition variable order test");
|
puts("Condition variable order test");
|
||||||
puts("Please refer to the README.md for more information\n");
|
puts("Please refer to the README.md for more information\n");
|
||||||
|
|
||||||
|
test_utils_interactive_sync();
|
||||||
|
|
||||||
mutex_init(&testlock);
|
mutex_init(&testlock);
|
||||||
cond_init(&testcond);
|
cond_init(&testcond);
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,8 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from testrunner import test_utils_interactive_sync
|
||||||
|
|
||||||
thread_prio = {
|
thread_prio = {
|
||||||
3: 6,
|
3: 6,
|
||||||
4: 4,
|
4: 4,
|
||||||
@ -21,6 +23,8 @@ first_group_size = 3
|
|||||||
|
|
||||||
|
|
||||||
def testfunc(child):
|
def testfunc(child):
|
||||||
|
test_utils_interactive_sync(child)
|
||||||
|
|
||||||
for k in thread_prio.keys():
|
for k in thread_prio.keys():
|
||||||
child.expect(u"T%i \(prio %i\): waiting on condition variable now" % (k, thread_prio[k]))
|
child.expect(u"T%i \(prio %i\): waiting on condition variable now" % (k, thread_prio[k]))
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ include ../Makefile.tests_common
|
|||||||
|
|
||||||
USEPKG += libfixmath
|
USEPKG += libfixmath
|
||||||
USEMODULE += libfixmath
|
USEMODULE += libfixmath
|
||||||
USEMODULE += xtimer
|
USEMODULE += test_utils_interactive_sync
|
||||||
|
|
||||||
TEST_ON_CI_WHITELIST += all
|
TEST_ON_CI_WHITELIST += all
|
||||||
|
|
||||||
|
|||||||
@ -30,8 +30,9 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "xtimer.h"
|
#include "kernel_defines.h"
|
||||||
#include "fix16.h"
|
#include "fix16.h"
|
||||||
|
#include "test_utils/interactive_sync.h"
|
||||||
|
|
||||||
#ifndef M_PI
|
#ifndef M_PI
|
||||||
# define M_PI 3.14159265359
|
# define M_PI 3.14159265359
|
||||||
@ -185,8 +186,9 @@ static void unary_ops(void)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
/* Delay output to prevent flooding of buffer */
|
/* Sync to prevent flooding of buffer */
|
||||||
xtimer_sleep(1);
|
test_utils_interactive_sync();
|
||||||
|
|
||||||
puts("Unary.");
|
puts("Unary.");
|
||||||
unary_ops();
|
unary_ops();
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from testrunner import run
|
from testrunner import run, test_utils_interactive_sync
|
||||||
|
|
||||||
|
|
||||||
def expect_unary(child):
|
def expect_unary(child):
|
||||||
@ -31,6 +31,7 @@ def expect_binary(child):
|
|||||||
|
|
||||||
|
|
||||||
def testfunc(child):
|
def testfunc(child):
|
||||||
|
test_utils_interactive_sync(child)
|
||||||
child.expect_exact('Unary.')
|
child.expect_exact('Unary.')
|
||||||
expect_unary(child)
|
expect_unary(child)
|
||||||
child.expect_exact('Binary.')
|
child.expect_exact('Binary.')
|
||||||
|
|||||||
@ -2,8 +2,7 @@ include ../Makefile.tests_common
|
|||||||
|
|
||||||
USEMODULE += posix_time
|
USEMODULE += posix_time
|
||||||
|
|
||||||
# This application uses getchar and thus expects input from stdio
|
USEMODULE += test_utils_interactive_sync
|
||||||
USEMODULE += stdin
|
|
||||||
|
|
||||||
TEST_ON_CI_WHITELIST += all
|
TEST_ON_CI_WHITELIST += all
|
||||||
|
|
||||||
|
|||||||
@ -26,11 +26,11 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "test_utils/interactive_sync.h"
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
puts("Please hit any key and then ENTER to continue");
|
test_utils_interactive_sync();
|
||||||
getchar();
|
|
||||||
puts("5 x usleep(i++ * 500000)");
|
puts("5 x usleep(i++ * 500000)");
|
||||||
for (unsigned i = 0; i < 5; i++) {
|
for (unsigned i = 0; i < 5; i++) {
|
||||||
useconds_t us = i * 500000u;
|
useconds_t us = i * 500000u;
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from testrunner import run
|
from testrunner import run, test_utils_interactive_sync
|
||||||
|
|
||||||
US_PER_SEC = 1000000
|
US_PER_SEC = 1000000
|
||||||
EXTERNAL_JITTER = 0.15
|
EXTERNAL_JITTER = 0.15
|
||||||
@ -22,8 +22,7 @@ class InvalidTimeout(Exception):
|
|||||||
|
|
||||||
def testfunc(child):
|
def testfunc(child):
|
||||||
try:
|
try:
|
||||||
child.expect_exact("Please hit any key and then ENTER to continue")
|
test_utils_interactive_sync(child)
|
||||||
child.sendline("a")
|
|
||||||
start_test = time.time()
|
start_test = time.time()
|
||||||
child.expect_exact("5 x usleep(i++ * 500000)")
|
child.expect_exact("5 x usleep(i++ * 500000)")
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
|
|||||||
@ -6,8 +6,7 @@ TEST_ON_CI_WHITELIST += all
|
|||||||
# This test randomly fails on `native` so disable it from CI
|
# This test randomly fails on `native` so disable it from CI
|
||||||
TEST_ON_CI_BLACKLIST += native
|
TEST_ON_CI_BLACKLIST += native
|
||||||
|
|
||||||
# This application uses getchar and thus expects input from stdio
|
USEMODULE += test_utils_interactive_sync
|
||||||
USEMODULE += stdin
|
|
||||||
|
|
||||||
# Port and pin configuration for probing with oscilloscope
|
# Port and pin configuration for probing with oscilloscope
|
||||||
# Port number should be found in port enum e.g in cpu/include/periph_cpu.h
|
# Port number should be found in port enum e.g in cpu/include/periph_cpu.h
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
#include "timex.h"
|
#include "timex.h"
|
||||||
|
#include "test_utils/interactive_sync.h"
|
||||||
|
|
||||||
#define RUNS (5U)
|
#define RUNS (5U)
|
||||||
#define SLEEP_TIMES_NUMOF ARRAY_SIZE(sleep_times)
|
#define SLEEP_TIMES_NUMOF ARRAY_SIZE(sleep_times)
|
||||||
@ -61,8 +62,7 @@ int main(void)
|
|||||||
|
|
||||||
printf("Running test %u times with %u distinct sleep times\n", RUNS,
|
printf("Running test %u times with %u distinct sleep times\n", RUNS,
|
||||||
(unsigned)SLEEP_TIMES_NUMOF);
|
(unsigned)SLEEP_TIMES_NUMOF);
|
||||||
puts("Please hit any key and then ENTER to continue");
|
test_utils_interactive_sync();
|
||||||
getchar();
|
|
||||||
start_test = xtimer_now_usec();
|
start_test = xtimer_now_usec();
|
||||||
for (unsigned m = 0; m < RUNS; m++) {
|
for (unsigned m = 0; m < RUNS; m++) {
|
||||||
for (unsigned n = 0;
|
for (unsigned n = 0;
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from testrunner import run
|
from testrunner import run, test_utils_interactive_sync
|
||||||
|
|
||||||
|
|
||||||
US_PER_SEC = 1000000
|
US_PER_SEC = 1000000
|
||||||
@ -28,8 +28,7 @@ def testfunc(child):
|
|||||||
RUNS = int(child.match.group(1))
|
RUNS = int(child.match.group(1))
|
||||||
SLEEP_TIMES_NUMOF = int(child.match.group(2))
|
SLEEP_TIMES_NUMOF = int(child.match.group(2))
|
||||||
try:
|
try:
|
||||||
child.expect_exact(u"Please hit any key and then ENTER to continue")
|
test_utils_interactive_sync(child)
|
||||||
child.sendline(u"a")
|
|
||||||
start_test = time.time()
|
start_test = time.time()
|
||||||
for m in range(RUNS):
|
for m in range(RUNS):
|
||||||
for n in range(SLEEP_TIMES_NUMOF):
|
for n in range(SLEEP_TIMES_NUMOF):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user