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