Skip to content

Commit 752d858

Browse files
authored
[WasmFS] Skip test_dlmalloc (#16139)
That test depends on the heap being in a pristine state so that we can predict where allocations will happen. WasmFS apparently does enough malloc/free during startup to disrupt that, and the test fails. Also simplify the test code while I was debugging it.
1 parent 6754be3 commit 752d858

File tree

2 files changed

+19
-40
lines changed

2 files changed

+19
-40
lines changed

tests/dlmalloc_test.c

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
// Emscripten tests
99

10-
#include <stdio.h>
11-
#include <stdlib.h>
1210
#include <assert.h>
11+
#include <emscripten.h>
12+
#include <stdlib.h>
1313

1414
int main(int ac, char **av)
1515
{
@@ -20,67 +20,30 @@ int main(int ac, char **av)
2020
char* allocations[NUM];
2121
for (int i = 0; i < NUM/2; i++) {
2222
allocations[i] = (char*)malloc((11*i)%1024 + x);
23-
//printf("zz alloc: %d\n", (int)allocations[i]);
2423
assert(allocations[i]);
2524
if (i > 10 && i%4 == 1 && allocations[i-10]) {
26-
//printf("zz free: %d\n", (int)allocations[i-10]);
2725
free(allocations[i-10]);
2826
allocations[i-10] = NULL;
2927
}
3028
}
3129
for (int i = NUM/2; i < NUM; i++) {
3230
allocations[i] = (char*)malloc(1024*(i+1));
33-
//printf("zz alloc: %d\n", (int)allocations[i]);
3431
assert(allocations[i]);
3532
if (i > 10 && i%4 != 1 && allocations[i-10]) {
36-
//printf("zz free: %d\n", (int)allocations[i-10]);
3733
free(allocations[i-10]);
3834
allocations[i-10] = NULL;
3935
}
4036
}
4137
char* first = allocations[0];
4238
for (int i = 0; i < NUM; i++) {
4339
if (allocations[i]) {
44-
//printf("zz free: %d\n", (int)allocations[i]);
4540
free(allocations[i]);
4641
}
4742
}
4843
char *last = (char*)malloc(512); // should be identical, as we free'd it all
49-
//printf("zz last: %d\n", (int)last);
5044
char *newer = (char*)malloc(512); // should be different
51-
//printf("zz newer: %d\n", (int)newer);
52-
#ifndef __APPLE__
5345
c1 += first == last;
5446
c2 += first == newer;
55-
#else // On OSX, it's been detected that memory is not necessarily allocated linearly, so skip this check and simulate success.
56-
++c1;
57-
#endif
5847
}
59-
printf("*%d,%d*\n", c1, c2);
48+
emscripten_log(EM_LOG_CONSOLE, "*%d,%d*\n", c1, c2);
6049
}
61-
62-
/* Some debugging tools: Make JS and native code work exactly the same */
63-
/*
64-
time_t time ( time_t * timer )
65-
{
66-
if (timer) *timer = 1;
67-
return 1;
68-
}
69-
70-
long sysconf(int name)
71-
{
72-
printf("sysconf: %d (30 is page size)\n", name);
73-
return 4096;
74-
}
75-
76-
void *sbrk(intptr_t increment)
77-
{
78-
static char spaace[1024*1024*1];
79-
static intptr_t where = 0;
80-
printf("sbrk! spaace=%d (%d,%d)\n", (int)&spaace[0], where, increment); // copy the value printed at runtime here in native code into your js
81-
void *ret = &spaace[where];
82-
where += increment;
83-
return ret;
84-
}
85-
*/
86-

tests/test_core.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,21 @@ def decorated(self, *args, **kwargs):
304304
return decorator
305305

306306

307+
def no_wasmfs(note):
308+
assert not callable(note)
309+
310+
def decorator(f):
311+
assert callable(f)
312+
313+
@wraps(f)
314+
def decorated(self, *args, **kwargs):
315+
if self.get_setting('WASMFS'):
316+
self.skipTest(note)
317+
f(self, *args, **kwargs)
318+
return decorated
319+
return decorator
320+
321+
307322
def make_no_decorator_for_setting(name):
308323
def outer_decorator(note):
309324
assert not callable(note)
@@ -5941,6 +5956,7 @@ def test_dlmalloc_inline(self):
59415956
@require_v8
59425957
@no_asan('depends on the specifics of memory size, which for asan we are forced to increase')
59435958
@no_lsan('depends on the specifics of memory size, which for lsan we are forced to increase')
5959+
@no_wasmfs('wasmfs does some malloc/free during startup, fragmenting the heap, leading to differences later')
59445960
def test_dlmalloc(self):
59455961
# needed with typed arrays
59465962
self.set_setting('INITIAL_MEMORY', '128mb')

0 commit comments

Comments
 (0)