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

WIP: fix clock_settime 8-1 test case #927

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <sys/wait.h>
#include "posixtest.h"
#include "helpers.h"
#include "timespec.h"

#define SLEEPSEC 5
#define SMALLTIME 2
Expand All @@ -35,6 +36,10 @@ int main(void)
{
struct timespec tsT0, tssleep;
int pid;
long diffnano, diffnano_low, diffnano_high;

diffnano_low = (long)(SLEEPSEC - SMALLTIME) * NSEC_IN_SEC;
diffnano_high = (long)(SLEEPSEC - SMALLTIME + ACCEPTABLEDELTA) * NSEC_IN_SEC;

/* Check that we're root...can't call clock_settime with CLOCK_REALTIME otherwise */
if (getuid() != 0) {
Expand Down Expand Up @@ -67,6 +72,11 @@ int main(void)

expectedsec = tsT0.tv_sec + (SLEEPSEC - SMALLTIME);

diffnano = timespec_nsec_diff(&tsT0, &tsend);

printf("diffnano: %ld, > low: %d, < high: %d\n", diffnano, diffnano >= diffnano_low, diffnano <= diffnano_high);


if (tsend.tv_sec >= expectedsec) {
if ((tsend.tv_sec - expectedsec) <= ACCEPTABLEDELTA) {
return CHILDPASS;
Expand Down
3 changes: 0 additions & 3 deletions testcases/open_posix_testsuite/include/timespec.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,5 @@ static inline long timespec_nsec_diff(struct timespec *t1, struct timespec *t2)
sec_diff = t1->tv_sec - t2->tv_sec;
nsec_diff = t1->tv_nsec - t2->tv_nsec;

if (sec_diff > 1 || (sec_diff == 1 && nsec_diff >= 0))
return NSEC_IN_SEC;

Copy link
Member

Choose a reason for hiding this comment

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

I do not think that this is a good idea to remove this check as it is. The function returns long, which is 32bit on x86 which means that the result will overflow if the difference is slightly over 2 seconds.

It would make much more sense to add timespec_msec_diff() function that would return difference in miliseconds, which would be granular enough for the check in the test, but will not overflow like this, since we can store difference worth of days in 32bit integer in miliseconds.

return labs(nsec_diff + NSEC_IN_SEC * sec_diff);
}