Skip to content

Commit fadaf2c

Browse files
authored
Report availability of toResizableBuffer in test_memory_growth. NFC (#27116)
Split out from #27096
1 parent d913170 commit fadaf2c

3 files changed

Lines changed: 33 additions & 10 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ jobs:
985985
other.test_node_emscripten_num_logical_cores
986986
other.test_js_base64_api
987987
other.test_pthread_growth*
988+
other.test_memory_growth
988989
core2.test_hello_world
989990
core2.test_pthread_create
990991
core2.test_i64_invoke_bigint

test/common.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,14 @@ def get_deno():
332332
return get_engine(engine_is_deno)
333333

334334

335+
def check_node_version(major, minor=0, revision=0):
336+
nodejs = get_nodejs()
337+
if not nodejs:
338+
return False
339+
version = shared.get_node_version(nodejs)
340+
return version >= (major, minor, revision)
341+
342+
335343
def clean_js_output(output):
336344
"""Cleanup the JS output prior to running verification steps on it.
337345
@@ -543,14 +551,10 @@ def require_wasm64(self):
543551
self.fail('either d8, node >= 24 or deno required to run wasm64 tests. Use EMTEST_SKIP_WASM64 to skip')
544552

545553
def try_require_node_version(self, major, minor=0, revision=0):
546-
nodejs = get_nodejs()
547-
if not nodejs:
548-
return False
549-
version = shared.get_node_version(nodejs)
550-
if version < (major, minor, revision):
554+
if not check_node_version(major, minor, revision):
551555
return False
552556

553-
self.require_engine(nodejs)
557+
self.require_engine(get_nodejs())
554558
return True
555559

556560
def require_wasm_legacy_eh(self):

test/test_other.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
TEST_ROOT,
4545
WEBIDL_BINDER,
4646
RunnerCore,
47+
check_node_version,
4748
copy_asset,
4849
copytree,
4950
create_file,
@@ -6454,22 +6455,39 @@ def test_file_packager_huge(self):
64546455
self.assertContained(MESSAGE, err)
64556456
self.clear()
64566457

6458+
@crossplatform
64576459
@also_with_wasm2js
64586460
def test_memory_growth(self):
64596461
create_file('main.c', r'''
64606462
#include <assert.h>
64616463
#include <stdlib.h>
6464+
#include <string.h>
6465+
#include <emscripten/em_asm.h>
6466+
#include <emscripten/console.h>
64626467

64636468
int main() {
6464-
void* x = malloc(10 * 1024 * 1024);
6469+
// Report whether `toResizableBuffer` is availble on the wasm memory.
6470+
EM_ASM(out('resizable memory buffers:', Boolean(wasmMemory.toResizableBuffer)));
6471+
6472+
char* x = malloc(10 * 1024 * 1024);
64656473
assert(x != NULL);
6474+
// Have JS use some of the memory in the expanded range.
6475+
char* str = x + 9 * 1024 * 1024;
6476+
strcpy(str, "Hello, world!");
6477+
emscripten_out(str);
64666478
return 0;
64676479
}
64686480
''')
6469-
output = self.do_runf('main.c', cflags=['-sALLOW_MEMORY_GROWTH', '-sINITIAL_HEAP=1mb'])
6481+
output = self.do_runf('main.c', 'Hello, world!\n', cflags=['-sALLOW_MEMORY_GROWTH', '-sINITIAL_HEAP=1mb'])
64706482
if self.is_wasm2js():
64716483
self.assertContained('Warning: Enlarging memory arrays, this is not fast! 1179648,10616832\n', output)
64726484

6485+
# Node versions older than 26 do not support toResizableBuffer
6486+
if self.is_wasm2js() or (self.engine_is_node() and not check_node_version(26)):
6487+
self.assertContained('resizable memory buffers: false\n', output)
6488+
else:
6489+
self.assertContained('resizable memory buffers: true\n', output)
6490+
64736491
@also_with_wasm2js
64746492
@parameterized({
64756493
'': (False,),
@@ -8587,7 +8605,7 @@ def test_exceptions_stack_trace_and_message(self):
85878605
'''
85888606
self.cflags += ['-g']
85898607

8590-
if '-fwasm-exceptions' in self.cflags and engine_is_node(self.js_engines[0]):
8608+
if '-fwasm-exceptions' in self.cflags and self.engine_is_node():
85918609
if not self.try_require_node_version(24):
85928610
# Node versions prior to v24 do not implement the new 'traceStack' option in
85938611
# WebAssembly.Exception constructor.
@@ -8707,7 +8725,7 @@ def test_exceptions_rethrow_stack_trace_and_message(self):
87078725
return 0;
87088726
}
87098727
'''
8710-
if '-fwasm-exceptions' in self.cflags and engine_is_node(self.js_engines[0]):
8728+
if '-fwasm-exceptions' in self.cflags and self.engine_is_node():
87118729
if not self.try_require_node_version(24):
87128730
# Node versions prior to v24 do not implement the new 'traceStack' option in
87138731
# WebAssembly.Exception constructor.

0 commit comments

Comments
 (0)