@@ -2221,50 +2221,52 @@ def test_openal_capture_sanity(self):
22212221
22222222 def test_runtimelink (self ):
22232223 create_file ('header.h' , r'''
2224- struct point
2225- {
2224+ struct point {
22262225 int x, y;
22272226 };
22282227 ''' )
22292228
2230- create_file ('supp.cpp ' , r'''
2229+ create_file ('supp.c ' , r'''
22312230 #include <stdio.h>
22322231 #include "header.h"
22332232
22342233 extern void mainFunc(int x);
22352234 extern int mainInt;
22362235
2237- void suppFunc(struct point & p) {
2238- printf("supp: %d,%d\n", p. x, p. y);
2239- mainFunc(p. x + p. y);
2236+ void suppFunc(struct point * p) {
2237+ printf("supp: %d,%d\n", p-> x, p-> y);
2238+ mainFunc(p-> x + p-> y);
22402239 printf("supp see: %d\n", mainInt);
22412240 }
22422241
22432242 int suppInt = 76;
22442243 ''' )
22452244
2246- create_file ('main.cpp ' , r'''
2245+ create_file ('main.c ' , r'''
22472246 #include <stdio.h>
2247+ #include <assert.h>
22482248 #include "header.h"
22492249
2250- extern void suppFunc(struct point & p);
2250+ extern void suppFunc(struct point * p);
22512251 extern int suppInt;
22522252
22532253 void mainFunc(int x) {
22542254 printf("main: %d\n", x);
2255+ assert(x == 56);
22552256 }
22562257
22572258 int mainInt = 543;
22582259
22592260 int main( int argc, const char *argv[] ) {
22602261 struct point p = { 54, 2 };
2261- suppFunc(p);
2262+ suppFunc(& p);
22622263 printf("main see: %d\nok.\n", suppInt);
2263- return suppInt;
2264+ assert(suppInt == 76);
2265+ return 0;
22642266 }
22652267 ''' )
2266- self .run_process ([EMCC , 'supp.cpp ' , '-o' , 'supp.wasm' , '-s' , 'SIDE_MODULE' , '-O2' , '-s' , 'EXPORT_ALL ' ])
2267- self .btest_exit ('main.cpp ' , args = ['-DBROWSER=1' , '- s' , 'MAIN_MODULE' , '-O2' , 'supp.wasm' , '-s' , 'EXPORT_ALL' ], assert_returncode = 76 )
2268+ self .run_process ([EMCC , 'supp.c ' , '-o' , 'supp.wasm' , '-s' , 'SIDE_MODULE' , '-O2' ])
2269+ self .btest_exit ('main.c ' , args = ['-s' , 'MAIN_MODULE=2 ' , '-O2' , 'supp.wasm' ] )
22682270
22692271 def test_pre_run_deps (self ):
22702272 # Adding a dependency in preRun will delay run
@@ -2458,8 +2460,8 @@ def test_emscripten_async_wget2_data(self):
24582460 time .sleep (10 )
24592461
24602462 def test_emscripten_async_wget_side_module (self ):
2461- self .run_process ([EMCC , test_file ('browser_module.cpp ' ), '-o' , 'lib.wasm' , '-O2' , '-s' , 'SIDE_MODULE' , '-s' , 'EXPORTED_FUNCTIONS=_one,_two ' ])
2462- self .btest_exit ('browser_main.cpp ' , args = ['-O2' , '-s' , 'MAIN_MODULE' ], assert_returncode = 8 )
2463+ self .run_process ([EMCC , test_file ('browser_module.c ' ), '-o' , 'lib.wasm' , '-O2' , '-s' , 'SIDE_MODULE' ])
2464+ self .btest_exit ('browser_main.c ' , args = ['-O2' , '-s' , 'MAIN_MODULE=2' ] )
24632465
24642466 @parameterized ({
24652467 'non-lz4' : ([],),
@@ -2472,7 +2474,7 @@ def test_preload_module(self, args):
24722474 return 42;
24732475 }
24742476 ''' )
2475- self .run_process ([EMCC , 'library.c' , '-s' , 'SIDE_MODULE' , '-O2' , '-o' , 'library.so' , '-s' , 'EXPORT_ALL' ])
2477+ self .run_process ([EMCC , 'library.c' , '-s' , 'SIDE_MODULE' , '-O2' , '-o' , 'library.so' ])
24762478 create_file ('main.c' , r'''
24772479 #include <dlfcn.h>
24782480 #include <stdio.h>
@@ -2498,7 +2500,7 @@ def test_preload_module(self, args):
24982500 ''' )
24992501 self .btest_exit (
25002502 'main.c' ,
2501- args = ['-s' , 'MAIN_MODULE' , '--preload-file' , '.@/' , '-O2' , '--use-preload-plugins' , '-s' , 'EXPORT_ALL ' ] + args )
2503+ args = ['-s' , 'MAIN_MODULE=2 ' , '--preload-file' , '.@/' , '-O2' , '--use-preload-plugins' ] + args )
25022504
25032505 def test_mmap_file (self ):
25042506 create_file ('data.dat' , 'data from the file ' + ('.' * 9000 ))
@@ -3215,7 +3217,6 @@ def test_sdl2_custom_cursor(self):
32153217 def test_sdl2_misc (self ):
32163218 self .btest_exit ('sdl2_misc.c' , args = ['-s' , 'USE_SDL=2' ])
32173219
3218- @disabled ('https://github.com/emscripten-core/emscripten/issues/13101' )
32193220 def test_sdl2_misc_main_module (self ):
32203221 self .btest_exit ('sdl2_misc.c' , args = ['-s' , 'USE_SDL=2' , '-s' , 'MAIN_MODULE' ])
32213222
@@ -3479,7 +3480,7 @@ def test_webidl(self):
34793480
34803481 @requires_sync_compilation
34813482 def test_dynamic_link (self ):
3482- create_file ('main.cpp ' , r'''
3483+ create_file ('main.c ' , r'''
34833484 #include <stdio.h>
34843485 #include <stdlib.h>
34853486 #include <string.h>
@@ -3499,11 +3500,10 @@ def test_dynamic_link(self):
34993500 });
35003501 puts(ret);
35013502 EM_ASM({ assert(Module.printed === 'hello through side', ['expected', Module.printed]); });
3502- REPORT_RESULT(2);
35033503 return 0;
35043504 }
35053505 ''' )
3506- create_file ('side.cpp ' , r'''
3506+ create_file ('side.c ' , r'''
35073507 #include <stdlib.h>
35083508 #include <string.h>
35093509 char *side(const char *data);
@@ -3513,18 +3513,18 @@ def test_dynamic_link(self):
35133513 return ret;
35143514 }
35153515 ''' )
3516- self .run_process ([EMCC , 'side.cpp ' , '-s' , 'SIDE_MODULE' , '-O2' , '-o' , 'side.wasm' , '-s' , 'EXPORT_ALL ' ])
3517- self .btest (self .in_dir ('main.cpp ' ), '2' , args = ['-s' , 'MAIN_MODULE' , '-O2' , '-s' , 'EXPORT_ALL ' , 'side.wasm' ])
3516+ self .run_process ([EMCC , 'side.c ' , '-s' , 'SIDE_MODULE' , '-O2' , '-o' , 'side.wasm' ])
3517+ self .btest_exit (self .in_dir ('main.c ' ), args = ['-s' , 'MAIN_MODULE=2 ' , '-O2' , 'side.wasm' ])
35183518
35193519 print ('wasm in worker (we can read binary data synchronously there)' )
35203520
3521- self .run_process ([EMCC , 'side.cpp ' , '-s' , 'SIDE_MODULE' , '-O2' , '-o' , 'side.wasm' , '-s' , 'EXPORT_ALL ' ])
3522- self .btest (self .in_dir ('main.cpp ' ), '2' , args = ['-s' , 'MAIN_MODULE' , '-O2' , '--proxy-to-worker' , '-s' , 'EXPORT_ALL ' , 'side.wasm' ])
3521+ self .run_process ([EMCC , 'side.c ' , '-s' , 'SIDE_MODULE' , '-O2' , '-o' , 'side.wasm' ])
3522+ self .btest_exit (self .in_dir ('main.c ' ), args = ['-s' , 'MAIN_MODULE=2 ' , '-O2' , '--proxy-to-worker' , 'side.wasm' ])
35233523
35243524 print ('wasm (will auto-preload since no sync binary reading)' )
35253525
35263526 # same wasm side module works
3527- self .btest (self .in_dir ('main.cpp ' ), '2' , args = ['-s' , 'MAIN_MODULE' , '-O2' , '-s' , 'EXPORT_ALL' , 'side.wasm' ])
3527+ self .btest_exit (self .in_dir ('main.c ' ), args = ['-s' , 'MAIN_MODULE=2 ' , '-O2' , '-s' , 'EXPORT_ALL' , 'side.wasm' ])
35283528
35293529 # verify that dynamic linking works in all kinds of in-browser environments.
35303530 # don't mix different kinds in a single test.
@@ -3573,7 +3573,7 @@ def do_run(src, expected_output, emcc_args=[]):
35733573 @requires_graphics_hardware
35743574 @requires_sync_compilation
35753575 def test_dynamic_link_glemu (self ):
3576- create_file ('main.cpp ' , r'''
3576+ create_file ('main.c ' , r'''
35773577 #include <stdio.h>
35783578 #include <string.h>
35793579 #include <assert.h>
@@ -3586,7 +3586,7 @@ def test_dynamic_link_glemu(self):
35863586 return 0;
35873587 }
35883588 ''' )
3589- create_file ('side.cpp ' , r'''
3589+ create_file ('side.c ' , r'''
35903590 #include "SDL/SDL.h"
35913591 #include "SDL/SDL_opengl.h"
35923592 const char *side() {
@@ -3595,17 +3595,20 @@ def test_dynamic_link_glemu(self):
35953595 return (const char *)glGetString(GL_EXTENSIONS);
35963596 }
35973597 ''' )
3598- self .run_process ([EMCC , 'side.cpp ' , '-s' , 'SIDE_MODULE' , '-O2' , '-o' , 'side.wasm' , '-lSDL' , '-s' , 'EXPORT_ALL ' ])
3598+ self .run_process ([EMCC , 'side.c ' , '-s' , 'SIDE_MODULE' , '-O2' , '-o' , 'side.wasm' , '-lSDL' ])
35993599
3600- self .btest (self .in_dir ('main.cpp ' ), '1' , args = ['-s' , 'MAIN_MODULE' , '-O2' , '-s' , 'LEGACY_GL_EMULATION' , '-lSDL' , '-lGL' , '-s' , 'EXPORT_ALL ' , 'side.wasm' ])
3600+ self .btest (self .in_dir ('main.c ' ), '1' , args = ['-s' , 'MAIN_MODULE=2 ' , '-O2' , '-s' , 'LEGACY_GL_EMULATION' , '-lSDL' , '-lGL' , 'side.wasm' ])
36013601
36023602 def test_dynamic_link_many (self ):
36033603 # test asynchronously loading two side modules during startup
36043604 create_file ('main.c' , r'''
3605+ #include <assert.h>
36053606 int side1();
36063607 int side2();
36073608 int main() {
3608- return side1() + side2();
3609+ assert(side1() == 1);
3610+ assert(side2() == 2);
3611+ return 0;
36093612 }
36103613 ''' )
36113614 create_file ('side1.c' , r'''
@@ -3616,8 +3619,7 @@ def test_dynamic_link_many(self):
36163619 ''' )
36173620 self .run_process ([EMCC , 'side1.c' , '-s' , 'SIDE_MODULE' , '-o' , 'side1.wasm' ])
36183621 self .run_process ([EMCC , 'side2.c' , '-s' , 'SIDE_MODULE' , '-o' , 'side2.wasm' ])
3619- self .btest_exit (self .in_dir ('main.c' ), assert_returncode = 3 ,
3620- args = ['-s' , 'MAIN_MODULE' , 'side1.wasm' , 'side2.wasm' ])
3622+ self .btest_exit (self .in_dir ('main.c' ), args = ['-s' , 'MAIN_MODULE=2' , 'side1.wasm' , 'side2.wasm' ])
36213623
36223624 def test_dynamic_link_pthread_many (self ):
36233625 # Test asynchronously loading two side modules during startup
@@ -3661,7 +3663,7 @@ def test_dynamic_link_pthread_many(self):
36613663 self .run_process ([EMCC , 'side1.cpp' , '-Wno-experimental' , '-pthread' , '-s' , 'SIDE_MODULE' , '-o' , 'side1.wasm' ])
36623664 self .run_process ([EMCC , 'side2.cpp' , '-Wno-experimental' , '-pthread' , '-s' , 'SIDE_MODULE' , '-o' , 'side2.wasm' ])
36633665 self .btest (self .in_dir ('main.cpp' ), '1' ,
3664- args = ['-Wno-experimental' , '-pthread' , '-s' , 'MAIN_MODULE' , 'side1.wasm' , 'side2.wasm' ])
3666+ args = ['-Wno-experimental' , '-pthread' , '-s' , 'MAIN_MODULE=2 ' , 'side1.wasm' , 'side2.wasm' ])
36653667
36663668 def test_memory_growth_during_startup (self ):
36673669 create_file ('data.dat' , 'X' * (30 * 1024 * 1024 ))
0 commit comments