diff --git a/tests/drivers/watchdog/wdt_basic_api/Makefile b/tests/drivers/watchdog/wdt_basic_api/Makefile new file mode 100644 index 00000000000..72f4b496150 --- /dev/null +++ b/tests/drivers/watchdog/wdt_basic_api/Makefile @@ -0,0 +1,5 @@ +BOARD ?= quark_se_c1000_devboard +CONF_FILE = prj.conf +#CFLAGS=-DINT_RESET + +include ${ZEPHYR_BASE}/Makefile.inc diff --git a/tests/drivers/watchdog/wdt_basic_api/prj.conf b/tests/drivers/watchdog/wdt_basic_api/prj.conf new file mode 100644 index 00000000000..f3186b9979b --- /dev/null +++ b/tests/drivers/watchdog/wdt_basic_api/prj.conf @@ -0,0 +1,2 @@ +CONFIG_WATCHDOG=y +CONFIG_ZTEST=y diff --git a/tests/drivers/watchdog/wdt_basic_api/src/Makefile b/tests/drivers/watchdog/wdt_basic_api/src/Makefile new file mode 100644 index 00000000000..79789913dfb --- /dev/null +++ b/tests/drivers/watchdog/wdt_basic_api/src/Makefile @@ -0,0 +1,3 @@ +include $(ZEPHYR_BASE)/tests/Makefile.test + +obj-y += main.o test_wdt_timeout.o diff --git a/tests/drivers/watchdog/wdt_basic_api/src/main.c b/tests/drivers/watchdog/wdt_basic_api/src/main.c new file mode 100644 index 00000000000..0b42e551f9b --- /dev/null +++ b/tests/drivers/watchdog/wdt_basic_api/src/main.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup t_driver_wdt + * @{ + * @defgroup t_wdt_basic test_wdt_basic_operations + * @} + */ + +#include +#include + +#ifdef INT_RESET +extern void test_wdt_int_reset_26(void); +#else +extern void test_wdt_reset_26(void); +#endif + +void test_main(void) +{ + ztest_test_suite(wdt_basic_test, +#ifdef INT_RESET + ztest_unit_test(test_wdt_int_reset_26)); +#else + ztest_unit_test(test_wdt_reset_26)); +#endif + ztest_run_test_suite(wdt_basic_test); +} diff --git a/tests/drivers/watchdog/wdt_basic_api/src/test_wdt_timeout.c b/tests/drivers/watchdog/wdt_basic_api/src/test_wdt_timeout.c new file mode 100644 index 00000000000..59e6a775689 --- /dev/null +++ b/tests/drivers/watchdog/wdt_basic_api/src/test_wdt_timeout.c @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2016 Intel Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * @addtogroup t_wdt_basic + * @{ + * @defgroup t_wdt_timeout test_wdt_timeout_capabilities + * @brief TestPurpose: verify Watchdog Timer enable/disable/set/get can work, + * and Warm Reset can be triggered when timeout + * @details + * - Test Steps + * -# Enable Watchdog Timer + * -# Configure timeout, mode and interrupt_fn for Watchdog Timer + * -# Fetch Watchdog Timer configurations and compare the settings + * -# Disable Watchdog Timer to disable the Warm Reset + * -# Enable Watchdog Timer again and wait fortimeout and Warm Reset + * -# Use General Purpose Sticky Scratchpad 2 (GPS2) as a flag to + * indicate whether a Warm Reset happened, because Warm Reset won't + * clear it + * - Expected Results + * -# If response mode is configured as Interrupt Reset, the interrupt + * callback function will be called first when the first timeout comes. + * The second timeout will trigger a Warm Reset and GPS2 will be two. + * -# If response mode is configured as Reset, a Warm Reset will be + * triggered when timeout and GPS2 will be one. + * @} + */ + +#include +#include +#include +#include + +#define WDT_DEV_NAME CONFIG_WDT_0_NAME + +static void wdt_int_cb(struct device *wdt_dev) +{ + static uint32_t wdt_int_cnt; + + TC_PRINT("%s: Invoked (%u)\n", __func__, ++wdt_int_cnt); + QM_SCSS_GP->gps2++; +} + +static int test_wdt(uint32_t timeout, enum wdt_mode r_mode) +{ + struct wdt_config config; + struct device *wdt = device_get_binding(WDT_DEV_NAME); + + if (!wdt) { + TC_PRINT("Cannot get WDT device\n"); + return TC_FAIL; + } + + config.timeout = timeout; + config.mode = r_mode; + if (r_mode == WDT_MODE_INTERRUPT_RESET) { + config.interrupt_fn = wdt_int_cb; + } else { + config.interrupt_fn = NULL; + } + + /* 1. Verify wdt_enable() */ + wdt_enable(wdt); + + /* 2. Verify wdt_set_config() */ + if (wdt_set_config(wdt, &config)) { + TC_PRINT("Fail to configure WDT device\n"); + wdt_disable(wdt); + return TC_FAIL; + } + + /* 3. Verify wdt_get_config() */ + wdt_get_config(wdt, &config); + + if (timeout != config.timeout || r_mode != config.mode) { + TC_PRINT("Fetch config doesn't match with set config\n"); + TC_PRINT("timeout = %d, config.timeout = %d", timeout, + config.timeout); + TC_PRINT("r_mode = %d, config.mode = %d", r_mode, config.mode); + wdt_disable(wdt); + return TC_FAIL; + } + + /* 4. Verify wdt_disable(), and Warm Reset won't happen */ + wdt_disable(wdt); + + if (QM_SCSS_GP->gps3) { + TC_PRINT("A Warm Reset shouldn't happen when Timer disabled\n"); + return TC_FAIL; + } + + QM_SCSS_GP->gps3 = 1; + + /* + * Wait to check whether a Warm Reset will happen. + * The sleep time should be longer than Watchdog Timer + * timeout value. If a Warm Reset happens, gps3 won't be + * cleared and then when the program comes here again, + * it will notice this and return a failure. + */ + k_sleep(5000); + + QM_SCSS_GP->gps3 = 0; + + /* 5. Verify watchdog trigger a Warm Reset */ + wdt_enable(wdt); + + if (!QM_SCSS_GP->gps2) { + TC_PRINT("Waiting for WDT reset\n"); + QM_SCSS_GP->gps2 = 1; + while (1) + ; + } else { + if (r_mode == WDT_MODE_INTERRUPT_RESET) { + if (QM_SCSS_GP->gps2 == 2) { + wdt_disable(wdt); + return TC_PASS; + } + } else { + if (QM_SCSS_GP->gps2) { + wdt_disable(wdt); + return TC_PASS; + } + } + TC_PRINT("QM_SCSS_GP->gps2 = %d\n", QM_SCSS_GP->gps2); + wdt_disable(wdt); + return TC_FAIL; + } +} + +/* + * Choose WDT_2_26_CYCLES as watchdog timeout cycle, which will + * timeout in 2.097s. Other timeout cycles are the same. + */ +void test_wdt_int_reset_26(void) +{ + assert_true(test_wdt(WDT_2_26_CYCLES, + WDT_MODE_INTERRUPT_RESET) == TC_PASS, NULL); + QM_SCSS_GP->gps2 = 0; +} + +void test_wdt_reset_26(void) +{ + assert_true(test_wdt(WDT_2_26_CYCLES, + WDT_MODE_RESET) == TC_PASS, NULL); + QM_SCSS_GP->gps2 = 0; +} diff --git a/tests/drivers/watchdog/wdt_basic_api/testcase.ini b/tests/drivers/watchdog/wdt_basic_api/testcase.ini new file mode 100644 index 00000000000..122306d1a5b --- /dev/null +++ b/tests/drivers/watchdog/wdt_basic_api/testcase.ini @@ -0,0 +1,10 @@ +[test_watchdog_reset] +tags = drivers +arch_whitelist = x86 arc +platform_whitelist = quark_se_c1000_devboard arduino_101 quark_d2000_crb + +[test_watchdog_int_reset] +tags = drivers +arch_whitelist = x86 arc +extra_args = CFLAGS=-DINT_RESET +platform_whitelist = quark_se_c1000_devboard arduino_101 quark_d2000_crb