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

Update sleep manager tests #7582

Merged
merged 8 commits into from Oct 10, 2018

Conversation

Projects
None yet
7 participants
@fkjagodzinski
Member

fkjagodzinski commented Jul 23, 2018

Description

Extended tests-mbed_hal-sleep_manager with:

  • deep sleep lock/unlock,
  • deep sleep locked USHRT_MAX times,
  • deep sleep locked more than USHRT_MAX times,
  • deep sleep unbalanced unlock,
  • sleep_auto calls sleep/deep sleep based on lock,
  • deep sleep lock/unlock test_check.

Updated tests-mbed_hal-sleep_manager and tests-mbed_hal-sleep_manager_racecondition test case docs and moved them to test header files.

Pull request type

[ ] Fix
[ ] Refactor
[ ] New target
[x] Feature
[ ] Breaking change

CC @c1728p9 @mprse @jamesbeyond @0xc0170

{
GREENTEA_SETUP(10, "default_auto");
// Suspend the RTOS kernel scheduler to prevent any OS interference.
osKernelSuspend();

This comment has been minimized.

@fkjagodzinski

fkjagodzinski Jul 23, 2018

Member

NOTE:
As @mprse pointed out, when #7524 is merged, this wait should be added here.

#if DEVICE_LPTICKER && (LPTICKER_DELAY_TICKS > 0)
    // After the OS is disabled wait until the microsecond timer
    // is no longer in use by the lp ticker wrapper code.
    // This prevents the low power ticker wrapper code from
    // getting stuck in a state where it is waiting for
    // the microsecond Timeout to run.
    while (lp_ticker_get_timeout_pending());
#endif
* This function is IRQ and thread safe
* Verified by ::sleep_manager_multithread_test and ::sleep_manager_irq_test

This comment has been minimized.

@fkjagodzinski

fkjagodzinski Jul 23, 2018

Member

@0xc0170 Is this way of referring tests acceptable? Or should I rather insert a separate defined/undefined behaviour section, e.g. as seen in the ticker API?

* Low level interface to the ticker of a target
*
* # Defined behavior
* * The function ticker_init is safe to call repeatedly - Verified by test ::ticker_init_test
* * The function ticker_init allows the ticker to keep counting and disables the ticker interrupt - Verified by test ::ticker_init_test
* * Ticker frequency is non-zero and counter is at least 8 bits - Verified by ::ticker_info_test
* * The ticker rolls over at (1 << bits) and continues counting starting from 0 - Verified by ::ticker_overflow_test
* * The ticker counts at the specified frequency +- 10% - Verified by ::ticker_frequency_test
* * The ticker increments by 1 each tick - Verified by ::ticker_increment_test
* * The ticker interrupt fires only when the ticker times increments to or past the value set by ticker_set_interrupt.
* Verified by ::ticker_interrupt_test and ::ticker_past_test
* * It is safe to call ticker_set_interrupt repeatedly before the handler is called - Verified by ::ticker_repeat_reschedule_test
* * The function ticker_fire_interrupt causes ticker_irq_handler to be called immediately from interrupt context -
* Verified by ::ticker_fire_now_test
* * The ticker operations ticker_read, ticker_clear_interrupt, ticker_set_interrupt and ticker_fire_interrupt
* take less than 20us to complete - Verified by ::ticker_speed_test
*
* # Undefined behavior
* * Calling any function other than ticker_init before the initialization of the ticker
* * Whether ticker_irq_handler is called a second time if the time wraps and matches the value set by ticker_set_interrupt again
* * Calling ticker_set_interrupt with a value that has more than the supported number of bits
* * Calling any function other than us_ticker_init after calling us_ticker_free
*
* # Potential bugs
* * Drift due to reschedule - Verified by ::ticker_repeat_reschedule_test
* * Incorrect overflow handling of timers - Verified by ::ticker_overflow_test
* * Interrupting at a time of 0 - Verified by ::ticker_overflow_test
* * Interrupt triggered more than once - Verified by ::ticker_interrupt_test

This comment has been minimized.

@0xc0170

0xc0170 Jul 24, 2018

Member

I assume as its in ticker (defined behavior + how it is verified)

This comment has been minimized.

@fkjagodzinski

fkjagodzinski Jul 25, 2018

Member

I created a new doxygen section for defined behavior.

@cmonr cmonr requested review from bulislaw and 0xc0170 Jul 24, 2018

@cmonr cmonr added the needs: review label Jul 24, 2018

@@ -162,6 +162,7 @@ void sleep_manager_lock_deep_sleep_internal(void)
if (deep_sleep_lock == USHRT_MAX) {
core_util_critical_section_exit();
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_HAL, MBED_ERROR_CODE_OVERFLOW), "DeepSleepLock overflow (> USHRT_MAX)", deep_sleep_lock);
return; // Handle overridden mbed_error(), i.e. when running sleep_manager tests.

