Skip to content

Commit 6812240

Browse files
authored
Cleanup some async browser tests. NFC (#25101)
- Convert the tests to C - Rename to include `test_` prefix - Use `reportResultToServer` instead of direct fetch.
1 parent e6587e7 commit 6812240

File tree

7 files changed

+28
-41
lines changed

7 files changed

+28
-41
lines changed

test/browser/async_returnvalue.js

Lines changed: 0 additions & 16 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

test/browser/async_bad_list.cpp renamed to test/browser/test_async_bad_list.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ int main() {
1717
Module.reported = true;
1818
console.log("reporting success");
1919
// manually REPORT_RESULT; we shouldn't call back into native code at this point
20-
await fetch("/report_result?0");
21-
window.close();
20+
reportResultToServer(0);
2221
}
2322
};
2423
return 0;
@@ -30,6 +29,5 @@ int main() {
3029
// functions - this function should be instrumented, but will not be.
3130
puts("We should not get here!");
3231
REPORT_RESULT(1);
33-
34-
return 0;
32+
return 1;
3533
}

test/browser/async_returnvalue.cpp renamed to test/browser/test_async_returnvalue.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,25 @@
55

66
#include <assert.h>
77
#include <stdio.h>
8+
#include <stdbool.h>
89

910
#include <emscripten.h>
1011

1112
// A "sync" tunnel that adds 1.
1213
#if USE_EM_JS
1314
EM_JS(int, sync_tunnel, (int value), {
1415
return Asyncify.handleSleep((wakeUp) => {
15-
setTimeout(function() {
16-
wakeUp(value + 1);
17-
}, 1);
16+
setTimeout(() => wakeUp(value + 1), 1);
1817
});
1918
})
2019
EM_JS(int, sync_tunnel_bool, (bool value), {
2120
return Asyncify.handleSleep((wakeUp) => {
22-
setTimeout(function() {
23-
wakeUp(!value);
24-
}, 1);
21+
setTimeout(() => wakeUp(!value), 1);
2522
});
2623
})
2724
#else
28-
extern "C" int sync_tunnel(int);
29-
extern "C" int sync_tunnel_bool(bool);
25+
int sync_tunnel(int);
26+
int sync_tunnel_bool(bool);
3027
#endif
3128

3229
int main() {
@@ -35,12 +32,9 @@ int main() {
3532
window.disableErrorReporting = true;
3633
window.onerror = async (e) => {
3734
var success = e.toString().indexOf("import sync_tunnel was not in ASYNCIFY_IMPORTS, but changed the state") > 0;
38-
if (success && !Module.reported) {
39-
Module.reported = true;
35+
if (success) {
4036
console.log("reporting success");
41-
// manually REPORT_RESULT; we shouldn't call back into native code at this point
42-
await fetch("/report_result?0");
43-
window.close();
37+
maybeReportResultToServer(0);
4438
}
4539
};
4640
});
@@ -65,11 +59,10 @@ int main() {
6559
y = sync_tunnel_bool(true);
6660
assert(y == false);
6761

68-
69-
7062
#ifdef BAD
7163
// We should not get here.
7264
printf("We should not get here\n");
65+
assert(false);
7366
#else
7467
// Success!
7568
REPORT_RESULT(0);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
addToLibrary({
2+
sync_tunnel: (value) => {
3+
return Asyncify.handleSleep((wakeUp) => {
4+
setTimeout(() => wakeUp(value + 1), 1);
5+
});
6+
},
7+
sync_tunnel_bool: (value) => {
8+
return Asyncify.handleSleep((wakeUp) => {
9+
setTimeout(() => wakeUp(!value), 1);
10+
});
11+
},
12+
});

test/test_browser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,19 +3298,19 @@ def test_async(self, args):
32983298

32993299
for opts in (0, 1, 2, 3):
33003300
print(opts)
3301-
self.btest_exit('async.cpp', cflags=['-O' + str(opts), '-g2'] + args)
3301+
self.btest_exit('test_async.c', cflags=['-O' + str(opts), '-g2'] + args)
33023302

33033303
def test_asyncify_tricky_function_sig(self):
33043304
self.btest('test_asyncify_tricky_function_sig.cpp', '85', cflags=['-sASYNCIFY_ONLY=[foo(char.const*?.int#),foo2(),main,__original_main]', '-sASYNCIFY'])
33053305

33063306
def test_async_in_pthread(self):
3307-
self.btest_exit('async.cpp', cflags=['-sASYNCIFY', '-pthread', '-sPROXY_TO_PTHREAD', '-g'])
3307+
self.btest_exit('test_async.c', cflags=['-sASYNCIFY', '-pthread', '-sPROXY_TO_PTHREAD', '-g'])
33083308

33093309
def test_async_2(self):
33103310
# Error.stackTraceLimit default to 10 in chrome but this test relies on more
33113311
# than 40 stack frames being reported.
33123312
create_file('pre.js', 'Error.stackTraceLimit = 80;\n')
3313-
self.btest_exit('async_2.cpp', cflags=['-O3', '--pre-js', 'pre.js', '-sASYNCIFY', '-sSTACK_SIZE=1MB'])
3313+
self.btest_exit('test_async_2.c', cflags=['-O3', '--pre-js', 'pre.js', '-sASYNCIFY', '-sSTACK_SIZE=1MB'])
33143314

33153315
@parameterized({
33163316
'': ([],),
@@ -3355,7 +3355,7 @@ def test_async_iostream(self):
33553355
# ASYNCIFY_IMPORTS.
33563356
# To make the test more precise we also use ASYNCIFY_IGNORE_INDIRECT here.
33573357
@parameterized({
3358-
'normal': (['-sASYNCIFY_IMPORTS=sync_tunnel,sync_tunnel_bool'],), # noqa
3358+
'': (['-sASYNCIFY_IMPORTS=sync_tunnel,sync_tunnel_bool'],), # noqa
33593359
'pattern_imports': (['-sASYNCIFY_IMPORTS=[sync_tun*]'],), # noqa
33603360
'response': (['[email protected]'],), # noqa
33613361
'nothing': (['-DBAD'],), # noqa
@@ -3365,10 +3365,10 @@ def test_async_iostream(self):
33653365
def test_async_returnvalue(self, args):
33663366
if '@' in str(args):
33673367
create_file('filey.txt', 'sync_tunnel\nsync_tunnel_bool\n')
3368-
self.btest('async_returnvalue.cpp', '0', cflags=['-sASYNCIFY', '-sASYNCIFY_IGNORE_INDIRECT', '--js-library', test_file('browser/async_returnvalue.js')] + args + ['-sASSERTIONS'])
3368+
self.btest('test_async_returnvalue.c', '0', cflags=['-sASSERTIONS', '-sASYNCIFY', '-sASYNCIFY_IGNORE_INDIRECT', '--js-library', test_file('browser/test_async_returnvalue.js')] + args)
33693369

33703370
def test_async_bad_list(self):
3371-
self.btest('async_bad_list.cpp', '0', cflags=['-sASYNCIFY', '-sASYNCIFY_ONLY=waka', '--profiling'])
3371+
self.btest('test_async_bad_list.c', '0', cflags=['-sASYNCIFY', '-sASYNCIFY_ONLY=waka', '--profiling'])
33723372

33733373
# Tests that when building with -sMINIMAL_RUNTIME, the build can use -sMODULARIZE as well.
33743374
def test_minimal_runtime_modularize(self):

0 commit comments

Comments
 (0)