tests: added test for mutex unlock order
parent
376874284b
commit
01137c5741
@ -0,0 +1,8 @@
|
||||
APPLICATION = mutex_order
|
||||
include ../Makefile.tests_common
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := stm32f0discovery weio
|
||||
|
||||
USEMODULE += xtimer
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
@ -0,0 +1,29 @@
|
||||
Expected result
|
||||
===============
|
||||
When successful, you should see 10 different threads printing their PID and
|
||||
priority. The thread with the lowest priority will print its status first,
|
||||
followed by the other threads in the order of their priority (highest next). The
|
||||
output should look like the following:
|
||||
|
||||
```
|
||||
main(): This is RIOT! (Version: xxx)
|
||||
Mutex order test
|
||||
Please refer to the README.md for more information
|
||||
|
||||
T3 (prio 6): locking mutex now
|
||||
T4 (prio 0): locking mutex now
|
||||
T5 (prio 4): locking mutex now
|
||||
T6 (prio 2): locking mutex now
|
||||
T7 (prio 1): locking mutex now
|
||||
T3 (prio 6): unlocking mutex now
|
||||
T4 (prio 0): unlocking mutex now
|
||||
T7 (prio 1): unlocking mutex now
|
||||
T6 (prio 2): unlocking mutex now
|
||||
T5 (prio 4): unlocking mutex now
|
||||
|
||||
Test END, check the order of priorities above.
|
||||
```
|
||||
|
||||
Background
|
||||
==========
|
||||
This test application stresses a mutex with a number of threads waiting on it.
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 Test application for testing mutexes
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "mutex.h"
|
||||
#include "thread.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
#define THREAD_NUMOF (5U)
|
||||
#define DELAY (10 * 1000U) /* 10ms */
|
||||
|
||||
extern volatile thread_t *sched_active_thread;
|
||||
|
||||
static char stacks[THREAD_NUMOF][THREAD_STACKSIZE_MAIN];
|
||||
|
||||
static const char prios[THREAD_NUMOF] = {THREAD_PRIORITY_MAIN - 1, 4, 0, 2, 1};
|
||||
|
||||
static mutex_t testlock;
|
||||
|
||||
static void *lockme(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
volatile thread_t *t = sched_active_thread;
|
||||
|
||||
printf("T%i (prio %i): locking mutex now\n",
|
||||
(int)t->pid, (int)t->priority);
|
||||
mutex_lock(&testlock);
|
||||
|
||||
xtimer_usleep(DELAY);
|
||||
|
||||
printf("T%i (prio %i): unlocking mutex now\n",
|
||||
(int)t->pid, (int)t->priority);
|
||||
mutex_unlock(&testlock);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("Mutex order test");
|
||||
puts("Please refer to the README.md for more information\n");
|
||||
|
||||
mutex_init(&testlock);
|
||||
|
||||
/* create threads */
|
||||
for (unsigned i = 0; i < THREAD_NUMOF; i++) {
|
||||
thread_create(stacks[i], sizeof(stacks[i]), prios[i], 0,
|
||||
lockme, NULL, "t");
|
||||
}
|
||||
|
||||
mutex_lock(&testlock);
|
||||
puts("\nTest END, check the order of priorities above.");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue