Skip to content

[test] Convert select and poll tests to using clock_gettime #26280

Open
inolen wants to merge 2 commits intoemscripten-core:mainfrom
inolen:inolen/monotonic_poll_tests
Open

[test] Convert select and poll tests to using clock_gettime #26280
inolen wants to merge 2 commits intoemscripten-core:mainfrom
inolen:inolen/monotonic_poll_tests

Conversation

@inolen
Copy link
Collaborator

@inolen inolen commented Feb 16, 2026

Prefer clock_gettime with CLOCK_MONOTONIC instead of gettimeofday whose implementation isn't guaranteed to be monotonic.

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Thanks!

if (diff.tv_nsec < 0) {
diff.tv_nsec += 1000000000;
diff.tv_sec -= 1;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would a negative tv_nsec here not just work in the return calculation below since + (diff.tv_nsec / 1000000) would end up substracting ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think about this? I'd love to land this change but maybe this part is not needed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think.. how about just:

delta_sec = end->tv_sec - begin->tv_sec,
delta_nsec = end->tv_nsec - begin->tv_nsec
return (deleta_sec * 1000) + (delta_nsec / 1000000);

I think the possible negative delta_nsec will be fine here.

@inolen inolen force-pushed the inolen/monotonic_poll_tests branch from 4408d11 to 09ed72e Compare February 17, 2026 00:57
@sbc100 sbc100 changed the title test / convert new select and poll tests to using clock_gettime with [test] Convert new select and poll tests to using clock_gettime with Feb 17, 2026
@sbc100 sbc100 changed the title [test] Convert new select and poll tests to using clock_gettime with [test] Convert select and poll tests to using clock_gettime with Feb 17, 2026
@sbc100 sbc100 changed the title [test] Convert select and poll tests to using clock_gettime with [test] Convert select and poll tests to using clock_gettime Feb 17, 2026
@inolen
Copy link
Collaborator Author

inolen commented Feb 18, 2026

Also to note, I can't guarantee this fixes the CI issues, but it fixes these tests often failing in a comical fashion on my WSL setup. Before these changes, end would often be reported as a timestamp earlier than begin (so the delta would be negative).

@sbc100
Copy link
Collaborator

sbc100 commented Feb 18, 2026

Also to note, I can't guarantee this fixes the CI issues, but it fixes these tests often failing in a comical fashion on my WSL setup. Before these changes, end would often be reported as a timestamp earlier than begin (so the delta would be negative).

Can you confirm what you mean by on my WSL setup? Are you talking about taking the test code and building for the host system (WSL) rather then emscripten? Or are you seeing it fail comically under emscripten?

@inolen
Copy link
Collaborator Author

inolen commented Feb 18, 2026

I mean running the test through the python runner script on WSL.

@sbc100
Copy link
Collaborator

sbc100 commented Feb 19, 2026

I marked the tests as flaky until this PR landed. Can you undo #26305 as part of this PR?

CLOCK_MONOTONIC instead of gettimeofday whose implementation isn't
guaranteed to be monotonic
@inolen inolen force-pushed the inolen/monotonic_poll_tests branch from 09ed72e to 221c465 Compare February 19, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments