Skip to content

Commit 72f90a6

Browse files
committed
Add test
1 parent 8a4a031 commit 72f90a6

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <emscripten.h>
2+
#include <stdio.h>
3+
4+
int main() {
5+
EM_ASM({
6+
Module["onExit"] = () => { out("onExit"); };
7+
runtimeKeepalivePush();
8+
out("runtimeKeepalivePush done");
9+
counter = 0;
10+
function timerCallback() {
11+
if (counter < 5) {
12+
runtimeKeepalivePush();
13+
out("runtimeKeepalivePush done");
14+
} else {
15+
runtimeKeepalivePop();
16+
out("runtimeKeepalivePop done");
17+
}
18+
counter += 1;
19+
callUserCallback(() => {
20+
out("in user callback: " + counter);
21+
}, 0);
22+
setTimeout(timerCallback, 0);
23+
}
24+
setTimeout(timerCallback, 0);
25+
});
26+
puts("returning from main");
27+
return 0;
28+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
runtimeKeepalivePush done
2+
returning from main
3+
runtimeKeepalivePush done
4+
in user callback: 1
5+
runtimeKeepalivePush done
6+
in user callback: 2
7+
runtimeKeepalivePush done
8+
in user callback: 3
9+
runtimeKeepalivePush done
10+
in user callback: 4
11+
runtimeKeepalivePush done
12+
in user callback: 5
13+
runtimeKeepalivePop done
14+
in user callback: 6
15+
runtimeKeepalivePop done
16+
in user callback: 7
17+
runtimeKeepalivePop done
18+
in user callback: 8
19+
runtimeKeepalivePop done
20+
in user callback: 9
21+
runtimeKeepalivePop done
22+
in user callback: 10
23+
runtimeKeepalivePop done
24+
in user callback: 11
25+
onExit

tests/test_other.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10104,3 +10104,9 @@ def test_shell_Oz(self):
1010410104
return self.skipTest('no shell to test')
1010510105
self.run_process([EMCC, path_from_root('tests', 'hello_world.c'), '-Oz'])
1010610106
self.assertContained('hello, world!', self.run_js('a.out.js', engine=config.V8_ENGINE))
10107+
10108+
def test_runtime_keepalive(self):
10109+
self.uses_es6 = True
10110+
self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$runtimeKeepalivePush', '$runtimeKeepalivePop', '$callUserCallback'])
10111+
self.set_setting('EXIT_RUNTIME')
10112+
self.do_other_test('test_runtime_keepalive.cpp')

0 commit comments

Comments
 (0)