diff --git a/test/test_browser.py b/test/test_browser.py index 452e8ed354f38..2528ea47f224a 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -2784,15 +2784,19 @@ def test_webgl2_sokol_arraytex(self): def test_sdl_touch(self, opts): self.btest_exit('test_sdl_touch.c', args=opts + ['-DAUTOMATE_SUCCESS=1', '-lSDL', '-lGL']) - def test_html5_mouse(self): - for opts in [[], ['-O2', '-g1', '--closure=1']]: - print(opts) - self.btest('test_html5_mouse.c', args=opts + ['-DAUTOMATE_SUCCESS=1'], expected='0') + @parameterized({ + '': ([],), + 'closure': (['-O2', '-g1', '--closure=1'],), + }) + def test_html5_mouse(self, opts): + self.btest('test_html5_mouse.c', args=opts + ['-DAUTOMATE_SUCCESS=1'], expected='0') - def test_sdl_mousewheel(self): - for opts in [[], ['-O2', '-g1', '--closure=1']]: - print(opts) - self.btest_exit('test_sdl_mousewheel.c', args=opts + ['-DAUTOMATE_SUCCESS=1', '-lSDL', '-lGL']) + @parameterized({ + '': ([],), + 'closure': (['-O2', '-g1', '--closure=1'],), + }) + def test_sdl_mousewheel(self, opts): + self.btest_exit('test_sdl_mousewheel.c', args=opts + ['-DAUTOMATE_SUCCESS=1', '-lSDL', '-lGL']) @also_with_wasmfs def test_wget(self): @@ -2807,62 +2811,59 @@ def test_wget_data(self): '': ([],), 'es6': (['-sEXPORT_ES6'],), }) + @also_with_wasm2js def test_locate_file(self, args): self.set_setting('EXIT_RUNTIME') - for wasm in [0, 1]: - if not wasm: - self.require_wasm2js() - self.clear() - create_file('src.cpp', r''' - #include - #include - #include - int main() { - FILE *f = fopen("data.txt", "r"); - assert(f && "could not open file"); - char buf[100]; - int num = fread(buf, 1, 20, f); - assert(num == 20 && "could not read 20 bytes"); - buf[20] = 0; - fclose(f); - printf("|%s|\n", buf); - assert(strcmp("load me right before", buf) == 0); - return 0; - } - ''') - create_file('data.txt', 'load me right before...') - create_file('pre.js', 'Module.locateFile = (x) => "sub/" + x;') - self.run_process([FILE_PACKAGER, 'test.data', '--preload', 'data.txt'], stdout=open('data.js', 'w')) - # put pre.js first, then the file packager data, so locateFile is there for the file loading code - 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) - ensure_dir('sub') - if wasm: - shutil.move('page.wasm', Path('sub/page.wasm')) - shutil.move('test.data', Path('sub/test.data')) - self.run_browser('page.html', '/report_result?exit:0') + create_file('src.cpp', r''' + #include + #include + #include + int main() { + FILE *f = fopen("data.txt", "r"); + assert(f && "could not open file"); + char buf[100]; + int num = fread(buf, 1, 20, f); + assert(num == 20 && "could not read 20 bytes"); + buf[20] = 0; + fclose(f); + printf("|%s|\n", buf); + assert(strcmp("load me right before", buf) == 0); + return 0; + } + ''') + create_file('data.txt', 'load me right before...') + create_file('pre.js', 'Module.locateFile = (x) => "sub/" + x;') + self.run_process([FILE_PACKAGER, 'test.data', '--preload', 'data.txt'], stdout=open('data.js', 'w')) + # put pre.js first, then the file packager data, so locateFile is there for the file loading code + 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) + ensure_dir('sub') + if self.is_wasm(): + shutil.move('page.wasm', Path('sub/page.wasm')) + shutil.move('test.data', Path('sub/test.data')) + self.run_browser('page.html', '/report_result?exit:0') - # alternatively, put locateFile in the HTML - print('in html') + # alternatively, put locateFile in the HTML + print('in html') - create_file('shell.html', ''' - - + create_file('shell.html', ''' + + - {{{ SCRIPT }}} - - ''') + {{{ SCRIPT }}} + + ''') - def in_html(expected): - 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) - if wasm: - shutil.move('page.wasm', Path('sub/page.wasm')) - self.run_browser('page.html', '/report_result?exit:' + expected) + def in_html(expected): + 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) + if self.is_wasm(): + shutil.move('page.wasm', Path('sub/page.wasm')) + self.run_browser('page.html', '/report_result?exit:' + expected) - in_html('0') + in_html('0') @requires_graphics_hardware def test_glfw3_default_hints(self): @@ -2878,10 +2879,13 @@ def test_glfw3(self, args): print(opts) self.btest('test_glfw3.c', args=['-sUSE_GLFW=3', '-lglfw', '-lGL'] + args + opts, expected='1') + @parameterized({ + '': (['-sUSE_GLFW=2', '-DUSE_GLFW=2'],), + 'glfw3': (['-sUSE_GLFW=2', '-DUSE_GLFW=2'],), + }) @requires_graphics_hardware - def test_glfw_events(self): - self.btest('test_glfw_events.c', args=['-sUSE_GLFW=2', "-DUSE_GLFW=2", '-lglfw', '-lGL'], expected='1') - self.btest('test_glfw_events.c', args=['-sUSE_GLFW=3', "-DUSE_GLFW=3", '-lglfw', '-lGL'], expected='1') + def test_glfw_events(self, args): + self.btest('test_glfw_events.c', args=args + ['-lglfw', '-lGL'], expected='1') @requires_graphics_hardware def test_glfw3_hi_dpi_aware(self): @@ -3076,12 +3080,16 @@ def test_sdl2_mouse_offsets(self): self.run_browser('page.html', '', '/report_result?exit:0') def test_sdl2_threads(self): - self.btest_exit('test_sdl2_threads.c', args=['-pthread', '-sUSE_SDL=2', '-sPROXY_TO_PTHREAD']) + self.btest_exit('test_sdl2_threads.c', args=['-pthread', '-sUSE_SDL=2', '-sPROXY_TO_PTHREAD']) @requires_graphics_hardware - def test_sdl2_glshader(self): - self.reftest('test_sdl2_glshader.c', 'test_sdl_glshader.png', args=['-sUSE_SDL=2', '-O2', '--closure=1', '-g1', '-sLEGACY_GL_EMULATION']) - 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 + @parameterized({ + '': ([], True), + # fails on proxy + 'closure': (['--closure=1', '-g1'], False), + }) + def test_sdl2_glshader(self, args, also_proxied): + self.reftest('test_sdl2_glshader.c', 'test_sdl_glshader.png', args=args + ['-sUSE_SDL=2', '-O2', '-sLEGACY_GL_EMULATION'], also_proxied=also_proxied) @requires_graphics_hardware def test_sdl2_canvas_blank(self): @@ -3333,20 +3341,26 @@ def test_async_2(self): create_file('pre.js', 'Error.stackTraceLimit = 80;\n') self.btest_exit('async_2.cpp', args=['-O3', '--pre-js', 'pre.js', '-sASYNCIFY', '-sSTACK_SIZE=1MB']) - def test_async_virtual(self): - for opts in [0, 3]: - print(opts) - self.btest_exit('async_virtual.cpp', args=['-O' + str(opts), '-profiling', '-sASYNCIFY']) + @parameterized({ + '': ([],), + 'O3': (['-O3'],), + }) + def test_async_virtual(self, args): + self.btest_exit('async_virtual.cpp', args=args + ['-profiling', '-sASYNCIFY']) - def test_async_virtual_2(self): - for opts in [0, 3]: - print(opts) - self.btest_exit('async_virtual_2.cpp', args=['-O' + str(opts), '-sASSERTIONS', '-sSAFE_HEAP', '-profiling', '-sASYNCIFY']) + @parameterized({ + '': ([],), + 'O3': (['-O3'],), + }) + def test_async_virtual_2(self, args): + self.btest_exit('async_virtual_2.cpp', args=args + ['-sASSERTIONS', '-sSAFE_HEAP', '-profiling', '-sASYNCIFY']) - def test_async_mainloop(self): - for opts in [0, 3]: - print(opts) - self.btest_exit('async_mainloop.cpp', args=['-O' + str(opts), '-sASYNCIFY']) + @parameterized({ + '': ([],), + 'O3': (['-O3'],), + }) + def test_async_mainloop(self, args): + self.btest_exit('async_mainloop.cpp', args=args + ['-sASYNCIFY']) @requires_sound_hardware def test_sdl_audio_beep_sleep(self): @@ -3389,44 +3403,44 @@ def test_minimal_runtime_modularize(self): def test_minimal_runtime_export_name(self): self.btest_exit('browser_test_hello_world.c', args=['-sEXPORT_NAME=Foo', '-sMINIMAL_RUNTIME']) - def test_modularize(self): - for opts in [ - [], - ['-O1'], - ['-O2', '-profiling'], - ['-O2'], - ['-O2', '--closure=1'] + @parameterized({ + '': ([],), + 'O1': (['-O1'],), + 'O2': (['-O2'],), + 'profiling': (['-O2', '-profiling'],), + 'closure': (['-O2', '--closure=1'],), + }) + def test_modularize(self, opts): + for args, code in [ + # defaults + ([], ''' + let promise = Module(); + if (!promise instanceof Promise) throw new Error('Return value should be a promise'); + '''), + # use EXPORT_NAME + (['-sEXPORT_NAME="HelloWorld"'], ''' + if (typeof Module !== "undefined") throw "what?!"; // do not pollute the global scope, we are modularized! + HelloWorld.noInitialRun = true; // errorneous module capture will load this and cause timeout + let promise = HelloWorld(); + if (!promise instanceof Promise) throw new Error('Return value should be a promise'); + '''), + # pass in a Module option (which prevents main(), which we then invoke ourselves) + (['-sEXPORT_NAME="HelloWorld"'], ''' + HelloWorld({ noInitialRun: true }).then(hello => { + hello._main(); + }); + '''), ]: - for args, code in [ - # defaults - ([], ''' - let promise = Module(); - if (!promise instanceof Promise) throw new Error('Return value should be a promise'); - '''), - # use EXPORT_NAME - (['-sEXPORT_NAME="HelloWorld"'], ''' - if (typeof Module !== "undefined") throw "what?!"; // do not pollute the global scope, we are modularized! - HelloWorld.noInitialRun = true; // errorneous module capture will load this and cause timeout - let promise = HelloWorld(); - if (!promise instanceof Promise) throw new Error('Return value should be a promise'); - '''), - # pass in a Module option (which prevents main(), which we then invoke ourselves) - (['-sEXPORT_NAME="HelloWorld"'], ''' - HelloWorld({ noInitialRun: true }).then(hello => { - hello._main(); - }); - '''), - ]: - print('test on', opts, args, code) - # this test is synchronous, so avoid async startup due to wasm features - self.compile_btest('browser_test_hello_world.c', ['-sMODULARIZE', '-sSINGLE_FILE'] + args + opts) - create_file('a.html', ''' - - - ''' % code) - self.run_browser('a.html', '/report_result?0') + print('test on', opts, args, code) + # this test is synchronous, so avoid async startup due to wasm features + self.compile_btest('browser_test_hello_world.c', ['-sMODULARIZE', '-sSINGLE_FILE'] + args + opts) + create_file('a.html', ''' + + + ''' % code) + self.run_browser('a.html', '/report_result?0') def test_modularize_network_error(self): browser_reporting_js_path = test_file('browser_reporting.js') @@ -3507,14 +3521,17 @@ def test_modularize_and_preload_files(self): ''' % totalMemory) self.run_browser('a.html', '/report_result?exit:0') - def test_webidl(self): + @parameterized({ + '': ([],), + 'O1': (['-O1'],), + 'O2': (['-O2'],), + }) + def test_webidl(self, args): # see original in test_core.py self.run_process([WEBIDL_BINDER, test_file('webidl/test.idl'), 'glue']) self.assertExists('glue.cpp') self.assertExists('glue.js') - for opts in [[], ['-O1'], ['-O2']]: - print(opts) - self.btest('webidl/test.cpp', '1', args=['--post-js', 'glue.js', '-I.', '-DBROWSER'] + opts) + self.btest('webidl/test.cpp', '1', args=['--post-js', 'glue.js', '-I.', '-DBROWSER'] + args) def test_dynamic_link(self): create_file('main.c', r'''