Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
24 changes: 21 additions & 3 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
TEST_ROOT,
WEBIDL_BINDER,
RunnerCore,
check_node_version,
copy_asset,
copytree,
create_file,
Expand Down Expand Up @@ -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 <assert.h>
#include <stdlib.h>
#include <string.h>
#include <emscripten/em_asm.h>
#include <emscripten/console.h>

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,),
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading