Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions testing/drivers/drivertest/drivertest_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
#define WDG_DEFAULT_TIMEOUT 2000
#define WDG_DEFAULT_TESTCASE 0
#define WDG_DEFAULT_DEVIATION 20
#ifdef CONFIG_ARCH_CHIP_ESP32S3

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 board_reset_cause(), so CONFIG_BOARDCTL_RESET_CAUSE does not link on ESP32-S3.
Fix: drop the chip check and let the caller give the expected reset cause, for example with a new command-line option next to -a.

# 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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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)
{
Expand All @@ -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 */
Expand All @@ -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);
Expand All @@ -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;
Expand Down
Loading