mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests: Add test for core_mutex/mutex_cancel
This commit is contained in:
parent
e348407888
commit
9127deb6fe
5
tests/mutex_cancel/Makefile
Normal file
5
tests/mutex_cancel/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += xtimer
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
79
tests/mutex_cancel/main.c
Normal file
79
tests/mutex_cancel/main.c
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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 testing the mutex_cancel function in
|
||||
* core_mutex
|
||||
*
|
||||
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "mutex.h"
|
||||
#include "test_utils/expect.h"
|
||||
#include "thread.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
static mutex_t testlock = MUTEX_INIT;
|
||||
|
||||
static void cb_unlock(void *mutex)
|
||||
{
|
||||
mutex_unlock(mutex);
|
||||
}
|
||||
|
||||
static void cb_cancel(void *mc)
|
||||
{
|
||||
mutex_cancel(mc);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
xtimer_t xt;
|
||||
puts(
|
||||
"Test Application for mutex_cancel / mutex_lock_cancelable\n"
|
||||
"=========================================================\n"
|
||||
);
|
||||
|
||||
printf("%s: ", "Test without cancellation");
|
||||
mutex_cancel_t mc = mutex_cancel_init(&testlock);
|
||||
expect(mutex_lock_cancelable(&mc) == 0);
|
||||
puts("OK");
|
||||
|
||||
printf("%s: ", "Test early cancellation");
|
||||
mc = mutex_cancel_init(&testlock);
|
||||
mutex_cancel(&mc);
|
||||
expect(mutex_lock_cancelable(&mc) == -ECANCELED);
|
||||
puts("OK");
|
||||
|
||||
printf("%s: ", "Verify no side effects on subsequent calls");
|
||||
mc = mutex_cancel_init(&testlock);
|
||||
xt.callback = cb_unlock;
|
||||
xt.arg = &testlock;
|
||||
xtimer_set(&xt, US_PER_MS * 10);
|
||||
expect(mutex_lock_cancelable(&mc) == 0);
|
||||
puts("OK");
|
||||
|
||||
printf("%s: ", "Test late cancellation");
|
||||
mc = mutex_cancel_init(&testlock);
|
||||
xt.callback = cb_cancel;
|
||||
xt.arg = &mc;
|
||||
xtimer_set(&xt, US_PER_MS * 10);
|
||||
expect(mutex_lock_cancelable(&mc) == -ECANCELED);
|
||||
puts("OK");
|
||||
|
||||
puts("TEST PASSED");
|
||||
|
||||
return 0;
|
||||
}
|
20
tests/mutex_cancel/tests/01-run.py
Executable file
20
tests/mutex_cancel/tests/01-run.py
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2020 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.
|
||||
|
||||
# @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
|
||||
|
||||
import sys
|
||||
from testrunner import run
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
child.expect("TEST PASSED")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run(testfunc))
|
Loading…
Reference in New Issue
Block a user