diff --git a/test/test_browser.py b/test/test_browser.py index d3feb10669333..e2d93d3250035 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -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 diff --git a/test/test_core.py b/test/test_core.py index cb65f6ae5c897..76ef2e2efca33 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -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) diff --git a/test/force_exit.c b/test/test_force_exit.c similarity index 61% rename from test/force_exit.c rename to test/test_force_exit.c index 350969858fae2..63ede6f040801 100644 --- a/test/force_exit.c +++ b/test/test_force_exit.c @@ -5,36 +5,39 @@ * found in the LICENSE file. */ +#include #include #include #include #include +#include -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; } diff --git a/test/test_force_exit.out b/test/test_force_exit.out new file mode 100644 index 0000000000000..85f13e55252f7 --- /dev/null +++ b/test/test_force_exit.out @@ -0,0 +1,3 @@ +exit, but still alive +later, now force an exit +atexit: done=1