Skip to content

Commit

Permalink
[Wasm64] Allow testing of wasm64 + standalone (#18771)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Apr 25, 2023
1 parent e2918ae commit cb5ca6e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 4 additions & 1 deletion system/lib/standalone/standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ int emscripten_resize_heap(size_t size) {
assert(old_size < size);
ssize_t diff = (size - old_size + WASM_PAGE_SIZE - 1) / WASM_PAGE_SIZE;
size_t result = __builtin_wasm_memory_grow(0, diff);
if (result != (size_t)-1) {
// Its seems v8 has a bug in memory.grow that causes it to return
// (uint32_t)-1 even with memory64:
// https://bugs.chromium.org/p/v8/issues/detail?id=13948
if (result != (uint32_t)-1 && result != (size_t)-1) {
// Success, update JS (see https://github.com/WebAssembly/WASI/issues/82)
emscripten_notify_memory_growth(0);
return 1;
Expand Down
1 change: 1 addition & 0 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ def require_engine(self, engine):
self.skipTest(f'Skipping test that requires `{engine}` when `{self.required_engine}` was previously required')
self.required_engine = engine
self.js_engines = [engine]
self.wasm_engines = []

def require_wasm64(self):
if config.NODE_JS and config.NODE_JS in self.js_engines:
Expand Down
19 changes: 14 additions & 5 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,20 @@ def metafunc(self, rawfs):
return metafunc


def can_do_standalone(self):
def can_do_wasm2c(self):
# the npm version of wasm2c does not support MEMORY64
return not self.get_setting('MEMORY64')


def can_do_standalone(self, impure=False):
# Pure standalone engines don't support MEMORY64 yet. Even with MEMORY64=2 (lowered)
# the WASI APIs that take pointer values don't have 64-bit variants yet.
if self.get_setting('MEMORY64') and not impure:
return False
return self.is_wasm() and \
self.get_setting('STACK_OVERFLOW_CHECK', 0) < 2 and \
not self.get_setting('MINIMAL_RUNTIME') and \
not self.get_setting('SAFE_HEAP') and \
not self.get_setting('MEMORY64') and \
not any(a.startswith('-fsanitize=') for a in self.emcc_args)


Expand Down Expand Up @@ -202,7 +210,7 @@ def metafunc(self, standalone):
if not standalone:
func(self)
else:
if not can_do_standalone(self):
if not can_do_standalone(self, impure):
self.skipTest('Test configuration is not compatible with STANDALONE_WASM')
self.set_setting('STANDALONE_WASM')
# we will not legalize the JS ffi interface, so we must use BigInt
Expand All @@ -213,10 +221,9 @@ def metafunc(self, standalone):
# if we are impure, disallow all wasm engines
if impure:
self.wasm_engines = []
self.js_engines = [config.NODE_JS]
self.node_args += shared.node_bigint_flags()
func(self)
if wasm2c:
if wasm2c and can_do_wasm2c(self):
print('wasm2c')
self.set_setting('WASM2C')
self.wasm_engines = []
Expand Down Expand Up @@ -7160,6 +7167,8 @@ def test_wasm2c_sandboxing(self, mode):
self.node_args += shared.node_bigint_flags()
if not can_do_standalone(self):
return self.skipTest('standalone mode not supported')
if not can_do_wasm2c(self):
return self.skipTest('wasm2c not supported')
self.set_setting('STANDALONE_WASM')
self.set_setting('WASM2C')
self.set_setting('WASM2C_SANDBOXING', mode)
Expand Down

0 comments on commit cb5ca6e

Please sign in to comment.