Skip to content

Commit c4745f7

Browse files
committed
Refactor browser.test_runtime_misuse. NFC
1 parent 3e3e46a commit c4745f7

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

test/test_browser.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,8 +2394,13 @@ def test_pre_run_deps(self):
23942394

23952395
self.btest('test_pre_run_deps.c', expected='10', emcc_args=['--pre-js', 'pre.js'])
23962396

2397+
23972398
@also_with_wasm2js
2398-
def test_runtime_misuse(self):
2399+
@parameterized({
2400+
'': ([], '600'),
2401+
'no_main': (['-DNO_MAIN', '--pre-js', 'pre_runtime.js'], '601'), # 601, because no main means we *do* run another call after exit()
2402+
})
2403+
def test_runtime_misuse(self, extra_args, second_code):
23992404
self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', '$ccall,$cwrap')
24002405
post_prep = '''
24012406
var expected_ok = false;
@@ -2453,36 +2458,31 @@ def test_runtime_misuse(self):
24532458
setTimeout(async () => {
24542459
out('done timeout noted = ' + Module.noted);
24552460
assert(Module.noted);
2456-
await fetch('http://localhost:%s/report_result?' + HEAP32[Module.noted/4]);
2461+
await fetch('http://localhost:8888/report_result?' + HEAP32[Module.noted/4]);
24572462
window.close();
24582463
}, 0);
24592464
// called from main, this is an ok time
24602465
doCcall(100);
24612466
doCwrapCall(200);
24622467
doDirectCall(300);
24632468
}
2464-
''' % self.PORT
2469+
'''
24652470

24662471
create_file('pre_runtime.js', r'''
24672472
Module.onRuntimeInitialized = myJSCallback;
24682473
''')
24692474

2470-
for filename, extra_args, second_code in [
2471-
('test_runtime_misuse.c', [], 600),
2472-
('test_runtime_misuse_2.c', ['--pre-js', 'pre_runtime.js'], 601), # 601, because no main means we *do* run another call after exit()
2473-
]:
2474-
print('\n', filename, extra_args)
2475-
2476-
print('mem init, so async, call too early')
2477-
create_file('post.js', post_prep + post_test + post_hook)
2478-
self.btest(filename, expected='600', emcc_args=['--post-js', 'post.js', '-sEXIT_RUNTIME'] + extra_args, reporting=Reporting.NONE)
2479-
print('sync startup, call too late')
2480-
create_file('post.js', post_prep + 'Module.postRun = () => { ' + post_test + ' };' + post_hook)
2481-
self.btest(filename, expected=str(second_code), emcc_args=['--post-js', 'post.js', '-sEXIT_RUNTIME'] + extra_args, reporting=Reporting.NONE)
2482-
2483-
print('sync, runtime still alive, so all good')
2484-
create_file('post.js', post_prep + 'expected_ok = true; Module.postRun = () => { ' + post_test + ' };' + post_hook)
2485-
self.btest(filename, expected='606', emcc_args=['--post-js', 'post.js'] + extra_args, reporting=Reporting.NONE)
2475+
print('mem init, so async, call too early')
2476+
create_file('post.js', post_prep + post_test + post_hook)
2477+
self.btest('test_runtime_misuse.c', expected='600', emcc_args=['--post-js', 'post.js', '-sEXIT_RUNTIME'] + extra_args, reporting=Reporting.NONE)
2478+
2479+
print('sync startup, call too late')
2480+
create_file('post.js', post_prep + 'Module.postRun = () => { ' + post_test + ' };' + post_hook)
2481+
self.btest('test_runtime_misuse.c', expected=second_code, emcc_args=['--post-js', 'post.js', '-sEXIT_RUNTIME'] + extra_args, reporting=Reporting.NONE)
2482+
2483+
print('sync, runtime still alive, so all good')
2484+
create_file('post.js', post_prep + 'expected_ok = true; Module.postRun = () => { ' + post_test + ' };' + post_hook)
2485+
self.btest('test_runtime_misuse.c', expected='606', emcc_args=['--post-js', 'post.js'] + extra_args, reporting=Reporting.NONE)
24862486

24872487
def test_cwrap_early(self):
24882488
self.btest('browser/test_cwrap_early.c', emcc_args=['-O2', '-sASSERTIONS', '--pre-js', test_file('browser/test_cwrap_early.js'), '-sEXPORTED_RUNTIME_METHODS=cwrap'], expected='0')

test/test_runtime_misuse.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ EMSCRIPTEN_KEEPALIVE char* note(int n) {
1616
return (char*)"silly-string";
1717
}
1818

19+
#ifndef NO_MAIN
1920
int main() {
2021
EM_ASM( myJSCallback() ); // calls a global JS func
2122
return 0;
2223
}
24+
#endif
2325

test/test_runtime_misuse_2.c renamed to test/test_runtime_misuse_no_main.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,3 @@ EMSCRIPTEN_KEEPALIVE char* note(int n) {
1515
EM_ASM({ out(['noted is now', $0]) }, noted);
1616
return (char*)"silly-string";
1717
}
18-
19-
void free(void* ptr) { // free is valid to call even after the runtime closes, so useful as a hack here for this test
20-
EM_ASM({ out(['reporting', $0]) }, noted);
21-
}

0 commit comments

Comments
 (0)