[sival, rv_timer] Fix the systick test's ticks bounds checking#29427
Draft
luismarques wants to merge 1 commit intolowRISC:masterfrom
Draft
[sival, rv_timer] Fix the systick test's ticks bounds checking#29427luismarques wants to merge 1 commit intolowRISC:masterfrom
luismarques wants to merge 1 commit intolowRISC:masterfrom
Conversation
Signed-off-by: Luís Marques <luismarques@lowrisc.org>
69da655 to
7c8963b
Compare
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.
The
chip_sw_rv_timer_systick_testtest is supposed to "Verify that the timer can be configured to generate a system tick (...) within 3% of tolerance". However, the existing implementation does not correctly enforce this tolerance:Because
kReferenceTimeMillis * 0.97andkReferenceTimeMillis * 1.03are cast to integers, their fractional parts are truncated. WithkReferenceTimeMillis == 5, the truncated bounds become4and5. As a result, the test effectively only checkselapsed_millis >= 4 && elapsed_millis <= 5, rather than the intended 3% tolerance.This PR adopts a different approach, that seemed more convenient, given the lack of floating-point math. Instead of converting the observed timer counter value to milliseconds, we directly compare it with the expected lower and upper number of ticks, for each tested frequency.
The
LOW_TICK_BOUNDandHIGH_TICK_BOUNDmacros and their uses could still be refined to improve precision and rounding, but that didn't seem essential for now, particularly given the very loose bounds of the previous implementation.