diff --git a/.circleci/config.yml b/.circleci/config.yml index cdf414a8c7c00..43bea6f53b48a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -985,6 +985,7 @@ jobs: other.test_node_emscripten_num_logical_cores other.test_js_base64_api other.test_pthread_growth* + other.test_memory_growth core2.test_hello_world core2.test_pthread_create core2.test_i64_invoke_bigint diff --git a/test/common.py b/test/common.py index ca1afe9cd8c42..98e71bcac81b1 100644 --- a/test/common.py +++ b/test/common.py @@ -332,6 +332,14 @@ def get_deno(): return get_engine(engine_is_deno) +def check_node_version(major, minor=0, revision=0): + nodejs = get_nodejs() + if not nodejs: + return False + version = shared.get_node_version(nodejs) + return version >= (major, minor, revision) + + def clean_js_output(output): """Cleanup the JS output prior to running verification steps on it. @@ -543,14 +551,10 @@ def require_wasm64(self): self.fail('either d8, node >= 24 or deno required to run wasm64 tests. Use EMTEST_SKIP_WASM64 to skip') def try_require_node_version(self, major, minor=0, revision=0): - nodejs = get_nodejs() - if not nodejs: - return False - version = shared.get_node_version(nodejs) - if version < (major, minor, revision): + if not check_node_version(major, minor, revision): return False - self.require_engine(nodejs) + self.require_engine(get_nodejs()) return True def require_wasm_legacy_eh(self): diff --git a/test/test_other.py b/test/test_other.py index 37334dcf5dfcd..970d91503295c 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -42,6 +42,7 @@ TEST_ROOT, WEBIDL_BINDER, RunnerCore, + check_node_version, copy_asset, copytree, create_file, @@ -6425,22 +6426,39 @@ def test_file_packager_huge(self): self.assertContained(MESSAGE, err) self.clear() + @crossplatform @also_with_wasm2js def test_memory_growth(self): create_file('main.c', r''' #include #include +#include +#include +#include int main() { + // Report whether `toResizableBuffer` is availble on the wasm memory. + EM_ASM(out('resizable memory buffers:', Boolean(wasmMemory.toResizableBuffer))); + void* x = malloc(10 * 1024 * 1024); assert(x != NULL); + // Have JS use some of the memory in the expanded range + char* str = (char*)x - 100; + strcpy(str, "Hello, world!"); + emscripten_out(str); return 0; } ''') - output = self.do_runf('main.c', cflags=['-sALLOW_MEMORY_GROWTH', '-sINITIAL_HEAP=1mb']) + output = self.do_runf('main.c', 'Hello, world!\n', cflags=['-sALLOW_MEMORY_GROWTH', '-sINITIAL_HEAP=1mb']) if self.is_wasm2js(): self.assertContained('Warning: Enlarging memory arrays, this is not fast! 1179648,10616832\n', output) + # Node versions older than 26 do not support toResizableBuffer + if self.is_wasm2js() or (self.engine_is_node() and not check_node_version(26)): + self.assertContained('resizable memory buffers: false\n', output) + else: + self.assertContained('resizable memory buffers: true\n', output) + @also_with_wasm2js @parameterized({ '': (False,), @@ -8558,7 +8576,7 @@ def test_exceptions_stack_trace_and_message(self): ''' self.cflags += ['-g'] - if '-fwasm-exceptions' in self.cflags and engine_is_node(self.js_engines[0]): + if '-fwasm-exceptions' in self.cflags and self.engine_is_node(): if not self.try_require_node_version(24): # Node versions prior to v24 do not implement the new 'traceStack' option in # WebAssembly.Exception constructor. @@ -8678,7 +8696,7 @@ def test_exceptions_rethrow_stack_trace_and_message(self): return 0; } ''' - if '-fwasm-exceptions' in self.cflags and engine_is_node(self.js_engines[0]): + if '-fwasm-exceptions' in self.cflags and self.engine_is_node(): if not self.try_require_node_version(24): # Node versions prior to v24 do not implement the new 'traceStack' option in # WebAssembly.Exception constructor.