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

tests-mbed_hal-sleep_manager: fix counter wraparound handling #12519

Merged
merged 1 commit into from
Feb 27, 2020

Conversation

mprse
Copy link
Contributor

@mprse mprse commented Feb 26, 2020

Summary of changes

This PR is a fix for Issue: #12373.

The test needs to be fixed since there is a mismatch while handling counter wraparound in test_sleep_auto test case.
In the test timestamps in ticks are first converted to us and then while counting the time difference wraparound is handled (us and ticks fields are mismatched). The ticker wraparound case must be handled in the field of ticks, and then the ticks difference converted to us.

In the following line:
us_diff1 = (us_ts1 <= us_ts2) ? (us_ts2 - us_ts1) : (us_ticker_mask - us_ts1 + us_ts2 + 1);

us_ts1 - timestamp before sleep in us.
us_ts2 - timestamp after sleep in us.

us_ticker_mask - max ticks count (depending on ticker width).

So when wraparound is detected we have mismatched arithmetic operations (ticks and us).

Test results:


| target       | platform_name | test suite                   | test case                                       | passed | failed | result | elapsed_time (sec) |
|--------------|---------------|------------------------------|-------------------------------------------------|--------|--------|--------|--------------------|
| K64F-GCC_ARM | K64F          | tests-mbed_hal-sleep_manager | deep sleep lock/unlock                          | 1      | 0      | OK     | 0.06               |
| K64F-GCC_ARM | K64F          | tests-mbed_hal-sleep_manager | deep sleep lock/unlock test_check               | 1      | 0      | OK     | 3.13               |
| K64F-GCC_ARM | K64F          | tests-mbed_hal-sleep_manager | deep sleep locked USHRT_MAX times               | 1      | 0      | OK     | 0.12               |
| K64F-GCC_ARM | K64F          | tests-mbed_hal-sleep_manager | sleep_auto calls sleep/deep sleep based on lock | 1      | 0      | OK     | 0.27               |
mbedgt: test case results: 4 OK



| target                  | platform_name   | test suite                   | test case                                       | passed | failed | result | elapsed_time (sec) |
|-------------------------|-----------------|------------------------------|-------------------------------------------------|--------|--------|--------|--------------------|
| EFM32GG_STK3700-GCC_ARM | EFM32GG_STK3700 | tests-mbed_hal-sleep_manager | deep sleep lock/unlock                          | 1      | 0      | OK     | 0.0                |
| EFM32GG_STK3700-GCC_ARM | EFM32GG_STK3700 | tests-mbed_hal-sleep_manager | deep sleep lock/unlock test_check               | 1      | 0      | OK     | 3.1                |
| EFM32GG_STK3700-GCC_ARM | EFM32GG_STK3700 | tests-mbed_hal-sleep_manager | deep sleep locked USHRT_MAX times               | 1      | 0      | OK     | 0.16               |
| EFM32GG_STK3700-GCC_ARM | EFM32GG_STK3700 | tests-mbed_hal-sleep_manager | sleep_auto calls sleep/deep sleep based on lock | 1      | 0      | OK     | 0.2                |
mbedgt: test case results: 4 OK

| target                | platform_name | test suite                   | test case                                       | passed | failed | result | elapsed_time (sec) |
|-----------------------|---------------|------------------------------|-------------------------------------------------|--------|--------|--------|--------------------|
| NUCLEO_F429ZI-GCC_ARM | NUCLEO_F429ZI | tests-mbed_hal-sleep_manager | deep sleep lock/unlock                          | 1      | 0      | OK     | 0.05               |
| NUCLEO_F429ZI-GCC_ARM | NUCLEO_F429ZI | tests-mbed_hal-sleep_manager | deep sleep lock/unlock test_check               | 1      | 0      | OK     | 3.35               |
| NUCLEO_F429ZI-GCC_ARM | NUCLEO_F429ZI | tests-mbed_hal-sleep_manager | deep sleep locked USHRT_MAX times               | 1      | 0      | OK     | 0.11               |
| NUCLEO_F429ZI-GCC_ARM | NUCLEO_F429ZI | tests-mbed_hal-sleep_manager | sleep_auto calls sleep/deep sleep based on lock | 1      | 0      | OK     | 0.28               |
mbedgt: test case results: 4 OK

Impact of changes

Migration actions required

Documentation


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[X] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


@stevew817 @amq @fkjagodzinski

Copy link
Member

@fkjagodzinski fkjagodzinski left a comment

Choose a reason for hiding this comment

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

Thanks! 👍

@@ -141,7 +141,7 @@ void test_sleep_auto()
const ticker_info_t *lp_ticker_info = get_lp_ticker_data()->interface->get_info();
const unsigned lp_ticker_mask = ((1 << lp_ticker_info->bits) - 1);
const ticker_irq_handler_type lp_ticker_irq_handler_org = set_lp_ticker_irq_handler(lp_ticker_isr);
us_timestamp_t us_ts1, us_ts2, lp_ts1, lp_ts2, us_diff1, us_diff2, lp_diff1, lp_diff2;
unsigned int us_ts1, us_ts2, lp_ts1, lp_ts2, us_diff1, us_diff2, lp_diff1, lp_diff2;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
unsigned int us_ts1, us_ts2, lp_ts1, lp_ts2, us_diff1, us_diff2, lp_diff1, lp_diff2;
uint32_t us_ts1, us_ts2, lp_ts1, lp_ts2, us_diff1, us_diff2, lp_diff1, lp_diff2;

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.

There is a mismatch while handling counter wraparound in `test_sleep_auto` test case.
In the test timestamps in ticks are first converted to us and then while counting the time difference wraparound is handled (us and ticks fields are mismatched). The ticker wraparound case must be handled in the field of ticks, and then the difference converted to us.
@mprse mprse force-pushed the sleepmanaget_test_fix branch from a9763f4 to 42a9cc1 Compare February 26, 2020 13:05
@ciarmcom ciarmcom requested review from fkjagodzinski, stevew817 and a team February 26, 2020 14:00
@ciarmcom
Copy link
Member

@mprse, thank you for your changes.
@fkjagodzinski @stevew817 @ARMmbed/mbed-os-hal @ARMmbed/mbed-os-test @ARMmbed/mbed-os-maintainers please review.

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 27, 2020

CI started

@mergify mergify bot added needs: CI and removed needs: review labels Feb 27, 2020
@mbed-ci
Copy link

mbed-ci commented Feb 27, 2020

Test run: SUCCESS

Summary: 5 of 5 test jobs passed
Build number : 1
Build artifacts

@0xc0170 0xc0170 merged commit 981691f into ARMmbed:master Feb 27, 2020
@mergify mergify bot removed the ready for merge label Feb 27, 2020
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.

7 participants