diff --git a/tests/trickle/Makefile b/tests/trickle/Makefile index 3c25ff48c03873888045e4e45a78e61a898411af..c8c377c3465487de20fcb23ddd3049781d79f006 100644 --- a/tests/trickle/Makefile +++ b/tests/trickle/Makefile @@ -4,3 +4,6 @@ include ../Makefile.tests_common USEMODULE += trickle include $(RIOTBASE)/Makefile.include + +test: + tests/01-run.py diff --git a/tests/trickle/README.md b/tests/trickle/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e9e7ad8bb0680ec87cec057ebb734eacb8370802 --- /dev/null +++ b/tests/trickle/README.md @@ -0,0 +1,7 @@ +# Trickle Test + +This test starts a trickle timer and roughly checks the diff between two +intervals to be greater than the diff of previous intervals. +After `5` callbacks, the trickle timer is reset and ends after another `7` +callbacks with either `[SUCCESS]` or `[FAILURE]`. The application exits with +`[FAILURE]` as soon as one diff is *not* greater than the previous diff. diff --git a/tests/trickle/main.c b/tests/trickle/main.c index 6b6c94846776a97a38d6e72573eed9d3675b9017..9ead2fde64cf8c3287ca46bfe0ccc9803a7e5f34 100644 --- a/tests/trickle/main.c +++ b/tests/trickle/main.c @@ -24,18 +24,32 @@ #include "thread.h" #include "msg.h" -#define Q_LEN (8) #define TRICKLE_MSG (0xfeef) #define TR_IMIN (8) #define TR_IDOUBLINGS (20) #define TR_REDCONST (10) +#define FIRST_ROUND (5) +#define SECOND_ROUND (12) -static msg_t _msg_q[Q_LEN]; +static uint32_t prev_now = 0, prev_diff = 0; +static bool error = false; static void callback(void *args) { (void) args; - printf("now: %" PRIu32 "\n", xtimer_now_usec()); + uint32_t now = xtimer_now_usec(); + uint32_t diff = (uint32_t) (now - prev_now); + + printf("now = %" PRIu32 ", prev_now = %" PRIu32 ", diff = %" PRIu32 + "\n", now, prev_now, diff); + + if (prev_diff >= diff) { + error = true; + } + + prev_now = now; + prev_diff = diff; + return; } @@ -45,13 +59,26 @@ static trickle_t trickle = { .callback.func = &callback, int main(void) { msg_t msg; - - msg_init_queue(_msg_q, Q_LEN); + unsigned counter = 0; trickle_start(sched_active_pid, &trickle, TRICKLE_MSG, TR_IMIN, TR_IDOUBLINGS, TR_REDCONST); - while (1) { + puts("[START]"); + + while (!error) { + if (counter == FIRST_ROUND) { + prev_diff = 0; + trickle_reset_timer(&trickle); + puts("[TRICKLE_RESET]"); + } + else if (counter == SECOND_ROUND) { + puts("[SUCCESS]"); + return 0; + } + + counter++; + msg_receive(&msg); switch (msg.type) { @@ -63,5 +90,7 @@ int main(void) } } - return 0; + puts("[FAILURE]"); + + return 1; } diff --git a/tests/trickle/tests/01-run.py b/tests/trickle/tests/01-run.py new file mode 100755 index 0000000000000000000000000000000000000000..ed0d8aa28e90810291df8c5ad93bfbefce5bb301 --- /dev/null +++ b/tests/trickle/tests/01-run.py @@ -0,0 +1,29 @@ +#!/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 + +sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner')) +import testrunner + +def testfunc(child): + child.expect_exact("[START]") + + for i in range(5): + child.expect(u"now = \d+, prev_now = \d+, diff = \d+") + + child.expect_exact("[TRICKLE_RESET]") + + for i in range(7): + child.expect(u"now = \d+, prev_now = \d+, diff = \d+") + + child.expect_exact("[SUCCESS]") + +if __name__ == "__main__": + sys.exit(testrunner.run(testfunc))