Skip to content

Commit

Permalink
Wasm backend pthreads testing improvements (#8842)
Browse files Browse the repository at this point in the history
 *   After #8811 landed a lot more tests can pass, this enables all those that can.
 *   Remove unnecessary stuff in test_pthread_gcc_atomic_fetch_and_op.
 *   Add more runtime assertions for the stack position.

There are still a few tests that don't pass, so this doesn't close #8718. But they are quite few at this point (and look unrelated to stack issues - something else going on there).
  • Loading branch information
kripken committed Jun 22, 2019
1 parent 4e8ad61 commit 16edbe5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/worker.js
Expand Up @@ -191,8 +191,14 @@ this.onmessage = function(e) {
assert(selfThreadId);
assert(parentThreadId);
assert(STACK_BASE != 0);
#if !WASM_BACKEND
assert(STACK_MAX > STACK_BASE);
#if WASM_BACKEND
assert(max === e.data.stackBase);
assert(top > max);
assert(e.data.stackBase == max);
#else
assert(max > e.data.stackBase);
assert(max > top);
assert(e.data.stackBase === top);
#endif
#endif
// Call inside asm.js/wasm module to set up the stack frame for this pthread in asm.js/wasm module scope
Expand Down
17 changes: 5 additions & 12 deletions tests/test_browser.py
Expand Up @@ -3538,13 +3538,11 @@ def prep_no_SAB(self):

# Test that the emscripten_ atomics api functions work.
@requires_threads
@no_wasm_backend('TODO - fix final pthreads tests (#8718)')
def test_pthread_atomics(self):
self.btest(path_from_root('tests', 'pthread', 'test_pthread_atomics.cpp'), expected='0', args=['-s', 'TOTAL_MEMORY=64MB', '-O3', '-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=8'])

# Test 64-bit atomics.
@requires_threads
@flaky # TODO - fix final pthreads tests (#8718)
def test_pthread_64bit_atomics(self):
self.btest(path_from_root('tests', 'pthread', 'test_pthread_64bit_atomics.cpp'), expected='0', args=['-s', 'TOTAL_MEMORY=64MB', '-O3', '-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=8'])

Expand All @@ -3557,17 +3555,17 @@ def test_pthread_64bit_cxx11_atomics(self):

# Test the old GCC atomic __sync_fetch_and_op builtin operations.
@requires_threads
@no_wasm_backend('TODO - fix final pthreads tests (#8718)')
def test_pthread_gcc_atomic_fetch_and_op(self):
# We need to resort to using regexes to optimize out SharedArrayBuffer when pthreads are not supported, which is brittle!
# Therefore perform very extensive testing of different codegen modes to catch any problems.
for opt in [[], ['-O1'], ['-O2'], ['-O3'], ['-O3', '-s', 'AGGRESSIVE_VARIABLE_ELIMINATION=1'], ['-Os'], ['-Oz']]:
for opt in [[], ['-O1'], ['-O2'], ['-O3'], ['-O3', '-s', 'AGGRESSIVE_VARIABLE_ELIMINATION=1'], ['-Os']]:
for debug in [[], ['-g1'], ['-g2'], ['-g4']]:
for f32 in [[], ['-s', 'PRECISE_F32=1', '--separate-asm', '-s', 'WASM=0']]:
print(opt, debug, f32)
if self.is_wasm_backend() and '--separate-asm' in f32:
args = opt + debug + f32
print(args)
if self.is_wasm_backend() and '--separate-asm' in args or 'AGGRESSIVE_VARIABLE_ELIMINATION=1' in args:
continue
self.btest(path_from_root('tests', 'pthread', 'test_pthread_gcc_atomic_fetch_and_op.cpp'), expected='0', args=opt + debug + f32 + ['-s', 'TOTAL_MEMORY=64MB', '-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=8'])
self.btest(path_from_root('tests', 'pthread', 'test_pthread_gcc_atomic_fetch_and_op.cpp'), expected='0', args=args + ['-s', 'TOTAL_MEMORY=64MB', '-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=8'])

# 64 bit version of the above test.
@requires_threads
Expand All @@ -3590,15 +3588,13 @@ def test_pthread_gcc_atomics(self):
self.btest(path_from_root('tests', 'pthread', 'test_pthread_gcc_atomics.cpp'), expected='0', args=['-s', 'TOTAL_MEMORY=64MB', '-O3', '-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=8'])

# Test the __sync_lock_test_and_set and __sync_lock_release primitives.
@no_wasm_backend('TODO - fix final pthreads tests (#8718)')
@requires_threads
def test_pthread_gcc_spinlock(self):
for arg in [[], ['-DUSE_EMSCRIPTEN_INTRINSICS']]:
self.btest(path_from_root('tests', 'pthread', 'test_pthread_gcc_spinlock.cpp'), expected='800', args=['-s', 'TOTAL_MEMORY=64MB', '-O3', '-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=8'] + arg, also_asmjs=True)

# Test that basic thread creation works.
@requires_threads
@no_wasm_backend('TODO - fix final pthreads tests (#8718)')
def test_pthread_create(self):
def test(args):
print(args)
Expand All @@ -3615,7 +3611,6 @@ def test_pthread_proxy_to_pthread(self):

# Test that a pthread can spawn another pthread of its own.
@requires_threads
@no_wasm_backend('TODO - fix final pthreads tests (#8718)')
def test_pthread_create_pthread(self):
for modularize in [[], ['-s', 'MODULARIZE=1', '-s', 'EXPORT_NAME=MyModule', '--shell-file', path_from_root('tests', 'shell_that_launches_modularize.html')]]:
self.btest(path_from_root('tests', 'pthread', 'test_pthread_create_pthread.cpp'), expected='1', args=['-O3', '-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=2'] + modularize)
Expand All @@ -3632,7 +3627,6 @@ def test_pthread_join(self):

# Test that threads can rejoin the pool once detached and finished
@requires_threads
@no_wasm_backend('TODO - fix final pthreads tests (#8718)')
def test_std_thread_detach(self):
self.btest(path_from_root('tests', 'pthread', 'test_std_thread_detach.cpp'), expected='0', args=['-std=c++11', '-s', 'USE_PTHREADS=1'])

Expand Down Expand Up @@ -3796,7 +3790,6 @@ def test_pthread_proxying_in_futex_wait(self):
self.btest(path_from_root('tests', 'pthread', 'test_pthread_proxying_in_futex_wait.cpp'), expected='0', args=['-O3', '-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=1'])

# Test that sbrk() operates properly in multithreaded conditions
@no_wasm_backend('TODO - fix final pthreads tests (#8718)')
@requires_threads
def test_pthread_sbrk(self):
for aborting_malloc in [0, 1]:
Expand Down

0 comments on commit 16edbe5

Please sign in to comment.