Skip to content

Commit 16edbe5

Browse files
authored
Wasm backend pthreads testing improvements (#8842)
* 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).
1 parent 4e8ad61 commit 16edbe5

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/worker.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,14 @@ this.onmessage = function(e) {
191191
assert(selfThreadId);
192192
assert(parentThreadId);
193193
assert(STACK_BASE != 0);
194-
#if !WASM_BACKEND
195-
assert(STACK_MAX > STACK_BASE);
194+
#if WASM_BACKEND
195+
assert(max === e.data.stackBase);
196+
assert(top > max);
197+
assert(e.data.stackBase == max);
198+
#else
199+
assert(max > e.data.stackBase);
200+
assert(max > top);
201+
assert(e.data.stackBase === top);
196202
#endif
197203
#endif
198204
// Call inside asm.js/wasm module to set up the stack frame for this pthread in asm.js/wasm module scope

tests/test_browser.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -3538,13 +3538,11 @@ def prep_no_SAB(self):
35383538

35393539
# Test that the emscripten_ atomics api functions work.
35403540
@requires_threads
3541-
@no_wasm_backend('TODO - fix final pthreads tests (#8718)')
35423541
def test_pthread_atomics(self):
35433542
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'])
35443543

35453544
# Test 64-bit atomics.
35463545
@requires_threads
3547-
@flaky # TODO - fix final pthreads tests (#8718)
35483546
def test_pthread_64bit_atomics(self):
35493547
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'])
35503548

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

35583556
# Test the old GCC atomic __sync_fetch_and_op builtin operations.
35593557
@requires_threads
3560-
@no_wasm_backend('TODO - fix final pthreads tests (#8718)')
35613558
def test_pthread_gcc_atomic_fetch_and_op(self):
35623559
# We need to resort to using regexes to optimize out SharedArrayBuffer when pthreads are not supported, which is brittle!
35633560
# Therefore perform very extensive testing of different codegen modes to catch any problems.
3564-
for opt in [[], ['-O1'], ['-O2'], ['-O3'], ['-O3', '-s', 'AGGRESSIVE_VARIABLE_ELIMINATION=1'], ['-Os'], ['-Oz']]:
3561+
for opt in [[], ['-O1'], ['-O2'], ['-O3'], ['-O3', '-s', 'AGGRESSIVE_VARIABLE_ELIMINATION=1'], ['-Os']]:
35653562
for debug in [[], ['-g1'], ['-g2'], ['-g4']]:
35663563
for f32 in [[], ['-s', 'PRECISE_F32=1', '--separate-asm', '-s', 'WASM=0']]:
3567-
print(opt, debug, f32)
3568-
if self.is_wasm_backend() and '--separate-asm' in f32:
3564+
args = opt + debug + f32
3565+
print(args)
3566+
if self.is_wasm_backend() and '--separate-asm' in args or 'AGGRESSIVE_VARIABLE_ELIMINATION=1' in args:
35693567
continue
3570-
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'])
3568+
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'])
35713569

35723570
# 64 bit version of the above test.
35733571
@requires_threads
@@ -3590,15 +3588,13 @@ def test_pthread_gcc_atomics(self):
35903588
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'])
35913589

35923590
# Test the __sync_lock_test_and_set and __sync_lock_release primitives.
3593-
@no_wasm_backend('TODO - fix final pthreads tests (#8718)')
35943591
@requires_threads
35953592
def test_pthread_gcc_spinlock(self):
35963593
for arg in [[], ['-DUSE_EMSCRIPTEN_INTRINSICS']]:
35973594
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)
35983595

35993596
# Test that basic thread creation works.
36003597
@requires_threads
3601-
@no_wasm_backend('TODO - fix final pthreads tests (#8718)')
36023598
def test_pthread_create(self):
36033599
def test(args):
36043600
print(args)
@@ -3615,7 +3611,6 @@ def test_pthread_proxy_to_pthread(self):
36153611

36163612
# Test that a pthread can spawn another pthread of its own.
36173613
@requires_threads
3618-
@no_wasm_backend('TODO - fix final pthreads tests (#8718)')
36193614
def test_pthread_create_pthread(self):
36203615
for modularize in [[], ['-s', 'MODULARIZE=1', '-s', 'EXPORT_NAME=MyModule', '--shell-file', path_from_root('tests', 'shell_that_launches_modularize.html')]]:
36213616
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)
@@ -3632,7 +3627,6 @@ def test_pthread_join(self):
36323627

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

@@ -3796,7 +3790,6 @@ def test_pthread_proxying_in_futex_wait(self):
37963790
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'])
37973791

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

0 commit comments

Comments
 (0)