From cfe5eacd2d13a799c2d613f2140a0a407cdd70f5 Mon Sep 17 00:00:00 2001 From: Vincent Dupont Date: Thu, 11 May 2017 10:04:05 +0200 Subject: [PATCH] tests: add a test app for schedstatistics --- tests/ps_schedstatistics/Makefile | 16 ++++++++ tests/ps_schedstatistics/main.c | 65 +++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 tests/ps_schedstatistics/Makefile create mode 100644 tests/ps_schedstatistics/main.c diff --git a/tests/ps_schedstatistics/Makefile b/tests/ps_schedstatistics/Makefile new file mode 100644 index 000000000..adfd70592 --- /dev/null +++ b/tests/ps_schedstatistics/Makefile @@ -0,0 +1,16 @@ +APPLICATION = ps_schedstatistics +include ../Makefile.tests_common + +BOARD_INSUFFICIENT_MEMORY := chronos msb-430 msb-430h nucleo-f030 nucleo-l053 \ + nucleo32-f031 nucleo32-f042 nucleo32-l031 \ + stm32f0discovery telosb weio wsn430-v1_3b \ + wsn430-v1_4 z1 + +CFLAGS += -DDEVELHELP +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += ps +USEMODULE += schedstatistics +USEMODULE += printf_float + +include $(RIOTBASE)/Makefile.include diff --git a/tests/ps_schedstatistics/main.c b/tests/ps_schedstatistics/main.c new file mode 100644 index 000000000..3d404a1d7 --- /dev/null +++ b/tests/ps_schedstatistics/main.c @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2017 OTA keys S.A. + * + * 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 ps schedstatistics test app + * + * @author Vincent Dupont + * + * @} + */ + +#include +#include + +#include +#include +#include + +#define NB_THREADS 5 + +static char stacks[NB_THREADS][THREAD_STACKSIZE_DEFAULT]; +static kernel_pid_t pids[NB_THREADS]; + +static void *_thread_fn(void *arg) +{ + int next = (int)arg < NB_THREADS - 1 ? (int)arg + 1 : 0; + msg_t msg; + + printf("Creating thread #%d, next=%d\n", (int)arg, next); + + while (1) { + msg_receive(&msg); + xtimer_usleep(XTIMER_BACKOFF - 1); + xtimer_usleep(2 * XTIMER_BACKOFF); + msg_send(&msg, pids[next]); + } + + return NULL; +} + +int main(void) +{ + for (int i = 0; i < NB_THREADS; i++) { + pids[i] = thread_create(stacks[i], sizeof(stacks[i]), + THREAD_PRIORITY_MAIN + 1, + THREAD_CREATE_STACKTEST, + _thread_fn, (void *)i, "thread"); + } + + + msg_t msg; + msg_send(&msg, pids[0]); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); +}