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 test for Timer class. #4971

Merged
merged 1 commit into from
Oct 13, 2017
Merged

Add test for Timer class. #4971

merged 1 commit into from
Oct 13, 2017

Conversation

mprse
Copy link
Contributor

@mprse mprse commented Aug 24, 2017

Description

Add unit tests for Timer class.

Status

READY

Migrations

NO

Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments:

  • I wonder if the intermediary variables read_val, read_ms_val, read_us_val and read_hr_us_val are necessary. In my opinion, calling the timer functions in the assertion is clear enough.
  • The comment about the timer existence present in every test is unnecessary.
  • Would it be possible to test accumulation with the stub while moving the counter value between stop/start call.
  • Would it be possible to split unit test from integration tests (the tests using the real ticker).
  • The Timer class is underspecified and inconsistent regards to the unit returned by read* function, it would be interesting to specify behavior in boundary case and add test for these case.

static uint32_t curr_ticker_us_val;

/* User ticker interface function. */
static void my_interface_init()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my_ functions are stubs. I suggest replacing my_ prefix by stub_ prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

* system clock frequency = 32 678 Hz (~32 kHz) => 1 tick = 31.25 us.
* delta = truncate(31.25 * 10 + 5) = truncate(317.5) = 317 us.
*/
#define DELTA_SYS_CLK_US ((int)((1.0f / ((float)osKernelGetSysTimerFreq() / US_PER_SEC) ) * 10 + 5))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use a constant variable instead of a macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible, but then it would have to be a very large value (e.g. 500 us), to be able to successfully execute test on each board. It looks like the better option is to define delta value based on board clock frequency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant:

static const int delta_sys_clk_us = (...);

* ticker data provided by the user.
*
* */
utest::v1::status_t timer_user_ticker_setup_h(const Case *const source, const size_t index_of_case)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the suffix _h stands for ? _handler ? If so then given there is no such suffix define by greentea_*_handler I suggest to use the _handler suffix instead of its shortened form.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

