Repository navigation
drivertest/watchdog: tighten reset cause and timing validation #3983
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,11 @@ | |
| #define WDG_DEFAULT_TIMEOUT 2000 | ||
| #define WDG_DEFAULT_TESTCASE 0 | ||
| #define WDG_DEFAULT_DEVIATION 20 | ||
| #ifdef CONFIG_ARCH_CHIP_ESP32S3 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On upstream the ESP32-S3 branch is never built: only boards/arm/n32h7 and boards/arm/samv7 provide |
||
| # define WDG_EXPECTED_RESET_CAUSE BOARDIOC_RESETCAUSE_CORE_MWDT | ||
| #else | ||
| # define WDG_EXPECTED_RESET_CAUSE BOARDIOC_RESETCAUSE_SYS_RWDT | ||
| #endif | ||
| #if defined(CONFIG_ARCH_ARMV7A) && defined(CONFIG_ARCH_HAVE_TRUSTZONE) | ||
| #define WDG_COUNT_TESTCASE 3 | ||
| #else | ||
|
|
@@ -93,6 +98,7 @@ struct wdg_state_s | |
| bool test_getstatus; | ||
| #ifdef CONFIG_BOARDCTL_RESET_CAUSE | ||
| sem_t semaphore; | ||
| volatile bool capture_seen; | ||
| #endif | ||
| #ifdef CONFIG_WATCHDOG_TIMEOUT_NOTIFIER | ||
| unsigned int notifier_calls; | ||
|
|
@@ -148,6 +154,7 @@ static uint32_t get_timestamp(void) | |
| { | ||
| struct timespec ts; | ||
| uint32_t ms; | ||
|
|
||
| clock_gettime(CLOCK_MONOTONIC, &ts); | ||
| ms = ts.tv_sec * 1000 + ts.tv_nsec / 1000000; | ||
| return ms; | ||
|
|
@@ -332,6 +339,7 @@ static void parse_commandline(FAR struct wdg_state_s *wdg_state, int argc, | |
| static int capture_callback(int irq, FAR void *context, FAR void *arg) | ||
| { | ||
| DEBUGASSERT(g_capture_test_state != NULL); | ||
| g_capture_test_state->capture_seen = true; | ||
| sem_post(&g_capture_test_state->semaphore); | ||
| return OK; | ||
| } | ||
|
|
@@ -603,7 +611,7 @@ static void drivertest_watchdog_interrupts(FAR void **state) | |
| } | ||
|
|
||
| boardctl(BOARDIOC_RESET_CAUSE, (uintptr_t)&reset_cause); | ||
| assert_int_equal(reset_cause.cause, BOARDIOC_RESETCAUSE_SYS_RWDT); | ||
| assert_int_equal(reset_cause.cause, WDG_EXPECTED_RESET_CAUSE); | ||
|
|
||
| wdg_init(wdg_state); | ||
|
|
||
|
|
@@ -648,7 +656,7 @@ static void drivertest_watchdog_loop(FAR void **state) | |
| } | ||
|
|
||
| boardctl(BOARDIOC_RESET_CAUSE, (uintptr_t)&reset_cause); | ||
| assert_int_equal(reset_cause.cause, BOARDIOC_RESETCAUSE_SYS_RWDT); | ||
| assert_int_equal(reset_cause.cause, WDG_EXPECTED_RESET_CAUSE); | ||
|
|
||
| wdg_init(wdg_state); | ||
|
|
||
|
|
@@ -685,7 +693,7 @@ static void drivertest_watchdog_api(FAR void **state) | |
| assert_int_equal(wdg_state->test_case, 3); | ||
|
|
||
| boardctl(BOARDIOC_RESET_CAUSE, (uintptr_t)&reset_cause); | ||
| assert_int_equal(reset_cause.cause, BOARDIOC_RESETCAUSE_SYS_RWDT); | ||
| assert_int_equal(reset_cause.cause, WDG_EXPECTED_RESET_CAUSE); | ||
|
|
||
| dev_fd = wdg_init(wdg_state); | ||
|
|
||
|
|
@@ -697,11 +705,18 @@ static void drivertest_watchdog_api(FAR void **state) | |
|
|
||
| while (get_time_elaps(start_ms) < wdg_state->pingtime) | ||
| { | ||
| uint32_t elapsed_max; | ||
| uint32_t elapsed_min; | ||
| uint32_t ping_elapsed; | ||
| uint32_t ping_start; | ||
|
|
||
| /* Sleep for the requested amount of time, use up_udelay prevent | ||
| * system into low power mode and watchdog be pause stop count. | ||
| */ | ||
|
|
||
| ping_start = get_timestamp(); | ||
| up_udelay(wdg_state->pingdelay * 1000); | ||
| ping_elapsed = get_time_elaps(ping_start); | ||
|
|
||
| if (wdg_state->test_getstatus) | ||
| { | ||
|
|
@@ -711,10 +726,15 @@ static void drivertest_watchdog_api(FAR void **state) | |
| assert_return_code(ret, OK); | ||
|
|
||
| assert_int_equal(status.timeout, wdg_state->timeout); | ||
| assert_true(status.timeleft <= status.timeout); | ||
|
|
||
| elapsed_min = ping_elapsed > wdg_state->deviation ? | ||
| ping_elapsed - wdg_state->deviation : 0; | ||
| elapsed_max = ping_elapsed + wdg_state->deviation; | ||
| assert_in_range( | ||
| status.timeout - status.timeleft, | ||
| wdg_state->pingdelay - wdg_state->deviation, | ||
| wdg_state->pingdelay + wdg_state->deviation); | ||
| elapsed_min, | ||
| elapsed_max); | ||
| } | ||
|
|
||
| /* Then ping */ | ||
|
|
@@ -728,6 +748,7 @@ static void drivertest_watchdog_api(FAR void **state) | |
| ret = sem_init(&wdg_state->semaphore, 0, 0); | ||
| assert_return_code(ret, OK); | ||
|
|
||
| wdg_state->capture_seen = false; | ||
| g_capture_test_state = wdg_state; | ||
| watchdog_capture.newhandler = capture_callback; | ||
| ret = ioctl(dev_fd, WDIOC_CAPTURE, &watchdog_capture); | ||
|
|
@@ -737,6 +758,8 @@ static void drivertest_watchdog_api(FAR void **state) | |
|
|
||
| up_udelay(2 * wdg_state->timeout * 1000); | ||
|
|
||
| assert_true(wdg_state->capture_seen); | ||
|
|
||
| sem_wait(&wdg_state->semaphore); | ||
|
|
||
| watchdog_capture.newhandler = watchdog_capture.oldhandler; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why check the special chip in the common code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is for the ESP32-S3