Skip to content

testing/drivers: add watchdog notifier cmocka coverage#3639

Open
Zepp-Hanzj wants to merge 5 commits into
apache:masterfrom
Zepp-Hanzj:fix/watchdog-notifier-tests
Open

testing/drivers: add watchdog notifier cmocka coverage#3639
Zepp-Hanzj wants to merge 5 commits into
apache:masterfrom
Zepp-Hanzj:fix/watchdog-notifier-tests

Conversation

@Zepp-Hanzj

@Zepp-Hanzj Zepp-Hanzj commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Add focused cmocka coverage for the watchdog timeout notifier chain and allow the watchdog drivertest to run notifier-only coverage on configurations without reset-cause support.

Changes

  • Register cmocka_driver_watchdog when watchdog support is enabled together with either reset-cause support or timeout-notifier support.
  • Compile the existing hardware watchdog cases only with CONFIG_BOARDCTL_RESET_CAUSE and the notifier cases only with CONFIG_WATCHDOG_TIMEOUT_NOTIFIER.
  • Add notifier tests covering:
    • priority ordering;
    • duplicate registration suppression;
    • repeated timeout delivery;
    • unregistering one notifier while preserving the others;
    • WATCHDOG_NOTIFIER_ACTION propagation;
    • data == NULL propagation;
    • concurrent register/timeout/unregister activity.

Validation

The test was run using the companion NuttX simulator configuration. Since that configuration enables timeout-notifier support without reset-cause support, cmocka_driver_watchdog runs only the two notifier cases:

[==========] tests: 2 test(s) run.
[  PASSED  ] 2 test(s).

Both the Make and CMake registration paths compile cmocka_driver_watchdog for this configuration. The race test repeatedly interleaves timeout delivery with notifier registration and unregistration and asserts that callbacks remain valid and receive a NULL payload.

Additional hardware-path validation was performed in the companion NuttX PR on STM32F407 WWDG hardware. The corresponding UART logs and screenshots are linked there:

Scope

This PR contains only watchdog notifier tests and their test registration. Unrelated O_RDONLY compatibility changes are intentionally excluded.

Merge order

Merge the companion NuttX core PR first, then enable this test configuration in CI or simulator validation.

Checklist

  • Makefile and CMake registration paths updated consistently.
  • Existing hardware watchdog cases remain enabled when reset-cause support is available.
  • git diff --check and NuttX checkpatch.sh pass.
  • Simulator cmocka notifier and race tests pass.

@Zepp-Hanzj

Copy link
Copy Markdown
Contributor Author

Updated the companion branch in response to the check results:

  • Added Signed-off-by trailers to both commits.
  • Applied cmake-format to testing/drivers/drivertest/CMakeLists.txt.
  • Fixed nxstyle issues in the notifier race test (blank lines and block-comment formatting).

The test scope and watchdog-only registration behavior are unchanged.

Comment thread testing/drivers/drivertest/drivertest_watchdog.c Outdated
@Zepp-Hanzj Zepp-Hanzj force-pushed the fix/watchdog-notifier-tests branch from 6ec0489 to cdd0b1f Compare July 14, 2026 14:49
#if !defined(CONFIG_ARCH_ARMV7A) || !defined(CONFIG_ARCH_HAVE_TRUSTZONE)
cmocka_unit_test_prestate(drivertest_watchdog_api, &wdg_state)
cmocka_unit_test_prestate(drivertest_watchdog_api, &wdg_state),
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#endif
#endif

#ifdef CONFIG_WATCHDOG_TIMEOUT_NOTIFIER
    cmocka_unit_test_prestate(drivertest_watchdog_notifier, &wdg_state),

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Zepp-Hanzj :-)

@cederom

cederom commented Jul 14, 2026 via email

Copy link
Copy Markdown
Contributor

@linguini1

Copy link
Copy Markdown
Contributor

If you are using AI tools, please add the Assisted-by: field to your commit messages.

Could you please attach the logs from the tests you ran on sim?

@xiaoxiang781216 xiaoxiang781216 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d

