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

[Backport v3.2-branch] lib: posix: make sleep() and usleep() standards-compliant #52545

Merged
merged 4 commits into from
Nov 29, 2022

Conversation

zephyrbot
Copy link
Collaborator

@zephyrbot zephyrbot commented Nov 25, 2022

Backport 027b79e~4..027b79e from #52519

Fixes #51776
Fixes #52517
Fixes #52518

Using `usleep()` for >= 10000000 microseconds results
in an error, so this test was kind of defective, having
explicitly called `usleep()` for seconds.

Also, check the return values of `clock_gettime()`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
(cherry picked from commit 23a1f0a)
In the case that `sleep()` is interrupted, the POSIX spec requires
it to return the number of "unslept" seconds (i.e. the number of
seconds requested minus the number of seconds actually slept).

Since `k_sleep()` already returns the amount of "unslept" time
in ms, we can simply use that.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
(cherry picked from commit dcfcc64)
The original implementation of `usleep()` was not compliant
to the POSIX spec in 3 ways.
- calling thread may not be suspended (because `k_busy_wait()`
  was previously used for short durations)
- if `usecs` > 1000000, previously we did not return -1 or set
  `errno` to `EINVAL`
- if interrupted, previously we did not return -1 or set
  `errno` to `EINTR`

This change addresses those issues to make `usleep()` more
POSIX-compliant.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
(cherry picked from commit 7b95428)
Previously, there was no test coverage for `sleep()` and
`usleep()`.

This change adds full test coverage.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
(cherry picked from commit 027b79e)
@zephyrbot zephyrbot requested a review from pfalcon as a code owner November 25, 2022 00:32
@zephyrbot zephyrbot added the area: POSIX POSIX API Library label Nov 25, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 25, 2022

Codecov Report

❗ No coverage uploaded for pull request base (v3.2-branch@005b8af). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head 027b79e differs from pull request most recent head cfafa79. Consider uploading reports for the commit cfafa79 to get more accurate results

Impacted file tree graph

@@              Coverage Diff               @@
##             v3.2-branch   #52545   +/-   ##
==============================================
  Coverage               ?   50.53%           
==============================================
  Files                  ?      711           
  Lines                  ?    89949           
  Branches               ?    21250           
==============================================
  Hits                   ?    45455           
  Misses                 ?    36793           
  Partials               ?     7701           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 005b8af...cfafa79. Read the comment docs.

@stephanosio stephanosio requested a review from a team November 27, 2022 03:37
@fabiobaltieri fabiobaltieri merged commit 470c220 into v3.2-branch Nov 29, 2022
@nashif nashif deleted the backport-52519-to-v3.2-branch branch April 6, 2023 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: POSIX POSIX API Library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants