Skip to content

Commit

Permalink
[wasm64] Fix a lot of the remaining browser tests
Browse files Browse the repository at this point in the history
This also inverts the testing logic such that we run all browser
tests in wasm64 mode.  Tests that don't currently pass are annotated
with @no_wasm64.
  • Loading branch information
sbc100 committed Oct 24, 2023
1 parent a0a3f24 commit f74fc7e
Show file tree
Hide file tree
Showing 44 changed files with 447 additions and 262 deletions.
46 changes: 1 addition & 45 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -776,51 +776,7 @@ jobs:
steps:
- run-tests-chrome:
title: "browser64"
test_targets: "
browser64.test_sdl_swsurface
browser64.test_sdl_surface_lock_opts
browser64.test_sdl_canvas
browser64.test_sdl_canvas_proxy
browser64.test_sdl_canvas_alpha
browser64.test_canvas_focus
browser64.test_sdl_text
browser64.test_sdl_mouse
browser64.test_sdl_mouse_offsets
browser64.test_sdl_joystick_1
browser64.test_sdl_joystick_2
browser64.test_idbstore
browser64.test_idbstore_sync_asyncify
browser64.test_idbstore_sync_jspi
browser64.test_sdl_pumpevents
browser64.test_sdl_canvas_size
browser64.test_sdl_gl_read
browser64.test_sdl_gl_mapbuffers
browser64.test_sdl_ogl
browser64.test_sdl_ogl_defaultmatrixmode
browser64.test_sdl_ogl_p
browser64.test_sdl_ogl_proc_alias
browser64.test_sdl_fog_simple
browser64.test_sdl_fog_negative
browser64.test_sdl_fog_density
browser64.test_sdl_fog_exp2
browser64.test_sdl_fog_linear
browser64.test_egl
browser64.test_egl_width_height
browser64.test_egl_createcontext_error
browser64.test_glgears_animation
browser64.test_glgears_deriv
browser64.test_anisotropic
browser64.test_webgpu_get_device
browser64.test_fetch_to_memory
browser64.test_fetch_to_indexdb
browser64.test_fetch_cached_xhr
browser64.test_fetch_response_headers
browser64.test_fetch_stream_file
browser64.test_fetch_headers_received
browser64.test_fetch_xhr_abort
browser64.test_fetch_sync_xhr
browser64.test_fetch_implicit_append
"
test_targets: "browser64 skip:browser64.test_zzz_zzz_4gb_fail"
test-browser-firefox:
executor: bionic
steps:
Expand Down
11 changes: 11 additions & 0 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,8 @@ def create_pointer_conversion_wrappers(metadata):
'emscripten_builtin_malloc': 'pp',
'malloc': 'pp',
'memalign': 'ppp',
'memcmp': '_ppp',
'memcpy': 'pppp',
'__getTypeName': 'pp',
'setThrew': '_p',
'free': '_p',
Expand All @@ -917,6 +919,10 @@ def create_pointer_conversion_wrappers(metadata):
'__cxa_increment_exception_refcount': '_p',
'__cxa_decrement_exception_refcount': '_p',
'_wasmfs_write_file': '_ppp',
'_wasmfs_mknod': '_p__',
'_wasmfs_get_cwd': 'p_',
'_wasmfs_identify': '_p',
'_wasmfs_read_file': 'pp',
'__dl_seterr': '_pp',
'_emscripten_run_on_main_thread_js': '___p_',
'_emscripten_proxy_execute_task_queue': '_p',
Expand All @@ -933,6 +939,11 @@ def create_pointer_conversion_wrappers(metadata):
'asyncify_start_rewind': '_p',
'asyncify_start_unwind': '_p',
'__get_exception_message': '_ppp',
'stbi_image_free': 'vp',
'stbi_load': 'ppppp_',
'stbi_load_from_memory': 'pp_ppp_',
'emscripten_proxy_finish': '_p',
'emscripten_proxy_execute_queue': '_p',
}

