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

tests/sched_change_priority: add test app

This commit is contained in:
Marian Buschsieweke 2021-11-01 12:43:02 +01:00
parent ed9bf358c5
commit 755652b6cf
No known key found for this signature in database
GPG Key ID: CB8E3238CE715A94
4 changed files with 141 additions and 0 deletions

View File

@ -0,0 +1,13 @@
include ../Makefile.tests_common
USEMODULE += nice
USEMODULE += ps
USEMODULE += shell
USEMODULE += shell_commands
# Use a terminal that does not introduce extra characters into the stream.
RIOT_TERMINAL ?= socat
APP_SHELL_FMT ?= NONE
include $(RIOTBASE)/Makefile.include

View File

@ -0,0 +1,9 @@
BOARD_INSUFFICIENT_MEMORY := \
arduino-duemilanove \
arduino-leonardo \
arduino-nano \
arduino-uno \
atmega328p \
atmega328p-xplained-mini \
nucleo-l011k4 \
#

View File

@ -0,0 +1,102 @@
/*
* Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
*
* 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 sched_change_priority / nice
*
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
*
* @}
*/
#include <stdio.h>
#include <stdlib.h>
#include "architecture.h"
#include "sched.h"
#include "shell.h"
#include "shell_commands.h"
#include "thread.h"
static int sc_hint(int argc, char **argv);
static WORD_ALIGNED char t2_stack[THREAD_STACKSIZE_TINY];
static WORD_ALIGNED char t3_stack[THREAD_STACKSIZE_DEFAULT];
static kernel_pid_t t3_pid;
static const shell_command_t cmds[] = {
{ "hint", "Display the correct invocation of nice for this teset", sc_hint },
{ NULL, NULL, NULL }
};
/*
* Note: An extra shell command just for displaying this hint is very much of
* an overkill for a human being, especially since the ps command already
* provides all the details. However, for automatic testing this makes it
* easy to extract the pid of t3 and the numeric value of
* THREAD_PRIORITY_MAIN - 1, resulting in more robust automatic testing.
* A shell command also has the convenient side effect of synchronizing
* with the shell.
*/
static int sc_hint(int argc, char **argv)
{
(void)argc;
(void)argv;
printf("Run \"nice %" PRIkernel_pid " %u\"\n",
t3_pid, (unsigned)THREAD_PRIORITY_MAIN - 1);
return EXIT_SUCCESS;
}
static void *t2_func(void *unused)
{
(void)unused;
while (1) {
/* blocking t3 from running with busy loop while t3 has lower prio than me */
}
return NULL;
}
static void *t3_func(void *unused)
{
(void)unused;
while (1) {
uint8_t prio = THREAD_PRIORITY_MAIN + 2;
printf("[t3] Setting my priority to THREAD_PRIORITY_MAIN + 2 = %u\n",
(unsigned)prio);
sched_change_priority(thread_get_active(), prio);
puts("[t3] Running again.");
}
return NULL;
}
int main(void)
{
thread_create(t2_stack, sizeof(t2_stack), THREAD_PRIORITY_MAIN + 1,
THREAD_CREATE_STACKTEST, t2_func, NULL, "t2");
t3_pid = thread_create(t3_stack, sizeof(t3_stack), THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST, t3_func, NULL, "t3");
puts("[main] Use shell command \"nice\" to increase prio of t3.\n"
"[main] If it works, it will run again. The \"hint\" cmd can be useful.");
char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(cmds, line_buf, SHELL_DEFAULT_BUFSIZE);
return 0;
}

View File

@ -0,0 +1,17 @@
#!/usr/bin/env python3
import sys
from testrunner import run
def testfunc(child):
child.sendline("hint")
child.expect(r"Run \"nice (\d+) (\d+)\"\r\n")
pid = int(child.match.group(1))
prio = int(child.match.group(2))
child.sendline("nice {} {}".format(pid, prio))
child.expect_exact('[t3] Running again.')
if __name__ == "__main__":
sys.exit(run(testfunc))