test: add Watchdog unit tests#170
Open
aki1770-del wants to merge 1 commit intotoyota-connected:v2.0from
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add unit test coverage for the
Watchdogclass, which previously had none.8 test cases covering:
EXPECT_EXITwhen 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
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-fixesatomic deadline changes — they validate the public API without depending on internal representation.Test results
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)