1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/rmutex: clean up test and reduce stack size

This results in a few more boards being able to run the test.
Also, the wording in the README.md is improved.
This commit is contained in:
Marian Buschsieweke 2023-02-22 09:22:30 +01:00
parent cf540a2648
commit 0620ac68ff
No known key found for this signature in database
GPG Key ID: CB8E3238CE715A94
3 changed files with 16 additions and 21 deletions

View File

@ -5,19 +5,10 @@ BOARD_INSUFFICIENT_MEMORY := \
arduino-uno \
atmega328p \
atmega328p-xplained-mini \
bluepill-stm32f030c8 \
i-nucleo-lrwan1 \
nucleo-f030r8 \
nucleo-f031k6 \
nucleo-f042k6 \
nucleo-l011k4 \
nucleo-l031k6 \
nucleo-l053r8 \
samd10-xmini \
slstk3400a \
stk3200 \
stm32f030f4-demo \
stm32f0discovery \
stm32g0316-disco \
stm32l0538-disco \
#

View File

@ -5,7 +5,8 @@ When successful, you should see 5 different threads printing their
PID, priority and recursion depth. The thread with the lowest priority
should be able to lock (and unlock) the mutex first, followed by the
other threads in the order of their priority (highest next). If two
threads have the same priority the lower thread id should acquire the
threads have the same priority the thread who comes first in the run queue
(in this test this is the one with the lower thread id) should acquire the
lock. The output should look like the following:
```

View File

@ -18,6 +18,8 @@
* @}
*/
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "rmutex.h"
@ -25,38 +27,39 @@
#define THREAD_NUMOF (5U)
static char stacks[THREAD_NUMOF][THREAD_STACKSIZE_MAIN];
static char stacks[THREAD_NUMOF][THREAD_STACKSIZE_SMALL + THREAD_EXTRA_STACKSIZE_PRINTF];
static const char prios[THREAD_NUMOF] = {THREAD_PRIORITY_MAIN - 1, 4, 5, 2, 4};
static const char depth[THREAD_NUMOF] = {5, 3, 3, 4, 5};
static const uint8_t prios[THREAD_NUMOF] = {THREAD_PRIORITY_MAIN - 1, 4, 5, 2, 4};
static const uint8_t depth[THREAD_NUMOF] = {5, 3, 3, 4, 5};
static rmutex_t testlock;
static void lock_recursive(char n, char depth)
static void lock_recursive(uint8_t current_depth, uint8_t max_depth)
{
thread_t *t = thread_get_active();
printf("T%i (prio %i, depth %i): trying to lock rmutex now\n",
(int)t->pid, (int)t->priority, (int)n);
(int)t->pid, (int)t->priority, (int)current_depth);
rmutex_lock(&testlock);
printf("T%i (prio %i, depth %i): locked rmutex now\n",
(int)t->pid, (int)t->priority, (int)n);
(int)t->pid, (int)t->priority, (int)current_depth);
if (n + 1 < depth)
lock_recursive(n + 1, depth);
if (current_depth + 1 < max_depth) {
lock_recursive(current_depth + 1, max_depth);
}
thread_yield();
rmutex_unlock(&testlock);
printf("T%i (prio %i, depth %i): unlocked rmutex\n",
(int)t->pid, (int)t->priority, (int)n);
(int)t->pid, (int)t->priority, (int)current_depth);
}
static void *lockme(void *arg)
{
intptr_t depth = (intptr_t)arg;
uintptr_t depth = (uintptr_t)arg;
lock_recursive(0, depth);
@ -75,7 +78,7 @@ int main(void)
/* create threads */
for (unsigned i = 0; i < THREAD_NUMOF; i++) {
thread_create(stacks[i], sizeof(stacks[i]), prios[i], 0,
lockme, (void*)(intptr_t)depth[i], "t");
lockme, (void*)(intptr_t)depth[i], "t");
}
/* allow threads to lock the mutex */
printf("main: unlocking recursive mutex\n");