Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/xtimer_drift: added test #9596

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/xtimer_drift/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/xtimer_drift/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
50 changes: 50 additions & 0 deletions tests/xtimer_drift/tests/01-run.py
Original file line number Diff line number Diff line change
@@ -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))