forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add tests to reproduce RIOT-OS#10881
- Loading branch information
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |