From 75c0d70236d8d3513818e356d0513b2fc8f1b306 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 14 Dec 2024 18:07:45 +0100 Subject: [PATCH] tool.ruff.format.exclude = ["test/test_browser.py"] --- pyproject.toml | 4 +- test/test_browser.py | 4254 ++++++++++++------------------------------ 2 files changed, 1237 insertions(+), 3021 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e91ded85fa2ca..825e5e34451ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,9 @@ exclude = [ "./tools/scons/", ".git", ] - +format.exclude = [ + "./test/test_browser.py", +] format.quote-style = "preserve" indent-width = 2 line-length = 120 diff --git a/test/test_browser.py b/test/test_browser.py index d6f423a2b30c1..04d3353faf1bc 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -69,7 +69,7 @@ def do_GET(s): end = min(len(data) - 1, end) length = end - start + 1 s.sendheaders([], length) - s.wfile.write(data[start : end + 1]) + s.wfile.write(data[start:end + 1]) # CORS preflight makes OPTIONS requests which we need to account for. expectedConns = 22 @@ -92,7 +92,8 @@ def metafunc(self, wasmfs, *args, **kwargs): else: f(self, *args, **kwargs) - parameterize(metafunc, {'': (False,), 'wasmfs': (True,)}) + parameterize(metafunc, {'': (False,), + 'wasmfs': (True,)}) return metafunc @@ -107,7 +108,8 @@ def metafunc(self, proxied, *args, **kwargs): self.proxied = proxied f(self, *args, **kwargs) - parameterize(metafunc, {'': (False,), 'proxied': (True,)}) + parameterize(metafunc, {'': (False,), + 'proxied': (True,)}) return metafunc @@ -139,9 +141,7 @@ def decorator(f): def decorated(self, *args, **kwargs): self.set_setting('WASMFS', 0) f(self, *args, **kwargs) - return decorated - return decorator @@ -198,7 +198,8 @@ def decorated(self, threads, *args, **kwargs): self.emcc_args += ['-pthread'] f(self, *args, **kwargs) - parameterize(decorated, {'': (False,), 'pthreads': (True,)}) + parameterize(decorated, {'': (False,), + 'pthreads': (True,)}) return decorated @@ -218,14 +219,10 @@ def decorated(self, *args, **kwargs): return decorator -requires_graphics_hardware = skipExecIf( - os.getenv('EMTEST_LACKS_GRAPHICS_HARDWARE'), 'This test requires graphics hardware' -) +requires_graphics_hardware = skipExecIf(os.getenv('EMTEST_LACKS_GRAPHICS_HARDWARE'), 'This test requires graphics hardware') requires_webgpu = unittest.skipIf(os.getenv('EMTEST_LACKS_WEBGPU'), "This test requires WebGPU to be available") requires_sound_hardware = skipExecIf(os.getenv('EMTEST_LACKS_SOUND_HARDWARE'), 'This test requires sound hardware') -requires_offscreen_canvas = skipExecIf( - os.getenv('EMTEST_LACKS_OFFSCREEN_CANVAS'), 'This test requires a browser with OffscreenCanvas' -) +requires_offscreen_canvas = skipExecIf(os.getenv('EMTEST_LACKS_OFFSCREEN_CANVAS'), 'This test requires a browser with OffscreenCanvas') class browser(BrowserCore): @@ -248,18 +245,14 @@ def setUp(self): def require_jspi(self): if not is_chrome(): - self.skipTest( - f'Current browser ({EMTEST_BROWSER}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.' - ) + self.skipTest(f'Current browser ({EMTEST_BROWSER}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.') super(browser, self).require_jspi() def post_manual_reftest(self): assert os.path.exists('reftest.js') shutil.copy(test_file('browser_reporting.js'), '.') html = read_file('test.html') - html = html.replace( - '', - ''' + html = html.replace('', ''' -''', - ) +''') create_file('test.html', html) def make_reftest(self, expected): # make sure the pngs used here have no color correction, using e.g. # pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB infile outfile shutil.copy(expected, 'expected.png') - create_file( - 'reftest.js', - f''' + create_file('reftest.js', f''' const reftestRebaseline = {common.EMTEST_REBASELINE}; - ''' - + read_file(test_file('reftest.js')), - ) + ''' + read_file(test_file('reftest.js'))) def reftest(self, filename, reference, reference_slack=0, *args, **kwargs): - """Special case of `btest` that uses reference image""" + """Special case of `btest` that uses reference image + """ reference = find_browser_test_file(reference) assert 'expected' not in kwargs expected = [str(i) for i in range(0, reference_slack + 1)] @@ -319,7 +308,7 @@ def test_sdl1_in_emscripten_nonstrict_mode(self): def test_sdl1(self): self.reftest('hello_world_sdl.c', 'htmltest.png', args=['-lSDL', '-lGL']) - self.reftest('hello_world_sdl.c', 'htmltest.png', args=['-sUSE_SDL', '-lGL']) # is the default anyhow + self.reftest('hello_world_sdl.c', 'htmltest.png', args=['-sUSE_SDL', '-lGL']) # is the default anyhow def test_sdl1_es6(self): self.reftest('hello_world_sdl.c', 'htmltest.png', args=['-sUSE_SDL', '-lGL', '-sEXPORT_ES6']) @@ -335,9 +324,7 @@ def test_zzz_html_source_map(self): # multiple mapped lines. in other words, if the program consists of a # single 'throw' statement, browsers may just map any thrown exception to # that line, because it will be the only mapped line. - create_file( - 'src.cpp', - r''' + create_file('src.cpp', r''' #include int main() { @@ -348,8 +335,7 @@ def test_zzz_html_source_map(self): printf("done\n"); return 0; } - ''', - ) + ''') # use relative paths when calling emcc, because file:// URIs can only load # sourceContent when the maps are relative paths self.compile_btest('src.cpp', ['-o', 'src.html', '-gsource-map']) @@ -366,10 +352,8 @@ def test_zzz_html_source_map(self): ''') def test_emscripten_log(self): - self.btest_exit( - 'emscripten_log/emscripten_log.cpp', - args=['-Wno-deprecated-pragma', '--pre-js', path_from_root('src/emscripten-source-map.min.js'), '-gsource-map'], - ) + self.btest_exit('emscripten_log/emscripten_log.cpp', + args=['-Wno-deprecated-pragma', '--pre-js', path_from_root('src/emscripten-source-map.min.js'), '-gsource-map']) @also_with_wasmfs def test_preload_file(self): @@ -381,13 +365,11 @@ def test_preload_file(self): def make_main(path): print('make main at', path) - path = path.replace('\\', '\\\\').replace('"', '\\"') # Escape tricky path name for use inside a C string. + path = path.replace('\\', '\\\\').replace('"', '\\"') # Escape tricky path name for use inside a C string. # TODO: change this when wasmfs supports relative paths. if self.get_setting('WASMFS'): path = "/" + path - create_file( - 'main.c', - r''' + create_file('main.c', r''' #include #include #include @@ -403,9 +385,7 @@ def make_main(path): assert(strcmp("load me right before", buf) == 0); return 0; } - ''' - % path, - ) + ''' % path) test_cases = [ # (source preload-file string, file on target FS to load) @@ -424,8 +404,7 @@ def make_main(path): ("somefile.txt@/directory/file.txt", "directory/file.txt"), (absolute_src_path + "@/directory/file.txt", "directory/file.txt"), ("some@@file.txt@other.txt", "other.txt"), - ("some@@file.txt@some@@otherfile.txt", "some@otherfile.txt"), - ] + ("some@@file.txt@some@@otherfile.txt", "some@otherfile.txt")] for srcpath, dstpath in test_cases: print('Testing', srcpath, dstpath) @@ -449,13 +428,13 @@ def make_main(path): # By absolute path - make_main('somefile.txt') # absolute becomes relative + make_main('somefile.txt') # absolute becomes relative self.btest_exit('main.c', args=['--preload-file', absolute_src_path]) # Test subdirectory handling with asset packaging. delete_dir('assets') ensure_dir('assets/sub/asset1') - ensure_dir('assets/sub/asset1/.git') # Test adding directory that shouldn't exist. + ensure_dir('assets/sub/asset1/.git') # Test adding directory that shouldn't exist. ensure_dir('assets/sub/asset2') create_file('assets/sub/asset1/file1.txt', '''load me right before running the code please''') create_file('assets/sub/asset1/.git/shouldnt_be_embedded.txt', '''this file should not get embedded''') @@ -463,9 +442,7 @@ def make_main(path): absolute_assets_src_path = 'assets' def make_main_two_files(path1, path2, nonexistingpath): - create_file( - 'main.c', - r''' + create_file('main.c', r''' #include #include #include @@ -489,40 +466,17 @@ def make_main_two_files(path1, path2, nonexistingpath): return 0; } - ''' - % (path1, path2, nonexistingpath), - ) + ''' % (path1, path2, nonexistingpath)) test_cases = [ # (source directory to embed, file1 on target FS to load, file2 on target FS to load, name of a file that *shouldn't* exist on VFS) - ( - "assets", - "assets/sub/asset1/file1.txt", - "assets/sub/asset2/file2.txt", - "assets/sub/asset1/.git/shouldnt_be_embedded.txt", - ), - ( - "assets/", - "assets/sub/asset1/file1.txt", - "assets/sub/asset2/file2.txt", - "assets/sub/asset1/.git/shouldnt_be_embedded.txt", - ), + ("assets", "assets/sub/asset1/file1.txt", "assets/sub/asset2/file2.txt", "assets/sub/asset1/.git/shouldnt_be_embedded.txt"), + ("assets/", "assets/sub/asset1/file1.txt", "assets/sub/asset2/file2.txt", "assets/sub/asset1/.git/shouldnt_be_embedded.txt"), ("assets@/", "/sub/asset1/file1.txt", "/sub/asset2/file2.txt", "/sub/asset1/.git/shouldnt_be_embedded.txt"), ("assets/@/", "/sub/asset1/file1.txt", "/sub/asset2/file2.txt", "/sub/asset1/.git/shouldnt_be_embedded.txt"), ("assets@./", "/sub/asset1/file1.txt", "/sub/asset2/file2.txt", "/sub/asset1/.git/shouldnt_be_embedded.txt"), - ( - absolute_assets_src_path + "@/", - "/sub/asset1/file1.txt", - "/sub/asset2/file2.txt", - "/sub/asset1/.git/shouldnt_be_embedded.txt", - ), - ( - absolute_assets_src_path + "@/assets", - "/assets/sub/asset1/file1.txt", - "/assets/sub/asset2/file2.txt", - "assets/sub/asset1/.git/shouldnt_be_embedded.txt", - ), - ] + (absolute_assets_src_path + "@/", "/sub/asset1/file1.txt", "/sub/asset2/file2.txt", "/sub/asset1/.git/shouldnt_be_embedded.txt"), + (absolute_assets_src_path + "@/assets", "/assets/sub/asset1/file1.txt", "/assets/sub/asset2/file2.txt", "assets/sub/asset1/.git/shouldnt_be_embedded.txt")] for test in test_cases: (srcpath, dstpath1, dstpath2, nonexistingpath) = test @@ -532,39 +486,29 @@ def make_main_two_files(path1, path2, nonexistingpath): # Should still work with -o subdir/.. - make_main('somefile.txt') # absolute becomes relative + make_main('somefile.txt') # absolute becomes relative ensure_dir('dirrey') - self.compile_btest( - 'main.c', ['--preload-file', absolute_src_path, '-o', 'dirrey/page.html'], reporting=Reporting.JS_ONLY - ) + self.compile_btest('main.c', ['--preload-file', absolute_src_path, '-o', 'dirrey/page.html'], reporting=Reporting.JS_ONLY) self.run_browser('dirrey/page.html', '/report_result?exit:0') # With FS.preloadFile - create_file( - 'pre.js', - ''' + create_file('pre.js', ''' // we need --use-preload-plugins for this. Module.preRun = () => FS.createPreloadedFile('/', 'someotherfile.txt', 'somefile.txt', true, false); - ''', - ) + ''') make_main('someotherfile.txt') self.btest_exit('main.c', args=['--pre-js', 'pre.js', '--use-preload-plugins']) # Tests that user .html shell files can manually download .data files created with --preload-file cmdline. - @parameterized( - { - '': ([],), - 'pthreads': (['-pthread', '-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME'],), - } - ) + @parameterized({ + '': ([],), + 'pthreads': (['-pthread', '-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME'],), + }) def test_preload_file_with_manual_data_download(self, args): create_file('file.txt', 'Hello!') - self.compile_btest( - 'browser/test_manual_download_data.c', - ['-sEXIT_RUNTIME', '-o', 'out.js', '--preload-file', 'file.txt@/file.txt'] + args, - ) + self.compile_btest('browser/test_manual_download_data.c', ['-sEXIT_RUNTIME', '-o', 'out.js', '--preload-file', 'file.txt@/file.txt'] + args) shutil.copy(test_file('browser/test_manual_download_data.html'), '.') # Move .data file out of server root to ensure that getPreloadedPackage is actually used @@ -578,9 +522,7 @@ def test_preload_file_with_manual_data_download(self, args): # correctly escaping the names. def test_output_file_escaping(self): self.set_setting('EXIT_RUNTIME') - tricky_part = ( - '\'' if WINDOWS else '\' and "' - ) # On Windows, files/directories may not contain a double quote character. On non-Windowses they can, so test that. + tricky_part = '\'' if WINDOWS else '\' and \"' # On Windows, files/directories may not contain a double quote character. On non-Windowses they can, so test that. d = 'dir with ' + tricky_part abs_d = os.path.abspath(d) @@ -589,9 +531,7 @@ def test_output_file_escaping(self): create_file(os.path.join(d, txt), 'load me right before') src = os.path.join(d, 'file with ' + tricky_part + '.c') - create_file( - src, - r''' + create_file(src, r''' #include #include #include @@ -606,44 +546,26 @@ def test_output_file_escaping(self): assert(strcmp("load me right before", buf) == 0); return 0; } - ''' - % (txt.replace('\'', '\\\'').replace('"', '\\"')), - ) + ''' % (txt.replace('\'', '\\\'').replace('\"', '\\"'))) data_file = os.path.join(abs_d, 'file with ' + tricky_part + '.data') data_js_file = os.path.join(abs_d, 'file with ' + tricky_part + '.js') abs_txt = os.path.join(abs_d, txt) - self.run_process( - [ - FILE_PACKAGER, - data_file, - '--use-preload-cache', - '--indexedDB-name=testdb', - '--preload', - abs_txt + '@' + txt, - '--js-output=' + data_js_file, - ] - ) + self.run_process([FILE_PACKAGER, data_file, '--use-preload-cache', '--indexedDB-name=testdb', '--preload', abs_txt + '@' + txt, '--js-output=' + data_js_file]) page_file = os.path.join(d, 'file with ' + tricky_part + '.html') abs_page_file = os.path.abspath(page_file) - self.compile_btest( - src, ['--pre-js', data_js_file, '-o', abs_page_file, '-sFORCE_FILESYSTEM'], reporting=Reporting.JS_ONLY - ) + self.compile_btest(src, ['--pre-js', data_js_file, '-o', abs_page_file, '-sFORCE_FILESYSTEM'], reporting=Reporting.JS_ONLY) self.run_browser(page_file, '/report_result?exit:0') - @parameterized( - { - '0': (0,), - '1mb': (1 * 1024 * 1024,), - '100mb': (100 * 1024 * 1024,), - '150mb': (150 * 1024 * 1024,), - } - ) + @parameterized({ + '0': (0,), + '1mb': (1 * 1024 * 1024,), + '100mb': (100 * 1024 * 1024,), + '150mb': (150 * 1024 * 1024,), + }) def test_preload_caching(self, extra_size): self.set_setting('EXIT_RUNTIME') - create_file( - 'main.c', - r''' + create_file('main.c', r''' #include #include #include @@ -662,13 +584,9 @@ def test_preload_caching(self, extra_size): assert(strcmp("load me right before", buf) == 0); return checkPreloadResults(); } - ''' - % 'somefile.txt', - ) + ''' % 'somefile.txt') - create_file( - 'test.js', - ''' + create_file('test.js', ''' addToLibrary({ checkPreloadResults: function() { var cached = 0; @@ -681,8 +599,7 @@ def test_preload_caching(self, extra_size): return cached; } }); - ''', - ) + ''') # test caching of various sizes, including sizes higher than 128MB which is # chrome's limit on IndexedDB item sizes, see @@ -692,20 +609,7 @@ def test_preload_caching(self, extra_size): self.skipTest('chrome bug') create_file('somefile.txt', '''load me right before running the code please''' + ('_' * extra_size)) print('size:', os.path.getsize('somefile.txt')) - self.compile_btest( - 'main.c', - [ - '--use-preload-cache', - '--js-library', - 'test.js', - '--preload-file', - 'somefile.txt', - '-o', - 'page.html', - '-sALLOW_MEMORY_GROWTH', - ], - reporting=Reporting.JS_ONLY, - ) + self.compile_btest('main.c', ['--use-preload-cache', '--js-library', 'test.js', '--preload-file', 'somefile.txt', '-o', 'page.html', '-sALLOW_MEMORY_GROWTH'], reporting=Reporting.JS_ONLY) self.run_browser('page.html', '/report_result?exit:0') self.run_browser('page.html', '/report_result?exit:1') @@ -715,9 +619,7 @@ def test_preload_caching_indexeddb_name(self): def make_main(path): print(path) - create_file( - 'main.c', - r''' + create_file('main.c', r''' #include #include #include @@ -738,13 +640,9 @@ def make_main(path): assert(strcmp("load me right before", buf) == 0); return checkPreloadResults(); } - ''' - % path, - ) + ''' % path) - create_file( - 'test.js', - ''' + create_file('test.js', ''' addToLibrary({ checkPreloadResults: function() { var cached = 0; @@ -757,26 +655,11 @@ def make_main(path): return cached; } }); - ''', - ) + ''') make_main('somefile.txt') - self.run_process( - [ - FILE_PACKAGER, - 'somefile.data', - '--use-preload-cache', - '--indexedDB-name=testdb', - '--preload', - 'somefile.txt', - '--js-output=' + 'somefile.js', - ] - ) - self.compile_btest( - 'main.c', - ['--js-library', 'test.js', '--pre-js', 'somefile.js', '-o', 'page.html', '-sFORCE_FILESYSTEM'], - reporting=Reporting.JS_ONLY, - ) + self.run_process([FILE_PACKAGER, 'somefile.data', '--use-preload-cache', '--indexedDB-name=testdb', '--preload', 'somefile.txt', '--js-output=' + 'somefile.js']) + self.compile_btest('main.c', ['--js-library', 'test.js', '--pre-js', 'somefile.js', '-o', 'page.html', '-sFORCE_FILESYSTEM'], reporting=Reporting.JS_ONLY) self.run_browser('page.html', '/report_result?exit:0') self.run_browser('page.html', '/report_result?exit:1') @@ -785,9 +668,7 @@ def test_multifile(self): ensure_dir('subdirr/moar') create_file('subdirr/data1.txt', '1214141516171819') create_file('subdirr/moar/data2.txt', '3.14159265358979') - create_file( - 'main.c', - r''' + create_file('main.c', r''' #include #include #include @@ -811,8 +692,7 @@ def test_multifile(self): return 0; } - ''', - ) + ''') # by individual files self.btest_exit('main.c', args=['--preload-file', 'subdirr/data1.txt', '--preload-file', 'subdirr/moar/data2.txt']) @@ -832,11 +712,7 @@ def test_custom_file_package_url(self): # you would add this in your own custom html file etc., and not by # modifying the existing shell in this manner default_shell = read_file(path_from_root('src/shell.html')) - create_file( - 'shell.html', - default_shell.replace( - 'var Module = {', - ''' + create_file('shell.html', default_shell.replace('var Module = {', ''' var Module = { locateFile: function(path, prefix) { if (path.endsWith(".wasm")) { @@ -845,12 +721,8 @@ def test_custom_file_package_url(self): return "cdn/" + path; } }, - ''', - ), - ) - create_file( - 'main.c', - r''' + ''')) + create_file('main.c', r''' #include #include #include @@ -867,15 +739,10 @@ def test_custom_file_package_url(self): return 0; } - ''', - ) + ''') self.set_setting('EXIT_RUNTIME') - self.compile_btest( - 'main.c', - ['--shell-file', 'shell.html', '--preload-file', 'subdirr/data1.txt', '-o', 'test.html'], - reporting=Reporting.JS_ONLY, - ) + self.compile_btest('main.c', ['--shell-file', 'shell.html', '--preload-file', 'subdirr/data1.txt', '-o', 'test.html'], reporting=Reporting.JS_ONLY) shutil.move('test.data', Path('cdn/test.data')) self.run_browser('test.html', '/report_result?exit:0') @@ -883,9 +750,7 @@ def test_missing_data_throws_error(self): def setup(assetLocalization): self.clear() create_file('data.txt', 'data') - create_file( - 'main.c', - r''' + create_file('main.c', r''' #include #include #include @@ -893,11 +758,8 @@ def setup(assetLocalization): // This code should never be executed in terms of missing required dependency file. return 0; } - ''', - ) - create_file( - 'on_window_error_shell.html', - r''' + ''') + create_file('on_window_error_shell.html', r'''


@@ -914,9 +776,7 @@ def setup(assetLocalization): window.addEventListener('error', handler); window.addEventListener('unhandledrejection', handler); var Module = { - locateFile: function (path, prefix) {if (path.endsWith(".wasm")) {return prefix + path;} else {return "''' - + assetLocalization - + r'''" + path;}}, + locateFile: function (path, prefix) {if (path.endsWith(".wasm")) {return prefix + path;} else {return "''' + assetLocalization + r'''" + path;}}, print: (function() { var element = document.getElementById('output'); return function(text) { element.innerHTML += text.replace('\n', '
', 'g') + '
';}; @@ -926,30 +786,23 @@ def setup(assetLocalization): {{{ SCRIPT }}} - ''', - ) + ''') def test(): # test test missing file should run xhr.onload with status different than 200, 304 or 206 setup("") - self.compile_btest( - 'main.c', ['--shell-file', 'on_window_error_shell.html', '--preload-file', 'data.txt', '-o', 'test.html'] - ) + self.compile_btest('main.c', ['--shell-file', 'on_window_error_shell.html', '--preload-file', 'data.txt', '-o', 'test.html']) shutil.move('test.data', 'missing.data') self.run_browser('test.html', '/report_result?1') # test unknown protocol should go through xhr.onerror setup("unknown_protocol://") - self.compile_btest( - 'main.c', ['--shell-file', 'on_window_error_shell.html', '--preload-file', 'data.txt', '-o', 'test.html'] - ) + self.compile_btest('main.c', ['--shell-file', 'on_window_error_shell.html', '--preload-file', 'data.txt', '-o', 'test.html']) self.run_browser('test.html', '/report_result?1') # test wrong protocol and port setup("https://localhost:8800/") - self.compile_btest( - 'main.c', ['--shell-file', 'on_window_error_shell.html', '--preload-file', 'data.txt', '-o', 'test.html'] - ) + self.compile_btest('main.c', ['--shell-file', 'on_window_error_shell.html', '--preload-file', 'data.txt', '-o', 'test.html']) self.run_browser('test.html', '/report_result?1') test() @@ -974,175 +827,105 @@ def test_sdl_image(self): # load an image file, get pixel data. Also O2 coverage for --preload-file shutil.copy(test_file('screenshot.jpg'), '.') src = test_file('browser/test_sdl_image.c') - for dest, dirname, basename in [ - ('screenshot.jpg', '/', 'screenshot.jpg'), - ('screenshot.jpg@/assets/screenshot.jpg', '/assets', 'screenshot.jpg'), - ]: - self.btest_exit( - src, - args=[ - '-O2', - '-lSDL', - '-lGL', - '--preload-file', - dest, - '-DSCREENSHOT_DIRNAME="' + dirname + '"', - '-DSCREENSHOT_BASENAME="' + basename + '"', - '--use-preload-plugins', - ], - ) + for dest, dirname, basename in [('screenshot.jpg', '/', 'screenshot.jpg'), + ('screenshot.jpg@/assets/screenshot.jpg', '/assets', 'screenshot.jpg')]: + self.btest_exit(src, args=[ + '-O2', '-lSDL', '-lGL', + '--preload-file', dest, '-DSCREENSHOT_DIRNAME="' + dirname + '"', '-DSCREENSHOT_BASENAME="' + basename + '"', '--use-preload-plugins' + ]) @also_with_wasmfs def test_sdl_image_jpeg(self): shutil.copy(test_file('screenshot.jpg'), 'screenshot.jpeg') - self.btest_exit( - 'test_sdl_image.c', - args=[ - '--preload-file', - 'screenshot.jpeg', - '-DSCREENSHOT_DIRNAME="/"', - '-DSCREENSHOT_BASENAME="screenshot.jpeg"', - '--use-preload-plugins', - '-lSDL', - '-lGL', - ], - ) + self.btest_exit('test_sdl_image.c', args=[ + '--preload-file', 'screenshot.jpeg', + '-DSCREENSHOT_DIRNAME="/"', '-DSCREENSHOT_BASENAME="screenshot.jpeg"', '--use-preload-plugins', + '-lSDL', '-lGL', + ]) def test_sdl_image_webp(self): shutil.copy(test_file('screenshot.webp'), '.') - self.btest_exit( - 'test_sdl_image.c', - args=[ - '--preload-file', - 'screenshot.webp', - '-DSCREENSHOT_DIRNAME="/"', - '-DSCREENSHOT_BASENAME="screenshot.webp"', - '--use-preload-plugins', - '-lSDL', - '-lGL', - ], - ) + self.btest_exit('test_sdl_image.c', args=[ + '--preload-file', 'screenshot.webp', + '-DSCREENSHOT_DIRNAME="/"', '-DSCREENSHOT_BASENAME="screenshot.webp"', '--use-preload-plugins', + '-lSDL', '-lGL', + ]) @also_with_wasmfs @also_with_proxying def test_sdl_image_prepare(self): # load an image file, get pixel data. shutil.copy(test_file('screenshot.jpg'), 'screenshot.not') - self.reftest( - 'test_sdl_image_prepare.c', 'screenshot.jpg', args=['--preload-file', 'screenshot.not', '-lSDL', '-lGL'] - ) - - @parameterized( - { - '': ([],), - # add testing for closure on preloaded files + ENVIRONMENT=web (we must not - # emit any node.js code here, see - # https://github.com/emscripten-core/emscripten/issues/14486 - 'closure_webonly': (['--closure', '1', '-sENVIRONMENT=web'],), - } - ) + self.reftest('test_sdl_image_prepare.c', 'screenshot.jpg', args=['--preload-file', 'screenshot.not', '-lSDL', '-lGL']) + + @parameterized({ + '': ([],), + # add testing for closure on preloaded files + ENVIRONMENT=web (we must not + # emit any node.js code here, see + # https://github.com/emscripten-core/emscripten/issues/14486 + 'closure_webonly': (['--closure', '1', '-sENVIRONMENT=web'],) + }) def test_sdl_image_prepare_data(self, args): # load an image file, get pixel data. shutil.copy(test_file('screenshot.jpg'), 'screenshot.not') - self.reftest( - 'test_sdl_image_prepare_data.c', - 'screenshot.jpg', - args=['--preload-file', 'screenshot.not', '-lSDL', '-lGL'] + args, - ) + self.reftest('test_sdl_image_prepare_data.c', 'screenshot.jpg', args=['--preload-file', 'screenshot.not', '-lSDL', '-lGL'] + args) def test_sdl_image_must_prepare(self): # load an image file, get pixel data. shutil.copy(test_file('screenshot.jpg'), 'screenshot.jpg') - self.reftest( - 'test_sdl_image_must_prepare.c', 'screenshot.jpg', args=['--preload-file', 'screenshot.jpg', '-lSDL', '-lGL'] - ) + self.reftest('test_sdl_image_must_prepare.c', 'screenshot.jpg', args=['--preload-file', 'screenshot.jpg', '-lSDL', '-lGL']) def test_sdl_stb_image(self): # load an image file, get pixel data. shutil.copy(test_file('screenshot.jpg'), 'screenshot.not') - self.reftest( - 'test_sdl_stb_image.c', - 'screenshot.jpg', - args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL'], - ) + self.reftest('test_sdl_stb_image.c', 'screenshot.jpg', args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL']) def test_sdl_stb_image_bpp(self): # load grayscale image without alpha shutil.copy(test_file('browser/test_sdl-stb-bpp1.png'), 'screenshot.not') - self.reftest( - 'test_sdl_stb_image.c', - 'test_sdl-stb-bpp1.png', - args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL'], - ) + self.reftest('test_sdl_stb_image.c', 'test_sdl-stb-bpp1.png', args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL']) # load grayscale image with alpha self.clear() shutil.copy(test_file('browser/test_sdl-stb-bpp2.png'), 'screenshot.not') - self.reftest( - 'test_sdl_stb_image.c', - 'test_sdl-stb-bpp2.png', - args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL'], - ) + self.reftest('test_sdl_stb_image.c', 'test_sdl-stb-bpp2.png', args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL']) # load RGB image self.clear() shutil.copy(test_file('browser/test_sdl-stb-bpp3.png'), 'screenshot.not') - self.reftest( - 'test_sdl_stb_image.c', - 'test_sdl-stb-bpp3.png', - args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL'], - ) + self.reftest('test_sdl_stb_image.c', 'test_sdl-stb-bpp3.png', args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL']) # load RGBA image self.clear() shutil.copy(test_file('browser/test_sdl-stb-bpp4.png'), 'screenshot.not') - self.reftest( - 'test_sdl_stb_image.c', - 'test_sdl-stb-bpp4.png', - args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL'], - ) + self.reftest('test_sdl_stb_image.c', 'test_sdl-stb-bpp4.png', args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL']) def test_sdl_stb_image_data(self): # load an image file, get pixel data. shutil.copy(test_file('screenshot.jpg'), 'screenshot.not') - self.reftest( - 'test_sdl_stb_image_data.c', - 'screenshot.jpg', - args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL'], - ) + self.reftest('test_sdl_stb_image_data.c', 'screenshot.jpg', args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL']) def test_sdl_stb_image_cleanup(self): shutil.copy(test_file('screenshot.jpg'), 'screenshot.not') - self.btest_exit( - 'test_sdl_stb_image_cleanup.c', - args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL', '--memoryprofiler'], - ) - - @parameterized( - { - '': ([],), - 'safe_heap': (['-sSAFE_HEAP'],), - 'safe_heap_O2': (['-sSAFE_HEAP', '-O2'],), - } - ) + self.btest_exit('test_sdl_stb_image_cleanup.c', args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL', '--memoryprofiler']) + + @parameterized({ + '': ([],), + 'safe_heap': (['-sSAFE_HEAP'],), + 'safe_heap_O2': (['-sSAFE_HEAP', '-O2'],), + }) def test_sdl_canvas(self, args): self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args) @proxied def test_sdl_canvas_proxy(self): create_file('data.txt', 'datum') - self.reftest( - 'test_sdl_canvas_proxy.c', - 'test_sdl_canvas_proxy.png', - args=['--proxy-to-worker', '--preload-file', 'data.txt', '-lSDL', '-lGL'], - ) + self.reftest('test_sdl_canvas_proxy.c', 'test_sdl_canvas_proxy.png', args=['--proxy-to-worker', '--preload-file', 'data.txt', '-lSDL', '-lGL']) @requires_graphics_hardware def test_glgears_proxy_jstarget(self): # test .js target with --proxy-worker; emits 2 js files, client and worker - self.compile_btest( - 'hello_world_gles_proxy.c', ['-o', 'test.js', '--proxy-to-worker', '-sGL_TESTING', '-lGL', '-lglut'] - ) + self.compile_btest('hello_world_gles_proxy.c', ['-o', 'test.js', '--proxy-to-worker', '-sGL_TESTING', '-lGL', '-lglut']) shell_with_script('shell_minimal.html', 'test.html', '') self.make_reftest(test_file('gears.png')) self.post_manual_reftest() @@ -1154,26 +937,20 @@ def test_sdl_canvas_alpha(self): create_file('flag_0.js', "Module['arguments'] = ['-0'];") self.reftest('test_sdl_canvas_alpha.c', 'test_sdl_canvas_alpha.png', args=['-lSDL', '-lGL'], reference_slack=12) - self.reftest( - 'test_sdl_canvas_alpha.c', - 'test_sdl_canvas_alpha_flag_0.png', - args=['--pre-js', 'flag_0.js', '-lSDL', '-lGL'], - reference_slack=12, - ) - - @parameterized( - { - '': ([],), - 'eventhandler': (['-DTEST_EMSCRIPTEN_SDL_SETEVENTHANDLER'],), - } - ) - @parameterized( - { - '': ([],), - 'asyncify': (['-DTEST_SLEEP', '-sASSERTIONS', '-sSAFE_HEAP', '-sASYNCIFY'],), - } - ) - @parameterized({'': (False,), 'delay': (True,)}) + self.reftest('test_sdl_canvas_alpha.c', 'test_sdl_canvas_alpha_flag_0.png', args=['--pre-js', 'flag_0.js', '-lSDL', '-lGL'], reference_slack=12) + + @parameterized({ + '': ([],), + 'eventhandler': (['-DTEST_EMSCRIPTEN_SDL_SETEVENTHANDLER'],), + }) + @parameterized({ + '': ([],), + 'asyncify': (['-DTEST_SLEEP', '-sASSERTIONS', '-sSAFE_HEAP', '-sASYNCIFY'],), + }) + @parameterized({ + '': (False,), + 'delay': (True,) + }) def test_sdl_key(self, defines, async_, delay): if delay: settimeout_start = 'setTimeout(function() {' @@ -1181,9 +958,7 @@ def test_sdl_key(self, defines, async_, delay): else: settimeout_start = '' settimeout_end = '' - create_file( - 'pre.js', - ''' + create_file('pre.js', ''' function keydown(c) { %s simulateKeyDown(c); @@ -1195,20 +970,12 @@ def test_sdl_key(self, defines, async_, delay): simulateKeyUp(c); %s } - ''' - % (settimeout_start, settimeout_end, settimeout_start, settimeout_end), - ) - self.btest_exit( - 'test_sdl_key.c', - 223092870, - args=defines + async_ + ['--pre-js', test_file('browser/fake_events.js'), '--pre-js=pre.js', '-lSDL', '-lGL'], - ) + ''' % (settimeout_start, settimeout_end, settimeout_start, settimeout_end)) + self.btest_exit('test_sdl_key.c', 223092870, args=defines + async_ + ['--pre-js', test_file('browser/fake_events.js'), '--pre-js=pre.js', '-lSDL', '-lGL']) def test_sdl_key_proxy(self): shutil.copy(test_file('browser/fake_events.js'), '.') - create_file( - 'pre.js', - ''' + create_file('pre.js', ''' Module.postRun = () => { function doOne() { Module._one(); @@ -1216,14 +983,11 @@ def test_sdl_key_proxy(self): } setTimeout(doOne, 1000/60); } - ''', - ) + ''') def post(): html = read_file('test.html') - html = html.replace( - '', - ''' + html = html.replace('', ''' -''', - ) +''') create_file('test.html', html) - self.btest_exit( - 'test_sdl_key_proxy.c', - 223092870, - args=['--proxy-to-worker', '--pre-js', 'pre.js', '-lSDL', '-lGL', '-sRUNTIME_DEBUG'], - post_build=post, - ) + self.btest_exit('test_sdl_key_proxy.c', 223092870, args=['--proxy-to-worker', '--pre-js', 'pre.js', '-lSDL', '-lGL', '-sRUNTIME_DEBUG'], post_build=post) def test_canvas_focus(self): self.btest_exit('test_canvas_focus.c', args=['--pre-js', test_file('browser/fake_events.js')]) @@ -1251,9 +1009,7 @@ def test_canvas_focus(self): def test_keydown_preventdefault_proxy(self): def post(): html = read_file('test.html') - html = html.replace( - '', - ''' + html = html.replace('', ''' -''', - ) +''') create_file('test.html', html) @@ -1276,9 +1031,7 @@ def post(): self.btest_exit('browser/test_keydown_preventdefault_proxy.c', 300, args=['--proxy-to-worker'], post_build=post) def test_sdl_text(self): - create_file( - 'pre.js', - ''' + create_file('pre.js', ''' Module.postRun = () => { function doOne() { Module._one(); @@ -1286,22 +1039,15 @@ def test_sdl_text(self): } setTimeout(doOne, 1000/60); } - ''', - ) + ''') - self.btest_exit( - 'test_sdl_text.c', args=['--pre-js', 'pre.js', '--pre-js', test_file('browser/fake_events.js'), '-lSDL', '-lGL'] - ) + self.btest_exit('test_sdl_text.c', args=['--pre-js', 'pre.js', '--pre-js', test_file('browser/fake_events.js'), '-lSDL', '-lGL']) def test_sdl_mouse(self): - self.btest_exit( - 'test_sdl_mouse.c', args=['-O2', '--minify=0', '--pre-js', test_file('browser/fake_events.js'), '-lSDL', '-lGL'] - ) + self.btest_exit('test_sdl_mouse.c', args=['-O2', '--minify=0', '--pre-js', test_file('browser/fake_events.js'), '-lSDL', '-lGL']) def test_sdl_mouse_offsets(self): - create_file( - 'page.html', - ''' + create_file('page.html', '''