Skip to content

testing/drivers: add watchdog notifier cmocka coverage#3639

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

testing/drivers: add watchdog notifier cmocka coverage#3639
Zepp-Hanzj wants to merge 4 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 an independent watchdog-only drivertest configuration.

Changes

  • Add CONFIG_TESTING_DRIVER_TEST_WATCHDOG_ONLY.
  • When enabled, register only cmocka_driver_watchdog from the drivertest Makefile/CMake rules.
  • 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.
  • Guard reset-cause assertions so the notifier-only simulator configuration does not require board reset-cause support.

Validation

The test was run using the companion NuttX simulator configuration, which registers only the watchdog cmocka driver. The final result was:

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

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/configuration. 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.
  • Watchdog-only configuration does not register unrelated drivertest applications.
  • git diff --check passes.
  • 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
unsigned int index;

test_nb = (FAR struct watchdog_notifier_test_nb_s *)
((FAR char *)nb - offsetof(struct watchdog_notifier_test_nb_s,

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.

call container_of


#ifdef CONFIG_WATCHDOG_TIMEOUT_NOTIFIER

struct watchdog_notifier_test_nb_s

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 not merge into wdg_state_s

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.

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