Skip to content

Commit 5a833ff

Browse files
committed
Add fix for Timer test - provide missing get_info ticker interface function
1 parent 20d93bf commit 5a833ff

File tree

1 file changed

+40
-28
lines changed

1 file changed

+40
-28
lines changed

TESTS/mbedmicro-rtos-mbed/timer/main.cpp

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ static const int delta_sys_clk_us = ((int) (TOLERANCE_FACTOR / (float)SystemCore
5353
#define DELTA_S ((float)delta_sys_clk_us/US_PER_SEC)
5454
#define DELTA_MS 1
5555

56+
#define TICKER_FREQ_1MHZ 1000000
57+
#define TICKER_BITS 32
58+
5659
static Timer *p_timer = NULL;
5760

5861
/* Global variable used to simulate passage of time
5962
* in case when timer which uses user ticker is tested.
6063
*/
61-
static uint32_t curr_ticker_us_val;
64+
static uint32_t curr_ticker_ticks_val;
6265

6366
/* User ticker interface function. */
6467
static void stub_interface_init()
@@ -71,7 +74,7 @@ static void stub_interface_init()
7174
static uint32_t stub_ticker_read(void)
7275
{
7376
/* Simulate elapsed time. */
74-
return curr_ticker_us_val;
77+
return curr_ticker_ticks_val;
7578
}
7679

7780
/* User ticker interface function. */
@@ -98,6 +101,14 @@ static void stub_fire_interrupt(void)
98101
/* do nothing. */
99102
}
100103

104+
ticker_info_t info =
105+
{ TICKER_FREQ_1MHZ, TICKER_BITS };
106+
107+
const ticker_info_t * stub_get_info(void)
108+
{
109+
return &info;
110+
}
111+
101112
/* User ticker event queue. */
102113
static ticker_event_queue_t my_events = { 0 };
103114

@@ -109,6 +120,7 @@ static const ticker_interface_t us_interface = {
109120
.clear_interrupt = stub_clear_interrupt,
110121
.set_interrupt = stub_set_interrupt,
111122
.fire_interrupt = stub_fire_interrupt,
123+
.get_info = stub_get_info,
112124
};
113125

114126
/* User ticker data structure. */
@@ -195,7 +207,7 @@ void test_timer_creation_os_ticker()
195207
* creation.
196208
*
197209
* Note: this function assumes that Timer uses user/fake ticker
198-
* which returns time value provided in curr_ticker_us_val
210+
* which returns time value provided in curr_ticker_ticks_val
199211
* global variable.
200212
*
201213
* Given Timer has been successfully created.
@@ -206,7 +218,7 @@ void test_timer_creation_user_ticker()
206218
{
207219
/* For timer which is using user ticker simulate timer
208220
* creation time (irrelevant in case of os ticker). */
209-
curr_ticker_us_val = 10000;
221+
curr_ticker_ticks_val = 10000;
210222

211223
/* Check results. */
212224
TEST_ASSERT_EQUAL_FLOAT(0, p_timer->read());
@@ -216,7 +228,7 @@ void test_timer_creation_user_ticker()
216228

217229
/* Simulate that 10 ms has elapsed.
218230
* After that operation timer read routines should still return 0. */
219-
curr_ticker_us_val += 10000;
231+
curr_ticker_ticks_val += 10000;
220232

221233
/* Check results. */
222234
TEST_ASSERT_EQUAL_FLOAT(0, p_timer->read());
@@ -229,7 +241,7 @@ void test_timer_creation_user_ticker()
229241
* read_high_resolution_us() functions returns valid values.
230242
*
231243
* Note: this function assumes that Timer uses user/fake ticker
232-
* which returns time value provided in curr_ticker_us_val
244+
* which returns time value provided in curr_ticker_ticks_val
233245
* global variable.
234246
*
235247
* Given Timer has been successfully created and
@@ -241,13 +253,13 @@ void test_timer_creation_user_ticker()
241253
void test_timer_time_accumulation_user_ticker()
242254
{
243255
/* Simulate that current time is equal to 0 us. */
244-
curr_ticker_us_val = 0;
256+
curr_ticker_ticks_val = 0;
245257

246258
/* Start the timer. */
247259
p_timer->start();
248260

249261
/* -- Simulate that current time is equal to 1 us -- */
250-
curr_ticker_us_val = 1;
262+
curr_ticker_ticks_val = 1;
251263

252264
/* Stop the timer. */
253265
p_timer->stop();
@@ -259,13 +271,13 @@ void test_timer_time_accumulation_user_ticker()
259271
TEST_ASSERT_EQUAL(1, p_timer->read_high_resolution_us());
260272

261273
/* Simulate that 100 us has elapsed between stop and start. */
262-
curr_ticker_us_val = 101;
274+
curr_ticker_ticks_val = 101;
263275

264276
/* Start the timer. */
265277
p_timer->start();
266278

267279
/* -- Simulate that current time is equal to 225 us -- */
268-
curr_ticker_us_val = 225;
280+
curr_ticker_ticks_val = 225;
269281

270282
/* Stop the timer. */
271283
p_timer->stop();
@@ -277,13 +289,13 @@ void test_timer_time_accumulation_user_ticker()
277289
TEST_ASSERT_EQUAL(125, p_timer->read_high_resolution_us());
278290

279291
/* Simulate that 100 us has elapsed between stop and start. */
280-
curr_ticker_us_val = 325;
292+
curr_ticker_ticks_val = 325;
281293

282294
/* Start the timer. */
283295
p_timer->start();
284296

285297
/* -- Simulate that current time is equal to 1200 us -- */
286-
curr_ticker_us_val = 1200;
298+
curr_ticker_ticks_val = 1200;
287299

288300
/* Stop the timer. */
289301
p_timer->stop();
@@ -295,13 +307,13 @@ void test_timer_time_accumulation_user_ticker()
295307
TEST_ASSERT_EQUAL(1000, p_timer->read_high_resolution_us());
296308

297309
/* Simulate that 100 us has elapsed between stop and start. */
298-
curr_ticker_us_val = 1300;
310+
curr_ticker_ticks_val = 1300;
299311

300312
/* Start the timer. */
301313
p_timer->start();
302314

303315
/* -- Simulate that current time is equal to 125300 us -- */
304-
curr_ticker_us_val = 125300;
316+
curr_ticker_ticks_val = 125300;
305317

306318
/* Stop the timer. */
307319
p_timer->stop();
@@ -313,13 +325,13 @@ void test_timer_time_accumulation_user_ticker()
313325
TEST_ASSERT_EQUAL(125000, p_timer->read_high_resolution_us());
314326

315327
/* Simulate that 100 us has elapsed between stop and start. */
316-
curr_ticker_us_val = 125400;
328+
curr_ticker_ticks_val = 125400;
317329

318330
/* Start the timer. */
319331
p_timer->start();
320332

321333
/* -- Simulate that current time is equal to 1000400 us -- */
322-
curr_ticker_us_val = 1000400;
334+
curr_ticker_ticks_val = 1000400;
323335

324336
/* Stop the timer. */
325337
p_timer->stop();
@@ -331,13 +343,13 @@ void test_timer_time_accumulation_user_ticker()
331343
TEST_ASSERT_EQUAL(1000000, p_timer->read_high_resolution_us());
332344

333345
/* Simulate that 100 us has elapsed between stop and start. */
334-
curr_ticker_us_val = 1000500;
346+
curr_ticker_ticks_val = 1000500;
335347

336348
/* Start the timer. */
337349
p_timer->start();
338350

339351
/* -- Simulate that current time is equal to 125000500 us -- */
340-
curr_ticker_us_val = 125000500;
352+
curr_ticker_ticks_val = 125000500;
341353

342354
/* Stop the timer. */
343355
p_timer->stop();
@@ -349,7 +361,7 @@ void test_timer_time_accumulation_user_ticker()
349361
TEST_ASSERT_EQUAL(125000000, p_timer->read_high_resolution_us());
350362

351363
/* Simulate that 100 us has elapsed between stop and start. */
352-
curr_ticker_us_val = 125000600;
364+
curr_ticker_ticks_val = 125000600;
353365

354366
/* Start the timer. */
355367
p_timer->start();
@@ -361,7 +373,7 @@ void test_timer_time_accumulation_user_ticker()
361373
* while timers are based on 32-bit signed int microsecond counters,
362374
* so timers can only count up to a maximum of 2^31-1 microseconds i.e.
363375
* 2147483647 us (about 35 minutes). */
364-
curr_ticker_us_val = 2147484247;
376+
curr_ticker_ticks_val = 2147484247;
365377

366378
/* Stop the timer. */
367379
p_timer->stop();
@@ -531,13 +543,13 @@ void test_timer_reset_user_ticker()
531543
{
532544
/* For timer which is using user ticker simulate set current
533545
* time (irrelevant in case of os ticker). */
534-
curr_ticker_us_val = 0;
546+
curr_ticker_ticks_val = 0;
535547

536548
/* First measure 10 ms delay. */
537549
p_timer->start();
538550

539551
/* Simulate that 10 ms have elapsed. */
540-
curr_ticker_us_val = 10000;
552+
curr_ticker_ticks_val = 10000;
541553

542554
/* Stop the timer. */
543555
p_timer->stop();
@@ -555,7 +567,7 @@ void test_timer_reset_user_ticker()
555567
p_timer->start();
556568

557569
/* Simulate that 20 ms have elapsed. */
558-
curr_ticker_us_val = 30000;
570+
curr_ticker_ticks_val = 30000;
559571

560572
/* Stop the timer. */
561573
p_timer->stop();
@@ -613,19 +625,19 @@ void test_timer_start_started_timer_user_ticker()
613625
{
614626
/* For timer which is using user ticker set current
615627
* time (irrelevant in case of os ticker). */
616-
curr_ticker_us_val = 0;
628+
curr_ticker_ticks_val = 0;
617629

618630
/* Start the timer. */
619631
p_timer->start();
620632

621633
/* Simulate that 10 ms have elapsed. */
622-
curr_ticker_us_val = 10000;
634+
curr_ticker_ticks_val = 10000;
623635

624636
/* Now start timer again. */
625637
p_timer->start();
626638

627639
/* Simulate that 20 ms have elapsed. */
628-
curr_ticker_us_val = 30000;
640+
curr_ticker_ticks_val = 30000;
629641

630642
/* Stop the timer. */
631643
p_timer->stop();
@@ -674,13 +686,13 @@ void test_timer_float_operator_user_ticker()
674686
{
675687
/* For timer which is using user ticker set current
676688
* time (irrelevant in case of os ticker). */
677-
curr_ticker_us_val = 0;
689+
curr_ticker_ticks_val = 0;
678690

679691
/* Start the timer. */
680692
p_timer->start();
681693

682694
/* Simulate that 10 ms have elapsed. */
683-
curr_ticker_us_val = 10000;
695+
curr_ticker_ticks_val = 10000;
684696

685697
/* Stop the timer. */
686698
p_timer->stop();

0 commit comments

Comments
 (0)