Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixups to timer_api test #24080

Merged
merged 2 commits into from
Apr 22, 2020

Conversation

andyross
Copy link
Contributor

@andyross andyross commented Apr 3, 2020

This test sets a timer, busy waits for half the duration, and then
checks the remaining time is correct. And it correctly does all its
math in tick precision and aligns to a timer interrupt to eliminate
aliasing due to the tick stride.

But it's waiting using k_busy_wait(), not a timer: "half the duration"
in MICROSECONDS (for k_busy_wait()) is not necessarily representable
as an integer number of TICKS on all platforms. Because k_busy_wait()
always rounds up, we need one extra tick of buffer on those platforms.

Fixes #24001

Signed-off-by: Andy Ross [email protected]

@andyross
Copy link
Contributor Author

andyross commented Apr 3, 2020

@dcpleung reported this on the microchip board. I haven't tested it there, and (oddly) it doesn't seem to happen on my nRF board which should have roughly the same properties. He should validate before merge.

@nashif nashif added the block: HW Test Testing on hardware required before merging label Apr 3, 2020
@zephyrbot zephyrbot added area: Tests Issues related to a particular existing or missing test area: Kernel labels Apr 3, 2020
@andyross
Copy link
Contributor Author

andyross commented Apr 3, 2020

(FWIW: I just remembered that nRF are 1:1 with ticks:cycles, so they aren't subject to this problem. We should check, if the microchip config has a non-divisible ratio we should fix that because it can cause problems like this in app code.)

Copy link
Member

@dcpleung dcpleung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixed the test_timer_remaining() test on mec15xxevb_assy6853. (relates to #24001)

@pabigot
Copy link
Collaborator

pabigot commented Apr 4, 2020

While Nordic has ticks and cycles the same, the busywait uses a different clock. Further, on it an integral number of ticks is rarely an exact number of milliseconds. So this may also be a factor in #23106.

@nashif
Copy link
Member

nashif commented Apr 4, 2020

just ran this on a few boards:

junit2html sanity-out/*.xml  --summary-matrix

Matrix Test Report
===================
                                                  disco_l475_iot1.xml
                                                  | frdm_k64f.xml
                                                  | | hifive1_revb.xml
                                                  | | | mimxrt1050_evk.xml
                                                  | | | | nrf52_pca10040.xml
                                                  | | | | | nucleo_f207zg.xml
                                                  | | | | | | reel_board.xml
                                                  | | | | | | | sam_e70_xplained.xml
                                                  | | | | | | | |
disco_l475_iot1:kernel.timer
- kernel.timer.time_conversions                   /                / Passed
- kernel.timer.timeout_abs                        /                / Passed
- kernel.timer.timer_duration_period              /                / Passed
- kernel.timer.timer_expirefn_null                /                / Passed
- kernel.timer.timer_k_define                     f                F Total Failure
- kernel.timer.timer_period_0                     /                / Passed
- kernel.timer.timer_periodicity                  /                / Passed
- kernel.timer.timer_remaining                    /                / Passed
- kernel.timer.timer_status_get                   /                / Passed
- kernel.timer.timer_status_get_anytime           /                / Passed
- kernel.timer.timer_status_sync                  /                / Passed
- kernel.timer.timer_user_data                    /                / Passed
disco_l475_iot1:kernel.timer.tickless
- kernel.timer.tickless.time_conversions          /                / Passed
- kernel.timer.tickless.timeout_abs               /                / Passed
- kernel.timer.tickless.timer_duration_period     /                / Passed
- kernel.timer.tickless.timer_expirefn_null       /                / Passed
- kernel.timer.tickless.timer_k_define            /                / Passed
- kernel.timer.tickless.timer_period_0            /                / Passed
- kernel.timer.tickless.timer_periodicity         /                / Passed
- kernel.timer.tickless.timer_remaining           /                / Passed
- kernel.timer.tickless.timer_status_get          /                / Passed
- kernel.timer.tickless.timer_status_get_anytime  /                / Passed
- kernel.timer.tickless.timer_status_sync         /                / Passed
- kernel.timer.tickless.timer_user_data           /                / Passed
frdm_k64f:kernel.timer
- kernel.timer.time_conversions                     /              / Passed
- kernel.timer.timeout_abs                          /              / Passed
- kernel.timer.timer_duration_period                /              / Passed
- kernel.timer.timer_expirefn_null                  /              / Passed
- kernel.timer.timer_k_define                       /              / Passed
- kernel.timer.timer_period_0                       /              / Passed
- kernel.timer.timer_periodicity                    /              / Passed
- kernel.timer.timer_remaining                      /              / Passed
- kernel.timer.timer_status_get                     /              / Passed
- kernel.timer.timer_status_get_anytime             /              / Passed
- kernel.timer.timer_status_sync                    /              / Passed
- kernel.timer.timer_user_data                      /              / Passed
frdm_k64f:kernel.timer.tickless
- kernel.timer.tickless.time_conversions            /              / Passed
- kernel.timer.tickless.timeout_abs                 /              / Passed
- kernel.timer.tickless.timer_duration_period       /              / Passed
- kernel.timer.tickless.timer_expirefn_null         /              / Passed
- kernel.timer.tickless.timer_k_define              /              / Passed
- kernel.timer.tickless.timer_period_0              /              / Passed
- kernel.timer.tickless.timer_periodicity           /              / Passed
- kernel.timer.tickless.timer_remaining             /              / Passed
- kernel.timer.tickless.timer_status_get            /              / Passed
- kernel.timer.tickless.timer_status_get_anytime    /              / Passed
- kernel.timer.tickless.timer_status_sync           /              / Passed
- kernel.timer.tickless.timer_user_data             /              / Passed
hifive1_revb:kernel.timer
- kernel.timer.time_conversions                       f            F Total Failure
- kernel.timer.timeout_abs                            f            F Total Failure
- kernel.timer.timer_duration_period                  f            F Total Failure
- kernel.timer.timer_expirefn_null                    f            F Total Failure
- kernel.timer.timer_k_define                         f            F Total Failure
- kernel.timer.timer_period_0                         f            F Total Failure
- kernel.timer.timer_periodicity                      f            F Total Failure
- kernel.timer.timer_remaining                        f            F Total Failure
- kernel.timer.timer_status_get                       f            F Total Failure
- kernel.timer.timer_status_get_anytime               f            F Total Failure
- kernel.timer.timer_status_sync                      f            F Total Failure
- kernel.timer.timer_user_data                        f            F Total Failure
mimxrt1050_evk:kernel.timer
- kernel.timer.time_conversions                         /          / Passed
- kernel.timer.timeout_abs                              /          / Passed
- kernel.timer.timer_duration_period                    /          / Passed
- kernel.timer.timer_expirefn_null                      /          / Passed
- kernel.timer.timer_k_define                           /          / Passed
- kernel.timer.timer_period_0                           /          / Passed
- kernel.timer.timer_periodicity                        /          / Passed
- kernel.timer.timer_remaining                          /          / Passed
- kernel.timer.timer_status_get                         /          / Passed
- kernel.timer.timer_status_get_anytime                 /          / Passed
- kernel.timer.timer_status_sync                        /          / Passed
- kernel.timer.timer_user_data                          /          / Passed
mimxrt1050_evk:kernel.timer.tickless
- kernel.timer.tickless.time_conversions                /          / Passed
- kernel.timer.tickless.timeout_abs                     /          / Passed
- kernel.timer.tickless.timer_duration_period           /          / Passed
- kernel.timer.tickless.timer_expirefn_null             /          / Passed
- kernel.timer.tickless.timer_k_define                  /          / Passed
- kernel.timer.tickless.timer_period_0                  /          / Passed
- kernel.timer.tickless.timer_periodicity               /          / Passed
- kernel.timer.tickless.timer_remaining                 /          / Passed
- kernel.timer.tickless.timer_status_get                /          / Passed
- kernel.timer.tickless.timer_status_get_anytime        /          / Passed
- kernel.timer.tickless.timer_status_sync               /          / Passed
- kernel.timer.tickless.timer_user_data                 /          / Passed
nrf52_pca10040:kernel.timer
- kernel.timer.time_conversions                           /        / Passed
- kernel.timer.timeout_abs                                f        F Total Failure
- kernel.timer.timer_duration_period                      /        / Passed
- kernel.timer.timer_expirefn_null                        /        / Passed
- kernel.timer.timer_k_define                             /        / Passed
- kernel.timer.timer_period_0                             /        / Passed
- kernel.timer.timer_periodicity                          /        / Passed
- kernel.timer.timer_remaining                            f        F Total Failure
- kernel.timer.timer_status_get                           /        / Passed
- kernel.timer.timer_status_get_anytime                   /        / Passed
- kernel.timer.timer_status_sync                          /        / Passed
- kernel.timer.timer_user_data                            /        / Passed
nrf52_pca10040:kernel.timer.tickless
- kernel.timer.tickless.time_conversions                  /        / Passed
- kernel.timer.tickless.timeout_abs                       f        F Total Failure
- kernel.timer.tickless.timer_duration_period             /        / Passed
- kernel.timer.tickless.timer_expirefn_null               /        / Passed
- kernel.timer.tickless.timer_k_define                    /        / Passed
- kernel.timer.tickless.timer_period_0                    /        / Passed
- kernel.timer.tickless.timer_periodicity                 /        / Passed
- kernel.timer.tickless.timer_remaining                   f        F Total Failure
- kernel.timer.tickless.timer_status_get                  /        / Passed
- kernel.timer.tickless.timer_status_get_anytime          /        / Passed
- kernel.timer.tickless.timer_status_sync                 /        / Passed
- kernel.timer.tickless.timer_user_data                   /        / Passed
nucleo_f207zg:kernel.timer
- kernel.timer.time_conversions                             /      / Passed
- kernel.timer.timeout_abs                                  /      / Passed
- kernel.timer.timer_duration_period                        /      / Passed
- kernel.timer.timer_expirefn_null                          /      / Passed
- kernel.timer.timer_k_define                               /      / Passed
- kernel.timer.timer_period_0                               /      / Passed
- kernel.timer.timer_periodicity                            /      / Passed
- kernel.timer.timer_remaining                              /      / Passed
- kernel.timer.timer_status_get                             /      / Passed
- kernel.timer.timer_status_get_anytime                     /      / Passed
- kernel.timer.timer_status_sync                            /      / Passed
- kernel.timer.timer_user_data                              /      / Passed
nucleo_f207zg:kernel.timer.tickless
- kernel.timer.tickless.time_conversions                    /      / Passed
- kernel.timer.tickless.timeout_abs                         /      / Passed
- kernel.timer.tickless.timer_duration_period               /      / Passed
- kernel.timer.tickless.timer_expirefn_null                 /      / Passed
- kernel.timer.tickless.timer_k_define                      /      / Passed
- kernel.timer.tickless.timer_period_0                      /      / Passed
- kernel.timer.tickless.timer_periodicity                   /      / Passed
- kernel.timer.tickless.timer_remaining                     /      / Passed
- kernel.timer.tickless.timer_status_get                    /      / Passed
- kernel.timer.tickless.timer_status_get_anytime            /      / Passed
- kernel.timer.tickless.timer_status_sync                   /      / Passed
- kernel.timer.tickless.timer_user_data                     /      / Passed
reel_board:kernel.timer
- kernel.timer.time_conversions                               /    / Passed
- kernel.timer.timeout_abs                                    f    F Total Failure
- kernel.timer.timer_duration_period                          /    / Passed
- kernel.timer.timer_expirefn_null                            /    / Passed
- kernel.timer.timer_k_define                                 /    / Passed
- kernel.timer.timer_period_0                                 /    / Passed
- kernel.timer.timer_periodicity                              /    / Passed
- kernel.timer.timer_remaining                                /    / Passed
- kernel.timer.timer_status_get                               /    / Passed
- kernel.timer.timer_status_get_anytime                       /    / Passed
- kernel.timer.timer_status_sync                              /    / Passed
- kernel.timer.timer_user_data                                /    / Passed
reel_board:kernel.timer.tickless
- kernel.timer.tickless.time_conversions                      /    / Passed
- kernel.timer.tickless.timeout_abs                           f    F Total Failure
- kernel.timer.tickless.timer_duration_period                 /    / Passed
- kernel.timer.tickless.timer_expirefn_null                   /    / Passed
- kernel.timer.tickless.timer_k_define                        /    / Passed
- kernel.timer.tickless.timer_period_0                        /    / Passed
- kernel.timer.tickless.timer_periodicity                     /    / Passed
- kernel.timer.tickless.timer_remaining                       /    / Passed
- kernel.timer.tickless.timer_status_get                      /    / Passed
- kernel.timer.tickless.timer_status_get_anytime              /    / Passed
- kernel.timer.tickless.timer_status_sync                     /    / Passed
- kernel.timer.tickless.timer_user_data                       /    / Passed
sam_e70_xplained:kernel.timer
- kernel.timer.time_conversions                                 /  / Passed
- kernel.timer.timeout_abs                                      /  / Passed
- kernel.timer.timer_duration_period                            /  / Passed
- kernel.timer.timer_expirefn_null                              /  / Passed
- kernel.timer.timer_k_define                                   /  / Passed
- kernel.timer.timer_period_0                                   /  / Passed
- kernel.timer.timer_periodicity                                /  / Passed
- kernel.timer.timer_remaining                                  /  / Passed
- kernel.timer.timer_status_get                                 /  / Passed
- kernel.timer.timer_status_get_anytime                         /  / Passed
- kernel.timer.timer_status_sync                                /  / Passed
- kernel.timer.timer_user_data                                  /  / Passed
sam_e70_xplained:kernel.timer.tickless
- kernel.timer.tickless.time_conversions                        /  / Passed
- kernel.timer.tickless.timeout_abs                             /  / Passed
- kernel.timer.tickless.timer_duration_period                   /  / Passed
- kernel.timer.tickless.timer_expirefn_null                     /  / Passed
- kernel.timer.tickless.timer_k_define                          /  / Passed
- kernel.timer.tickless.timer_period_0                          /  / Passed
- kernel.timer.tickless.timer_periodicity                       /  / Passed
- kernel.timer.tickless.timer_remaining                         /  / Passed
- kernel.timer.tickless.timer_status_get                        /  / Passed
- kernel.timer.tickless.timer_status_get_anytime                /  / Passed
- kernel.timer.tickless.timer_status_sync                       /  / Passed
- kernel.timer.tickless.timer_user_data                         /  / Passed

-------------------------------------------------------------------------------
Test Results:
  Failed       :     19
  Passed       :    161

@andyross andyross changed the title tests/kernel/timer/timer_api: Correct tick math for odd freq timers Fixups to timer_api test Apr 7, 2020
@andyross
Copy link
Contributor Author

andyross commented Apr 7, 2020

Add a patch to fix the abs_timeout test's conversion goof.

Andy Ross added 2 commits April 8, 2020 13:19
This test sets a timer, busy waits for half the duration, and then
checks the remaining time is correct.  And it correctly does all its
math in tick precision and aligns to a timer interrupt to eliminate
aliasing due to the tick stride.

But it's waiting using k_busy_wait(), not a timer: "half the duration"
in MICROSECONDS (for k_busy_wait()) is not necessarily representable
as an integer number of TICKS on all platforms.  Because k_busy_wait()
always rounds up, we need one extra tick of buffer on those platforms.

Signed-off-by: Andy Ross <[email protected]>
The test of the absolute timeout feature was a simple whitebox test
that inspected the generated ticks field of different constructors for
identity.  But it wasn't simple enough, because it was doing a
ticks->ms->ticks conversion (at compile time, sigh) on the input data,
which is obviously lossy on platforms where ticks are shorter than
milliseconds by non-integral factors.

Fix to do the conversion in just one direction.

Signed-off-by: Andy Ross <[email protected]>
@andyross
Copy link
Contributor Author

andyross commented Apr 8, 2020

Rebase to clear out that weird doc failure.

@FRASTM
Copy link
Collaborator

FRASTM commented Apr 14, 2020

@andyross , I see your change to add one tick to the zassert_true(((s64_t)exp_ticks - (s64_t)now) <= (dur_ticks / 2) + 1, NULL);
My question was about the previous check : on our side, that
zassert_true(rem_ticks <= (dur_ticks / 2) + 1 , NULL);
is fixing same kind of error.
Why this one-tick delay you could not apply there ?

@FRASTM
Copy link
Collaborator

FRASTM commented Apr 14, 2020

Fixes #24072

@andrewboie
Copy link
Contributor

@nashif does this still cause regressions, or is it now an improvement on the master branch with your testing rig?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Kernel area: Tests Issues related to a particular existing or missing test block: HW Test Testing on hardware required before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tests/kernel/timer/timer_api failed on reel_board and mec15xxevb_assy6853.
9 participants