diff --git a/tests/trickle/README.md b/tests/trickle/README.md new file mode 100644 index 0000000000..e9e7ad8bb0 --- /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 6b6c948467..9ead2fde64 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; }