Skip to content

Commit

Permalink
[test] Improve test_force_exit. NFC (#23597)
Browse files Browse the repository at this point in the history
Split out from #23589
  • Loading branch information
sbc100 authored Feb 5, 2025
1 parent 89ec839 commit 8278ad1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@ def test_idbstore_sync_worker(self):
self.btest('test_idbstore_sync_worker.c', expected='0', args=['-lidbstore.js', f'-DSECRET="{secret}"', '-O3', '-g2', '--proxy-to-worker', '-sASYNCIFY'])

def test_force_exit(self):
self.btest_exit('force_exit.c', assert_returncode=10)
self.btest_exit('test_force_exit.c')

def test_sdl_pumpevents(self):
# key events should be detected using SDL_PumpEvents
Expand Down
4 changes: 4 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,10 @@ def test_atexit(self):
self.set_setting('EXIT_RUNTIME')
self.do_core_test('test_atexit.c')

def test_force_exit(self):
self.set_setting('EXIT_RUNTIME')
self.do_run_in_out_file_test('test_force_exit.c')

@no_lsan('https://github.com/emscripten-core/emscripten/issues/15988')
def test_atexit_threads_stub(self):
# also tests thread exit (__cxa_thread_atexit)
Expand Down
23 changes: 13 additions & 10 deletions test/force_exit.c → test/test_force_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,39 @@
* found in the LICENSE file.
*/

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <emscripten.h>
#include <emscripten/eventloop.h>

int result = 0;
bool done = false;

void EMSCRIPTEN_KEEPALIVE success() {
printf("success? %d\n", result);
assert(result == 10);
void success() {
printf("atexit: done=%d\n", done);
assert(done);
}

void EMSCRIPTEN_KEEPALIVE later() {
printf("later, now force an exit\n");
result += 10;
emscripten_force_exit(result);
done = true;
emscripten_force_exit(0);
}

EM_JS_DEPS(deps, "$callUserCallback")

int main() {
atexit(success);

EM_ASM({
setTimeout(function() {
Module._later();
}, 1000);
// Use callUserCallback here so that ExitStatus is handled correctly
setTimeout(() => callUserCallback(Module._later), 1);
});

printf("exit, but still alive\n");
emscripten_exit_with_live_runtime();
__builtin_trap();
return 0;
return 99;
}

3 changes: 3 additions & 0 deletions test/test_force_exit.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exit, but still alive
later, now force an exit
atexit: done=1

0 comments on commit 8278ad1

Please sign in to comment.