mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
tests/xtimer_mutex_lock_timeout: minimal xtimer_mutex_lock_timeout test
Adding a first normal test case where the mutex is unlocked and the timeout is long. The timer will not trigger in this test and instead wil be removed after getting the mutex.
This commit is contained in:
parent
1fff551d7c
commit
f207c6adc6
8
tests/xtimer_mutex_lock_timeout/Makefile
Normal file
8
tests/xtimer_mutex_lock_timeout/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += xtimer
|
||||
USEMODULE += shell
|
||||
|
||||
TEST_ON_CI_WHITELIST += all
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
92
tests/xtimer_mutex_lock_timeout/main.c
Normal file
92
tests/xtimer_mutex_lock_timeout/main.c
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 testing xtimer_mutex_lock_timeout function
|
||||
*
|
||||
*
|
||||
* @author Julian Holzwarth <julian.holzwarth@fu-berlin.de>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "shell.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
/* timeout at one millisecond (1000 us) to make sure it does not spin. */
|
||||
#define LONG_MUTEX_TIMEOUT 1000
|
||||
|
||||
/**
|
||||
* Foward declarations
|
||||
*/
|
||||
static int cmd_test_xtimer_mutex_lock_timeout_long_unlocked(int argc,
|
||||
char **argv);
|
||||
|
||||
/**
|
||||
* @brief List of command for this application.
|
||||
*/
|
||||
static const shell_command_t shell_commands[] = {
|
||||
{ "mutex_timeout_long_unlocked", "unlocked mutex with long timeout",
|
||||
cmd_test_xtimer_mutex_lock_timeout_long_unlocked, },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief shell command to test xtimer_mutex_lock_timeout
|
||||
*
|
||||
* the mutex is not locked before the function call and
|
||||
* the timer long. Meaning the timer will get removed
|
||||
* before triggering.
|
||||
*
|
||||
* @param[in] argc Number of arguments
|
||||
* @param[in] argv Array of arguments
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
static int cmd_test_xtimer_mutex_lock_timeout_long_unlocked(int argc,
|
||||
char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
puts("starting test: xtimer mutex lock timeout");
|
||||
mutex_t test_mutex = MUTEX_INIT;
|
||||
|
||||
if (xtimer_mutex_lock_timeout(&test_mutex, LONG_MUTEX_TIMEOUT) == 0) {
|
||||
/* mutex has to be locked */
|
||||
if (mutex_trylock(&test_mutex) == 0) {
|
||||
puts("OK");
|
||||
}
|
||||
else {
|
||||
puts("error mutex not locked");
|
||||
}
|
||||
}
|
||||
else {
|
||||
puts("error: mutex timed out");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief main function starting shell
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
puts("Starting shell...");
|
||||
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
||||
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
|
||||
|
||||
return 0;
|
||||
}
|
29
tests/xtimer_mutex_lock_timeout/tests/01-run.py
Executable file
29
tests/xtimer_mutex_lock_timeout/tests/01-run.py
Executable file
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2019 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.
|
||||
|
||||
# @author Julian Holzwarth <julian.holzwarth@fu-berlin.de>
|
||||
|
||||
import sys
|
||||
import pexpect
|
||||
from testrunner import run
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
# Try to wait for the shell
|
||||
for _ in range(0, 10):
|
||||
child.sendline("help")
|
||||
if child.expect_exact(["> ", pexpect.TIMEOUT], timeout=1) == 0:
|
||||
break
|
||||
child.sendline("mutex_timeout_long_unlocked")
|
||||
child.expect("starting test: xtimer mutex lock timeout")
|
||||
child.expect("OK")
|
||||
child.expect_exact("> ")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run(testfunc))
|
Loading…
Reference in New Issue
Block a user