From 0f39c5549e853562a670fbebeb77606be85471ab Mon Sep 17 00:00:00 2001 From: Martine Lenders <m.lenders@fu-berlin.de> Date: Tue, 21 Mar 2017 12:13:11 +0100 Subject: [PATCH] tests: add test for evtimer underflow --- tests/evtimer_underflow/Makefile | 13 +++++ tests/evtimer_underflow/main.c | 75 +++++++++++++++++++++++++ tests/evtimer_underflow/tests/01-run.py | 29 ++++++++++ 3 files changed, 117 insertions(+) create mode 100644 tests/evtimer_underflow/Makefile create mode 100644 tests/evtimer_underflow/main.c create mode 100755 tests/evtimer_underflow/tests/01-run.py diff --git a/tests/evtimer_underflow/Makefile b/tests/evtimer_underflow/Makefile new file mode 100644 index 0000000000..fff087ba1d --- /dev/null +++ b/tests/evtimer_underflow/Makefile @@ -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 diff --git a/tests/evtimer_underflow/main.c b/tests/evtimer_underflow/main.c new file mode 100644 index 0000000000..4c8e008fa4 --- /dev/null +++ b/tests/evtimer_underflow/main.c @@ -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); + } + } +} diff --git a/tests/evtimer_underflow/tests/01-run.py b/tests/evtimer_underflow/tests/01-run.py new file mode 100755 index 0000000000..66c324239b --- /dev/null +++ b/tests/evtimer_underflow/tests/01-run.py @@ -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)) -- GitLab