Skip to content

fix: clock type mismatch and duration cast unit in test_timer_t#1020

Closed
aki1770-del wants to merge 1 commit into
COVESA:masterfrom
aki1770-del:fix/issue821-test-timer-clock-type
Closed

fix: clock type mismatch and duration cast unit in test_timer_t#1020
aki1770-del wants to merge 1 commit into
COVESA:masterfrom
aki1770-del:fix/issue821-test-timer-clock-type

Conversation

@aki1770-del

Copy link
Copy Markdown

Fixes #821

Two bugs in test/common/include/common/test_timer.hpp:

Bug 1 — Clock type mismatch (compile error on Android/Clang)

start is declared as std::chrono::system_clock::time_point but initialized
via std::chrono::high_resolution_clock::now() in both constructors.

On platforms where high_resolution_clock is not an alias for system_clock
(Android x86_64 with Clang, MSVC), this fails with:

no matching constructor for initialization of 'std::chrono::system_clock::time_point'

Fix: change the member type to std::chrono::high_resolution_clock::time_point,
consistent with the initialization expression already present.

Bug 2 — Duration cast to wrong unit (logic error)

has_elapsed() casts the elapsed duration to std::chrono::seconds before
comparing against target, which is std::chrono::milliseconds. For sub-second
timers the cast always produces seconds(0), causing the timer to fire immediately
regardless of the target interval.

Fix: change duration_cast<std::chrono::seconds> to
duration_cast<std::chrono::milliseconds>.

Both fixes are single-line changes in the same header. No production code
is affected. No new includes or dependencies.

Two bugs in test/common/include/common/test_timer.hpp:

1. start member was declared as system_clock::time_point but initialized
   via high_resolution_clock::now() in both constructors. On platforms
   where high_resolution_clock is not an alias for system_clock (Android
   x86_64 with Clang, MSVC) this fails with:
     no matching constructor for initialization of
     'std::chrono::system_clock::time_point'
   Fix: change member type to high_resolution_clock::time_point,
   consistent with the initialization expression.

2. has_elapsed() cast the elapsed duration to std::chrono::seconds before
   comparing against target (std::chrono::milliseconds). For sub-second
   timers the cast always produces seconds(0), causing the timer to fire
   immediately regardless of target.
   Fix: use duration_cast<std::chrono::milliseconds> to match target units.

Fixes COVESA#821
@fcmonteiro fcmonteiro closed this Apr 21, 2026
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.

[BUG]: Clock Type Mismatch Causing Initialization Error in "offer_stop_offer_test"

2 participants