From c1d7b514a13a1c794fefdaeac2cc23e2b7be50b4 Mon Sep 17 00:00:00 2001 From: Craig Hesling Date: Mon, 26 Jul 2021 19:19:28 -0400 Subject: test/stm32f_rtc: Allow real rtc delay to be early The current check for if the RTC delay is within 1ms, only accounts for actual delays that exceed 500ms. This doesn't seem right, since you would rather wake up early than late. This change allows the RTC delay to be early or late by the tolerance window. I have also tightened the tolerance window to +/- 500us. BRANCH=none BUG=b:194720920 TEST=# Repeat the following test 10 times ./test/run_device_tests.py --board bloonchipper --tests stm32f_rtc TEST=# Disable CONFIG_LOW_POWER_IDLE # Repeat the following test 10 times ./test/run_device_tests.py --board bloonchipper --tests stm32f_rtc TEST=# Disable CONFIG_LOW_POWER_IDLE and comment out idle loop "wfi" # instruction. # Repeat the following test 10 times ./test/run_device_tests.py --board bloonchipper --tests stm32f_rtc Signed-off-by: Craig Hesling Change-Id: I68505c4011d9e12d54ed2630975a5b3be42ba6f2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3055119 Reviewed-by: Jack Rosenthal --- test/stm32f_rtc.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/test/stm32f_rtc.c b/test/stm32f_rtc.c index 4a09085e4f..f2731ad9d3 100644 --- a/test/stm32f_rtc.c +++ b/test/stm32f_rtc.c @@ -10,6 +10,12 @@ static uint32_t rtc_fired; static struct rtc_time_reg rtc_irq; static const int rtc_delay_ms = 500; +/* + * We will be testing that the RTC interrupt timestamp occurs + * within +/- delay_tol_us (tolerance) of the above rtc_delay_ms. + */ +static const int delay_tol_us = MSEC / 2; + /* Override default RTC interrupt handler */ void __rtc_alarm_irq(void) { @@ -21,7 +27,6 @@ test_static int test_rtc_alarm(void) { struct rtc_time_reg rtc; uint32_t rtc_diff_us; - uint32_t rtc_diff_ms; const int delay_us = rtc_delay_ms * MSEC; set_rtc_alarm(0, delay_us, &rtc, 0); @@ -33,13 +38,17 @@ test_static int test_rtc_alarm(void) rtc_diff_us = get_rtc_diff(&rtc, &rtc_irq); - ccprintf("rtc_diff_us: %d\n", rtc_diff_us); + ccprintf("Target delay was %dus\n", delay_us); + ccprintf("Actual delay was %dus\n", rtc_diff_us); + ccprintf("The delays are expected to be within +/- %dus\n", MSEC / 2); - /* Assume we'll always fire within 1 ms. May need to be adjusted if + /* Assume we'll always fire within 500us. May need to be adjusted if * this doesn't hold. + * + * delay_us-delay_tol_us < rtc_diff_us < delay_us+delay_tol_us */ - rtc_diff_ms = rtc_diff_us / MSEC; - TEST_EQ(rtc_diff_ms, rtc_delay_ms, "%d"); + TEST_LT(delay_us - delay_tol_us, rtc_diff_us, "%dus"); + TEST_LT(rtc_diff_us, delay_us + delay_tol_us, "%dus"); return EC_SUCCESS; } -- cgit v1.2.1