![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/TESTS/mbed_hal/ticker/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 | |
kadonotakashi | 0:8fdf9a60065b | 17 | #define __STDC_LIMIT_MACROS |
kadonotakashi | 0:8fdf9a60065b | 18 | #include <stdint.h> |
kadonotakashi | 0:8fdf9a60065b | 19 | #include <algorithm> |
kadonotakashi | 0:8fdf9a60065b | 20 | |
kadonotakashi | 0:8fdf9a60065b | 21 | #include "utest/utest.h" |
kadonotakashi | 0:8fdf9a60065b | 22 | #include "unity/unity.h" |
kadonotakashi | 0:8fdf9a60065b | 23 | #include "greentea-client/test_env.h" |
kadonotakashi | 0:8fdf9a60065b | 24 | |
kadonotakashi | 0:8fdf9a60065b | 25 | #include "mbed.h" |
kadonotakashi | 0:8fdf9a60065b | 26 | #include "ticker_api.h" |
kadonotakashi | 0:8fdf9a60065b | 27 | |
kadonotakashi | 0:8fdf9a60065b | 28 | using namespace utest::v1; |
kadonotakashi | 0:8fdf9a60065b | 29 | |
kadonotakashi | 0:8fdf9a60065b | 30 | #define MBED_ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0])) |
kadonotakashi | 0:8fdf9a60065b | 31 | |
kadonotakashi | 0:8fdf9a60065b | 32 | #define TIMESTAMP_MAX_DELTA_BITS(bits) ((uint64_t)(0x7 << ((bits) - 4))) |
kadonotakashi | 0:8fdf9a60065b | 33 | #define TIMESTAMP_MAX_DELTA TIMESTAMP_MAX_DELTA_BITS(32) |
kadonotakashi | 0:8fdf9a60065b | 34 | |
kadonotakashi | 0:8fdf9a60065b | 35 | struct ticker_interface_stub_t { |
kadonotakashi | 0:8fdf9a60065b | 36 | ticker_interface_t interface; |
kadonotakashi | 0:8fdf9a60065b | 37 | bool initialized; |
kadonotakashi | 0:8fdf9a60065b | 38 | bool interrupt_flag; |
kadonotakashi | 0:8fdf9a60065b | 39 | timestamp_t timestamp ; |
kadonotakashi | 0:8fdf9a60065b | 40 | timestamp_t interrupt_timestamp; |
kadonotakashi | 0:8fdf9a60065b | 41 | unsigned int init_call; |
kadonotakashi | 0:8fdf9a60065b | 42 | unsigned int read_call; |
kadonotakashi | 0:8fdf9a60065b | 43 | unsigned int disable_interrupt_call; |
kadonotakashi | 0:8fdf9a60065b | 44 | unsigned int clear_interrupt_call; |
kadonotakashi | 0:8fdf9a60065b | 45 | unsigned int set_interrupt_call; |
kadonotakashi | 0:8fdf9a60065b | 46 | unsigned int fire_interrupt_call; |
kadonotakashi | 0:8fdf9a60065b | 47 | unsigned int get_info_call; |
kadonotakashi | 0:8fdf9a60065b | 48 | }; |
kadonotakashi | 0:8fdf9a60065b | 49 | |
kadonotakashi | 0:8fdf9a60065b | 50 | static ticker_interface_stub_t interface_stub = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 51 | static ticker_info_t interface_info_stub = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 52 | |
kadonotakashi | 0:8fdf9a60065b | 53 | static void ticker_interface_stub_init() |
kadonotakashi | 0:8fdf9a60065b | 54 | { |
kadonotakashi | 0:8fdf9a60065b | 55 | ++interface_stub.init_call; |
kadonotakashi | 0:8fdf9a60065b | 56 | interface_stub.initialized = true; |
kadonotakashi | 0:8fdf9a60065b | 57 | } |
kadonotakashi | 0:8fdf9a60065b | 58 | |
kadonotakashi | 0:8fdf9a60065b | 59 | static uint32_t ticker_interface_stub_read() |
kadonotakashi | 0:8fdf9a60065b | 60 | { |
kadonotakashi | 0:8fdf9a60065b | 61 | ++interface_stub.read_call; |
kadonotakashi | 0:8fdf9a60065b | 62 | return interface_stub.timestamp; |
kadonotakashi | 0:8fdf9a60065b | 63 | } |
kadonotakashi | 0:8fdf9a60065b | 64 | |
kadonotakashi | 0:8fdf9a60065b | 65 | static void ticker_interface_stub_disable_interrupt() |
kadonotakashi | 0:8fdf9a60065b | 66 | { |
kadonotakashi | 0:8fdf9a60065b | 67 | ++interface_stub.disable_interrupt_call; |
kadonotakashi | 0:8fdf9a60065b | 68 | } |
kadonotakashi | 0:8fdf9a60065b | 69 | |
kadonotakashi | 0:8fdf9a60065b | 70 | static void ticker_interface_stub_clear_interrupt() |
kadonotakashi | 0:8fdf9a60065b | 71 | { |
kadonotakashi | 0:8fdf9a60065b | 72 | ++interface_stub.clear_interrupt_call; |
kadonotakashi | 0:8fdf9a60065b | 73 | interface_stub.interrupt_flag = false; |
kadonotakashi | 0:8fdf9a60065b | 74 | } |
kadonotakashi | 0:8fdf9a60065b | 75 | |
kadonotakashi | 0:8fdf9a60065b | 76 | static void ticker_interface_stub_set_interrupt(timestamp_t timestamp) |
kadonotakashi | 0:8fdf9a60065b | 77 | { |
kadonotakashi | 0:8fdf9a60065b | 78 | ++interface_stub.set_interrupt_call; |
kadonotakashi | 0:8fdf9a60065b | 79 | interface_stub.interrupt_timestamp = timestamp; |
kadonotakashi | 0:8fdf9a60065b | 80 | } |
kadonotakashi | 0:8fdf9a60065b | 81 | |
kadonotakashi | 0:8fdf9a60065b | 82 | static void ticker_interface_stub_fire_interrupt() |
kadonotakashi | 0:8fdf9a60065b | 83 | { |
kadonotakashi | 0:8fdf9a60065b | 84 | ++interface_stub.fire_interrupt_call; |
kadonotakashi | 0:8fdf9a60065b | 85 | } |
kadonotakashi | 0:8fdf9a60065b | 86 | |
kadonotakashi | 0:8fdf9a60065b | 87 | static const ticker_info_t *ticker_interface_stub_get_info() |
kadonotakashi | 0:8fdf9a60065b | 88 | { |
kadonotakashi | 0:8fdf9a60065b | 89 | ++interface_stub.get_info_call; |
kadonotakashi | 0:8fdf9a60065b | 90 | return &interface_info_stub; |
kadonotakashi | 0:8fdf9a60065b | 91 | } |
kadonotakashi | 0:8fdf9a60065b | 92 | |
kadonotakashi | 0:8fdf9a60065b | 93 | static void reset_ticker_interface_stub() |
kadonotakashi | 0:8fdf9a60065b | 94 | { |
kadonotakashi | 0:8fdf9a60065b | 95 | interface_stub.interface.init = ticker_interface_stub_init; |
kadonotakashi | 0:8fdf9a60065b | 96 | interface_stub.interface.read = ticker_interface_stub_read; |
kadonotakashi | 0:8fdf9a60065b | 97 | interface_stub.interface.disable_interrupt = |
kadonotakashi | 0:8fdf9a60065b | 98 | ticker_interface_stub_disable_interrupt; |
kadonotakashi | 0:8fdf9a60065b | 99 | interface_stub.interface.clear_interrupt = |
kadonotakashi | 0:8fdf9a60065b | 100 | ticker_interface_stub_clear_interrupt; |
kadonotakashi | 0:8fdf9a60065b | 101 | interface_stub.interface.set_interrupt = ticker_interface_stub_set_interrupt; |
kadonotakashi | 0:8fdf9a60065b | 102 | interface_stub.interface.fire_interrupt = ticker_interface_stub_fire_interrupt; |
kadonotakashi | 0:8fdf9a60065b | 103 | interface_stub.interface.get_info = ticker_interface_stub_get_info; |
kadonotakashi | 0:8fdf9a60065b | 104 | interface_stub.initialized = false; |
kadonotakashi | 0:8fdf9a60065b | 105 | interface_stub.interrupt_flag = false; |
kadonotakashi | 0:8fdf9a60065b | 106 | interface_stub.timestamp = 0; |
kadonotakashi | 0:8fdf9a60065b | 107 | interface_stub.interrupt_timestamp = 0; |
kadonotakashi | 0:8fdf9a60065b | 108 | interface_stub.init_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 109 | interface_stub.read_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 110 | interface_stub.disable_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 111 | interface_stub.clear_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 112 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 113 | interface_stub.fire_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 114 | |
kadonotakashi | 0:8fdf9a60065b | 115 | interface_info_stub.frequency = 1000000; |
kadonotakashi | 0:8fdf9a60065b | 116 | interface_info_stub.bits = 32; |
kadonotakashi | 0:8fdf9a60065b | 117 | } |
kadonotakashi | 0:8fdf9a60065b | 118 | |
kadonotakashi | 0:8fdf9a60065b | 119 | // stub of the event queue |
kadonotakashi | 0:8fdf9a60065b | 120 | static ticker_event_queue_t queue_stub = { |
kadonotakashi | 0:8fdf9a60065b | 121 | /* event handler */ NULL, |
kadonotakashi | 0:8fdf9a60065b | 122 | /* head */ NULL, |
kadonotakashi | 0:8fdf9a60065b | 123 | /* timestamp */ 0, |
kadonotakashi | 0:8fdf9a60065b | 124 | /* initialized */ false |
kadonotakashi | 0:8fdf9a60065b | 125 | }; |
kadonotakashi | 0:8fdf9a60065b | 126 | |
kadonotakashi | 0:8fdf9a60065b | 127 | static void reset_queue_stub() |
kadonotakashi | 0:8fdf9a60065b | 128 | { |
kadonotakashi | 0:8fdf9a60065b | 129 | queue_stub.event_handler = NULL; |
kadonotakashi | 0:8fdf9a60065b | 130 | queue_stub.head = NULL, |
kadonotakashi | 0:8fdf9a60065b | 131 | queue_stub.tick_last_read = 0; |
kadonotakashi | 0:8fdf9a60065b | 132 | queue_stub.tick_remainder = 0; |
kadonotakashi | 0:8fdf9a60065b | 133 | queue_stub.frequency = 0; |
kadonotakashi | 0:8fdf9a60065b | 134 | queue_stub.bitmask = 0; |
kadonotakashi | 0:8fdf9a60065b | 135 | queue_stub.max_delta = 0; |
kadonotakashi | 0:8fdf9a60065b | 136 | queue_stub.max_delta_us = 0; |
kadonotakashi | 0:8fdf9a60065b | 137 | queue_stub.present_time = 0; |
kadonotakashi | 0:8fdf9a60065b | 138 | queue_stub.initialized = false; |
kadonotakashi | 0:8fdf9a60065b | 139 | } |
kadonotakashi | 0:8fdf9a60065b | 140 | |
kadonotakashi | 0:8fdf9a60065b | 141 | // stub of the ticker |
kadonotakashi | 0:8fdf9a60065b | 142 | static ticker_data_t ticker_stub = { |
kadonotakashi | 0:8fdf9a60065b | 143 | /* interface */ &interface_stub.interface, |
kadonotakashi | 0:8fdf9a60065b | 144 | /* queue */ &queue_stub |
kadonotakashi | 0:8fdf9a60065b | 145 | }; |
kadonotakashi | 0:8fdf9a60065b | 146 | |
kadonotakashi | 0:8fdf9a60065b | 147 | static void reset_ticker_stub() |
kadonotakashi | 0:8fdf9a60065b | 148 | { |
kadonotakashi | 0:8fdf9a60065b | 149 | reset_queue_stub(); |
kadonotakashi | 0:8fdf9a60065b | 150 | reset_ticker_interface_stub(); |
kadonotakashi | 0:8fdf9a60065b | 151 | } |
kadonotakashi | 0:8fdf9a60065b | 152 | |
kadonotakashi | 0:8fdf9a60065b | 153 | const uint32_t test_frequencies[] = { |
kadonotakashi | 0:8fdf9a60065b | 154 | 1, |
kadonotakashi | 0:8fdf9a60065b | 155 | 32768, // 2^15 |
kadonotakashi | 0:8fdf9a60065b | 156 | 1000000, |
kadonotakashi | 0:8fdf9a60065b | 157 | 0xFFFFFFFF // 2^32 - 1 |
kadonotakashi | 0:8fdf9a60065b | 158 | }; |
kadonotakashi | 0:8fdf9a60065b | 159 | |
kadonotakashi | 0:8fdf9a60065b | 160 | const uint32_t test_bitwidths[] = { |
kadonotakashi | 0:8fdf9a60065b | 161 | 32, |
kadonotakashi | 0:8fdf9a60065b | 162 | 31, |
kadonotakashi | 0:8fdf9a60065b | 163 | 16, |
kadonotakashi | 0:8fdf9a60065b | 164 | 8 |
kadonotakashi | 0:8fdf9a60065b | 165 | }; |
kadonotakashi | 0:8fdf9a60065b | 166 | |
kadonotakashi | 0:8fdf9a60065b | 167 | template < void (F)(uint32_t a, uint32_t b)> |
kadonotakashi | 0:8fdf9a60065b | 168 | static void test_over_frequency_and_width(void) |
kadonotakashi | 0:8fdf9a60065b | 169 | { |
kadonotakashi | 0:8fdf9a60065b | 170 | for (unsigned int i = 0; i < MBED_ARRAY_SIZE(test_frequencies); i++) { |
kadonotakashi | 0:8fdf9a60065b | 171 | for (unsigned int j = 0; j < MBED_ARRAY_SIZE(test_bitwidths); j++) { |
kadonotakashi | 0:8fdf9a60065b | 172 | reset_ticker_stub(); |
kadonotakashi | 0:8fdf9a60065b | 173 | interface_info_stub.frequency = test_frequencies[i]; |
kadonotakashi | 0:8fdf9a60065b | 174 | interface_info_stub.bits = test_bitwidths[j]; |
kadonotakashi | 0:8fdf9a60065b | 175 | |
kadonotakashi | 0:8fdf9a60065b | 176 | F(test_frequencies[i], test_bitwidths[j]); |
kadonotakashi | 0:8fdf9a60065b | 177 | } |
kadonotakashi | 0:8fdf9a60065b | 178 | } |
kadonotakashi | 0:8fdf9a60065b | 179 | } |
kadonotakashi | 0:8fdf9a60065b | 180 | |
kadonotakashi | 0:8fdf9a60065b | 181 | static utest::v1::status_t case_setup_handler( |
kadonotakashi | 0:8fdf9a60065b | 182 | const Case *const source, const size_t index_of_case |
kadonotakashi | 0:8fdf9a60065b | 183 | ) |
kadonotakashi | 0:8fdf9a60065b | 184 | { |
kadonotakashi | 0:8fdf9a60065b | 185 | utest::v1::status_t status = greentea_case_setup_handler(source, index_of_case); |
kadonotakashi | 0:8fdf9a60065b | 186 | reset_ticker_stub(); |
kadonotakashi | 0:8fdf9a60065b | 187 | return status; |
kadonotakashi | 0:8fdf9a60065b | 188 | } |
kadonotakashi | 0:8fdf9a60065b | 189 | |
kadonotakashi | 0:8fdf9a60065b | 190 | static utest::v1::status_t case_teardown_handler( |
kadonotakashi | 0:8fdf9a60065b | 191 | const Case *const source, const size_t passed, const size_t failed, const failure_t reason |
kadonotakashi | 0:8fdf9a60065b | 192 | ) |
kadonotakashi | 0:8fdf9a60065b | 193 | { |
kadonotakashi | 0:8fdf9a60065b | 194 | reset_ticker_stub(); |
kadonotakashi | 0:8fdf9a60065b | 195 | utest::v1::status_t status = greentea_case_teardown_handler( |
kadonotakashi | 0:8fdf9a60065b | 196 | source, passed, failed, reason |
kadonotakashi | 0:8fdf9a60065b | 197 | ); |
kadonotakashi | 0:8fdf9a60065b | 198 | return status; |
kadonotakashi | 0:8fdf9a60065b | 199 | } |
kadonotakashi | 0:8fdf9a60065b | 200 | |
kadonotakashi | 0:8fdf9a60065b | 201 | static utest::v1::status_t greentea_failure_handler( |
kadonotakashi | 0:8fdf9a60065b | 202 | const Case *const source, const failure_t reason |
kadonotakashi | 0:8fdf9a60065b | 203 | ) |
kadonotakashi | 0:8fdf9a60065b | 204 | { |
kadonotakashi | 0:8fdf9a60065b | 205 | utest::v1::status_t status = greentea_case_failure_abort_handler( |
kadonotakashi | 0:8fdf9a60065b | 206 | source, reason |
kadonotakashi | 0:8fdf9a60065b | 207 | ); |
kadonotakashi | 0:8fdf9a60065b | 208 | return status; |
kadonotakashi | 0:8fdf9a60065b | 209 | } |
kadonotakashi | 0:8fdf9a60065b | 210 | |
kadonotakashi | 0:8fdf9a60065b | 211 | #define MAKE_TEST_CASE(description, handler) \ |
kadonotakashi | 0:8fdf9a60065b | 212 | { \ |
kadonotakashi | 0:8fdf9a60065b | 213 | description, \ |
kadonotakashi | 0:8fdf9a60065b | 214 | handler, \ |
kadonotakashi | 0:8fdf9a60065b | 215 | NULL, \ |
kadonotakashi | 0:8fdf9a60065b | 216 | NULL, \ |
kadonotakashi | 0:8fdf9a60065b | 217 | case_setup_handler, \ |
kadonotakashi | 0:8fdf9a60065b | 218 | case_teardown_handler, \ |
kadonotakashi | 0:8fdf9a60065b | 219 | greentea_failure_handler \ |
kadonotakashi | 0:8fdf9a60065b | 220 | } |
kadonotakashi | 0:8fdf9a60065b | 221 | |
kadonotakashi | 0:8fdf9a60065b | 222 | /** |
kadonotakashi | 0:8fdf9a60065b | 223 | * Given an unitialized ticker_data instance. |
kadonotakashi | 0:8fdf9a60065b | 224 | * When the ticker is initialized |
kadonotakashi | 0:8fdf9a60065b | 225 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 226 | * - The ticker interface should be initialized |
kadonotakashi | 0:8fdf9a60065b | 227 | * - The queue handler should be set to the handler provided in parameter |
kadonotakashi | 0:8fdf9a60065b | 228 | * - The internal ticker timestamp should be zero |
kadonotakashi | 0:8fdf9a60065b | 229 | * - interrupt should be scheduled in current timestamp + |
kadonotakashi | 0:8fdf9a60065b | 230 | * TIMESTAMP_MAX_DELTA |
kadonotakashi | 0:8fdf9a60065b | 231 | * - The queue should not contains any event |
kadonotakashi | 0:8fdf9a60065b | 232 | */ |
kadonotakashi | 0:8fdf9a60065b | 233 | static void test_ticker_initialization() |
kadonotakashi | 0:8fdf9a60065b | 234 | { |
kadonotakashi | 0:8fdf9a60065b | 235 | ticker_event_handler dummy_handler = (ticker_event_handler)0xDEADBEEF; |
kadonotakashi | 0:8fdf9a60065b | 236 | |
kadonotakashi | 0:8fdf9a60065b | 237 | // setup of the stub |
kadonotakashi | 0:8fdf9a60065b | 238 | interface_stub.timestamp = 0xFEEDBABE; |
kadonotakashi | 0:8fdf9a60065b | 239 | |
kadonotakashi | 0:8fdf9a60065b | 240 | ticker_set_handler(&ticker_stub, dummy_handler); |
kadonotakashi | 0:8fdf9a60065b | 241 | |
kadonotakashi | 0:8fdf9a60065b | 242 | TEST_ASSERT_TRUE(interface_stub.initialized); |
kadonotakashi | 0:8fdf9a60065b | 243 | TEST_ASSERT_EQUAL_PTR(dummy_handler, queue_stub.event_handler); |
kadonotakashi | 0:8fdf9a60065b | 244 | TEST_ASSERT_EQUAL_UINT64(0, queue_stub.present_time); |
kadonotakashi | 0:8fdf9a60065b | 245 | TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 246 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 247 | interface_stub.timestamp + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 248 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 249 | ); |
kadonotakashi | 0:8fdf9a60065b | 250 | TEST_ASSERT_EQUAL_PTR(NULL, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 251 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 252 | } |
kadonotakashi | 0:8fdf9a60065b | 253 | |
kadonotakashi | 0:8fdf9a60065b | 254 | /** |
kadonotakashi | 0:8fdf9a60065b | 255 | * Given an initialized ticker_data instance. |
kadonotakashi | 0:8fdf9a60065b | 256 | * When the ticker handler is set to a new value |
kadonotakashi | 0:8fdf9a60065b | 257 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 258 | * - The ticker interface initialization function should not be called. |
kadonotakashi | 0:8fdf9a60065b | 259 | * - The queue handler should be set to the new handler. |
kadonotakashi | 0:8fdf9a60065b | 260 | * - The events in the queue should remains the same. |
kadonotakashi | 0:8fdf9a60065b | 261 | */ |
kadonotakashi | 0:8fdf9a60065b | 262 | static void test_ticker_re_initialization() |
kadonotakashi | 0:8fdf9a60065b | 263 | { |
kadonotakashi | 0:8fdf9a60065b | 264 | ticker_event_handler dummy_handler = (ticker_event_handler) 0xDEADBEEF; |
kadonotakashi | 0:8fdf9a60065b | 265 | ticker_event_handler expected_handler = (ticker_event_handler) 0xFEEDDEAF; |
kadonotakashi | 0:8fdf9a60065b | 266 | |
kadonotakashi | 0:8fdf9a60065b | 267 | ticker_event_t first_event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 268 | ticker_event_t second_event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 269 | ticker_event_t third_event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 270 | |
kadonotakashi | 0:8fdf9a60065b | 271 | first_event.next = &second_event; |
kadonotakashi | 0:8fdf9a60065b | 272 | second_event.next = &third_event; |
kadonotakashi | 0:8fdf9a60065b | 273 | |
kadonotakashi | 0:8fdf9a60065b | 274 | // initialize the ticker and put few events in the queue. |
kadonotakashi | 0:8fdf9a60065b | 275 | ticker_set_handler(&ticker_stub, dummy_handler); |
kadonotakashi | 0:8fdf9a60065b | 276 | // simulate insertion, it shouldn't affect the queue behaviour for this test |
kadonotakashi | 0:8fdf9a60065b | 277 | queue_stub.head = &first_event; |
kadonotakashi | 0:8fdf9a60065b | 278 | interface_stub.init_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 279 | |
kadonotakashi | 0:8fdf9a60065b | 280 | ticker_set_handler(&ticker_stub, expected_handler); |
kadonotakashi | 0:8fdf9a60065b | 281 | |
kadonotakashi | 0:8fdf9a60065b | 282 | TEST_ASSERT_TRUE(interface_stub.initialized); |
kadonotakashi | 0:8fdf9a60065b | 283 | TEST_ASSERT_EQUAL(0, interface_stub.init_call); |
kadonotakashi | 0:8fdf9a60065b | 284 | TEST_ASSERT_EQUAL(expected_handler, queue_stub.event_handler); |
kadonotakashi | 0:8fdf9a60065b | 285 | TEST_ASSERT_EQUAL(&first_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 286 | TEST_ASSERT_EQUAL(&second_event, queue_stub.head->next); |
kadonotakashi | 0:8fdf9a60065b | 287 | TEST_ASSERT_EQUAL(&third_event, queue_stub.head->next->next); |
kadonotakashi | 0:8fdf9a60065b | 288 | TEST_ASSERT_EQUAL(NULL, queue_stub.head->next->next->next); |
kadonotakashi | 0:8fdf9a60065b | 289 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 290 | } |
kadonotakashi | 0:8fdf9a60065b | 291 | |
kadonotakashi | 0:8fdf9a60065b | 292 | /** |
kadonotakashi | 0:8fdf9a60065b | 293 | * Given an initialized ticker_data instance. |
kadonotakashi | 0:8fdf9a60065b | 294 | * When the ticker is read |
kadonotakashi | 0:8fdf9a60065b | 295 | * Then it should return the value present in the ticker interface |
kadonotakashi | 0:8fdf9a60065b | 296 | */ |
kadonotakashi | 0:8fdf9a60065b | 297 | static void test_ticker_read() |
kadonotakashi | 0:8fdf9a60065b | 298 | { |
kadonotakashi | 0:8fdf9a60065b | 299 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 300 | |
kadonotakashi | 0:8fdf9a60065b | 301 | timestamp_t timestamps[] = { |
kadonotakashi | 0:8fdf9a60065b | 302 | 0xA, |
kadonotakashi | 0:8fdf9a60065b | 303 | 0xAA, |
kadonotakashi | 0:8fdf9a60065b | 304 | 0xAAA, |
kadonotakashi | 0:8fdf9a60065b | 305 | 0xAAAA, |
kadonotakashi | 0:8fdf9a60065b | 306 | 0xAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 307 | 0xAAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 308 | 0xAAAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 309 | 0xAAAAAAAA |
kadonotakashi | 0:8fdf9a60065b | 310 | }; |
kadonotakashi | 0:8fdf9a60065b | 311 | |
kadonotakashi | 0:8fdf9a60065b | 312 | for (size_t i = 0; i < MBED_ARRAY_SIZE(timestamps); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 313 | interface_stub.timestamp = timestamps[i]; |
kadonotakashi | 0:8fdf9a60065b | 314 | TEST_ASSERT_EQUAL_UINT32(timestamps[i], ticker_read(&ticker_stub)); |
kadonotakashi | 0:8fdf9a60065b | 315 | TEST_ASSERT_EQUAL_UINT64(timestamps[i], ticker_read_us(&ticker_stub)); |
kadonotakashi | 0:8fdf9a60065b | 316 | } |
kadonotakashi | 0:8fdf9a60065b | 317 | |
kadonotakashi | 0:8fdf9a60065b | 318 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 319 | } |
kadonotakashi | 0:8fdf9a60065b | 320 | |
kadonotakashi | 0:8fdf9a60065b | 321 | /** |
kadonotakashi | 0:8fdf9a60065b | 322 | * Given an initialized ticker_data instance. |
kadonotakashi | 0:8fdf9a60065b | 323 | * When the ticker is read and the value read is less than the previous |
kadonotakashi | 0:8fdf9a60065b | 324 | * value read. |
kadonotakashi | 0:8fdf9a60065b | 325 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 326 | * - ticker_read should return the value read in the ticker interface |
kadonotakashi | 0:8fdf9a60065b | 327 | * - ticker_read_us should return a value where: |
kadonotakashi | 0:8fdf9a60065b | 328 | * + lower 8 bytes should be equal to the value in the ticker interface |
kadonotakashi | 0:8fdf9a60065b | 329 | * + upper 8 bytes should be equal to the previous value of upper 8 bytes |
kadonotakashi | 0:8fdf9a60065b | 330 | * plus one. |
kadonotakashi | 0:8fdf9a60065b | 331 | */ |
kadonotakashi | 0:8fdf9a60065b | 332 | static void test_ticker_read_overflow() |
kadonotakashi | 0:8fdf9a60065b | 333 | { |
kadonotakashi | 0:8fdf9a60065b | 334 | const timestamp_t timestamps[] = { |
kadonotakashi | 0:8fdf9a60065b | 335 | 0xAAAAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 336 | 0xAAAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 337 | 0xAAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 338 | 0xAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 339 | 0xAAAA, |
kadonotakashi | 0:8fdf9a60065b | 340 | 0xAAA, |
kadonotakashi | 0:8fdf9a60065b | 341 | 0xAA, |
kadonotakashi | 0:8fdf9a60065b | 342 | 0xA |
kadonotakashi | 0:8fdf9a60065b | 343 | }; |
kadonotakashi | 0:8fdf9a60065b | 344 | |
kadonotakashi | 0:8fdf9a60065b | 345 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 346 | |
kadonotakashi | 0:8fdf9a60065b | 347 | uint32_t upper_bytes_begin = ticker_read_us(&ticker_stub) >> 32; |
kadonotakashi | 0:8fdf9a60065b | 348 | |
kadonotakashi | 0:8fdf9a60065b | 349 | for (size_t i = 0; i < MBED_ARRAY_SIZE(timestamps); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 350 | interface_stub.timestamp = timestamps[i]; |
kadonotakashi | 0:8fdf9a60065b | 351 | TEST_ASSERT_EQUAL_UINT32(timestamps[i], ticker_read(&ticker_stub)); |
kadonotakashi | 0:8fdf9a60065b | 352 | TEST_ASSERT_EQUAL_UINT32(timestamps[i], ticker_read_us(&ticker_stub)); |
kadonotakashi | 0:8fdf9a60065b | 353 | TEST_ASSERT_EQUAL_UINT64( |
kadonotakashi | 0:8fdf9a60065b | 354 | upper_bytes_begin + i, ticker_read_us(&ticker_stub) >> 32 |
kadonotakashi | 0:8fdf9a60065b | 355 | ); |
kadonotakashi | 0:8fdf9a60065b | 356 | } |
kadonotakashi | 0:8fdf9a60065b | 357 | |
kadonotakashi | 0:8fdf9a60065b | 358 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 359 | } |
kadonotakashi | 0:8fdf9a60065b | 360 | |
kadonotakashi | 0:8fdf9a60065b | 361 | /** |
kadonotakashi | 0:8fdf9a60065b | 362 | * Given an initialized ticker without user registered events. |
kadonotakashi | 0:8fdf9a60065b | 363 | * When an event is inserted with ticker_insert_event and the timestamp passed |
kadonotakashi | 0:8fdf9a60065b | 364 | * in parameter is in range [ticker_timestamp : ticker_timestamp + |
kadonotakashi | 0:8fdf9a60065b | 365 | * TIMESTAMP_MAX_DELTA[. |
kadonotakashi | 0:8fdf9a60065b | 366 | * Then |
kadonotakashi | 0:8fdf9a60065b | 367 | * - The event should be in the queue |
kadonotakashi | 0:8fdf9a60065b | 368 | * - The interrupt timestamp should be equal to the timestamp of the event |
kadonotakashi | 0:8fdf9a60065b | 369 | * - The timestamp of the event should reflect the timestamp requested. |
kadonotakashi | 0:8fdf9a60065b | 370 | * - The id of the event should be equal to the id passed in parameter. |
kadonotakashi | 0:8fdf9a60065b | 371 | */ |
kadonotakashi | 0:8fdf9a60065b | 372 | static void test_legacy_insert_event_outside_overflow_range() |
kadonotakashi | 0:8fdf9a60065b | 373 | { |
kadonotakashi | 0:8fdf9a60065b | 374 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 375 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 376 | |
kadonotakashi | 0:8fdf9a60065b | 377 | // test the end of the range |
kadonotakashi | 0:8fdf9a60065b | 378 | ticker_event_t last_event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 379 | const timestamp_t timestamp_last_event = |
kadonotakashi | 0:8fdf9a60065b | 380 | interface_stub.timestamp + TIMESTAMP_MAX_DELTA; |
kadonotakashi | 0:8fdf9a60065b | 381 | const uint32_t id_last_event = 0xDEADDEAF; |
kadonotakashi | 0:8fdf9a60065b | 382 | |
kadonotakashi | 0:8fdf9a60065b | 383 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 384 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 385 | &last_event, timestamp_last_event, id_last_event |
kadonotakashi | 0:8fdf9a60065b | 386 | ); |
kadonotakashi | 0:8fdf9a60065b | 387 | |
kadonotakashi | 0:8fdf9a60065b | 388 | TEST_ASSERT_EQUAL_PTR(&last_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 389 | TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 390 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 391 | timestamp_last_event, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 392 | ); |
kadonotakashi | 0:8fdf9a60065b | 393 | TEST_ASSERT_EQUAL_PTR(NULL, queue_stub.head->next); |
kadonotakashi | 0:8fdf9a60065b | 394 | TEST_ASSERT_EQUAL_UINT32(timestamp_last_event, last_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 395 | TEST_ASSERT_EQUAL_UINT32(id_last_event, last_event.id); |
kadonotakashi | 0:8fdf9a60065b | 396 | |
kadonotakashi | 0:8fdf9a60065b | 397 | // test the beginning of the range |
kadonotakashi | 0:8fdf9a60065b | 398 | ticker_event_t first_event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 399 | const timestamp_t timestamp_first_event = interface_stub.timestamp + 1; |
kadonotakashi | 0:8fdf9a60065b | 400 | const uint32_t id_first_event = 0xAAAAAAAA; |
kadonotakashi | 0:8fdf9a60065b | 401 | |
kadonotakashi | 0:8fdf9a60065b | 402 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 403 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 404 | &first_event, timestamp_first_event, id_first_event |
kadonotakashi | 0:8fdf9a60065b | 405 | ); |
kadonotakashi | 0:8fdf9a60065b | 406 | |
kadonotakashi | 0:8fdf9a60065b | 407 | TEST_ASSERT_EQUAL_PTR(&first_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 408 | TEST_ASSERT_EQUAL(2, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 409 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 410 | timestamp_first_event, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 411 | ); |
kadonotakashi | 0:8fdf9a60065b | 412 | TEST_ASSERT_EQUAL_PTR(&last_event, queue_stub.head->next); |
kadonotakashi | 0:8fdf9a60065b | 413 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 414 | timestamp_first_event, first_event.timestamp |
kadonotakashi | 0:8fdf9a60065b | 415 | ); |
kadonotakashi | 0:8fdf9a60065b | 416 | TEST_ASSERT_EQUAL_UINT32(id_first_event, first_event.id); |
kadonotakashi | 0:8fdf9a60065b | 417 | |
kadonotakashi | 0:8fdf9a60065b | 418 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 419 | } |
kadonotakashi | 0:8fdf9a60065b | 420 | |
kadonotakashi | 0:8fdf9a60065b | 421 | /** |
kadonotakashi | 0:8fdf9a60065b | 422 | * Given an initialized ticker without user registered events. |
kadonotakashi | 0:8fdf9a60065b | 423 | * When an event is inserted with ticker_insert_event and a timestamp in the |
kadonotakashi | 0:8fdf9a60065b | 424 | * range [ticker_timestamp + TIMESTAMP_MAX_DELTA + 1 : |
kadonotakashi | 0:8fdf9a60065b | 425 | * ticker_timestamp + UINT32MAX [ |
kadonotakashi | 0:8fdf9a60065b | 426 | * Then |
kadonotakashi | 0:8fdf9a60065b | 427 | * - The event should be in the queue |
kadonotakashi | 0:8fdf9a60065b | 428 | * - The interrupt timestamp should be equal to |
kadonotakashi | 0:8fdf9a60065b | 429 | * TIMESTAMP_MAX_DELTA |
kadonotakashi | 0:8fdf9a60065b | 430 | * - The timestamp of the event should reflect the timestamp requested. |
kadonotakashi | 0:8fdf9a60065b | 431 | * - The id of the event should be equal to the id passed in parameter. |
kadonotakashi | 0:8fdf9a60065b | 432 | */ |
kadonotakashi | 0:8fdf9a60065b | 433 | static void test_legacy_insert_event_in_overflow_range() |
kadonotakashi | 0:8fdf9a60065b | 434 | { |
kadonotakashi | 0:8fdf9a60065b | 435 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 436 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 437 | |
kadonotakashi | 0:8fdf9a60065b | 438 | // test the end of the range |
kadonotakashi | 0:8fdf9a60065b | 439 | ticker_event_t last_event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 440 | const timestamp_t timestamp_last_event = |
kadonotakashi | 0:8fdf9a60065b | 441 | interface_stub.timestamp + UINT32_MAX; |
kadonotakashi | 0:8fdf9a60065b | 442 | const uint32_t id_last_event = 0xDEADDEAF; |
kadonotakashi | 0:8fdf9a60065b | 443 | |
kadonotakashi | 0:8fdf9a60065b | 444 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 445 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 446 | &last_event, timestamp_last_event, id_last_event |
kadonotakashi | 0:8fdf9a60065b | 447 | ); |
kadonotakashi | 0:8fdf9a60065b | 448 | |
kadonotakashi | 0:8fdf9a60065b | 449 | TEST_ASSERT_EQUAL_PTR(&last_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 450 | TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 451 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 452 | interface_stub.timestamp + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 453 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 454 | ); |
kadonotakashi | 0:8fdf9a60065b | 455 | TEST_ASSERT_EQUAL_PTR(NULL, queue_stub.head->next); |
kadonotakashi | 0:8fdf9a60065b | 456 | TEST_ASSERT_EQUAL_UINT32(timestamp_last_event, last_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 457 | TEST_ASSERT_EQUAL_UINT32(id_last_event, last_event.id); |
kadonotakashi | 0:8fdf9a60065b | 458 | |
kadonotakashi | 0:8fdf9a60065b | 459 | // test the beginning of the range |
kadonotakashi | 0:8fdf9a60065b | 460 | ++interface_stub.timestamp; |
kadonotakashi | 0:8fdf9a60065b | 461 | |
kadonotakashi | 0:8fdf9a60065b | 462 | ticker_event_t first_event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 463 | const timestamp_t timestamp_first_event = |
kadonotakashi | 0:8fdf9a60065b | 464 | interface_stub.timestamp + TIMESTAMP_MAX_DELTA + 1; |
kadonotakashi | 0:8fdf9a60065b | 465 | const uint32_t id_first_event = 0xAAAAAAAA; |
kadonotakashi | 0:8fdf9a60065b | 466 | |
kadonotakashi | 0:8fdf9a60065b | 467 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 468 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 469 | &first_event, timestamp_first_event, id_first_event |
kadonotakashi | 0:8fdf9a60065b | 470 | ); |
kadonotakashi | 0:8fdf9a60065b | 471 | |
kadonotakashi | 0:8fdf9a60065b | 472 | TEST_ASSERT_EQUAL_PTR(&first_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 473 | TEST_ASSERT_EQUAL(2, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 474 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 475 | interface_stub.timestamp + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 476 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 477 | ); |
kadonotakashi | 0:8fdf9a60065b | 478 | TEST_ASSERT_EQUAL_PTR(&last_event, queue_stub.head->next); |
kadonotakashi | 0:8fdf9a60065b | 479 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 480 | timestamp_first_event, first_event.timestamp |
kadonotakashi | 0:8fdf9a60065b | 481 | ); |
kadonotakashi | 0:8fdf9a60065b | 482 | TEST_ASSERT_EQUAL_UINT32(id_first_event, first_event.id); |
kadonotakashi | 0:8fdf9a60065b | 483 | |
kadonotakashi | 0:8fdf9a60065b | 484 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 485 | } |
kadonotakashi | 0:8fdf9a60065b | 486 | |
kadonotakashi | 0:8fdf9a60065b | 487 | /** |
kadonotakashi | 0:8fdf9a60065b | 488 | * Given an initialized ticker without user registered events. |
kadonotakashi | 0:8fdf9a60065b | 489 | * When an event is inserted with ticker_insert_event and the timestamp in |
kadonotakashi | 0:8fdf9a60065b | 490 | * parameter is less than the current timestamp value. |
kadonotakashi | 0:8fdf9a60065b | 491 | * Then |
kadonotakashi | 0:8fdf9a60065b | 492 | * - The event should be in the queue |
kadonotakashi | 0:8fdf9a60065b | 493 | * - The timestamp of the event should reflect the timestamp requested: |
kadonotakashi | 0:8fdf9a60065b | 494 | * + lower 8 bytes should be equal to the timestamp in input. |
kadonotakashi | 0:8fdf9a60065b | 495 | * + upper 8 bytes should be equal to the upper of the upper 8 bytes of the |
kadonotakashi | 0:8fdf9a60065b | 496 | * timestamp state stored in the queue plus one. |
kadonotakashi | 0:8fdf9a60065b | 497 | * - The id of the event should be equal to the id passed in parameter. |
kadonotakashi | 0:8fdf9a60065b | 498 | */ |
kadonotakashi | 0:8fdf9a60065b | 499 | static void test_legacy_insert_event_overflow() |
kadonotakashi | 0:8fdf9a60065b | 500 | { |
kadonotakashi | 0:8fdf9a60065b | 501 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 502 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 503 | |
kadonotakashi | 0:8fdf9a60065b | 504 | interface_stub.timestamp = 0x20000000; |
kadonotakashi | 0:8fdf9a60065b | 505 | ticker_read(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 506 | |
kadonotakashi | 0:8fdf9a60065b | 507 | ticker_event_t event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 508 | const timestamp_t expected_timestamp = |
kadonotakashi | 0:8fdf9a60065b | 509 | interface_stub.timestamp + |
kadonotakashi | 0:8fdf9a60065b | 510 | TIMESTAMP_MAX_DELTA + |
kadonotakashi | 0:8fdf9a60065b | 511 | 1; |
kadonotakashi | 0:8fdf9a60065b | 512 | const us_timestamp_t expected_us_timestamp = |
kadonotakashi | 0:8fdf9a60065b | 513 | (((queue_stub.present_time >> 32) + 1) << 32) | expected_timestamp; |
kadonotakashi | 0:8fdf9a60065b | 514 | const uint32_t expected_id = 0xDEADDEAF; |
kadonotakashi | 0:8fdf9a60065b | 515 | |
kadonotakashi | 0:8fdf9a60065b | 516 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 517 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 518 | &event, expected_timestamp, expected_id |
kadonotakashi | 0:8fdf9a60065b | 519 | ); |
kadonotakashi | 0:8fdf9a60065b | 520 | |
kadonotakashi | 0:8fdf9a60065b | 521 | TEST_ASSERT_EQUAL_PTR(&event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 522 | TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 523 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 524 | interface_stub.timestamp + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 525 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 526 | ); |
kadonotakashi | 0:8fdf9a60065b | 527 | TEST_ASSERT_EQUAL_PTR(NULL, queue_stub.head->next); |
kadonotakashi | 0:8fdf9a60065b | 528 | TEST_ASSERT_EQUAL_UINT32(expected_us_timestamp, event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 529 | TEST_ASSERT_EQUAL_UINT32(expected_id, event.id); |
kadonotakashi | 0:8fdf9a60065b | 530 | |
kadonotakashi | 0:8fdf9a60065b | 531 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 532 | } |
kadonotakashi | 0:8fdf9a60065b | 533 | |
kadonotakashi | 0:8fdf9a60065b | 534 | /** |
kadonotakashi | 0:8fdf9a60065b | 535 | * Given an initialized ticker. |
kadonotakashi | 0:8fdf9a60065b | 536 | * When an event is inserted with ticker_insert_event and a timestamp less than |
kadonotakashi | 0:8fdf9a60065b | 537 | * the one for the next scheduled timestamp. |
kadonotakashi | 0:8fdf9a60065b | 538 | * Then |
kadonotakashi | 0:8fdf9a60065b | 539 | * - The event inserted should be the first in the queue |
kadonotakashi | 0:8fdf9a60065b | 540 | * - The interrupt timestamp should be equal to the timestamp of the event or |
kadonotakashi | 0:8fdf9a60065b | 541 | * TIMESTAMP_MAX_DELTA if in the overflow range. |
kadonotakashi | 0:8fdf9a60065b | 542 | * - The timestamp of the event should reflect the timestamp requested. |
kadonotakashi | 0:8fdf9a60065b | 543 | * - The id of the event should be equal to the id passed in parameter. |
kadonotakashi | 0:8fdf9a60065b | 544 | * - Events in the queue should remained ordered by timestamp. |
kadonotakashi | 0:8fdf9a60065b | 545 | */ |
kadonotakashi | 0:8fdf9a60065b | 546 | static void test_legacy_insert_event_head() |
kadonotakashi | 0:8fdf9a60065b | 547 | { |
kadonotakashi | 0:8fdf9a60065b | 548 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 549 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 550 | |
kadonotakashi | 0:8fdf9a60065b | 551 | const timestamp_t timestamps[] = { |
kadonotakashi | 0:8fdf9a60065b | 552 | UINT32_MAX, |
kadonotakashi | 0:8fdf9a60065b | 553 | TIMESTAMP_MAX_DELTA + 1, |
kadonotakashi | 0:8fdf9a60065b | 554 | TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 555 | TIMESTAMP_MAX_DELTA / 2, |
kadonotakashi | 0:8fdf9a60065b | 556 | TIMESTAMP_MAX_DELTA / 4, |
kadonotakashi | 0:8fdf9a60065b | 557 | TIMESTAMP_MAX_DELTA / 8, |
kadonotakashi | 0:8fdf9a60065b | 558 | TIMESTAMP_MAX_DELTA / 16, |
kadonotakashi | 0:8fdf9a60065b | 559 | }; |
kadonotakashi | 0:8fdf9a60065b | 560 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 561 | |
kadonotakashi | 0:8fdf9a60065b | 562 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 563 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 564 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 565 | &events[i], timestamps[i], i |
kadonotakashi | 0:8fdf9a60065b | 566 | ); |
kadonotakashi | 0:8fdf9a60065b | 567 | |
kadonotakashi | 0:8fdf9a60065b | 568 | TEST_ASSERT_EQUAL_PTR(&events[i], queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 569 | TEST_ASSERT_EQUAL(i + 1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 570 | if (timestamps[i] < TIMESTAMP_MAX_DELTA) { |
kadonotakashi | 0:8fdf9a60065b | 571 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 572 | timestamps[i], |
kadonotakashi | 0:8fdf9a60065b | 573 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 574 | ); |
kadonotakashi | 0:8fdf9a60065b | 575 | } else { |
kadonotakashi | 0:8fdf9a60065b | 576 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 577 | TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 578 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 579 | ); |
kadonotakashi | 0:8fdf9a60065b | 580 | } |
kadonotakashi | 0:8fdf9a60065b | 581 | |
kadonotakashi | 0:8fdf9a60065b | 582 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 583 | timestamps[i], events[i].timestamp |
kadonotakashi | 0:8fdf9a60065b | 584 | ); |
kadonotakashi | 0:8fdf9a60065b | 585 | TEST_ASSERT_EQUAL_UINT32(i, events[i].id); |
kadonotakashi | 0:8fdf9a60065b | 586 | |
kadonotakashi | 0:8fdf9a60065b | 587 | ticker_event_t *e = &events[i]; |
kadonotakashi | 0:8fdf9a60065b | 588 | while (e) { |
kadonotakashi | 0:8fdf9a60065b | 589 | TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp); |
kadonotakashi | 0:8fdf9a60065b | 590 | if (e->next) { |
kadonotakashi | 0:8fdf9a60065b | 591 | TEST_ASSERT_TRUE(e->id > e->next->id); |
kadonotakashi | 0:8fdf9a60065b | 592 | TEST_ASSERT_TRUE(e->timestamp < e->next->timestamp); |
kadonotakashi | 0:8fdf9a60065b | 593 | } else { |
kadonotakashi | 0:8fdf9a60065b | 594 | TEST_ASSERT_EQUAL_UINT32(0, e->id); |
kadonotakashi | 0:8fdf9a60065b | 595 | } |
kadonotakashi | 0:8fdf9a60065b | 596 | e = e->next; |
kadonotakashi | 0:8fdf9a60065b | 597 | } |
kadonotakashi | 0:8fdf9a60065b | 598 | } |
kadonotakashi | 0:8fdf9a60065b | 599 | |
kadonotakashi | 0:8fdf9a60065b | 600 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 601 | } |
kadonotakashi | 0:8fdf9a60065b | 602 | |
kadonotakashi | 0:8fdf9a60065b | 603 | /** |
kadonotakashi | 0:8fdf9a60065b | 604 | * Given an initialized ticker. |
kadonotakashi | 0:8fdf9a60065b | 605 | * When an event is inserted with ticker_insert_event and its timestamp is bigger |
kadonotakashi | 0:8fdf9a60065b | 606 | * than the one of the last event in the queue. |
kadonotakashi | 0:8fdf9a60065b | 607 | * Then |
kadonotakashi | 0:8fdf9a60065b | 608 | * - The event inserted should be the last in the queue |
kadonotakashi | 0:8fdf9a60065b | 609 | * - The interrupt timestamp should remains equal to the interrupt timestamp |
kadonotakashi | 0:8fdf9a60065b | 610 | * of the head event . |
kadonotakashi | 0:8fdf9a60065b | 611 | * - The timestamp of the event should reflect the timestamp requested. |
kadonotakashi | 0:8fdf9a60065b | 612 | * - The id of the event should be equal to the id passed in parameter. |
kadonotakashi | 0:8fdf9a60065b | 613 | * - Events in the queue should remained ordered by timestamp. |
kadonotakashi | 0:8fdf9a60065b | 614 | */ |
kadonotakashi | 0:8fdf9a60065b | 615 | static void test_legacy_insert_event_tail() |
kadonotakashi | 0:8fdf9a60065b | 616 | { |
kadonotakashi | 0:8fdf9a60065b | 617 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 618 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 619 | |
kadonotakashi | 0:8fdf9a60065b | 620 | const timestamp_t timestamps[] = { |
kadonotakashi | 0:8fdf9a60065b | 621 | 0xA, |
kadonotakashi | 0:8fdf9a60065b | 622 | 0xAA, |
kadonotakashi | 0:8fdf9a60065b | 623 | 0xAAA, |
kadonotakashi | 0:8fdf9a60065b | 624 | 0xAAAA, |
kadonotakashi | 0:8fdf9a60065b | 625 | 0xAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 626 | 0xAAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 627 | 0xAAAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 628 | 0xAAAAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 629 | }; |
kadonotakashi | 0:8fdf9a60065b | 630 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 631 | |
kadonotakashi | 0:8fdf9a60065b | 632 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 633 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 634 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 635 | &events[i], timestamps[i], i |
kadonotakashi | 0:8fdf9a60065b | 636 | ); |
kadonotakashi | 0:8fdf9a60065b | 637 | |
kadonotakashi | 0:8fdf9a60065b | 638 | TEST_ASSERT_EQUAL_PTR(&events[0], queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 639 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 640 | timestamps[0], interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 641 | ); |
kadonotakashi | 0:8fdf9a60065b | 642 | |
kadonotakashi | 0:8fdf9a60065b | 643 | TEST_ASSERT_EQUAL_UINT32(timestamps[i], events[i].timestamp); |
kadonotakashi | 0:8fdf9a60065b | 644 | TEST_ASSERT_EQUAL_UINT32(i, events[i].id); |
kadonotakashi | 0:8fdf9a60065b | 645 | |
kadonotakashi | 0:8fdf9a60065b | 646 | ticker_event_t *e = queue_stub.head; |
kadonotakashi | 0:8fdf9a60065b | 647 | while (e) { |
kadonotakashi | 0:8fdf9a60065b | 648 | TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp); |
kadonotakashi | 0:8fdf9a60065b | 649 | if (e->next) { |
kadonotakashi | 0:8fdf9a60065b | 650 | TEST_ASSERT_TRUE(e->id < e->next->id); |
kadonotakashi | 0:8fdf9a60065b | 651 | TEST_ASSERT_TRUE(e->timestamp < e->next->timestamp); |
kadonotakashi | 0:8fdf9a60065b | 652 | } else { |
kadonotakashi | 0:8fdf9a60065b | 653 | TEST_ASSERT_EQUAL_UINT32(&events[i], e); |
kadonotakashi | 0:8fdf9a60065b | 654 | } |
kadonotakashi | 0:8fdf9a60065b | 655 | e = e->next; |
kadonotakashi | 0:8fdf9a60065b | 656 | } |
kadonotakashi | 0:8fdf9a60065b | 657 | } |
kadonotakashi | 0:8fdf9a60065b | 658 | |
kadonotakashi | 0:8fdf9a60065b | 659 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 660 | } |
kadonotakashi | 0:8fdf9a60065b | 661 | |
kadonotakashi | 0:8fdf9a60065b | 662 | /** |
kadonotakashi | 0:8fdf9a60065b | 663 | * Given an initialized ticker. |
kadonotakashi | 0:8fdf9a60065b | 664 | * When an event is inserted with ticker_insert_event and a timestamp less |
kadonotakashi | 0:8fdf9a60065b | 665 | * than the current timestamp in the interface and less than the relative |
kadonotakashi | 0:8fdf9a60065b | 666 | * timestamp of the next event to execute. |
kadonotakashi | 0:8fdf9a60065b | 667 | * Then |
kadonotakashi | 0:8fdf9a60065b | 668 | * - The event inserted should be after the head |
kadonotakashi | 0:8fdf9a60065b | 669 | * - The interrupt timestamp should remains equal to the interrupt timestamp |
kadonotakashi | 0:8fdf9a60065b | 670 | * of the head event . |
kadonotakashi | 0:8fdf9a60065b | 671 | * - The timestamp of the event should reflect the timestamp requested (overflow) |
kadonotakashi | 0:8fdf9a60065b | 672 | * - The id of the event should be equal to the id passed in parameter. |
kadonotakashi | 0:8fdf9a60065b | 673 | * - Events in the queue should remained ordered by timestamp. |
kadonotakashi | 0:8fdf9a60065b | 674 | */ |
kadonotakashi | 0:8fdf9a60065b | 675 | static void test_legacy_insert_event_multiple_overflow() |
kadonotakashi | 0:8fdf9a60065b | 676 | { |
kadonotakashi | 0:8fdf9a60065b | 677 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 678 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 679 | |
kadonotakashi | 0:8fdf9a60065b | 680 | const timestamp_t timestamps[] = { |
kadonotakashi | 0:8fdf9a60065b | 681 | 0xA, |
kadonotakashi | 0:8fdf9a60065b | 682 | 0xAA, |
kadonotakashi | 0:8fdf9a60065b | 683 | 0xAAA, |
kadonotakashi | 0:8fdf9a60065b | 684 | 0xAAAA, |
kadonotakashi | 0:8fdf9a60065b | 685 | 0xAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 686 | 0xAAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 687 | 0xAAAAAAA, |
kadonotakashi | 0:8fdf9a60065b | 688 | 0xAAAAAAAA |
kadonotakashi | 0:8fdf9a60065b | 689 | }; |
kadonotakashi | 0:8fdf9a60065b | 690 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 691 | |
kadonotakashi | 0:8fdf9a60065b | 692 | ticker_event_t ref_event; |
kadonotakashi | 0:8fdf9a60065b | 693 | timestamp_t ref_event_timestamp = 0xCCCCCCCC; |
kadonotakashi | 0:8fdf9a60065b | 694 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 695 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 696 | &ref_event, ref_event_timestamp, 0xDEADBEEF |
kadonotakashi | 0:8fdf9a60065b | 697 | ); |
kadonotakashi | 0:8fdf9a60065b | 698 | |
kadonotakashi | 0:8fdf9a60065b | 699 | timestamp_t last_timestamp_to_insert = |
kadonotakashi | 0:8fdf9a60065b | 700 | timestamps[MBED_ARRAY_SIZE(timestamps) - 1]; |
kadonotakashi | 0:8fdf9a60065b | 701 | interface_stub.timestamp = |
kadonotakashi | 0:8fdf9a60065b | 702 | last_timestamp_to_insert + |
kadonotakashi | 0:8fdf9a60065b | 703 | ((ref_event_timestamp - last_timestamp_to_insert) / 2); |
kadonotakashi | 0:8fdf9a60065b | 704 | ticker_irq_handler(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 705 | |
kadonotakashi | 0:8fdf9a60065b | 706 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 707 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 708 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 709 | &events[i], timestamps[i], i |
kadonotakashi | 0:8fdf9a60065b | 710 | ); |
kadonotakashi | 0:8fdf9a60065b | 711 | |
kadonotakashi | 0:8fdf9a60065b | 712 | TEST_ASSERT_EQUAL_PTR(&ref_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 713 | TEST_ASSERT_EQUAL_PTR(&events[0], queue_stub.head->next); |
kadonotakashi | 0:8fdf9a60065b | 714 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 715 | ref_event_timestamp, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 716 | ); |
kadonotakashi | 0:8fdf9a60065b | 717 | |
kadonotakashi | 0:8fdf9a60065b | 718 | TEST_ASSERT_EQUAL_UINT32(timestamps[i], events[i].timestamp); |
kadonotakashi | 0:8fdf9a60065b | 719 | TEST_ASSERT_EQUAL_UINT32(i, events[i].id); |
kadonotakashi | 0:8fdf9a60065b | 720 | |
kadonotakashi | 0:8fdf9a60065b | 721 | ticker_event_t *e = queue_stub.head->next; |
kadonotakashi | 0:8fdf9a60065b | 722 | while (e) { |
kadonotakashi | 0:8fdf9a60065b | 723 | TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp); |
kadonotakashi | 0:8fdf9a60065b | 724 | if (e->next) { |
kadonotakashi | 0:8fdf9a60065b | 725 | TEST_ASSERT_TRUE(e->id < e->next->id); |
kadonotakashi | 0:8fdf9a60065b | 726 | TEST_ASSERT_TRUE(e->timestamp < e->next->timestamp); |
kadonotakashi | 0:8fdf9a60065b | 727 | } else { |
kadonotakashi | 0:8fdf9a60065b | 728 | TEST_ASSERT_EQUAL_UINT32(&events[i], e); |
kadonotakashi | 0:8fdf9a60065b | 729 | } |
kadonotakashi | 0:8fdf9a60065b | 730 | e = e->next; |
kadonotakashi | 0:8fdf9a60065b | 731 | } |
kadonotakashi | 0:8fdf9a60065b | 732 | } |
kadonotakashi | 0:8fdf9a60065b | 733 | |
kadonotakashi | 0:8fdf9a60065b | 734 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 735 | } |
kadonotakashi | 0:8fdf9a60065b | 736 | |
kadonotakashi | 0:8fdf9a60065b | 737 | /** |
kadonotakashi | 0:8fdf9a60065b | 738 | * Given an initialized ticker. |
kadonotakashi | 0:8fdf9a60065b | 739 | * When an event is inserted with ticker_insert_event. |
kadonotakashi | 0:8fdf9a60065b | 740 | * Then |
kadonotakashi | 0:8fdf9a60065b | 741 | * - The event inserted should be at the correct position in the queue |
kadonotakashi | 0:8fdf9a60065b | 742 | * - The event queue should remain ordered by timestamp |
kadonotakashi | 0:8fdf9a60065b | 743 | * - The interrupt timestamp should be equal to the interrupt timestamp |
kadonotakashi | 0:8fdf9a60065b | 744 | * of the head event or TIMESTAMP_MAX_DELTA if the |
kadonotakashi | 0:8fdf9a60065b | 745 | * timestamp is in the overflow range. |
kadonotakashi | 0:8fdf9a60065b | 746 | * - The timestamp of the event should reflect the timestamp requested (overflow) |
kadonotakashi | 0:8fdf9a60065b | 747 | * - The id of the event should be equal to the id passed in parameter. |
kadonotakashi | 0:8fdf9a60065b | 748 | * - Events in the queue should remained ordered by timestamp. |
kadonotakashi | 0:8fdf9a60065b | 749 | */ |
kadonotakashi | 0:8fdf9a60065b | 750 | static void test_legacy_insert_event_multiple_random() |
kadonotakashi | 0:8fdf9a60065b | 751 | { |
kadonotakashi | 0:8fdf9a60065b | 752 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 753 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 754 | |
kadonotakashi | 0:8fdf9a60065b | 755 | const timestamp_t ref_timestamp = UINT32_MAX / 2; |
kadonotakashi | 0:8fdf9a60065b | 756 | interface_stub.timestamp = ref_timestamp; |
kadonotakashi | 0:8fdf9a60065b | 757 | |
kadonotakashi | 0:8fdf9a60065b | 758 | // insert first event at the head of the queue |
kadonotakashi | 0:8fdf9a60065b | 759 | ticker_event_t first_event; |
kadonotakashi | 0:8fdf9a60065b | 760 | const timestamp_t first_event_timestamp = |
kadonotakashi | 0:8fdf9a60065b | 761 | ref_timestamp + TIMESTAMP_MAX_DELTA + 100; |
kadonotakashi | 0:8fdf9a60065b | 762 | |
kadonotakashi | 0:8fdf9a60065b | 763 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 764 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 765 | &first_event, first_event_timestamp, (uint32_t) &first_event |
kadonotakashi | 0:8fdf9a60065b | 766 | ); |
kadonotakashi | 0:8fdf9a60065b | 767 | |
kadonotakashi | 0:8fdf9a60065b | 768 | TEST_ASSERT_EQUAL_PTR(&first_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 769 | TEST_ASSERT_EQUAL_PTR(NULL, first_event.next); |
kadonotakashi | 0:8fdf9a60065b | 770 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 771 | ref_timestamp + TIMESTAMP_MAX_DELTA, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 772 | ); |
kadonotakashi | 0:8fdf9a60065b | 773 | TEST_ASSERT_EQUAL_UINT32(first_event_timestamp, first_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 774 | TEST_ASSERT_EQUAL_UINT64( |
kadonotakashi | 0:8fdf9a60065b | 775 | first_event.timestamp, |
kadonotakashi | 0:8fdf9a60065b | 776 | first_event_timestamp + |
kadonotakashi | 0:8fdf9a60065b | 777 | ((first_event_timestamp < ref_timestamp) ? (1ULL << 32) : 0) |
kadonotakashi | 0:8fdf9a60065b | 778 | ); |
kadonotakashi | 0:8fdf9a60065b | 779 | TEST_ASSERT_EQUAL_UINT32((uint32_t) &first_event, first_event.id); |
kadonotakashi | 0:8fdf9a60065b | 780 | |
kadonotakashi | 0:8fdf9a60065b | 781 | // insert second event at the tail of the queue |
kadonotakashi | 0:8fdf9a60065b | 782 | ticker_event_t second_event; |
kadonotakashi | 0:8fdf9a60065b | 783 | const timestamp_t second_event_timestamp = first_event_timestamp + 1; |
kadonotakashi | 0:8fdf9a60065b | 784 | |
kadonotakashi | 0:8fdf9a60065b | 785 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 786 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 787 | &second_event, second_event_timestamp, (uint32_t) &second_event |
kadonotakashi | 0:8fdf9a60065b | 788 | ); |
kadonotakashi | 0:8fdf9a60065b | 789 | |
kadonotakashi | 0:8fdf9a60065b | 790 | TEST_ASSERT_EQUAL_PTR(&first_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 791 | TEST_ASSERT_EQUAL_PTR(&second_event, first_event.next); |
kadonotakashi | 0:8fdf9a60065b | 792 | TEST_ASSERT_EQUAL_PTR(NULL, second_event.next); |
kadonotakashi | 0:8fdf9a60065b | 793 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 794 | ref_timestamp + TIMESTAMP_MAX_DELTA, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 795 | ); |
kadonotakashi | 0:8fdf9a60065b | 796 | TEST_ASSERT_EQUAL_UINT32(second_event_timestamp, second_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 797 | TEST_ASSERT_EQUAL_UINT64( |
kadonotakashi | 0:8fdf9a60065b | 798 | second_event.timestamp, |
kadonotakashi | 0:8fdf9a60065b | 799 | second_event_timestamp + |
kadonotakashi | 0:8fdf9a60065b | 800 | ((second_event_timestamp < ref_timestamp) ? (1ULL << 32) : 0) |
kadonotakashi | 0:8fdf9a60065b | 801 | ); |
kadonotakashi | 0:8fdf9a60065b | 802 | TEST_ASSERT_EQUAL_UINT32((uint32_t) &second_event, second_event.id); |
kadonotakashi | 0:8fdf9a60065b | 803 | |
kadonotakashi | 0:8fdf9a60065b | 804 | |
kadonotakashi | 0:8fdf9a60065b | 805 | // insert third event at the head of the queue out the overflow zone |
kadonotakashi | 0:8fdf9a60065b | 806 | ticker_event_t third_event; |
kadonotakashi | 0:8fdf9a60065b | 807 | const timestamp_t third_event_timestamp = |
kadonotakashi | 0:8fdf9a60065b | 808 | ref_timestamp + TIMESTAMP_MAX_DELTA - 100; |
kadonotakashi | 0:8fdf9a60065b | 809 | |
kadonotakashi | 0:8fdf9a60065b | 810 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 811 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 812 | &third_event, third_event_timestamp, (uint32_t) &third_event |
kadonotakashi | 0:8fdf9a60065b | 813 | ); |
kadonotakashi | 0:8fdf9a60065b | 814 | |
kadonotakashi | 0:8fdf9a60065b | 815 | TEST_ASSERT_EQUAL_PTR(&third_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 816 | TEST_ASSERT_EQUAL_PTR(&first_event, third_event.next); |
kadonotakashi | 0:8fdf9a60065b | 817 | TEST_ASSERT_EQUAL_PTR(&second_event, first_event.next); |
kadonotakashi | 0:8fdf9a60065b | 818 | TEST_ASSERT_EQUAL_PTR(NULL, second_event.next); |
kadonotakashi | 0:8fdf9a60065b | 819 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 820 | third_event_timestamp, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 821 | ); |
kadonotakashi | 0:8fdf9a60065b | 822 | TEST_ASSERT_EQUAL_UINT32(third_event_timestamp, third_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 823 | TEST_ASSERT_EQUAL_UINT64( |
kadonotakashi | 0:8fdf9a60065b | 824 | third_event.timestamp, |
kadonotakashi | 0:8fdf9a60065b | 825 | third_event_timestamp + |
kadonotakashi | 0:8fdf9a60065b | 826 | ((third_event_timestamp < ref_timestamp) ? (1ULL << 32) : 0) |
kadonotakashi | 0:8fdf9a60065b | 827 | ); |
kadonotakashi | 0:8fdf9a60065b | 828 | TEST_ASSERT_EQUAL_UINT32((uint32_t) &third_event, third_event.id); |
kadonotakashi | 0:8fdf9a60065b | 829 | |
kadonotakashi | 0:8fdf9a60065b | 830 | // insert fourth event right after the third event |
kadonotakashi | 0:8fdf9a60065b | 831 | ticker_event_t fourth_event; |
kadonotakashi | 0:8fdf9a60065b | 832 | const timestamp_t fourth_event_timestamp = third_event_timestamp + 50; |
kadonotakashi | 0:8fdf9a60065b | 833 | |
kadonotakashi | 0:8fdf9a60065b | 834 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 835 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 836 | &fourth_event, fourth_event_timestamp, (uint32_t) &fourth_event |
kadonotakashi | 0:8fdf9a60065b | 837 | ); |
kadonotakashi | 0:8fdf9a60065b | 838 | |
kadonotakashi | 0:8fdf9a60065b | 839 | TEST_ASSERT_EQUAL_PTR(&third_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 840 | TEST_ASSERT_EQUAL_PTR(&fourth_event, third_event.next); |
kadonotakashi | 0:8fdf9a60065b | 841 | TEST_ASSERT_EQUAL_PTR(&first_event, fourth_event.next); |
kadonotakashi | 0:8fdf9a60065b | 842 | TEST_ASSERT_EQUAL_PTR(&second_event, first_event.next); |
kadonotakashi | 0:8fdf9a60065b | 843 | TEST_ASSERT_EQUAL_PTR(NULL, second_event.next); |
kadonotakashi | 0:8fdf9a60065b | 844 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 845 | third_event_timestamp, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 846 | ); |
kadonotakashi | 0:8fdf9a60065b | 847 | TEST_ASSERT_EQUAL_UINT32(fourth_event_timestamp, fourth_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 848 | TEST_ASSERT_EQUAL_UINT64( |
kadonotakashi | 0:8fdf9a60065b | 849 | fourth_event.timestamp, |
kadonotakashi | 0:8fdf9a60065b | 850 | fourth_event_timestamp + |
kadonotakashi | 0:8fdf9a60065b | 851 | ((fourth_event_timestamp < ref_timestamp) ? (1ULL << 32) : 0) |
kadonotakashi | 0:8fdf9a60065b | 852 | ); |
kadonotakashi | 0:8fdf9a60065b | 853 | TEST_ASSERT_EQUAL_UINT32((uint32_t) &fourth_event, fourth_event.id); |
kadonotakashi | 0:8fdf9a60065b | 854 | |
kadonotakashi | 0:8fdf9a60065b | 855 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 856 | } |
kadonotakashi | 0:8fdf9a60065b | 857 | |
kadonotakashi | 0:8fdf9a60065b | 858 | /** |
kadonotakashi | 0:8fdf9a60065b | 859 | * Given an initialized ticker without user registered events. |
kadonotakashi | 0:8fdf9a60065b | 860 | * When an event is inserted with ticker_insert_event_us and the timestamp passed |
kadonotakashi | 0:8fdf9a60065b | 861 | * in parameter is in range [ticker_timestamp : ticker_timestamp + |
kadonotakashi | 0:8fdf9a60065b | 862 | * TIMESTAMP_MAX_DELTA[. |
kadonotakashi | 0:8fdf9a60065b | 863 | * Then |
kadonotakashi | 0:8fdf9a60065b | 864 | * - The event should be in the queue |
kadonotakashi | 0:8fdf9a60065b | 865 | * - The interrupt timestamp should be equal to the lower 8 bytes of the event. |
kadonotakashi | 0:8fdf9a60065b | 866 | * - The timestamp of the event should be equal to the timestamp requested. |
kadonotakashi | 0:8fdf9a60065b | 867 | * - The id of the event should be equal to the id passed in parameter. |
kadonotakashi | 0:8fdf9a60065b | 868 | */ |
kadonotakashi | 0:8fdf9a60065b | 869 | static void test_insert_event_us_outside_overflow_range() |
kadonotakashi | 0:8fdf9a60065b | 870 | { |
kadonotakashi | 0:8fdf9a60065b | 871 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 872 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 873 | interface_stub.timestamp = 0xAAAAAAAA; |
kadonotakashi | 0:8fdf9a60065b | 874 | queue_stub.tick_last_read = interface_stub.timestamp; |
kadonotakashi | 0:8fdf9a60065b | 875 | queue_stub.present_time = 10ULL << 32 | interface_stub.timestamp; |
kadonotakashi | 0:8fdf9a60065b | 876 | |
kadonotakashi | 0:8fdf9a60065b | 877 | // test the end of the range |
kadonotakashi | 0:8fdf9a60065b | 878 | ticker_event_t last_event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 879 | const us_timestamp_t timestamp_last_event = |
kadonotakashi | 0:8fdf9a60065b | 880 | queue_stub.present_time + TIMESTAMP_MAX_DELTA; |
kadonotakashi | 0:8fdf9a60065b | 881 | const uint32_t id_last_event = 0xDEADDEAF; |
kadonotakashi | 0:8fdf9a60065b | 882 | |
kadonotakashi | 0:8fdf9a60065b | 883 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 884 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 885 | &last_event, timestamp_last_event, id_last_event |
kadonotakashi | 0:8fdf9a60065b | 886 | ); |
kadonotakashi | 0:8fdf9a60065b | 887 | |
kadonotakashi | 0:8fdf9a60065b | 888 | TEST_ASSERT_EQUAL_PTR(&last_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 889 | TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 890 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 891 | timestamp_last_event, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 892 | ); |
kadonotakashi | 0:8fdf9a60065b | 893 | TEST_ASSERT_EQUAL_PTR(NULL, queue_stub.head->next); |
kadonotakashi | 0:8fdf9a60065b | 894 | TEST_ASSERT_EQUAL_UINT64(timestamp_last_event, last_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 895 | TEST_ASSERT_EQUAL_UINT32(id_last_event, last_event.id); |
kadonotakashi | 0:8fdf9a60065b | 896 | |
kadonotakashi | 0:8fdf9a60065b | 897 | // test the beginning of the range |
kadonotakashi | 0:8fdf9a60065b | 898 | ticker_event_t first_event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 899 | const us_timestamp_t timestamp_first_event = queue_stub.present_time + 1; |
kadonotakashi | 0:8fdf9a60065b | 900 | const uint32_t id_first_event = 0xAAAAAAAA; |
kadonotakashi | 0:8fdf9a60065b | 901 | |
kadonotakashi | 0:8fdf9a60065b | 902 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 903 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 904 | &first_event, timestamp_first_event, id_first_event |
kadonotakashi | 0:8fdf9a60065b | 905 | ); |
kadonotakashi | 0:8fdf9a60065b | 906 | |
kadonotakashi | 0:8fdf9a60065b | 907 | TEST_ASSERT_EQUAL_PTR(&first_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 908 | TEST_ASSERT_EQUAL(2, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 909 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 910 | timestamp_first_event, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 911 | ); |
kadonotakashi | 0:8fdf9a60065b | 912 | TEST_ASSERT_EQUAL_PTR(&last_event, queue_stub.head->next); |
kadonotakashi | 0:8fdf9a60065b | 913 | TEST_ASSERT_EQUAL_UINT64( |
kadonotakashi | 0:8fdf9a60065b | 914 | timestamp_first_event, first_event.timestamp |
kadonotakashi | 0:8fdf9a60065b | 915 | ); |
kadonotakashi | 0:8fdf9a60065b | 916 | TEST_ASSERT_EQUAL_UINT32(id_first_event, first_event.id); |
kadonotakashi | 0:8fdf9a60065b | 917 | |
kadonotakashi | 0:8fdf9a60065b | 918 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 919 | } |
kadonotakashi | 0:8fdf9a60065b | 920 | |
kadonotakashi | 0:8fdf9a60065b | 921 | /** |
kadonotakashi | 0:8fdf9a60065b | 922 | * Given an initialized ticker without user registered events. |
kadonotakashi | 0:8fdf9a60065b | 923 | * When an event is inserted with ticker_insert_event_us and a timestamp in the |
kadonotakashi | 0:8fdf9a60065b | 924 | * range [ticker_timestamp + TIMESTAMP_MAX_DELTA + 1 : UINT64_MAX [ |
kadonotakashi | 0:8fdf9a60065b | 925 | * Then |
kadonotakashi | 0:8fdf9a60065b | 926 | * - The event should be in the queue |
kadonotakashi | 0:8fdf9a60065b | 927 | * - The interrupt timestamp should be equal to TIMESTAMP_MAX_DELTA |
kadonotakashi | 0:8fdf9a60065b | 928 | * - The timestamp of the event should be equal to the timestamp in parameter. |
kadonotakashi | 0:8fdf9a60065b | 929 | * - The id of the event should be equal to the id passed in parameter. |
kadonotakashi | 0:8fdf9a60065b | 930 | */ |
kadonotakashi | 0:8fdf9a60065b | 931 | static void test_insert_event_us_in_overflow_range() |
kadonotakashi | 0:8fdf9a60065b | 932 | { |
kadonotakashi | 0:8fdf9a60065b | 933 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 934 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 935 | interface_stub.timestamp = 0xAAAAAAAA; |
kadonotakashi | 0:8fdf9a60065b | 936 | queue_stub.tick_last_read = interface_stub.timestamp; |
kadonotakashi | 0:8fdf9a60065b | 937 | queue_stub.present_time = 10ULL << 32 | interface_stub.timestamp; |
kadonotakashi | 0:8fdf9a60065b | 938 | |
kadonotakashi | 0:8fdf9a60065b | 939 | // test the end of the range |
kadonotakashi | 0:8fdf9a60065b | 940 | ticker_event_t last_event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 941 | const us_timestamp_t timestamp_last_event = UINT64_MAX; |
kadonotakashi | 0:8fdf9a60065b | 942 | const uint32_t id_last_event = 0xDEADDEAF; |
kadonotakashi | 0:8fdf9a60065b | 943 | |
kadonotakashi | 0:8fdf9a60065b | 944 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 945 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 946 | &last_event, timestamp_last_event, id_last_event |
kadonotakashi | 0:8fdf9a60065b | 947 | ); |
kadonotakashi | 0:8fdf9a60065b | 948 | |
kadonotakashi | 0:8fdf9a60065b | 949 | TEST_ASSERT_EQUAL_PTR(&last_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 950 | TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 951 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 952 | interface_stub.timestamp + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 953 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 954 | ); |
kadonotakashi | 0:8fdf9a60065b | 955 | TEST_ASSERT_EQUAL_PTR(NULL, queue_stub.head->next); |
kadonotakashi | 0:8fdf9a60065b | 956 | TEST_ASSERT_EQUAL_UINT64(timestamp_last_event, last_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 957 | TEST_ASSERT_EQUAL_UINT32(id_last_event, last_event.id); |
kadonotakashi | 0:8fdf9a60065b | 958 | |
kadonotakashi | 0:8fdf9a60065b | 959 | // test the beginning of the range |
kadonotakashi | 0:8fdf9a60065b | 960 | ++interface_stub.timestamp; |
kadonotakashi | 0:8fdf9a60065b | 961 | ++queue_stub.present_time; |
kadonotakashi | 0:8fdf9a60065b | 962 | |
kadonotakashi | 0:8fdf9a60065b | 963 | ticker_event_t first_event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 964 | const us_timestamp_t timestamp_first_event = |
kadonotakashi | 0:8fdf9a60065b | 965 | queue_stub.present_time + TIMESTAMP_MAX_DELTA + 1; |
kadonotakashi | 0:8fdf9a60065b | 966 | uint32_t id_first_event = 0xAAAAAAAA; |
kadonotakashi | 0:8fdf9a60065b | 967 | |
kadonotakashi | 0:8fdf9a60065b | 968 | ticker_insert_event_us(&ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 969 | &first_event, timestamp_first_event, id_first_event |
kadonotakashi | 0:8fdf9a60065b | 970 | ); |
kadonotakashi | 0:8fdf9a60065b | 971 | |
kadonotakashi | 0:8fdf9a60065b | 972 | TEST_ASSERT_EQUAL_PTR(&first_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 973 | TEST_ASSERT_EQUAL(2, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 974 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 975 | interface_stub.timestamp + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 976 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 977 | ); |
kadonotakashi | 0:8fdf9a60065b | 978 | TEST_ASSERT_EQUAL_PTR(&last_event, queue_stub.head->next); |
kadonotakashi | 0:8fdf9a60065b | 979 | TEST_ASSERT_EQUAL_UINT64(timestamp_first_event, first_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 980 | TEST_ASSERT_EQUAL_UINT32(id_first_event, first_event.id); |
kadonotakashi | 0:8fdf9a60065b | 981 | |
kadonotakashi | 0:8fdf9a60065b | 982 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 983 | } |
kadonotakashi | 0:8fdf9a60065b | 984 | |
kadonotakashi | 0:8fdf9a60065b | 985 | /** |
kadonotakashi | 0:8fdf9a60065b | 986 | * Given an initialized ticker without user registered events. |
kadonotakashi | 0:8fdf9a60065b | 987 | * When an event is inserted with ticker_insert_event_us and a timestamp less |
kadonotakashi | 0:8fdf9a60065b | 988 | * than timestamp value in the ticker interface. |
kadonotakashi | 0:8fdf9a60065b | 989 | * Then |
kadonotakashi | 0:8fdf9a60065b | 990 | * - The event should be in the queue |
kadonotakashi | 0:8fdf9a60065b | 991 | * - The interrupt timestamp should be set to interface_stub.timestamp so it |
kadonotakashi | 0:8fdf9a60065b | 992 | * is scheduled immediately. |
kadonotakashi | 0:8fdf9a60065b | 993 | */ |
kadonotakashi | 0:8fdf9a60065b | 994 | static void test_insert_event_us_underflow() |
kadonotakashi | 0:8fdf9a60065b | 995 | { |
kadonotakashi | 0:8fdf9a60065b | 996 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 997 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 998 | |
kadonotakashi | 0:8fdf9a60065b | 999 | interface_stub.timestamp = 0xAAAAAAAA; |
kadonotakashi | 0:8fdf9a60065b | 1000 | queue_stub.tick_last_read = interface_stub.timestamp; |
kadonotakashi | 0:8fdf9a60065b | 1001 | queue_stub.present_time = 10ULL << 32 | interface_stub.timestamp; |
kadonotakashi | 0:8fdf9a60065b | 1002 | |
kadonotakashi | 0:8fdf9a60065b | 1003 | // test the end of the range |
kadonotakashi | 0:8fdf9a60065b | 1004 | ticker_event_t event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 1005 | const timestamp_t expected_timestamp = queue_stub.present_time - 1; |
kadonotakashi | 0:8fdf9a60065b | 1006 | const uint32_t expected_id = 0xDEADDEAF; |
kadonotakashi | 0:8fdf9a60065b | 1007 | |
kadonotakashi | 0:8fdf9a60065b | 1008 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1009 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1010 | &event, expected_timestamp, expected_id |
kadonotakashi | 0:8fdf9a60065b | 1011 | ); |
kadonotakashi | 0:8fdf9a60065b | 1012 | |
kadonotakashi | 0:8fdf9a60065b | 1013 | TEST_ASSERT_EQUAL_PTR(&event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1014 | TEST_ASSERT_EQUAL(1, interface_stub.fire_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1015 | |
kadonotakashi | 0:8fdf9a60065b | 1016 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1017 | } |
kadonotakashi | 0:8fdf9a60065b | 1018 | |
kadonotakashi | 0:8fdf9a60065b | 1019 | /** |
kadonotakashi | 0:8fdf9a60065b | 1020 | * Given an initialized ticker. |
kadonotakashi | 0:8fdf9a60065b | 1021 | * When an event is inserted with ticker_insert_event_us and a timestamp less |
kadonotakashi | 0:8fdf9a60065b | 1022 | * than the one for the next scheduled timestamp. |
kadonotakashi | 0:8fdf9a60065b | 1023 | * Then |
kadonotakashi | 0:8fdf9a60065b | 1024 | * - The event inserted should be the first in the queue |
kadonotakashi | 0:8fdf9a60065b | 1025 | * - The interrupt timestamp should be equal to the timestamp of the event or |
kadonotakashi | 0:8fdf9a60065b | 1026 | * TIMESTAMP_MAX_DELTA if in the overflow range. |
kadonotakashi | 0:8fdf9a60065b | 1027 | * - The timestamp of the event should be equal to the timestamp in parameter. |
kadonotakashi | 0:8fdf9a60065b | 1028 | * - The id of the event should be equal to the id passed in parameter. |
kadonotakashi | 0:8fdf9a60065b | 1029 | * - Events in the queue should remained ordered by timestamp. |
kadonotakashi | 0:8fdf9a60065b | 1030 | */ |
kadonotakashi | 0:8fdf9a60065b | 1031 | static void test_insert_event_us_head() |
kadonotakashi | 0:8fdf9a60065b | 1032 | { |
kadonotakashi | 0:8fdf9a60065b | 1033 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 1034 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1035 | interface_stub.timestamp = 0xAAAAAAAA; |
kadonotakashi | 0:8fdf9a60065b | 1036 | queue_stub.tick_last_read = interface_stub.timestamp; |
kadonotakashi | 0:8fdf9a60065b | 1037 | queue_stub.present_time = 10ULL << 32 | interface_stub.timestamp; |
kadonotakashi | 0:8fdf9a60065b | 1038 | |
kadonotakashi | 0:8fdf9a60065b | 1039 | const us_timestamp_t timestamps[] = { |
kadonotakashi | 0:8fdf9a60065b | 1040 | UINT64_MAX, |
kadonotakashi | 0:8fdf9a60065b | 1041 | queue_stub.present_time + TIMESTAMP_MAX_DELTA + 1, |
kadonotakashi | 0:8fdf9a60065b | 1042 | queue_stub.present_time + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1043 | queue_stub.present_time + (TIMESTAMP_MAX_DELTA / 2), |
kadonotakashi | 0:8fdf9a60065b | 1044 | queue_stub.present_time + (TIMESTAMP_MAX_DELTA / 4), |
kadonotakashi | 0:8fdf9a60065b | 1045 | queue_stub.present_time + (TIMESTAMP_MAX_DELTA / 8), |
kadonotakashi | 0:8fdf9a60065b | 1046 | queue_stub.present_time + (TIMESTAMP_MAX_DELTA / 16), |
kadonotakashi | 0:8fdf9a60065b | 1047 | }; |
kadonotakashi | 0:8fdf9a60065b | 1048 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 1049 | |
kadonotakashi | 0:8fdf9a60065b | 1050 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 1051 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1052 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1053 | &events[i], timestamps[i], i |
kadonotakashi | 0:8fdf9a60065b | 1054 | ); |
kadonotakashi | 0:8fdf9a60065b | 1055 | |
kadonotakashi | 0:8fdf9a60065b | 1056 | TEST_ASSERT_EQUAL_PTR(&events[i], queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1057 | if ((timestamps[i] - queue_stub.present_time) < TIMESTAMP_MAX_DELTA) { |
kadonotakashi | 0:8fdf9a60065b | 1058 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1059 | timestamps[i], |
kadonotakashi | 0:8fdf9a60065b | 1060 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1061 | ); |
kadonotakashi | 0:8fdf9a60065b | 1062 | } else { |
kadonotakashi | 0:8fdf9a60065b | 1063 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1064 | queue_stub.present_time + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1065 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1066 | ); |
kadonotakashi | 0:8fdf9a60065b | 1067 | } |
kadonotakashi | 0:8fdf9a60065b | 1068 | |
kadonotakashi | 0:8fdf9a60065b | 1069 | TEST_ASSERT_EQUAL_UINT64(timestamps[i], events[i].timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1070 | TEST_ASSERT_EQUAL_UINT32(i, events[i].id); |
kadonotakashi | 0:8fdf9a60065b | 1071 | |
kadonotakashi | 0:8fdf9a60065b | 1072 | ticker_event_t *e = &events[i]; |
kadonotakashi | 0:8fdf9a60065b | 1073 | while (e) { |
kadonotakashi | 0:8fdf9a60065b | 1074 | TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1075 | if (e->next) { |
kadonotakashi | 0:8fdf9a60065b | 1076 | TEST_ASSERT_TRUE(e->id > e->next->id); |
kadonotakashi | 0:8fdf9a60065b | 1077 | TEST_ASSERT_TRUE(e->timestamp < e->next->timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1078 | } else { |
kadonotakashi | 0:8fdf9a60065b | 1079 | TEST_ASSERT_EQUAL_UINT32(0, e->id); |
kadonotakashi | 0:8fdf9a60065b | 1080 | } |
kadonotakashi | 0:8fdf9a60065b | 1081 | e = e->next; |
kadonotakashi | 0:8fdf9a60065b | 1082 | } |
kadonotakashi | 0:8fdf9a60065b | 1083 | } |
kadonotakashi | 0:8fdf9a60065b | 1084 | |
kadonotakashi | 0:8fdf9a60065b | 1085 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1086 | } |
kadonotakashi | 0:8fdf9a60065b | 1087 | |
kadonotakashi | 0:8fdf9a60065b | 1088 | /** |
kadonotakashi | 0:8fdf9a60065b | 1089 | * Given an initialized ticker. |
kadonotakashi | 0:8fdf9a60065b | 1090 | * When an event is inserted with ticker_insert_event_us and its timestamp is |
kadonotakashi | 0:8fdf9a60065b | 1091 | * bigger than the one of the last event in the queue. |
kadonotakashi | 0:8fdf9a60065b | 1092 | * Then |
kadonotakashi | 0:8fdf9a60065b | 1093 | * - The event inserted should be the last in the queue |
kadonotakashi | 0:8fdf9a60065b | 1094 | * - The interrupt timestamp should remains equal to the interrupt timestamp |
kadonotakashi | 0:8fdf9a60065b | 1095 | * of the head event . |
kadonotakashi | 0:8fdf9a60065b | 1096 | * - The timestamp of the event should reflect the timestamp requested. |
kadonotakashi | 0:8fdf9a60065b | 1097 | * - The id of the event should be equal to the id passed in parameter. |
kadonotakashi | 0:8fdf9a60065b | 1098 | * - Events in the queue should remained ordered by timestamp. |
kadonotakashi | 0:8fdf9a60065b | 1099 | */ |
kadonotakashi | 0:8fdf9a60065b | 1100 | static void test_insert_event_us_tail() |
kadonotakashi | 0:8fdf9a60065b | 1101 | { |
kadonotakashi | 0:8fdf9a60065b | 1102 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 1103 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1104 | |
kadonotakashi | 0:8fdf9a60065b | 1105 | const us_timestamp_t timestamps[] = { |
kadonotakashi | 0:8fdf9a60065b | 1106 | 0xA, |
kadonotakashi | 0:8fdf9a60065b | 1107 | (1ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1108 | (2ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1109 | (4ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1110 | (8ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1111 | (16ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1112 | (32ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1113 | (64ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1114 | }; |
kadonotakashi | 0:8fdf9a60065b | 1115 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 1116 | |
kadonotakashi | 0:8fdf9a60065b | 1117 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 1118 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1119 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1120 | &events[i], timestamps[i], i |
kadonotakashi | 0:8fdf9a60065b | 1121 | ); |
kadonotakashi | 0:8fdf9a60065b | 1122 | |
kadonotakashi | 0:8fdf9a60065b | 1123 | TEST_ASSERT_EQUAL_PTR(&events[0], queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1124 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1125 | timestamps[0], interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1126 | ); |
kadonotakashi | 0:8fdf9a60065b | 1127 | TEST_ASSERT_EQUAL_UINT64(timestamps[i], events[i].timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1128 | TEST_ASSERT_EQUAL_UINT32(i, events[i].id); |
kadonotakashi | 0:8fdf9a60065b | 1129 | |
kadonotakashi | 0:8fdf9a60065b | 1130 | ticker_event_t *e = queue_stub.head; |
kadonotakashi | 0:8fdf9a60065b | 1131 | while (e) { |
kadonotakashi | 0:8fdf9a60065b | 1132 | TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1133 | if (e->next) { |
kadonotakashi | 0:8fdf9a60065b | 1134 | TEST_ASSERT_TRUE(e->id < e->next->id); |
kadonotakashi | 0:8fdf9a60065b | 1135 | TEST_ASSERT_TRUE(e->timestamp < e->next->timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1136 | } else { |
kadonotakashi | 0:8fdf9a60065b | 1137 | TEST_ASSERT_EQUAL_UINT32(&events[i], e); |
kadonotakashi | 0:8fdf9a60065b | 1138 | } |
kadonotakashi | 0:8fdf9a60065b | 1139 | e = e->next; |
kadonotakashi | 0:8fdf9a60065b | 1140 | } |
kadonotakashi | 0:8fdf9a60065b | 1141 | } |
kadonotakashi | 0:8fdf9a60065b | 1142 | |
kadonotakashi | 0:8fdf9a60065b | 1143 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1144 | } |
kadonotakashi | 0:8fdf9a60065b | 1145 | |
kadonotakashi | 0:8fdf9a60065b | 1146 | /** |
kadonotakashi | 0:8fdf9a60065b | 1147 | * Given an initialized ticker. |
kadonotakashi | 0:8fdf9a60065b | 1148 | * When an event is inserted with ticker_insert_event_us. |
kadonotakashi | 0:8fdf9a60065b | 1149 | * Then |
kadonotakashi | 0:8fdf9a60065b | 1150 | * - The event inserted should be at the correct position in the queue |
kadonotakashi | 0:8fdf9a60065b | 1151 | * - The event queue should remain ordered by timestamp |
kadonotakashi | 0:8fdf9a60065b | 1152 | * - The interrupt timestamp should be equal to the interrupt timestamp |
kadonotakashi | 0:8fdf9a60065b | 1153 | * of the head event or TIMESTAMP_MAX_DELTA if the |
kadonotakashi | 0:8fdf9a60065b | 1154 | * timestamp is in the overflow range. |
kadonotakashi | 0:8fdf9a60065b | 1155 | * - The timestamp of the event should be equal to the timestamp parameter. |
kadonotakashi | 0:8fdf9a60065b | 1156 | * - The id of the event should be equal to the id passed in parameter. |
kadonotakashi | 0:8fdf9a60065b | 1157 | * - Events in the queue should remained ordered by timestamp. |
kadonotakashi | 0:8fdf9a60065b | 1158 | */ |
kadonotakashi | 0:8fdf9a60065b | 1159 | static void test_insert_event_us_multiple_random() |
kadonotakashi | 0:8fdf9a60065b | 1160 | { |
kadonotakashi | 0:8fdf9a60065b | 1161 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 1162 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1163 | |
kadonotakashi | 0:8fdf9a60065b | 1164 | const timestamp_t ref_timestamp = UINT32_MAX / 2; |
kadonotakashi | 0:8fdf9a60065b | 1165 | interface_stub.timestamp = ref_timestamp; |
kadonotakashi | 0:8fdf9a60065b | 1166 | |
kadonotakashi | 0:8fdf9a60065b | 1167 | // insert first event at the head of the queue |
kadonotakashi | 0:8fdf9a60065b | 1168 | ticker_event_t first_event; |
kadonotakashi | 0:8fdf9a60065b | 1169 | const us_timestamp_t first_event_timestamp = |
kadonotakashi | 0:8fdf9a60065b | 1170 | ref_timestamp + TIMESTAMP_MAX_DELTA + 100; |
kadonotakashi | 0:8fdf9a60065b | 1171 | |
kadonotakashi | 0:8fdf9a60065b | 1172 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1173 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1174 | &first_event, first_event_timestamp, (uint32_t) &first_event |
kadonotakashi | 0:8fdf9a60065b | 1175 | ); |
kadonotakashi | 0:8fdf9a60065b | 1176 | |
kadonotakashi | 0:8fdf9a60065b | 1177 | TEST_ASSERT_EQUAL_PTR(&first_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1178 | TEST_ASSERT_EQUAL_PTR(NULL, first_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1179 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1180 | ref_timestamp + TIMESTAMP_MAX_DELTA, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1181 | ); |
kadonotakashi | 0:8fdf9a60065b | 1182 | TEST_ASSERT_EQUAL_UINT64(first_event.timestamp, first_event_timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1183 | TEST_ASSERT_EQUAL_UINT32((uint32_t) &first_event, first_event.id); |
kadonotakashi | 0:8fdf9a60065b | 1184 | |
kadonotakashi | 0:8fdf9a60065b | 1185 | // insert second event at the tail of the queue |
kadonotakashi | 0:8fdf9a60065b | 1186 | ticker_event_t second_event; |
kadonotakashi | 0:8fdf9a60065b | 1187 | const us_timestamp_t second_event_timestamp = first_event_timestamp + 1; |
kadonotakashi | 0:8fdf9a60065b | 1188 | |
kadonotakashi | 0:8fdf9a60065b | 1189 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1190 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1191 | &second_event, second_event_timestamp, (uint32_t) &second_event |
kadonotakashi | 0:8fdf9a60065b | 1192 | ); |
kadonotakashi | 0:8fdf9a60065b | 1193 | |
kadonotakashi | 0:8fdf9a60065b | 1194 | TEST_ASSERT_EQUAL_PTR(&first_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1195 | TEST_ASSERT_EQUAL_PTR(&second_event, first_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1196 | TEST_ASSERT_EQUAL_PTR(NULL, second_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1197 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1198 | ref_timestamp + TIMESTAMP_MAX_DELTA, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1199 | ); |
kadonotakashi | 0:8fdf9a60065b | 1200 | TEST_ASSERT_EQUAL_UINT64(second_event_timestamp, second_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1201 | TEST_ASSERT_EQUAL_UINT32((uint32_t) &second_event, second_event.id); |
kadonotakashi | 0:8fdf9a60065b | 1202 | |
kadonotakashi | 0:8fdf9a60065b | 1203 | |
kadonotakashi | 0:8fdf9a60065b | 1204 | // insert third event at the head of the queue out the overflow zone |
kadonotakashi | 0:8fdf9a60065b | 1205 | ticker_event_t third_event; |
kadonotakashi | 0:8fdf9a60065b | 1206 | const us_timestamp_t third_event_timestamp = |
kadonotakashi | 0:8fdf9a60065b | 1207 | ref_timestamp + TIMESTAMP_MAX_DELTA - 100; |
kadonotakashi | 0:8fdf9a60065b | 1208 | |
kadonotakashi | 0:8fdf9a60065b | 1209 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1210 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1211 | &third_event, third_event_timestamp, (uint32_t) &third_event |
kadonotakashi | 0:8fdf9a60065b | 1212 | ); |
kadonotakashi | 0:8fdf9a60065b | 1213 | |
kadonotakashi | 0:8fdf9a60065b | 1214 | TEST_ASSERT_EQUAL_PTR(&third_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1215 | TEST_ASSERT_EQUAL_PTR(&first_event, third_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1216 | TEST_ASSERT_EQUAL_PTR(&second_event, first_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1217 | TEST_ASSERT_EQUAL_PTR(NULL, second_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1218 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1219 | third_event_timestamp, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1220 | ); |
kadonotakashi | 0:8fdf9a60065b | 1221 | TEST_ASSERT_EQUAL_UINT64(third_event_timestamp, third_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1222 | TEST_ASSERT_EQUAL_UINT32((uint32_t) &third_event, third_event.id); |
kadonotakashi | 0:8fdf9a60065b | 1223 | |
kadonotakashi | 0:8fdf9a60065b | 1224 | // insert fourth event right after the third event |
kadonotakashi | 0:8fdf9a60065b | 1225 | ticker_event_t fourth_event; |
kadonotakashi | 0:8fdf9a60065b | 1226 | const us_timestamp_t fourth_event_timestamp = third_event_timestamp + 50; |
kadonotakashi | 0:8fdf9a60065b | 1227 | |
kadonotakashi | 0:8fdf9a60065b | 1228 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1229 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1230 | &fourth_event, fourth_event_timestamp, (uint32_t) &fourth_event |
kadonotakashi | 0:8fdf9a60065b | 1231 | ); |
kadonotakashi | 0:8fdf9a60065b | 1232 | |
kadonotakashi | 0:8fdf9a60065b | 1233 | TEST_ASSERT_EQUAL_PTR(&third_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1234 | TEST_ASSERT_EQUAL_PTR(&fourth_event, third_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1235 | TEST_ASSERT_EQUAL_PTR(&first_event, fourth_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1236 | TEST_ASSERT_EQUAL_PTR(&second_event, first_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1237 | TEST_ASSERT_EQUAL_PTR(NULL, second_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1238 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1239 | third_event_timestamp, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1240 | ); |
kadonotakashi | 0:8fdf9a60065b | 1241 | TEST_ASSERT_EQUAL_UINT64(fourth_event_timestamp, fourth_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1242 | TEST_ASSERT_EQUAL_UINT32((uint32_t) &fourth_event, fourth_event.id); |
kadonotakashi | 0:8fdf9a60065b | 1243 | |
kadonotakashi | 0:8fdf9a60065b | 1244 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1245 | } |
kadonotakashi | 0:8fdf9a60065b | 1246 | |
kadonotakashi | 0:8fdf9a60065b | 1247 | /** |
kadonotakashi | 0:8fdf9a60065b | 1248 | * Given an initialized ticker with multiple events registered. |
kadonotakashi | 0:8fdf9a60065b | 1249 | * When the event at the tail of the queue is removed from the queue. |
kadonotakashi | 0:8fdf9a60065b | 1250 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 1251 | * - The event should not be in the queue. |
kadonotakashi | 0:8fdf9a60065b | 1252 | * - The events in the queue should remain ordered |
kadonotakashi | 0:8fdf9a60065b | 1253 | * - The interrupt timestamp should be unchanged. |
kadonotakashi | 0:8fdf9a60065b | 1254 | */ |
kadonotakashi | 0:8fdf9a60065b | 1255 | static void test_remove_event_tail() |
kadonotakashi | 0:8fdf9a60065b | 1256 | { |
kadonotakashi | 0:8fdf9a60065b | 1257 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 1258 | const us_timestamp_t timestamps[] = { |
kadonotakashi | 0:8fdf9a60065b | 1259 | 0xA, |
kadonotakashi | 0:8fdf9a60065b | 1260 | (1ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1261 | (2ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1262 | (4ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1263 | (8ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1264 | (16ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1265 | (32ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1266 | (64ULL << 32), |
kadonotakashi | 0:8fdf9a60065b | 1267 | }; |
kadonotakashi | 0:8fdf9a60065b | 1268 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 1269 | |
kadonotakashi | 0:8fdf9a60065b | 1270 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 1271 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1272 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1273 | &events[i], timestamps[i], i |
kadonotakashi | 0:8fdf9a60065b | 1274 | ); |
kadonotakashi | 0:8fdf9a60065b | 1275 | } |
kadonotakashi | 0:8fdf9a60065b | 1276 | |
kadonotakashi | 0:8fdf9a60065b | 1277 | for (ssize_t i = MBED_ARRAY_SIZE(events) - 1; i >= 0; --i) { |
kadonotakashi | 0:8fdf9a60065b | 1278 | ticker_remove_event(&ticker_stub, &events[i]); |
kadonotakashi | 0:8fdf9a60065b | 1279 | |
kadonotakashi | 0:8fdf9a60065b | 1280 | ticker_event_t *e = queue_stub.head; |
kadonotakashi | 0:8fdf9a60065b | 1281 | size_t event_count = 0; |
kadonotakashi | 0:8fdf9a60065b | 1282 | while (e) { |
kadonotakashi | 0:8fdf9a60065b | 1283 | TEST_ASSERT_NOT_EQUAL(e, &events[i]); |
kadonotakashi | 0:8fdf9a60065b | 1284 | if (e->next) { |
kadonotakashi | 0:8fdf9a60065b | 1285 | TEST_ASSERT_TRUE(e->timestamp <= e->next->timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1286 | } |
kadonotakashi | 0:8fdf9a60065b | 1287 | e = e->next; |
kadonotakashi | 0:8fdf9a60065b | 1288 | ++event_count; |
kadonotakashi | 0:8fdf9a60065b | 1289 | } |
kadonotakashi | 0:8fdf9a60065b | 1290 | |
kadonotakashi | 0:8fdf9a60065b | 1291 | TEST_ASSERT_EQUAL(i, event_count); |
kadonotakashi | 0:8fdf9a60065b | 1292 | |
kadonotakashi | 0:8fdf9a60065b | 1293 | if (i != 0) { |
kadonotakashi | 0:8fdf9a60065b | 1294 | TEST_ASSERT_EQUAL( |
kadonotakashi | 0:8fdf9a60065b | 1295 | timestamps[0], |
kadonotakashi | 0:8fdf9a60065b | 1296 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1297 | ); |
kadonotakashi | 0:8fdf9a60065b | 1298 | } else { |
kadonotakashi | 0:8fdf9a60065b | 1299 | TEST_ASSERT_EQUAL( |
kadonotakashi | 0:8fdf9a60065b | 1300 | interface_stub.timestamp + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1301 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1302 | ); |
kadonotakashi | 0:8fdf9a60065b | 1303 | } |
kadonotakashi | 0:8fdf9a60065b | 1304 | } |
kadonotakashi | 0:8fdf9a60065b | 1305 | |
kadonotakashi | 0:8fdf9a60065b | 1306 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1307 | } |
kadonotakashi | 0:8fdf9a60065b | 1308 | |
kadonotakashi | 0:8fdf9a60065b | 1309 | /** |
kadonotakashi | 0:8fdf9a60065b | 1310 | * Given an initialized ticker with multiple events registered. |
kadonotakashi | 0:8fdf9a60065b | 1311 | * When the event at the head of the queue is removed from the queue. |
kadonotakashi | 0:8fdf9a60065b | 1312 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 1313 | * - The event should not be in the queue. |
kadonotakashi | 0:8fdf9a60065b | 1314 | * - The event at the head of the queue should be the equal to the one |
kadonotakashi | 0:8fdf9a60065b | 1315 | * after the event removed. |
kadonotakashi | 0:8fdf9a60065b | 1316 | * - The interrupt timestamp should be equal to the interrupt timestamp |
kadonotakashi | 0:8fdf9a60065b | 1317 | * of the head event or TIMESTAMP_MAX_DELTA if the |
kadonotakashi | 0:8fdf9a60065b | 1318 | * timestamp is in the overflow range. |
kadonotakashi | 0:8fdf9a60065b | 1319 | */ |
kadonotakashi | 0:8fdf9a60065b | 1320 | static void test_remove_event_head() |
kadonotakashi | 0:8fdf9a60065b | 1321 | { |
kadonotakashi | 0:8fdf9a60065b | 1322 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 1323 | const us_timestamp_t timestamps[] = { |
kadonotakashi | 0:8fdf9a60065b | 1324 | TIMESTAMP_MAX_DELTA / 8, |
kadonotakashi | 0:8fdf9a60065b | 1325 | TIMESTAMP_MAX_DELTA / 4, |
kadonotakashi | 0:8fdf9a60065b | 1326 | TIMESTAMP_MAX_DELTA / 2, |
kadonotakashi | 0:8fdf9a60065b | 1327 | TIMESTAMP_MAX_DELTA - 1, |
kadonotakashi | 0:8fdf9a60065b | 1328 | TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1329 | TIMESTAMP_MAX_DELTA + 1, |
kadonotakashi | 0:8fdf9a60065b | 1330 | (1ULL << 32) | TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1331 | UINT64_MAX |
kadonotakashi | 0:8fdf9a60065b | 1332 | }; |
kadonotakashi | 0:8fdf9a60065b | 1333 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 1334 | |
kadonotakashi | 0:8fdf9a60065b | 1335 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 1336 | ticker_insert_event_us(&ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1337 | &events[i], timestamps[i], i |
kadonotakashi | 0:8fdf9a60065b | 1338 | ); |
kadonotakashi | 0:8fdf9a60065b | 1339 | } |
kadonotakashi | 0:8fdf9a60065b | 1340 | |
kadonotakashi | 0:8fdf9a60065b | 1341 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 1342 | ticker_remove_event(&ticker_stub, &events[i]); |
kadonotakashi | 0:8fdf9a60065b | 1343 | |
kadonotakashi | 0:8fdf9a60065b | 1344 | ticker_event_t *e = queue_stub.head; |
kadonotakashi | 0:8fdf9a60065b | 1345 | size_t event_count = 0; |
kadonotakashi | 0:8fdf9a60065b | 1346 | while (e) { |
kadonotakashi | 0:8fdf9a60065b | 1347 | TEST_ASSERT_NOT_EQUAL(e, &events[i]); |
kadonotakashi | 0:8fdf9a60065b | 1348 | if (e->next) { |
kadonotakashi | 0:8fdf9a60065b | 1349 | TEST_ASSERT_TRUE(e->timestamp <= e->next->timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1350 | } |
kadonotakashi | 0:8fdf9a60065b | 1351 | e = e->next; |
kadonotakashi | 0:8fdf9a60065b | 1352 | ++event_count; |
kadonotakashi | 0:8fdf9a60065b | 1353 | } |
kadonotakashi | 0:8fdf9a60065b | 1354 | |
kadonotakashi | 0:8fdf9a60065b | 1355 | TEST_ASSERT_EQUAL(MBED_ARRAY_SIZE(events) - i - 1, event_count); |
kadonotakashi | 0:8fdf9a60065b | 1356 | |
kadonotakashi | 0:8fdf9a60065b | 1357 | if (event_count) { |
kadonotakashi | 0:8fdf9a60065b | 1358 | TEST_ASSERT_EQUAL( |
kadonotakashi | 0:8fdf9a60065b | 1359 | std::min( |
kadonotakashi | 0:8fdf9a60065b | 1360 | timestamps[i + 1], |
kadonotakashi | 0:8fdf9a60065b | 1361 | interface_stub.timestamp + TIMESTAMP_MAX_DELTA |
kadonotakashi | 0:8fdf9a60065b | 1362 | ), |
kadonotakashi | 0:8fdf9a60065b | 1363 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1364 | ); |
kadonotakashi | 0:8fdf9a60065b | 1365 | } else { |
kadonotakashi | 0:8fdf9a60065b | 1366 | TEST_ASSERT_EQUAL( |
kadonotakashi | 0:8fdf9a60065b | 1367 | interface_stub.timestamp + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1368 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1369 | ); |
kadonotakashi | 0:8fdf9a60065b | 1370 | } |
kadonotakashi | 0:8fdf9a60065b | 1371 | |
kadonotakashi | 0:8fdf9a60065b | 1372 | } |
kadonotakashi | 0:8fdf9a60065b | 1373 | |
kadonotakashi | 0:8fdf9a60065b | 1374 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1375 | } |
kadonotakashi | 0:8fdf9a60065b | 1376 | |
kadonotakashi | 0:8fdf9a60065b | 1377 | /** |
kadonotakashi | 0:8fdf9a60065b | 1378 | * Given an initialized ticker with multiple events registered. |
kadonotakashi | 0:8fdf9a60065b | 1379 | * When an event not in the queue is attempted to be removed. |
kadonotakashi | 0:8fdf9a60065b | 1380 | * Then the queue should remains identical as before. |
kadonotakashi | 0:8fdf9a60065b | 1381 | */ |
kadonotakashi | 0:8fdf9a60065b | 1382 | static void test_remove_event_invalid() |
kadonotakashi | 0:8fdf9a60065b | 1383 | { |
kadonotakashi | 0:8fdf9a60065b | 1384 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 1385 | const us_timestamp_t timestamps[] = { |
kadonotakashi | 0:8fdf9a60065b | 1386 | TIMESTAMP_MAX_DELTA / 8, |
kadonotakashi | 0:8fdf9a60065b | 1387 | TIMESTAMP_MAX_DELTA / 4, |
kadonotakashi | 0:8fdf9a60065b | 1388 | TIMESTAMP_MAX_DELTA / 2, |
kadonotakashi | 0:8fdf9a60065b | 1389 | TIMESTAMP_MAX_DELTA - 1, |
kadonotakashi | 0:8fdf9a60065b | 1390 | TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1391 | TIMESTAMP_MAX_DELTA + 1, |
kadonotakashi | 0:8fdf9a60065b | 1392 | (1ULL << 32) | TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1393 | UINT64_MAX |
kadonotakashi | 0:8fdf9a60065b | 1394 | }; |
kadonotakashi | 0:8fdf9a60065b | 1395 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 1396 | |
kadonotakashi | 0:8fdf9a60065b | 1397 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 1398 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1399 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1400 | &events[i], timestamps[i], i |
kadonotakashi | 0:8fdf9a60065b | 1401 | ); |
kadonotakashi | 0:8fdf9a60065b | 1402 | } |
kadonotakashi | 0:8fdf9a60065b | 1403 | |
kadonotakashi | 0:8fdf9a60065b | 1404 | ticker_event_t invalid_event; |
kadonotakashi | 0:8fdf9a60065b | 1405 | ticker_remove_event(&ticker_stub, &invalid_event); |
kadonotakashi | 0:8fdf9a60065b | 1406 | |
kadonotakashi | 0:8fdf9a60065b | 1407 | TEST_ASSERT_EQUAL(&events[0], queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1408 | |
kadonotakashi | 0:8fdf9a60065b | 1409 | ticker_event_t *e = queue_stub.head; |
kadonotakashi | 0:8fdf9a60065b | 1410 | size_t event_count = 0; |
kadonotakashi | 0:8fdf9a60065b | 1411 | while (e) { |
kadonotakashi | 0:8fdf9a60065b | 1412 | TEST_ASSERT_EQUAL(e, &events[event_count]); |
kadonotakashi | 0:8fdf9a60065b | 1413 | e = e->next; |
kadonotakashi | 0:8fdf9a60065b | 1414 | ++event_count; |
kadonotakashi | 0:8fdf9a60065b | 1415 | } |
kadonotakashi | 0:8fdf9a60065b | 1416 | TEST_ASSERT_EQUAL(MBED_ARRAY_SIZE(events), event_count); |
kadonotakashi | 0:8fdf9a60065b | 1417 | } |
kadonotakashi | 0:8fdf9a60065b | 1418 | |
kadonotakashi | 0:8fdf9a60065b | 1419 | /** |
kadonotakashi | 0:8fdf9a60065b | 1420 | * Given an initialized ticker with multiple events inserted. |
kadonotakashi | 0:8fdf9a60065b | 1421 | * When an event is remoced |
kadonotakashi | 0:8fdf9a60065b | 1422 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 1423 | * - the event should not be in the queue |
kadonotakashi | 0:8fdf9a60065b | 1424 | * - the queue should remain ordered |
kadonotakashi | 0:8fdf9a60065b | 1425 | * - the interrupt timestamp should be set to either head->timestamp or |
kadonotakashi | 0:8fdf9a60065b | 1426 | * TIMESTAMP_MAX_DELTA depending on the distance between the current time |
kadonotakashi | 0:8fdf9a60065b | 1427 | * ans the timestamp of the event at the head of the queue. |
kadonotakashi | 0:8fdf9a60065b | 1428 | */ |
kadonotakashi | 0:8fdf9a60065b | 1429 | static void test_remove_random() |
kadonotakashi | 0:8fdf9a60065b | 1430 | { |
kadonotakashi | 0:8fdf9a60065b | 1431 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 1432 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1433 | |
kadonotakashi | 0:8fdf9a60065b | 1434 | const timestamp_t ref_timestamp = UINT32_MAX / 2; |
kadonotakashi | 0:8fdf9a60065b | 1435 | interface_stub.timestamp = ref_timestamp; |
kadonotakashi | 0:8fdf9a60065b | 1436 | |
kadonotakashi | 0:8fdf9a60065b | 1437 | // insert all events |
kadonotakashi | 0:8fdf9a60065b | 1438 | ticker_event_t first_event; |
kadonotakashi | 0:8fdf9a60065b | 1439 | const us_timestamp_t first_event_timestamp = |
kadonotakashi | 0:8fdf9a60065b | 1440 | ref_timestamp + TIMESTAMP_MAX_DELTA + 100; |
kadonotakashi | 0:8fdf9a60065b | 1441 | |
kadonotakashi | 0:8fdf9a60065b | 1442 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1443 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1444 | &first_event, first_event_timestamp, (uint32_t) &first_event |
kadonotakashi | 0:8fdf9a60065b | 1445 | ); |
kadonotakashi | 0:8fdf9a60065b | 1446 | |
kadonotakashi | 0:8fdf9a60065b | 1447 | |
kadonotakashi | 0:8fdf9a60065b | 1448 | ticker_event_t second_event; |
kadonotakashi | 0:8fdf9a60065b | 1449 | const us_timestamp_t second_event_timestamp = first_event_timestamp + 1; |
kadonotakashi | 0:8fdf9a60065b | 1450 | |
kadonotakashi | 0:8fdf9a60065b | 1451 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1452 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1453 | &second_event, second_event_timestamp, (uint32_t) &second_event |
kadonotakashi | 0:8fdf9a60065b | 1454 | ); |
kadonotakashi | 0:8fdf9a60065b | 1455 | |
kadonotakashi | 0:8fdf9a60065b | 1456 | ticker_event_t third_event; |
kadonotakashi | 0:8fdf9a60065b | 1457 | const us_timestamp_t third_event_timestamp = |
kadonotakashi | 0:8fdf9a60065b | 1458 | ref_timestamp + TIMESTAMP_MAX_DELTA - 100; |
kadonotakashi | 0:8fdf9a60065b | 1459 | |
kadonotakashi | 0:8fdf9a60065b | 1460 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1461 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1462 | &third_event, third_event_timestamp, (uint32_t) &third_event |
kadonotakashi | 0:8fdf9a60065b | 1463 | ); |
kadonotakashi | 0:8fdf9a60065b | 1464 | |
kadonotakashi | 0:8fdf9a60065b | 1465 | ticker_event_t fourth_event; |
kadonotakashi | 0:8fdf9a60065b | 1466 | const us_timestamp_t fourth_event_timestamp = third_event_timestamp + 50; |
kadonotakashi | 0:8fdf9a60065b | 1467 | |
kadonotakashi | 0:8fdf9a60065b | 1468 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1469 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1470 | &fourth_event, fourth_event_timestamp, (uint32_t) &fourth_event |
kadonotakashi | 0:8fdf9a60065b | 1471 | ); |
kadonotakashi | 0:8fdf9a60065b | 1472 | |
kadonotakashi | 0:8fdf9a60065b | 1473 | // test that the queue is in the correct state |
kadonotakashi | 0:8fdf9a60065b | 1474 | TEST_ASSERT_EQUAL_PTR(&third_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1475 | TEST_ASSERT_EQUAL_PTR(&fourth_event, third_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1476 | TEST_ASSERT_EQUAL_PTR(&first_event, fourth_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1477 | TEST_ASSERT_EQUAL_PTR(&second_event, first_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1478 | TEST_ASSERT_EQUAL_PTR(NULL, second_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1479 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1480 | third_event_timestamp, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1481 | ); |
kadonotakashi | 0:8fdf9a60065b | 1482 | TEST_ASSERT_EQUAL_UINT64(fourth_event_timestamp, fourth_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1483 | TEST_ASSERT_EQUAL_UINT32((uint32_t) &fourth_event, fourth_event.id); |
kadonotakashi | 0:8fdf9a60065b | 1484 | |
kadonotakashi | 0:8fdf9a60065b | 1485 | // remove fourth event |
kadonotakashi | 0:8fdf9a60065b | 1486 | ticker_remove_event(&ticker_stub, &fourth_event); |
kadonotakashi | 0:8fdf9a60065b | 1487 | |
kadonotakashi | 0:8fdf9a60065b | 1488 | TEST_ASSERT_EQUAL_PTR(&third_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1489 | TEST_ASSERT_EQUAL_PTR(&first_event, third_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1490 | TEST_ASSERT_EQUAL_PTR(&second_event, first_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1491 | TEST_ASSERT_EQUAL_PTR(NULL, second_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1492 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1493 | third_event_timestamp, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1494 | ); |
kadonotakashi | 0:8fdf9a60065b | 1495 | TEST_ASSERT_EQUAL_UINT64(third_event_timestamp, third_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1496 | TEST_ASSERT_EQUAL_UINT32((uint32_t) &third_event, third_event.id); |
kadonotakashi | 0:8fdf9a60065b | 1497 | |
kadonotakashi | 0:8fdf9a60065b | 1498 | // remove third event |
kadonotakashi | 0:8fdf9a60065b | 1499 | ticker_remove_event(&ticker_stub, &third_event); |
kadonotakashi | 0:8fdf9a60065b | 1500 | |
kadonotakashi | 0:8fdf9a60065b | 1501 | TEST_ASSERT_EQUAL_PTR(&first_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1502 | TEST_ASSERT_EQUAL_PTR(&second_event, first_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1503 | TEST_ASSERT_EQUAL_PTR(NULL, second_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1504 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1505 | ref_timestamp + TIMESTAMP_MAX_DELTA, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1506 | ); |
kadonotakashi | 0:8fdf9a60065b | 1507 | TEST_ASSERT_EQUAL_UINT64(second_event_timestamp, second_event.timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1508 | TEST_ASSERT_EQUAL_UINT32((uint32_t) &second_event, second_event.id); |
kadonotakashi | 0:8fdf9a60065b | 1509 | |
kadonotakashi | 0:8fdf9a60065b | 1510 | // remove second event |
kadonotakashi | 0:8fdf9a60065b | 1511 | ticker_remove_event(&ticker_stub, &second_event); |
kadonotakashi | 0:8fdf9a60065b | 1512 | |
kadonotakashi | 0:8fdf9a60065b | 1513 | TEST_ASSERT_EQUAL_PTR(&first_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1514 | TEST_ASSERT_EQUAL_PTR(NULL, first_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1515 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1516 | ref_timestamp + TIMESTAMP_MAX_DELTA, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1517 | ); |
kadonotakashi | 0:8fdf9a60065b | 1518 | TEST_ASSERT_EQUAL_UINT64(first_event.timestamp, first_event_timestamp); |
kadonotakashi | 0:8fdf9a60065b | 1519 | TEST_ASSERT_EQUAL_UINT32((uint32_t) &first_event, first_event.id); |
kadonotakashi | 0:8fdf9a60065b | 1520 | |
kadonotakashi | 0:8fdf9a60065b | 1521 | // remove first event |
kadonotakashi | 0:8fdf9a60065b | 1522 | ticker_remove_event(&ticker_stub, &first_event); |
kadonotakashi | 0:8fdf9a60065b | 1523 | |
kadonotakashi | 0:8fdf9a60065b | 1524 | TEST_ASSERT_EQUAL_PTR(NULL, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1525 | TEST_ASSERT_EQUAL_PTR(NULL, first_event.next); |
kadonotakashi | 0:8fdf9a60065b | 1526 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1527 | ref_timestamp + TIMESTAMP_MAX_DELTA, interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1528 | ); |
kadonotakashi | 0:8fdf9a60065b | 1529 | |
kadonotakashi | 0:8fdf9a60065b | 1530 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1531 | } |
kadonotakashi | 0:8fdf9a60065b | 1532 | |
kadonotakashi | 0:8fdf9a60065b | 1533 | /** |
kadonotakashi | 0:8fdf9a60065b | 1534 | * Given an initialized ticker without user registered events and a ticker |
kadonotakashi | 0:8fdf9a60065b | 1535 | * interface timestamp equal or bigger than the one registered by the overflow |
kadonotakashi | 0:8fdf9a60065b | 1536 | * event. |
kadonotakashi | 0:8fdf9a60065b | 1537 | * When the interrupt handler is called. |
kadonotakashi | 0:8fdf9a60065b | 1538 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 1539 | * - The interrupt timestamp should be updated to the timestamp of the ticker |
kadonotakashi | 0:8fdf9a60065b | 1540 | * interface plus TIMESTAMP_MAX_DELTA. |
kadonotakashi | 0:8fdf9a60065b | 1541 | * - The irq handler registered should not be called. |
kadonotakashi | 0:8fdf9a60065b | 1542 | */ |
kadonotakashi | 0:8fdf9a60065b | 1543 | static void test_overflow_event_update() |
kadonotakashi | 0:8fdf9a60065b | 1544 | { |
kadonotakashi | 0:8fdf9a60065b | 1545 | static uint32_t handler_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1546 | struct irq_handler_stub_t { |
kadonotakashi | 0:8fdf9a60065b | 1547 | static void event_handler(uint32_t id) |
kadonotakashi | 0:8fdf9a60065b | 1548 | { |
kadonotakashi | 0:8fdf9a60065b | 1549 | ++handler_call; |
kadonotakashi | 0:8fdf9a60065b | 1550 | } |
kadonotakashi | 0:8fdf9a60065b | 1551 | }; |
kadonotakashi | 0:8fdf9a60065b | 1552 | handler_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1553 | |
kadonotakashi | 0:8fdf9a60065b | 1554 | ticker_set_handler(&ticker_stub, irq_handler_stub_t::event_handler); |
kadonotakashi | 0:8fdf9a60065b | 1555 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1556 | |
kadonotakashi | 0:8fdf9a60065b | 1557 | for (size_t i = 0; i < 8; ++i) { |
kadonotakashi | 0:8fdf9a60065b | 1558 | us_timestamp_t previous_timestamp = queue_stub.present_time; |
kadonotakashi | 0:8fdf9a60065b | 1559 | timestamp_t interface_timestamp = |
kadonotakashi | 0:8fdf9a60065b | 1560 | previous_timestamp + (TIMESTAMP_MAX_DELTA + i * 100); |
kadonotakashi | 0:8fdf9a60065b | 1561 | interface_stub.timestamp = interface_timestamp; |
kadonotakashi | 0:8fdf9a60065b | 1562 | |
kadonotakashi | 0:8fdf9a60065b | 1563 | ticker_irq_handler(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 1564 | TEST_ASSERT_EQUAL(i + 1, interface_stub.clear_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1565 | |
kadonotakashi | 0:8fdf9a60065b | 1566 | TEST_ASSERT_EQUAL(i + 1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1567 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1568 | interface_timestamp + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1569 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1570 | ); |
kadonotakashi | 0:8fdf9a60065b | 1571 | TEST_ASSERT_EQUAL(0, handler_call); |
kadonotakashi | 0:8fdf9a60065b | 1572 | } |
kadonotakashi | 0:8fdf9a60065b | 1573 | |
kadonotakashi | 0:8fdf9a60065b | 1574 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1575 | } |
kadonotakashi | 0:8fdf9a60065b | 1576 | |
kadonotakashi | 0:8fdf9a60065b | 1577 | /** |
kadonotakashi | 0:8fdf9a60065b | 1578 | * Given an initialized ticker without user registered events and a ticker |
kadonotakashi | 0:8fdf9a60065b | 1579 | * interface timestamp less than the one registered to handle overflow. |
kadonotakashi | 0:8fdf9a60065b | 1580 | * When the interrupt handler is called. |
kadonotakashi | 0:8fdf9a60065b | 1581 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 1582 | * - The interrupt timestamp should be updated to the timestamp of the ticker |
kadonotakashi | 0:8fdf9a60065b | 1583 | * interface plus TIMESTAMP_MAX_DELTA. |
kadonotakashi | 0:8fdf9a60065b | 1584 | * - The irq handler registered should not be called. |
kadonotakashi | 0:8fdf9a60065b | 1585 | */ |
kadonotakashi | 0:8fdf9a60065b | 1586 | static void test_overflow_event_update_when_spurious_interrupt() |
kadonotakashi | 0:8fdf9a60065b | 1587 | { |
kadonotakashi | 0:8fdf9a60065b | 1588 | static uint32_t handler_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1589 | struct irq_handler_stub_t { |
kadonotakashi | 0:8fdf9a60065b | 1590 | static void event_handler(uint32_t id) |
kadonotakashi | 0:8fdf9a60065b | 1591 | { |
kadonotakashi | 0:8fdf9a60065b | 1592 | ++handler_call; |
kadonotakashi | 0:8fdf9a60065b | 1593 | } |
kadonotakashi | 0:8fdf9a60065b | 1594 | }; |
kadonotakashi | 0:8fdf9a60065b | 1595 | handler_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1596 | |
kadonotakashi | 0:8fdf9a60065b | 1597 | ticker_set_handler(&ticker_stub, irq_handler_stub_t::event_handler); |
kadonotakashi | 0:8fdf9a60065b | 1598 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1599 | |
kadonotakashi | 0:8fdf9a60065b | 1600 | for (size_t i = 0; i < 8; ++i) { |
kadonotakashi | 0:8fdf9a60065b | 1601 | us_timestamp_t previous_timestamp = queue_stub.present_time; |
kadonotakashi | 0:8fdf9a60065b | 1602 | timestamp_t interface_timestamp = |
kadonotakashi | 0:8fdf9a60065b | 1603 | previous_timestamp + (TIMESTAMP_MAX_DELTA / (2 + i)); |
kadonotakashi | 0:8fdf9a60065b | 1604 | interface_stub.timestamp = interface_timestamp; |
kadonotakashi | 0:8fdf9a60065b | 1605 | |
kadonotakashi | 0:8fdf9a60065b | 1606 | ticker_irq_handler(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 1607 | |
kadonotakashi | 0:8fdf9a60065b | 1608 | TEST_ASSERT_EQUAL(i + 1, interface_stub.clear_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1609 | TEST_ASSERT_EQUAL(i + 1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1610 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1611 | interface_timestamp + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1612 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1613 | ); |
kadonotakashi | 0:8fdf9a60065b | 1614 | TEST_ASSERT_EQUAL(0, handler_call); |
kadonotakashi | 0:8fdf9a60065b | 1615 | } |
kadonotakashi | 0:8fdf9a60065b | 1616 | |
kadonotakashi | 0:8fdf9a60065b | 1617 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1618 | } |
kadonotakashi | 0:8fdf9a60065b | 1619 | |
kadonotakashi | 0:8fdf9a60065b | 1620 | /** |
kadonotakashi | 0:8fdf9a60065b | 1621 | * Given an initialized ticker with a single ticker event inserted and a ticker |
kadonotakashi | 0:8fdf9a60065b | 1622 | * interface timestamp bigger than the one set for interrupt. |
kadonotakashi | 0:8fdf9a60065b | 1623 | * When ticker_irq_handler is called. |
kadonotakashi | 0:8fdf9a60065b | 1624 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 1625 | * - The IRQ handler should be called with the id of the event at the head of |
kadonotakashi | 0:8fdf9a60065b | 1626 | * the queue. |
kadonotakashi | 0:8fdf9a60065b | 1627 | * - The event at the head of the queue should be replaced by the next event. |
kadonotakashi | 0:8fdf9a60065b | 1628 | * - The interrupt timestamp in the ticker interface should be set to the |
kadonotakashi | 0:8fdf9a60065b | 1629 | * value of the interface timestamp + TIMESTAMP_MAX_DELTA |
kadonotakashi | 0:8fdf9a60065b | 1630 | */ |
kadonotakashi | 0:8fdf9a60065b | 1631 | static void test_irq_handler_single_event() |
kadonotakashi | 0:8fdf9a60065b | 1632 | { |
kadonotakashi | 0:8fdf9a60065b | 1633 | static const timestamp_t event_timestamp = 0xAAAAAAAA; |
kadonotakashi | 0:8fdf9a60065b | 1634 | static const timestamp_t interface_timestamp_after_irq = event_timestamp + 100; |
kadonotakashi | 0:8fdf9a60065b | 1635 | |
kadonotakashi | 0:8fdf9a60065b | 1636 | uint32_t handler_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1637 | struct irq_handler_stub_t { |
kadonotakashi | 0:8fdf9a60065b | 1638 | static void event_handler(uint32_t id) |
kadonotakashi | 0:8fdf9a60065b | 1639 | { |
kadonotakashi | 0:8fdf9a60065b | 1640 | ++ (*((uint32_t *) id)); |
kadonotakashi | 0:8fdf9a60065b | 1641 | interface_stub.timestamp = interface_timestamp_after_irq; |
kadonotakashi | 0:8fdf9a60065b | 1642 | } |
kadonotakashi | 0:8fdf9a60065b | 1643 | }; |
kadonotakashi | 0:8fdf9a60065b | 1644 | |
kadonotakashi | 0:8fdf9a60065b | 1645 | ticker_set_handler(&ticker_stub, irq_handler_stub_t::event_handler); |
kadonotakashi | 0:8fdf9a60065b | 1646 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1647 | |
kadonotakashi | 0:8fdf9a60065b | 1648 | ticker_event_t e; |
kadonotakashi | 0:8fdf9a60065b | 1649 | ticker_insert_event(&ticker_stub, &e, event_timestamp, (uint32_t) &handler_call); |
kadonotakashi | 0:8fdf9a60065b | 1650 | |
kadonotakashi | 0:8fdf9a60065b | 1651 | interface_stub.timestamp = event_timestamp; |
kadonotakashi | 0:8fdf9a60065b | 1652 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1653 | |
kadonotakashi | 0:8fdf9a60065b | 1654 | ticker_irq_handler(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 1655 | |
kadonotakashi | 0:8fdf9a60065b | 1656 | TEST_ASSERT_EQUAL(1, interface_stub.clear_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1657 | TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1658 | TEST_ASSERT_EQUAL(1, handler_call); |
kadonotakashi | 0:8fdf9a60065b | 1659 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1660 | interface_timestamp_after_irq + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1661 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1662 | ); |
kadonotakashi | 0:8fdf9a60065b | 1663 | |
kadonotakashi | 0:8fdf9a60065b | 1664 | TEST_ASSERT_NULL(queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1665 | |
kadonotakashi | 0:8fdf9a60065b | 1666 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1667 | } |
kadonotakashi | 0:8fdf9a60065b | 1668 | |
kadonotakashi | 0:8fdf9a60065b | 1669 | /** |
kadonotakashi | 0:8fdf9a60065b | 1670 | * Given an initialized ticker with at least a ticker event inserted and a ticker |
kadonotakashi | 0:8fdf9a60065b | 1671 | * interface timestamp less than the one set for interrupt. |
kadonotakashi | 0:8fdf9a60065b | 1672 | * When ticker_irq_handler is called. |
kadonotakashi | 0:8fdf9a60065b | 1673 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 1674 | * - The IRQ handler should not be called. |
kadonotakashi | 0:8fdf9a60065b | 1675 | * - The event at the head of the queue should remains the same. |
kadonotakashi | 0:8fdf9a60065b | 1676 | * - The interrupt timestamp in the ticker interface should be set to the |
kadonotakashi | 0:8fdf9a60065b | 1677 | * value of the event timestamp |
kadonotakashi | 0:8fdf9a60065b | 1678 | */ |
kadonotakashi | 0:8fdf9a60065b | 1679 | static void test_irq_handler_single_event_spurious() |
kadonotakashi | 0:8fdf9a60065b | 1680 | { |
kadonotakashi | 0:8fdf9a60065b | 1681 | struct irq_handler_stub_t { |
kadonotakashi | 0:8fdf9a60065b | 1682 | static void event_handler(uint32_t id) |
kadonotakashi | 0:8fdf9a60065b | 1683 | { |
kadonotakashi | 0:8fdf9a60065b | 1684 | TEST_FAIL(); |
kadonotakashi | 0:8fdf9a60065b | 1685 | } |
kadonotakashi | 0:8fdf9a60065b | 1686 | }; |
kadonotakashi | 0:8fdf9a60065b | 1687 | |
kadonotakashi | 0:8fdf9a60065b | 1688 | ticker_set_handler(&ticker_stub, irq_handler_stub_t::event_handler); |
kadonotakashi | 0:8fdf9a60065b | 1689 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1690 | |
kadonotakashi | 0:8fdf9a60065b | 1691 | const us_timestamp_t timestamps [] = { |
kadonotakashi | 0:8fdf9a60065b | 1692 | UINT32_MAX, |
kadonotakashi | 0:8fdf9a60065b | 1693 | TIMESTAMP_MAX_DELTA + 1, |
kadonotakashi | 0:8fdf9a60065b | 1694 | TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1695 | TIMESTAMP_MAX_DELTA - 1 |
kadonotakashi | 0:8fdf9a60065b | 1696 | }; |
kadonotakashi | 0:8fdf9a60065b | 1697 | |
kadonotakashi | 0:8fdf9a60065b | 1698 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 1699 | |
kadonotakashi | 0:8fdf9a60065b | 1700 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 1701 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1702 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1703 | &events[i], timestamps[i], timestamps[i] |
kadonotakashi | 0:8fdf9a60065b | 1704 | ); |
kadonotakashi | 0:8fdf9a60065b | 1705 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1706 | interface_stub.clear_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1707 | |
kadonotakashi | 0:8fdf9a60065b | 1708 | ticker_irq_handler(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 1709 | |
kadonotakashi | 0:8fdf9a60065b | 1710 | TEST_ASSERT_EQUAL(1, interface_stub.clear_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1711 | TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1712 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1713 | std::min(timestamps[i], TIMESTAMP_MAX_DELTA), |
kadonotakashi | 0:8fdf9a60065b | 1714 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1715 | ); |
kadonotakashi | 0:8fdf9a60065b | 1716 | } |
kadonotakashi | 0:8fdf9a60065b | 1717 | |
kadonotakashi | 0:8fdf9a60065b | 1718 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1719 | } |
kadonotakashi | 0:8fdf9a60065b | 1720 | |
kadonotakashi | 0:8fdf9a60065b | 1721 | /** |
kadonotakashi | 0:8fdf9a60065b | 1722 | * Given an initialized ticker with multiple ticker event inserted, its |
kadonotakashi | 0:8fdf9a60065b | 1723 | * interface timestamp at greater than the timestamp of the next schedule event |
kadonotakashi | 0:8fdf9a60065b | 1724 | * and all event execution time taking at least the time befor ethe next event. |
kadonotakashi | 0:8fdf9a60065b | 1725 | * When ticker_irq_handler is called. |
kadonotakashi | 0:8fdf9a60065b | 1726 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 1727 | * - The IRQ handler should have been called for every event. |
kadonotakashi | 0:8fdf9a60065b | 1728 | * - The head of the queue should be set to NULL. |
kadonotakashi | 0:8fdf9a60065b | 1729 | * - The interrupt timestamp in the ticker interface should be scheduled in |
kadonotakashi | 0:8fdf9a60065b | 1730 | * TIMESTAMP_MAX_DELTAs |
kadonotakashi | 0:8fdf9a60065b | 1731 | */ |
kadonotakashi | 0:8fdf9a60065b | 1732 | static void test_irq_handler_multiple_event_multiple_dequeue() |
kadonotakashi | 0:8fdf9a60065b | 1733 | { |
kadonotakashi | 0:8fdf9a60065b | 1734 | const us_timestamp_t timestamps [] = { |
kadonotakashi | 0:8fdf9a60065b | 1735 | 10, |
kadonotakashi | 0:8fdf9a60065b | 1736 | 10 + TIMESTAMP_MAX_DELTA - 1, |
kadonotakashi | 0:8fdf9a60065b | 1737 | 10 + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1738 | 10 + TIMESTAMP_MAX_DELTA + 1, |
kadonotakashi | 0:8fdf9a60065b | 1739 | UINT32_MAX |
kadonotakashi | 0:8fdf9a60065b | 1740 | }; |
kadonotakashi | 0:8fdf9a60065b | 1741 | |
kadonotakashi | 0:8fdf9a60065b | 1742 | static size_t handler_called = 0; |
kadonotakashi | 0:8fdf9a60065b | 1743 | struct irq_handler_stub_t { |
kadonotakashi | 0:8fdf9a60065b | 1744 | static void event_handler(uint32_t id) |
kadonotakashi | 0:8fdf9a60065b | 1745 | { |
kadonotakashi | 0:8fdf9a60065b | 1746 | ++handler_called; |
kadonotakashi | 0:8fdf9a60065b | 1747 | ticker_event_t *e = (ticker_event_t *) id; |
kadonotakashi | 0:8fdf9a60065b | 1748 | if (e->next) { |
kadonotakashi | 0:8fdf9a60065b | 1749 | interface_stub.timestamp = e->next->timestamp; |
kadonotakashi | 0:8fdf9a60065b | 1750 | } |
kadonotakashi | 0:8fdf9a60065b | 1751 | } |
kadonotakashi | 0:8fdf9a60065b | 1752 | }; |
kadonotakashi | 0:8fdf9a60065b | 1753 | handler_called = 0; |
kadonotakashi | 0:8fdf9a60065b | 1754 | |
kadonotakashi | 0:8fdf9a60065b | 1755 | ticker_set_handler(&ticker_stub, irq_handler_stub_t::event_handler); |
kadonotakashi | 0:8fdf9a60065b | 1756 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1757 | |
kadonotakashi | 0:8fdf9a60065b | 1758 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 1759 | |
kadonotakashi | 0:8fdf9a60065b | 1760 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 1761 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1762 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1763 | &events[i], timestamps[i], (uint32_t) &events[i] |
kadonotakashi | 0:8fdf9a60065b | 1764 | ); |
kadonotakashi | 0:8fdf9a60065b | 1765 | } |
kadonotakashi | 0:8fdf9a60065b | 1766 | |
kadonotakashi | 0:8fdf9a60065b | 1767 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1768 | interface_stub.clear_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1769 | interface_stub.timestamp = timestamps[0]; |
kadonotakashi | 0:8fdf9a60065b | 1770 | |
kadonotakashi | 0:8fdf9a60065b | 1771 | ticker_irq_handler(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 1772 | |
kadonotakashi | 0:8fdf9a60065b | 1773 | TEST_ASSERT_EQUAL(1, interface_stub.clear_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1774 | TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1775 | TEST_ASSERT_EQUAL_UINT32(MBED_ARRAY_SIZE(timestamps), handler_called); |
kadonotakashi | 0:8fdf9a60065b | 1776 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1777 | timestamps[MBED_ARRAY_SIZE(timestamps) - 1] + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1778 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1779 | ); |
kadonotakashi | 0:8fdf9a60065b | 1780 | TEST_ASSERT_NULL(queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1781 | |
kadonotakashi | 0:8fdf9a60065b | 1782 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1783 | } |
kadonotakashi | 0:8fdf9a60065b | 1784 | |
kadonotakashi | 0:8fdf9a60065b | 1785 | /** |
kadonotakashi | 0:8fdf9a60065b | 1786 | * Given an initialized ticker with two ticker event inserted scheduled from more |
kadonotakashi | 0:8fdf9a60065b | 1787 | * than TIMESTAMP_MAX_DELTA from one another. The interface |
kadonotakashi | 0:8fdf9a60065b | 1788 | * timestamp is equal to the timestamp of the first event. |
kadonotakashi | 0:8fdf9a60065b | 1789 | * When ticker_irq_handler is called. |
kadonotakashi | 0:8fdf9a60065b | 1790 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 1791 | * - The IRQ handler should have been called for the first event. |
kadonotakashi | 0:8fdf9a60065b | 1792 | * - The head of the queue should be set to the event after the first event. |
kadonotakashi | 0:8fdf9a60065b | 1793 | * - The interrupt timestamp in the ticker interface should be scheduled in |
kadonotakashi | 0:8fdf9a60065b | 1794 | * TIMESTAMP_MAX_DELTA. |
kadonotakashi | 0:8fdf9a60065b | 1795 | */ |
kadonotakashi | 0:8fdf9a60065b | 1796 | static void test_irq_handler_multiple_event_single_dequeue_overflow() |
kadonotakashi | 0:8fdf9a60065b | 1797 | { |
kadonotakashi | 0:8fdf9a60065b | 1798 | const us_timestamp_t timestamps [] = { |
kadonotakashi | 0:8fdf9a60065b | 1799 | 10, |
kadonotakashi | 0:8fdf9a60065b | 1800 | 10 + TIMESTAMP_MAX_DELTA + 1 |
kadonotakashi | 0:8fdf9a60065b | 1801 | }; |
kadonotakashi | 0:8fdf9a60065b | 1802 | |
kadonotakashi | 0:8fdf9a60065b | 1803 | size_t handler_called = 0; |
kadonotakashi | 0:8fdf9a60065b | 1804 | struct irq_handler_stub_t { |
kadonotakashi | 0:8fdf9a60065b | 1805 | static void event_handler(uint32_t id) |
kadonotakashi | 0:8fdf9a60065b | 1806 | { |
kadonotakashi | 0:8fdf9a60065b | 1807 | ++ (*((size_t *) id)); |
kadonotakashi | 0:8fdf9a60065b | 1808 | } |
kadonotakashi | 0:8fdf9a60065b | 1809 | }; |
kadonotakashi | 0:8fdf9a60065b | 1810 | |
kadonotakashi | 0:8fdf9a60065b | 1811 | ticker_set_handler(&ticker_stub, irq_handler_stub_t::event_handler); |
kadonotakashi | 0:8fdf9a60065b | 1812 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1813 | |
kadonotakashi | 0:8fdf9a60065b | 1814 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 1815 | |
kadonotakashi | 0:8fdf9a60065b | 1816 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 1817 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1818 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1819 | &events[i], timestamps[i], (uint32_t) &handler_called |
kadonotakashi | 0:8fdf9a60065b | 1820 | ); |
kadonotakashi | 0:8fdf9a60065b | 1821 | } |
kadonotakashi | 0:8fdf9a60065b | 1822 | |
kadonotakashi | 0:8fdf9a60065b | 1823 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1824 | interface_stub.clear_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1825 | interface_stub.timestamp = timestamps[0]; |
kadonotakashi | 0:8fdf9a60065b | 1826 | |
kadonotakashi | 0:8fdf9a60065b | 1827 | ticker_irq_handler(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 1828 | |
kadonotakashi | 0:8fdf9a60065b | 1829 | TEST_ASSERT_EQUAL(1, interface_stub.clear_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1830 | TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1831 | TEST_ASSERT_EQUAL_UINT32(1, handler_called); |
kadonotakashi | 0:8fdf9a60065b | 1832 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1833 | timestamps[0] + TIMESTAMP_MAX_DELTA, |
kadonotakashi | 0:8fdf9a60065b | 1834 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1835 | ); |
kadonotakashi | 0:8fdf9a60065b | 1836 | TEST_ASSERT_EQUAL_PTR(&events[1], queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1837 | |
kadonotakashi | 0:8fdf9a60065b | 1838 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1839 | } |
kadonotakashi | 0:8fdf9a60065b | 1840 | |
kadonotakashi | 0:8fdf9a60065b | 1841 | /** |
kadonotakashi | 0:8fdf9a60065b | 1842 | * Given an initialized ticker with two ticker event inserted scheduled from less |
kadonotakashi | 0:8fdf9a60065b | 1843 | * than TIMESTAMP_MAX_DELTA from one another. The interface |
kadonotakashi | 0:8fdf9a60065b | 1844 | * timestamp is equal to the timestamp of the first event. |
kadonotakashi | 0:8fdf9a60065b | 1845 | * When ticker_irq_handler is called. |
kadonotakashi | 0:8fdf9a60065b | 1846 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 1847 | * - The IRQ handler should have been called for the first event. |
kadonotakashi | 0:8fdf9a60065b | 1848 | * - The head of the queue should be set to second event. |
kadonotakashi | 0:8fdf9a60065b | 1849 | * - The interrupt timestamp in the ticker interface should be equal to the |
kadonotakashi | 0:8fdf9a60065b | 1850 | * timestamp of the second event. |
kadonotakashi | 0:8fdf9a60065b | 1851 | */ |
kadonotakashi | 0:8fdf9a60065b | 1852 | static void test_irq_handler_multiple_event_single_dequeue() |
kadonotakashi | 0:8fdf9a60065b | 1853 | { |
kadonotakashi | 0:8fdf9a60065b | 1854 | const us_timestamp_t timestamps [] = { |
kadonotakashi | 0:8fdf9a60065b | 1855 | 10, |
kadonotakashi | 0:8fdf9a60065b | 1856 | 10 + TIMESTAMP_MAX_DELTA - 1 |
kadonotakashi | 0:8fdf9a60065b | 1857 | }; |
kadonotakashi | 0:8fdf9a60065b | 1858 | |
kadonotakashi | 0:8fdf9a60065b | 1859 | size_t handler_called = 0; |
kadonotakashi | 0:8fdf9a60065b | 1860 | struct irq_handler_stub_t { |
kadonotakashi | 0:8fdf9a60065b | 1861 | static void event_handler(uint32_t id) |
kadonotakashi | 0:8fdf9a60065b | 1862 | { |
kadonotakashi | 0:8fdf9a60065b | 1863 | ++ (*((size_t *) id)); |
kadonotakashi | 0:8fdf9a60065b | 1864 | } |
kadonotakashi | 0:8fdf9a60065b | 1865 | }; |
kadonotakashi | 0:8fdf9a60065b | 1866 | |
kadonotakashi | 0:8fdf9a60065b | 1867 | ticker_set_handler(&ticker_stub, irq_handler_stub_t::event_handler); |
kadonotakashi | 0:8fdf9a60065b | 1868 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1869 | |
kadonotakashi | 0:8fdf9a60065b | 1870 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 1871 | |
kadonotakashi | 0:8fdf9a60065b | 1872 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 1873 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1874 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1875 | &events[i], timestamps[i], (uint32_t) &handler_called |
kadonotakashi | 0:8fdf9a60065b | 1876 | ); |
kadonotakashi | 0:8fdf9a60065b | 1877 | } |
kadonotakashi | 0:8fdf9a60065b | 1878 | |
kadonotakashi | 0:8fdf9a60065b | 1879 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1880 | interface_stub.clear_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1881 | interface_stub.timestamp = timestamps[0]; |
kadonotakashi | 0:8fdf9a60065b | 1882 | |
kadonotakashi | 0:8fdf9a60065b | 1883 | ticker_irq_handler(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 1884 | |
kadonotakashi | 0:8fdf9a60065b | 1885 | TEST_ASSERT_EQUAL(1, interface_stub.clear_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1886 | TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1887 | TEST_ASSERT_EQUAL_UINT32(1, handler_called); |
kadonotakashi | 0:8fdf9a60065b | 1888 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1889 | timestamps[1], |
kadonotakashi | 0:8fdf9a60065b | 1890 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1891 | ); |
kadonotakashi | 0:8fdf9a60065b | 1892 | TEST_ASSERT_EQUAL_PTR(&events[1], queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1893 | |
kadonotakashi | 0:8fdf9a60065b | 1894 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1895 | } |
kadonotakashi | 0:8fdf9a60065b | 1896 | |
kadonotakashi | 0:8fdf9a60065b | 1897 | /** |
kadonotakashi | 0:8fdf9a60065b | 1898 | * Given an initialized ticker with multiple ticker event inserted and the |
kadonotakashi | 0:8fdf9a60065b | 1899 | * interface timestamp is equal to the timestamp of the first event. The first |
kadonotakashi | 0:8fdf9a60065b | 1900 | * event to execute will insert an events in the ticker which have to be executed |
kadonotakashi | 0:8fdf9a60065b | 1901 | * immediately. |
kadonotakashi | 0:8fdf9a60065b | 1902 | * When ticker_irq_handler is called. |
kadonotakashi | 0:8fdf9a60065b | 1903 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 1904 | * - The IRQ handler should have been called for the first event and the event |
kadonotakashi | 0:8fdf9a60065b | 1905 | * inserted during irq. |
kadonotakashi | 0:8fdf9a60065b | 1906 | * - The head of the queue should be set correctly. |
kadonotakashi | 0:8fdf9a60065b | 1907 | * - The interrupt timestamp in the ticker interface should be equal to |
kadonotakashi | 0:8fdf9a60065b | 1908 | * timestamp of the head event. |
kadonotakashi | 0:8fdf9a60065b | 1909 | */ |
kadonotakashi | 0:8fdf9a60065b | 1910 | static void test_irq_handler_insert_immediate_in_irq() |
kadonotakashi | 0:8fdf9a60065b | 1911 | { |
kadonotakashi | 0:8fdf9a60065b | 1912 | static const us_timestamp_t timestamps [] = { |
kadonotakashi | 0:8fdf9a60065b | 1913 | 10, |
kadonotakashi | 0:8fdf9a60065b | 1914 | 10 + TIMESTAMP_MAX_DELTA - 1 |
kadonotakashi | 0:8fdf9a60065b | 1915 | }; |
kadonotakashi | 0:8fdf9a60065b | 1916 | |
kadonotakashi | 0:8fdf9a60065b | 1917 | static const us_timestamp_t expected_timestamp = |
kadonotakashi | 0:8fdf9a60065b | 1918 | ((timestamps[1] - timestamps[0]) / 2) + timestamps[0]; |
kadonotakashi | 0:8fdf9a60065b | 1919 | |
kadonotakashi | 0:8fdf9a60065b | 1920 | struct ctrl_block_t { |
kadonotakashi | 0:8fdf9a60065b | 1921 | bool irq_event_called; |
kadonotakashi | 0:8fdf9a60065b | 1922 | ticker_event_t immediate_event; |
kadonotakashi | 0:8fdf9a60065b | 1923 | size_t handler_called; |
kadonotakashi | 0:8fdf9a60065b | 1924 | }; |
kadonotakashi | 0:8fdf9a60065b | 1925 | |
kadonotakashi | 0:8fdf9a60065b | 1926 | ctrl_block_t ctrl_block = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 1927 | |
kadonotakashi | 0:8fdf9a60065b | 1928 | struct irq_handler_stub_t { |
kadonotakashi | 0:8fdf9a60065b | 1929 | static void event_handler(uint32_t id) |
kadonotakashi | 0:8fdf9a60065b | 1930 | { |
kadonotakashi | 0:8fdf9a60065b | 1931 | ctrl_block_t *ctrl_block = (ctrl_block_t *) id; |
kadonotakashi | 0:8fdf9a60065b | 1932 | |
kadonotakashi | 0:8fdf9a60065b | 1933 | if (ctrl_block->handler_called == 0) { |
kadonotakashi | 0:8fdf9a60065b | 1934 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 1935 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1936 | &ctrl_block->immediate_event, expected_timestamp, id |
kadonotakashi | 0:8fdf9a60065b | 1937 | ); |
kadonotakashi | 0:8fdf9a60065b | 1938 | interface_stub.timestamp = expected_timestamp; |
kadonotakashi | 0:8fdf9a60065b | 1939 | } else if (ctrl_block->handler_called > 1) { |
kadonotakashi | 0:8fdf9a60065b | 1940 | TEST_FAIL(); |
kadonotakashi | 0:8fdf9a60065b | 1941 | } |
kadonotakashi | 0:8fdf9a60065b | 1942 | ++ctrl_block->handler_called; |
kadonotakashi | 0:8fdf9a60065b | 1943 | } |
kadonotakashi | 0:8fdf9a60065b | 1944 | }; |
kadonotakashi | 0:8fdf9a60065b | 1945 | |
kadonotakashi | 0:8fdf9a60065b | 1946 | ticker_set_handler(&ticker_stub, irq_handler_stub_t::event_handler); |
kadonotakashi | 0:8fdf9a60065b | 1947 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1948 | |
kadonotakashi | 0:8fdf9a60065b | 1949 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 1950 | |
kadonotakashi | 0:8fdf9a60065b | 1951 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 1952 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 1953 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 1954 | &events[i], timestamps[i], (uint32_t) &ctrl_block |
kadonotakashi | 0:8fdf9a60065b | 1955 | ); |
kadonotakashi | 0:8fdf9a60065b | 1956 | } |
kadonotakashi | 0:8fdf9a60065b | 1957 | |
kadonotakashi | 0:8fdf9a60065b | 1958 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1959 | interface_stub.clear_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 1960 | interface_stub.timestamp = timestamps[0]; |
kadonotakashi | 0:8fdf9a60065b | 1961 | |
kadonotakashi | 0:8fdf9a60065b | 1962 | ticker_irq_handler(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 1963 | |
kadonotakashi | 0:8fdf9a60065b | 1964 | TEST_ASSERT_EQUAL(1, interface_stub.clear_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1965 | TEST_ASSERT_EQUAL_UINT32(2, ctrl_block.handler_called); |
kadonotakashi | 0:8fdf9a60065b | 1966 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 1967 | timestamps[1], |
kadonotakashi | 0:8fdf9a60065b | 1968 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 1969 | ); |
kadonotakashi | 0:8fdf9a60065b | 1970 | TEST_ASSERT_EQUAL_PTR(&events[1], queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 1971 | |
kadonotakashi | 0:8fdf9a60065b | 1972 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 1973 | } |
kadonotakashi | 0:8fdf9a60065b | 1974 | |
kadonotakashi | 0:8fdf9a60065b | 1975 | /** |
kadonotakashi | 0:8fdf9a60065b | 1976 | * Given an initialized ticker with multiple ticker event inserted and the |
kadonotakashi | 0:8fdf9a60065b | 1977 | * interface timestamp is equal to the timestamp of the first event. The first |
kadonotakashi | 0:8fdf9a60065b | 1978 | * event to execute will insert an events in the ticker which does not have to |
kadonotakashi | 0:8fdf9a60065b | 1979 | * be executed immediately. |
kadonotakashi | 0:8fdf9a60065b | 1980 | * When ticker_irq_handler is called. |
kadonotakashi | 0:8fdf9a60065b | 1981 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 1982 | * - The IRQ handler should have been called for the first event. |
kadonotakashi | 0:8fdf9a60065b | 1983 | * - The head of the queue should be set to the event inserted in IRQ. |
kadonotakashi | 0:8fdf9a60065b | 1984 | * - The interrupt timestamp in the ticker interface should be equal to |
kadonotakashi | 0:8fdf9a60065b | 1985 | * timestamp of the head event. |
kadonotakashi | 0:8fdf9a60065b | 1986 | */ |
kadonotakashi | 0:8fdf9a60065b | 1987 | static void test_irq_handler_insert_non_immediate_in_irq() |
kadonotakashi | 0:8fdf9a60065b | 1988 | { |
kadonotakashi | 0:8fdf9a60065b | 1989 | static const us_timestamp_t timestamps [] = { |
kadonotakashi | 0:8fdf9a60065b | 1990 | 10, |
kadonotakashi | 0:8fdf9a60065b | 1991 | 10 + TIMESTAMP_MAX_DELTA - 1 |
kadonotakashi | 0:8fdf9a60065b | 1992 | }; |
kadonotakashi | 0:8fdf9a60065b | 1993 | |
kadonotakashi | 0:8fdf9a60065b | 1994 | static const us_timestamp_t expected_timestamp = |
kadonotakashi | 0:8fdf9a60065b | 1995 | ((timestamps[1] - timestamps[0]) / 2) + timestamps[0]; |
kadonotakashi | 0:8fdf9a60065b | 1996 | |
kadonotakashi | 0:8fdf9a60065b | 1997 | struct ctrl_block_t { |
kadonotakashi | 0:8fdf9a60065b | 1998 | bool irq_event_called; |
kadonotakashi | 0:8fdf9a60065b | 1999 | ticker_event_t non_immediate_event; |
kadonotakashi | 0:8fdf9a60065b | 2000 | size_t handler_called; |
kadonotakashi | 0:8fdf9a60065b | 2001 | }; |
kadonotakashi | 0:8fdf9a60065b | 2002 | |
kadonotakashi | 0:8fdf9a60065b | 2003 | ctrl_block_t ctrl_block = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 2004 | |
kadonotakashi | 0:8fdf9a60065b | 2005 | struct irq_handler_stub_t { |
kadonotakashi | 0:8fdf9a60065b | 2006 | static void event_handler(uint32_t id) |
kadonotakashi | 0:8fdf9a60065b | 2007 | { |
kadonotakashi | 0:8fdf9a60065b | 2008 | ctrl_block_t *ctrl_block = (ctrl_block_t *) id; |
kadonotakashi | 0:8fdf9a60065b | 2009 | |
kadonotakashi | 0:8fdf9a60065b | 2010 | if (ctrl_block->handler_called == 0) { |
kadonotakashi | 0:8fdf9a60065b | 2011 | ticker_insert_event( |
kadonotakashi | 0:8fdf9a60065b | 2012 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 2013 | &ctrl_block->non_immediate_event, expected_timestamp, id |
kadonotakashi | 0:8fdf9a60065b | 2014 | ); |
kadonotakashi | 0:8fdf9a60065b | 2015 | } else { |
kadonotakashi | 0:8fdf9a60065b | 2016 | TEST_FAIL(); |
kadonotakashi | 0:8fdf9a60065b | 2017 | } |
kadonotakashi | 0:8fdf9a60065b | 2018 | ++ctrl_block->handler_called; |
kadonotakashi | 0:8fdf9a60065b | 2019 | } |
kadonotakashi | 0:8fdf9a60065b | 2020 | }; |
kadonotakashi | 0:8fdf9a60065b | 2021 | |
kadonotakashi | 0:8fdf9a60065b | 2022 | |
kadonotakashi | 0:8fdf9a60065b | 2023 | ticker_set_handler(&ticker_stub, irq_handler_stub_t::event_handler); |
kadonotakashi | 0:8fdf9a60065b | 2024 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 2025 | |
kadonotakashi | 0:8fdf9a60065b | 2026 | ticker_event_t events[MBED_ARRAY_SIZE(timestamps)] = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 2027 | |
kadonotakashi | 0:8fdf9a60065b | 2028 | for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { |
kadonotakashi | 0:8fdf9a60065b | 2029 | ticker_insert_event_us( |
kadonotakashi | 0:8fdf9a60065b | 2030 | &ticker_stub, |
kadonotakashi | 0:8fdf9a60065b | 2031 | &events[i], timestamps[i], (uint32_t) &ctrl_block |
kadonotakashi | 0:8fdf9a60065b | 2032 | ); |
kadonotakashi | 0:8fdf9a60065b | 2033 | } |
kadonotakashi | 0:8fdf9a60065b | 2034 | |
kadonotakashi | 0:8fdf9a60065b | 2035 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 2036 | interface_stub.clear_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 2037 | interface_stub.timestamp = timestamps[0]; |
kadonotakashi | 0:8fdf9a60065b | 2038 | |
kadonotakashi | 0:8fdf9a60065b | 2039 | ticker_irq_handler(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 2040 | |
kadonotakashi | 0:8fdf9a60065b | 2041 | TEST_ASSERT_EQUAL(1, interface_stub.clear_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2042 | TEST_ASSERT_EQUAL_UINT32(1, ctrl_block.handler_called); |
kadonotakashi | 0:8fdf9a60065b | 2043 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 2044 | expected_timestamp, |
kadonotakashi | 0:8fdf9a60065b | 2045 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 2046 | ); |
kadonotakashi | 0:8fdf9a60065b | 2047 | TEST_ASSERT_EQUAL_PTR(&ctrl_block.non_immediate_event, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 2048 | TEST_ASSERT_EQUAL_PTR(&events[1], queue_stub.head->next); |
kadonotakashi | 0:8fdf9a60065b | 2049 | |
kadonotakashi | 0:8fdf9a60065b | 2050 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2051 | } |
kadonotakashi | 0:8fdf9a60065b | 2052 | |
kadonotakashi | 0:8fdf9a60065b | 2053 | static uint32_t ticker_interface_stub_read_interrupt_time() |
kadonotakashi | 0:8fdf9a60065b | 2054 | { |
kadonotakashi | 0:8fdf9a60065b | 2055 | ++interface_stub.read_call; |
kadonotakashi | 0:8fdf9a60065b | 2056 | // only if set interrupt call, to test the condition afterwards |
kadonotakashi | 0:8fdf9a60065b | 2057 | if (interface_stub.set_interrupt_call) { |
kadonotakashi | 0:8fdf9a60065b | 2058 | return interface_stub.interrupt_timestamp; |
kadonotakashi | 0:8fdf9a60065b | 2059 | } else { |
kadonotakashi | 0:8fdf9a60065b | 2060 | return interface_stub.timestamp; |
kadonotakashi | 0:8fdf9a60065b | 2061 | } |
kadonotakashi | 0:8fdf9a60065b | 2062 | } |
kadonotakashi | 0:8fdf9a60065b | 2063 | |
kadonotakashi | 0:8fdf9a60065b | 2064 | /** |
kadonotakashi | 0:8fdf9a60065b | 2065 | * Test to insert an event that is already in the past, the fire_interrupt should |
kadonotakashi | 0:8fdf9a60065b | 2066 | * be invoked, instead of set_interrupt |
kadonotakashi | 0:8fdf9a60065b | 2067 | */ |
kadonotakashi | 0:8fdf9a60065b | 2068 | static void test_set_interrupt_past_time() |
kadonotakashi | 0:8fdf9a60065b | 2069 | { |
kadonotakashi | 0:8fdf9a60065b | 2070 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 2071 | |
kadonotakashi | 0:8fdf9a60065b | 2072 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 2073 | interface_stub.fire_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 2074 | interface_stub.timestamp = 0xFF; |
kadonotakashi | 0:8fdf9a60065b | 2075 | |
kadonotakashi | 0:8fdf9a60065b | 2076 | |
kadonotakashi | 0:8fdf9a60065b | 2077 | // This tests fire now functinality when next_event_timestamp <= present |
kadonotakashi | 0:8fdf9a60065b | 2078 | ticker_event_t event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 2079 | const timestamp_t event_timestamp = interface_stub.timestamp; |
kadonotakashi | 0:8fdf9a60065b | 2080 | const uint32_t id_last_event = 0xDEADDEAF; |
kadonotakashi | 0:8fdf9a60065b | 2081 | |
kadonotakashi | 0:8fdf9a60065b | 2082 | ticker_insert_event(&ticker_stub, &event, event_timestamp, id_last_event); |
kadonotakashi | 0:8fdf9a60065b | 2083 | TEST_ASSERT_EQUAL(0, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2084 | TEST_ASSERT_EQUAL(1, interface_stub.fire_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2085 | } |
kadonotakashi | 0:8fdf9a60065b | 2086 | /** |
kadonotakashi | 0:8fdf9a60065b | 2087 | * Test to insert an event that is being delayed, set_interrupt is set |
kadonotakashi | 0:8fdf9a60065b | 2088 | * but then event is already in the past, thus fire_interrupt should be invoked right-away |
kadonotakashi | 0:8fdf9a60065b | 2089 | */ |
kadonotakashi | 0:8fdf9a60065b | 2090 | static void test_set_interrupt_past_time_with_delay() |
kadonotakashi | 0:8fdf9a60065b | 2091 | { |
kadonotakashi | 0:8fdf9a60065b | 2092 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 2093 | |
kadonotakashi | 0:8fdf9a60065b | 2094 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 2095 | interface_stub.fire_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 2096 | interface_stub.timestamp = 0xFF; |
kadonotakashi | 0:8fdf9a60065b | 2097 | |
kadonotakashi | 0:8fdf9a60065b | 2098 | // This tests fire now functionality when present time >= new_match_time |
kadonotakashi | 0:8fdf9a60065b | 2099 | interface_stub.interface.read = ticker_interface_stub_read_interrupt_time; |
kadonotakashi | 0:8fdf9a60065b | 2100 | ticker_event_t event = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 2101 | const timestamp_t event_timestamp = interface_stub.timestamp + 5; |
kadonotakashi | 0:8fdf9a60065b | 2102 | const uint32_t id_last_event = 0xDEADDEAF; |
kadonotakashi | 0:8fdf9a60065b | 2103 | |
kadonotakashi | 0:8fdf9a60065b | 2104 | ticker_insert_event(&ticker_stub, &event, event_timestamp, id_last_event); |
kadonotakashi | 0:8fdf9a60065b | 2105 | TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2106 | TEST_ASSERT_EQUAL(1, interface_stub.fire_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2107 | } |
kadonotakashi | 0:8fdf9a60065b | 2108 | |
kadonotakashi | 0:8fdf9a60065b | 2109 | /** |
kadonotakashi | 0:8fdf9a60065b | 2110 | * Convert ticks at a given frequency to time in microseconds |
kadonotakashi | 0:8fdf9a60065b | 2111 | * |
kadonotakashi | 0:8fdf9a60065b | 2112 | * Assert if there is a 64-bit overflow |
kadonotakashi | 0:8fdf9a60065b | 2113 | */ |
kadonotakashi | 0:8fdf9a60065b | 2114 | static uint64_t convert_to_us(uint64_t ticks, uint32_t frequency) |
kadonotakashi | 0:8fdf9a60065b | 2115 | { |
kadonotakashi | 0:8fdf9a60065b | 2116 | uint64_t scaled_ticks = ticks * 1000000; |
kadonotakashi | 0:8fdf9a60065b | 2117 | // Assert that there was not an overflow |
kadonotakashi | 0:8fdf9a60065b | 2118 | TEST_ASSERT_EQUAL(ticks, scaled_ticks / 1000000); |
kadonotakashi | 0:8fdf9a60065b | 2119 | return scaled_ticks / frequency; |
kadonotakashi | 0:8fdf9a60065b | 2120 | } |
kadonotakashi | 0:8fdf9a60065b | 2121 | |
kadonotakashi | 0:8fdf9a60065b | 2122 | /** |
kadonotakashi | 0:8fdf9a60065b | 2123 | * Given an uninitialized ticker instance and an interface of a |
kadonotakashi | 0:8fdf9a60065b | 2124 | * certain frequency and bit width. |
kadonotakashi | 0:8fdf9a60065b | 2125 | * Then the time returned the ticker should match the cumulative time. |
kadonotakashi | 0:8fdf9a60065b | 2126 | */ |
kadonotakashi | 0:8fdf9a60065b | 2127 | void test_frequencies_and_masks(uint32_t frequency, uint32_t bits) |
kadonotakashi | 0:8fdf9a60065b | 2128 | { |
kadonotakashi | 0:8fdf9a60065b | 2129 | const uint32_t bitmask = ((uint64_t)1 << bits) - 1; |
kadonotakashi | 0:8fdf9a60065b | 2130 | |
kadonotakashi | 0:8fdf9a60065b | 2131 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 2132 | uint64_t ticks = 0; |
kadonotakashi | 0:8fdf9a60065b | 2133 | |
kadonotakashi | 0:8fdf9a60065b | 2134 | // Single tick |
kadonotakashi | 0:8fdf9a60065b | 2135 | ticks += 1; |
kadonotakashi | 0:8fdf9a60065b | 2136 | interface_stub.timestamp = ticks & bitmask; |
kadonotakashi | 0:8fdf9a60065b | 2137 | TEST_ASSERT_EQUAL_UINT32(convert_to_us(ticks, frequency), ticker_read(&ticker_stub)); |
kadonotakashi | 0:8fdf9a60065b | 2138 | TEST_ASSERT_EQUAL_UINT64(convert_to_us(ticks, frequency), ticker_read_us(&ticker_stub)); |
kadonotakashi | 0:8fdf9a60065b | 2139 | |
kadonotakashi | 0:8fdf9a60065b | 2140 | // Run until the loop before 64-bit overflow (worst case with frequency=1hz, bits=32) |
kadonotakashi | 0:8fdf9a60065b | 2141 | for (unsigned int k = 0; k < 4294; k++) { |
kadonotakashi | 0:8fdf9a60065b | 2142 | |
kadonotakashi | 0:8fdf9a60065b | 2143 | // Largest value possible tick |
kadonotakashi | 0:8fdf9a60065b | 2144 | ticks += ((uint64_t)1 << bits) - 1; |
kadonotakashi | 0:8fdf9a60065b | 2145 | interface_stub.timestamp = ticks & bitmask; |
kadonotakashi | 0:8fdf9a60065b | 2146 | TEST_ASSERT_EQUAL_UINT32(convert_to_us(ticks, frequency), ticker_read(&ticker_stub)); |
kadonotakashi | 0:8fdf9a60065b | 2147 | TEST_ASSERT_EQUAL_UINT64(convert_to_us(ticks, frequency), ticker_read_us(&ticker_stub)); |
kadonotakashi | 0:8fdf9a60065b | 2148 | } |
kadonotakashi | 0:8fdf9a60065b | 2149 | } |
kadonotakashi | 0:8fdf9a60065b | 2150 | |
kadonotakashi | 0:8fdf9a60065b | 2151 | /** |
kadonotakashi | 0:8fdf9a60065b | 2152 | * Given an uninitialized ticker_data instance. |
kadonotakashi | 0:8fdf9a60065b | 2153 | * When the ticker is initialized |
kadonotakashi | 0:8fdf9a60065b | 2154 | * Then: |
kadonotakashi | 0:8fdf9a60065b | 2155 | * - The internal ticker timestamp should be zero |
kadonotakashi | 0:8fdf9a60065b | 2156 | * - interrupt should be scheduled in current (timestamp + |
kadonotakashi | 0:8fdf9a60065b | 2157 | * TIMESTAMP_MAX_DELTA_BITS(bitwidth)) % modval |
kadonotakashi | 0:8fdf9a60065b | 2158 | * - The queue should not contains any event |
kadonotakashi | 0:8fdf9a60065b | 2159 | */ |
kadonotakashi | 0:8fdf9a60065b | 2160 | static void test_ticker_max_value() |
kadonotakashi | 0:8fdf9a60065b | 2161 | { |
kadonotakashi | 0:8fdf9a60065b | 2162 | for (int bitwidth = 8; bitwidth <= 32; bitwidth++) { |
kadonotakashi | 0:8fdf9a60065b | 2163 | const uint64_t modval = 1ULL << bitwidth; |
kadonotakashi | 0:8fdf9a60065b | 2164 | |
kadonotakashi | 0:8fdf9a60065b | 2165 | // setup of the stub |
kadonotakashi | 0:8fdf9a60065b | 2166 | reset_ticker_stub(); |
kadonotakashi | 0:8fdf9a60065b | 2167 | interface_info_stub.bits = bitwidth; |
kadonotakashi | 0:8fdf9a60065b | 2168 | interface_stub.timestamp = 0xBA; |
kadonotakashi | 0:8fdf9a60065b | 2169 | |
kadonotakashi | 0:8fdf9a60065b | 2170 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 2171 | |
kadonotakashi | 0:8fdf9a60065b | 2172 | TEST_ASSERT_EQUAL_UINT64(0, queue_stub.present_time); |
kadonotakashi | 0:8fdf9a60065b | 2173 | TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2174 | TEST_ASSERT_EQUAL_UINT32( |
kadonotakashi | 0:8fdf9a60065b | 2175 | (interface_stub.timestamp + TIMESTAMP_MAX_DELTA_BITS(bitwidth)) % modval, |
kadonotakashi | 0:8fdf9a60065b | 2176 | interface_stub.interrupt_timestamp |
kadonotakashi | 0:8fdf9a60065b | 2177 | ); |
kadonotakashi | 0:8fdf9a60065b | 2178 | TEST_ASSERT_EQUAL_PTR(NULL, queue_stub.head); |
kadonotakashi | 0:8fdf9a60065b | 2179 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2180 | } |
kadonotakashi | 0:8fdf9a60065b | 2181 | } |
kadonotakashi | 0:8fdf9a60065b | 2182 | |
kadonotakashi | 0:8fdf9a60065b | 2183 | /** |
kadonotakashi | 0:8fdf9a60065b | 2184 | * Check that _ticker_match_interval_passed correctly detects matches |
kadonotakashi | 0:8fdf9a60065b | 2185 | * |
kadonotakashi | 0:8fdf9a60065b | 2186 | * Brute force test that _ticker_match_interval_passed returns the correct match value |
kadonotakashi | 0:8fdf9a60065b | 2187 | * for all cominations of values within a small range. |
kadonotakashi | 0:8fdf9a60065b | 2188 | */ |
kadonotakashi | 0:8fdf9a60065b | 2189 | static void test_match_interval_passed() |
kadonotakashi | 0:8fdf9a60065b | 2190 | { |
kadonotakashi | 0:8fdf9a60065b | 2191 | |
kadonotakashi | 0:8fdf9a60065b | 2192 | for (int modval = 1; modval <= 5; modval++) { |
kadonotakashi | 0:8fdf9a60065b | 2193 | for (int prev = 0; prev < modval; prev++) { |
kadonotakashi | 0:8fdf9a60065b | 2194 | for (int cur = 0; cur < modval; cur++) { |
kadonotakashi | 0:8fdf9a60065b | 2195 | for (int match = 0; match < modval; match++) { |
kadonotakashi | 0:8fdf9a60065b | 2196 | uint32_t delta = (cur - prev) % modval; |
kadonotakashi | 0:8fdf9a60065b | 2197 | uint32_t delta_to_match = (match - prev) % modval; |
kadonotakashi | 0:8fdf9a60065b | 2198 | bool match_expected = false; |
kadonotakashi | 0:8fdf9a60065b | 2199 | if (delta_to_match) { |
kadonotakashi | 0:8fdf9a60065b | 2200 | match_expected = delta >= delta_to_match; |
kadonotakashi | 0:8fdf9a60065b | 2201 | } |
kadonotakashi | 0:8fdf9a60065b | 2202 | |
kadonotakashi | 0:8fdf9a60065b | 2203 | // Sanity checks |
kadonotakashi | 0:8fdf9a60065b | 2204 | if (prev == cur) { |
kadonotakashi | 0:8fdf9a60065b | 2205 | // No time has passed |
kadonotakashi | 0:8fdf9a60065b | 2206 | TEST_ASSERT_EQUAL(false, match_expected); |
kadonotakashi | 0:8fdf9a60065b | 2207 | } else if (match == prev) { |
kadonotakashi | 0:8fdf9a60065b | 2208 | // Match can't occur without an overflow occurring |
kadonotakashi | 0:8fdf9a60065b | 2209 | TEST_ASSERT_EQUAL(false, match_expected); |
kadonotakashi | 0:8fdf9a60065b | 2210 | } else if (cur == match) { |
kadonotakashi | 0:8fdf9a60065b | 2211 | // All other cases where cur == match a match should be expected |
kadonotakashi | 0:8fdf9a60065b | 2212 | TEST_ASSERT_EQUAL(true, match_expected); |
kadonotakashi | 0:8fdf9a60065b | 2213 | } |
kadonotakashi | 0:8fdf9a60065b | 2214 | |
kadonotakashi | 0:8fdf9a60065b | 2215 | // Actual test |
kadonotakashi | 0:8fdf9a60065b | 2216 | TEST_ASSERT_EQUAL(match_expected, _ticker_match_interval_passed(prev, cur, match)); |
kadonotakashi | 0:8fdf9a60065b | 2217 | } |
kadonotakashi | 0:8fdf9a60065b | 2218 | } |
kadonotakashi | 0:8fdf9a60065b | 2219 | } |
kadonotakashi | 0:8fdf9a60065b | 2220 | } |
kadonotakashi | 0:8fdf9a60065b | 2221 | } |
kadonotakashi | 0:8fdf9a60065b | 2222 | |
kadonotakashi | 0:8fdf9a60065b | 2223 | typedef struct { |
kadonotakashi | 0:8fdf9a60065b | 2224 | timestamp_t prev; |
kadonotakashi | 0:8fdf9a60065b | 2225 | timestamp_t cur; |
kadonotakashi | 0:8fdf9a60065b | 2226 | timestamp_t match; |
kadonotakashi | 0:8fdf9a60065b | 2227 | bool result; |
kadonotakashi | 0:8fdf9a60065b | 2228 | } match_interval_entry_t; |
kadonotakashi | 0:8fdf9a60065b | 2229 | |
kadonotakashi | 0:8fdf9a60065b | 2230 | /** |
kadonotakashi | 0:8fdf9a60065b | 2231 | * Check that _ticker_match_interval_passed correctly detects matches |
kadonotakashi | 0:8fdf9a60065b | 2232 | * |
kadonotakashi | 0:8fdf9a60065b | 2233 | * Use a table of pre-computed values to check that _ticker_match_interval_passed |
kadonotakashi | 0:8fdf9a60065b | 2234 | * returns the correct match value. |
kadonotakashi | 0:8fdf9a60065b | 2235 | */ |
kadonotakashi | 0:8fdf9a60065b | 2236 | static void test_match_interval_passed_table() |
kadonotakashi | 0:8fdf9a60065b | 2237 | { |
kadonotakashi | 0:8fdf9a60065b | 2238 | static const match_interval_entry_t test_values[] = { |
kadonotakashi | 0:8fdf9a60065b | 2239 | /* prev, cur, match, result */ |
kadonotakashi | 0:8fdf9a60065b | 2240 | {0x00000000, 0x00000000, 0x00000000, false}, |
kadonotakashi | 0:8fdf9a60065b | 2241 | {0x00000000, 0x00000000, 0xffffffff, false}, |
kadonotakashi | 0:8fdf9a60065b | 2242 | {0x00000000, 0x00000000, 0x00000001, false}, |
kadonotakashi | 0:8fdf9a60065b | 2243 | {0x00000000, 0xffffffff, 0x00000000, false}, |
kadonotakashi | 0:8fdf9a60065b | 2244 | {0x00000000, 0x00000001, 0x00000000, false}, |
kadonotakashi | 0:8fdf9a60065b | 2245 | {0xffffffff, 0x00000000, 0x00000000, true}, |
kadonotakashi | 0:8fdf9a60065b | 2246 | {0x00000001, 0x00000000, 0x00000000, true}, |
kadonotakashi | 0:8fdf9a60065b | 2247 | {0x00005555, 0x00005555, 0x00005555, false}, |
kadonotakashi | 0:8fdf9a60065b | 2248 | {0x00005555, 0x00005555, 0x00005554, false}, |
kadonotakashi | 0:8fdf9a60065b | 2249 | {0x00005555, 0x00005555, 0x00005556, false}, |
kadonotakashi | 0:8fdf9a60065b | 2250 | {0x00005555, 0x00005554, 0x00005555, false}, |
kadonotakashi | 0:8fdf9a60065b | 2251 | {0x00005555, 0x00005556, 0x00005555, false}, |
kadonotakashi | 0:8fdf9a60065b | 2252 | {0x00005554, 0x00005555, 0x00005555, true}, |
kadonotakashi | 0:8fdf9a60065b | 2253 | {0x00005556, 0x00005555, 0x00005555, true}, |
kadonotakashi | 0:8fdf9a60065b | 2254 | {0xffffffff, 0xffffffff, 0xffffffff, false}, |
kadonotakashi | 0:8fdf9a60065b | 2255 | {0xffffffff, 0xffffffff, 0xfffffffe, false}, |
kadonotakashi | 0:8fdf9a60065b | 2256 | {0xffffffff, 0xffffffff, 0x00000000, false}, |
kadonotakashi | 0:8fdf9a60065b | 2257 | {0xffffffff, 0xfffffffe, 0xffffffff, false}, |
kadonotakashi | 0:8fdf9a60065b | 2258 | {0xffffffff, 0x00000000, 0xffffffff, false}, |
kadonotakashi | 0:8fdf9a60065b | 2259 | {0xfffffffe, 0xffffffff, 0xffffffff, true}, |
kadonotakashi | 0:8fdf9a60065b | 2260 | {0x00000000, 0xffffffff, 0xffffffff, true}, |
kadonotakashi | 0:8fdf9a60065b | 2261 | }; |
kadonotakashi | 0:8fdf9a60065b | 2262 | for (int i = 0; i < MBED_ARRAY_SIZE(test_values); i++) { |
kadonotakashi | 0:8fdf9a60065b | 2263 | const uint32_t prev = test_values[i].prev; |
kadonotakashi | 0:8fdf9a60065b | 2264 | const uint32_t cur = test_values[i].cur; |
kadonotakashi | 0:8fdf9a60065b | 2265 | const uint32_t match = test_values[i].match; |
kadonotakashi | 0:8fdf9a60065b | 2266 | const uint32_t result = test_values[i].result; |
kadonotakashi | 0:8fdf9a60065b | 2267 | TEST_ASSERT_EQUAL(result, _ticker_match_interval_passed(prev, cur, match)); |
kadonotakashi | 0:8fdf9a60065b | 2268 | } |
kadonotakashi | 0:8fdf9a60065b | 2269 | } |
kadonotakashi | 0:8fdf9a60065b | 2270 | |
kadonotakashi | 0:8fdf9a60065b | 2271 | /** |
kadonotakashi | 0:8fdf9a60065b | 2272 | * Check that suspend and resume work as expected |
kadonotakashi | 0:8fdf9a60065b | 2273 | * |
kadonotakashi | 0:8fdf9a60065b | 2274 | * Check the following |
kadonotakashi | 0:8fdf9a60065b | 2275 | * -time does not change while suspended |
kadonotakashi | 0:8fdf9a60065b | 2276 | * -restricted interface functions are not called |
kadonotakashi | 0:8fdf9a60065b | 2277 | * -scheduling resumes correctly |
kadonotakashi | 0:8fdf9a60065b | 2278 | */ |
kadonotakashi | 0:8fdf9a60065b | 2279 | static void test_suspend_resume() |
kadonotakashi | 0:8fdf9a60065b | 2280 | { |
kadonotakashi | 0:8fdf9a60065b | 2281 | ticker_set_handler(&ticker_stub, NULL); |
kadonotakashi | 0:8fdf9a60065b | 2282 | |
kadonotakashi | 0:8fdf9a60065b | 2283 | interface_stub.timestamp = 1000; |
kadonotakashi | 0:8fdf9a60065b | 2284 | us_timestamp_t start = ticker_read_us(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 2285 | TEST_ASSERT_EQUAL(1000, start); |
kadonotakashi | 0:8fdf9a60065b | 2286 | |
kadonotakashi | 0:8fdf9a60065b | 2287 | /* Reset call count */ |
kadonotakashi | 0:8fdf9a60065b | 2288 | interface_stub.init_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 2289 | interface_stub.read_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 2290 | interface_stub.set_interrupt_call = 0; |
kadonotakashi | 0:8fdf9a60065b | 2291 | |
kadonotakashi | 0:8fdf9a60065b | 2292 | /* Suspend the ticker */ |
kadonotakashi | 0:8fdf9a60065b | 2293 | ticker_suspend(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 2294 | const timestamp_t suspend_time = queue_stub.present_time; |
kadonotakashi | 0:8fdf9a60065b | 2295 | |
kadonotakashi | 0:8fdf9a60065b | 2296 | |
kadonotakashi | 0:8fdf9a60065b | 2297 | /* Simulate time passing */ |
kadonotakashi | 0:8fdf9a60065b | 2298 | interface_stub.timestamp = 1500; |
kadonotakashi | 0:8fdf9a60065b | 2299 | us_timestamp_t next = ticker_read_us(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 2300 | |
kadonotakashi | 0:8fdf9a60065b | 2301 | /* Time should not have passed and no calls to interface should have been made */ |
kadonotakashi | 0:8fdf9a60065b | 2302 | TEST_ASSERT_EQUAL(start, next); |
kadonotakashi | 0:8fdf9a60065b | 2303 | TEST_ASSERT_EQUAL(0, interface_stub.init_call); |
kadonotakashi | 0:8fdf9a60065b | 2304 | TEST_ASSERT_EQUAL(0, interface_stub.read_call); |
kadonotakashi | 0:8fdf9a60065b | 2305 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2306 | TEST_ASSERT_EQUAL(0, interface_stub.clear_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2307 | TEST_ASSERT_EQUAL(0, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2308 | TEST_ASSERT_EQUAL(0, interface_stub.fire_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2309 | |
kadonotakashi | 0:8fdf9a60065b | 2310 | |
kadonotakashi | 0:8fdf9a60065b | 2311 | /* Simulate a reinit (time reset to 0) */ |
kadonotakashi | 0:8fdf9a60065b | 2312 | interface_stub.timestamp = 0; |
kadonotakashi | 0:8fdf9a60065b | 2313 | next = ticker_read_us(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 2314 | |
kadonotakashi | 0:8fdf9a60065b | 2315 | /* Time should not have passed and no calls to interface should have been made */ |
kadonotakashi | 0:8fdf9a60065b | 2316 | TEST_ASSERT_EQUAL(start, next); |
kadonotakashi | 0:8fdf9a60065b | 2317 | TEST_ASSERT_EQUAL(0, interface_stub.init_call); |
kadonotakashi | 0:8fdf9a60065b | 2318 | TEST_ASSERT_EQUAL(0, interface_stub.read_call); |
kadonotakashi | 0:8fdf9a60065b | 2319 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2320 | TEST_ASSERT_EQUAL(0, interface_stub.clear_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2321 | TEST_ASSERT_EQUAL(0, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2322 | TEST_ASSERT_EQUAL(0, interface_stub.fire_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2323 | |
kadonotakashi | 0:8fdf9a60065b | 2324 | |
kadonotakashi | 0:8fdf9a60065b | 2325 | /* Insert an event in the past and future */ |
kadonotakashi | 0:8fdf9a60065b | 2326 | ticker_event_t event_past = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 2327 | const timestamp_t event_past_timestamp = suspend_time - 10; |
kadonotakashi | 0:8fdf9a60065b | 2328 | ticker_insert_event_us(&ticker_stub, &event_past, event_past_timestamp, 0); |
kadonotakashi | 0:8fdf9a60065b | 2329 | |
kadonotakashi | 0:8fdf9a60065b | 2330 | ticker_event_t event_future = { 0 }; |
kadonotakashi | 0:8fdf9a60065b | 2331 | const timestamp_t event_future_timestamp = suspend_time + 10; |
kadonotakashi | 0:8fdf9a60065b | 2332 | ticker_insert_event_us(&ticker_stub, &event_future, event_future_timestamp, 0); |
kadonotakashi | 0:8fdf9a60065b | 2333 | |
kadonotakashi | 0:8fdf9a60065b | 2334 | TEST_ASSERT_EQUAL(0, interface_stub.init_call); |
kadonotakashi | 0:8fdf9a60065b | 2335 | TEST_ASSERT_EQUAL(0, interface_stub.read_call); |
kadonotakashi | 0:8fdf9a60065b | 2336 | TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2337 | TEST_ASSERT_EQUAL(0, interface_stub.clear_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2338 | TEST_ASSERT_EQUAL(0, interface_stub.set_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2339 | TEST_ASSERT_EQUAL(0, interface_stub.fire_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2340 | |
kadonotakashi | 0:8fdf9a60065b | 2341 | /* Resume and verify everything starts again */ |
kadonotakashi | 0:8fdf9a60065b | 2342 | ticker_resume(&ticker_stub); |
kadonotakashi | 0:8fdf9a60065b | 2343 | TEST_ASSERT_EQUAL(suspend_time, queue_stub.present_time); |
kadonotakashi | 0:8fdf9a60065b | 2344 | TEST_ASSERT_EQUAL(1, interface_stub.fire_interrupt_call); |
kadonotakashi | 0:8fdf9a60065b | 2345 | } |
kadonotakashi | 0:8fdf9a60065b | 2346 | |
kadonotakashi | 0:8fdf9a60065b | 2347 | static const case_t cases[] = { |
kadonotakashi | 0:8fdf9a60065b | 2348 | MAKE_TEST_CASE("ticker initialization", test_ticker_initialization), |
kadonotakashi | 0:8fdf9a60065b | 2349 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2350 | "ticker multiple initialization", test_ticker_re_initialization |
kadonotakashi | 0:8fdf9a60065b | 2351 | ), |
kadonotakashi | 0:8fdf9a60065b | 2352 | MAKE_TEST_CASE("ticker read", test_ticker_read), |
kadonotakashi | 0:8fdf9a60065b | 2353 | MAKE_TEST_CASE("ticker read overflow", test_ticker_read_overflow), |
kadonotakashi | 0:8fdf9a60065b | 2354 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2355 | "legacy insert event outside overflow range", |
kadonotakashi | 0:8fdf9a60065b | 2356 | test_legacy_insert_event_outside_overflow_range |
kadonotakashi | 0:8fdf9a60065b | 2357 | ), |
kadonotakashi | 0:8fdf9a60065b | 2358 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2359 | "legacy insert event in overflow range", |
kadonotakashi | 0:8fdf9a60065b | 2360 | test_legacy_insert_event_in_overflow_range |
kadonotakashi | 0:8fdf9a60065b | 2361 | ), |
kadonotakashi | 0:8fdf9a60065b | 2362 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2363 | "legacy insert event overflow", test_legacy_insert_event_overflow |
kadonotakashi | 0:8fdf9a60065b | 2364 | ), |
kadonotakashi | 0:8fdf9a60065b | 2365 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2366 | "legacy insert event head", test_legacy_insert_event_head |
kadonotakashi | 0:8fdf9a60065b | 2367 | ), |
kadonotakashi | 0:8fdf9a60065b | 2368 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2369 | "legacy insert event tail", test_legacy_insert_event_tail |
kadonotakashi | 0:8fdf9a60065b | 2370 | ), |
kadonotakashi | 0:8fdf9a60065b | 2371 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2372 | "legacy insert event multiple overflow", |
kadonotakashi | 0:8fdf9a60065b | 2373 | test_legacy_insert_event_multiple_overflow |
kadonotakashi | 0:8fdf9a60065b | 2374 | ), |
kadonotakashi | 0:8fdf9a60065b | 2375 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2376 | "test_legacy_insert_event_multiple_random", |
kadonotakashi | 0:8fdf9a60065b | 2377 | test_legacy_insert_event_multiple_random |
kadonotakashi | 0:8fdf9a60065b | 2378 | ), |
kadonotakashi | 0:8fdf9a60065b | 2379 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2380 | "test_insert_event_us_outside_overflow_range", |
kadonotakashi | 0:8fdf9a60065b | 2381 | test_insert_event_us_outside_overflow_range |
kadonotakashi | 0:8fdf9a60065b | 2382 | ), |
kadonotakashi | 0:8fdf9a60065b | 2383 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2384 | "test_insert_event_us_in_overflow_range", |
kadonotakashi | 0:8fdf9a60065b | 2385 | test_insert_event_us_in_overflow_range |
kadonotakashi | 0:8fdf9a60065b | 2386 | ), |
kadonotakashi | 0:8fdf9a60065b | 2387 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2388 | "test_insert_event_us_underflow", test_insert_event_us_underflow |
kadonotakashi | 0:8fdf9a60065b | 2389 | ), |
kadonotakashi | 0:8fdf9a60065b | 2390 | MAKE_TEST_CASE("test_insert_event_us_head", test_insert_event_us_head), |
kadonotakashi | 0:8fdf9a60065b | 2391 | MAKE_TEST_CASE("test_insert_event_us_tail", test_insert_event_us_tail), |
kadonotakashi | 0:8fdf9a60065b | 2392 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2393 | "test_insert_event_us_multiple_random", |
kadonotakashi | 0:8fdf9a60065b | 2394 | test_insert_event_us_multiple_random |
kadonotakashi | 0:8fdf9a60065b | 2395 | ), |
kadonotakashi | 0:8fdf9a60065b | 2396 | MAKE_TEST_CASE("test_remove_event_tail", test_remove_event_tail), |
kadonotakashi | 0:8fdf9a60065b | 2397 | MAKE_TEST_CASE("test_remove_event_head", test_remove_event_head), |
kadonotakashi | 0:8fdf9a60065b | 2398 | MAKE_TEST_CASE("test_remove_event_invalid", test_remove_event_invalid), |
kadonotakashi | 0:8fdf9a60065b | 2399 | MAKE_TEST_CASE("test_remove_random", test_remove_random), |
kadonotakashi | 0:8fdf9a60065b | 2400 | MAKE_TEST_CASE("update overflow guard", test_overflow_event_update), |
kadonotakashi | 0:8fdf9a60065b | 2401 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2402 | "update overflow guard in case of spurious interrupt", |
kadonotakashi | 0:8fdf9a60065b | 2403 | test_overflow_event_update_when_spurious_interrupt |
kadonotakashi | 0:8fdf9a60065b | 2404 | ), |
kadonotakashi | 0:8fdf9a60065b | 2405 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2406 | "test_irq_handler_single_event", test_irq_handler_single_event |
kadonotakashi | 0:8fdf9a60065b | 2407 | ), |
kadonotakashi | 0:8fdf9a60065b | 2408 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2409 | "test_irq_handler_single_event_spurious", |
kadonotakashi | 0:8fdf9a60065b | 2410 | test_irq_handler_single_event_spurious |
kadonotakashi | 0:8fdf9a60065b | 2411 | ), |
kadonotakashi | 0:8fdf9a60065b | 2412 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2413 | "test_irq_handler_multiple_event_multiple_dequeue", |
kadonotakashi | 0:8fdf9a60065b | 2414 | test_irq_handler_multiple_event_multiple_dequeue |
kadonotakashi | 0:8fdf9a60065b | 2415 | ), |
kadonotakashi | 0:8fdf9a60065b | 2416 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2417 | "test_irq_handler_multiple_event_single_dequeue_overflow", |
kadonotakashi | 0:8fdf9a60065b | 2418 | test_irq_handler_multiple_event_single_dequeue_overflow |
kadonotakashi | 0:8fdf9a60065b | 2419 | ), |
kadonotakashi | 0:8fdf9a60065b | 2420 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2421 | "test_irq_handler_multiple_event_single_dequeue", |
kadonotakashi | 0:8fdf9a60065b | 2422 | test_irq_handler_multiple_event_single_dequeue |
kadonotakashi | 0:8fdf9a60065b | 2423 | ), |
kadonotakashi | 0:8fdf9a60065b | 2424 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2425 | "test_irq_handler_insert_immediate_in_irq", |
kadonotakashi | 0:8fdf9a60065b | 2426 | test_irq_handler_insert_immediate_in_irq |
kadonotakashi | 0:8fdf9a60065b | 2427 | ), |
kadonotakashi | 0:8fdf9a60065b | 2428 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2429 | "test_irq_handler_insert_non_immediate_in_irq", |
kadonotakashi | 0:8fdf9a60065b | 2430 | test_irq_handler_insert_non_immediate_in_irq |
kadonotakashi | 0:8fdf9a60065b | 2431 | ), |
kadonotakashi | 0:8fdf9a60065b | 2432 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2433 | "test_set_interrupt_past_time", |
kadonotakashi | 0:8fdf9a60065b | 2434 | test_set_interrupt_past_time |
kadonotakashi | 0:8fdf9a60065b | 2435 | ), |
kadonotakashi | 0:8fdf9a60065b | 2436 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2437 | "test_set_interrupt_past_time_with_delay", |
kadonotakashi | 0:8fdf9a60065b | 2438 | test_set_interrupt_past_time_with_delay |
kadonotakashi | 0:8fdf9a60065b | 2439 | ), |
kadonotakashi | 0:8fdf9a60065b | 2440 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2441 | "test_frequencies_and_masks", |
kadonotakashi | 0:8fdf9a60065b | 2442 | test_over_frequency_and_width<test_frequencies_and_masks> |
kadonotakashi | 0:8fdf9a60065b | 2443 | ), |
kadonotakashi | 0:8fdf9a60065b | 2444 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2445 | "test_ticker_max_value", |
kadonotakashi | 0:8fdf9a60065b | 2446 | test_ticker_max_value |
kadonotakashi | 0:8fdf9a60065b | 2447 | ), |
kadonotakashi | 0:8fdf9a60065b | 2448 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2449 | "test_match_interval_passed", |
kadonotakashi | 0:8fdf9a60065b | 2450 | test_match_interval_passed |
kadonotakashi | 0:8fdf9a60065b | 2451 | ), |
kadonotakashi | 0:8fdf9a60065b | 2452 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2453 | "test_match_interval_passed_table", |
kadonotakashi | 0:8fdf9a60065b | 2454 | test_match_interval_passed_table |
kadonotakashi | 0:8fdf9a60065b | 2455 | ), |
kadonotakashi | 0:8fdf9a60065b | 2456 | MAKE_TEST_CASE( |
kadonotakashi | 0:8fdf9a60065b | 2457 | "test_suspend_resume", |
kadonotakashi | 0:8fdf9a60065b | 2458 | test_suspend_resume |
kadonotakashi | 0:8fdf9a60065b | 2459 | ) |
kadonotakashi | 0:8fdf9a60065b | 2460 | }; |
kadonotakashi | 0:8fdf9a60065b | 2461 | |
kadonotakashi | 0:8fdf9a60065b | 2462 | static utest::v1::status_t greentea_test_setup(const size_t number_of_cases) |
kadonotakashi | 0:8fdf9a60065b | 2463 | { |
kadonotakashi | 0:8fdf9a60065b | 2464 | GREENTEA_SETUP(60, "default_auto"); |
kadonotakashi | 0:8fdf9a60065b | 2465 | return verbose_test_setup_handler(number_of_cases); |
kadonotakashi | 0:8fdf9a60065b | 2466 | } |
kadonotakashi | 0:8fdf9a60065b | 2467 | |
kadonotakashi | 0:8fdf9a60065b | 2468 | int main() |
kadonotakashi | 0:8fdf9a60065b | 2469 | { |
kadonotakashi | 0:8fdf9a60065b | 2470 | Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); |
kadonotakashi | 0:8fdf9a60065b | 2471 | return !Harness::run(specification); |
kadonotakashi | 0:8fdf9a60065b | 2472 | } |