Skip to content

Commit 2893d21

Browse files
authored
Convert test_zzz_zzz_emmalloc_4gb to btest_exit (#20656)
This simplifies the test so it can also be run under node. e.g. ``` $ ./test/runner browser.test_zzz_zzz_emmalloc_4gb --browser=node ```
1 parent 3fd368c commit 2893d21

File tree

3 files changed

+37
-35
lines changed

3 files changed

+37
-35
lines changed

test/mem_growth.cpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

test/test_browser.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5438,10 +5438,10 @@ def test_wasm_worker_proxied_function(self):
54385438
@requires_v8
54395439
def test_zzz_zzz_4gb(self):
54405440
# TODO Convert to an actual browser test when it reaches stable.
5441-
# For now, keep this in browser as this suite runs serially, which
5442-
# means we don't compete for memory with anything else (and run it
5443-
# at the very very end, to reduce the risk of it OOM-killing the
5444-
# browser).
5441+
# For now, keep this in browser as this suite runs serially, which
5442+
# means we don't compete for memory with anything else (and run it
5443+
# at the very very end, to reduce the risk of it OOM-killing the
5444+
# browser).
54455445

54465446
# test that we can allocate in the 2-4GB range, if we enable growth and
54475447
# set the max appropriately
@@ -5451,9 +5451,11 @@ def test_zzz_zzz_4gb(self):
54515451
# Tests that emmalloc supports up to 4GB Wasm heaps.
54525452
@no_firefox('no 4GB support yet')
54535453
def test_zzz_zzz_emmalloc_4gb(self):
5454-
self.btest('mem_growth.cpp',
5455-
expected='-65536', # == 4*1024*1024*1024 - 65536 casted to signed
5456-
args=['-sMALLOC=emmalloc', '-sABORTING_MALLOC=0', '-sALLOW_MEMORY_GROWTH=1', '-sMAXIMUM_MEMORY=4GB'])
5454+
# For now, keep this in browser as this suite runs serially, which
5455+
# means we don't compete for memory with anything else (and run it
5456+
# at the very very end, to reduce the risk of it OOM-killing the
5457+
# browser).
5458+
self.btest_exit('test_mem_growth.c', args=['-sMALLOC=emmalloc', '-sABORTING_MALLOC=0', '-sALLOW_MEMORY_GROWTH=1', '-sMAXIMUM_MEMORY=4GB'])
54575459

54585460
# Test that it is possible to malloc() a huge 3GB memory block in 4GB mode using emmalloc.
54595461
# Also test emmalloc-memvalidate and emmalloc-memvalidate-verbose build configurations.

test/test_mem_growth.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <assert.h>
2+
#include <stdio.h>
3+
4+
#include <emscripten/emmalloc.h>
5+
#include <emscripten/html5.h>
6+
#include <emscripten/heap.h>
7+
8+
#define EXPECTED_FINAL_HEAP_SIZE (4*1024*1024*1024ll - 65536)
9+
10+
int main() {
11+
size_t prevheapsize = 0;
12+
int count = 0;
13+
while (1) {
14+
size_t heap_size = emscripten_get_heap_size();
15+
if (prevheapsize != heap_size) {
16+
printf("Heap size: %zu inc: %zu count: %d\n", heap_size, heap_size - prevheapsize, count);
17+
}
18+
19+
prevheapsize = heap_size;
20+
void *ptr = malloc(16*1024*1024);
21+
if (!ptr) {
22+
printf("Cannot malloc anymore. Final heap size: %zu\n", emscripten_get_heap_size());
23+
assert(emscripten_get_heap_size() == EXPECTED_FINAL_HEAP_SIZE);
24+
return 0;
25+
}
26+
count++;
27+
}
28+
}

0 commit comments

Comments
 (0)