From 9529b1a3054daad63281580fa617f986595e54cf Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 29 Nov 2016 12:46:25 +0100 Subject: [PATCH 1/2] tests: add regression test for thread_yield() vs thread_yield_higher() --- tests/isr_yield_higher/Makefile | 11 +++++ tests/isr_yield_higher/main.c | 69 ++++++++++++++++++++++++++++ tests/isr_yield_higher/tests/test.py | 23 ++++++++++ 3 files changed, 103 insertions(+) create mode 100644 tests/isr_yield_higher/Makefile create mode 100644 tests/isr_yield_higher/main.c create mode 100755 tests/isr_yield_higher/tests/test.py diff --git a/tests/isr_yield_higher/Makefile b/tests/isr_yield_higher/Makefile new file mode 100644 index 0000000000..43de5a792f --- /dev/null +++ b/tests/isr_yield_higher/Makefile @@ -0,0 +1,11 @@ +APPLICATION = isr_yield_higher +include ../Makefile.tests_common + +BOARD_INSUFFICIENT_MEMORY := nucleo32-f031 + +USEMODULE += xtimer + +include $(RIOTBASE)/Makefile.include + +test: + ./tests/test.py diff --git a/tests/isr_yield_higher/main.c b/tests/isr_yield_higher/main.c new file mode 100644 index 0000000000..fff50947ef --- /dev/null +++ b/tests/isr_yield_higher/main.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2017 Kaspar Schleiser + * + * 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 Application for testing cooperative scheduling of same-priority + * threads + * + * @author Kaspar Schleiser + * + * @} + */ + +#include + +#include "thread.h" +#include "xtimer.h" + +#define TEST_TIME (200000U) + +static char t2_stack[THREAD_STACKSIZE_MAIN]; + +static void *second_thread(void *arg) +{ + (void) arg; + if (xtimer_now_usec() < TEST_TIME) { + puts("TEST FAILED"); + } + else { + puts("TEST SUCCESSFUL"); + } + return NULL; +} + +static void _cb(void *arg) +{ + (void)arg; + puts("timer triggered"); + sched_context_switch_request = 1; +} + +int main(void) +{ + (void) thread_create( + t2_stack, sizeof(t2_stack), + THREAD_PRIORITY_MAIN, + THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST, + second_thread, NULL, "nr2"); + + puts("first thread started"); + + xtimer_t timer; + timer.callback = _cb; + xtimer_set(&timer, TEST_TIME/2); + + while(xtimer_now_usec() < TEST_TIME) {} + + puts("first thread done"); + + return 0; +} diff --git a/tests/isr_yield_higher/tests/test.py b/tests/isr_yield_higher/tests/test.py new file mode 100755 index 0000000000..5890d00763 --- /dev/null +++ b/tests/isr_yield_higher/tests/test.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2017 Kaspar Schleiser +# +# 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. + +import os +import sys + + +def testfunc(child): + child.expect('first thread started') + child.expect('timer triggered') + child.expect('first thread done') + child.expect('TEST SUCCESSFUL') + + +if __name__ == "__main__": + sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner')) + from testrunner import run + sys.exit(run(testfunc, echo=False)) From c9c7cd4951d895733e185cdd2f2465551189d54f Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 8 Nov 2017 17:38:39 +0100 Subject: [PATCH 2/2] cpu: cortexm_common: use thread_yield_higher() in cortexm_isr_end() --- cpu/cortexm_common/include/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/cortexm_common/include/cpu.h b/cpu/cortexm_common/include/cpu.h index 558046fbb0..48e355ea2e 100644 --- a/cpu/cortexm_common/include/cpu.h +++ b/cpu/cortexm_common/include/cpu.h @@ -122,7 +122,7 @@ static inline void cortexm_sleep(int deep) static inline void cortexm_isr_end(void) { if (sched_context_switch_request) { - thread_yield(); + thread_yield_higher(); } }