mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #6051 from OlegHahm/fix_test_mutex_order_readme
tests: mutex_order: updated test and fixed README
This commit is contained in:
commit
815426b0a1
@ -3,6 +3,4 @@ include ../Makefile.tests_common
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := stm32f0discovery weio nucleo-f030
|
||||
|
||||
USEMODULE += xtimer
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
@ -1,25 +1,25 @@
|
||||
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:
|
||||
When successful, you should see 5 different threads printing their PID and
|
||||
priority. 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). 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
|
||||
T3 (prio 6): trying to lock mutex now
|
||||
T4 (prio 4): trying to lock mutex now
|
||||
T5 (prio 0): trying to lock mutex now
|
||||
T6 (prio 2): trying to lock mutex now
|
||||
T7 (prio 1): trying to lock mutex now
|
||||
T5 (prio 0): unlocking mutex now
|
||||
T7 (prio 1): unlocking mutex now
|
||||
T6 (prio 2): unlocking mutex now
|
||||
T5 (prio 4): unlocking mutex now
|
||||
T4 (prio 4): unlocking mutex now
|
||||
T3 (prio 6): unlocking mutex now
|
||||
|
||||
Test END, check the order of priorities above.
|
||||
```
|
||||
|
@ -21,10 +21,8 @@
|
||||
|
||||
#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;
|
||||
|
||||
@ -39,14 +37,14 @@ static void *lockme(void *arg)
|
||||
(void)arg;
|
||||
volatile thread_t *t = sched_active_thread;
|
||||
|
||||
printf("T%i (prio %i): locking mutex now\n",
|
||||
printf("T%i (prio %i): trying to lock mutex now\n",
|
||||
(int)t->pid, (int)t->priority);
|
||||
mutex_lock(&testlock);
|
||||
|
||||
xtimer_usleep(DELAY);
|
||||
|
||||
printf("T%i (prio %i): unlocking mutex now\n",
|
||||
printf("T%i (prio %i): locked mutex now\n",
|
||||
(int)t->pid, (int)t->priority);
|
||||
|
||||
thread_yield();
|
||||
|
||||
mutex_unlock(&testlock);
|
||||
|
||||
return NULL;
|
||||
@ -59,11 +57,15 @@ int main(void)
|
||||
|
||||
mutex_init(&testlock);
|
||||
|
||||
/* lock mutex, so that spawned threads have to wait */
|
||||
mutex_lock(&testlock);
|
||||
/* create threads */
|
||||
for (unsigned i = 0; i < THREAD_NUMOF; i++) {
|
||||
thread_create(stacks[i], sizeof(stacks[i]), prios[i], 0,
|
||||
lockme, NULL, "t");
|
||||
}
|
||||
/* allow threads to lock the mutex */
|
||||
mutex_unlock(&testlock);
|
||||
|
||||
mutex_lock(&testlock);
|
||||
puts("\nTest END, check the order of priorities above.");
|
||||
|
35
tests/mutex_order/tests/01-run.py
Executable file
35
tests/mutex_order/tests/01-run.py
Executable file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
# Copyright (C) 2016 Oliver Hahm <oliver.hahm@inria.fr>
|
||||
#
|
||||
# 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.
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
|
||||
import testrunner
|
||||
|
||||
thread_prio = {
|
||||
3: 6,
|
||||
4: 4,
|
||||
5: 0,
|
||||
6: 2,
|
||||
7: 1
|
||||
}
|
||||
|
||||
def testfunc(child):
|
||||
for k in thread_prio.keys():
|
||||
child.expect(u"T%i \(prio %i\): trying to lock mutex now" % (k, thread_prio[k]))
|
||||
|
||||
last = -1
|
||||
for i in range(len(thread_prio)):
|
||||
child.expect(u"T\d+ \(prio (\d+)\): locked mutex now")
|
||||
assert(int(child.match.group(1)) > last)
|
||||
last = int(child.match.group(1))
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(testrunner.run(testfunc))
|
Loading…
Reference in New Issue
Block a user