Skip to content

Commit fa7c05c

Browse files
nordic-seglcarlescufi
authored andcommitted
tests: drivers: watchdog: Add negative test cases for Watchdog
Extend test coverage by adding tests that check invalid use of the Watchdog API. Signed-off-by: Sebastian Głąb <[email protected]>
1 parent 49d6b6b commit fa7c05c

File tree

6 files changed

+1073
-0
lines changed

6 files changed

+1073
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(wdt_error_cases)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
This test suite contains negative test cases for the Watchdog driver.
2+
Test scenarios validate that invalid use of the watchdog driver
3+
returns error code as described in the API documentation
4+
(or Assertion Fail as explained below).
5+
6+
Ideally, the driver shall be fully compliant with the documentation.
7+
However, it may happen that invalid function call results in
8+
Assertion Fail instead of error code.
9+
Since, main goal is to detect (and report) invalid use of the driver,
10+
both error code and assertion fail set test result as passed.
11+
See for example test_02_wdt_setup_before_setting_timeouts where
12+
ztest_set_assert_valid(true);
13+
is used to catch assertion fail.
14+
15+
These tests were written to increase test coverage for the Watchdog driver.
16+
Since, coverage data is stored in the RAM, it is lost when watchdog fires.
17+
Therefore, in all test cases watchdog shall NOT expire.
18+
Use other sample to verify positive scenario for the watchdog driver.
19+
20+
These tests were prepared on a target that had a bug in the wdt_disable()
21+
implementation. As a temporary remedy, order of tests was imposed.
22+
Since, tests are executed alphabetically, order was set by starting
23+
each test name with f.e. 'test_08b_...'.
24+
25+
26+
Tests are based on the watchdog API documentation available here:
27+
https://docs.zephyrproject.org/latest/hardware/peripherals/watchdog.html
28+
29+
30+
Follow these guidelines when enabling test execution on a new target.
31+
32+
1. Although, code defines WDT_DISABLE_SUPPORTED but it was tested on a
33+
target that supports disabling the watchdog.
34+
Multiple tests call wdt_setup() which starts the watchdog.
35+
Every test assumes that watchdog is disabled at startup.
36+
As a result, executing this test suite on a target that doesn't
37+
support wdt_disable() may require changes to the code.
38+
When target supports wdt_disable() then extend WDT_TEST_FLAGS with:
39+
#define WDT_TEST_FLAGS (... | WDT_DISABLE_SUPPORTED)
40+
41+
2. There are three watchdog flags that can be passed to wdt_install_timeout():
42+
- WDT_FLAG_RESET_NONE - when watchdog expires, it's callback is serviced but
43+
reset doesn't occur.
44+
- WDT_FLAG_RESET_CPU_CORE - when watchdog expires, only one core is reset, while
45+
other cores are not affected.
46+
- WDT_FLAG_RESET_SOC - when watchdog expires, target as "a whole" is reset.
47+
Support for these flags varies between vendors and products.
48+
a) List all supported flags in
49+
#define WDT_TEST_FLAGS (... | WDT_FLAG_RESET_NONE_SUPPORTED |
50+
WDT_FLAG_RESET_CPU_CORE_SUPPORTED |
51+
WDT_FLAG_RESET_SOC_SUPPORTED)
52+
b) Set supported flag in
53+
#define DEFAULT_FLAGS (WDT_FLAG_RESET_SOC)
54+
This define will be used in wdt_install_timeout() "correct" test step.
55+
56+
3. These tests assume that watchdog driver supports multiple timeouts. Set
57+
#define MAX_INSTALLABLE_TIMEOUTS (8)
58+
59+
4. When all watchdog timeouts must have exactly the same watchdog timeout value
60+
then extend WDT_TEST_FLAGS with:
61+
#define WDT_TEST_FLAGS (... | WDT_FLAG_ONLY_ONE_TIMEOUT_VALUE_SUPPORTED)
62+
63+
5. Set maximal allowed watchdog timeout value, f.e.:
64+
#define WDT_WINDOW_MAX_ALLOWED (0xFFFFFFFFU)
65+
Also, test assumes that minimal allowed watchdog timeout value must be zero.
66+
67+
6. There are two watchdog options that can be passed to wdt_setup():
68+
- WDT_OPT_PAUSE_IN_SLEEP;
69+
- WDT_OPT_PAUSE_HALTED_BY_DBG.
70+
Support for these options varies between vendors and products.
71+
a) List all supported options in
72+
#define WDT_TEST_FLAGS (... | WDT_OPT_PAUSE_IN_SLEEP_SUPPORTED |
73+
WDT_OPT_PAUSE_HALTED_BY_DBG_SUPPORTED)
74+
b) Set supported option(s) in
75+
#define DEFAULT_OPTIONS (WDT_OPT_PAUSE_IN_SLEEP | WDT_OPT_PAUSE_HALTED_BY_DBG)
76+
This define will be used in wdt_setup() "correct" test step.
77+
78+
7. When wdt_feed() can stall, extend WDT_TEST_FLAGS with:
79+
#define WDT_TEST_FLAGS (... | WDT_FEED_CAN_STALL)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&wdt31 {
8+
status = "okay";
9+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_ZTEST_ASSERT_HOOK=y
3+
CONFIG_WATCHDOG=y

0 commit comments

Comments
 (0)