-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: test for prio inversion using msg_send_recv #9306
Open
haukepetersen
wants to merge
1
commit into
RIOT-OS:master
Choose a base branch
from
haukepetersen:add_test_priorityinversionmsg
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+228
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 nucleo-f042k6 | ||
|
||
USEMODULE += xtimer | ||
|
||
test: | ||
tests/01-run.py | ||
|
||
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,44 @@ | ||
NOTE | ||
==== | ||
THIS TEST WILL FAIL WHEN RUNNING RIOT USING THE DEFAULT CORE/KERNEL CONFIGURATION! | ||
|
||
TODO: merge the `core_priority_inheritance` module to enable priority | ||
inheritance and with this successfully pass this test. | ||
|
||
Expected result | ||
=============== | ||
When successful, you will see the 3 configured threads printing 6 different | ||
events in a defined order. If the test passes, the output should look like this: | ||
|
||
``` | ||
main(): This is RIOT! (Version: xxx) | ||
Test for showing priority inversion when using msg_send_receive | ||
|
||
If this tests succeeds, you should see 6 events appearing in order. | ||
The expected output should look like this: | ||
Event 1: t_low - waiting for incoming message | ||
Event 2: t_high - sending msg to t_low (msg_send_receive) | ||
Event 3: t_low - received message and do some quick work | ||
Event 4: t_mid - starting infinite loop, potentially starving others | ||
Event 5: t_low - sending reply | ||
Event 6: t_high - received reply | ||
|
||
TEST OUTPUT: | ||
Event 1: t_low - waiting for incoming message | ||
Event 2: t_high - sending msg to t_low (msg_send_receive) | ||
Event 3: t_low - received message and do some quick work | ||
Event 4: t_mid - starting infinite loop, potentially starving others | ||
Event 5: t_low - sending reply | ||
Event 6: t_high - received reply | ||
|
||
[SUCCESS] | ||
``` | ||
|
||
Background | ||
========== | ||
Priority inversion is a known problem in real-time systems, leading in certain | ||
constellations to lower priority threads indirectly blocking higher priority | ||
threads. This test constructs a simple scenario, where a high priority thread | ||
(`t_high`) is trying to `send_receive` a message to a low priority thread | ||
(`t_low`), but never gets a reply as a medium priority thread (`t_mid`) is never | ||
letting `t_mid` to be scheduled. |
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,152 @@ | ||
/* | ||
* Copyright (C) 2017 Technische Universität Berlin | ||
* 2017,2018 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 priority inheritance when using | ||
* nested msg_send_receive calls | ||
* | ||
* @author Thomas Geithner <thomas.geithner@dai-labor.de> | ||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de> | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdint.h> | ||
|
||
#include "thread.h" | ||
#include "msg.h" | ||
#include "xtimer.h" | ||
|
||
#define TICK_LEN (50UL * US_PER_MS) | ||
#define EXPECTED_RESULT (-3) | ||
|
||
#define T_NUMOF (3U) | ||
#define MSG_TYPE (0xabcd) | ||
|
||
enum { | ||
HIGH = 0, | ||
MID = 1, | ||
LOW = 2, | ||
}; | ||
|
||
static char _stacks[T_NUMOF][THREAD_STACKSIZE_MAIN]; | ||
static kernel_pid_t _pids[T_NUMOF]; | ||
static const char *_names[] = { "t_high", " t_mid", " t_low" }; | ||
|
||
static int _result = 0; | ||
static int _res_addsub = 1; | ||
|
||
static inline void _delay(unsigned ticks) | ||
{ | ||
xtimer_usleep(ticks * TICK_LEN); | ||
} | ||
|
||
static inline void _event(int num, const char *t_name, const char *msg) | ||
{ | ||
/* record event */ | ||
_result += (_res_addsub * num); | ||
_res_addsub *= -1; | ||
|
||
printf("Event %2i: %7s - %s\n", num, t_name, msg); | ||
} | ||
|
||
static void *t_high(void *arg) | ||
{ | ||
(void)arg; | ||
msg_t m; | ||
msg_t rply; | ||
|
||
m.type = MSG_TYPE; | ||
m.content.value = (uint32_t)'M'; | ||
|
||
_delay(1); | ||
|
||
_event(2, _names[HIGH], "sending msg to t_low (msg_send_receive)"); | ||
msg_send_receive(&m, &rply, _pids[2]); | ||
_event(6, _names[HIGH], "received reply"); | ||
|
||
return NULL; | ||
} | ||
|
||
static void *t_mid(void *arg) | ||
{ | ||
(void)arg; | ||
|
||
_delay(2); | ||
|
||
_event(4, _names[MID], "starting infinite loop, potentially starving others"); | ||
while (1) { | ||
thread_yield_higher(); | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
static void *t_low(void *arg) | ||
{ | ||
(void)arg; | ||
msg_t m; | ||
msg_t rply; | ||
|
||
rply.type = MSG_TYPE; | ||
rply.content.value = (uint32_t)'m'; | ||
|
||
_event(1, _names[LOW], "waiting for incoming message"); | ||
msg_receive(&m); | ||
_event(3, _names[LOW], "received message and do some quick work"); | ||
|
||
_delay(2); | ||
|
||
_event(5, _names[LOW], "sending reply"); | ||
msg_reply(&m, &rply); | ||
|
||
return NULL; | ||
} | ||
|
||
static thread_task_func_t _handlers[] = { t_high, t_mid, t_low }; | ||
|
||
int main(void) | ||
{ | ||
puts("Test for showing priority inversion when using msg_send_receive\n"); | ||
puts("If this tests succeeds, you should see 6 events appearing in order.\n" | ||
"The expected output should look like this:\n" | ||
"Event 1: t_low - waiting for incoming message\n" | ||
"Event 2: t_high - sending msg to t_low (msg_send_receive)\n" | ||
"Event 3: t_low - received message and do some quick work\n" | ||
"Event 4: t_mid - starting infinite loop, potentially starving others\n" | ||
"Event 5: t_low - sending reply\n" | ||
"Event 6: t_high - received reply\n"); | ||
|
||
puts("TEST OUTPUT:"); | ||
|
||
/* create threads */ | ||
for (unsigned i = 0; i < T_NUMOF; i++) { | ||
_pids[i] = thread_create(_stacks[i], sizeof(_stacks[i]), | ||
(THREAD_PRIORITY_MAIN + 1 + i), | ||
THREAD_CREATE_WOUT_YIELD, | ||
_handlers[i], NULL, | ||
_names[i]); | ||
} | ||
|
||
_delay(4); | ||
|
||
if (_result == EXPECTED_RESULT) { | ||
puts("\n[SUCCESS]"); | ||
} | ||
else { | ||
puts("\n[FAILED]"); | ||
} | ||
|
||
return 0; | ||
} |
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,22 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (C) 2018 Hauke Petersen <hauke.petersen@fu-berlin.de> | ||
# | ||
# 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 | ||
|
||
|
||
def testfunc(child): | ||
rt = child.expect([r"\[SUCCESS\]", r"\[FAILED\]"]) | ||
if rt == 1: | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner')) | ||
from testrunner import run | ||
sys.exit(run(testfunc)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please change the readme to reflect the recent changes in the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course