tests: trickle: extend trickle test to print SUCCESS/FAILURE

This commit is contained in:
Cenk Gündoğan 2017-10-30 15:43:28 +01:00
parent b80cdd81d8
commit 22b9e6337b
2 changed files with 43 additions and 7 deletions

7
tests/trickle/README.md Normal file
View File

@ -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.

View File

@ -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;
}