Skip to content

Commit de1191e

Browse files
committed
Fix wasm2s (SAFE_HEAP) test suite
This change fixes all the failing tests in the wasm2s suite. Depends on WebAssembly/binaryen#4439.
1 parent 2885620 commit de1191e

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

emcc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,9 @@ def default_setting(name, new_default):
14381438
if name not in settings_map:
14391439
setattr(settings, name, new_default)
14401440

1441-
if settings.OPT_LEVEL >= 1:
1441+
if settings.SAFE_HEAP >= 1:
1442+
default_setting('ASSERTIONS', 1)
1443+
elif settings.OPT_LEVEL >= 1:
14421444
default_setting('ASSERTIONS', 0)
14431445
if settings.SHRINK_LEVEL >= 2:
14441446
default_setting('EVAL_CTORS', 1)
@@ -1954,6 +1956,8 @@ def default_setting(name, new_default):
19541956
# SAFE_HEAP check includes calling emscripten_get_sbrk_ptr() from wasm
19551957
settings.REQUIRED_EXPORTS += ['emscripten_get_sbrk_ptr', 'emscripten_stack_get_base']
19561958
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$unSign']
1959+
if not settings.ASSERTIONS:
1960+
exit_with_error('SAFE_HEAP requires ASSERTIONS to be enabled')
19571961

19581962
if not settings.DECLARE_ASM_MODULE_EXPORTS:
19591963
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$exportAsmFunctions']

