Skip to content

Commit

Permalink
tests: add tests to reproduce RIOT-OS#10881
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Jan 30, 2019
1 parent 21dda94 commit c3f9c60
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/thread_msg_block_race/Makefile
Original file line number Diff line number Diff line change
@@ -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
99 changes: 99 additions & 0 deletions tests/thread_msg_block_race/main.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* @author Lotte Steenbrink <[email protected]>
*
* @}
*/

#include <stdio.h>
#include <string.h>

#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;
}

0 comments on commit c3f9c60

Please sign in to comment.