tests/xtimer_mutex_lock_timeout: new test for mutex locked
New test function cmd_test_xtimer_mutex_lock_timeout_long_locked. In this test the mutex is locked and the timeout is long. When it works the thread continues running and stops waiting for the mutex and the function will return that it did not get the mutex.
This commit is contained in:
parent
f207c6adc6
commit
b3d2324ccf
@ -31,6 +31,8 @@
|
||||
*/
|
||||
static int cmd_test_xtimer_mutex_lock_timeout_long_unlocked(int argc,
|
||||
char **argv);
|
||||
static int cmd_test_xtimer_mutex_lock_timeout_long_locked(int argc,
|
||||
char **argv);
|
||||
|
||||
/**
|
||||
* @brief List of command for this application.
|
||||
@ -38,6 +40,8 @@ static int cmd_test_xtimer_mutex_lock_timeout_long_unlocked(int argc,
|
||||
static const shell_command_t shell_commands[] = {
|
||||
{ "mutex_timeout_long_unlocked", "unlocked mutex with long timeout",
|
||||
cmd_test_xtimer_mutex_lock_timeout_long_unlocked, },
|
||||
{ "mutex_timeout_long_locked", "locked mutex with long timeout",
|
||||
cmd_test_xtimer_mutex_lock_timeout_long_locked, },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
@ -77,6 +81,43 @@ static int cmd_test_xtimer_mutex_lock_timeout_long_unlocked(int argc,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief shell command to test xtimer_mutex_lock_timeout
|
||||
*
|
||||
* the mutex is locked before the function call and
|
||||
* the timer long. Meaning the timer will trigger
|
||||
* and remove the thread from the mutex waiting list.
|
||||
*
|
||||
* @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_locked(int argc,
|
||||
char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
puts("starting test: xtimer mutex lock timeout");
|
||||
mutex_t test_mutex = MUTEX_INIT;
|
||||
mutex_lock(&test_mutex);
|
||||
|
||||
if (xtimer_mutex_lock_timeout(&test_mutex, LONG_MUTEX_TIMEOUT) == 0) {
|
||||
puts("Error: mutex taken");
|
||||
}
|
||||
else {
|
||||
/* mutex has to be locked */
|
||||
if (mutex_trylock(&test_mutex) == 0) {
|
||||
puts("OK");
|
||||
}
|
||||
else {
|
||||
puts("error mutex not locked");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief main function starting shell
|
||||
*
|
||||
|
||||
@ -23,6 +23,10 @@ def testfunc(child):
|
||||
child.expect("starting test: xtimer mutex lock timeout")
|
||||
child.expect("OK")
|
||||
child.expect_exact("> ")
|
||||
child.sendline("mutex_timeout_long_locked")
|
||||
child.expect("starting test: xtimer mutex lock timeout")
|
||||
child.expect("OK")
|
||||
child.expect_exact("> ")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user