@@ -2784,15 +2784,19 @@ def test_webgl2_sokol_arraytex(self):
2784
2784
def test_sdl_touch (self , opts ):
2785
2785
self .btest_exit ('test_sdl_touch.c' , args = opts + ['-DAUTOMATE_SUCCESS=1' , '-lSDL' , '-lGL' ])
2786
2786
2787
- def test_html5_mouse (self ):
2788
- for opts in [[], ['-O2' , '-g1' , '--closure=1' ]]:
2789
- print (opts )
2790
- self .btest ('test_html5_mouse.c' , args = opts + ['-DAUTOMATE_SUCCESS=1' ], expected = '0' )
2787
+ @parameterized ({
2788
+ '' : ([],),
2789
+ 'closure' : (['-O2' , '-g1' , '--closure=1' ],),
2790
+ })
2791
+ def test_html5_mouse (self , opts ):
2792
+ self .btest ('test_html5_mouse.c' , args = opts + ['-DAUTOMATE_SUCCESS=1' ], expected = '0' )
2791
2793
2792
- def test_sdl_mousewheel (self ):
2793
- for opts in [[], ['-O2' , '-g1' , '--closure=1' ]]:
2794
- print (opts )
2795
- self .btest_exit ('test_sdl_mousewheel.c' , args = opts + ['-DAUTOMATE_SUCCESS=1' , '-lSDL' , '-lGL' ])
2794
+ @parameterized ({
2795
+ '' : ([],),
2796
+ 'closure' : (['-O2' , '-g1' , '--closure=1' ],),
2797
+ })
2798
+ def test_sdl_mousewheel (self , opts ):
2799
+ self .btest_exit ('test_sdl_mousewheel.c' , args = opts + ['-DAUTOMATE_SUCCESS=1' , '-lSDL' , '-lGL' ])
2796
2800
2797
2801
@also_with_wasmfs
2798
2802
def test_wget (self ):
@@ -2807,62 +2811,59 @@ def test_wget_data(self):
2807
2811
'' : ([],),
2808
2812
'es6' : (['-sEXPORT_ES6' ],),
2809
2813
})
2814
+ @also_with_wasm2js
2810
2815
def test_locate_file (self , args ):
2811
2816
self .set_setting ('EXIT_RUNTIME' )
2812
- for wasm in [0 , 1 ]:
2813
- if not wasm :
2814
- self .require_wasm2js ()
2815
- self .clear ()
2816
- create_file ('src.cpp' , r'''
2817
- #include <stdio.h>
2818
- #include <string.h>
2819
- #include <assert.h>
2820
- int main() {
2821
- FILE *f = fopen("data.txt", "r");
2822
- assert(f && "could not open file");
2823
- char buf[100];
2824
- int num = fread(buf, 1, 20, f);
2825
- assert(num == 20 && "could not read 20 bytes");
2826
- buf[20] = 0;
2827
- fclose(f);
2828
- printf("|%s|\n", buf);
2829
- assert(strcmp("load me right before", buf) == 0);
2830
- return 0;
2831
- }
2832
- ''' )
2833
- create_file ('data.txt' , 'load me right before...' )
2834
- create_file ('pre.js' , 'Module.locateFile = (x) => "sub/" + x;' )
2835
- self .run_process ([FILE_PACKAGER , 'test.data' , '--preload' , 'data.txt' ], stdout = open ('data.js' , 'w' ))
2836
- # put pre.js first, then the file packager data, so locateFile is there for the file loading code
2837
- self .compile_btest ('src.cpp' , ['-O2' , '-g' , '--pre-js' , 'pre.js' , '--pre-js' , 'data.js' , '-o' , 'page.html' , '-sFORCE_FILESYSTEM' , '-sWASM=' + str (wasm )] + args , reporting = Reporting .JS_ONLY )
2838
- ensure_dir ('sub' )
2839
- if wasm :
2840
- shutil .move ('page.wasm' , Path ('sub/page.wasm' ))
2841
- shutil .move ('test.data' , Path ('sub/test.data' ))
2842
- self .run_browser ('page.html' , '/report_result?exit:0' )
2817
+ create_file ('src.cpp' , r'''
2818
+ #include <stdio.h>
2819
+ #include <string.h>
2820
+ #include <assert.h>
2821
+ int main() {
2822
+ FILE *f = fopen("data.txt", "r");
2823
+ assert(f && "could not open file");
2824
+ char buf[100];
2825
+ int num = fread(buf, 1, 20, f);
2826
+ assert(num == 20 && "could not read 20 bytes");
2827
+ buf[20] = 0;
2828
+ fclose(f);
2829
+ printf("|%s|\n", buf);
2830
+ assert(strcmp("load me right before", buf) == 0);
2831
+ return 0;
2832
+ }
2833
+ ''' )
2834
+ create_file ('data.txt' , 'load me right before...' )
2835
+ create_file ('pre.js' , 'Module.locateFile = (x) => "sub/" + x;' )
2836
+ self .run_process ([FILE_PACKAGER , 'test.data' , '--preload' , 'data.txt' ], stdout = open ('data.js' , 'w' ))
2837
+ # put pre.js first, then the file packager data, so locateFile is there for the file loading code
2838
+ self .compile_btest ('src.cpp' , ['-O2' , '-g' , '--pre-js' , 'pre.js' , '--pre-js' , 'data.js' , '-o' , 'page.html' , '-sFORCE_FILESYSTEM' ] + args , reporting = Reporting .JS_ONLY )
2839
+ ensure_dir ('sub' )
2840
+ if self .is_wasm ():
2841
+ shutil .move ('page.wasm' , Path ('sub/page.wasm' ))
2842
+ shutil .move ('test.data' , Path ('sub/test.data' ))
2843
+ self .run_browser ('page.html' , '/report_result?exit:0' )
2843
2844
2844
- # alternatively, put locateFile in the HTML
2845
- print ('in html' )
2845
+ # alternatively, put locateFile in the HTML
2846
+ print ('in html' )
2846
2847
2847
- create_file ('shell.html' , '''
2848
- <body>
2849
- <script>
2850
- var Module = {
2851
- locateFile: function(x) { return "sub/" + x }
2852
- };
2853
- </script>
2848
+ create_file ('shell.html' , '''
2849
+ <body>
2850
+ <script>
2851
+ var Module = {
2852
+ locateFile: function(x) { return "sub/" + x }
2853
+ };
2854
+ </script>
2854
2855
2855
- {{{ SCRIPT }}}
2856
- </body>
2857
- ''' )
2856
+ {{{ SCRIPT }}}
2857
+ </body>
2858
+ ''' )
2858
2859
2859
- def in_html (expected ):
2860
- self .compile_btest ('src.cpp' , ['-O2' , '-g' , '--shell-file' , 'shell.html' , '--pre-js' , 'data.js' , '-o' , 'page.html' , '-sSAFE_HEAP' , '-sASSERTIONS' , '-sFORCE_FILESYSTEM' , '-sWASM=' + str ( wasm ) ] + args , reporting = Reporting .JS_ONLY )
2861
- if wasm :
2862
- shutil .move ('page.wasm' , Path ('sub/page.wasm' ))
2863
- self .run_browser ('page.html' , '/report_result?exit:' + expected )
2860
+ def in_html (expected ):
2861
+ self .compile_btest ('src.cpp' , ['-O2' , '-g' , '--shell-file' , 'shell.html' , '--pre-js' , 'data.js' , '-o' , 'page.html' , '-sSAFE_HEAP' , '-sASSERTIONS' , '-sFORCE_FILESYSTEM' ] + args , reporting = Reporting .JS_ONLY )
2862
+ if self . is_wasm () :
2863
+ shutil .move ('page.wasm' , Path ('sub/page.wasm' ))
2864
+ self .run_browser ('page.html' , '/report_result?exit:' + expected )
2864
2865
2865
- in_html ('0' )
2866
+ in_html ('0' )
2866
2867
2867
2868
@requires_graphics_hardware
2868
2869
def test_glfw3_default_hints (self ):
@@ -2878,10 +2879,13 @@ def test_glfw3(self, args):
2878
2879
print (opts )
2879
2880
self .btest ('test_glfw3.c' , args = ['-sUSE_GLFW=3' , '-lglfw' , '-lGL' ] + args + opts , expected = '1' )
2880
2881
2882
+ @parameterized ({
2883
+ '' : (['-sUSE_GLFW=2' , '-DUSE_GLFW=2' ],),
2884
+ 'glfw3' : (['-sUSE_GLFW=2' , '-DUSE_GLFW=2' ],),
2885
+ })
2881
2886
@requires_graphics_hardware
2882
- def test_glfw_events (self ):
2883
- self .btest ('test_glfw_events.c' , args = ['-sUSE_GLFW=2' , "-DUSE_GLFW=2" , '-lglfw' , '-lGL' ], expected = '1' )
2884
- self .btest ('test_glfw_events.c' , args = ['-sUSE_GLFW=3' , "-DUSE_GLFW=3" , '-lglfw' , '-lGL' ], expected = '1' )
2887
+ def test_glfw_events (self , args ):
2888
+ self .btest ('test_glfw_events.c' , args = args + ['-lglfw' , '-lGL' ], expected = '1' )
2885
2889
2886
2890
@requires_graphics_hardware
2887
2891
def test_glfw3_hi_dpi_aware (self ):
@@ -3076,12 +3080,16 @@ def test_sdl2_mouse_offsets(self):
3076
3080
self .run_browser ('page.html' , '' , '/report_result?exit:0' )
3077
3081
3078
3082
def test_sdl2_threads (self ):
3079
- self .btest_exit ('test_sdl2_threads.c' , args = ['-pthread' , '-sUSE_SDL=2' , '-sPROXY_TO_PTHREAD' ])
3083
+ self .btest_exit ('test_sdl2_threads.c' , args = ['-pthread' , '-sUSE_SDL=2' , '-sPROXY_TO_PTHREAD' ])
3080
3084
3081
3085
@requires_graphics_hardware
3082
- def test_sdl2_glshader (self ):
3083
- self .reftest ('test_sdl2_glshader.c' , 'test_sdl_glshader.png' , args = ['-sUSE_SDL=2' , '-O2' , '--closure=1' , '-g1' , '-sLEGACY_GL_EMULATION' ])
3084
- self .reftest ('test_sdl2_glshader.c' , 'test_sdl_glshader.png' , args = ['-sUSE_SDL=2' , '-O2' , '-sLEGACY_GL_EMULATION' ], also_proxied = True ) # XXX closure fails on proxy
3086
+ @parameterized ({
3087
+ '' : ([], True ),
3088
+ # fails on proxy
3089
+ 'closure' : (['--closure=1' , '-g1' ], False ),
3090
+ })
3091
+ def test_sdl2_glshader (self , args , also_proxied ):
3092
+ self .reftest ('test_sdl2_glshader.c' , 'test_sdl_glshader.png' , args = ['-sUSE_SDL=2' , '-O2' , '-sLEGACY_GL_EMULATION' ], also_proxied = also_proxied )
3085
3093
3086
3094
@requires_graphics_hardware
3087
3095
def test_sdl2_canvas_blank (self ):
@@ -3333,20 +3341,26 @@ def test_async_2(self):
3333
3341
create_file ('pre.js' , 'Error.stackTraceLimit = 80;\n ' )
3334
3342
self .btest_exit ('async_2.cpp' , args = ['-O3' , '--pre-js' , 'pre.js' , '-sASYNCIFY' , '-sSTACK_SIZE=1MB' ])
3335
3343
3336
- def test_async_virtual (self ):
3337
- for opts in [0 , 3 ]:
3338
- print (opts )
3339
- self .btest_exit ('async_virtual.cpp' , args = ['-O' + str (opts ), '-profiling' , '-sASYNCIFY' ])
3344
+ @parameterized ({
3345
+ '' : ([],),
3346
+ 'O3' : (['-03' ],),
3347
+ })
3348
+ def test_async_virtual (self , args ):
3349
+ self .btest_exit ('async_virtual.cpp' , args = args + ['-profiling' , '-sASYNCIFY' ])
3340
3350
3351
+ @parameterized ({
3352
+ '' : ([],),
3353
+ 'O3' : (['-03' ],),
3354
+ })
3341
3355
def test_async_virtual_2 (self ):
3342
- for opts in [0 , 3 ]:
3343
- print (opts )
3344
- self .btest_exit ('async_virtual_2.cpp' , args = ['-O' + str (opts ), '-sASSERTIONS' , '-sSAFE_HEAP' , '-profiling' , '-sASYNCIFY' ])
3356
+ self .btest_exit ('async_virtual_2.cpp' , args = args + ['-sASSERTIONS' , '-sSAFE_HEAP' , '-profiling' , '-sASYNCIFY' ])
3345
3357
3358
+ @parameterized ({
3359
+ '' : ([],),
3360
+ 'O3' : (['-03' ],),
3361
+ })
3346
3362
def test_async_mainloop (self ):
3347
- for opts in [0 , 3 ]:
3348
- print (opts )
3349
- self .btest_exit ('async_mainloop.cpp' , args = ['-O' + str (opts ), '-sASYNCIFY' ])
3363
+ self .btest_exit ('async_mainloop.cpp' , args = args + ['-sASYNCIFY' ])
3350
3364
3351
3365
@requires_sound_hardware
3352
3366
def test_sdl_audio_beep_sleep (self ):
@@ -3389,44 +3403,44 @@ def test_minimal_runtime_modularize(self):
3389
3403
def test_minimal_runtime_export_name (self ):
3390
3404
self .btest_exit ('browser_test_hello_world.c' , args = ['-sEXPORT_NAME=Foo' , '-sMINIMAL_RUNTIME' ])
3391
3405
3392
- def test_modularize (self ):
3393
- for opts in [
3394
- [],
3395
- ['-O1' ],
3396
- ['-O2' , '-profiling' ],
3397
- ['-O2' ],
3398
- ['-O2' , '--closure=1' ]
3406
+ @parameterized ({
3407
+ '' : ([],),
3408
+ 'O1' : (['-O1' ],),
3409
+ 'O2' : (['-O2' ],),
3410
+ 'profiling' : (['-O2' , '-profiling' ],),
3411
+ 'closure' : (['-O2' , '--closure=1' ],),
3412
+ })
3413
+ def test_modularize (self , opts ):
3414
+ for args , code in [
3415
+ # defaults
3416
+ ([], '''
3417
+ let promise = Module();
3418
+ if (!promise instanceof Promise) throw new Error('Return value should be a promise');
3419
+ ''' ),
3420
+ # use EXPORT_NAME
3421
+ (['-sEXPORT_NAME="HelloWorld"' ], '''
3422
+ if (typeof Module !== "undefined") throw "what?!"; // do not pollute the global scope, we are modularized!
3423
+ HelloWorld.noInitialRun = true; // errorneous module capture will load this and cause timeout
3424
+ let promise = HelloWorld();
3425
+ if (!promise instanceof Promise) throw new Error('Return value should be a promise');
3426
+ ''' ),
3427
+ # pass in a Module option (which prevents main(), which we then invoke ourselves)
3428
+ (['-sEXPORT_NAME="HelloWorld"' ], '''
3429
+ HelloWorld({ noInitialRun: true }).then(hello => {
3430
+ hello._main();
3431
+ });
3432
+ ''' ),
3399
3433
]:
3400
- for args , code in [
3401
- # defaults
3402
- ([], '''
3403
- let promise = Module();
3404
- if (!promise instanceof Promise) throw new Error('Return value should be a promise');
3405
- ''' ),
3406
- # use EXPORT_NAME
3407
- (['-sEXPORT_NAME="HelloWorld"' ], '''
3408
- if (typeof Module !== "undefined") throw "what?!"; // do not pollute the global scope, we are modularized!
3409
- HelloWorld.noInitialRun = true; // errorneous module capture will load this and cause timeout
3410
- let promise = HelloWorld();
3411
- if (!promise instanceof Promise) throw new Error('Return value should be a promise');
3412
- ''' ),
3413
- # pass in a Module option (which prevents main(), which we then invoke ourselves)
3414
- (['-sEXPORT_NAME="HelloWorld"' ], '''
3415
- HelloWorld({ noInitialRun: true }).then(hello => {
3416
- hello._main();
3417
- });
3418
- ''' ),
3419
- ]:
3420
- print ('test on' , opts , args , code )
3421
- # this test is synchronous, so avoid async startup due to wasm features
3422
- self .compile_btest ('browser_test_hello_world.c' , ['-sMODULARIZE' , '-sSINGLE_FILE' ] + args + opts )
3423
- create_file ('a.html' , '''
3424
- <script src="a.out.js"></script>
3425
- <script>
3426
- %s
3427
- </script>
3428
- ''' % code )
3429
- self .run_browser ('a.html' , '/report_result?0' )
3434
+ print ('test on' , opts , args , code )
3435
+ # this test is synchronous, so avoid async startup due to wasm features
3436
+ self .compile_btest ('browser_test_hello_world.c' , ['-sMODULARIZE' , '-sSINGLE_FILE' ] + args + opts )
3437
+ create_file ('a.html' , '''
3438
+ <script src="a.out.js"></script>
3439
+ <script>
3440
+ %s
3441
+ </script>
3442
+ ''' % code )
3443
+ self .run_browser ('a.html' , '/report_result?0' )
3430
3444
3431
3445
def test_modularize_network_error (self ):
3432
3446
browser_reporting_js_path = test_file ('browser_reporting.js' )
@@ -3507,14 +3521,17 @@ def test_modularize_and_preload_files(self):
3507
3521
''' % totalMemory )
3508
3522
self .run_browser ('a.html' , '/report_result?exit:0' )
3509
3523
3510
- def test_webidl (self ):
3524
+ @parameterized ({
3525
+ '' : ([],),
3526
+ 'O1' : (['-O1' ],),
3527
+ 'O2' : (['-O2' ],),
3528
+ })
3529
+ def test_webidl (self , args ):
3511
3530
# see original in test_core.py
3512
3531
self .run_process ([WEBIDL_BINDER , test_file ('webidl/test.idl' ), 'glue' ])
3513
3532
self .assertExists ('glue.cpp' )
3514
3533
self .assertExists ('glue.js' )
3515
- for opts in [[], ['-O1' ], ['-O2' ]]:
3516
- print (opts )
3517
- self .btest ('webidl/test.cpp' , '1' , args = ['--post-js' , 'glue.js' , '-I.' , '-DBROWSER' ] + opts )
3534
+ self .btest ('webidl/test.cpp' , '1' , args = ['--post-js' , 'glue.js' , '-I.' , '-DBROWSER' ] + args )
3518
3535
3519
3536
def test_dynamic_link (self ):
3520
3537
create_file ('main.c' , r'''
0 commit comments