From dfbcbddd9a207be39f0281da7ddb048cdca2c311 Mon Sep 17 00:00:00 2001 From: YarivCol Date: Thu, 22 Jun 2017 14:13:50 +0300 Subject: [PATCH] RTOS: add tests for EvenFlags class --- .../mbedmicro-rtos-mbed/event_flags/main.cpp | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 TESTS/mbedmicro-rtos-mbed/event_flags/main.cpp diff --git a/TESTS/mbedmicro-rtos-mbed/event_flags/main.cpp b/TESTS/mbedmicro-rtos-mbed/event_flags/main.cpp new file mode 100644 index 0000000000..507fd42a34 --- /dev/null +++ b/TESTS/mbedmicro-rtos-mbed/event_flags/main.cpp @@ -0,0 +1,50 @@ +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "rtos.h" + +#if defined(MBED_RTOS_SINGLE_THREAD) + #error [NOT_SUPPORTED] test not supported +#endif + +#define TEST_STACK_SIZE 512 + +#define EVENT_SET_VALUE 0x01 +const int EVENT_TO_EMIT = 100; +const int EVENT_HANDLE_DELEY = 25; + +DigitalOut led(LED1); +EventFlags event_flags(); + +int events_counter = 0; + +void led_thread() { + while (true) { + // events flags that are reported as event are automatically cleared. + event_flags.wait(EVENT_SET_VALUE); + led = !led; + events_counter++; + } +} + +int main (void) { + GREENTEA_SETUP(20, "default_auto"); + + Thread thread(osPriorityNormal, TEST_STACK_SIZE); + thread.start(led_thread); + + bool result = false; + + printf("Handling %d events...\r\n", EVENT_TO_EMIT); + + while (true) { + Thread::wait(2 * EVENT_HANDLE_DELEY); + event_flags.set(EVENT_SET_VALUE); + if (events_counter == EVENT_TO_EMIT) { + printf("Handled %d events\r\n", events_counter); + result = true; + break; + } + } + GREENTEA_TESTSUITE_RESULT(result); + return 0; +}