From f7779895fd37fea203e8aec4487f48abfbd2a9cb Mon Sep 17 00:00:00 2001 From: Rajavardhan Gundi Date: Mon, 6 Aug 2018 09:45:40 +0530 Subject: [PATCH] tests/cmsis_rtos_v1: Introduce tests to make use of Signal APIs Some test programs to illustrate the usage of Signal Event APIs. Signed-off-by: Rajavardhan Gundi --- tests/cmsis_rtos_v1/src/main.c | 8 ++- tests/cmsis_rtos_v1/src/signal.c | 89 ++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/cmsis_rtos_v1/src/signal.c diff --git a/tests/cmsis_rtos_v1/src/main.c b/tests/cmsis_rtos_v1/src/main.c index a6bd38e92b5..a7ba521f9d2 100644 --- a/tests/cmsis_rtos_v1/src/main.c +++ b/tests/cmsis_rtos_v1/src/main.c @@ -18,6 +18,9 @@ extern void test_semaphore(void); extern void test_mempool(void); extern void test_mailq(void); extern void test_messageq(void); +extern void test_signal_events_no_wait(void); +extern void test_signal_events_timeout(void); +extern void test_signal_events_signalled(void); void test_main(void) { @@ -31,7 +34,10 @@ void test_main(void) ztest_unit_test(test_semaphore), ztest_unit_test(test_mempool), ztest_unit_test(test_mailq), - ztest_unit_test(test_messageq)); + ztest_unit_test(test_messageq), + ztest_unit_test(test_signal_events_no_wait), + ztest_unit_test(test_signal_events_timeout), + ztest_unit_test(test_signal_events_signalled)); ztest_run_test_suite(test_cmsis_apis); } diff --git a/tests/cmsis_rtos_v1/src/signal.c b/tests/cmsis_rtos_v1/src/signal.c new file mode 100644 index 00000000000..f131db06fcb --- /dev/null +++ b/tests/cmsis_rtos_v1/src/signal.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#define TIMEOUT (100) +#define SIGNAL1 (0x00000020) +#define SIGNAL2 (0x00000004) +#define SIGNAL (SIGNAL1 | SIGNAL2) + +void Thread_1(void const *arg) +{ + int signals = osSignalSet((osThreadId)arg, SIGNAL1); + + zassert_not_equal(signals, 0x80000000, ""); +} + +void Thread_2(void const *arg) +{ + int signals = osSignalSet((osThreadId)arg, SIGNAL2); + + zassert_not_equal(signals, 0x80000000, ""); +} + +osThreadDef(Thread_1, osPriorityHigh, 3, 0); +osThreadDef(Thread_2, osPriorityHigh, 1, 0); + +void test_signal_events_no_wait(void) +{ + osThreadId id1; + osEvent evt; + + id1 = osThreadCreate(osThread(Thread_1), osThreadGetId()); + zassert_true(id1 != NULL, "Thread creation failed"); + + /* Let id1 run to trigger SIGNAL1 */ + osDelay(10); + + /* wait for SIGNAL1. It should return immediately as it is + * already triggered. + */ + evt = osSignalWait(SIGNAL1, 0); + zassert_equal(evt.status, osEventSignal, ""); + zassert_equal((evt.value.signals & SIGNAL1), SIGNAL1, ""); +} + +void test_signal_events_timeout(void) +{ + osThreadId id1; + int signals; + osEvent evt; + + id1 = osThreadCreate(osThread(Thread_1), osThreadGetId()); + zassert_true(id1 != NULL, "Thread creation failed"); + + /* Let id1 run to trigger SIGNAL1 */ + osDelay(10); + + signals = osSignalClear(osThreadGetId(), SIGNAL1); + zassert_not_equal(signals, 0x80000000, ""); + + /* wait for SIGNAL1. It should timeout here as the signal + * though triggered, gets cleared in the previous step. + */ + evt = osSignalWait(SIGNAL1, TIMEOUT); + zassert_equal(evt.status, osEventTimeout, ""); +} + +void test_signal_events_signalled(void) +{ + osThreadId id1, id2; + osEvent evt; + + id1 = osThreadCreate(osThread(Thread_1), osThreadGetId()); + zassert_true(id1 != NULL, "Thread creation failed"); + + id2 = osThreadCreate(osThread(Thread_2), osThreadGetId()); + zassert_true(id2 != NULL, "Thread creation failed"); + + /* wait for a signal */ + evt = osSignalWait(SIGNAL, TIMEOUT); + zassert_equal(evt.status, osEventSignal, ""); + zassert_equal((evt.value.signals & SIGNAL), SIGNAL, ""); +}