*/
void test_timer_creation()
{
float read_val;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to declare variables at initialization point ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed - removed local variables to hold measured time. Instead call read function inside assertion.

read_hr_us_val = p_timer->read_high_resolution_us();

/* Check results. */
TEST_ASSERT_EQUAL(0, read_val);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read_val is a float, might be good to use the float assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

read_hr_us_val = p_timer->read_high_resolution_us();

/* Check results. */
TEST_ASSERT_EQUAL(0, read_val);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read_val is a float, might be good to use the float assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

/* Note that timers are based on 32-bit int microsecond counters,
* so can only time up to a maximum of 2^31-1 microseconds i.e.
* 2147483647 us (about 35 minutes). */
curr_ticker_us_val = 2147483647;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serious question, what is supposed to happens when curr_ticker_us_val.read returns a value outside the [0 : MAX_INT] range ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curr_ticker_us_val is of unsigned integer type. In case when the value would be greater than MAX_INT, then we have inconsistency. In such case read functions would return negative values.

I have assumed that the max tested measured time can not exceed MAX_INT based on information from mBed handbook (see Warning):
https://developer.mbed.org/handbook/Timer
https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/tasks/Timer/

According to the documentation Timer is dedicated to measure small times (between microseconds and seconds).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bulislaw Could you clarify the behavior of the Timer class when the time measured exceeds the value returned ?

There is a warning in the handbook but nothing in the class declaration. The range returned by read, read_ms, read_us and read_high_resolution_us is also unspecified. According to the warning in the handbook, the maximum value returned by read_ms will be 2147483 which is not very intuitive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, best would be to check how it actually works. Confirm it makes sense and update the docs/handbook.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bulislaw @pan- I created test based on documentation provided in handbook. So the boundary case for max measured time is MAX_INT. I agree that values returned by the read* functions are not very intuitive. Currently when measured time is equal to MAX_INT (2147483647) read* functions return the following values:
read(): 2147.483643 - ok
read_ms(): 2147483 - ok
read_us(): 2147483647 - ok
read_high_resolution_us(): 2147483647 - ok
When measured time is equal to MAX_INT+1 (2147483648), then we have the following results:
read(): -2147.483643 - wrong
read_ms(): 2147483 - ok
read_us(): -2147483648 - wrong
read_high_resolution_us(): 2147483648 - ok.

It is very strange that returned time can be negative, but warning in handbook informs about Timer time measurement limitations. On the other hand maybe we could modify Timer::read_us()
and Timer::read_ms() function declarations and change returned type to unsigned int. This way measured time limit would be increased and we would also rid of negative results.
In such case handbook and documents need to be also updated.

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 31, 2017

Please look at the failure in jenkins ci : Error: main.cpp@6,0: #5: cannot open source input file “timer.h”: No such file or directory

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 4, 2017

@mprse Bump

@mprse mprse force-pushed the test_timer branch 3 times, most recently from 8e11d6a to 4255a54 Compare September 14, 2017 05:51
@mprse
Copy link
Contributor Author

mprse commented Sep 14, 2017

@pan- @0xc0170 @bulislaw All issues have been fixed. Please re-review.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 21, 2017

I restarted jenkins CI, as the last failure is not available anymore to review, @mprse please review if it fails again

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 21, 2017

@pan- @0xc0170 @bulislaw All issues have been fixed. Please re-review.

adding @c1728p9

bump for review

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 26, 2017

retest uvisor

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 26, 2017

bump for review round !

@bulislaw
Copy link
Member

@pan- are you happy with the fixes?

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 27, 2017

retest uvisor

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 28, 2017

@pan- are you happy with the fixes?

bump

#define DELTA_US delta_sys_clk_us
#define DELTA_S ((float)delta_sys_clk_us/US_PER_SEC)

static Timer *p_timer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please initialize p_timer to NULL so the test in timer_user_ticker_setup_handler is valid.

* */
utest::v1::status_t cleanup_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t reason)
{
delete p_timer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please reset p_timer to NULL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@theotherjimmy
Copy link
Contributor

/morph test

1 similar comment
@mbed-bot
Copy link

/morph test

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1457

Test failed!

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1457

Test failed!

Output

mbed Build Number: 1462

Build failed!

@mbed-bot
Copy link

mbed-bot commented Oct 1, 2017

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1457

Test failed!

Output

mbed Build Number: 1462

Build failed!

Output

mbed Build Number: 1467

Test failed!

@mbed-bot
Copy link

mbed-bot commented Oct 1, 2017

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1457

Test failed!

Output

mbed Build Number: 1462

Build failed!

Output

mbed Build Number: 1467

Test failed!

Output

mbed Build Number: 1473

Test failed!

@mbed-bot
Copy link

mbed-bot commented Oct 2, 2017

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1457

Test failed!

Output

mbed Build Number: 1462

Build failed!

Output

mbed Build Number: 1467

Test failed!

Output

mbed Build Number: 1473

Test failed!

Output

mbed Build Number: 1478

Test failed!

@mbed-bot
Copy link

mbed-bot commented Oct 2, 2017

Result: ABORTED

Your command has finished executing! Here's what you wrote!

 /morph test

Output

mbed Build Number: 1457

Test failed!

Output

mbed Build Number: 1462

Build failed!

Output

mbed Build Number: 1467

Test failed!

Output

mbed Build Number: 1473

Test failed!

Output

mbed Build Number: 1478

Test failed!

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 2, 2017

@studavekar Just to be aware of cyclic running CI (it seems to me) ?

@mprse Please look at the failures, there are related to this patch

I aborted the last job

@studavekar
Copy link
Contributor

@0xc0170 the recursive trigger was due to an experimental scrip where bot triggered the aborted jobs, however when bot makes a comment of results it has a test trigger morph command in it causing recursive trigger.

this is disabled and we shouldn't see this now.

@mprse
Copy link
Contributor Author

mprse commented Oct 3, 2017

Increased measured time tolerance (for NRF51_DK).

@theotherjimmy
Copy link
Contributor

/morph test

@mbed-bot
Copy link

mbed-bot commented Oct 5, 2017

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1531

All builds and test passed!

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 7, 2017

/morph test-nightly

@mbed-bot
Copy link

mbed-bot commented Oct 8, 2017

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test-nightly

Output

mbed Build Number: 1543

All builds and test passed!

@theotherjimmy
Copy link
Contributor

We're going to make sure this is not flaky by running it a bunch.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 11, 2017

/morph test-nightly

@mbed-ci
Copy link

mbed-ci commented Oct 11, 2017

Build : SUCCESS

Build number : 101
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/4971/

Triggering tests

/test mbed-os

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test-nightly

Output

mbed Build Number: 1562

Build failed!

@mprse
Copy link
Contributor Author

mprse commented Oct 11, 2017

Result: FAILURE

It looks like there was IAR licence problem:
Fatal error[LMS001]: License check failed.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 11, 2017

@mprse The build trigger the test that is equal to nightly, wait for the next status, should be OK , license problem was resolved

@studavekar
Copy link
Contributor

studavekar commented Oct 11, 2017

Updated the status of "morph-test-nightly" with last passing run #4971 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants