diff --git a/tests/xtimer_drift/Makefile b/tests/xtimer_drift/Makefile index 0a59269b7140..008983f92791 100644 --- a/tests/xtimer_drift/Makefile +++ b/tests/xtimer_drift/Makefile @@ -2,6 +2,10 @@ include ../Makefile.tests_common BOARD_INSUFFICIENT_MEMORY := nucleo-f031k6 nucleo-f042k6 +FEATURES_REQUIRED += periph_gpio USEMODULE += xtimer include $(RIOTBASE)/Makefile.include + +test: + tests/01-run.py diff --git a/tests/xtimer_drift/main.c b/tests/xtimer_drift/main.c index 814800e575de..e46624c5fe91 100644 --- a/tests/xtimer_drift/main.c +++ b/tests/xtimer_drift/main.c @@ -116,9 +116,9 @@ void *worker_thread(void *arg) expected = last + TEST_HZ * TEST_INTERVAL; int32_t jitter = now - expected; printf("now=%" PRIu32 ".%06" PRIu32 " (0x%08" PRIx32 " ticks), ", - sec, us, ticks.ticks32); + sec, us, ticks.ticks32); printf("drift=%" PRId32 " us, jitter=%" PRId32 " us\n", - drift, jitter); + drift, jitter); last = now; } ++loop_counter; diff --git a/tests/xtimer_drift/tests/01-run.py b/tests/xtimer_drift/tests/01-run.py new file mode 100755 index 000000000000..426066850caa --- /dev/null +++ b/tests/xtimer_drift/tests/01-run.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2017 HAW Hamburg +# +# 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 time + +HOST_JITTER = 0.1 +TEST_INTERVAL_LOWER = 1 - HOST_JITTER +TEST_INTERVAL_UPPER = 1 + HOST_JITTER + + +class InvalidTimeout(Exception): + pass + + +def testfunc(child): + error = 0 + + child.expect_exact(u"[START]") + child.expect(u"\r\n") + child.expect(u"now=(([0-9]*[.])?[0-9]+) .+ us\r\n") + start = time.time() + try: + while 1: + child.expect(u"now=(([0-9]*[.])?[0-9]+) .+ us\r\n") + end = time.time() + delta = end - start + start = time.time() + timestamp = float(child.match.group(1)) + if (delta < TEST_INTERVAL_LOWER) or (delta > TEST_INTERVAL_UPPER): + error = error + 1 + print("{}: Invalid timebetween messages, expected {} < {} < {}" + .format(timestamp, TEST_INTERVAL_LOWER, delta, TEST_INTERVAL_UPPER)) + # if error > 20: + # raise InvalidTimeout("20 times Invalid time between messages") + except InvalidTimeout as e: + print(e) + sys.exit(1) + + +if __name__ == "__main__": + sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner')) + from testrunner import run + sys.exit(run(testfunc))