Enhance RTC handling with unit test support for system time fallback#10642
Merged
Conversation
7 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR strengthens RTC/system-time fallback behavior so that a later readFromRTC() (on platforms where gettimeofday() may only reflect uptime) won’t overwrite higher-quality time already established via network/GPS, while still allowing the fallback to seed time when nothing better exists. It also adds a native unit test suite with test seams to force the fallback path and inject deterministic system time.
Changes:
- Refactors the no-hardware-RTC
gettimeofday()path into a dedicated fallback that only seeds internal timekeeping when current quality isRTCQualityNone. - Adds unit-test-only hooks to inject/mock system time and force the fallback path even when a hardware-RTC branch is compiled.
- Introduces a new
test_rtcunit test suite covering preservation of higher-quality time and fallback seeding behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
test/test_rtc/test_main.cpp |
Adds regression tests validating fallback seeding and preservation of higher-quality network time. |
src/gps/RTC.h |
Exposes new PIO_UNIT_TESTING test seam APIs for RTC/system-time behavior. |
src/gps/RTC.cpp |
Implements system-time fallback helper, test seams for injected time/forced fallback, and adjusts readFromRTC()/perhapsSetRTC() behavior accordingly. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Evil8it
pushed a commit
to Evil8it/ME4TACTNK
that referenced
this pull request
Jun 10, 2026
…eshtastic#10642) * Enhance RTC handling with unit test support for system time fallback * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
NomDeTom
pushed a commit
to NomDeTom/MeshtasticFirmware
that referenced
this pull request
Jun 25, 2026
…eshtastic#10642) * Enhance RTC handling with unit test support for system time fallback * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> (cherry picked from commit c7f17a8)
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.
This pull request adds robust unit testing support and fixes for RTC (real-time clock) fallback logic, especially for platforms without a hardware RTC (like RP2040). The main focus is to ensure that the system time fallback does not overwrite higher-quality time sources (e.g., from GPS or network) and to allow deterministic testing of time-related logic. It introduces test seams, new helper functions for tests, and regression tests for a previously reported issue.
Closes #9828
Key changes:
RTC fallback improvements and test seams:
RTC.cppto allow injection and control of system time and fallback behavior during unit tests, enabling deterministic and isolated testing of RTC logic.readFromRTC()and related code to use a newreadFromSystemTimeFallback()helper, ensuring system time is only adopted when no better source exists and simplifying the fallback handling.perhapsSetRTC().Unit test support functions:
RTC.cpp/RTC.hfor unit tests:resetRTCStateForTests(),setRTCSystemTimeForTests(),clearRTCSystemTimeForTests(), andsetReadFromRTCUseSystemTimeForTests(), enabling tests to control and reset RTC state and behavior. [1] [2]Regression and behavior tests:
test/test_rtc/test_main.cppto verify:These tests directly address issue [Bug]: RTC time overwritten with uptime on platforms without hardware RTC #9828 and validate the new test seams and fallback logic.