This comment has been minimized.

@0xc0170

0xc0170 Jul 24, 2018

Member

This return was added so while running tests, it would immediately return instead of continue (does not trap)?

This comment has been minimized.

@fkjagodzinski

fkjagodzinski Jul 24, 2018

Member

Yes, since I overridden mbed_error() for test purposes and now it does not halt, I had to add this return to prevent execution of following lines -- changing the value of deep_sleep_lock var.

us_diff2 = ticker_read_us(us_ticker) - us_ts;
lp_diff2 = ticker_read_us(lp_ticker) - lp_ts;

TEST_ASSERT_MESSAGE(us_diff2 < lp_diff2 / 4, "Deep sleep mode not used when unlocked");

This comment has been minimized.

@0xc0170

0xc0170 Jul 24, 2018

Member

where does 4 come from? what are these 2 lines testing ?

This comment has been minimized.

@fkjagodzinski

fkjagodzinski Jul 24, 2018

Member

Now I can see, I didn't provide much explanation here; will add more verbose comments.
This test relies on the fact that us tickers are powered off during deep sleep, and lp tickers stay on for both sleep and deepsleep. The type of sleep that was actually used can be checked by comparing time measured by us and lp tickers.

4 is an arbitrary value. Test checks if us ticker incremented at most 25% of lp ticker time.

This comment has been minimized.

@0xc0170

0xc0170 Jul 25, 2018

Member

Please update with comments

This comment has been minimized.

@fkjagodzinski

fkjagodzinski Jul 25, 2018

Member

Comments added.

@0xc0170

This comment has been minimized.

Member

0xc0170 commented Jul 24, 2018

Please review travis docs failure

@0xc0170 0xc0170 added needs: work and removed needs: review labels Jul 25, 2018

@0xc0170 0xc0170 requested a review from ARMmbed/mbed-os-test Jul 25, 2018

@fkjagodzinski fkjagodzinski force-pushed the fkjagodzinski:test_update-sleep_manager branch from 568daed to 10d687d Jul 25, 2018

@fkjagodzinski

This comment has been minimized.

Member

fkjagodzinski commented Jul 25, 2018

Doxygen generates fine locally, so travis should also be happy with updated code.

@cmonr

This comment has been minimized.

Contributor

cmonr commented Jul 30, 2018

@cmonr cmonr requested a review from c1728p9 Jul 30, 2018

@cmonr cmonr added needs: review and removed needs: work labels Jul 30, 2018

@jamesbeyond

LGTM

@fkjagodzinski

This comment has been minimized.

Member

fkjagodzinski commented Aug 10, 2018

@0xc0170 @bulislaw @c1728p9 could you take a look at this PR?

@fkjagodzinski fkjagodzinski force-pushed the fkjagodzinski:test_update-sleep_manager branch from 10d687d to b59ef18 Aug 10, 2018

@fkjagodzinski

This comment has been minimized.

Member

fkjagodzinski commented Aug 10, 2018

I noticed there was a conflict due to recent astyle update on TESTS dir, so I rebased changes onto current master and update the files using astyle locally.

Although there are no conflicts at the moment, I think this PR could wait for #7524. Both update sleep_manager test files but #7524 looks to be further in the pipeline.

@0xc0170

This comment has been minimized.

Member

0xc0170 commented Aug 22, 2018

Although there are no conflicts at the moment, I think this PR could wait for #7524. Both update sleep_manager test files but #7524 looks to be further in the pipeline.

Already integrated.

Please rebase to resolve the conflict

@mbed-ci

This comment has been minimized.

@mbed-ci

This comment has been minimized.

@cmonr cmonr added needs: work and removed needs: CI labels Sep 28, 2018

@fkjagodzinski

This comment has been minimized.

Member

fkjagodzinski commented Oct 1, 2018

Waiting for PR #8279 which will fix the last issue.

fkjagodzinski added some commits Jul 18, 2018

Tests: SleepManager: extend test suite
New test cases:
* "deep sleep lock/unlock"
* "deep sleep unbalanced unlock"
* "deep sleep locked USHRT_MAX times"
* "deep sleep locked more than USHRT_MAX times"
* "sleep_auto calls sleep/deep sleep based on lock"
HAL: SleepManager: Update header file
Move sleep manager API into its own doxygen group.
Add defined behavior section and links to tests.
Tests: SleepManager: Add test for new check() fun
sleep_manager_can_deep_sleep_test_check() is intended to be used in test
code.
Tests: SleepManager: Fix test suite setup
Use ticker init functions from upper HAL layer to allow proper handling
of ticker overflows.
Tests: SleepManager: Update test_check() test
Increase delta to 500 us. This value is still short enough to detect
incorrect behavior of the sleep_manager_can_deep_sleep_test_check() fun,
but allows the targets with low LP timer accuracy to pass, i.e.
NUCLEO_F429ZI.
Tests: Sleep: Extract test utility functions
Move a few of utility functions so other tests can use them.
Tests: SleepManager: Fix sleep_auto test
Use us & lp tickers directly, without the common ticker layer.

@fkjagodzinski fkjagodzinski force-pushed the fkjagodzinski:test_update-sleep_manager branch from 77f9f25 to 3fcd8c4 Oct 9, 2018

@fkjagodzinski

This comment has been minimized.

Member

fkjagodzinski commented Oct 9, 2018

Update:

  • rebased to master,
  • updated sleep_auto calls sleep/deep sleep based on lock test case to use lp and us tickers directly, with upper ticker layer and LowPowerTickerWrapper suspended -- no need to wait for the outcome of #8278

PR is ready for morph tests again.

@0xc0170

This comment has been minimized.

Member

0xc0170 commented Oct 9, 2018

/morph build

@mbed-ci

This comment has been minimized.

mbed-ci commented Oct 10, 2018

Build : SUCCESS

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

Triggering tests

/morph test
/morph export-build
/morph mbed2-build

@mbed-ci

This comment has been minimized.

@mbed-ci

This comment has been minimized.

@cmonr cmonr added ready for merge and removed needs: CI labels Oct 10, 2018

@cmonr cmonr merged commit 9deefe5 into ARMmbed:master Oct 10, 2018

15 checks passed

ci-morph-build build completed
Details
ci-morph-exporter build completed
Details
ci-morph-mbed2-build build completed
Details
ci-morph-test test completed
Details
continuous-integration/jenkins/pr-head This commit looks good
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
jenkins-ci/cloud-client-test Success
Details
jenkins-ci/unittests Success
Details
travis-ci/astyle Passed, 655 files
Details
travis-ci/docs Local docs testing has passed
Details
travis-ci/events Passed, runtime is 9163 cycles (-1153 cycles)
Details
travis-ci/gitattributestest Local gitattributestest testing has passed
Details
travis-ci/licence_check Local licence_check testing has passed
Details
travis-ci/littlefs Passed, code size is 8372B (+0.00%)
Details
travis-ci/tools-py2.7 Local tools-py2.7 testing has passed
Details

@cmonr cmonr removed the ready for merge label Oct 10, 2018

@fkjagodzinski fkjagodzinski deleted the fkjagodzinski:test_update-sleep_manager branch Oct 11, 2018

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