1
0
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:
Marian Buschsieweke 2020-11-13 20:58:38 +01:00
parent e348407888
commit 9127deb6fe
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F
3 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,5 @@
include ../Makefile.tests_common
USEMODULE += xtimer
include $(RIOTBASE)/Makefile.include

79
tests/mutex_cancel/main.c Normal file
View 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;
}

View 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))