src/runtime_safe_heap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function SAFE_HEAP_STORE(dest, value, bytes, isFloat) {
110110
#else
111111
if (dest % bytes !== 0) warnOnce('alignment error in a memory store operation, alignment was a multiple of ' + (((dest ^ (dest-1)) >> 1) + 1) + ', but was was expected to be aligned to a multiple of ' + bytes);
112112
#endif
113-
if (runtimeInitialized) {
113+
if (runtimeInitialized && !runtimeExited) {
114114
var brk = _sbrk() >>> 0;
115115
if (dest + bytes > brk) abort('segmentation fault, exceeded the top of the available dynamic heap when storing ' + bytes + ' bytes to address ' + dest + '. DYNAMICTOP=' + brk);
116116
assert(brk >= _emscripten_stack_get_base()); // sbrk-managed memory must be above the stack
@@ -134,7 +134,7 @@ function SAFE_HEAP_LOAD(dest, bytes, unsigned, isFloat) {
134134
#else
135135
if (dest % bytes !== 0) warnOnce('alignment error in a memory load operation, alignment was a multiple of ' + (((dest ^ (dest-1)) >> 1) + 1) + ', but was was expected to be aligned to a multiple of ' + bytes);
136136
#endif
137-
if (runtimeInitialized) {
137+
if (runtimeInitialized && !runtimeExited) {
138138
var brk = _sbrk() >>> 0;
139139
if (dest + bytes > brk) abort('segmentation fault, exceeded the top of the available dynamic heap when loading ' + bytes + ' bytes from address ' + dest + '. DYNAMICTOP=' + brk);
140140
assert(brk >= _emscripten_stack_get_base()); // sbrk-managed memory must be above the stack

src/shell.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,9 @@ assert(typeof Module['TOTAL_MEMORY'] === 'undefined', 'Module.TOTAL_MEMORY has b
450450
{{{ makeRemovedFSAssert('IDBFS') }}}
451451
{{{ makeRemovedFSAssert('PROXYFS') }}}
452452
{{{ makeRemovedFSAssert('WORKERFS') }}}
453+
#if !NODERAWFS
453454
{{{ makeRemovedFSAssert('NODEFS') }}}
455+
#endif
454456
{{{ makeRemovedRuntimeFunction('alignMemory') }}}
455457

456458
#if USE_PTHREADS

tests/core/test_functionpointer_libfunc_varargs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ typedef int (*fp_t)(int, int, ...);
1111
int main(int argc, char **argv) {
1212
fp_t fp = &fcntl;
1313
if (argc == 1337) fp = (fp_t) & main;
14-
(*fp)(0, 10);
15-
(*fp)(0, 10, 5);
14+
(*fp)(0, F_GETFL);
15+
(*fp)(0, F_SETSIG, 5);
1616
printf("waka\n");
1717
return 0;
1818
}

tests/test_core.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6512,6 +6512,7 @@ def test_dyncall_specific(self, *args):
65126512
print(str(args) + ' ' + which)
65136513
self.do_core_test('dyncall_specific.c', emcc_args=['-D' + which] + list(args) + extra_args)
65146514

6515+
@no_safe_heap('SAFE_HEAP is not compatible with ASSERTIONS=0')
65156516
def test_getValue_setValue(self):
65166517
# these used to be exported, but no longer are by default
65176518
def test(output_prefix='', args=[], assert_returncode=0):
@@ -6535,6 +6536,7 @@ def test(output_prefix='', args=[], assert_returncode=0):
65356536
'': ([],),
65366537
'_files': (['-DUSE_FILES'],)
65376538
})
6539+
@no_safe_heap('SAFE_HEAP is not compatible with ASSERTIONS=0')
65386540
def test_FS_exports(self, extra_args):
65396541
# these used to be exported, but no longer are by default
65406542
def test(output_prefix='', args=[], assert_returncode=0):
@@ -6557,6 +6559,7 @@ def test(output_prefix='', args=[], assert_returncode=0):
65576559
self.set_setting('EXPORTED_RUNTIME_METHODS', ['FS_createDataFile'])
65586560
test(args=['-s', 'FORCE_FILESYSTEM'])
65596561

6562+
@no_safe_heap('SAFE_HEAP is not compatible with ASSERTIONS=0')
65606563
def test_legacy_exported_runtime_numbers(self):
65616564
# these used to be exported, but no longer are by default
65626565
def test(output_prefix='', args=[], assert_returncode=0):
@@ -6717,6 +6720,7 @@ def test_emulate_function_pointer_casts(self):
67176720
self.do_core_test('test_emulate_function_pointer_casts.cpp')
67186721

67196722
@no_wasm2js('TODO: nicely printed names in wasm2js')
6723+
@no_safe_heap('SAFE_HEAP is not compatible with ASSERTIONS=0')
67206724
@parameterized({
67216725
'normal': ([],),
67226726
'noexcept': (['-fno-exceptions'],)
@@ -7881,13 +7885,11 @@ def test_memprof_requirements(self):
78817885
# This test checks for the global variables required to run the memory
78827886
# profiler. It would fail if these variables were made no longer global
78837887
# or if their identifiers were changed.
7884-
create_file('main.cpp', '''
7885-
extern "C" {
7886-
void check_memprof_requirements();
7887-
}
7888+
create_file('main.c', '''
7889+
int check_memprof_requirements();
7890+
78887891
int main() {
7889-
check_memprof_requirements();
7890-
return 0;
7892+
return check_memprof_requirements();
78917893
}
78927894
''')
78937895
create_file('lib.js', '''
@@ -7898,14 +7900,16 @@ def test_memprof_requirements(self):
78987900
typeof _emscripten_stack_get_current === 'function' &&
78997901
typeof Module['___heap_base'] === 'number') {
79007902
out('able to run memprof');
7903+
return 0;
79017904
} else {
79027905
out('missing the required variables to run memprof');
7906+
return 1;
79037907
}
79047908
}
79057909
});
79067910
''')
79077911
self.emcc_args += ['--memoryprofiler', '--js-library', 'lib.js']
7908-
self.do_runf('main.cpp', 'able to run memprof')
7912+
self.do_runf('main.c', 'able to run memprof')
79097913

79107914
def test_fs_dict(self):
79117915
self.set_setting('FORCE_FILESYSTEM')

0 commit comments

Comments
 (0)