mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-25 06:23:53 +01:00
tests/evtimer_msg: modify test to delete entries
The evtimer_msg test is expanded to also delete entries. Furthermore the messages that are printed should now show numbers that are very close (if not equal). Something like this: At 740 ms received msg 0: "#2 supposed to be 740" At 1081 ms received msg 1: "#0 supposed to be 1081" At 1581 ms received msg 2: "#1 supposed to be 1581" At 4035 ms received msg 3: "#3 supposed to be 4035" The function evtimer_print is also called to show the intermediate status of evtimer entries.
This commit is contained in:
parent
d2cd666841
commit
ea11de5258
@ -27,14 +27,20 @@
|
||||
|
||||
static char worker_stack[THREAD_STACKSIZE_MAIN];
|
||||
static evtimer_t evtimer;
|
||||
static evtimer_msg_event_t events[] = {
|
||||
{ .event = { .offset = 1000 }, .msg = { .content = { .ptr = "supposed to be 1000" } } },
|
||||
{ .event = { .offset = 1500 }, .msg = { .content = { .ptr = "supposed to be 1500" } } },
|
||||
{ .event = { .offset = 659 }, .msg = { .content = { .ptr = "supposed to be 659" } } },
|
||||
{ .event = { .offset = 3954 }, .msg = { .content = { .ptr = "supposed to be 3954" } } },
|
||||
#define NEVENTS (unsigned)(4)
|
||||
/*
|
||||
* The events (.offset) are modified by evtimer_add.
|
||||
* This list of offsets is used to populate the events
|
||||
* before adding (or re-adding).
|
||||
*/
|
||||
static uint32_t offsets[NEVENTS] = {
|
||||
1000,
|
||||
1500,
|
||||
659,
|
||||
3954,
|
||||
};
|
||||
|
||||
#define NEVENTS ((unsigned)(sizeof(events) / sizeof(evtimer_msg_event_t)))
|
||||
static evtimer_msg_event_t events[NEVENTS];
|
||||
static char texts[NEVENTS][40];
|
||||
|
||||
/* This thread will print the drift to stdout once per second */
|
||||
void *worker_thread(void *arg)
|
||||
@ -56,7 +62,7 @@ void *worker_thread(void *arg)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint32_t now = xtimer_now_usec() / US_PER_MS;
|
||||
uint32_t now;
|
||||
|
||||
evtimer_init_msg(&evtimer);
|
||||
|
||||
@ -65,11 +71,47 @@ int main(void)
|
||||
THREAD_PRIORITY_MAIN - 1,
|
||||
THREAD_CREATE_STACKTEST,
|
||||
worker_thread, NULL, "worker");
|
||||
printf("Testing generic evtimer (start time = %" PRIu32 " ms)\n", now);
|
||||
|
||||
printf("Testing generic evtimer\n");
|
||||
|
||||
/* Add all the events */
|
||||
for (unsigned i = 0; i < NEVENTS; i++) {
|
||||
events[i].event.offset = offsets[i];
|
||||
now = xtimer_now_usec() / US_PER_MS;
|
||||
snprintf(texts[i], sizeof(texts[i]) - 1, "#%u supposed to be %" PRIu32, i, now + events[i].event.offset);
|
||||
events[i].msg.content.ptr = texts[i];
|
||||
evtimer_add_msg(&evtimer, &events[i], pid);
|
||||
}
|
||||
|
||||
/* Delete all the events */
|
||||
/* First we delete the last, to test deleting the last */
|
||||
/* Then we delete the first, to test deleting the first */
|
||||
evtimer_del(&evtimer, &events[3].event);
|
||||
evtimer_del(&evtimer, &events[2].event);
|
||||
printf("This should list %u items\n", NEVENTS - 2);
|
||||
evtimer_print(&evtimer);
|
||||
|
||||
/* Delete the remaining entries */
|
||||
for (unsigned i = 0; i < NEVENTS; i++) {
|
||||
evtimer_del(&evtimer, &events[i].event);
|
||||
}
|
||||
|
||||
/* Add all the events, again */
|
||||
for (unsigned i = 0; i < NEVENTS; i++) {
|
||||
events[i].event.offset = offsets[i];
|
||||
now = xtimer_now_usec() / US_PER_MS;
|
||||
snprintf(texts[i], sizeof(texts[i]) - 1, "#%u supposed to be %" PRIu32, i, now + events[i].event.offset);
|
||||
events[i].msg.content.ptr = texts[i];
|
||||
evtimer_add_msg(&evtimer, &events[i], pid);
|
||||
}
|
||||
printf("This should list %u items\n", NEVENTS);
|
||||
evtimer_print(&evtimer);
|
||||
|
||||
printf("Are the reception times of all %u msgs close to the supposed values?\n",
|
||||
NEVENTS);
|
||||
|
||||
/* The last offset is the largest, wait for it and a tiny bit more */
|
||||
xtimer_usleep((offsets[3] + 10) * US_PER_MS);
|
||||
puts("By now all msgs should have been received");
|
||||
puts("If yes, the tests were successful");
|
||||
}
|
||||
|
||||
@ -10,20 +10,20 @@ from __future__ import print_function
|
||||
import sys
|
||||
from testrunner import run
|
||||
|
||||
ACCEPTED_ERROR = 20
|
||||
ACCEPTED_ERROR = 2
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
child.expect(r"Testing generic evtimer \(start time = (\d+) ms\)")
|
||||
timer_offset = int(child.match.group(1))
|
||||
child.expect(r"Testing generic evtimer")
|
||||
child.expect(r"Are the reception times of all (\d+) msgs close to the supposed values?")
|
||||
numof = int(child.match.group(1))
|
||||
|
||||
for i in range(numof):
|
||||
child.expect(r'At \s*(\d+) ms received msg %i: "supposed to be (\d+)"' % i)
|
||||
child.expect(r'At \s*(\d+) ms received msg %i: "#\d+ supposed to be (\d+)"' % i)
|
||||
# check if output is correct
|
||||
exp = int(child.match.group(2)) + timer_offset
|
||||
assert(int(child.match.group(1)) in range(exp - ACCEPTED_ERROR, exp + ACCEPTED_ERROR + 1))
|
||||
expected = int(child.match.group(2))
|
||||
actual = int(child.match.group(1))
|
||||
assert(actual in range(expected - ACCEPTED_ERROR, expected + ACCEPTED_ERROR))
|
||||
print(".", end="", flush=True)
|
||||
print("")
|
||||
print("All tests successful")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user