Skip to content

Commit 8278ad1

Browse files
authored
[test] Improve test_force_exit. NFC (#23597)
Split out from #23589
1 parent 89ec839 commit 8278ad1

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

test/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,7 @@ def test_idbstore_sync_worker(self):
14911491
self.btest('test_idbstore_sync_worker.c', expected='0', args=['-lidbstore.js', f'-DSECRET="{secret}"', '-O3', '-g2', '--proxy-to-worker', '-sASYNCIFY'])
14921492

14931493
def test_force_exit(self):
1494-
self.btest_exit('force_exit.c', assert_returncode=10)
1494+
self.btest_exit('test_force_exit.c')
14951495

14961496
def test_sdl_pumpevents(self):
14971497
# key events should be detected using SDL_PumpEvents

test/test_core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,6 +2416,10 @@ def test_atexit(self):
24162416
self.set_setting('EXIT_RUNTIME')
24172417
self.do_core_test('test_atexit.c')
24182418

2419+
def test_force_exit(self):
2420+
self.set_setting('EXIT_RUNTIME')
2421+
self.do_run_in_out_file_test('test_force_exit.c')
2422+
24192423
@no_lsan('https://github.com/emscripten-core/emscripten/issues/15988')
24202424
def test_atexit_threads_stub(self):
24212425
# also tests thread exit (__cxa_thread_atexit)

test/force_exit.c renamed to test/test_force_exit.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,39 @@
55
* found in the LICENSE file.
66
*/
77

8+
#include <stdbool.h>
89
#include <stdio.h>
910
#include <stdlib.h>
1011
#include <assert.h>
1112
#include <emscripten.h>
13+
#include <emscripten/eventloop.h>
1214

13-
int result = 0;
15+
bool done = false;
1416

15-
void EMSCRIPTEN_KEEPALIVE success() {
16-
printf("success? %d\n", result);
17-
assert(result == 10);
17+
void success() {
18+
printf("atexit: done=%d\n", done);
19+
assert(done);
1820
}
1921

2022
void EMSCRIPTEN_KEEPALIVE later() {
2123
printf("later, now force an exit\n");
22-
result += 10;
23-
emscripten_force_exit(result);
24+
done = true;
25+
emscripten_force_exit(0);
2426
}
2527

28+
EM_JS_DEPS(deps, "$callUserCallback")
29+
2630
int main() {
2731
atexit(success);
2832

2933
EM_ASM({
30-
setTimeout(function() {
31-
Module._later();
32-
}, 1000);
34+
// Use callUserCallback here so that ExitStatus is handled correctly
35+
setTimeout(() => callUserCallback(Module._later), 1);
3336
});
3437

3538
printf("exit, but still alive\n");
3639
emscripten_exit_with_live_runtime();
3740
__builtin_trap();
38-
return 0;
41+
return 99;
3942
}
4043

test/test_force_exit.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exit, but still alive
2+
later, now force an exit
3+
atexit: done=1

0 commit comments

Comments
 (0)