takashi kadono
/
Nucleo446_SSD1331
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/TESTS/mbedmicro-rtos-mbed/signals/main.cpp@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | /* mbed Microcontroller Library |
kadonotakashi | 0:8fdf9a60065b | 2 | * Copyright (c) 2017 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 3 | * |
kadonotakashi | 0:8fdf9a60065b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 5 | * you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 6 | * You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 7 | * |
kadonotakashi | 0:8fdf9a60065b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 9 | * |
kadonotakashi | 0:8fdf9a60065b | 10 | * Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 13 | * See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 14 | * limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 15 | */ |
kadonotakashi | 0:8fdf9a60065b | 16 | #include "mbed.h" |
kadonotakashi | 0:8fdf9a60065b | 17 | #include "greentea-client/test_env.h" |
kadonotakashi | 0:8fdf9a60065b | 18 | #include "utest/utest.h" |
kadonotakashi | 0:8fdf9a60065b | 19 | #include "unity/unity.h" |
kadonotakashi | 0:8fdf9a60065b | 20 | |
kadonotakashi | 0:8fdf9a60065b | 21 | using utest::v1::Case; |
kadonotakashi | 0:8fdf9a60065b | 22 | |
kadonotakashi | 0:8fdf9a60065b | 23 | #if defined(MBED_RTOS_SINGLE_THREAD) |
kadonotakashi | 0:8fdf9a60065b | 24 | #error [NOT_SUPPORTED] test not supported |
kadonotakashi | 0:8fdf9a60065b | 25 | #endif |
kadonotakashi | 0:8fdf9a60065b | 26 | |
kadonotakashi | 0:8fdf9a60065b | 27 | #if !DEVICE_USTICKER |
kadonotakashi | 0:8fdf9a60065b | 28 | #error [NOT_SUPPORTED] test not supported |
kadonotakashi | 0:8fdf9a60065b | 29 | #endif |
kadonotakashi | 0:8fdf9a60065b | 30 | |
kadonotakashi | 0:8fdf9a60065b | 31 | #define TEST_STACK_SIZE 512 |
kadonotakashi | 0:8fdf9a60065b | 32 | #define MAX_FLAG_POS 30 |
kadonotakashi | 0:8fdf9a60065b | 33 | |
kadonotakashi | 0:8fdf9a60065b | 34 | #define ALL_SIGNALS 0x7fffffff |
kadonotakashi | 0:8fdf9a60065b | 35 | #define NO_SIGNALS 0x0 |
kadonotakashi | 0:8fdf9a60065b | 36 | #define PROHIBITED_SIGNAL 0x80000000 |
kadonotakashi | 0:8fdf9a60065b | 37 | #define SIGNAL1 0x1 |
kadonotakashi | 0:8fdf9a60065b | 38 | #define SIGNAL2 0x2 |
kadonotakashi | 0:8fdf9a60065b | 39 | #define SIGNAL3 0x4 |
kadonotakashi | 0:8fdf9a60065b | 40 | |
kadonotakashi | 0:8fdf9a60065b | 41 | struct Sync { |
kadonotakashi | 0:8fdf9a60065b | 42 | Sync(Semaphore &parent, Semaphore &child): sem_parent(parent), sem_child(child) |
kadonotakashi | 0:8fdf9a60065b | 43 | {} |
kadonotakashi | 0:8fdf9a60065b | 44 | |
kadonotakashi | 0:8fdf9a60065b | 45 | Semaphore &sem_parent; |
kadonotakashi | 0:8fdf9a60065b | 46 | Semaphore &sem_child; |
kadonotakashi | 0:8fdf9a60065b | 47 | }; |
kadonotakashi | 0:8fdf9a60065b | 48 | |
kadonotakashi | 0:8fdf9a60065b | 49 | |
kadonotakashi | 0:8fdf9a60065b | 50 | /* In order to successfully run this test suite when compiled with --profile=debug |
kadonotakashi | 0:8fdf9a60065b | 51 | * error() has to be redefined as noop. |
kadonotakashi | 0:8fdf9a60065b | 52 | * |
kadonotakashi | 0:8fdf9a60065b | 53 | * ThreadFlags calls RTX API which uses Event Recorder functionality. When compiled |
kadonotakashi | 0:8fdf9a60065b | 54 | * with MBED_TRAP_ERRORS_ENABLED=1 (set in debug profile) EvrRtxEventFlagsError() calls error() |
kadonotakashi | 0:8fdf9a60065b | 55 | * which aborts test program. |
kadonotakashi | 0:8fdf9a60065b | 56 | */ |
kadonotakashi | 0:8fdf9a60065b | 57 | #if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED |
kadonotakashi | 0:8fdf9a60065b | 58 | void error(const char *format, ...) |
kadonotakashi | 0:8fdf9a60065b | 59 | { |
kadonotakashi | 0:8fdf9a60065b | 60 | (void) format; |
kadonotakashi | 0:8fdf9a60065b | 61 | } |
kadonotakashi | 0:8fdf9a60065b | 62 | |
kadonotakashi | 0:8fdf9a60065b | 63 | mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number) |
kadonotakashi | 0:8fdf9a60065b | 64 | { |
kadonotakashi | 0:8fdf9a60065b | 65 | return MBED_SUCCESS; |
kadonotakashi | 0:8fdf9a60065b | 66 | } |
kadonotakashi | 0:8fdf9a60065b | 67 | #endif |
kadonotakashi | 0:8fdf9a60065b | 68 | |
kadonotakashi | 0:8fdf9a60065b | 69 | |
kadonotakashi | 0:8fdf9a60065b | 70 | template <int32_t signals, uint32_t timeout, int32_t test_val> |
kadonotakashi | 0:8fdf9a60065b | 71 | void run_signal_wait(void) |
kadonotakashi | 0:8fdf9a60065b | 72 | { |
kadonotakashi | 0:8fdf9a60065b | 73 | osEvent ev = Thread::signal_wait(signals, timeout); |
kadonotakashi | 0:8fdf9a60065b | 74 | TEST_ASSERT_EQUAL(test_val, ev.status); |
kadonotakashi | 0:8fdf9a60065b | 75 | } |
kadonotakashi | 0:8fdf9a60065b | 76 | |
kadonotakashi | 0:8fdf9a60065b | 77 | template <int32_t signals, uint32_t timeout, int32_t test_val> |
kadonotakashi | 0:8fdf9a60065b | 78 | void run_release_signal_wait(Semaphore *sem) |
kadonotakashi | 0:8fdf9a60065b | 79 | { |
kadonotakashi | 0:8fdf9a60065b | 80 | sem->release(); |
kadonotakashi | 0:8fdf9a60065b | 81 | osEvent ev = Thread::signal_wait(signals, timeout); |
kadonotakashi | 0:8fdf9a60065b | 82 | TEST_ASSERT_EQUAL(test_val, ev.status); |
kadonotakashi | 0:8fdf9a60065b | 83 | } |
kadonotakashi | 0:8fdf9a60065b | 84 | |
kadonotakashi | 0:8fdf9a60065b | 85 | template <int32_t signals, uint32_t timeout, int32_t test_val> |
kadonotakashi | 0:8fdf9a60065b | 86 | void run_release_wait_signal_wait(Sync *sync) |
kadonotakashi | 0:8fdf9a60065b | 87 | { |
kadonotakashi | 0:8fdf9a60065b | 88 | sync->sem_parent.release(); |
kadonotakashi | 0:8fdf9a60065b | 89 | sync->sem_child.wait(); |
kadonotakashi | 0:8fdf9a60065b | 90 | osEvent ev = Thread::signal_wait(signals, timeout); |
kadonotakashi | 0:8fdf9a60065b | 91 | TEST_ASSERT_EQUAL(test_val, ev.status); |
kadonotakashi | 0:8fdf9a60065b | 92 | } |
kadonotakashi | 0:8fdf9a60065b | 93 | |
kadonotakashi | 0:8fdf9a60065b | 94 | template <int32_t signals, int32_t test_val> |
kadonotakashi | 0:8fdf9a60065b | 95 | void run_clear(void) |
kadonotakashi | 0:8fdf9a60065b | 96 | { |
kadonotakashi | 0:8fdf9a60065b | 97 | int32_t ret = Thread::signal_clr(signals); |
kadonotakashi | 0:8fdf9a60065b | 98 | TEST_ASSERT_EQUAL(test_val, ret); |
kadonotakashi | 0:8fdf9a60065b | 99 | } |
kadonotakashi | 0:8fdf9a60065b | 100 | |
kadonotakashi | 0:8fdf9a60065b | 101 | template <int32_t signals, int32_t test_val> |
kadonotakashi | 0:8fdf9a60065b | 102 | void run_wait_clear(Sync *sync) |
kadonotakashi | 0:8fdf9a60065b | 103 | { |
kadonotakashi | 0:8fdf9a60065b | 104 | sync->sem_parent.release(); |
kadonotakashi | 0:8fdf9a60065b | 105 | sync->sem_child.wait(); |
kadonotakashi | 0:8fdf9a60065b | 106 | int32_t ret = Thread::signal_clr(signals); |
kadonotakashi | 0:8fdf9a60065b | 107 | TEST_ASSERT_EQUAL(test_val, ret); |
kadonotakashi | 0:8fdf9a60065b | 108 | } |
kadonotakashi | 0:8fdf9a60065b | 109 | |
kadonotakashi | 0:8fdf9a60065b | 110 | template <int32_t signals1, int32_t signals2, int32_t test_val1, int32_t test_val2> |
kadonotakashi | 0:8fdf9a60065b | 111 | void run_double_wait_clear(Sync *sync) |
kadonotakashi | 0:8fdf9a60065b | 112 | { |
kadonotakashi | 0:8fdf9a60065b | 113 | int32_t ret; |
kadonotakashi | 0:8fdf9a60065b | 114 | |
kadonotakashi | 0:8fdf9a60065b | 115 | sync->sem_parent.release(); |
kadonotakashi | 0:8fdf9a60065b | 116 | sync->sem_child.wait(); |
kadonotakashi | 0:8fdf9a60065b | 117 | ret = Thread::signal_clr(signals1); |
kadonotakashi | 0:8fdf9a60065b | 118 | TEST_ASSERT_EQUAL(test_val1, ret); |
kadonotakashi | 0:8fdf9a60065b | 119 | |
kadonotakashi | 0:8fdf9a60065b | 120 | ret = Thread::signal_clr(signals2); |
kadonotakashi | 0:8fdf9a60065b | 121 | TEST_ASSERT_EQUAL(test_val2, ret); |
kadonotakashi | 0:8fdf9a60065b | 122 | } |
kadonotakashi | 0:8fdf9a60065b | 123 | |
kadonotakashi | 0:8fdf9a60065b | 124 | void run_loop_wait_clear(Sync *sync) |
kadonotakashi | 0:8fdf9a60065b | 125 | { |
kadonotakashi | 0:8fdf9a60065b | 126 | int32_t signals = NO_SIGNALS; |
kadonotakashi | 0:8fdf9a60065b | 127 | for (int i = 0; i <= MAX_FLAG_POS; i++) { |
kadonotakashi | 0:8fdf9a60065b | 128 | int32_t signal = 1 << i; |
kadonotakashi | 0:8fdf9a60065b | 129 | signals |= signal; |
kadonotakashi | 0:8fdf9a60065b | 130 | sync->sem_child.wait(); |
kadonotakashi | 0:8fdf9a60065b | 131 | int32_t ret = Thread::signal_clr(NO_SIGNALS); |
kadonotakashi | 0:8fdf9a60065b | 132 | TEST_ASSERT_EQUAL(signals, ret); |
kadonotakashi | 0:8fdf9a60065b | 133 | sync->sem_parent.release(); |
kadonotakashi | 0:8fdf9a60065b | 134 | } |
kadonotakashi | 0:8fdf9a60065b | 135 | } |
kadonotakashi | 0:8fdf9a60065b | 136 | |
kadonotakashi | 0:8fdf9a60065b | 137 | |
kadonotakashi | 0:8fdf9a60065b | 138 | /** Validate that call signal_clr(NO_SIGNALS) doesn't change thread signals and return actual signals |
kadonotakashi | 0:8fdf9a60065b | 139 | |
kadonotakashi | 0:8fdf9a60065b | 140 | Given two threads A & B are started, B with all signals already set |
kadonotakashi | 0:8fdf9a60065b | 141 | When thread B calls @a signal_clr(NO_SIGNALS) |
kadonotakashi | 0:8fdf9a60065b | 142 | Then thread B @a signal_clr status should be ALL_SIGNALS indicating that thread B state is unchanged |
kadonotakashi | 0:8fdf9a60065b | 143 | */ |
kadonotakashi | 0:8fdf9a60065b | 144 | void test_clear_no_signals(void) |
kadonotakashi | 0:8fdf9a60065b | 145 | { |
kadonotakashi | 0:8fdf9a60065b | 146 | Semaphore sem_parent(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 147 | Semaphore sem_child(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 148 | Sync sync(sem_parent, sem_child); |
kadonotakashi | 0:8fdf9a60065b | 149 | |
kadonotakashi | 0:8fdf9a60065b | 150 | Thread t(osPriorityNormal, TEST_STACK_SIZE); |
kadonotakashi | 0:8fdf9a60065b | 151 | t.start(callback(run_double_wait_clear<NO_SIGNALS, NO_SIGNALS, ALL_SIGNALS, ALL_SIGNALS>, &sync)); |
kadonotakashi | 0:8fdf9a60065b | 152 | sem_parent.wait(); |
kadonotakashi | 0:8fdf9a60065b | 153 | t.signal_set(ALL_SIGNALS); |
kadonotakashi | 0:8fdf9a60065b | 154 | sem_child.release(); |
kadonotakashi | 0:8fdf9a60065b | 155 | t.join(); |
kadonotakashi | 0:8fdf9a60065b | 156 | } |
kadonotakashi | 0:8fdf9a60065b | 157 | |
kadonotakashi | 0:8fdf9a60065b | 158 | /** Validate if any signals are set on just created thread |
kadonotakashi | 0:8fdf9a60065b | 159 | |
kadonotakashi | 0:8fdf9a60065b | 160 | Given the thread is running |
kadonotakashi | 0:8fdf9a60065b | 161 | When thread execute @a signal_clr(NO_SIGNALS) |
kadonotakashi | 0:8fdf9a60065b | 162 | Then thread @a signal_clr return status should be NO_SIGNALS(0) indicating no signals set |
kadonotakashi | 0:8fdf9a60065b | 163 | */ |
kadonotakashi | 0:8fdf9a60065b | 164 | void test_init_state(void) |
kadonotakashi | 0:8fdf9a60065b | 165 | { |
kadonotakashi | 0:8fdf9a60065b | 166 | Thread t(osPriorityNormal, TEST_STACK_SIZE); |
kadonotakashi | 0:8fdf9a60065b | 167 | t.start(callback(run_clear<NO_SIGNALS, NO_SIGNALS>)); |
kadonotakashi | 0:8fdf9a60065b | 168 | t.join(); |
kadonotakashi | 0:8fdf9a60065b | 169 | } |
kadonotakashi | 0:8fdf9a60065b | 170 | |
kadonotakashi | 0:8fdf9a60065b | 171 | /** Validate all signals set in one shot |
kadonotakashi | 0:8fdf9a60065b | 172 | |
kadonotakashi | 0:8fdf9a60065b | 173 | Given two threads A & B are started |
kadonotakashi | 0:8fdf9a60065b | 174 | When thread A call @a signal_set(ALL_SIGNALS) with all possible signals |
kadonotakashi | 0:8fdf9a60065b | 175 | Then thread B @a signal_clr(NO_SIGNALS) status should be ALL_SIGNALS indicating all signals set correctly |
kadonotakashi | 0:8fdf9a60065b | 176 | */ |
kadonotakashi | 0:8fdf9a60065b | 177 | void test_set_all(void) |
kadonotakashi | 0:8fdf9a60065b | 178 | { |
kadonotakashi | 0:8fdf9a60065b | 179 | int32_t ret; |
kadonotakashi | 0:8fdf9a60065b | 180 | Semaphore sem_parent(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 181 | Semaphore sem_child(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 182 | Sync sync(sem_parent, sem_child); |
kadonotakashi | 0:8fdf9a60065b | 183 | |
kadonotakashi | 0:8fdf9a60065b | 184 | Thread t(osPriorityNormal, TEST_STACK_SIZE); |
kadonotakashi | 0:8fdf9a60065b | 185 | t.start(callback(run_wait_clear<NO_SIGNALS, ALL_SIGNALS>, &sync)); |
kadonotakashi | 0:8fdf9a60065b | 186 | |
kadonotakashi | 0:8fdf9a60065b | 187 | sem_parent.wait(); |
kadonotakashi | 0:8fdf9a60065b | 188 | ret = t.signal_set(ALL_SIGNALS); |
kadonotakashi | 0:8fdf9a60065b | 189 | TEST_ASSERT_EQUAL(ALL_SIGNALS, ret); |
kadonotakashi | 0:8fdf9a60065b | 190 | |
kadonotakashi | 0:8fdf9a60065b | 191 | sem_child.release(); |
kadonotakashi | 0:8fdf9a60065b | 192 | t.join(); |
kadonotakashi | 0:8fdf9a60065b | 193 | } |
kadonotakashi | 0:8fdf9a60065b | 194 | |
kadonotakashi | 0:8fdf9a60065b | 195 | /** Validate that call signal_set with prohibited signal doesn't change thread signals |
kadonotakashi | 0:8fdf9a60065b | 196 | |
kadonotakashi | 0:8fdf9a60065b | 197 | Given two threads A & B are started, B with all signals set |
kadonotakashi | 0:8fdf9a60065b | 198 | When thread A executes @a signal_set(PROHIBITED_SIGNAL) with prohibited signal |
kadonotakashi | 0:8fdf9a60065b | 199 | Then thread B @a signal_clr(NO_SIGNALS) status should be ALL_SIGNALS indicating that thread B signals are unchanged |
kadonotakashi | 0:8fdf9a60065b | 200 | |
kadonotakashi | 0:8fdf9a60065b | 201 | @note Each signal has up to 31 event flags 0x1, 0x2, 0x4, 0x8, ..., 0x40000000 |
kadonotakashi | 0:8fdf9a60065b | 202 | Most significant bit is reserved and thereby flag 0x80000000 is prohibited |
kadonotakashi | 0:8fdf9a60065b | 203 | */ |
kadonotakashi | 0:8fdf9a60065b | 204 | void test_set_prohibited(void) |
kadonotakashi | 0:8fdf9a60065b | 205 | { |
kadonotakashi | 0:8fdf9a60065b | 206 | int32_t ret; |
kadonotakashi | 0:8fdf9a60065b | 207 | Semaphore sem_parent(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 208 | Semaphore sem_child(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 209 | Sync sync(sem_parent, sem_child); |
kadonotakashi | 0:8fdf9a60065b | 210 | |
kadonotakashi | 0:8fdf9a60065b | 211 | Thread t(osPriorityNormal, TEST_STACK_SIZE); |
kadonotakashi | 0:8fdf9a60065b | 212 | t.start(callback(run_wait_clear<NO_SIGNALS, ALL_SIGNALS>, &sync)); |
kadonotakashi | 0:8fdf9a60065b | 213 | |
kadonotakashi | 0:8fdf9a60065b | 214 | sem_parent.wait(); |
kadonotakashi | 0:8fdf9a60065b | 215 | t.signal_set(ALL_SIGNALS); |
kadonotakashi | 0:8fdf9a60065b | 216 | |
kadonotakashi | 0:8fdf9a60065b | 217 | ret = t.signal_set(PROHIBITED_SIGNAL); |
kadonotakashi | 0:8fdf9a60065b | 218 | TEST_ASSERT_EQUAL(osErrorParameter, ret); |
kadonotakashi | 0:8fdf9a60065b | 219 | |
kadonotakashi | 0:8fdf9a60065b | 220 | sem_child.release(); |
kadonotakashi | 0:8fdf9a60065b | 221 | t.join(); |
kadonotakashi | 0:8fdf9a60065b | 222 | } |
kadonotakashi | 0:8fdf9a60065b | 223 | |
kadonotakashi | 0:8fdf9a60065b | 224 | /** Validate all signals clear in one shot |
kadonotakashi | 0:8fdf9a60065b | 225 | |
kadonotakashi | 0:8fdf9a60065b | 226 | Given two threads A & B are started, B with all signals set |
kadonotakashi | 0:8fdf9a60065b | 227 | When thread B execute @a signal_clr(ALL_SIGNALS) with all possible signals |
kadonotakashi | 0:8fdf9a60065b | 228 | Then thread B @a signal_clr(NO_SIGNALS) status should be NO_SIGNALS(0) indicating all signals cleared correctly |
kadonotakashi | 0:8fdf9a60065b | 229 | */ |
kadonotakashi | 0:8fdf9a60065b | 230 | void test_clear_all(void) |
kadonotakashi | 0:8fdf9a60065b | 231 | { |
kadonotakashi | 0:8fdf9a60065b | 232 | Semaphore sem_parent(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 233 | Semaphore sem_child(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 234 | Sync sync(sem_parent, sem_child); |
kadonotakashi | 0:8fdf9a60065b | 235 | |
kadonotakashi | 0:8fdf9a60065b | 236 | Thread t(osPriorityNormal, TEST_STACK_SIZE); |
kadonotakashi | 0:8fdf9a60065b | 237 | t.start(callback(run_double_wait_clear<ALL_SIGNALS, NO_SIGNALS, ALL_SIGNALS, NO_SIGNALS>, &sync)); |
kadonotakashi | 0:8fdf9a60065b | 238 | sem_parent.wait(); |
kadonotakashi | 0:8fdf9a60065b | 239 | t.signal_set(ALL_SIGNALS); |
kadonotakashi | 0:8fdf9a60065b | 240 | sem_child.release(); |
kadonotakashi | 0:8fdf9a60065b | 241 | t.join(); |
kadonotakashi | 0:8fdf9a60065b | 242 | } |
kadonotakashi | 0:8fdf9a60065b | 243 | |
kadonotakashi | 0:8fdf9a60065b | 244 | /** Validate all signals set one by one in loop |
kadonotakashi | 0:8fdf9a60065b | 245 | |
kadonotakashi | 0:8fdf9a60065b | 246 | Given two threads A & B are started |
kadonotakashi | 0:8fdf9a60065b | 247 | When thread A executes @a signal_set(signal) in loop with all possible signals |
kadonotakashi | 0:8fdf9a60065b | 248 | */ |
kadonotakashi | 0:8fdf9a60065b | 249 | void test_set_all_loop(void) |
kadonotakashi | 0:8fdf9a60065b | 250 | { |
kadonotakashi | 0:8fdf9a60065b | 251 | int32_t ret; |
kadonotakashi | 0:8fdf9a60065b | 252 | Semaphore sem_parent(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 253 | Semaphore sem_child(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 254 | Sync sync(sem_parent, sem_child); |
kadonotakashi | 0:8fdf9a60065b | 255 | |
kadonotakashi | 0:8fdf9a60065b | 256 | Thread t(osPriorityNormal, TEST_STACK_SIZE); |
kadonotakashi | 0:8fdf9a60065b | 257 | t.start(callback(run_loop_wait_clear, &sync)); |
kadonotakashi | 0:8fdf9a60065b | 258 | |
kadonotakashi | 0:8fdf9a60065b | 259 | int32_t signals = 0; |
kadonotakashi | 0:8fdf9a60065b | 260 | for (int i = 0; i <= MAX_FLAG_POS; i++) { |
kadonotakashi | 0:8fdf9a60065b | 261 | int32_t signal = 1 << i; |
kadonotakashi | 0:8fdf9a60065b | 262 | |
kadonotakashi | 0:8fdf9a60065b | 263 | ret = t.signal_set(signal); |
kadonotakashi | 0:8fdf9a60065b | 264 | signals |= signal; |
kadonotakashi | 0:8fdf9a60065b | 265 | TEST_ASSERT_EQUAL(signals, ret); |
kadonotakashi | 0:8fdf9a60065b | 266 | sem_child.release(); |
kadonotakashi | 0:8fdf9a60065b | 267 | sem_parent.wait(); |
kadonotakashi | 0:8fdf9a60065b | 268 | } |
kadonotakashi | 0:8fdf9a60065b | 269 | t.join(); |
kadonotakashi | 0:8fdf9a60065b | 270 | } |
kadonotakashi | 0:8fdf9a60065b | 271 | |
kadonotakashi | 0:8fdf9a60065b | 272 | /** Validate signal_wait return status if timeout specified |
kadonotakashi | 0:8fdf9a60065b | 273 | |
kadonotakashi | 0:8fdf9a60065b | 274 | Given the thread is running |
kadonotakashi | 0:8fdf9a60065b | 275 | When thread executes @a signal_wait(signals, timeout) with specified signals and timeout |
kadonotakashi | 0:8fdf9a60065b | 276 | Then thread @a signal_wait status should be osEventTimeout indicating a timeout |
kadonotakashi | 0:8fdf9a60065b | 277 | thread @a signal_wait status should be osOK indicating 0[ms] timeout set |
kadonotakashi | 0:8fdf9a60065b | 278 | */ |
kadonotakashi | 0:8fdf9a60065b | 279 | template <int32_t signals, uint32_t timeout, int32_t status> |
kadonotakashi | 0:8fdf9a60065b | 280 | void test_wait_timeout(void) |
kadonotakashi | 0:8fdf9a60065b | 281 | { |
kadonotakashi | 0:8fdf9a60065b | 282 | Thread t(osPriorityNormal, TEST_STACK_SIZE); |
kadonotakashi | 0:8fdf9a60065b | 283 | t.start(callback(run_signal_wait<signals, timeout, status>)); |
kadonotakashi | 0:8fdf9a60065b | 284 | t.join(); |
kadonotakashi | 0:8fdf9a60065b | 285 | } |
kadonotakashi | 0:8fdf9a60065b | 286 | |
kadonotakashi | 0:8fdf9a60065b | 287 | /** Validate that call of signal_wait return correctly when thread has all signals already set |
kadonotakashi | 0:8fdf9a60065b | 288 | |
kadonotakashi | 0:8fdf9a60065b | 289 | Given two threads A & B are started, B with all signals already set |
kadonotakashi | 0:8fdf9a60065b | 290 | When thread B executes @a signal_wait(ALL_SIGNALS, osWaitForever), |
kadonotakashi | 0:8fdf9a60065b | 291 | Then thread B @a signal_wait return immediately with status osEventSignal indicating all wait signals was already set |
kadonotakashi | 0:8fdf9a60065b | 292 | */ |
kadonotakashi | 0:8fdf9a60065b | 293 | void test_wait_all_already_set(void) |
kadonotakashi | 0:8fdf9a60065b | 294 | { |
kadonotakashi | 0:8fdf9a60065b | 295 | Semaphore sem_parent(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 296 | Semaphore sem_child(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 297 | Sync sync(sem_parent, sem_child); |
kadonotakashi | 0:8fdf9a60065b | 298 | |
kadonotakashi | 0:8fdf9a60065b | 299 | Thread t(osPriorityNormal, TEST_STACK_SIZE); |
kadonotakashi | 0:8fdf9a60065b | 300 | t.start(callback(run_release_wait_signal_wait<ALL_SIGNALS, osWaitForever, osEventSignal>, &sync)); |
kadonotakashi | 0:8fdf9a60065b | 301 | |
kadonotakashi | 0:8fdf9a60065b | 302 | sem_parent.wait(); |
kadonotakashi | 0:8fdf9a60065b | 303 | TEST_ASSERT_EQUAL(Thread::WaitingSemaphore, t.get_state()); |
kadonotakashi | 0:8fdf9a60065b | 304 | t.signal_set(ALL_SIGNALS); |
kadonotakashi | 0:8fdf9a60065b | 305 | sem_child.release(); |
kadonotakashi | 0:8fdf9a60065b | 306 | t.join(); |
kadonotakashi | 0:8fdf9a60065b | 307 | } |
kadonotakashi | 0:8fdf9a60065b | 308 | |
kadonotakashi | 0:8fdf9a60065b | 309 | /** Validate if signal_wait return correctly when all signals set |
kadonotakashi | 0:8fdf9a60065b | 310 | |
kadonotakashi | 0:8fdf9a60065b | 311 | Given two threads A & B are started and B waiting for a thread flag to be set |
kadonotakashi | 0:8fdf9a60065b | 312 | When thread A executes @a signal_set(ALL_SIGNALS) with all possible signals |
kadonotakashi | 0:8fdf9a60065b | 313 | Then thread B @a signal_wait status is osEventSignal indicating all wait signals was set |
kadonotakashi | 0:8fdf9a60065b | 314 | */ |
kadonotakashi | 0:8fdf9a60065b | 315 | void test_wait_all(void) |
kadonotakashi | 0:8fdf9a60065b | 316 | { |
kadonotakashi | 0:8fdf9a60065b | 317 | Semaphore sem(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 318 | |
kadonotakashi | 0:8fdf9a60065b | 319 | Thread t(osPriorityNormal, TEST_STACK_SIZE); |
kadonotakashi | 0:8fdf9a60065b | 320 | t.start(callback(run_release_signal_wait<ALL_SIGNALS, osWaitForever, osEventSignal>, &sem)); |
kadonotakashi | 0:8fdf9a60065b | 321 | |
kadonotakashi | 0:8fdf9a60065b | 322 | sem.wait(); |
kadonotakashi | 0:8fdf9a60065b | 323 | TEST_ASSERT_EQUAL(Thread::WaitingThreadFlag, t.get_state()); |
kadonotakashi | 0:8fdf9a60065b | 324 | |
kadonotakashi | 0:8fdf9a60065b | 325 | t.signal_set(ALL_SIGNALS); |
kadonotakashi | 0:8fdf9a60065b | 326 | t.join(); |
kadonotakashi | 0:8fdf9a60065b | 327 | } |
kadonotakashi | 0:8fdf9a60065b | 328 | |
kadonotakashi | 0:8fdf9a60065b | 329 | /** Validate if signal_wait accumulate signals and return correctly when all signals set |
kadonotakashi | 0:8fdf9a60065b | 330 | |
kadonotakashi | 0:8fdf9a60065b | 331 | Given two threads A & B are started and B waiting for a thread signals to be set |
kadonotakashi | 0:8fdf9a60065b | 332 | When thread A executes @a signal_set setting all signals in loop |
kadonotakashi | 0:8fdf9a60065b | 333 | Then thread B @a signal_wait status is osEventSignal indicating that all wait signals was set |
kadonotakashi | 0:8fdf9a60065b | 334 | */ |
kadonotakashi | 0:8fdf9a60065b | 335 | void test_wait_all_loop(void) |
kadonotakashi | 0:8fdf9a60065b | 336 | { |
kadonotakashi | 0:8fdf9a60065b | 337 | int32_t ret; |
kadonotakashi | 0:8fdf9a60065b | 338 | Semaphore sem(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 339 | |
kadonotakashi | 0:8fdf9a60065b | 340 | Thread t(osPriorityNormal, TEST_STACK_SIZE); |
kadonotakashi | 0:8fdf9a60065b | 341 | t.start(callback(run_release_signal_wait<ALL_SIGNALS, osWaitForever, osEventSignal>, &sem)); |
kadonotakashi | 0:8fdf9a60065b | 342 | |
kadonotakashi | 0:8fdf9a60065b | 343 | sem.wait(); |
kadonotakashi | 0:8fdf9a60065b | 344 | TEST_ASSERT_EQUAL(Thread::WaitingThreadFlag, t.get_state()); |
kadonotakashi | 0:8fdf9a60065b | 345 | |
kadonotakashi | 0:8fdf9a60065b | 346 | for (int i = 0; i < MAX_FLAG_POS; i++) { |
kadonotakashi | 0:8fdf9a60065b | 347 | int32_t signal = 1 << i; |
kadonotakashi | 0:8fdf9a60065b | 348 | ret = t.signal_set(signal); |
kadonotakashi | 0:8fdf9a60065b | 349 | } |
kadonotakashi | 0:8fdf9a60065b | 350 | ret = t.signal_set(1 << MAX_FLAG_POS); |
kadonotakashi | 0:8fdf9a60065b | 351 | TEST_ASSERT_EQUAL(NO_SIGNALS, ret); |
kadonotakashi | 0:8fdf9a60065b | 352 | t.join(); |
kadonotakashi | 0:8fdf9a60065b | 353 | } |
kadonotakashi | 0:8fdf9a60065b | 354 | |
kadonotakashi | 0:8fdf9a60065b | 355 | /** Validate if setting same signal twice cause any unwanted behaviour |
kadonotakashi | 0:8fdf9a60065b | 356 | |
kadonotakashi | 0:8fdf9a60065b | 357 | Given two threads A & B are started and B waiting for a thread signals to be set |
kadonotakashi | 0:8fdf9a60065b | 358 | When thread A executes @a signal_set twice for the same signal |
kadonotakashi | 0:8fdf9a60065b | 359 | Then thread A @a signal_set status is current signal set |
kadonotakashi | 0:8fdf9a60065b | 360 | thread B @a signal_wait status is osEventSignal indicating that all wait signals was set |
kadonotakashi | 0:8fdf9a60065b | 361 | */ |
kadonotakashi | 0:8fdf9a60065b | 362 | void test_set_double(void) |
kadonotakashi | 0:8fdf9a60065b | 363 | { |
kadonotakashi | 0:8fdf9a60065b | 364 | int32_t ret; |
kadonotakashi | 0:8fdf9a60065b | 365 | Semaphore sem(0, 1); |
kadonotakashi | 0:8fdf9a60065b | 366 | |
kadonotakashi | 0:8fdf9a60065b | 367 | Thread t(osPriorityNormal, TEST_STACK_SIZE); |
kadonotakashi | 0:8fdf9a60065b | 368 | t.start(callback(run_release_signal_wait < SIGNAL1 | SIGNAL2 | SIGNAL3, osWaitForever, osEventSignal >, &sem)); |
kadonotakashi | 0:8fdf9a60065b | 369 | |
kadonotakashi | 0:8fdf9a60065b | 370 | sem.wait(); |
kadonotakashi | 0:8fdf9a60065b | 371 | TEST_ASSERT_EQUAL(Thread::WaitingThreadFlag, t.get_state()); |
kadonotakashi | 0:8fdf9a60065b | 372 | |
kadonotakashi | 0:8fdf9a60065b | 373 | ret = t.signal_set(SIGNAL1); |
kadonotakashi | 0:8fdf9a60065b | 374 | TEST_ASSERT_EQUAL(SIGNAL1, ret); |
kadonotakashi | 0:8fdf9a60065b | 375 | |
kadonotakashi | 0:8fdf9a60065b | 376 | ret = t.signal_set(SIGNAL2); |
kadonotakashi | 0:8fdf9a60065b | 377 | TEST_ASSERT_EQUAL(SIGNAL1 | SIGNAL2, ret); |
kadonotakashi | 0:8fdf9a60065b | 378 | |
kadonotakashi | 0:8fdf9a60065b | 379 | ret = t.signal_set(SIGNAL2); |
kadonotakashi | 0:8fdf9a60065b | 380 | TEST_ASSERT_EQUAL(SIGNAL1 | SIGNAL2, ret); |
kadonotakashi | 0:8fdf9a60065b | 381 | TEST_ASSERT_EQUAL(Thread::WaitingThreadFlag, t.get_state()); |
kadonotakashi | 0:8fdf9a60065b | 382 | |
kadonotakashi | 0:8fdf9a60065b | 383 | ret = t.signal_set(SIGNAL3); |
kadonotakashi | 0:8fdf9a60065b | 384 | TEST_ASSERT_EQUAL(NO_SIGNALS, ret); |
kadonotakashi | 0:8fdf9a60065b | 385 | t.join(); |
kadonotakashi | 0:8fdf9a60065b | 386 | } |
kadonotakashi | 0:8fdf9a60065b | 387 | |
kadonotakashi | 0:8fdf9a60065b | 388 | |
kadonotakashi | 0:8fdf9a60065b | 389 | utest::v1::status_t test_setup(const size_t number_of_cases) |
kadonotakashi | 0:8fdf9a60065b | 390 | { |
kadonotakashi | 0:8fdf9a60065b | 391 | GREENTEA_SETUP(10, "default_auto"); |
kadonotakashi | 0:8fdf9a60065b | 392 | return utest::v1::verbose_test_setup_handler(number_of_cases); |
kadonotakashi | 0:8fdf9a60065b | 393 | } |
kadonotakashi | 0:8fdf9a60065b | 394 | |
kadonotakashi | 0:8fdf9a60065b | 395 | Case cases[] = { |
kadonotakashi | 0:8fdf9a60065b | 396 | Case("Validate that call signal_clr(NO_SIGNALS) doesn't change thread signals and return actual signals", test_clear_no_signals), |
kadonotakashi | 0:8fdf9a60065b | 397 | Case("Validate if any signals are set on just created thread", test_init_state), |
kadonotakashi | 0:8fdf9a60065b | 398 | Case("Validate all signals set in one shot", test_set_all), |
kadonotakashi | 0:8fdf9a60065b | 399 | Case("Validate that call signal_set with prohibited signal doesn't change thread signals", test_set_prohibited), |
kadonotakashi | 0:8fdf9a60065b | 400 | Case("Validate all signals clear in one shot", test_clear_all), |
kadonotakashi | 0:8fdf9a60065b | 401 | Case("Validate all signals set one by one in loop", test_set_all_loop), |
kadonotakashi | 0:8fdf9a60065b | 402 | Case("Validate signal_wait return status if timeout specified: 0[ms] no signals", test_wait_timeout<0, 0, osOK>), |
kadonotakashi | 0:8fdf9a60065b | 403 | Case("Validate signal_wait return status if timeout specified: 0[ms] all signals", test_wait_timeout<ALL_SIGNALS, 0, osOK>), |
kadonotakashi | 0:8fdf9a60065b | 404 | Case("Validate signal_wait return status if timeout specified: 1[ms] no signals", test_wait_timeout<0, 1, osEventTimeout>), |
kadonotakashi | 0:8fdf9a60065b | 405 | Case("Validate signal_wait return status if timeout specified: 1[ms] all signals", test_wait_timeout<ALL_SIGNALS, 1, osEventTimeout>), |
kadonotakashi | 0:8fdf9a60065b | 406 | Case("Validate that call of signal_wait return correctly when thread has all signals already set", test_wait_all_already_set), |
kadonotakashi | 0:8fdf9a60065b | 407 | Case("Validate if signal_wait return correctly when all signals set", test_wait_all), |
kadonotakashi | 0:8fdf9a60065b | 408 | Case("Validate if signal_wait accumulate signals and return correctly when all signals set", test_wait_all_loop), |
kadonotakashi | 0:8fdf9a60065b | 409 | Case("Validate if setting same signal twice cause any unwanted behaviour", test_set_double) |
kadonotakashi | 0:8fdf9a60065b | 410 | }; |
kadonotakashi | 0:8fdf9a60065b | 411 | |
kadonotakashi | 0:8fdf9a60065b | 412 | utest::v1::Specification specification(test_setup, cases); |
kadonotakashi | 0:8fdf9a60065b | 413 | |
kadonotakashi | 0:8fdf9a60065b | 414 | int main() |
kadonotakashi | 0:8fdf9a60065b | 415 | { |
kadonotakashi | 0:8fdf9a60065b | 416 | return !utest::v1::Harness::run(specification); |
kadonotakashi | 0:8fdf9a60065b | 417 | } |