Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Thu Oct 11 02:27:46 2018 +0000
Revision:
3:f3764f852aa8
Parent:
0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;

Who changed what in which revision?

UserRevisionLine numberNew 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_events.h"
kadonotakashi 0:8fdf9a60065b 17 #include "mbed.h"
kadonotakashi 0:8fdf9a60065b 18 #include "rtos.h"
kadonotakashi 0:8fdf9a60065b 19 #include "greentea-client/test_env.h"
kadonotakashi 0:8fdf9a60065b 20 #include "unity.h"
kadonotakashi 0:8fdf9a60065b 21 #include "utest.h"
kadonotakashi 0:8fdf9a60065b 22
kadonotakashi 0:8fdf9a60065b 23 #if !DEVICE_USTICKER
kadonotakashi 0:8fdf9a60065b 24 #error [NOT_SUPPORTED] test not supported
kadonotakashi 0:8fdf9a60065b 25 #endif
kadonotakashi 0:8fdf9a60065b 26
kadonotakashi 0:8fdf9a60065b 27 using namespace utest::v1;
kadonotakashi 0:8fdf9a60065b 28
kadonotakashi 0:8fdf9a60065b 29 // Assume that tolerance is 5% of measured time.
kadonotakashi 0:8fdf9a60065b 30 #define DELTA(ms) (ms / 20)
kadonotakashi 0:8fdf9a60065b 31
kadonotakashi 0:8fdf9a60065b 32 // TEST_EQUEUE_SIZE was reduced below 1024B to fit this test to devices with small RAM (RAM <= 16kB)
kadonotakashi 0:8fdf9a60065b 33 // additionally TEST_EQUEUE_SIZE was expressed in EVENTS_EVENT_SIZE to increase readability
kadonotakashi 0:8fdf9a60065b 34 // (for more details about EVENTS_EVENT_SIZE see EventQueue constructor)
kadonotakashi 0:8fdf9a60065b 35 #define TEST_EQUEUE_SIZE (18*EVENTS_EVENT_SIZE)
kadonotakashi 0:8fdf9a60065b 36
kadonotakashi 0:8fdf9a60065b 37 // flag for called
kadonotakashi 0:8fdf9a60065b 38 volatile bool touched = false;
kadonotakashi 0:8fdf9a60065b 39
kadonotakashi 0:8fdf9a60065b 40 // static functions
kadonotakashi 0:8fdf9a60065b 41 void func5(int a0, int a1, int a2, int a3, int a4)
kadonotakashi 0:8fdf9a60065b 42 {
kadonotakashi 0:8fdf9a60065b 43 touched = true;
kadonotakashi 0:8fdf9a60065b 44 TEST_ASSERT_EQUAL(a0 | a1 | a2 | a3 | a4, 0x1f);
kadonotakashi 0:8fdf9a60065b 45 }
kadonotakashi 0:8fdf9a60065b 46
kadonotakashi 0:8fdf9a60065b 47 void func4(int a0, int a1, int a2, int a3)
kadonotakashi 0:8fdf9a60065b 48 {
kadonotakashi 0:8fdf9a60065b 49 touched = true;
kadonotakashi 0:8fdf9a60065b 50 TEST_ASSERT_EQUAL(a0 | a1 | a2 | a3, 0xf);
kadonotakashi 0:8fdf9a60065b 51 }
kadonotakashi 0:8fdf9a60065b 52
kadonotakashi 0:8fdf9a60065b 53 void func3(int a0, int a1, int a2)
kadonotakashi 0:8fdf9a60065b 54 {
kadonotakashi 0:8fdf9a60065b 55 touched = true;
kadonotakashi 0:8fdf9a60065b 56 TEST_ASSERT_EQUAL(a0 | a1 | a2, 0x7);
kadonotakashi 0:8fdf9a60065b 57 }
kadonotakashi 0:8fdf9a60065b 58
kadonotakashi 0:8fdf9a60065b 59 void func2(int a0, int a1)
kadonotakashi 0:8fdf9a60065b 60 {
kadonotakashi 0:8fdf9a60065b 61 touched = true;
kadonotakashi 0:8fdf9a60065b 62 TEST_ASSERT_EQUAL(a0 | a1, 0x3);
kadonotakashi 0:8fdf9a60065b 63 }
kadonotakashi 0:8fdf9a60065b 64
kadonotakashi 0:8fdf9a60065b 65 void func1(int a0)
kadonotakashi 0:8fdf9a60065b 66 {
kadonotakashi 0:8fdf9a60065b 67 touched = true;
kadonotakashi 0:8fdf9a60065b 68 TEST_ASSERT_EQUAL(a0, 0x1);
kadonotakashi 0:8fdf9a60065b 69 }
kadonotakashi 0:8fdf9a60065b 70
kadonotakashi 0:8fdf9a60065b 71 void func0()
kadonotakashi 0:8fdf9a60065b 72 {
kadonotakashi 0:8fdf9a60065b 73 touched = true;
kadonotakashi 0:8fdf9a60065b 74 }
kadonotakashi 0:8fdf9a60065b 75
kadonotakashi 0:8fdf9a60065b 76 #define SIMPLE_POSTS_TEST(i, ...) \
kadonotakashi 0:8fdf9a60065b 77 void simple_posts_test##i() { \
kadonotakashi 0:8fdf9a60065b 78 EventQueue queue(TEST_EQUEUE_SIZE); \
kadonotakashi 0:8fdf9a60065b 79 \
kadonotakashi 0:8fdf9a60065b 80 touched = false; \
kadonotakashi 0:8fdf9a60065b 81 queue.call(func##i,##__VA_ARGS__); \
kadonotakashi 0:8fdf9a60065b 82 queue.dispatch(0); \
kadonotakashi 0:8fdf9a60065b 83 TEST_ASSERT(touched); \
kadonotakashi 0:8fdf9a60065b 84 \
kadonotakashi 0:8fdf9a60065b 85 touched = false; \
kadonotakashi 0:8fdf9a60065b 86 queue.call_in(1, func##i,##__VA_ARGS__); \
kadonotakashi 0:8fdf9a60065b 87 queue.dispatch(2); \
kadonotakashi 0:8fdf9a60065b 88 TEST_ASSERT(touched); \
kadonotakashi 0:8fdf9a60065b 89 \
kadonotakashi 0:8fdf9a60065b 90 touched = false; \
kadonotakashi 0:8fdf9a60065b 91 queue.call_every(1, func##i,##__VA_ARGS__); \
kadonotakashi 0:8fdf9a60065b 92 queue.dispatch(2); \
kadonotakashi 0:8fdf9a60065b 93 TEST_ASSERT(touched); \
kadonotakashi 0:8fdf9a60065b 94 }
kadonotakashi 0:8fdf9a60065b 95
kadonotakashi 0:8fdf9a60065b 96 SIMPLE_POSTS_TEST(5, 0x01, 0x02, 0x04, 0x08, 0x010)
kadonotakashi 0:8fdf9a60065b 97 SIMPLE_POSTS_TEST(4, 0x01, 0x02, 0x04, 0x08)
kadonotakashi 0:8fdf9a60065b 98 SIMPLE_POSTS_TEST(3, 0x01, 0x02, 0x04)
kadonotakashi 0:8fdf9a60065b 99 SIMPLE_POSTS_TEST(2, 0x01, 0x02)
kadonotakashi 0:8fdf9a60065b 100 SIMPLE_POSTS_TEST(1, 0x01)
kadonotakashi 0:8fdf9a60065b 101 SIMPLE_POSTS_TEST(0)
kadonotakashi 0:8fdf9a60065b 102
kadonotakashi 0:8fdf9a60065b 103
kadonotakashi 0:8fdf9a60065b 104 void time_func(Timer *t, int ms)
kadonotakashi 0:8fdf9a60065b 105 {
kadonotakashi 0:8fdf9a60065b 106 TEST_ASSERT_INT_WITHIN(DELTA(ms), ms, t->read_ms());
kadonotakashi 0:8fdf9a60065b 107 t->reset();
kadonotakashi 0:8fdf9a60065b 108 }
kadonotakashi 0:8fdf9a60065b 109
kadonotakashi 0:8fdf9a60065b 110 template <int N>
kadonotakashi 0:8fdf9a60065b 111 void call_in_test()
kadonotakashi 0:8fdf9a60065b 112 {
kadonotakashi 0:8fdf9a60065b 113 Timer tickers[N];
kadonotakashi 0:8fdf9a60065b 114
kadonotakashi 0:8fdf9a60065b 115 EventQueue queue(TEST_EQUEUE_SIZE);
kadonotakashi 0:8fdf9a60065b 116
kadonotakashi 0:8fdf9a60065b 117 for (int i = 0; i < N; i++) {
kadonotakashi 0:8fdf9a60065b 118 tickers[i].start();
kadonotakashi 0:8fdf9a60065b 119 queue.call_in((i + 1) * 100, time_func, &tickers[i], (i + 1) * 100);
kadonotakashi 0:8fdf9a60065b 120 }
kadonotakashi 0:8fdf9a60065b 121
kadonotakashi 0:8fdf9a60065b 122 queue.dispatch(N * 100);
kadonotakashi 0:8fdf9a60065b 123 }
kadonotakashi 0:8fdf9a60065b 124
kadonotakashi 0:8fdf9a60065b 125 template <int N>
kadonotakashi 0:8fdf9a60065b 126 void call_every_test()
kadonotakashi 0:8fdf9a60065b 127 {
kadonotakashi 0:8fdf9a60065b 128 Timer tickers[N];
kadonotakashi 0:8fdf9a60065b 129
kadonotakashi 0:8fdf9a60065b 130 EventQueue queue(TEST_EQUEUE_SIZE);
kadonotakashi 0:8fdf9a60065b 131
kadonotakashi 0:8fdf9a60065b 132 for (int i = 0; i < N; i++) {
kadonotakashi 0:8fdf9a60065b 133 tickers[i].start();
kadonotakashi 0:8fdf9a60065b 134 queue.call_every((i + 1) * 100, time_func, &tickers[i], (i + 1) * 100);
kadonotakashi 0:8fdf9a60065b 135 }
kadonotakashi 0:8fdf9a60065b 136
kadonotakashi 0:8fdf9a60065b 137 queue.dispatch(N * 100);
kadonotakashi 0:8fdf9a60065b 138 }
kadonotakashi 0:8fdf9a60065b 139
kadonotakashi 0:8fdf9a60065b 140 void allocate_failure_test()
kadonotakashi 0:8fdf9a60065b 141 {
kadonotakashi 0:8fdf9a60065b 142 EventQueue queue(TEST_EQUEUE_SIZE);
kadonotakashi 0:8fdf9a60065b 143 int id;
kadonotakashi 0:8fdf9a60065b 144
kadonotakashi 0:8fdf9a60065b 145 for (int i = 0; i < 100; i++) {
kadonotakashi 0:8fdf9a60065b 146 id = queue.call((void (*)())0);
kadonotakashi 0:8fdf9a60065b 147 }
kadonotakashi 0:8fdf9a60065b 148
kadonotakashi 0:8fdf9a60065b 149 TEST_ASSERT(!id);
kadonotakashi 0:8fdf9a60065b 150 }
kadonotakashi 0:8fdf9a60065b 151
kadonotakashi 0:8fdf9a60065b 152 void no()
kadonotakashi 0:8fdf9a60065b 153 {
kadonotakashi 0:8fdf9a60065b 154 TEST_ASSERT(false);
kadonotakashi 0:8fdf9a60065b 155 }
kadonotakashi 0:8fdf9a60065b 156
kadonotakashi 0:8fdf9a60065b 157 template <int N>
kadonotakashi 0:8fdf9a60065b 158 void cancel_test1()
kadonotakashi 0:8fdf9a60065b 159 {
kadonotakashi 0:8fdf9a60065b 160 EventQueue queue(TEST_EQUEUE_SIZE);
kadonotakashi 0:8fdf9a60065b 161
kadonotakashi 0:8fdf9a60065b 162 int ids[N];
kadonotakashi 0:8fdf9a60065b 163
kadonotakashi 0:8fdf9a60065b 164 for (int i = 0; i < N; i++) {
kadonotakashi 0:8fdf9a60065b 165 ids[i] = queue.call_in(1000, no);
kadonotakashi 0:8fdf9a60065b 166 }
kadonotakashi 0:8fdf9a60065b 167
kadonotakashi 0:8fdf9a60065b 168 for (int i = N - 1; i >= 0; i--) {
kadonotakashi 0:8fdf9a60065b 169 queue.cancel(ids[i]);
kadonotakashi 0:8fdf9a60065b 170 }
kadonotakashi 0:8fdf9a60065b 171
kadonotakashi 0:8fdf9a60065b 172 queue.dispatch(0);
kadonotakashi 0:8fdf9a60065b 173 }
kadonotakashi 0:8fdf9a60065b 174
kadonotakashi 0:8fdf9a60065b 175
kadonotakashi 0:8fdf9a60065b 176 // Testing the dynamic arguments to the event class
kadonotakashi 0:8fdf9a60065b 177 unsigned counter = 0;
kadonotakashi 0:8fdf9a60065b 178
kadonotakashi 0:8fdf9a60065b 179 void count5(unsigned a0, unsigned a1, unsigned a2, unsigned a3, unsigned a5)
kadonotakashi 0:8fdf9a60065b 180 {
kadonotakashi 0:8fdf9a60065b 181 counter += a0 + a1 + a2 + a3 + a5;
kadonotakashi 0:8fdf9a60065b 182 }
kadonotakashi 0:8fdf9a60065b 183
kadonotakashi 0:8fdf9a60065b 184 void count4(unsigned a0, unsigned a1, unsigned a2, unsigned a3)
kadonotakashi 0:8fdf9a60065b 185 {
kadonotakashi 0:8fdf9a60065b 186 counter += a0 + a1 + a2 + a3;
kadonotakashi 0:8fdf9a60065b 187 }
kadonotakashi 0:8fdf9a60065b 188
kadonotakashi 0:8fdf9a60065b 189 void count3(unsigned a0, unsigned a1, unsigned a2)
kadonotakashi 0:8fdf9a60065b 190 {
kadonotakashi 0:8fdf9a60065b 191 counter += a0 + a1 + a2;
kadonotakashi 0:8fdf9a60065b 192 }
kadonotakashi 0:8fdf9a60065b 193
kadonotakashi 0:8fdf9a60065b 194 void count2(unsigned a0, unsigned a1)
kadonotakashi 0:8fdf9a60065b 195 {
kadonotakashi 0:8fdf9a60065b 196 counter += a0 + a1;
kadonotakashi 0:8fdf9a60065b 197 }
kadonotakashi 0:8fdf9a60065b 198
kadonotakashi 0:8fdf9a60065b 199 void count1(unsigned a0)
kadonotakashi 0:8fdf9a60065b 200 {
kadonotakashi 0:8fdf9a60065b 201 counter += a0;
kadonotakashi 0:8fdf9a60065b 202 }
kadonotakashi 0:8fdf9a60065b 203
kadonotakashi 0:8fdf9a60065b 204 void count0()
kadonotakashi 0:8fdf9a60065b 205 {
kadonotakashi 0:8fdf9a60065b 206 counter += 0;
kadonotakashi 0:8fdf9a60065b 207 }
kadonotakashi 0:8fdf9a60065b 208
kadonotakashi 0:8fdf9a60065b 209 void event_class_test()
kadonotakashi 0:8fdf9a60065b 210 {
kadonotakashi 0:8fdf9a60065b 211 counter = 0;
kadonotakashi 0:8fdf9a60065b 212 EventQueue queue(TEST_EQUEUE_SIZE);
kadonotakashi 0:8fdf9a60065b 213
kadonotakashi 0:8fdf9a60065b 214 Event<void(int, int, int, int, int)> e5(&queue, count5);
kadonotakashi 0:8fdf9a60065b 215 Event<void(int, int, int, int)> e4(&queue, count5, 1);
kadonotakashi 0:8fdf9a60065b 216 Event<void(int, int, int)> e3(&queue, count5, 1, 1);
kadonotakashi 0:8fdf9a60065b 217 Event<void(int, int)> e2(&queue, count5, 1, 1, 1);
kadonotakashi 0:8fdf9a60065b 218 Event<void(int)> e1(&queue, count5, 1, 1, 1, 1);
kadonotakashi 0:8fdf9a60065b 219 Event<void()> e0(&queue, count5, 1, 1, 1, 1, 1);
kadonotakashi 0:8fdf9a60065b 220
kadonotakashi 0:8fdf9a60065b 221 e5.post(1, 1, 1, 1, 1);
kadonotakashi 0:8fdf9a60065b 222 e4.post(1, 1, 1, 1);
kadonotakashi 0:8fdf9a60065b 223 e3.post(1, 1, 1);
kadonotakashi 0:8fdf9a60065b 224 e2.post(1, 1);
kadonotakashi 0:8fdf9a60065b 225 e1.post(1);
kadonotakashi 0:8fdf9a60065b 226 e0.post();
kadonotakashi 0:8fdf9a60065b 227
kadonotakashi 0:8fdf9a60065b 228 queue.dispatch(0);
kadonotakashi 0:8fdf9a60065b 229
kadonotakashi 0:8fdf9a60065b 230 TEST_ASSERT_EQUAL(counter, 30);
kadonotakashi 0:8fdf9a60065b 231 }
kadonotakashi 0:8fdf9a60065b 232
kadonotakashi 0:8fdf9a60065b 233 void event_class_helper_test()
kadonotakashi 0:8fdf9a60065b 234 {
kadonotakashi 0:8fdf9a60065b 235 counter = 0;
kadonotakashi 0:8fdf9a60065b 236 EventQueue queue(TEST_EQUEUE_SIZE);
kadonotakashi 0:8fdf9a60065b 237
kadonotakashi 0:8fdf9a60065b 238 Event<void()> e5 = queue.event(count5, 1, 1, 1, 1, 1);
kadonotakashi 0:8fdf9a60065b 239 Event<void()> e4 = queue.event(count4, 1, 1, 1, 1);
kadonotakashi 0:8fdf9a60065b 240 Event<void()> e3 = queue.event(count3, 1, 1, 1);
kadonotakashi 0:8fdf9a60065b 241 Event<void()> e2 = queue.event(count2, 1, 1);
kadonotakashi 0:8fdf9a60065b 242 Event<void()> e1 = queue.event(count1, 1);
kadonotakashi 0:8fdf9a60065b 243 Event<void()> e0 = queue.event(count0);
kadonotakashi 0:8fdf9a60065b 244
kadonotakashi 0:8fdf9a60065b 245 e5.post();
kadonotakashi 0:8fdf9a60065b 246 e4.post();
kadonotakashi 0:8fdf9a60065b 247 e3.post();
kadonotakashi 0:8fdf9a60065b 248 e2.post();
kadonotakashi 0:8fdf9a60065b 249 e1.post();
kadonotakashi 0:8fdf9a60065b 250 e0.post();
kadonotakashi 0:8fdf9a60065b 251
kadonotakashi 0:8fdf9a60065b 252 queue.dispatch(0);
kadonotakashi 0:8fdf9a60065b 253
kadonotakashi 0:8fdf9a60065b 254 TEST_ASSERT_EQUAL(counter, 15);
kadonotakashi 0:8fdf9a60065b 255 }
kadonotakashi 0:8fdf9a60065b 256
kadonotakashi 0:8fdf9a60065b 257 void event_inference_test()
kadonotakashi 0:8fdf9a60065b 258 {
kadonotakashi 0:8fdf9a60065b 259 counter = 0;
kadonotakashi 0:8fdf9a60065b 260 EventQueue queue(TEST_EQUEUE_SIZE);
kadonotakashi 0:8fdf9a60065b 261
kadonotakashi 0:8fdf9a60065b 262 queue.event(count5, 1, 1, 1, 1, 1).post();
kadonotakashi 0:8fdf9a60065b 263 queue.event(count5, 1, 1, 1, 1).post(1);
kadonotakashi 0:8fdf9a60065b 264 queue.event(count5, 1, 1, 1).post(1, 1);
kadonotakashi 0:8fdf9a60065b 265 queue.event(count5, 1, 1).post(1, 1, 1);
kadonotakashi 0:8fdf9a60065b 266 queue.event(count5, 1).post(1, 1, 1, 1);
kadonotakashi 0:8fdf9a60065b 267 queue.event(count5).post(1, 1, 1, 1, 1);
kadonotakashi 0:8fdf9a60065b 268
kadonotakashi 0:8fdf9a60065b 269 queue.event(callback(count5), 1, 1, 1, 1, 1).post();
kadonotakashi 0:8fdf9a60065b 270 queue.event(callback(count5), 1, 1, 1, 1).post(1);
kadonotakashi 0:8fdf9a60065b 271 queue.event(callback(count5), 1, 1, 1).post(1, 1);
kadonotakashi 0:8fdf9a60065b 272 queue.event(callback(count5), 1, 1).post(1, 1, 1);
kadonotakashi 0:8fdf9a60065b 273 queue.event(callback(count5), 1).post(1, 1, 1, 1);
kadonotakashi 0:8fdf9a60065b 274 queue.event(callback(count5)).post(1, 1, 1, 1, 1);
kadonotakashi 0:8fdf9a60065b 275
kadonotakashi 0:8fdf9a60065b 276 queue.dispatch(0);
kadonotakashi 0:8fdf9a60065b 277
kadonotakashi 0:8fdf9a60065b 278 TEST_ASSERT_EQUAL(counter, 60);
kadonotakashi 0:8fdf9a60065b 279 }
kadonotakashi 0:8fdf9a60065b 280
kadonotakashi 0:8fdf9a60065b 281 int timeleft_events[2];
kadonotakashi 0:8fdf9a60065b 282
kadonotakashi 0:8fdf9a60065b 283 void check_time_left(EventQueue *queue, int index, int expected)
kadonotakashi 0:8fdf9a60065b 284 {
kadonotakashi 0:8fdf9a60065b 285 const int event_id = timeleft_events[index];
kadonotakashi 0:8fdf9a60065b 286 TEST_ASSERT_INT_WITHIN(2, expected, queue->time_left(event_id));
kadonotakashi 0:8fdf9a60065b 287 touched = true;
kadonotakashi 0:8fdf9a60065b 288 }
kadonotakashi 0:8fdf9a60065b 289
kadonotakashi 0:8fdf9a60065b 290 void time_left(EventQueue *queue, int index)
kadonotakashi 0:8fdf9a60065b 291 {
kadonotakashi 0:8fdf9a60065b 292 const int event_id = timeleft_events[index];
kadonotakashi 0:8fdf9a60065b 293 TEST_ASSERT_EQUAL(0, queue->time_left(event_id));
kadonotakashi 0:8fdf9a60065b 294 }
kadonotakashi 0:8fdf9a60065b 295
kadonotakashi 0:8fdf9a60065b 296 void time_left_test()
kadonotakashi 0:8fdf9a60065b 297 {
kadonotakashi 0:8fdf9a60065b 298 EventQueue queue(TEST_EQUEUE_SIZE);
kadonotakashi 0:8fdf9a60065b 299
kadonotakashi 0:8fdf9a60065b 300 // Enque check events
kadonotakashi 0:8fdf9a60065b 301 TEST_ASSERT(queue.call_in(50, check_time_left, &queue, 0, 100 - 50));
kadonotakashi 0:8fdf9a60065b 302 TEST_ASSERT(queue.call_in(200, check_time_left, &queue, 1, 200 - 200));
kadonotakashi 0:8fdf9a60065b 303
kadonotakashi 0:8fdf9a60065b 304 // Enque events to be checked
kadonotakashi 0:8fdf9a60065b 305 timeleft_events[0] = queue.call_in(100, time_left, &queue, 0);
kadonotakashi 0:8fdf9a60065b 306 timeleft_events[1] = queue.call_in(200, time_left, &queue, 1);
kadonotakashi 0:8fdf9a60065b 307 TEST_ASSERT(timeleft_events[0]);
kadonotakashi 0:8fdf9a60065b 308 TEST_ASSERT(timeleft_events[1]);
kadonotakashi 0:8fdf9a60065b 309
kadonotakashi 0:8fdf9a60065b 310 queue.dispatch(300);
kadonotakashi 0:8fdf9a60065b 311
kadonotakashi 0:8fdf9a60065b 312 // Ensure check was called
kadonotakashi 0:8fdf9a60065b 313 TEST_ASSERT(touched);
kadonotakashi 0:8fdf9a60065b 314 touched = false;
kadonotakashi 0:8fdf9a60065b 315
kadonotakashi 0:8fdf9a60065b 316 int id = queue.call(func0);
kadonotakashi 0:8fdf9a60065b 317 TEST_ASSERT(id);
kadonotakashi 0:8fdf9a60065b 318 TEST_ASSERT_EQUAL(0, queue.time_left(id));
kadonotakashi 0:8fdf9a60065b 319 queue.dispatch(10);
kadonotakashi 0:8fdf9a60065b 320
kadonotakashi 0:8fdf9a60065b 321 // Test invalid event id
kadonotakashi 0:8fdf9a60065b 322 TEST_ASSERT_EQUAL(-1, queue.time_left(0));
kadonotakashi 0:8fdf9a60065b 323 }
kadonotakashi 0:8fdf9a60065b 324
kadonotakashi 0:8fdf9a60065b 325 // Test setup
kadonotakashi 0:8fdf9a60065b 326 utest::v1::status_t test_setup(const size_t number_of_cases)
kadonotakashi 0:8fdf9a60065b 327 {
kadonotakashi 0:8fdf9a60065b 328 GREENTEA_SETUP(20, "default_auto");
kadonotakashi 0:8fdf9a60065b 329 return verbose_test_setup_handler(number_of_cases);
kadonotakashi 0:8fdf9a60065b 330 }
kadonotakashi 0:8fdf9a60065b 331
kadonotakashi 0:8fdf9a60065b 332 const Case cases[] = {
kadonotakashi 0:8fdf9a60065b 333 Case("Testing calls with 5 args", simple_posts_test5),
kadonotakashi 0:8fdf9a60065b 334 Case("Testing calls with 4 args", simple_posts_test4),
kadonotakashi 0:8fdf9a60065b 335 Case("Testing calls with 3 args", simple_posts_test3),
kadonotakashi 0:8fdf9a60065b 336 Case("Testing calls with 2 args", simple_posts_test2),
kadonotakashi 0:8fdf9a60065b 337 Case("Testing calls with 1 args", simple_posts_test1),
kadonotakashi 0:8fdf9a60065b 338 Case("Testing calls with 0 args", simple_posts_test0),
kadonotakashi 0:8fdf9a60065b 339
kadonotakashi 0:8fdf9a60065b 340 Case("Testing call_in", call_in_test<20>),
kadonotakashi 0:8fdf9a60065b 341 Case("Testing call_every", call_every_test<20>),
kadonotakashi 0:8fdf9a60065b 342
kadonotakashi 0:8fdf9a60065b 343 Case("Testing allocate failure", allocate_failure_test),
kadonotakashi 0:8fdf9a60065b 344
kadonotakashi 0:8fdf9a60065b 345 Case("Testing event cancel 1", cancel_test1<20>),
kadonotakashi 0:8fdf9a60065b 346 Case("Testing the event class", event_class_test),
kadonotakashi 0:8fdf9a60065b 347 Case("Testing the event class helpers", event_class_helper_test),
kadonotakashi 0:8fdf9a60065b 348 Case("Testing the event inference", event_inference_test),
kadonotakashi 0:8fdf9a60065b 349
kadonotakashi 0:8fdf9a60065b 350 Case("Testing time_left", time_left_test),
kadonotakashi 0:8fdf9a60065b 351 };
kadonotakashi 0:8fdf9a60065b 352
kadonotakashi 0:8fdf9a60065b 353 Specification specification(test_setup, cases);
kadonotakashi 0:8fdf9a60065b 354
kadonotakashi 0:8fdf9a60065b 355 int main()
kadonotakashi 0:8fdf9a60065b 356 {
kadonotakashi 0:8fdf9a60065b 357 return !Harness::run(specification);
kadonotakashi 0:8fdf9a60065b 358 }
kadonotakashi 0:8fdf9a60065b 359