From 825ffddbf9f0bb47a800e99cbed50a5839158ec3 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 8 Jun 2020 17:04:58 +0200 Subject: [PATCH] sys/test_utils/dummy_thread: initial commit This commit adds a module that just creates a thread that does nothing, at boot time, in auto_init(). --- sys/Makefile | 3 ++ sys/auto_init/auto_init.c | 4 ++ sys/test_utils/dummy_thread/Makefile | 1 + sys/test_utils/dummy_thread/dummy_thread.c | 57 ++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 sys/test_utils/dummy_thread/Makefile create mode 100644 sys/test_utils/dummy_thread/dummy_thread.c diff --git a/sys/Makefile b/sys/Makefile index 0321b81dec..19f289758e 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -31,6 +31,9 @@ endif ifneq (,$(filter test_utils_interactive_sync,$(USEMODULE))) DIRS += test_utils/interactive_sync endif +ifneq (,$(filter dummy_thread,$(USEMODULE))) + DIRS += test_utils/dummy_thread +endif ifneq (,$(filter net_help,$(USEMODULE))) DIRS += net/crosslayer/net_help endif diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 406b4255b6..628649afbd 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -49,6 +49,10 @@ void auto_init(void) extern void init_schedstatistics(void); init_schedstatistics(); } + if (IS_USED(MODULE_DUMMY_THREAD)) { + extern void dummy_thread_create(void); + dummy_thread_create(); + } if (IS_USED(MODULE_EVENT_THREAD)) { LOG_DEBUG("Auto init event threads.\n"); extern void auto_init_event_thread(void); diff --git a/sys/test_utils/dummy_thread/Makefile b/sys/test_utils/dummy_thread/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/sys/test_utils/dummy_thread/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/sys/test_utils/dummy_thread/dummy_thread.c b/sys/test_utils/dummy_thread/dummy_thread.c new file mode 100644 index 0000000000..e7312a9149 --- /dev/null +++ b/sys/test_utils/dummy_thread/dummy_thread.c @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2020 Kaspar Schleiser + * Freie Universität Berlin + * Inria + * + * 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 sys + * @{ + * + * @file + * @brief Module creating a dummy thread + * + * This module can be used to mess up the number of threads a bit, e.g., for + * testing test scripts. + * + * This module can be used by manually adding it to the command line when + * building, e.g., + * + * USEMODULE+=dummy_thread make -C tests/rmutex + * make -C tests/rmutex test + * + * Note how the output of the test changes compared to a build without + * dummy_thread. + * + * @author Kaspar Schleiser + * + * @} + */ + +#include "thread.h" + +static char _dummy_stack[THREAD_STACKSIZE_IDLE]; + +static void *_dummy_thread(void *arg) +{ + (void)arg; + while (1) { + thread_sleep(); + } + + return NULL; +} + +void dummy_thread_create(void) +{ + thread_create(_dummy_stack, sizeof(_dummy_stack), + THREAD_PRIORITY_IDLE, + THREAD_CREATE_WOUT_YIELD \ + | THREAD_CREATE_STACKTEST \ + | THREAD_CREATE_SLEEPING, + _dummy_thread, NULL, "dummy"); +}