tests: drivers: watchdog: add test watchdog for s32z270dc2_r52
This test to verify Watchdog install/setup/feed can work and interrupt can be triggered on timeouts. This test doesn't test the case of reseting the board on time out because flash isn't currently support. Signed-off-by: Quang Bui Trong <quang.buitrong@nxp.com>
This commit is contained in:
parent
391f90e0cc
commit
411549c22c
4 changed files with 156 additions and 0 deletions
10
tests/drivers/watchdog/wdt_basic_reset_none/CMakeLists.txt
Normal file
10
tests/drivers/watchdog/wdt_basic_reset_none/CMakeLists.txt
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Copyright 2022 NXP
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(wdt_basic_reset_none)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
6
tests/drivers/watchdog/wdt_basic_reset_none/prj.conf
Normal file
6
tests/drivers/watchdog/wdt_basic_reset_none/prj.conf
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Copyright 2022 NXP
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_ZTEST_NEW_API=y
|
||||
CONFIG_WATCHDOG=y
|
132
tests/drivers/watchdog/wdt_basic_reset_none/src/main.c
Normal file
132
tests/drivers/watchdog/wdt_basic_reset_none/src/main.c
Normal file
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright 2022 NXP
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/ztest.h>
|
||||
#include <zephyr/drivers/watchdog.h>
|
||||
|
||||
|
||||
/*
|
||||
* To use this test, either the devicetree's /aliases must have a
|
||||
* 'watchdog0' property, or one of the following watchdog compatibles
|
||||
* must have an enabled node.
|
||||
*/
|
||||
#if DT_NODE_HAS_STATUS(DT_ALIAS(watchdog0), okay)
|
||||
#define WDT_NODE DT_ALIAS(watchdog0)
|
||||
#elif DT_HAS_COMPAT_STATUS_OKAY(nxp_s32_swt)
|
||||
#define WDT_NODE DT_INST(0, nxp_s32_swt)
|
||||
#endif
|
||||
|
||||
#define WDT_FEED_TRIES 2
|
||||
#define WDT_MAX_WINDOW 1000
|
||||
#define WDT_TIMEOUT K_MSEC(1100)
|
||||
#define SLEEP_TIME K_MSEC(500)
|
||||
#define WDT_TEST_CB_TEST_VALUE 0xCB
|
||||
|
||||
static struct wdt_timeout_cfg m_cfg_wdt0;
|
||||
static volatile int wdt_interrupted_flag;
|
||||
static volatile int wdt_feed_flag;
|
||||
|
||||
|
||||
static void wdt_callback(const struct device *dev, int channel_id)
|
||||
{
|
||||
wdt_interrupted_flag += WDT_TEST_CB_TEST_VALUE;
|
||||
zassert_equal(WDT_FEED_TRIES, wdt_feed_flag,
|
||||
"%d: Invalid number of feeding (expected: %d)",
|
||||
wdt_feed_flag, WDT_FEED_TRIES);
|
||||
}
|
||||
|
||||
static int test_wdt_callback_reset_none(void)
|
||||
{
|
||||
int err;
|
||||
const struct device *const wdt = DEVICE_DT_GET(WDT_NODE);
|
||||
|
||||
if (!device_is_ready(wdt)) {
|
||||
TC_PRINT("WDT device is not ready\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
m_cfg_wdt0.window.min = 0U;
|
||||
m_cfg_wdt0.window.max = WDT_MAX_WINDOW;
|
||||
m_cfg_wdt0.flags = WDT_FLAG_RESET_NONE;
|
||||
m_cfg_wdt0.callback = wdt_callback;
|
||||
|
||||
err = wdt_install_timeout(wdt, &m_cfg_wdt0);
|
||||
if (err != 0) {
|
||||
TC_PRINT("Watchdog install error\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
err = wdt_setup(wdt, WDT_OPT_PAUSE_HALTED_BY_DBG);
|
||||
if (err != 0) {
|
||||
TC_PRINT("Watchdog setup error\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
TC_PRINT("Feeding watchdog %d times\n", WDT_FEED_TRIES);
|
||||
wdt_feed_flag = 0;
|
||||
wdt_interrupted_flag = 0;
|
||||
for (int i = 0; i < WDT_FEED_TRIES; ++i) {
|
||||
TC_PRINT("Feeding %d\n", i+1);
|
||||
wdt_feed(wdt, 0);
|
||||
wdt_feed_flag++;
|
||||
k_sleep(SLEEP_TIME);
|
||||
}
|
||||
|
||||
k_timeout_t timeout = WDT_TIMEOUT;
|
||||
uint64_t start_time = k_uptime_ticks();
|
||||
|
||||
while (wdt_interrupted_flag == 0) {
|
||||
if (k_uptime_ticks() - start_time >= timeout.ticks) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
zassert_equal(wdt_interrupted_flag, WDT_TEST_CB_TEST_VALUE,
|
||||
"wdt callback failed");
|
||||
|
||||
err = wdt_disable(wdt);
|
||||
if (err != 0) {
|
||||
TC_PRINT("Disable watchdog error\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
return TC_PASS;
|
||||
}
|
||||
|
||||
static int test_wdt_bad_window_max(void)
|
||||
{
|
||||
int err;
|
||||
const struct device *const wdt = DEVICE_DT_GET(WDT_NODE);
|
||||
|
||||
if (!device_is_ready(wdt)) {
|
||||
TC_PRINT("WDT device is not ready\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
m_cfg_wdt0.callback = NULL;
|
||||
m_cfg_wdt0.flags = WDT_FLAG_RESET_NONE;
|
||||
m_cfg_wdt0.window.max = 0U;
|
||||
m_cfg_wdt0.window.min = 0U;
|
||||
err = wdt_install_timeout(wdt, &m_cfg_wdt0);
|
||||
if (err == -EINVAL) {
|
||||
return TC_PASS;
|
||||
}
|
||||
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
|
||||
ZTEST(wdt_basic_reset_none, test_wdt_callback_reset_none)
|
||||
{
|
||||
zassert_true(test_wdt_callback_reset_none() == TC_PASS);
|
||||
}
|
||||
|
||||
ZTEST(wdt_basic_reset_none, test_wdt_bad_window_max)
|
||||
{
|
||||
zassert_true(test_wdt_bad_window_max() == TC_PASS);
|
||||
}
|
||||
|
||||
ZTEST_SUITE(wdt_basic_reset_none, NULL, NULL, NULL, NULL, NULL);
|
|
@ -0,0 +1,8 @@
|
|||
# Copyright 2022 NXP
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
tests:
|
||||
drivers.watchdog.reset_none:
|
||||
platform_allow: s32z270dc2_rtu0_r52 s32z270dc2_rtu1_r52
|
||||
tags: drivers watchdog
|
||||
depends_on: watchdog
|
Loading…
Add table
Add a link
Reference in a new issue