Skip to content

Commit d99a75f

Browse files
authored
Simplify test_dynamic_link. NFC (#22246)
- Use @parameterize - Simply test logic - Rename test_dynamic_link* tests to test_dylink* for consistency.
1 parent e6e7b74 commit d99a75f

File tree

1 file changed

+13
-33
lines changed

1 file changed

+13
-33
lines changed

test/test_browser.py

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3361,52 +3361,32 @@ def test_webidl(self, args):
33613361
self.btest('webidl/test.cpp', '1', args=['--post-js', 'glue.js', '-I.', '-DBROWSER'] + args)
33623362

33633363
@no_wasm64('https://github.com/llvm/llvm-project/issues/98778')
3364-
def test_dynamic_link(self):
3364+
@parameterized({
3365+
'': ([],),
3366+
'proxy_to_worker': (['--proxy-to-worker'],),
3367+
})
3368+
def test_dylink(self, args):
33653369
create_file('main.c', r'''
3370+
#include <assert.h>
33663371
#include <stdio.h>
33673372
#include <stdlib.h>
33683373
#include <string.h>
3369-
#include <emscripten.h>
33703374
char *side(const char *data);
33713375
int main() {
3372-
char *temp = side("hello through side\n");
3373-
char *ret = (char*)malloc(strlen(temp)+1);
3374-
strcpy(ret, temp);
3375-
temp[1] = 'x';
3376-
EM_ASM({
3377-
Module.realPrint = out;
3378-
out = (x) => {
3379-
if (!Module.printed) Module.printed = x;
3380-
Module.realPrint(x);
3381-
};
3382-
});
3376+
char *ret = side("hello through side\n");
33833377
puts(ret);
3384-
EM_ASM({ assert(Module.printed === 'hello through side', ['expected', Module.printed]); });
3378+
assert(strcmp(ret, "hello through side\n") == 0);
33853379
return 0;
33863380
}
33873381
''')
33883382
create_file('side.c', r'''
3389-
#include <stdlib.h>
33903383
#include <string.h>
3391-
char *side(const char *data);
33923384
char *side(const char *data) {
3393-
char *ret = (char*)malloc(strlen(data)+1);
3394-
strcpy(ret, data);
3395-
return ret;
3385+
return strdup(data);
33963386
}
33973387
''')
33983388
self.emcc('side.c', ['-sSIDE_MODULE', '-O2', '-o', 'side.wasm'])
3399-
self.btest_exit(self.in_dir('main.c'), args=['-sMAIN_MODULE=2', '-O2', 'side.wasm'])
3400-
3401-
print('wasm in worker (we can read binary data synchronously there)')
3402-
3403-
self.emcc('side.c', ['-sSIDE_MODULE', '-O2', '-o', 'side.wasm'])
3404-
self.btest_exit(self.in_dir('main.c'), args=['-sMAIN_MODULE=2', '-O2', '--proxy-to-worker', 'side.wasm'])
3405-
3406-
print('wasm (will auto-preload since no sync binary reading)')
3407-
3408-
# same wasm side module works
3409-
self.btest_exit(self.in_dir('main.c'), args=['-sMAIN_MODULE=2', '-O2', '-sEXPORT_ALL', 'side.wasm'])
3389+
self.btest_exit(self.in_dir('main.c'), args=['-sMAIN_MODULE=2', '-O2', 'side.wasm'] + args)
34103390

34113391
def test_dlopen_async(self):
34123392
create_file('side.c', 'int foo = 42;\n')
@@ -3467,7 +3447,7 @@ def do_run(src, expected_output, emcc_args):
34673447

34683448
@requires_graphics_hardware
34693449
@no_wasm64('https://github.com/llvm/llvm-project/issues/98778')
3470-
def test_dynamic_link_glemu(self):
3450+
def test_dylink_glemu(self):
34713451
create_file('main.c', r'''
34723452
#include <stdio.h>
34733453
#include <string.h>
@@ -3493,7 +3473,7 @@ def test_dynamic_link_glemu(self):
34933473

34943474
self.btest_exit(self.in_dir('main.c'), args=['-sMAIN_MODULE=2', '-O2', '-sLEGACY_GL_EMULATION', '-lSDL', '-lGL', 'side.wasm'])
34953475

3496-
def test_dynamic_link_many(self):
3476+
def test_dylink_many(self):
34973477
# test asynchronously loading two side modules during startup
34983478
create_file('main.c', r'''
34993479
#include <assert.h>
@@ -3515,7 +3495,7 @@ def test_dynamic_link_many(self):
35153495
self.emcc('side2.c', ['-sSIDE_MODULE', '-o', 'side2.wasm'])
35163496
self.btest_exit(self.in_dir('main.c'), args=['-sMAIN_MODULE=2', 'side1.wasm', 'side2.wasm'])
35173497

3518-
def test_dynamic_link_pthread_many(self):
3498+
def test_dylink_pthread_many(self):
35193499
# Test asynchronously loading two side modules during startup
35203500
# They should always load in the same order
35213501
# Verify that function pointers in the browser's main thread

0 commit comments

Comments
 (0)