Comment thread testing/drivers/drivertest/drivertest_watchdog.c Outdated
Comment thread testing/drivers/drivertest/drivertest_watchdog.c Outdated
Comment thread testing/drivers/drivertest/drivertest_watchdog.c
Comment thread testing/drivers/drivertest/Makefile Outdated
ifeq ($(CONFIG_TESTING_DRIVER_TEST_WATCHDOG_ONLY),y)
MAINSRC += drivertest_watchdog.c
PROGNAME += cmocka_driver_watchdog
else

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why skip other wdog test

@Zepp-Hanzj Zepp-Hanzj force-pushed the fix/watchdog-notifier-tests branch from cdd0b1f to f1d3688 Compare July 15, 2026 05:51
@Zepp-Hanzj

Copy link
Copy Markdown
Contributor Author

Addressed the review comments in the latest push.

Code updates

  • Merged notifier test state into the existing wdg_state_s.
  • Replaced manual offsetof pointer arithmetic with container_of().
  • Removed the extra space before id.
  • Added Assisted-by: OpenAI Codex to both commits.
  • Commits now use the requested identity and trailer:
    Signed-off-by: hanzhijian <hanzhijian@zepp.com>.

The watchdog-only option intentionally skips the other drivertest applications: its purpose is to produce a minimal simulator image that registers only cmocka_driver_watchdog. The normal configuration path is unchanged and still builds the complete drivertest set.

Simulator test log

Configuration: sim:watchdog-notifier

Configuration: sim:watchdog-notifier
Configuration: CONFIG_WATCHDOG_AUTOMONITOR_BY_CAPTURE=y
Command: cmocka_driver_watchdog

[==========] tests: Running 2 test(s).
[ RUN      ] drivertest_watchdog_notifier
[       OK ] drivertest_watchdog_notifier
[ RUN      ] drivertest_watchdog_notifier_race
[       OK ] drivertest_watchdog_notifier_race
[==========] tests: 2 test(s) run.
[  PASSED  ] 2 test(s).

The race test interleaves timeout delivery with notifier registration and
unregistration from a concurrent pthread. It completed without a fault,
deadlock, or invalid callback payload.

The capture-stop pending-interrupt validation also passed: the callback returned safely after the association was cleared and did not dereference a NULL upper-half.

Add cmocka coverage for notifier priority ordering, duplicate registration,
repeated timeout delivery, unregister behavior, action propagation, and
NULL callback data.

Signed-off-by: hanzhijian <hanzhijian@zepp.com>
Assisted-by: OpenAI Codex
Add a focused watchdog-only cmocka registration and exercise notifier
ordering, duplicate registration, repeated timeout delivery, unregister
behavior, NULL data, and concurrent register/timeout/unregister activity.

Signed-off-by: hanzhijian <hanzhijian@zepp.com>
Assisted-by: OpenAI Codex
@Zepp-Hanzj Zepp-Hanzj force-pushed the fix/watchdog-notifier-tests branch from f1d3688 to 8fa68e9 Compare July 15, 2026 05:54
@Zepp-Hanzj

Copy link
Copy Markdown
Contributor Author

The checkpatch failure was caused by commit messages shorter than the repository minimum of five lines. Both commits now include a descriptive body, the requested Signed-off-by: hanzhijian <hanzhijian@zepp.com>, and Assisted-by: OpenAI Codex. The branch was force-updated; the new commit range passes the local checkpatch message checks (apart from locally unavailable optional codespell/cvt2utf tools).

Include the container_of declaration and exclude unused hardware-only
helpers when the watchdog notifier test is built alone.

Signed-off-by: hanzhijian <hanzhijian@zepp.com>
Assisted-by: OpenAI Codex
@Zepp-Hanzj

Copy link
Copy Markdown
Contributor Author

The simulator build exposed and is now fixed in commit 764e0a045: include <nuttx/nuttx.h> for container_of() and conditionally exclude hardware-only helpers from the watchdog-only configuration. A local make -j$(nproc) now completes without the previous compile error or unused-helper warnings. Please rerun the simulator test and attach your own raw build/run logs.

@Zepp-Hanzj

Zepp-Hanzj commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@Zepp-Hanzj

