From c3f9c60eeb2e101ad6de638091de10d67a1d752d Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 30 Jan 2019 16:38:21 +0100 Subject: [PATCH] tests: add tests to reproduce #10881 --- tests/thread_msg_block_race/Makefile | 10 +++ tests/thread_msg_block_race/main.c | 99 ++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 tests/thread_msg_block_race/Makefile create mode 100644 tests/thread_msg_block_race/main.c diff --git a/tests/thread_msg_block_race/Makefile b/tests/thread_msg_block_race/Makefile new file mode 100644 index 0000000000000..25ad0a900146b --- /dev/null +++ b/tests/thread_msg_block_race/Makefile @@ -0,0 +1,10 @@ +include ../Makefile.tests_common + +BOARD_INSUFFICIENT_MEMORY := nucleo-f031k6 + +DISABLE_MODULE += auto_init +FEATURES_REQUIRED += periph_timer + +TEST_ON_CI_WHITELIST += all + +include $(RIOTBASE)/Makefile.include diff --git a/tests/thread_msg_block_race/main.c b/tests/thread_msg_block_race/main.c new file mode 100644 index 0000000000000..e3cf84dd9a072 --- /dev/null +++ b/tests/thread_msg_block_race/main.c @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2014 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 Thread test application + * + * @author Christian Mehlis + * @author Lotte Steenbrink + * + * @} + */ + +#include +#include + +#include "thread.h" +#include "msg.h" +#include "xtimer.h" + +#define CANARY_TYPE (0x21fd) + +#define TIMER_FREQ (1000000LU) +#define TIMER_TIMEOUT (1U) + +static char _t1_stack[THREAD_STACKSIZE_DEFAULT]; +static char _t2_stack[THREAD_STACKSIZE_DEFAULT]; + +static mutex_t _mutex = MUTEX_INIT_LOCKED; + +static kernel_pid_t _pid_main = KERNEL_PID_UNDEF; + +static void _timer(void *arg, int channel) +{ + (void)arg; + (void)channel; + /* do context switch */ + mutex_unlock(&_mutex); + timer_set(TIMER_DEV(0), 0, TIMER_TIMEOUT); +} + +static void *_thread1(void *arg) +{ + (void) arg; + + while (1) { + mutex_lock(&_mutex); + puts("nr1"); + } + + return NULL; +} + +static void *_thread2(void *arg) +{ + (void) arg; + + while (1) { + msg_t msg = { .type = 0U }; + + msg_try_send(&msg, _pid_main); + puts("nr2"); + } + + return NULL; +} + +int main(void) +{ + kernel_pid_t pid; + + timer_init(TIMER_DEV(0), TIMER_FREQ, _timer, NULL); + puts("Test is \"successful\" if it runs forever without crashing"); + _pid_main = sched_active_pid; + timer_set(TIMER_DEV(0), 0, TIMER_TIMEOUT); + pid = thread_create(_t1_stack, sizeof(_t1_stack), THREAD_PRIORITY_MAIN - 2, + THREAD_CREATE_STACKTEST, _thread1, NULL, "nr1"); + assert(pid != KERNEL_PID_UNDEF); + pid = thread_create(_t2_stack, sizeof(_t2_stack), THREAD_PRIORITY_MAIN - 1, + THREAD_CREATE_STACKTEST, _thread2, NULL, "nr2"); + assert(pid != KERNEL_PID_UNDEF); + + while (1) { + msg_t msg = { .type = CANARY_TYPE }; + + msg_receive(&msg); + assert(msg.type != CANARY_TYPE); + puts("main"); + } + return 0; +}