Skip to content

Commit f5c2ef8

Browse files
hakehuangcfriedt
authored andcommitted
tests wdt: add WDT_OPT_PAUSE_IN_SLEEP test
add WDT_OPT_PAUSE_IN_SLEEP testing for long period this need enable PM Signed-off-by: Hake Huang <[email protected]>
1 parent b591d14 commit f5c2ef8

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_PM=y

tests/drivers/watchdog/wdt_basic_api/src/test_wdt.c

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,74 @@ static int test_wdt_bad_window_max(void)
400400
return TC_FAIL;
401401
}
402402

403+
static int test_wdt_enable_wait_mode(void)
404+
{
405+
#ifndef CONFIG_PM
406+
TC_PRINT("Testcase: %s\n", __func__);
407+
ztest_test_skip();
408+
m_state = WDT_TEST_STATE_IDLE;
409+
return TC_SKIP;
410+
#else
411+
int err;
412+
int wdt_channel_id;
413+
const struct device *const wdt = DEVICE_DT_GET(WDT_NODE);
414+
415+
if (!device_is_ready(wdt)) {
416+
TC_PRINT("WDT device is not ready\n");
417+
return TC_FAIL;
418+
}
419+
420+
TC_PRINT("Testcase: %s\n", __func__);
421+
422+
if (m_state == WDT_TEST_STATE_CHECK_RESET) {
423+
m_state = WDT_TEST_STATE_IDLE;
424+
TC_PRINT("Testcase passed\n");
425+
return TC_PASS;
426+
}
427+
428+
struct wdt_timeout_cfg wdt_config = {
429+
/* Reset SoC when watchdog timer expires. */
430+
.flags = WDT_FLAG_RESET_SOC,
431+
432+
/* Expire watchdog after max window */
433+
.window.min = 0U,
434+
.window.max = 1000U,
435+
};
436+
437+
wdt_channel_id = wdt_install_timeout(wdt, &wdt_config);
438+
if (wdt_channel_id < 0) {
439+
printk("Watchdog install error\n");
440+
return TC_FAIL;
441+
}
442+
443+
err = wdt_setup(wdt, (WDT_OPT_PAUSE_HALTED_BY_DBG | WDT_OPT_PAUSE_IN_SLEEP));
444+
if (err < 0) {
445+
printk("Watchdog setup error\n");
446+
ztest_test_skip();
447+
return TC_SKIP;
448+
}
449+
450+
for (int i = 0; i < 20; ++i) {
451+
printk("Feeding watchdog... %d\n", i);
452+
wdt_feed(wdt, 0);
453+
k_sleep(K_MSEC(2000));
454+
}
455+
456+
TC_PRINT("Waiting to restart MCU\n");
457+
m_testvalue = 0U;
458+
m_state = WDT_TEST_STATE_CHECK_RESET;
459+
while (1) {
460+
k_yield();
461+
}
462+
463+
return TC_PASS;
464+
#endif
465+
}
466+
403467
ZTEST(wdt_basic_test_suite, test_wdt)
404468
{
405-
if ((m_testcase_index != 1U) && (m_testcase_index != 2U)) {
469+
if ((m_testcase_index != 1U) && (m_testcase_index != 2U)
470+
&& (m_testcase_index != 3U)) {
406471
zassert_true(test_wdt_no_callback() == TC_PASS);
407472
}
408473
if (m_testcase_index == 1U) {
@@ -420,10 +485,14 @@ ZTEST(wdt_basic_test_suite, test_wdt)
420485
#endif
421486
}
422487
if (m_testcase_index == 3U) {
488+
zassert_true(test_wdt_enable_wait_mode() == TC_PASS);
489+
m_testcase_index++;
490+
}
491+
if (m_testcase_index == 4U) {
423492
zassert_true(test_wdt_bad_window_max() == TC_PASS);
424493
m_testcase_index++;
425494
}
426-
if (m_testcase_index > 3) {
495+
if (m_testcase_index > 4) {
427496
m_state = WDT_TEST_STATE_IDLE;
428497
}
429498
}

0 commit comments

Comments
 (0)