Skip to content

testing/drivers: add watchdog notifier cmocka coverage#3639

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

testing/drivers: add watchdog notifier cmocka coverage#3639
Zepp-Hanzj wants to merge 1 commit 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 Outdated
Comment thread testing/drivers/drivertest/Makefile Outdated
@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.

@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).

@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
@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
Comment thread testing/drivers/drivertest/drivertest_watchdog.c Outdated

@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.

Comment thread testing/drivers/drivertest/drivertest_watchdog.c Outdated
Comment thread testing/drivers/drivertest/drivertest_watchdog.c Outdated
Comment thread testing/drivers/drivertest/Makefile
@Zepp-Hanzj
Zepp-Hanzj force-pushed the fix/watchdog-notifier-tests branch from f26a62d to 7abf319 Compare July 20, 2026 10:01
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 Outdated
Extend the watchdog drivertest with notifier ordering, duplicate registration, repeated delivery, unregister, NULL-data, and concurrent registration coverage.

Register the watchdog test when either reset-cause or timeout-notifier support is available. Keep hardware watchdog cases gated by reset-cause support and allow notifier-only simulator builds through both Make and CMake.

Keep test state in the watchdog fixture and notifier blocks so callbacks do not depend on shared notifier state.

Assisted-by: OpenAI Codex
Signed-off-by: hanzhijian <hanzhijian@zepp.com>
@Zepp-Hanzj
Zepp-Hanzj force-pushed the fix/watchdog-notifier-tests branch from 7abf319 to cbddb03 Compare July 21, 2026 01:33
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