Skip to content

Commit 68c7164

Browse files
authored
Revert "[test] Convert select and poll tests to using clock_gettime " (emscripten-core#26397)
Reverts emscripten-core#26280 `core3.test_select_blocking` on the linux release builder was permanently failing. I'll try to look into failures tomorrow. https://logs.chromium.org/logs/emscripten-releases/buildbucket/cr-buildbucket/8688158203848069089/+/u/Emscripten_testsuite__core3_/stdout
1 parent cee62bc commit 68c7164

File tree

4 files changed

+59
-75
lines changed

4 files changed

+59
-75
lines changed

test/core/test_poll_blocking.c

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,41 @@ void sleep_ms(int ms) {
2222
usleep(ms * 1000);
2323
}
2424

25-
int64_t timespec_delta_ms(struct timespec* begin, struct timespec* end) {
26-
int64_t delta_sec = end->tv_sec - begin->tv_sec;
27-
int64_t delta_nsec = end->tv_nsec - begin->tv_nsec;
28-
29-
assert(delta_sec >= 0);
30-
assert(delta_nsec > -1000000000 && delta_nsec < 1000000000);
31-
32-
int64_t delta_ms = (delta_sec * 1000) + (delta_nsec / 1000000);
33-
assert(delta_ms >= 0);
34-
return delta_ms;
25+
int64_t timeval_delta_ms(struct timeval* begin, struct timeval* end) {
26+
int64_t delta_s = end->tv_sec - begin->tv_sec;
27+
int64_t delta_us = end->tv_usec - begin->tv_usec;
28+
assert(delta_s >= 0);
29+
return (delta_s * 1000) + (delta_us / 1000);
3530
}
3631

3732
// Check if timeout works without fds
3833
void test_timeout_without_fds() {
3934
printf("test_timeout_without_fds\n");
40-
struct timespec begin, end;
35+
struct timeval begin, end;
4136

42-
clock_gettime(CLOCK_MONOTONIC, &begin);
37+
gettimeofday(&begin, NULL);
4338
assert(poll(NULL, 0, TIMEOUT_MS) == 0);
44-
clock_gettime(CLOCK_MONOTONIC, &end);
39+
gettimeofday(&end, NULL);
4540

46-
int64_t duration = timespec_delta_ms(&begin, &end);
41+
int64_t duration = timeval_delta_ms(&begin, &end);
4742
printf(" -> duration: %lld ms\n", duration);
4843
assert(duration >= TIMEOUT_MS);
4944
}
5045

5146
// Check if timeout works with fds without events
5247
void test_timeout_with_fds_without_events() {
5348
printf("test_timeout_with_fds_without_events\n");
54-
struct timespec begin, end;
49+
struct timeval begin, end;
5550
int pipe_a[2];
5651

5752
assert(pipe(pipe_a) == 0);
5853

59-
clock_gettime(CLOCK_MONOTONIC, &begin);
54+
gettimeofday(&begin, NULL);
6055
struct pollfd fds = {pipe_a[0], 0, 0};
6156
assert(poll(&fds, 1, TIMEOUT_MS) == 0);
62-
clock_gettime(CLOCK_MONOTONIC, &end);
57+
gettimeofday(&end, NULL);
6358

64-
int64_t duration = timespec_delta_ms(&begin, &end);
59+
int64_t duration = timeval_delta_ms(&begin, &end);
6560
printf(" -> duration: %lld ms\n", duration);
6661
assert(duration >= TIMEOUT_MS);
6762

@@ -82,7 +77,7 @@ void *write_after_sleep(void * arg) {
8277
// Check if poll can unblock on an event
8378
void test_unblock_poll() {
8479
printf("test_unblock_poll\n");
85-
struct timespec begin, end;
80+
struct timeval begin, end;
8681
pthread_t tid;
8782
int pipe_a[2];
8883

@@ -93,13 +88,13 @@ void test_unblock_poll() {
9388
{pipe_a[0], POLLIN, 0},
9489
{pipe_shared[0], POLLIN, 0},
9590
};
96-
clock_gettime(CLOCK_MONOTONIC, &begin);
91+
gettimeofday(&begin, NULL);
9792
assert(pthread_create(&tid, NULL, write_after_sleep, NULL) == 0);
9893
assert(poll(fds, 2, -1) == 1);
99-
clock_gettime(CLOCK_MONOTONIC, &end);
94+
gettimeofday(&end, NULL);
10095
assert(fds[1].revents & POLLIN);
10196

102-
int64_t duration = timespec_delta_ms(&begin, &end);
97+
int64_t duration = timeval_delta_ms(&begin, &end);
10398
printf(" -> duration: %lld ms\n", duration);
10499
assert(duration >= TIMEOUT_MS);
105100

@@ -110,15 +105,15 @@ void test_unblock_poll() {
110105
}
111106

112107
void *do_poll_in_thread(void * arg) {
113-
struct timespec begin, end;
108+
struct timeval begin, end;
114109

115-
clock_gettime(CLOCK_MONOTONIC, &begin);
110+
gettimeofday(&begin, NULL);
116111
struct pollfd fds = {pipe_shared[0], POLLIN, 0};
117112
assert(poll(&fds, 1, 4000) == 1);
118-
clock_gettime(CLOCK_MONOTONIC, &end);
113+
gettimeofday(&end, NULL);
119114
assert(fds.revents & POLLIN);
120115

121-
int64_t duration = timespec_delta_ms(&begin, &end);
116+
int64_t duration = timeval_delta_ms(&begin, &end);
122117
printf(" -> duration: %lld ms\n", duration);
123118
assert((duration >= TIMEOUT_MS) && (duration < 4000));
124119

test/core/test_poll_blocking_asyncify.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,23 @@
1919

2020
#include <emscripten/eventloop.h>
2121

22-
int64_t timespec_delta_ms(struct timespec* begin, struct timespec* end) {
23-
int64_t delta_sec = end->tv_sec - begin->tv_sec;
24-
int64_t delta_nsec = end->tv_nsec - begin->tv_nsec;
25-
26-
assert(delta_sec >= 0);
27-
assert(delta_nsec > -1000000000 && delta_nsec < 1000000000);
28-
29-
int64_t delta_ms = (delta_sec * 1000) + (delta_nsec / 1000000);
30-
assert(delta_ms >= 0);
31-
return delta_ms;
22+
int64_t timeval_delta_ms(struct timeval* begin, struct timeval* end) {
23+
int64_t delta_s = end->tv_sec - begin->tv_sec;
24+
int64_t delta_us = end->tv_usec - begin->tv_usec;
25+
assert(delta_s >= 0);
26+
return (delta_s * 1000) + (delta_us / 1000);
3227
}
3328

3429
// Check if timeout works without fds
3530
void test_timeout_without_fds() {
3631
printf("test_timeout_without_fds\n");
37-
struct timespec begin = {0};
38-
struct timespec end = {0};
32+
struct timeval begin, end;
3933

40-
clock_gettime(CLOCK_MONOTONIC, &begin);
34+
gettimeofday(&begin, NULL);
4135
assert(poll(NULL, 0, 1000) == 0);
42-
clock_gettime(CLOCK_MONOTONIC, &end);
36+
gettimeofday(&end, NULL);
4337

44-
int64_t duration = timespec_delta_ms(&begin, &end);
38+
int64_t duration = timeval_delta_ms(&begin, &end);
4539
printf(" -> duration: %lld ms\n", duration);
4640
assert(duration >= 1000);
4741
}
@@ -57,8 +51,7 @@ void write_to_pipe(void * arg) {
5751
// Check if poll can unblock on an event
5852
void test_unblock_poll() {
5953
printf("test_unblock_poll\n");
60-
struct timespec begin = {0};
61-
struct timespec end = {0};
54+
struct timeval begin, end;
6255
int pipe_a[2];
6356

6457
assert(pipe(pipe_a) == 0);
@@ -69,12 +62,12 @@ void test_unblock_poll() {
6962
{pipe_shared[0], POLLIN, 0},
7063
};
7164
emscripten_set_timeout(write_to_pipe, 1000, NULL);
72-
clock_gettime(CLOCK_MONOTONIC, &begin);
65+
gettimeofday(&begin, NULL);
7366
assert(poll(fds, 2, -1) == 1);
74-
clock_gettime(CLOCK_MONOTONIC, &end);
67+
gettimeofday(&end, NULL);
7568
assert(fds[1].revents & POLLIN);
7669

77-
int64_t duration = timespec_delta_ms(&begin, &end);
70+
int64_t duration = timeval_delta_ms(&begin, &end);
7871
printf(" -> duration: %lld ms\n", duration);
7972
assert(duration >= 1000);
8073

test/core/test_select_blocking.c

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,33 @@ void sleep_ms(int ms) {
1919
usleep(ms * 1000);
2020
}
2121

22-
int64_t timespec_delta_ms(struct timespec* begin, struct timespec* end) {
23-
int64_t delta_sec = end->tv_sec - begin->tv_sec;
24-
int64_t delta_nsec = end->tv_nsec - begin->tv_nsec;
25-
26-
assert(delta_sec >= 0);
27-
assert(delta_nsec > -1000000000 && delta_nsec < 1000000000);
28-
29-
int64_t delta_ms = (delta_sec * 1000) + (delta_nsec / 1000000);
30-
assert(delta_ms >= 0);
31-
return delta_ms;
22+
int64_t timeval_delta_ms(struct timeval* begin, struct timeval* end) {
23+
int64_t delta_s = end->tv_sec - begin->tv_sec;
24+
int64_t delta_us = end->tv_usec - begin->tv_usec;
25+
assert(delta_s >= 0);
26+
return (delta_s * 1000) + (delta_us / 1000);
3227
}
3328

3429
// Check if timeout works without fds
3530
void test_timeout_without_fds() {
3631
printf("test_timeout_without_fds\n");
37-
struct timespec begin, end;
38-
struct timeval tv;
32+
struct timeval tv, begin, end;
3933

4034
tv.tv_sec = 0;
4135
tv.tv_usec = TIMEOUT_MS * 1000;
42-
clock_gettime(CLOCK_MONOTONIC, &begin);
36+
gettimeofday(&begin, NULL);
4337
assert(select(0, NULL, NULL, NULL, &tv) == 0);
44-
clock_gettime(CLOCK_MONOTONIC, &end);
38+
gettimeofday(&end, NULL);
4539

46-
int64_t duration = timespec_delta_ms(&begin, &end);
40+
int64_t duration = timeval_delta_ms(&begin, &end);
4741
printf(" -> duration: %lld ms\n", duration);
4842
assert(duration >= TIMEOUT_MS);
4943
}
5044

5145
// Check if timeout works with fds without events
5246
void test_timeout_with_fds_without_events() {
5347
printf("test_timeout_with_fds_without_events\n");
54-
struct timespec begin, end;
55-
struct timeval tv;
48+
struct timeval tv, begin, end;
5649
fd_set readfds;
5750
int pipe_a[2];
5851

@@ -62,11 +55,11 @@ void test_timeout_with_fds_without_events() {
6255
tv.tv_usec = TIMEOUT_MS * 1000;
6356
FD_ZERO(&readfds);
6457
FD_SET(pipe_a[0], &readfds);
65-
clock_gettime(CLOCK_MONOTONIC, &begin);
58+
gettimeofday(&begin, NULL);
6659
assert(select(pipe_a[0] + 1, &readfds, NULL, NULL, &tv) == 0);
67-
clock_gettime(CLOCK_MONOTONIC, &end);
60+
gettimeofday(&end, NULL);
6861

69-
int64_t duration = timespec_delta_ms(&begin, &end);
62+
int64_t duration = timeval_delta_ms(&begin, &end);
7063
printf(" -> duration: %lld ms\n", duration);
7164
assert(duration >= TIMEOUT_MS);
7265

@@ -87,7 +80,7 @@ void *write_after_sleep(void * arg) {
8780
// Check if select can unblock on an event
8881
void test_unblock_select() {
8982
printf("test_unblock_select\n");
90-
struct timespec begin, end;
83+
struct timeval begin, end;
9184
fd_set readfds;
9285
pthread_t tid;
9386
int pipe_a[2];
@@ -99,13 +92,13 @@ void test_unblock_select() {
9992
FD_SET(pipe_a[0], &readfds);
10093
FD_SET(pipe_shared[0], &readfds);
10194
int maxfd = (pipe_a[0] > pipe_shared[0] ? pipe_a[0] : pipe_shared[0]);
102-
clock_gettime(CLOCK_MONOTONIC, &begin);
95+
gettimeofday(&begin, NULL);
10396
assert(pthread_create(&tid, NULL, write_after_sleep, NULL) == 0);
10497
assert(select(maxfd + 1, &readfds, NULL, NULL, NULL) == 1);
105-
clock_gettime(CLOCK_MONOTONIC, &end);
98+
gettimeofday(&end, NULL);
10699
assert(FD_ISSET(pipe_shared[0], &readfds));
107100

108-
int64_t duration = timespec_delta_ms(&begin, &end);
101+
int64_t duration = timeval_delta_ms(&begin, &end);
109102
printf(" -> duration: %lld ms\n", duration);
110103
assert(duration >= TIMEOUT_MS);
111104

@@ -116,22 +109,22 @@ void test_unblock_select() {
116109
}
117110

118111
void *do_select_in_thread(void * arg) {
119-
struct timespec begin, end;
120-
struct timeval tv;
112+
struct timeval begin, end;
121113
fd_set readfds;
114+
struct timeval tv;
122115
tv.tv_sec = 4;
123116
tv.tv_usec = 0;
124117

125118
FD_ZERO(&readfds);
126119
FD_SET(pipe_shared[0], &readfds);
127120
int maxfd = pipe_shared[0];
128121

129-
clock_gettime(CLOCK_MONOTONIC, &begin);
122+
gettimeofday(&begin, NULL);
130123
assert(select(maxfd + 1, &readfds, NULL, NULL, &tv) == 1);
131-
clock_gettime(CLOCK_MONOTONIC, &end);
124+
gettimeofday(&end, NULL);
132125
assert(FD_ISSET(pipe_shared[0], &readfds));
133126

134-
int64_t duration = timespec_delta_ms(&begin, &end);
127+
int64_t duration = timeval_delta_ms(&begin, &end);
135128
printf(" -> duration: %lld ms\n", duration);
136129
assert((duration >= TIMEOUT_MS) && (duration < 4000));
137130

test/test_core.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9573,14 +9573,17 @@ def test_syscall_intercept(self):
95739573
self.do_core_test('test_syscall_intercept.c')
95749574

95759575
@requires_pthreads
9576+
@flaky('https://github.com/emscripten-core/emscripten/issues/26256')
95769577
def test_select_blocking(self):
95779578
self.do_runf('core/test_select_blocking.c', cflags=['-pthread', '-sPROXY_TO_PTHREAD=1', '-sEXIT_RUNTIME=1'])
95789579

95799580
@requires_pthreads
9581+
@flaky('https://github.com/emscripten-core/emscripten/issues/26256')
95809582
def test_poll_blocking(self):
95819583
self.do_runf('core/test_poll_blocking.c', cflags=['-pthread', '-sPROXY_TO_PTHREAD=1', '-sEXIT_RUNTIME=1'])
95829584

95839585
@with_asyncify_and_jspi
9586+
@flaky('https://github.com/emscripten-core/emscripten/issues/26256')
95849587
def test_poll_blocking_asyncify(self):
95859588
if self.get_setting('JSPI') and engine_is_v8(self.get_current_js_engine()):
95869589
self.skipTest('test requires setTimeout which is not supported under v8')

0 commit comments

Comments
 (0)