Skip to content

test: add Watchdog unit tests#170

Open
aki1770-del wants to merge 1 commit intotoyota-connected:v2.0from
aki1770-del:test/watchdog-unit-tests
Open

test: add Watchdog unit tests#170
aki1770-del wants to merge 1 commit intotoyota-connected:v2.0from
aki1770-del:test/watchdog-unit-tests

Conversation

@aki1770-del
Copy link
Copy Markdown

Summary

Add unit test coverage for the Watchdog class, which previously had none.

8 test cases covering:

  • Construction (default + custom interval)
  • Start → pet → stop lifecycle (no timeout fires)
  • Pet extending deadline beyond a single interval period
  • Double-stop safety
  • Stop before start safety
  • RAII destructor cleanup (thread joins on destruction)
  • Timeout death test (EXPECT_EXIT when watchdog is not petted)

Production change: one parameterized constructor Watchdog(std::chrono::microseconds interval) added for testability (5 lines in watchdog.cc, 11 lines in watchdog.h). The default constructor is unchanged.

Motivation

Component Has tests? Lines
EventTimer 221
Configuration 368
FlutterView 138
Utils 129
SharedLibrary 83
Watchdog 0

The Watchdog class manages a critical thread-safety boundary (deadline polling from a background thread). Adding test coverage validates the start/pet/stop contract and ensures the timeout path functions correctly.

The tests are compatible with the jw/reliability-fixes atomic deadline changes — they validate the public API without depending on internal representation.

Test results

[==========] 8 tests from 6 test suites ran. (2255 ms total)
[  PASSED  ] 8 tests.

Built and tested with Clang 18 on Ubuntu 24.04.

Files changed

  • shell/watchdog.h — parameterized constructor declaration (+11)
  • shell/watchdog.cc — parameterized constructor implementation (+5)
  • test/unit_test/watchdog-test/test_case_watchdog.cc — 8 test cases (new)
  • test/unit_test/watchdog-test/CMakeLists.txt — build config (new)
  • test/unit_test/CMakeLists.txt — register watchdog-test subdirectory (+1)

Add 8 GTest cases covering the Watchdog class lifecycle:
- Default and parameterized construction
- Start/pet/stop normal lifecycle
- Pet extending deadline beyond single interval
- Double-stop and stop-before-start safety
- RAII destructor thread cleanup
- Timeout death test (EXPECT_EXIT on unpetted watchdog)

Add a parameterized constructor Watchdog(std::chrono::microseconds)
to enable testing with short intervals without affecting the default
or systemd-provided timeout.

The Watchdog class previously had zero test coverage. These tests
validate the thread lifecycle and timeout behavior on v2.0 and are
compatible with the atomic deadline changes on jw/reliability-fixes.

Signed-off-by: Akihiko Komada <aki1770@gmail.com>
@aki1770-del aki1770-del requested a review from jwinarske as a code owner March 1, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant