tests: add test for evtimer underflow
This commit is contained in:
parent
15732bede6
commit
0f39c5549e
13
tests/evtimer_underflow/Makefile
Normal file
13
tests/evtimer_underflow/Makefile
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
APPLICATION = evtimer_msg
|
||||||
|
include ../Makefile.tests_common
|
||||||
|
|
||||||
|
BOARD_INSUFFICIENT_MEMORY := nucleo32-f031 nucleo32-f042
|
||||||
|
|
||||||
|
USEMODULE += evtimer
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
|
||||||
|
test:
|
||||||
|
# `testrunner` calls `make term` recursively, results in duplicated `TERMFLAGS`.
|
||||||
|
# So clears `TERMFLAGS` before run.
|
||||||
|
TERMFLAGS= tests/01-run.py
|
||||||
75
tests/evtimer_underflow/main.c
Normal file
75
tests/evtimer_underflow/main.c
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Freie Universität Berlin
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup tests
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief evtimer_msg test application
|
||||||
|
*
|
||||||
|
* @author Martine Lenders <m.lenders@fu-berlin.de>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "evtimer_msg.h"
|
||||||
|
#include "thread.h"
|
||||||
|
#include "msg.h"
|
||||||
|
|
||||||
|
#define WORKER_MSG_QUEUE_SIZE (8)
|
||||||
|
|
||||||
|
msg_t worker_msg_queue[WORKER_MSG_QUEUE_SIZE];
|
||||||
|
static char worker_stack[THREAD_STACKSIZE_MAIN];
|
||||||
|
static evtimer_t evtimer;
|
||||||
|
static evtimer_msg_event_t events[] = {
|
||||||
|
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "1" } } },
|
||||||
|
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "2" } } },
|
||||||
|
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "3" } } },
|
||||||
|
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "4" } } },
|
||||||
|
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "5" } } },
|
||||||
|
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "6" } } },
|
||||||
|
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "7" } } },
|
||||||
|
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "8" } } },
|
||||||
|
};
|
||||||
|
|
||||||
|
#define NEVENTS (sizeof(events) / sizeof(evtimer_msg_event_t))
|
||||||
|
|
||||||
|
/* This thread will print the drift to stdout once per second */
|
||||||
|
void *worker_thread(void *arg)
|
||||||
|
{
|
||||||
|
(void) arg;
|
||||||
|
|
||||||
|
msg_init_queue(worker_msg_queue, WORKER_MSG_QUEUE_SIZE);
|
||||||
|
while (1) {
|
||||||
|
char *ctx;
|
||||||
|
msg_t m;
|
||||||
|
|
||||||
|
msg_receive(&m);
|
||||||
|
ctx = m.content.ptr;
|
||||||
|
printf("received msg \"%s\"\n", ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
evtimer_init_msg(&evtimer);
|
||||||
|
|
||||||
|
/* create worker thread */
|
||||||
|
kernel_pid_t pid = thread_create(worker_stack, sizeof(worker_stack),
|
||||||
|
THREAD_PRIORITY_MAIN - 1,
|
||||||
|
THREAD_CREATE_STACKTEST,
|
||||||
|
worker_thread, NULL, "worker");
|
||||||
|
while (1) {
|
||||||
|
for (unsigned i = 0; i < NEVENTS; i++) {
|
||||||
|
evtimer_add_msg(&evtimer, &events[i], pid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
tests/evtimer_underflow/tests/01-run.py
Executable file
29
tests/evtimer_underflow/tests/01-run.py
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# Copyright (C) 2016 Freie Universität Berlin
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
|
||||||
|
import testrunner
|
||||||
|
|
||||||
|
how_many = 100
|
||||||
|
|
||||||
|
def testfunc(child):
|
||||||
|
for i in range(how_many):
|
||||||
|
for j in range(8):
|
||||||
|
child.expect(r'received msg "%i"' % (j + 1))
|
||||||
|
print(".", end="", flush=True)
|
||||||
|
print("")
|
||||||
|
print("Stopped after %i iterations, but should run forever." % how_many)
|
||||||
|
print("=> All tests successful")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(testrunner.run(testfunc, echo=False))
|
||||||
Loading…
x
Reference in New Issue
Block a user