tests: watchdog: Add new testcase and improve existing ones

New testcase sets max value to zero and checks if install function
fails.
Improvement introduces k_yield and k_sleep in while loops to make zephyr
responding.

Signed-off-by: Karol Lasończyk <karol.lasonczyk@nordicsemi.no>
This commit is contained in:
Karol Lasończyk 2018-07-18 15:56:41 +02:00 committed by Anas Nashif
parent 14112768c0
commit f19a05385d
1 changed files with 31 additions and 1 deletions

View File

@ -150,6 +150,7 @@ static int test_wdt_no_callback(void)
m_testvalue = 0;
m_state = WDT_TEST_STATE_CHECK_RESET;
while (1) {
k_yield();
};
}
@ -196,6 +197,7 @@ static int test_wdt_callback_1(void)
m_testvalue = 0;
m_state = WDT_TEST_STATE_CHECK_RESET;
while (1) {
k_yield();
};
}
@ -256,10 +258,34 @@ static int test_wdt_callback_2(void)
while (1) {
wdt_feed(wdt, 0);
k_sleep(100);
};
}
#endif
static int test_wdt_bad_window_max(void)
{
int err;
struct device *wdt = device_get_binding(WDT_DEV_NAME);
if (!wdt) {
TC_PRINT("Cannot get WDT device\n");
return TC_FAIL;
}
TC_PRINT("Testcase: %s\n", __func__);
m_cfg_wdt0.callback = NULL;
m_cfg_wdt0.flags = WDT_FLAG_RESET_SOC;
m_cfg_wdt0.window.max = 0;
err = wdt_install_timeout(wdt, &m_cfg_wdt0);
if (err == -EINVAL) {
return TC_PASS;
}
return TC_FAIL;
}
void test_wdt(void)
{
if (m_testcase_index == 0) {
@ -275,7 +301,11 @@ void test_wdt(void)
m_testcase_index++;
#endif
}
if (m_testcase_index > 2) {
if (m_testcase_index == 3) {
zassert_true(test_wdt_bad_window_max() == TC_PASS, NULL);
m_testcase_index++;
}
if (m_testcase_index > 3) {
m_testcase_index = 0;
m_state = WDT_TEST_STATE_IDLE;
}