From 1f3c0dc0cc821145f05f142a4f51a303fd238036 Mon Sep 17 00:00:00 2001 From: Josarn Date: Mon, 30 Apr 2018 13:46:39 +0200 Subject: [PATCH] tests/xtimer_periodic_wakeup: all states --- tests/xtimer_periodic_wakeup/main.c | 55 ++++++++++++++++---- tests/xtimer_periodic_wakeup/tests/01-run.py | 14 ++--- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/tests/xtimer_periodic_wakeup/main.c b/tests/xtimer_periodic_wakeup/main.c index a0497b3b37bc6..75ee7b67745bf 100644 --- a/tests/xtimer_periodic_wakeup/main.c +++ b/tests/xtimer_periodic_wakeup/main.c @@ -23,32 +23,52 @@ #include "periph_conf.h" #ifndef NUMOF -#define NUMOF (256) +#define NUMOF (2 * XTIMER_PERIODIC_SPIN + 22) #endif int32_t res[NUMOF]; int main(void) { - puts("xtimer_periodic_wakeup test application.\n"); + printf("xtimer_periodic_wakeup test application runs %d\n.", NUMOF ); - uint32_t interval = NUMOF; + uint32_t interval; int32_t max_diff = INT32_MIN; int32_t min_diff = INT32_MAX; - for (int i = 0; i < NUMOF; i++) { + /* Testing + * 1. interval with timer interrupt + * 2. interval with timer interrupt and relative time stamp */ + puts("xtimer_periodic_wakeup test timer interrupt."); + for (int i = 21; i >= 1; i--) { + interval = _xtimer_usec_from_ticks(XTIMER_PERIODIC_RELATIVE + 10 - i); + xtimer_ticks32_t now = xtimer_now(); + printf("Testing interval %" PRIu32 " ticks (now=%" PRIu32 ")\n", + _xtimer_ticks_from_usec(interval), now.ticks32); + xtimer_ticks32_t last_wakeup = xtimer_now(); + xtimer_ticks32_t before = last_wakeup; + xtimer_periodic_wakeup(&last_wakeup, interval); + now = xtimer_now(); + res[2 * XTIMER_PERIODIC_SPIN + i] = (now.ticks32 - before.ticks32) + - _xtimer_ticks_from_usec(interval); + } + + puts("\nxtimer_periodic_wakeup test spinning."); + /* Testing + * 3. spinning */ + for (int i = 2 * XTIMER_PERIODIC_SPIN; i >= 0; i--) { + interval = _xtimer_usec_from_ticks(i); xtimer_ticks32_t now = xtimer_now(); - printf("Testing interval %" PRIu32 "... (now=%" PRIu32 ")\n", interval, xtimer_usec_from_ticks(now)); + printf("Testing interval %" PRIu32 " ticks (now=%" PRIu32 ")\n", + _xtimer_ticks_from_usec(i), now.ticks32); xtimer_ticks32_t last_wakeup = xtimer_now(); xtimer_ticks32_t before = last_wakeup; xtimer_periodic_wakeup(&last_wakeup, interval); now = xtimer_now(); - res[i] = (xtimer_usec_from_ticks(now) - xtimer_usec_from_ticks(before)) - interval; - interval -= 1; + res[i] = (now.ticks32 - before.ticks32) - _xtimer_ticks_from_usec(interval); } for (int i = 0; i < NUMOF; i++) { - printf("%4d diff=%" PRIi32 "\n", NUMOF - i, res[i]); if (res[i] > max_diff) { max_diff = res[i]; @@ -56,15 +76,32 @@ int main(void) if (res[i] < min_diff) { min_diff = res[i]; } + + if (i == 0) { + puts("\n Results xtimer_periodic_wakeup test spinning."); + } + else if (i == 2 * XTIMER_PERIODIC_SPIN) { + puts("\n Results xtimer_periodic_wakeup test timer interrupt."); + } + + if (i < 2 * XTIMER_PERIODIC_SPIN) { + interval = _xtimer_ticks_from_usec(_xtimer_usec_from_ticks(i)); + printf("Interval %" PRIu32 " ticks diff=%" PRIi32 "\n", interval, res[i]); + } + else { + interval = XTIMER_PERIODIC_RELATIVE - 10 - 2 * XTIMER_PERIODIC_SPIN + i; + printf("Interval %" PRIu32 " ticks diff=%" PRIi32 "\n", interval, res[i]); + } } printf("\nMin/max error: %" PRId32 "/%" PRId32 "\n", min_diff, max_diff); if (min_diff < -1000 || max_diff > 1000) { puts("too large difference.\n"); - puts("Test Failed.\n"); + puts("[FAILED]"); return 1; } printf("\nTest complete.\n"); + puts("[SUCCESS]"); return 0; } diff --git a/tests/xtimer_periodic_wakeup/tests/01-run.py b/tests/xtimer_periodic_wakeup/tests/01-run.py index 6f243b1bdd51a..91207ca1d4c07 100755 --- a/tests/xtimer_periodic_wakeup/tests/01-run.py +++ b/tests/xtimer_periodic_wakeup/tests/01-run.py @@ -11,15 +11,17 @@ def testfunc(child): - child.expect_exact("xtimer_periodic_wakeup test application.") + child.expect(u"xtimer_periodic_wakeup test application runs (\\d+)") + SLEEP_TIMES_NUMOF = int(child.match.group(1)) - for i in range(256): - child.expect(u"Testing interval \d+... \(now=\d+\)") - for i in range(256): - child.expect(u" +\d+ diff=\d+") + for i in range(SLEEP_TIMES_NUMOF): + child.expect(u"Testing interval \\d+ ticks \(now=\\d+\)") + for i in range(SLEEP_TIMES_NUMOF): + child.expect(u"Interval \\d+ ticks diff=\\d+") - child.expect(u"Min/max error: \d+/\d+") + child.expect(u"Min/max error: \\d+/\\d+") child.expect_exact("Test complete.") + child.expect_exact("[SUCCESS]") if __name__ == "__main__":