EL4121 Embedded System / mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

UserRevisionLine numberNew contents of line
be_bryan 0:b74591d5ab33 1 /* mbed Microcontroller Library
be_bryan 0:b74591d5ab33 2 * Copyright (c) 2017 ARM Limited
be_bryan 0:b74591d5ab33 3 *
be_bryan 0:b74591d5ab33 4 * Licensed under the Apache License, Version 2.0 (the "License");
be_bryan 0:b74591d5ab33 5 * you may not use this file except in compliance with the License.
be_bryan 0:b74591d5ab33 6 * You may obtain a copy of the License at
be_bryan 0:b74591d5ab33 7 *
be_bryan 0:b74591d5ab33 8 * http://www.apache.org/licenses/LICENSE-2.0
be_bryan 0:b74591d5ab33 9 *
be_bryan 0:b74591d5ab33 10 * Unless required by applicable law or agreed to in writing, software
be_bryan 0:b74591d5ab33 11 * distributed under the License is distributed on an "AS IS" BASIS,
be_bryan 0:b74591d5ab33 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
be_bryan 0:b74591d5ab33 13 * See the License for the specific language governing permissions and
be_bryan 0:b74591d5ab33 14 * limitations under the License.
be_bryan 0:b74591d5ab33 15 */
be_bryan 0:b74591d5ab33 16 #include "mbed.h"
be_bryan 0:b74591d5ab33 17 #include "greentea-client/test_env.h"
be_bryan 0:b74591d5ab33 18 #include "unity.h"
be_bryan 0:b74591d5ab33 19 #include "utest.h"
be_bryan 0:b74591d5ab33 20 #include "rtos.h"
be_bryan 0:b74591d5ab33 21 #include "SynchronizedIntegral.h"
be_bryan 0:b74591d5ab33 22 #include "LockGuard.h"
be_bryan 0:b74591d5ab33 23
be_bryan 0:b74591d5ab33 24 #if defined(MBED_RTOS_SINGLE_THREAD)
be_bryan 0:b74591d5ab33 25 #error [NOT_SUPPORTED] test not supported
be_bryan 0:b74591d5ab33 26 #endif
be_bryan 0:b74591d5ab33 27
be_bryan 0:b74591d5ab33 28 #define THREAD_STACK_SIZE 512
be_bryan 0:b74591d5ab33 29 #define PARALLEL_THREAD_STACK_SIZE 384
be_bryan 0:b74591d5ab33 30 #define CHILD_THREAD_STACK_SIZE 384
be_bryan 0:b74591d5ab33 31
be_bryan 0:b74591d5ab33 32 using namespace utest::v1;
be_bryan 0:b74591d5ab33 33
be_bryan 0:b74591d5ab33 34 // The counter type used accross all the tests
be_bryan 0:b74591d5ab33 35 // It is internall ysynchronized so read
be_bryan 0:b74591d5ab33 36 typedef SynchronizedIntegral<int> counter_t;
be_bryan 0:b74591d5ab33 37
be_bryan 0:b74591d5ab33 38 template<osPriority P, uint32_t S>
be_bryan 0:b74591d5ab33 39 class ParallelThread : public Thread {
be_bryan 0:b74591d5ab33 40 public:
be_bryan 0:b74591d5ab33 41 ParallelThread() : Thread(P, S) { }
be_bryan 0:b74591d5ab33 42 };
be_bryan 0:b74591d5ab33 43
be_bryan 0:b74591d5ab33 44 // Tasks with different functions to test on threads
be_bryan 0:b74591d5ab33 45 void increment(counter_t* counter) {
be_bryan 0:b74591d5ab33 46 (*counter)++;
be_bryan 0:b74591d5ab33 47 }
be_bryan 0:b74591d5ab33 48
be_bryan 0:b74591d5ab33 49 void increment_with_yield(counter_t* counter) {
be_bryan 0:b74591d5ab33 50 Thread::yield();
be_bryan 0:b74591d5ab33 51 (*counter)++;
be_bryan 0:b74591d5ab33 52 }
be_bryan 0:b74591d5ab33 53
be_bryan 0:b74591d5ab33 54 void increment_with_wait(counter_t* counter) {
be_bryan 0:b74591d5ab33 55 Thread::wait(100);
be_bryan 0:b74591d5ab33 56 (*counter)++;
be_bryan 0:b74591d5ab33 57 }
be_bryan 0:b74591d5ab33 58
be_bryan 0:b74591d5ab33 59 void increment_with_child(counter_t* counter) {
be_bryan 0:b74591d5ab33 60 Thread *child = new Thread(osPriorityNormal, CHILD_THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 61 child->start(callback(increment, counter));
be_bryan 0:b74591d5ab33 62 child->join();
be_bryan 0:b74591d5ab33 63 delete child;
be_bryan 0:b74591d5ab33 64 }
be_bryan 0:b74591d5ab33 65
be_bryan 0:b74591d5ab33 66 void increment_with_murder(counter_t* counter) {
be_bryan 0:b74591d5ab33 67 {
be_bryan 0:b74591d5ab33 68 // take ownership of the counter mutex so it prevent the child to
be_bryan 0:b74591d5ab33 69 // modify counter.
be_bryan 0:b74591d5ab33 70 LockGuard lock(counter->internal_mutex());
be_bryan 0:b74591d5ab33 71 Thread *child = new Thread(osPriorityNormal, CHILD_THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 72 child->start(callback(increment, counter));
be_bryan 0:b74591d5ab33 73 child->terminate();
be_bryan 0:b74591d5ab33 74 delete child;
be_bryan 0:b74591d5ab33 75 }
be_bryan 0:b74591d5ab33 76
be_bryan 0:b74591d5ab33 77 (*counter)++;
be_bryan 0:b74591d5ab33 78 }
be_bryan 0:b74591d5ab33 79
be_bryan 0:b74591d5ab33 80 void self_terminate(Thread *self) {
be_bryan 0:b74591d5ab33 81 self->terminate();
be_bryan 0:b74591d5ab33 82 // Code should not get here
be_bryan 0:b74591d5ab33 83 TEST_ASSERT(0);
be_bryan 0:b74591d5ab33 84 }
be_bryan 0:b74591d5ab33 85
be_bryan 0:b74591d5ab33 86 // Tests that spawn tasks in different configurations
be_bryan 0:b74591d5ab33 87
be_bryan 0:b74591d5ab33 88 /** Template for tests: single thread, with yield, with wait, with child, with murder
be_bryan 0:b74591d5ab33 89
be_bryan 0:b74591d5ab33 90 Testing single thread
be_bryan 0:b74591d5ab33 91 Given single thread is started
be_bryan 0:b74591d5ab33 92 when the thread increments the counter
be_bryan 0:b74591d5ab33 93 then the final value of the counter is equal to 1
be_bryan 0:b74591d5ab33 94
be_bryan 0:b74591d5ab33 95 Testing single thread with yield
be_bryan 0:b74591d5ab33 96 Given single thread is started
be_bryan 0:b74591d5ab33 97 when the thread yields and then increments the counter
be_bryan 0:b74591d5ab33 98 then the final value of the counter is equal to 1
be_bryan 0:b74591d5ab33 99
be_bryan 0:b74591d5ab33 100 Testing single thread with wait
be_bryan 0:b74591d5ab33 101 Given single thread is started
be_bryan 0:b74591d5ab33 102 when the thread waits for 100ms and then increments the counter
be_bryan 0:b74591d5ab33 103 then the final value of the counter is equal to 1
be_bryan 0:b74591d5ab33 104
be_bryan 0:b74591d5ab33 105 Testing single thread with child
be_bryan 0:b74591d5ab33 106 Given single thread is started
be_bryan 0:b74591d5ab33 107 when the thread spawns another thread that increments the counter
be_bryan 0:b74591d5ab33 108 then the final value of the counter is equal to 1
be_bryan 0:b74591d5ab33 109
be_bryan 0:b74591d5ab33 110 Testing serial threads with murder
be_bryan 0:b74591d5ab33 111 Given single thread is started
be_bryan 0:b74591d5ab33 112 when the parent thread is holding a lock
be_bryan 0:b74591d5ab33 113 and the parent thread spawns a child thread that waits for the lock before incrementing the counter
be_bryan 0:b74591d5ab33 114 and the parent terminates the child before releasing the lock
be_bryan 0:b74591d5ab33 115 and the parent increments the counter
be_bryan 0:b74591d5ab33 116 then the final value of the counter is equal to 1
be_bryan 0:b74591d5ab33 117 */
be_bryan 0:b74591d5ab33 118 template <void (*F)(counter_t *)>
be_bryan 0:b74591d5ab33 119 void test_single_thread() {
be_bryan 0:b74591d5ab33 120 counter_t counter(0);
be_bryan 0:b74591d5ab33 121 Thread thread(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 122 thread.start(callback(F, &counter));
be_bryan 0:b74591d5ab33 123 thread.join();
be_bryan 0:b74591d5ab33 124 TEST_ASSERT_EQUAL(counter, 1);
be_bryan 0:b74591d5ab33 125 }
be_bryan 0:b74591d5ab33 126
be_bryan 0:b74591d5ab33 127 /** Template for tests: parallel threads, with yield, with wait, with child, with murder
be_bryan 0:b74591d5ab33 128
be_bryan 0:b74591d5ab33 129 Testing parallel threads
be_bryan 0:b74591d5ab33 130 Given multiple threads are started in parallel
be_bryan 0:b74591d5ab33 131 when each of the threads increments the counter
be_bryan 0:b74591d5ab33 132 then the final value of the counter is equal to number of threads
be_bryan 0:b74591d5ab33 133
be_bryan 0:b74591d5ab33 134 Testing parallel threads with yield
be_bryan 0:b74591d5ab33 135 Given multiple threads are started in parallel
be_bryan 0:b74591d5ab33 136 when each of the threads yields and then increments the counter
be_bryan 0:b74591d5ab33 137 then the final value of the counter is equal to number of threads
be_bryan 0:b74591d5ab33 138
be_bryan 0:b74591d5ab33 139 Testing parallel threads with wait
be_bryan 0:b74591d5ab33 140 Given multiple threads are started in parallel
be_bryan 0:b74591d5ab33 141 when each of the threads waits for 100ms and then increments the counter
be_bryan 0:b74591d5ab33 142 then the final value of the counter is equal to number of threads
be_bryan 0:b74591d5ab33 143
be_bryan 0:b74591d5ab33 144 Testing parallel threads with child
be_bryan 0:b74591d5ab33 145 Given multiple threads are started in parallel
be_bryan 0:b74591d5ab33 146 when each of the threads spawns another thread that increments the counter
be_bryan 0:b74591d5ab33 147 then the final value of the counter is equal to number of parallel threads
be_bryan 0:b74591d5ab33 148
be_bryan 0:b74591d5ab33 149 Testing parallel threads with murder
be_bryan 0:b74591d5ab33 150 Given multiple threads are started in parallel
be_bryan 0:b74591d5ab33 151 when the parent thread is holding a lock
be_bryan 0:b74591d5ab33 152 and the parent thread spawns a child thread that waits for the lock before incrementing the counter
be_bryan 0:b74591d5ab33 153 and the parent terminates the child before releasing the lock
be_bryan 0:b74591d5ab33 154 and the parent increments the counter
be_bryan 0:b74591d5ab33 155 then the final value of the counter is equal to number of parallel threads
be_bryan 0:b74591d5ab33 156 */
be_bryan 0:b74591d5ab33 157 template <int N, void (*F)(counter_t *)>
be_bryan 0:b74591d5ab33 158 void test_parallel_threads() {
be_bryan 0:b74591d5ab33 159 counter_t counter(0);
be_bryan 0:b74591d5ab33 160 ParallelThread<osPriorityNormal, PARALLEL_THREAD_STACK_SIZE> threads[N];
be_bryan 0:b74591d5ab33 161
be_bryan 0:b74591d5ab33 162 for (int i = 0; i < N; i++) {
be_bryan 0:b74591d5ab33 163 threads[i].start(callback(F, &counter));
be_bryan 0:b74591d5ab33 164 }
be_bryan 0:b74591d5ab33 165
be_bryan 0:b74591d5ab33 166 for (int i = 0; i < N; i++) {
be_bryan 0:b74591d5ab33 167 threads[i].join();
be_bryan 0:b74591d5ab33 168 }
be_bryan 0:b74591d5ab33 169
be_bryan 0:b74591d5ab33 170 TEST_ASSERT_EQUAL(counter, N);
be_bryan 0:b74591d5ab33 171 }
be_bryan 0:b74591d5ab33 172
be_bryan 0:b74591d5ab33 173 /** Template for tests: serial threads, with yield, with wait, with child, with murder
be_bryan 0:b74591d5ab33 174
be_bryan 0:b74591d5ab33 175 Testing serial threads
be_bryan 0:b74591d5ab33 176 Given multiple threads are started serially
be_bryan 0:b74591d5ab33 177 when each of the threads increments the counter
be_bryan 0:b74591d5ab33 178 then the final value of the counter is equal to number of threads
be_bryan 0:b74591d5ab33 179
be_bryan 0:b74591d5ab33 180 Testing serial threads with yield
be_bryan 0:b74591d5ab33 181 Given multiple threads are started serially
be_bryan 0:b74591d5ab33 182 when each of the threads yields and then increments the counter
be_bryan 0:b74591d5ab33 183 then the final value of the counter is equal to number of threads
be_bryan 0:b74591d5ab33 184
be_bryan 0:b74591d5ab33 185 Testing serial threads with wait
be_bryan 0:b74591d5ab33 186 Given multiple threads are started serially
be_bryan 0:b74591d5ab33 187 when each of the threads waits for 100ms and then increments the counter
be_bryan 0:b74591d5ab33 188 then the final value of the counter is equal to number of threads
be_bryan 0:b74591d5ab33 189
be_bryan 0:b74591d5ab33 190 Testing serial threads with child
be_bryan 0:b74591d5ab33 191 Given multiple threads are started serially
be_bryan 0:b74591d5ab33 192 when each of the threads spawns another thread that increments the counter
be_bryan 0:b74591d5ab33 193 then the final value of the counter is equal to number of serial threads
be_bryan 0:b74591d5ab33 194
be_bryan 0:b74591d5ab33 195 Testing serial threads with murder
be_bryan 0:b74591d5ab33 196 Given multiple threads are started serially
be_bryan 0:b74591d5ab33 197 when the parent thread is holding a lock
be_bryan 0:b74591d5ab33 198 and the parent thread spawns a child thread that waits for the lock before incrementing the counter
be_bryan 0:b74591d5ab33 199 and the parent terminates the child before releasing the lock
be_bryan 0:b74591d5ab33 200 and the parent increments the counter
be_bryan 0:b74591d5ab33 201 then the final value of the counter is equal to number of serial threads
be_bryan 0:b74591d5ab33 202 */
be_bryan 0:b74591d5ab33 203 template <int N, void (*F)(counter_t *)>
be_bryan 0:b74591d5ab33 204 void test_serial_threads() {
be_bryan 0:b74591d5ab33 205 counter_t counter(0);
be_bryan 0:b74591d5ab33 206
be_bryan 0:b74591d5ab33 207 for (int i = 0; i < N; i++) {
be_bryan 0:b74591d5ab33 208 Thread thread(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 209 thread.start(callback(F, &counter));
be_bryan 0:b74591d5ab33 210 thread.join();
be_bryan 0:b74591d5ab33 211 }
be_bryan 0:b74591d5ab33 212
be_bryan 0:b74591d5ab33 213 TEST_ASSERT_EQUAL(counter, N);
be_bryan 0:b74591d5ab33 214 }
be_bryan 0:b74591d5ab33 215
be_bryan 0:b74591d5ab33 216 /** Testing thread self terminate
be_bryan 0:b74591d5ab33 217
be_bryan 0:b74591d5ab33 218 Given the thread is running
be_bryan 0:b74591d5ab33 219 when the thread calls @a terminate on its self
be_bryan 0:b74591d5ab33 220 then the thread terminates execution cleanly
be_bryan 0:b74591d5ab33 221 */
be_bryan 0:b74591d5ab33 222 void test_self_terminate() {
be_bryan 0:b74591d5ab33 223 Thread *thread = new Thread(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 224 thread->start(callback(self_terminate, thread));
be_bryan 0:b74591d5ab33 225 thread->join();
be_bryan 0:b74591d5ab33 226 delete thread;
be_bryan 0:b74591d5ab33 227 }
be_bryan 0:b74591d5ab33 228
be_bryan 0:b74591d5ab33 229 void signal_wait()
be_bryan 0:b74591d5ab33 230 {
be_bryan 0:b74591d5ab33 231 osEvent evt = Thread::signal_wait(0x1);
be_bryan 0:b74591d5ab33 232 TEST_ASSERT_EQUAL(osEventSignal, evt.status);
be_bryan 0:b74591d5ab33 233 TEST_ASSERT_EQUAL(0x1, evt.value.signals);
be_bryan 0:b74591d5ab33 234 }
be_bryan 0:b74591d5ab33 235
be_bryan 0:b74591d5ab33 236 void signal_wait_tout()
be_bryan 0:b74591d5ab33 237 {
be_bryan 0:b74591d5ab33 238 osEvent evt = Thread::signal_wait(0x2, 50);
be_bryan 0:b74591d5ab33 239 TEST_ASSERT_EQUAL(osEventTimeout, evt.status);
be_bryan 0:b74591d5ab33 240 }
be_bryan 0:b74591d5ab33 241
be_bryan 0:b74591d5ab33 242 void signal_wait_multibit()
be_bryan 0:b74591d5ab33 243 {
be_bryan 0:b74591d5ab33 244 osEvent evt = Thread::signal_wait(0x1 | 0x2, 50);
be_bryan 0:b74591d5ab33 245 TEST_ASSERT_EQUAL(osEventSignal, evt.status);
be_bryan 0:b74591d5ab33 246 TEST_ASSERT_EQUAL(0x3, evt.value.signals);
be_bryan 0:b74591d5ab33 247 }
be_bryan 0:b74591d5ab33 248
be_bryan 0:b74591d5ab33 249 void signal_wait_multibit_tout()
be_bryan 0:b74591d5ab33 250 {
be_bryan 0:b74591d5ab33 251 osEvent evt = Thread::signal_wait(0x1 | 0x2, 50);
be_bryan 0:b74591d5ab33 252 TEST_ASSERT_EQUAL(osEventTimeout, evt.status);
be_bryan 0:b74591d5ab33 253 }
be_bryan 0:b74591d5ab33 254
be_bryan 0:b74591d5ab33 255 /**
be_bryan 0:b74591d5ab33 256 Testing thread signal: wait
be_bryan 0:b74591d5ab33 257 Given two threads (A & B) are started
be_bryan 0:b74591d5ab33 258 when thread A executes @a signal_wait(0x1)
be_bryan 0:b74591d5ab33 259 and thread B execute @a signal_set(0x1)
be_bryan 0:b74591d5ab33 260 then thread A exits the wait and continues execution
be_bryan 0:b74591d5ab33 261
be_bryan 0:b74591d5ab33 262 Testing thread signal: timeout
be_bryan 0:b74591d5ab33 263 Given two threads (A & B) are started
be_bryan 0:b74591d5ab33 264 when thread A executes @a signal_wait(0x1 | 0x2, 50) with a timeout of 50ms
be_bryan 0:b74591d5ab33 265 and thread B execute @a signal_set(0x2)
be_bryan 0:b74591d5ab33 266 then thread A keeps waiting for correct signal until it timeouts
be_bryan 0:b74591d5ab33 267
be_bryan 0:b74591d5ab33 268 Testing thread signal: multi-bit
be_bryan 0:b74591d5ab33 269 Given two threads (A & B) are started
be_bryan 0:b74591d5ab33 270 when thread A executes @a signal_wait(0x1 | 0x2)
be_bryan 0:b74591d5ab33 271 and thread B execute @a signal_set(0x1 | 0x2)
be_bryan 0:b74591d5ab33 272 then thread A exits the wait and continues execution
be_bryan 0:b74591d5ab33 273
be_bryan 0:b74591d5ab33 274 Testing thread signal: multi-bit timeout
be_bryan 0:b74591d5ab33 275 Given two threads (A & B) are started
be_bryan 0:b74591d5ab33 276 when thread A executes @a signal_wait(0x1, 50) with a timeout of 50ms
be_bryan 0:b74591d5ab33 277 and thread B execute @a signal_set(0x2)
be_bryan 0:b74591d5ab33 278 then thread A keeps waiting for correct signal until it timeouts
be_bryan 0:b74591d5ab33 279 */
be_bryan 0:b74591d5ab33 280 template <int S, void (*F)()>
be_bryan 0:b74591d5ab33 281 void test_thread_signal()
be_bryan 0:b74591d5ab33 282 {
be_bryan 0:b74591d5ab33 283 Thread t_wait(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 284
be_bryan 0:b74591d5ab33 285 t_wait.start(callback(F));
be_bryan 0:b74591d5ab33 286
be_bryan 0:b74591d5ab33 287 Thread::yield();
be_bryan 0:b74591d5ab33 288
be_bryan 0:b74591d5ab33 289 Thread::State state = t_wait.get_state();
be_bryan 0:b74591d5ab33 290 TEST_ASSERT_EQUAL(Thread::WaitingThreadFlag, state);
be_bryan 0:b74591d5ab33 291
be_bryan 0:b74591d5ab33 292 int32_t res = t_wait.signal_set(S);
be_bryan 0:b74591d5ab33 293
be_bryan 0:b74591d5ab33 294 t_wait.join();
be_bryan 0:b74591d5ab33 295 }
be_bryan 0:b74591d5ab33 296
be_bryan 0:b74591d5ab33 297 void signal_clr()
be_bryan 0:b74591d5ab33 298 {
be_bryan 0:b74591d5ab33 299 Thread::yield();
be_bryan 0:b74591d5ab33 300
be_bryan 0:b74591d5ab33 301 int32_t sig = Thread::signal_clr(0x1);
be_bryan 0:b74591d5ab33 302 TEST_ASSERT_EQUAL(0x1, sig);
be_bryan 0:b74591d5ab33 303
be_bryan 0:b74591d5ab33 304 /* Signal cleared we should get timeout */
be_bryan 0:b74591d5ab33 305 osEvent evt = Thread::signal_wait(0x1, 0);
be_bryan 0:b74591d5ab33 306 TEST_ASSERT_EQUAL(osOK, evt.status);
be_bryan 0:b74591d5ab33 307 }
be_bryan 0:b74591d5ab33 308
be_bryan 0:b74591d5ab33 309 /** Testing thread signals: signal clear
be_bryan 0:b74591d5ab33 310
be_bryan 0:b74591d5ab33 311 Given two threads (A & B) are started
be_bryan 0:b74591d5ab33 312 when thread A executes @a signal_set(0x1)
be_bryan 0:b74591d5ab33 313 and thread B execute @a signal_clr(0x1)
be_bryan 0:b74591d5ab33 314 and thread B execute @a signal_wait(0x1, 0)
be_bryan 0:b74591d5ab33 315 then thread B @a signal_wait status should be osOK indicating a timeout
be_bryan 0:b74591d5ab33 316 */
be_bryan 0:b74591d5ab33 317 void test_thread_signal_clr()
be_bryan 0:b74591d5ab33 318 {
be_bryan 0:b74591d5ab33 319 Thread t_wait(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 320
be_bryan 0:b74591d5ab33 321 t_wait.start(callback(signal_clr));
be_bryan 0:b74591d5ab33 322
be_bryan 0:b74591d5ab33 323 int32_t res = t_wait.signal_set(0x1);
be_bryan 0:b74591d5ab33 324 TEST_ASSERT_EQUAL(0x1, res);
be_bryan 0:b74591d5ab33 325
be_bryan 0:b74591d5ab33 326 t_wait.join();
be_bryan 0:b74591d5ab33 327 }
be_bryan 0:b74591d5ab33 328
be_bryan 0:b74591d5ab33 329 void thread_wait_signal() {
be_bryan 0:b74591d5ab33 330 Thread::signal_wait(0x1);
be_bryan 0:b74591d5ab33 331 }
be_bryan 0:b74591d5ab33 332
be_bryan 0:b74591d5ab33 333 void stack_info() {
be_bryan 0:b74591d5ab33 334 Thread::signal_wait(0x1);
be_bryan 0:b74591d5ab33 335
be_bryan 0:b74591d5ab33 336 thread_wait_signal();
be_bryan 0:b74591d5ab33 337
be_bryan 0:b74591d5ab33 338 Thread::signal_wait(0x1);
be_bryan 0:b74591d5ab33 339 }
be_bryan 0:b74591d5ab33 340
be_bryan 0:b74591d5ab33 341 /** Testing thread stack info
be_bryan 0:b74591d5ab33 342
be_bryan 0:b74591d5ab33 343 Given the thread is running
be_bryan 0:b74591d5ab33 344 when a function is called from the thread context
be_bryan 0:b74591d5ab33 345 then the stack usage goes up
be_bryan 0:b74591d5ab33 346 and the reported stack size is as requested in the constructor
be_bryan 0:b74591d5ab33 347 and the sum of free and used stack sizes is equal to the total stack size
be_bryan 0:b74591d5ab33 348 when the function returns
be_bryan 0:b74591d5ab33 349 then the stack usage goes down
be_bryan 0:b74591d5ab33 350 and the reported stack size is as requested in the constructor
be_bryan 0:b74591d5ab33 351 and the sum of free and used stack sizes is equal to the total stack size
be_bryan 0:b74591d5ab33 352 */
be_bryan 0:b74591d5ab33 353 void test_thread_stack_info() {
be_bryan 0:b74591d5ab33 354 Thread t(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 355 t.start(callback(stack_info));
be_bryan 0:b74591d5ab33 356
be_bryan 0:b74591d5ab33 357 Thread::yield();
be_bryan 0:b74591d5ab33 358
be_bryan 0:b74591d5ab33 359 TEST_ASSERT_EQUAL(THREAD_STACK_SIZE, t.stack_size());
be_bryan 0:b74591d5ab33 360 TEST_ASSERT_EQUAL(THREAD_STACK_SIZE, t.free_stack() + t.used_stack());
be_bryan 0:b74591d5ab33 361 uint32_t last_stack = t.used_stack();
be_bryan 0:b74591d5ab33 362
be_bryan 0:b74591d5ab33 363 t.signal_set(0x1);
be_bryan 0:b74591d5ab33 364 Thread::yield();
be_bryan 0:b74591d5ab33 365
be_bryan 0:b74591d5ab33 366 TEST_ASSERT_EQUAL(THREAD_STACK_SIZE, t.free_stack() + t.used_stack());
be_bryan 0:b74591d5ab33 367 TEST_ASSERT(last_stack <= t.used_stack());
be_bryan 0:b74591d5ab33 368 last_stack = t.used_stack();
be_bryan 0:b74591d5ab33 369
be_bryan 0:b74591d5ab33 370 t.signal_set(0x1);
be_bryan 0:b74591d5ab33 371 Thread::yield();
be_bryan 0:b74591d5ab33 372
be_bryan 0:b74591d5ab33 373 TEST_ASSERT_EQUAL(THREAD_STACK_SIZE, t.free_stack() + t.used_stack());
be_bryan 0:b74591d5ab33 374 TEST_ASSERT(last_stack >= t.used_stack());
be_bryan 0:b74591d5ab33 375
be_bryan 0:b74591d5ab33 376 t.signal_set(0x1);
be_bryan 0:b74591d5ab33 377
be_bryan 0:b74591d5ab33 378 t.join();
be_bryan 0:b74591d5ab33 379 }
be_bryan 0:b74591d5ab33 380
be_bryan 0:b74591d5ab33 381 /** Testing thread wait aka delay
be_bryan 0:b74591d5ab33 382
be_bryan 0:b74591d5ab33 383 Given the thread is running
be_bryan 0:b74591d5ab33 384 when the @a wait function is called
be_bryan 0:b74591d5ab33 385 then the thread sleeps for given amount of time
be_bryan 0:b74591d5ab33 386 */
be_bryan 0:b74591d5ab33 387 void test_thread_wait() {
be_bryan 0:b74591d5ab33 388 Timer timer;
be_bryan 0:b74591d5ab33 389 timer.start();
be_bryan 0:b74591d5ab33 390
be_bryan 0:b74591d5ab33 391 Thread::wait(150);
be_bryan 0:b74591d5ab33 392
be_bryan 0:b74591d5ab33 393 TEST_ASSERT_UINT32_WITHIN(50000, 150000, timer.read_us());
be_bryan 0:b74591d5ab33 394 }
be_bryan 0:b74591d5ab33 395
be_bryan 0:b74591d5ab33 396 /** Testing thread name
be_bryan 0:b74591d5ab33 397
be_bryan 0:b74591d5ab33 398 Given a thread is started with a specified name
be_bryan 0:b74591d5ab33 399 when the name is queried using @a get_name
be_bryan 0:b74591d5ab33 400 then the returned name is as set
be_bryan 0:b74591d5ab33 401 */
be_bryan 0:b74591d5ab33 402 void test_thread_name() {
be_bryan 0:b74591d5ab33 403 const char tname[] = "Amazing thread";
be_bryan 0:b74591d5ab33 404 Thread t(osPriorityNormal, THREAD_STACK_SIZE, NULL, tname);
be_bryan 0:b74591d5ab33 405 t.start(callback(thread_wait_signal));
be_bryan 0:b74591d5ab33 406 TEST_ASSERT_EQUAL(strcmp(tname, t.get_name()), 0);
be_bryan 0:b74591d5ab33 407 t.signal_set(0x1);
be_bryan 0:b74591d5ab33 408 t.join();
be_bryan 0:b74591d5ab33 409 }
be_bryan 0:b74591d5ab33 410
be_bryan 0:b74591d5ab33 411 void test_deleted_thread()
be_bryan 0:b74591d5ab33 412 {
be_bryan 0:b74591d5ab33 413 }
be_bryan 0:b74591d5ab33 414
be_bryan 0:b74591d5ab33 415 /** Testing thread states: deleted
be_bryan 0:b74591d5ab33 416
be_bryan 0:b74591d5ab33 417 Given the thread is not started
be_bryan 0:b74591d5ab33 418 then its state, as reported by @a get_state, is @a Deleted
be_bryan 0:b74591d5ab33 419 when the thread is started and finishes executing
be_bryan 0:b74591d5ab33 420 then its state, as reported by @a get_state, is @a Deleted
be_bryan 0:b74591d5ab33 421 */
be_bryan 0:b74591d5ab33 422 void test_deleted()
be_bryan 0:b74591d5ab33 423 {
be_bryan 0:b74591d5ab33 424 Thread t(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 425
be_bryan 0:b74591d5ab33 426 TEST_ASSERT_EQUAL(Thread::Deleted, t.get_state());
be_bryan 0:b74591d5ab33 427
be_bryan 0:b74591d5ab33 428 t.start(callback(test_deleted_thread));
be_bryan 0:b74591d5ab33 429
be_bryan 0:b74591d5ab33 430 t.join();
be_bryan 0:b74591d5ab33 431 TEST_ASSERT_EQUAL(Thread::Deleted, t.get_state());
be_bryan 0:b74591d5ab33 432 }
be_bryan 0:b74591d5ab33 433
be_bryan 0:b74591d5ab33 434 void test_delay_thread()
be_bryan 0:b74591d5ab33 435 {
be_bryan 0:b74591d5ab33 436 Thread::wait(50);
be_bryan 0:b74591d5ab33 437 }
be_bryan 0:b74591d5ab33 438
be_bryan 0:b74591d5ab33 439 /** Testing thread states: wait delay
be_bryan 0:b74591d5ab33 440
be_bryan 0:b74591d5ab33 441 Given the thread is running
be_bryan 0:b74591d5ab33 442 when thread calls @a wait
be_bryan 0:b74591d5ab33 443 then its state, as reported by @a get_state, is @a WaitingDelay
be_bryan 0:b74591d5ab33 444 */
be_bryan 0:b74591d5ab33 445 void test_delay()
be_bryan 0:b74591d5ab33 446 {
be_bryan 0:b74591d5ab33 447 Thread t(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 448
be_bryan 0:b74591d5ab33 449 t.start(callback(test_delay_thread));
be_bryan 0:b74591d5ab33 450
be_bryan 0:b74591d5ab33 451 Thread::yield();
be_bryan 0:b74591d5ab33 452
be_bryan 0:b74591d5ab33 453 TEST_ASSERT_EQUAL(Thread::WaitingDelay, t.get_state());
be_bryan 0:b74591d5ab33 454
be_bryan 0:b74591d5ab33 455 t.join();
be_bryan 0:b74591d5ab33 456 TEST_ASSERT_EQUAL(Thread::Deleted, t.get_state());
be_bryan 0:b74591d5ab33 457 }
be_bryan 0:b74591d5ab33 458
be_bryan 0:b74591d5ab33 459 void test_signal_thread()
be_bryan 0:b74591d5ab33 460 {
be_bryan 0:b74591d5ab33 461 Thread::signal_wait(0x1);
be_bryan 0:b74591d5ab33 462 }
be_bryan 0:b74591d5ab33 463
be_bryan 0:b74591d5ab33 464 /** Testing thread states: wait signal
be_bryan 0:b74591d5ab33 465
be_bryan 0:b74591d5ab33 466 Given the thread is running
be_bryan 0:b74591d5ab33 467 when thread waits for a signal
be_bryan 0:b74591d5ab33 468 then its state, as reported by @a get_state, is @a WaitingSignal
be_bryan 0:b74591d5ab33 469 */
be_bryan 0:b74591d5ab33 470 void test_signal()
be_bryan 0:b74591d5ab33 471 {
be_bryan 0:b74591d5ab33 472 Thread t(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 473
be_bryan 0:b74591d5ab33 474 t.start(callback(test_signal_thread));
be_bryan 0:b74591d5ab33 475
be_bryan 0:b74591d5ab33 476 Thread::yield();
be_bryan 0:b74591d5ab33 477
be_bryan 0:b74591d5ab33 478 TEST_ASSERT_EQUAL(Thread::WaitingThreadFlag, t.get_state());
be_bryan 0:b74591d5ab33 479
be_bryan 0:b74591d5ab33 480 t.signal_set(0x1);
be_bryan 0:b74591d5ab33 481 }
be_bryan 0:b74591d5ab33 482
be_bryan 0:b74591d5ab33 483 void test_evt_flag_thread(osEventFlagsId_t evtflg)
be_bryan 0:b74591d5ab33 484 {
be_bryan 0:b74591d5ab33 485 osEventFlagsWait(evtflg, 0x1, osFlagsWaitAny, osWaitForever);
be_bryan 0:b74591d5ab33 486 }
be_bryan 0:b74591d5ab33 487
be_bryan 0:b74591d5ab33 488 /** Testing thread states: wait evt flag
be_bryan 0:b74591d5ab33 489
be_bryan 0:b74591d5ab33 490 Given the thread is running
be_bryan 0:b74591d5ab33 491 when thread waits for an event flag
be_bryan 0:b74591d5ab33 492 then its state, as reported by @a get_state, is @a WaitingEventFlag
be_bryan 0:b74591d5ab33 493 */
be_bryan 0:b74591d5ab33 494 void test_evt_flag()
be_bryan 0:b74591d5ab33 495 {
be_bryan 0:b74591d5ab33 496 Thread t(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 497 mbed_rtos_storage_event_flags_t evtflg_mem;
be_bryan 0:b74591d5ab33 498 osEventFlagsAttr_t evtflg_attr;
be_bryan 0:b74591d5ab33 499 osEventFlagsId_t evtflg;
be_bryan 0:b74591d5ab33 500
be_bryan 0:b74591d5ab33 501 evtflg_attr.cb_mem = &evtflg_mem;
be_bryan 0:b74591d5ab33 502 evtflg_attr.cb_size = sizeof(evtflg_mem);
be_bryan 0:b74591d5ab33 503 evtflg = osEventFlagsNew(&evtflg_attr);
be_bryan 0:b74591d5ab33 504 TEST_ASSERT_NOT_EQUAL(NULL, evtflg);
be_bryan 0:b74591d5ab33 505
be_bryan 0:b74591d5ab33 506 t.start(callback(test_evt_flag_thread, evtflg));
be_bryan 0:b74591d5ab33 507
be_bryan 0:b74591d5ab33 508 Thread::yield();
be_bryan 0:b74591d5ab33 509
be_bryan 0:b74591d5ab33 510 TEST_ASSERT_EQUAL(Thread::WaitingEventFlag, t.get_state());
be_bryan 0:b74591d5ab33 511
be_bryan 0:b74591d5ab33 512 osEventFlagsSet(evtflg, 0x1);
be_bryan 0:b74591d5ab33 513 }
be_bryan 0:b74591d5ab33 514
be_bryan 0:b74591d5ab33 515 void test_mutex_thread(Mutex *mutex)
be_bryan 0:b74591d5ab33 516 {
be_bryan 0:b74591d5ab33 517 mutex->lock();
be_bryan 0:b74591d5ab33 518 }
be_bryan 0:b74591d5ab33 519
be_bryan 0:b74591d5ab33 520 /** Testing thread states: wait mutex
be_bryan 0:b74591d5ab33 521
be_bryan 0:b74591d5ab33 522 Given the thread is running
be_bryan 0:b74591d5ab33 523 when thread waits for a mutex
be_bryan 0:b74591d5ab33 524 then its state, as reported by @a get_state, is @a WaitingMutex
be_bryan 0:b74591d5ab33 525 */
be_bryan 0:b74591d5ab33 526 void test_mutex()
be_bryan 0:b74591d5ab33 527 {
be_bryan 0:b74591d5ab33 528 Thread t(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 529 Mutex mutex;
be_bryan 0:b74591d5ab33 530
be_bryan 0:b74591d5ab33 531 mutex.lock();
be_bryan 0:b74591d5ab33 532
be_bryan 0:b74591d5ab33 533 t.start(callback(test_mutex_thread, &mutex));
be_bryan 0:b74591d5ab33 534
be_bryan 0:b74591d5ab33 535 Thread::yield();
be_bryan 0:b74591d5ab33 536
be_bryan 0:b74591d5ab33 537 TEST_ASSERT_EQUAL(Thread::WaitingMutex, t.get_state());
be_bryan 0:b74591d5ab33 538
be_bryan 0:b74591d5ab33 539 mutex.unlock();
be_bryan 0:b74591d5ab33 540 }
be_bryan 0:b74591d5ab33 541
be_bryan 0:b74591d5ab33 542 void test_semaphore_thread(Semaphore *sem)
be_bryan 0:b74591d5ab33 543 {
be_bryan 0:b74591d5ab33 544 sem->wait();
be_bryan 0:b74591d5ab33 545 }
be_bryan 0:b74591d5ab33 546
be_bryan 0:b74591d5ab33 547 /** Testing thread states: wait semaphore
be_bryan 0:b74591d5ab33 548
be_bryan 0:b74591d5ab33 549 Given the thread is running
be_bryan 0:b74591d5ab33 550 when thread waits for a semaphore
be_bryan 0:b74591d5ab33 551 then its state, as reported by @a get_state, is @a WaitingSemaphore
be_bryan 0:b74591d5ab33 552 */
be_bryan 0:b74591d5ab33 553 void test_semaphore()
be_bryan 0:b74591d5ab33 554 {
be_bryan 0:b74591d5ab33 555 Thread t(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 556 Semaphore sem;
be_bryan 0:b74591d5ab33 557
be_bryan 0:b74591d5ab33 558 t.start(callback(test_semaphore_thread, &sem));
be_bryan 0:b74591d5ab33 559
be_bryan 0:b74591d5ab33 560 Thread::yield();
be_bryan 0:b74591d5ab33 561
be_bryan 0:b74591d5ab33 562 TEST_ASSERT_EQUAL(Thread::WaitingSemaphore, t.get_state());
be_bryan 0:b74591d5ab33 563
be_bryan 0:b74591d5ab33 564 sem.release();
be_bryan 0:b74591d5ab33 565 }
be_bryan 0:b74591d5ab33 566
be_bryan 0:b74591d5ab33 567 void test_msg_get_thread(Queue<int32_t, 1> *queue)
be_bryan 0:b74591d5ab33 568 {
be_bryan 0:b74591d5ab33 569 queue->get();
be_bryan 0:b74591d5ab33 570 }
be_bryan 0:b74591d5ab33 571
be_bryan 0:b74591d5ab33 572 /** Testing thread states: wait message get
be_bryan 0:b74591d5ab33 573
be_bryan 0:b74591d5ab33 574 Given the thread is running
be_bryan 0:b74591d5ab33 575 when thread tries to get a message from an empty queue
be_bryan 0:b74591d5ab33 576 then its state, as reported by @a get_state, is @a WaitingMessageGet
be_bryan 0:b74591d5ab33 577 */
be_bryan 0:b74591d5ab33 578 void test_msg_get()
be_bryan 0:b74591d5ab33 579 {
be_bryan 0:b74591d5ab33 580 Thread t(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 581 Queue<int32_t, 1> queue;
be_bryan 0:b74591d5ab33 582
be_bryan 0:b74591d5ab33 583 t.start(callback(test_msg_get_thread, &queue));
be_bryan 0:b74591d5ab33 584
be_bryan 0:b74591d5ab33 585 Thread::yield();
be_bryan 0:b74591d5ab33 586
be_bryan 0:b74591d5ab33 587 TEST_ASSERT_EQUAL(Thread::WaitingMessageGet, t.get_state());
be_bryan 0:b74591d5ab33 588
be_bryan 0:b74591d5ab33 589 queue.put((int32_t *)0xE1EE7);
be_bryan 0:b74591d5ab33 590 }
be_bryan 0:b74591d5ab33 591
be_bryan 0:b74591d5ab33 592 void test_msg_put_thread(Queue<int32_t, 1> *queue)
be_bryan 0:b74591d5ab33 593 {
be_bryan 0:b74591d5ab33 594 queue->put((int32_t *)0xDEADBEEF, osWaitForever);
be_bryan 0:b74591d5ab33 595
be_bryan 0:b74591d5ab33 596 }
be_bryan 0:b74591d5ab33 597
be_bryan 0:b74591d5ab33 598 /** Testing thread states: wait message put
be_bryan 0:b74591d5ab33 599
be_bryan 0:b74591d5ab33 600 Given the thread is running
be_bryan 0:b74591d5ab33 601 when thread tries to put a message into a full queue
be_bryan 0:b74591d5ab33 602 then its state, as reported by @a get_state, is @a WaitingMessagePut
be_bryan 0:b74591d5ab33 603 */
be_bryan 0:b74591d5ab33 604 void test_msg_put()
be_bryan 0:b74591d5ab33 605 {
be_bryan 0:b74591d5ab33 606 Thread t(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 607 Queue<int32_t, 1> queue;
be_bryan 0:b74591d5ab33 608
be_bryan 0:b74591d5ab33 609 queue.put((int32_t *)0xE1EE7);
be_bryan 0:b74591d5ab33 610
be_bryan 0:b74591d5ab33 611 t.start(callback(test_msg_put_thread, &queue));
be_bryan 0:b74591d5ab33 612
be_bryan 0:b74591d5ab33 613 Thread::yield();
be_bryan 0:b74591d5ab33 614
be_bryan 0:b74591d5ab33 615 TEST_ASSERT_EQUAL(Thread::WaitingMessagePut, t.get_state());
be_bryan 0:b74591d5ab33 616 queue.get();
be_bryan 0:b74591d5ab33 617 }
be_bryan 0:b74591d5ab33 618
be_bryan 0:b74591d5ab33 619 /** Utility function that places some date on the stack */
be_bryan 0:b74591d5ab33 620 void use_some_stack () {
be_bryan 0:b74591d5ab33 621 volatile uint32_t stack_filler[10] = {0xDEADBEEF};
be_bryan 0:b74591d5ab33 622 }
be_bryan 0:b74591d5ab33 623
be_bryan 0:b74591d5ab33 624 /** Testing thread with external stack memory
be_bryan 0:b74591d5ab33 625
be_bryan 0:b74591d5ab33 626 Given external buffer is supplied as stack to a thread
be_bryan 0:b74591d5ab33 627 when the thread executes
be_bryan 0:b74591d5ab33 628 then the supplies buffer is used as a stack
be_bryan 0:b74591d5ab33 629 */
be_bryan 0:b74591d5ab33 630 void test_thread_ext_stack() {
be_bryan 0:b74591d5ab33 631 char stack[512];
be_bryan 0:b74591d5ab33 632 Thread t(osPriorityNormal, sizeof(stack), (unsigned char*)stack);
be_bryan 0:b74591d5ab33 633
be_bryan 0:b74591d5ab33 634 memset(&stack, 0, sizeof(stack));
be_bryan 0:b74591d5ab33 635 t.start(callback(use_some_stack));
be_bryan 0:b74591d5ab33 636 t.join();
be_bryan 0:b74591d5ab33 637
be_bryan 0:b74591d5ab33 638 /* If buffer was used as a stack it was cleared with pattern and some data were placed in it */
be_bryan 0:b74591d5ab33 639 for(unsigned i = 0; i < sizeof(stack); i++) {
be_bryan 0:b74591d5ab33 640 if (stack[i] != 0)
be_bryan 0:b74591d5ab33 641 return;
be_bryan 0:b74591d5ab33 642 }
be_bryan 0:b74591d5ab33 643
be_bryan 0:b74591d5ab33 644 TEST_FAIL_MESSAGE("External stack was not used.");
be_bryan 0:b74591d5ab33 645 }
be_bryan 0:b74591d5ab33 646
be_bryan 0:b74591d5ab33 647 /** Testing thread priority operations
be_bryan 0:b74591d5ab33 648
be_bryan 0:b74591d5ab33 649 Given thread running with osPriorityNormal
be_bryan 0:b74591d5ab33 650 when new priority is set using @a set_priority
be_bryan 0:b74591d5ab33 651 then priority is changed and can be retrieved using @a get_priority
be_bryan 0:b74591d5ab33 652 */
be_bryan 0:b74591d5ab33 653 void test_thread_prio() {
be_bryan 0:b74591d5ab33 654 Thread t(osPriorityNormal, THREAD_STACK_SIZE);
be_bryan 0:b74591d5ab33 655 t.start(callback(thread_wait_signal));
be_bryan 0:b74591d5ab33 656
be_bryan 0:b74591d5ab33 657 TEST_ASSERT_EQUAL(osPriorityNormal, t.get_priority());
be_bryan 0:b74591d5ab33 658
be_bryan 0:b74591d5ab33 659 t.set_priority(osPriorityHigh);
be_bryan 0:b74591d5ab33 660
be_bryan 0:b74591d5ab33 661 TEST_ASSERT_EQUAL(osPriorityHigh, t.get_priority());
be_bryan 0:b74591d5ab33 662
be_bryan 0:b74591d5ab33 663 t.signal_set(0x1);
be_bryan 0:b74591d5ab33 664 t.join();
be_bryan 0:b74591d5ab33 665 }
be_bryan 0:b74591d5ab33 666
be_bryan 0:b74591d5ab33 667 utest::v1::status_t test_setup(const size_t number_of_cases) {
be_bryan 0:b74591d5ab33 668 GREENTEA_SETUP(20, "default_auto");
be_bryan 0:b74591d5ab33 669 return verbose_test_setup_handler(number_of_cases);
be_bryan 0:b74591d5ab33 670 }
be_bryan 0:b74591d5ab33 671
be_bryan 0:b74591d5ab33 672 #define DEFAULT_HANDLERS NULL,NULL,greentea_case_setup_handler,greentea_case_teardown_handler,greentea_case_failure_abort_handler
be_bryan 0:b74591d5ab33 673
be_bryan 0:b74591d5ab33 674 // Test cases. It's spelled out rather than constructed with macro because
be_bryan 0:b74591d5ab33 675 // macros don't play nicely with the templates (extra comma).
be_bryan 0:b74591d5ab33 676 static const case_t cases[] = {
be_bryan 0:b74591d5ab33 677 {"Testing single thread", test_single_thread<increment>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 678 {"Testing parallel threads", test_parallel_threads<3, increment> , DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 679 {"Testing serial threads", test_serial_threads<10, increment> , DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 680
be_bryan 0:b74591d5ab33 681 {"Testing single thread with yield", test_single_thread<increment_with_yield>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 682 {"Testing parallel threads with yield", test_parallel_threads<3, increment_with_yield>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 683 {"Testing serial threads with yield", test_serial_threads<10, increment_with_yield>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 684
be_bryan 0:b74591d5ab33 685 {"Testing single thread with wait", test_single_thread<increment_with_wait>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 686 {"Testing parallel threads with wait", test_parallel_threads<3, increment_with_wait>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 687 {"Testing serial threads with wait", test_serial_threads<10, increment_with_wait>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 688
be_bryan 0:b74591d5ab33 689 {"Testing single thread with child", test_single_thread<increment_with_child>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 690 {"Testing parallel threads with child", test_parallel_threads<2, increment_with_child>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 691 {"Testing serial threads with child", test_serial_threads<10, increment_with_child>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 692
be_bryan 0:b74591d5ab33 693 {"Testing single thread with murder", test_single_thread<increment_with_murder>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 694 {"Testing parallel threads with murder", test_parallel_threads<2, increment_with_murder>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 695 {"Testing serial threads with murder", test_serial_threads<10, increment_with_murder>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 696
be_bryan 0:b74591d5ab33 697 {"Testing thread self terminate", test_self_terminate, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 698
be_bryan 0:b74591d5ab33 699 {"Testing thread signals: wait", test_thread_signal<0x1, signal_wait>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 700 {"Testing thread signals: timeout", test_thread_signal<0x1, signal_wait_tout>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 701 {"Testing thread signals: multi-bit", test_thread_signal<0x3, signal_wait_multibit>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 702 {"Testing thread signals: multi-bit timeout", test_thread_signal<0x1, signal_wait_multibit_tout>, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 703 {"Testing thread signals: signal clear", test_thread_signal_clr, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 704
be_bryan 0:b74591d5ab33 705
be_bryan 0:b74591d5ab33 706 {"Testing thread stack info", test_thread_stack_info, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 707 {"Testing thread wait", test_thread_wait, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 708 {"Testing thread name", test_thread_name, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 709
be_bryan 0:b74591d5ab33 710 {"Testing thread states: deleted", test_deleted, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 711 {"Testing thread states: wait delay", test_delay, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 712 {"Testing thread states: wait signal", test_signal, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 713 {"Testing thread states: wait event flag", test_evt_flag, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 714 {"Testing thread states: wait mutex", test_mutex, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 715 {"Testing thread states: wait semaphore", test_semaphore, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 716 {"Testing thread states: wait message get", test_msg_get, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 717 {"Testing thread states: wait message put", test_msg_put, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 718
be_bryan 0:b74591d5ab33 719 {"Testing thread with external stack memory", test_thread_ext_stack, DEFAULT_HANDLERS},
be_bryan 0:b74591d5ab33 720 {"Testing thread priority ops", test_thread_prio, DEFAULT_HANDLERS}
be_bryan 0:b74591d5ab33 721
be_bryan 0:b74591d5ab33 722 };
be_bryan 0:b74591d5ab33 723
be_bryan 0:b74591d5ab33 724 Specification specification(test_setup, cases);
be_bryan 0:b74591d5ab33 725
be_bryan 0:b74591d5ab33 726 int main() {
be_bryan 0:b74591d5ab33 727 return !Harness::run(specification);
be_bryan 0:b74591d5ab33 728 }