for function in settings.SIGNATURE_CONVERSIONS:
Expand Down
5 changes: 4 additions & 1 deletion src/jsifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,13 @@ function(${args}) {
if (oneliner) {
body = `return ${body}`;
}
const rtnType = sig && sig.length ? sig[0] : null;
const proxyFunc = (MEMORY64 && rtnType == 'p') ? 'proxyToMainThreadPtr' : 'proxyToMainThread';
deps.push('$' + proxyFunc);
return `
function(${args}) {
if (ENVIRONMENT_IS_PTHREAD)
return proxyToMainThread(${proxiedFunctionTable.length}, ${+sync}${args ? ', ' : ''}${args});
return ${proxyFunc}(${proxiedFunctionTable.length}, ${+sync}${args ? ', ' : ''}${args});
${body}
}\n`
});
Expand Down
10 changes: 5 additions & 5 deletions src/library_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,11 @@ var LibraryBrowser = {
new Uint8Array(data.object.contents), true, true,
() => {
{{{ runtimeKeepalivePop() }}}
if (onload) {{{ makeDynCall('vi', 'onload') }}}(file);
if (onload) {{{ makeDynCall('vp', 'onload') }}}(file);
},
() => {
{{{ runtimeKeepalivePop() }}}
if (onerror) {{{ makeDynCall('vi', 'onerror') }}}(file);
if (onerror) {{{ makeDynCall('vp', 'onerror') }}}(file);
},
true // don'tCreateFile - it's already there
);
Expand All @@ -743,11 +743,11 @@ var LibraryBrowser = {
true, true,
() => {
{{{ runtimeKeepalivePop() }}}
if (onload) {{{ makeDynCall('vii', 'onload') }}}(arg, cname);
if (onload) {{{ makeDynCall('vpp', 'onload') }}}(arg, cname);
},
() => {
{{{ runtimeKeepalivePop() }}}
if (onerror) {{{ makeDynCall('vi', 'onerror') }}}(arg);
if (onerror) {{{ makeDynCall('vp', 'onerror') }}}(arg);
},
true // don'tCreateFile - it's already there
);
Expand Down Expand Up @@ -1224,7 +1224,7 @@ var LibraryBrowser = {
{{{ runtimeKeepalivePush() }}}
callbackId = info.callbacks.length;
info.callbacks.push({
func: {{{ makeDynCall('viii', 'callback') }}},
func: {{{ makeDynCall('vpip', 'callback') }}},
arg
});
info.awaited++;
Expand Down
2 changes: 1 addition & 1 deletion src/library_glew.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var LibraryGLEW = {

extensionIsSupported(name) {
if (!GLEW.extensions) {
GLEW.extensions = UTF8ToString(_glGetString(0x1F03)).split(' ');
GLEW.extensions = GLctx.getSupportedExtensions() || [];
}

if (GLEW.extensions.includes(name))
Expand Down
62 changes: 32 additions & 30 deletions src/library_glfw.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ var LibraryGLFW = {
this.domKeys = new Array();
this.shouldClose = 0;
this.title = null;
this.windowPosFunc = null; // GLFWwindowposfun
this.windowSizeFunc = null; // GLFWwindowsizefun
this.windowCloseFunc = null; // GLFWwindowclosefun
this.windowRefreshFunc = null; // GLFWwindowrefreshfun
this.windowFocusFunc = null; // GLFWwindowfocusfun
this.windowIconifyFunc = null; // GLFWwindowiconifyfun
this.windowMaximizeFunc = null; // GLFWwindowmaximizefun
this.framebufferSizeFunc = null; // GLFWframebuffersizefun
this.windowContentScaleFunc = null; // GLFWwindowcontentscalefun
this.mouseButtonFunc = null; // GLFWmousebuttonfun
this.cursorPosFunc = null; // GLFWcursorposfun
this.cursorEnterFunc = null; // GLFWcursorenterfun
this.scrollFunc = null; // GLFWscrollfun
this.dropFunc = null; // GLFWdropfun
this.keyFunc = null; // GLFWkeyfun
this.charFunc = null; // GLFWcharfun
this.userptr = null;
this.windowPosFunc = 0; // GLFWwindowposfun
this.windowSizeFunc = 0; // GLFWwindowsizefun
this.windowCloseFunc = 0; // GLFWwindowclosefun
this.windowRefreshFunc = 0; // GLFWwindowrefreshfun
this.windowFocusFunc = 0; // GLFWwindowfocusfun
this.windowIconifyFunc = 0; // GLFWwindowiconifyfun
this.windowMaximizeFunc = 0; // GLFWwindowmaximizefun
this.framebufferSizeFunc = 0; // GLFWframebuffersizefun
this.windowContentScaleFunc = 0; // GLFWwindowcontentscalefun
this.mouseButtonFunc = 0; // GLFWmousebuttonfun
this.cursorPosFunc = 0; // GLFWcursorposfun
this.cursorEnterFunc = 0; // GLFWcursorenterfun
this.scrollFunc = 0; // GLFWscrollfun
this.dropFunc = 0; // GLFWdropfun
this.keyFunc = 0; // GLFWkeyfun
this.charFunc = 0; // GLFWcharfun
this.userptr = 0;
},

$GLFW__deps: ['emscripten_get_now', '$GL', '$Browser', '$GLFW_Window',
Expand All @@ -94,9 +94,9 @@ var LibraryGLFW = {
return GLFW.windows[id - 1];
},

joystickFunc: null, // GLFWjoystickfun
errorFunc: null, // GLFWerrorfun
monitorFunc: null, // GLFWmonitorfun
joystickFunc: 0, // GLFWjoystickfun
errorFunc: 0, // GLFWerrorfun
monitorFunc: 0, // GLFWmonitorfun
active: null, // active window
scale: null,
windows: null,
Expand Down Expand Up @@ -372,7 +372,7 @@ var LibraryGLFW = {
{{{ makeDynCall('vii', 'GLFW.active.charFunc') }}}(charCode, 1);
#endif
#if USE_GLFW == 3
{{{ makeDynCall('vii', 'GLFW.active.charFunc') }}}(GLFW.active.id, charCode);
{{{ makeDynCall('vpi', 'GLFW.active.charFunc') }}}(GLFW.active.id, charCode);
#endif
},

Expand All @@ -394,7 +394,7 @@ var LibraryGLFW = {
#endif
#if USE_GLFW == 3
if (repeat) status = 2; // GLFW_REPEAT
{{{ makeDynCall('viiiii', 'GLFW.active.keyFunc') }}}(GLFW.active.id, key, keyCode, status, GLFW.getModBits(GLFW.active));
{{{ makeDynCall('vpiiii', 'GLFW.active.keyFunc') }}}(GLFW.active.id, key, keyCode, status, GLFW.getModBits(GLFW.active));
#endif
}
},
Expand Down Expand Up @@ -510,7 +510,7 @@ var LibraryGLFW = {
{{{ makeDynCall('vii', 'GLFW.active.mouseButtonFunc') }}}(eventButton, status);
#endif
#if USE_GLFW == 3
{{{ makeDynCall('viiii', 'GLFW.active.mouseButtonFunc') }}}(GLFW.active.id, eventButton, status, GLFW.getModBits(GLFW.active));
{{{ makeDynCall('vpiii', 'GLFW.active.mouseButtonFunc') }}}(GLFW.active.id, eventButton, status, GLFW.getModBits(GLFW.active));
#endif
}
},
Expand Down Expand Up @@ -601,7 +601,7 @@ var LibraryGLFW = {
{{{ makeDynCall('vii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.width, GLFW.active.height);
#endif
#if USE_GLFW == 3
{{{ makeDynCall('viii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height);
{{{ makeDynCall('vpii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height);
#endif
}
},
Expand All @@ -611,7 +611,7 @@ var LibraryGLFW = {

#if USE_GLFW == 3
if (GLFW.active.framebufferSizeFunc) {
{{{ makeDynCall('viii', 'GLFW.active.framebufferSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height);
{{{ makeDynCall('vpii', 'GLFW.active.framebufferSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height);
}
#endif
},
Expand Down Expand Up @@ -642,8 +642,10 @@ var LibraryGLFW = {
},

setJoystickCallback: (cbfun) => {
var prevcbfun = GLFW.joystickFunc;
GLFW.joystickFunc = cbfun;
GLFW.refreshJoysticks();
return prevcbfun;
},

joys: {}, // glfw joystick data
Expand Down Expand Up @@ -780,7 +782,7 @@ var LibraryGLFW = {
var data = e.target.result;
FS.writeFile(path, new Uint8Array(data));
if (++written === count) {
{{{ makeDynCall('viii', 'GLFW.active.dropFunc') }}}(GLFW.active.id, count, filenames);
{{{ makeDynCall('vpii', 'GLFW.active.dropFunc') }}}(GLFW.active.id, count, filenames);

for (var i = 0; i < filenamesArray.length; ++i) {
_free(filenamesArray[i]);
Expand Down Expand Up @@ -994,7 +996,7 @@ var LibraryGLFW = {
{{{ makeDynCall('vii', 'win.windowSizeFunc') }}}(width, height);
#endif
#if USE_GLFW == 3
{{{ makeDynCall('viii', 'win.windowSizeFunc') }}}(win.id, width, height);
{{{ makeDynCall('vpii', 'win.windowSizeFunc') }}}(win.id, width, height);
#endif
}
},
Expand Down Expand Up @@ -1064,7 +1066,7 @@ var LibraryGLFW = {

#if USE_GLFW == 3
if (win.windowCloseFunc) {
{{{ makeDynCall('vi', 'win.windowCloseFunc') }}}(win.id);
{{{ makeDynCall('vp', 'win.windowCloseFunc') }}}(win.id);
}
#endif

Expand Down Expand Up @@ -1220,7 +1222,7 @@ var LibraryGLFW = {
glfwExtensionSupported__deps: ['glGetString'],
glfwExtensionSupported: (extension) => {
if (!GLFW.extensions) {
GLFW.extensions = UTF8ToString(_glGetString(0x1F03)).split(' ');
GLFW.extensions = GLctx.getSupportedExtensions() || [];
}

if (GLFW.extensions.includes(extension)) return 1;
Expand Down Expand Up @@ -1758,7 +1760,7 @@ var LibraryGLFW = {
},

glfwCreateThread: (fun, arg) => {
{{{ makeDynCall('vi', 'fun') }}}(arg);
{{{ makeDynCall('vp', 'fun') }}}(arg);
// One single thread
return 0;
},
Expand Down
24 changes: 20 additions & 4 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var LibraryPThread = {

#if PTHREADS_PROFILING
getThreadName(pthreadPtr) {
var profilerBlock = {{{ makeGetValue('pthreadPtr', C_STRUCTS.pthread.profilerBlock, POINTER_TYPE) }}};
var profilerBlock = {{{ makeGetValue('pthreadPtr', C_STRUCTS.pthread.profilerBlock, '*') }}};
if (!profilerBlock) return "";
return UTF8ToString(profilerBlock + {{{ C_STRUCTS.thread_profiler_block.name }}});
},
Expand All @@ -162,7 +162,7 @@ var LibraryPThread = {
},

threadStatusAsString(pthreadPtr) {
var profilerBlock = {{{ makeGetValue('pthreadPtr', C_STRUCTS.pthread.profilerBlock, POINTER_TYPE) }}};
var profilerBlock = {{{ makeGetValue('pthreadPtr', C_STRUCTS.pthread.profilerBlock, '*') }}};
var status = (profilerBlock == 0) ? 0 : Atomics.load(HEAPU32, {{{ getHeapOffset('profilerBlock + ' + C_STRUCTS.thread_profiler_block.threadStatus, 'i32') }}});
return PThread.threadStatusToString(status);
},
Expand Down Expand Up @@ -759,7 +759,7 @@ var LibraryPThread = {
// Deduce which WebGL canvases (HTMLCanvasElements or OffscreenCanvases) should be passed over to the
// Worker that hosts the spawned pthread.
// Comma-delimited list of CSS selectors that must identify canvases by IDs: "#canvas1, #canvas2, ..."
var transferredCanvasNames = attr ? {{{ makeGetValue('attr', C_STRUCTS.pthread_attr_t._a_transferredcanvases, POINTER_TYPE) }}} : 0;
var transferredCanvasNames = attr ? {{{ makeGetValue('attr', C_STRUCTS.pthread_attr_t._a_transferredcanvases, '*') }}} : 0;
#if OFFSCREENCANVASES_TO_PTHREAD
// Proxied canvases string pointer -1 is used as a special token to fetch
// whatever canvases were passed to build in -s
Expand Down Expand Up @@ -948,7 +948,13 @@ var LibraryPThread = {
_exit(returnCode);
},
$proxyToMainThread__deps: ['$withStackSave', '_emscripten_run_on_main_thread_js'],
// Calls proxyToMainThread but returns a bigint rather than a number
$proxyToMainThreadPtr__deps: ['$proxyToMainThread'],
$proxyToMainThreadPtr: function() {
return BigInt(proxyToMainThread.apply(null, arguments));
},
$proxyToMainThread__deps: ['$withStackSave', '_emscripten_run_on_main_thread_js'].concat(i53ConversionDeps),
$proxyToMainThread__docs: '/** @type{function(number, (number|boolean), ...(number|boolean))} */',
$proxyToMainThread: function(index, sync) {
// Additional arguments are passed after those two, which are the actual
Expand Down Expand Up @@ -1032,6 +1038,16 @@ var LibraryPThread = {
PThread.currentProxiedOperationCallerThread = callingThread;
var rtn = func.apply(null, proxiedJSCallArgs);
PThread.currentProxiedOperationCallerThread = 0;
#if MEMORY64
if (typeof rtn == "bigint") {
rtn = bigintToI53Checked(rtn);
}
#endif
#if ASSERTIONS
// Proxied functions can return any type except bigint. All other types
// cooerce to i32 (the return type of this function) but not bigint.
assert(typeof rtn != "bigint");
#endif
return rtn;
},
Expand Down
4 changes: 4 additions & 0 deletions src/library_sigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,12 @@ sigs = {
emscripten_idb_clear__sig: 'vpp',
emscripten_idb_delete__sig: 'vppp',
emscripten_idb_exists__sig: 'vpppp',
emscripten_idb_free_blob__sig: 'vi',
emscripten_idb_load__sig: 'vppppp',
emscripten_idb_load_blob__sig: 'vpppp',
emscripten_idb_read_from_blob__sig: 'viiip',
emscripten_idb_store__sig: 'vpppip',
emscripten_idb_store_blob__sig: 'vpppip',
emscripten_is_webgl_context_lost__sig: 'ii',
emscripten_lazy_load_code__sig: 'v',
emscripten_lock_async_acquire__sig: 'vpppd',
Expand Down
4 changes: 2 additions & 2 deletions src/library_strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ addToLibrary({
#endif
$UTF8ToString: (ptr, maxBytesToRead) => {
#if ASSERTIONS
assert(typeof ptr == 'number');
assert(typeof ptr == 'number', `UTF8ToString expects a number (got ${typeof ptr})`);
#endif
#if CAN_ADDRESS_2GB
ptr >>>= 0;
Expand Down Expand Up @@ -158,7 +158,7 @@ addToLibrary({
outIdx >>>= 0;
#endif
#if ASSERTIONS
assert(typeof str === 'string');
assert(typeof str === 'string', `stringToUTF8Array expects a string (got ${typeof str})`);
#endif
// Parameter maxBytesToWrite is not optional. Negative values, 0, null,
// undefined and false each don't write out any bytes.
Expand Down
2 changes: 1 addition & 1 deletion src/library_wasm_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ if (ENVIRONMENT_IS_WASM_WORKER) {
emscripten_lock_async_acquire: (lock, asyncWaitFinished, userData, maxWaitMilliseconds) => {
let dispatch = (val, ret) => {
setTimeout(() => {
{{{ makeDynCall('viiii', 'asyncWaitFinished') }}}(lock, val, /*waitResult=*/ret, userData);
{{{ makeDynCall('vpiip', 'asyncWaitFinished') }}}(lock, val, /*waitResult=*/ret, userData);
}, 0);
};
let tryAcquireLock = () => {
Expand Down
Loading

0 comments on commit f74fc7e

Please sign in to comment.