Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fix for Timer test - provide missing get_info ticker interface fu… #5325

Merged
merged 1 commit into from Oct 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 40 additions & 28 deletions TESTS/mbedmicro-rtos-mbed/timer/main.cpp
Expand Up @@ -53,12 +53,15 @@ static const int delta_sys_clk_us = ((int) (TOLERANCE_FACTOR / (float)SystemCore
#define DELTA_S ((float)delta_sys_clk_us/US_PER_SEC)
#define DELTA_MS 1

#define TICKER_FREQ_1MHZ 1000000
#define TICKER_BITS 32

static Timer *p_timer = NULL;

/* Global variable used to simulate passage of time
* in case when timer which uses user ticker is tested.
*/
static uint32_t curr_ticker_us_val;
static uint32_t curr_ticker_ticks_val;

/* User ticker interface function. */
static void stub_interface_init()
Expand All @@ -71,7 +74,7 @@ static void stub_interface_init()
static uint32_t stub_ticker_read(void)
{
/* Simulate elapsed time. */
return curr_ticker_us_val;
return curr_ticker_ticks_val;
}

/* User ticker interface function. */
Expand All @@ -98,6 +101,14 @@ static void stub_fire_interrupt(void)
/* do nothing. */
}

ticker_info_t info =
{ TICKER_FREQ_1MHZ, TICKER_BITS };

const ticker_info_t * stub_get_info(void)
{
return &info;
}

/* User ticker event queue. */
static ticker_event_queue_t my_events = { 0 };

Expand All @@ -109,6 +120,7 @@ static const ticker_interface_t us_interface = {
.clear_interrupt = stub_clear_interrupt,
.set_interrupt = stub_set_interrupt,
.fire_interrupt = stub_fire_interrupt,
.get_info = stub_get_info,
};

/* User ticker data structure. */
Expand Down Expand Up @@ -195,7 +207,7 @@ void test_timer_creation_os_ticker()
* creation.
*
* Note: this function assumes that Timer uses user/fake ticker
* which returns time value provided in curr_ticker_us_val
* which returns time value provided in curr_ticker_ticks_val
* global variable.
*
* Given Timer has been successfully created.
Expand All @@ -206,7 +218,7 @@ void test_timer_creation_user_ticker()
{
/* For timer which is using user ticker simulate timer
* creation time (irrelevant in case of os ticker). */
curr_ticker_us_val = 10000;
curr_ticker_ticks_val = 10000;

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

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

/* Check results. */
TEST_ASSERT_EQUAL_FLOAT(0, p_timer->read());
Expand All @@ -229,7 +241,7 @@ void test_timer_creation_user_ticker()
* read_high_resolution_us() functions returns valid values.
*
* Note: this function assumes that Timer uses user/fake ticker
* which returns time value provided in curr_ticker_us_val
* which returns time value provided in curr_ticker_ticks_val
* global variable.
*
* Given Timer has been successfully created and
Expand All @@ -241,13 +253,13 @@ void test_timer_creation_user_ticker()
void test_timer_time_accumulation_user_ticker()
{
/* Simulate that current time is equal to 0 us. */
curr_ticker_us_val = 0;
curr_ticker_ticks_val = 0;

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

/* -- Simulate that current time is equal to 1 us -- */
curr_ticker_us_val = 1;
curr_ticker_ticks_val = 1;

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

/* Simulate that 100 us has elapsed between stop and start. */
curr_ticker_us_val = 101;
curr_ticker_ticks_val = 101;

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

/* -- Simulate that current time is equal to 225 us -- */
curr_ticker_us_val = 225;
curr_ticker_ticks_val = 225;

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

/* Simulate that 100 us has elapsed between stop and start. */
curr_ticker_us_val = 325;
curr_ticker_ticks_val = 325;

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

/* -- Simulate that current time is equal to 1200 us -- */
curr_ticker_us_val = 1200;
curr_ticker_ticks_val = 1200;

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

/* Simulate that 100 us has elapsed between stop and start. */
curr_ticker_us_val = 1300;
curr_ticker_ticks_val = 1300;

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

/* -- Simulate that current time is equal to 125300 us -- */
curr_ticker_us_val = 125300;
curr_ticker_ticks_val = 125300;

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

/* Simulate that 100 us has elapsed between stop and start. */
curr_ticker_us_val = 125400;
curr_ticker_ticks_val = 125400;

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

/* -- Simulate that current time is equal to 1000400 us -- */
curr_ticker_us_val = 1000400;
curr_ticker_ticks_val = 1000400;

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

/* Simulate that 100 us has elapsed between stop and start. */
curr_ticker_us_val = 1000500;
curr_ticker_ticks_val = 1000500;

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

/* -- Simulate that current time is equal to 125000500 us -- */
curr_ticker_us_val = 125000500;
curr_ticker_ticks_val = 125000500;

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

/* Simulate that 100 us has elapsed between stop and start. */
curr_ticker_us_val = 125000600;
curr_ticker_ticks_val = 125000600;

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

/* Stop the timer. */
p_timer->stop();
Expand Down Expand Up @@ -531,13 +543,13 @@ void test_timer_reset_user_ticker()
{
/* For timer which is using user ticker simulate set current
* time (irrelevant in case of os ticker). */
curr_ticker_us_val = 0;
curr_ticker_ticks_val = 0;

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

/* Simulate that 10 ms have elapsed. */
curr_ticker_us_val = 10000;
curr_ticker_ticks_val = 10000;

/* Stop the timer. */
p_timer->stop();
Expand All @@ -555,7 +567,7 @@ void test_timer_reset_user_ticker()
p_timer->start();

/* Simulate that 20 ms have elapsed. */
curr_ticker_us_val = 30000;
curr_ticker_ticks_val = 30000;

/* Stop the timer. */
p_timer->stop();
Expand Down Expand Up @@ -613,19 +625,19 @@ void test_timer_start_started_timer_user_ticker()
{
/* For timer which is using user ticker set current
* time (irrelevant in case of os ticker). */
curr_ticker_us_val = 0;
curr_ticker_ticks_val = 0;

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

/* Simulate that 10 ms have elapsed. */
curr_ticker_us_val = 10000;
curr_ticker_ticks_val = 10000;

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

/* Simulate that 20 ms have elapsed. */
curr_ticker_us_val = 30000;
curr_ticker_ticks_val = 30000;

/* Stop the timer. */
p_timer->stop();
Expand Down Expand Up @@ -674,13 +686,13 @@ void test_timer_float_operator_user_ticker()
{
/* For timer which is using user ticker set current
* time (irrelevant in case of os ticker). */
curr_ticker_us_val = 0;
curr_ticker_ticks_val = 0;

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

/* Simulate that 10 ms have elapsed. */
curr_ticker_us_val = 10000;
curr_ticker_ticks_val = 10000;

/* Stop the timer. */
p_timer->stop();
Expand Down