Copy link
Copy Markdown
Contributor Author

Thanks @cederom. Agreed — the remaining cosmetic formatting discussion can be skipped. The required commit messages are now in place with both Signed-off-by and Assisted-by trailers, and the simulator build/run logs have been attached in the comments above. The latest branch also contains the watchdog-only build fix and local compilation passes. I will leave the PR ready for final CI/review.

jerpelea
jerpelea previously approved these changes Jul 15, 2026
Keep the existing drivertest applications under the main test option and
register only the watchdog notifier application for the watchdog-only mode.
This prevents unrelated cmocka applications from being added to simulator
configurations that do not enable the driver test option.

Signed-off-by: hanzhijian <hanzhijian@zepp.com>
Assisted-by: OpenAI Codex
@Zepp-Hanzj

Copy link
Copy Markdown
Contributor Author

The failed CI jobs were investigated. The root cause was the CMake condition in testing/drivers/drivertest/CMakeLists.txt: the else() was matching the outer CONFIG_TESTING_DRIVER_TEST condition, so configurations that did not enable the driver test could still register cmocka applications. This caused cmocka.h errors in the sim-02 matrix.

Fixed in commit b4167a1a5:

  • Register cmocka_driver_watchdog only when CONFIG_TESTING_DRIVER_TEST_WATCHDOG_ONLY=y.
  • Keep the original drivertest application block under CONFIG_TESTING_DRIVER_TEST && NOT CONFIG_TESTING_DRIVER_TEST_WATCHDOG_ONLY.
  • Preserve the normal configuration behavior.

cmake-format --check and git diff --check pass locally. The branch update has triggered a new CI run.

Comment thread testing/drivers/drivertest/Kconfig Outdated
bool "Enable cmocka driver simple test"
default n

config TESTING_DRIVER_TEST_WATCHDOG_ONLY

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need special config

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option was originally added to isolate the notifier tests on the simulator, because the existing watchdog tests require reset-cause support and a real watchdog device. After re-evaluating the registration logic, I agree that a special WATCHDOG_ONLY option is unnecessary and causes the existing watchdog tests to be skipped.
I will remove it, register cmocka_driver_watchdog when either CONFIG_BOARDCTL_RESET_CAUSE or CONFIG_WATCHDOG_TIMEOUT_NOTIFIER is available, and guard the hardware and notifier test groups separately. This preserves all existing watchdog tests when reset-cause support is available, while the simulator runs only the notifier cases.

#define WDG_DEFAULT_TIMEOUT 2000
#define WDG_DEFAULT_TESTCASE 0
#define WDG_DEFAULT_DEVIATION 20
#ifndef BOARDIOC_RESETCAUSE_SYS_CHIPPOR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These definitions were originally added because the reset-cause enum is not declared when reset-cause support is disabled. However, the enum values are not preprocessor macros, so these fallback checks are incorrect. I will remove both definitions and compile the reset-cause-dependent tests only under CONFIG_BOARDCTL_RESET_CAUSE.

Remove the special watchdog-only selection and register the watchdog cmocka application when reset-cause or timeout-notifier support is available. Compile the hardware watchdog cases only when reset-cause support is enabled, while allowing notifier-only simulator coverage.

Remove the invalid reset-cause fallback macros so the real enum values are preserved.

Assisted-by: OpenAI Codex
Signed-off-by: hanzhijian <hanzhijian@zepp.com>

@acassis acassis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zepp-Hanzj please add Documentation to drivertest to https://nuttx.apache.org/docs/latest/applications/testing/drivertest/index.html since the original author didn't add it and in the past we didn't required Documentation for new features

Please explain what is drivertest and which kind of tests are executed currently

@Zepp-Hanzj

Copy link
Copy Markdown
Contributor Author

Thanks. I expanded the drivertest documentation to explain what the test collection is, how its applications are selected and run, the current test categories, and the watchdog reset/notifier cases.

The documentation source is in the main NuttX repository, so the change is in the companion NuttX PR #19433, commit 2eef87d73c.

I also verified the complete documentation tree with Sphinx using -W --keep-going; the build passed without warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants