Skip to content

Commit c74c6c7

Browse files
committed
lp_ticker test - provide lp ticker glitch test case
Test that lp ticker does not glitch backwards due to an incorrectly implemented ripple counter driver.
1 parent 9d1d32c commit c74c6c7

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

TESTS/mbed_hal/lp_ticker/lp_ticker_api_tests.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ void lp_ticker_info_test(void);
4444
*/
4545
void lp_ticker_deepsleep_test(void);
4646

47-
47+
/** Test that the ticker does not glitch backwards due to an incorrectly implemented ripple counter driver.
48+
*
49+
* Given ticker is available.
50+
* When ticker is enabled and counts.
51+
* Then ticker does not glitch backwards due to an incorrectly implemented ripple counter driver.
52+
*/
53+
void lp_ticker_glitch_test(void);
4854
/**@}*/
4955

5056
#ifdef __cplusplus

TESTS/mbed_hal/lp_ticker/main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ void lp_ticker_deepsleep_test()
8686
TEST_ASSERT_EQUAL(1, intFlag);
8787
}
8888

89+
/* Test that the ticker does not glitch backwards due to an incorrectly implemented ripple counter driver. */
90+
void lp_ticker_glitch_test()
91+
{
92+
lp_ticker_init();
93+
94+
const ticker_info_t* p_ticker_info = lp_ticker_get_info();
95+
96+
uint32_t last = lp_ticker_read();
97+
const uint32_t start = last;
98+
99+
/* Set test time to 2 sec. */
100+
while (last < (start + p_ticker_info->frequency * 2)) {
101+
const uint32_t cur = lp_ticker_read();
102+
TEST_ASSERT(cur >= last);
103+
last = cur;
104+
}
105+
}
106+
89107
utest::v1::status_t test_setup(const size_t number_of_cases)
90108
{
91109
GREENTEA_SETUP(20, "default_auto");
@@ -95,6 +113,7 @@ utest::v1::status_t test_setup(const size_t number_of_cases)
95113
Case cases[] = {
96114
Case("lp ticker info test", lp_ticker_info_test),
97115
Case("lp ticker sleep test", lp_ticker_deepsleep_test),
116+
Case("lp ticker glitch test", lp_ticker_glitch_test)
98117
};
99118

100119
Specification specification(test_setup, cases);

hal/lp_ticker_api.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ extern "C" {
4343
* * See the @ref hal_ticker_shared "ticker specification"
4444
* * Calling any function other than lp_ticker_init after calling lp_ticker_free
4545
*
46+
* # Potential bugs
47+
* * Glitches due to ripple counter - Verified by ::lp_ticker_glitch_test
48+
*
4649
* @see hal_lp_ticker_tests
4750
*
4851
* @{

0 commit comments

Comments
 (0)