Skip to content

Commit 7505c06

Browse files
committed
Cleanup the emscripten tests relating to the event loop. NFC
The browser tests were only being run in `PROXY_TO_PTHREAD` mode for some reason even though these tests should pass on the main thread. In test_other the `PROXY_TO_PTHREAD` flags were being passed as args (rather then emcc_args). Likely a copy/paste bug.
1 parent 52815ef commit 7505c06

6 files changed

+71
-70
lines changed

test/emscripten_performance_now.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ void test(void *userData) {
1212
double now3 = emscripten_date_now();
1313
assert(now3 >= dateNow + 100);
1414

15-
#ifdef REPORT_RESULT
16-
REPORT_RESULT(0);
17-
#endif
15+
exit(0);
1816
}
1917

2018
int main() {
@@ -30,4 +28,5 @@ int main() {
3028
#else
3129
emscripten_set_timeout(test, 200, 0);
3230
#endif
31+
return 99;
3332
}

test/emscripten_set_interval.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
int funcExecuted = 0;
88

99
void testDone(void *userData) {
10+
printf("testDone\n");
1011
assert((long)userData == 2);
1112
assert(funcExecuted == 10);
1213
exit(0);
@@ -15,6 +16,7 @@ void testDone(void *userData) {
1516
long intervalId = 0;
1617

1718
void tick(void *userData) {
19+
printf("tick: %d\n", funcExecuted);
1820
assert((long)userData == 1);
1921
++funcExecuted;
2022
if (funcExecuted == 10) {
@@ -28,6 +30,5 @@ void tick(void *userData) {
2830

2931
int main() {
3032
intervalId = emscripten_set_interval(tick, 100, (void*)1);
31-
emscripten_exit_with_live_runtime();
3233
return 99;
3334
}

test/emscripten_set_timeout.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
11
#include <emscripten/emscripten.h>
22
#include <emscripten/html5.h>
3-
#include <emscripten/em_asm.h>
43
#include <assert.h>
54
#include <stdlib.h>
5+
#include <stdio.h>
66

77
int func1Executed = 0;
88
int func2Executed = 0;
99

1010
void func1(void *userData);
1111

1212
void func2(void *userData) {
13-
assert((long)userData == 2);
1413
++func2Executed;
14+
printf("func2: %d\n", func2Executed);
15+
assert((long)userData == 2);
1516

16-
if (func2Executed == 1)
17-
{
17+
if (func2Executed == 1) {
1818
// Test canceling a setTimeout: register a callback but then cancel it immediately
1919
long id = emscripten_set_timeout(func1, 10, (void*)2);
2020
emscripten_clear_timeout(id);
2121

22+
// Without this, the test will not exit correctly
23+
// https://github.com/emscripten-core/emscripten/issues/23763
24+
emscripten_runtime_keepalive_pop();
25+
2226
emscripten_set_timeout(func2, 100, (void*)2);
2327
}
24-
if (func2Executed == 2)
25-
{
28+
29+
if (func2Executed == 2) {
2630
assert(func1Executed == 1);
31+
printf("done\n");
2732
exit(0);
2833
}
2934
}
3035

3136
void func1(void *userData) {
37+
printf("func1\n");
3238
assert((long)userData == 1);
3339
++func1Executed;
3440

@@ -39,6 +45,5 @@ void func1(void *userData) {
3945

4046
int main() {
4147
emscripten_set_timeout(func1, 100, (void*)1);
42-
emscripten_exit_with_live_runtime();
4348
return 99;
4449
}

test/emscripten_set_timeout_loop.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
#include <emscripten/emscripten.h>
22
#include <emscripten/html5.h>
3-
#include <emscripten/em_asm.h>
43
#include <assert.h>
54
#include <stdlib.h>
5+
#include <stdio.h>
66

77
double previousSetTimeouTime = 0;
88
int funcExecuted = 0;
99

1010
void testDone(void *userData) {
11+
printf("testDone\n");
1112
assert((long)userData == 2);
1213
assert(funcExecuted == 10);
14+
emscripten_runtime_keepalive_pop();
1315
exit(0);
1416
}
1517

1618
bool tick(double time, void *userData) {
19+
printf("tick: %d\n", funcExecuted);
1720
assert(time >= previousSetTimeouTime);
1821
previousSetTimeouTime = time;
1922
assert((long)userData == 1);
2023
++funcExecuted;
21-
if (funcExecuted == 10)
22-
{
24+
if (funcExecuted == 10) {
2325
emscripten_set_timeout(testDone, 300, (void*)2);
2426
}
2527
return funcExecuted < 10;
2628
}
2729

2830
int main() {
2931
emscripten_set_timeout_loop(tick, 100, (void*)1);
30-
emscripten_exit_with_live_runtime();
32+
emscripten_runtime_keepalive_push();
3133
return 99;
3234
}

test/test_browser.py

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,22 @@ def decorated(self, threads, *args, **kwargs):
199199
f(self, *args, **kwargs)
200200

201201
parameterize(decorated, {'': (False,),
202-
'pthreads': (True,)})
202+
'pthread': (True,)})
203+
204+
return decorated
205+
206+
207+
def also_with_proxy_to_pthread(f):
208+
assert callable(f)
209+
210+
@wraps(f)
211+
def decorated(self, threads, *args, **kwargs):
212+
if threads:
213+
self.emcc_args += ['-pthread', '-sPROXY_TO_PTHREAD']
214+
f(self, *args, **kwargs)
215+
216+
parameterize(decorated, {'': (False,),
217+
'pthread': (True,)})
203218

204219
return decorated
205220

@@ -495,14 +510,11 @@ def make_main_two_files(path1, path2, nonexistingpath):
495510
self.btest_exit('main.c', emcc_args=['--pre-js', 'pre.js', '--use-preload-plugins'])
496511

497512
# Tests that user .html shell files can manually download .data files created with --preload-file cmdline.
498-
@parameterized({
499-
'': ([],),
500-
'pthreads': (['-pthread', '-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME'],),
501-
})
502-
def test_preload_file_with_manual_data_download(self, args):
513+
@also_with_proxy_to_pthread
514+
def test_preload_file_with_manual_data_download(self):
503515
create_file('file.txt', 'Hello!')
504516

505-
self.compile_btest('browser/test_manual_download_data.c', ['-sEXIT_RUNTIME', '-o', 'out.js', '--preload-file', 'file.txt@/file.txt'] + args)
517+
self.compile_btest('browser/test_manual_download_data.c', ['-sEXIT_RUNTIME', '-o', 'out.js', '--preload-file', 'file.txt@/file.txt'])
506518
shutil.copy(test_file('browser/test_manual_download_data.html'), '.')
507519

508520
# Move .data file out of server root to ensure that getPreloadedPackage is actually used
@@ -1602,12 +1614,9 @@ def test_glfw_time(self):
16021614
def test_egl(self, args):
16031615
self.btest_exit('test_egl.c', emcc_args=['-O2', '-lEGL', '-lGL', '-sGL_ENABLE_GET_PROC_ADDRESS'] + args)
16041616

1605-
@parameterized({
1606-
'': ([],),
1607-
'proxy_to_pthread': (['-pthread', '-sPROXY_TO_PTHREAD'],),
1608-
})
1609-
def test_egl_width_height(self, args):
1610-
self.btest_exit('test_egl_width_height.c', emcc_args=['-O2', '-lEGL', '-lGL'] + args)
1617+
@also_with_proxy_to_pthread
1618+
def test_egl_width_height(self):
1619+
self.btest_exit('test_egl_width_height.c', emcc_args=['-O2', '-lEGL', '-lGL'])
16111620

16121621
@requires_graphics_hardware
16131622
def test_egl_createcontext_error(self):
@@ -1891,27 +1900,17 @@ def setup():
18911900
def test_emscripten_api_infloop(self):
18921901
self.btest_exit('emscripten_api_browser_infloop.cpp')
18931902

1894-
@parameterized({
1895-
'': ([],),
1896-
'pthreads': (['-pthread', '-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME'],),
1897-
})
1898-
def test_emscripten_main_loop(self, args):
1899-
self.btest_exit('test_emscripten_main_loop.c', emcc_args=args)
1903+
@also_with_proxy_to_pthread
1904+
def test_emscripten_main_loop(self):
1905+
self.btest_exit('test_emscripten_main_loop.c')
19001906

1901-
@parameterized({
1902-
'': ([],),
1903-
# test pthreads + AUTO_JS_LIBRARIES mode as well
1904-
'pthreads': (['-pthread', '-sPROXY_TO_PTHREAD', '-sAUTO_JS_LIBRARIES=0'],),
1905-
})
1906-
def test_emscripten_main_loop_settimeout(self, args):
1907-
self.btest_exit('test_emscripten_main_loop_settimeout.c', emcc_args=args)
1907+
@also_with_proxy_to_pthread
1908+
def test_emscripten_main_loop_settimeout(self):
1909+
self.btest_exit('test_emscripten_main_loop_settimeout.c', emcc_args=['-sAUTO_JS_LIBRARIES=0'])
19081910

1909-
@parameterized({
1910-
'': ([],),
1911-
'pthreads': (['-pthread', '-sPROXY_TO_PTHREAD'],),
1912-
})
1913-
def test_emscripten_main_loop_and_blocker(self, args):
1914-
self.btest_exit('test_emscripten_main_loop_and_blocker.c', emcc_args=args)
1911+
@also_with_proxy_to_pthread
1912+
def test_emscripten_main_loop_and_blocker(self):
1913+
self.btest_exit('test_emscripten_main_loop_and_blocker.c')
19151914

19161915
def test_emscripten_main_loop_and_blocker_exit(self):
19171916
# Same as above but tests that EXIT_RUNTIME works with emscripten_main_loop. The
@@ -1967,13 +1966,10 @@ def test_sdl_glshader2(self):
19671966
def test_gl_glteximage(self):
19681967
self.btest('gl_teximage.c', '1', emcc_args=['-lGL', '-lSDL'])
19691968

1970-
@parameterized({
1971-
'': ([],),
1972-
'pthreads': (['-pthread', '-sPROXY_TO_PTHREAD', '-sOFFSCREEN_FRAMEBUFFER'],),
1973-
})
19741969
@requires_graphics_hardware
1975-
def test_gl_textures(self, args):
1976-
self.btest_exit('gl_textures.c', emcc_args=['-lGL', '-g', '-sSTACK_SIZE=1MB'] + args)
1970+
@also_with_proxy_to_pthread
1971+
def test_gl_textures(self):
1972+
self.btest_exit('gl_textures.c', args=['-lGL', '-g', '-sSTACK_SIZE=1MB'])
19771973

19781974
@requires_graphics_hardware
19791975
def test_gl_ps(self):
@@ -2632,10 +2628,10 @@ def test_html5_core(self, opts):
26322628
self.emcc_args.append('--pre-js=pre.js')
26332629
self.btest_exit('test_html5_core.c', emcc_args=opts)
26342630

2631+
@also_with_proxy_to_pthread
26352632
@parameterized({
26362633
'': ([],),
26372634
'closure': (['-O2', '-g1', '--closure=1'],),
2638-
'pthread': (['-pthread', '-sPROXY_TO_PTHREAD'],),
26392635
})
26402636
def test_html5_gamepad(self, args):
26412637
self.btest_exit('test_gamepad.c', emcc_args=args)
@@ -4965,24 +4961,28 @@ def test_emscripten_request_animation_frame_loop(self):
49654961
def test_request_animation_frame(self):
49664962
self.btest_exit('test_request_animation_frame.c')
49674963

4964+
@also_with_proxy_to_pthread
49684965
def test_emscripten_set_timeout(self):
4969-
self.btest_exit('emscripten_set_timeout.c', emcc_args=['-pthread', '-sPROXY_TO_PTHREAD'])
4966+
self.btest_exit('emscripten_set_timeout.c')
49704967

4968+
@also_with_proxy_to_pthread
49714969
def test_emscripten_set_timeout_loop(self):
4972-
self.btest_exit('emscripten_set_timeout_loop.c', emcc_args=['-pthread', '-sPROXY_TO_PTHREAD'])
4970+
self.btest_exit('emscripten_set_timeout_loop.c')
49734971

49744972
def test_emscripten_set_immediate(self):
49754973
self.btest_exit('emscripten_set_immediate.c')
49764974

49774975
def test_emscripten_set_immediate_loop(self):
49784976
self.btest_exit('emscripten_set_immediate_loop.c')
49794977

4978+
@also_with_proxy_to_pthread
49804979
def test_emscripten_set_interval(self):
4981-
self.btest_exit('emscripten_set_interval.c', emcc_args=['-pthread', '-sPROXY_TO_PTHREAD'])
4980+
self.btest_exit('emscripten_set_interval.c')
49824981

49834982
# Test emscripten_performance_now() and emscripten_date_now()
4983+
@also_with_proxy_to_pthread
49844984
def test_emscripten_performance_now(self):
4985-
self.btest('emscripten_performance_now.c', '0', emcc_args=['-pthread', '-sPROXY_TO_PTHREAD'])
4985+
self.btest_exit('emscripten_performance_now.c')
49864986

49874987
def test_embind_with_pthreads(self):
49884988
self.btest_exit('embind/test_pthreads.cpp', emcc_args=['-lembind', '-pthread', '-sPTHREAD_POOL_SIZE=2'])
@@ -5054,12 +5054,9 @@ def test_minimal_runtime_loader_shell(self, args):
50545054
def test_minimal_runtime_hello_world(self, args):
50555055
self.btest_exit('small_hello_world.c', emcc_args=args + ['-sMINIMAL_RUNTIME'])
50565056

5057-
@parameterized({
5058-
'': ([],),
5059-
'pthread': (['-sPROXY_TO_PTHREAD', '-pthread'],),
5060-
})
5061-
def test_offset_converter(self, args):
5062-
self.btest_exit('test_offset_converter.c', emcc_args=['-sUSE_OFFSET_CONVERTER', '-gsource-map'] + args)
5057+
@also_with_proxy_to_pthread
5058+
def test_offset_converter(self):
5059+
self.btest_exit('test_offset_converter.c', emcc_args=['-sUSE_OFFSET_CONVERTER', '-gsource-map'])
50635060

50645061
# Tests emscripten_unwind_to_js_event_loop() behavior
50655062
def test_emscripten_unwind_to_js_event_loop(self):

test/test_other.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14173,9 +14173,8 @@ def test_pthread_trap(self):
1417314173
def test_pthread_kill(self):
1417414174
self.do_run_in_out_file_test('pthread/test_pthread_kill.c')
1417514175

14176-
@node_pthreads
1417714176
def test_emscripten_set_interval(self):
14178-
self.do_runf('emscripten_set_interval.c', args=['-pthread', '-sPROXY_TO_PTHREAD'])
14177+
self.do_runf('emscripten_set_interval.c')
1417914178

1418014179
# Test emscripten_console_log(), emscripten_console_warn() and emscripten_console_error()
1418114180
def test_emscripten_console_log(self):
@@ -14185,13 +14184,11 @@ def test_emscripten_console_log(self):
1418514184
def test_emscripten_unwind_to_js_event_loop(self):
1418614185
self.do_runf('test_emscripten_unwind_to_js_event_loop.c')
1418714186

14188-
@node_pthreads
1418914187
def test_emscripten_set_timeout(self):
14190-
self.do_runf('emscripten_set_timeout.c', args=['-pthread', '-sPROXY_TO_PTHREAD'])
14188+
self.do_runf('emscripten_set_timeout.c', emcc_args=['-sEXIT_RUNTIME'])
1419114189

14192-
@node_pthreads
1419314190
def test_emscripten_set_timeout_loop(self):
14194-
self.do_runf('emscripten_set_timeout_loop.c', args=['-pthread', '-sPROXY_TO_PTHREAD'])
14191+
self.do_runf('emscripten_set_timeout_loop.c', emcc_args=['-sEXIT_RUNTIME'])
1419514192

1419614193
# Verify that we are able to successfully compile a script when the Windows 7
1419714194
# and Python workaround env. vars are enabled.

0 commit comments

Comments
 (0)