Skip to content

Ticker tests fix #5971

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

Merged
merged 2 commits into from
Feb 8, 2018
Merged

Ticker tests fix #5971

merged 2 commits into from
Feb 8, 2018

Conversation

maciejbocianski
Copy link
Contributor

@maciejbocianski maciejbocianski commented Jan 30, 2018

Description

This PR contains fix for mbed_drivers-ticker tests.

Despite the test was always green there was hidden bug in test_case_2x_callbacks subtest detected in #5955 and #5892.

In effect of this bug (source code 1):

  • ticker_callback_1_switch_to_2 was called only once
  • ticker2 was never been fired because it was repeatedly detached just before fire and attached again

Fix for this bug (source code 2) showed that time measure with repeatedly rescheduled ticker is not accurate. When we use ticker without rescheduling (like in test_case_1x_ticker) ticker callback is executed within ticker interval time - not extra time is added to ticker interval until the callback execution time is less then ticker interval time.

Test test_case_2x_callbacks (after fix - source code 2) at each interval(callback call) reschedules ticker (call detach() an attach_us()) what cause that the time between consecutive callback calls is not 1ms but 1ms + time needed to call the callback and attach new one.

So the cross-call fix, fixed the algorithm but caused the test inaccurate.

Finally the two tickers test was redesigned and now it just uses two tickers to update counter alternatively every 1ms without rescheduling

// source code 1
void ticker_callback_1_switch_to_2(void)
{
    ++callback_trigger_count;
    // If ticker is NULL then it is being or has been deleted
    if (ticker1) {
        ticker1->detach();
        ticker1->attach_us(ticker_callback_2_switch_to_1, ONE_MILLI_SEC);
    }
    switch_led1_state();
}

void ticker_callback_2_switch_to_1(void)
{
    ++callback_trigger_count;
    // If ticker is NULL then it is being or has been deleted
    if (ticker2) {
        ticker2->detach();
        ticker2->attach_us(ticker_callback_1_switch_to_2, ONE_MILLI_SEC);
    }
    switch_led2_state();
}

void test_case_2x_callbacks()
{
    ...
    ticker1->attach_us(ticker_callback_1_switch_to_2, ONE_MILLI_SEC);
    ...
}
// source code 2
void ticker_callback_1_switch_to_2(void)
{
    ++callback_trigger_count;
    // If ticker is NULL then it is being or has been deleted
    if (ticker1) {
        ticker1->detach();
    }
    if (ticker2) {
        ticker2->attach_us(ticker_callback_2_switch_to_1, ONE_MILLI_SEC);
    }
    switch_led1_state();
}

void ticker_callback_2_switch_to_1(void)
{
    ++callback_trigger_count;
    // If ticker is NULL then it is being or has been deleted
    if (ticker2) {
        ticker2->detach();
    }
    if (ticker1) {
        ticker1->attach_us(ticker_callback_1_switch_to_2, ONE_MILLI_SEC);
    }
    switch_led2_state();
}

Status

READY

Migrations

NO

This commit fixes ticker cross-schedule bug in test_case_2x_callbacks subtest

In effect of this bug:
    ticker_callback_1_switch_to_2 was called only once
    ticker2 was never been fired because it was repeatedly detached just before fire and attached again
test_case_2x_callbacks test was redesigned to eliminate ticker rescheduling and improve time mesure accuracy.

Constant ticker rescheduling (detach()/attach_us() calls)
was causing the gap between consecutive callback calls was not exact 1ms
but 1ms + time needed to call the callback and attach new one.
New design just uses two tickers to update counter alternatively every 1ms without rescheduling them
@drewcassidy
Copy link
Contributor

Great, this fixes the issue of test never completing.

only problem (which should probably go in its own issue) is that the tests will occasionally fail on nRF51 boards when using the internal RC (tested with an nRF51-DK). I wonder if the tolerance shouldnt be increased for those targets since the RC clock is never going to match the accuracy of the external crystal

@maciejbocianski
Copy link
Contributor Author

@drewcassidy usually tests are designed and run for default targets configuration so there is nothing unusual that test is failing if we change configuration. Especially when we use oscillator with lower accuracy then assumed by test designer.

If we increase test tolerance then more configurations will pass but test will be less reliable

@0xc0170 @bulislaw @jamesbeyond

@drewcassidy
Copy link
Contributor

drewcassidy commented Jan 31, 2018

Log here: https://gist.github.com/anonymous/4873033bb990e29f3f321b5f61c1c9a4, usually the result is closer to the expected value. This is on an nRF51-DK with the RC clock selected with the app_config.json file

This should probably move back to #5892, which is attempting to add a target using the nRF51822 using the RC clock. I didnt mean to suggest increasing the tolerance universally, but as something based on the configuration. I'm not sure if thats set in the test and can just use an #ifdef or if it would require extra python tooling

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 31, 2018

Thanks @drewcassidy , we will look into this to find a way to set tolerance better

@drewcassidy
Copy link
Contributor

I checked the nRF51822 datasheet again and the internal RC clock SHOULD have an accuracy of ±250ppm, far less than the ±5% its currently failing to reach. Either the datasheet is wildly off, I have multiple defective chips, or there is something wrong with the way this test is being performed

@bulislaw bulislaw requested a review from jamesbeyond February 5, 2018 12:13
@0xc0170 0xc0170 mentioned this pull request Feb 5, 2018
2 tasks
@drewcassidy drewcassidy mentioned this pull request Feb 6, 2018
3 tasks
@0xc0170
Copy link
Contributor

0xc0170 commented Feb 6, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Feb 6, 2018

Build : SUCCESS

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

Triggering tests

/morph test
/morph uvisor-test
/morph export-build

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 6, 2018

There is target addition in #5996, and having the issue with ticker, but solved with this PR.

This should probably move back to #5892, which is attempting to add a target using the nRF51822 using the RC clock. I didnt mean to suggest increasing the tolerance universally, but as something based on the configuration. I'm not sure if thats set in the test and can just use an #ifdef or if it would require extra python tooling

We will review this test fix, and we should still look at why it still fails for your setup, but as you mentioned, might move to 5892 (in case this goes in, you can review the test with your new target addition, and resolve the issue there).

Restarting

/morph uvisor-test

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 6, 2018

/morph uvisor-test

@mbed-ci
Copy link

mbed-ci commented Feb 6, 2018

@mbed-ci
Copy link

mbed-ci commented Feb 6, 2018

@cmonr
Copy link
Contributor

cmonr commented Feb 6, 2018

/morph uvisor-test

1 similar comment
@cmonr
Copy link
Contributor

cmonr commented Feb 6, 2018

/morph uvisor-test

Copy link
Contributor

@jamesbeyond jamesbeyond left a comment

Choose a reason for hiding this comment

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

looks good!

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.

6 participants