From 6f5dde7e803bd5ed807786f3cb33584c166137b2 Mon Sep 17 00:00:00 2001 From: Guanzhong Chen Date: Fri, 26 Jul 2019 15:12:46 -0700 Subject: [PATCH 1/2] Add a test for STACK_BASE and STACK_MAX --- tests/test_browser.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_browser.py b/tests/test_browser.py index 680f2ab369e4e..fb1b9ff87b922 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -3885,6 +3885,11 @@ def test_pthread_utf8_funcs(self): def test_pthread_wake_all(self): self.btest(path_from_root('tests', 'pthread', 'test_futex_wake_all.cpp'), expected='0', args=['-O3', '-s', 'USE_PTHREADS=1', '-s', 'TOTAL_MEMORY=64MB', '-s', 'NO_EXIT_RUNTIME=1'], also_asmjs=True) + # Test that STACK_BASE and STACK_MAX correctly bound the stack on pthreads. + @requires_threads + def test_pthread_stack_bounds(self): + self.btest(path_from_root('tests', 'pthread', 'test_pthread_stack_bounds.cpp'), expected='1', args=['-s', 'USE_PTHREADS', '-std=c++11']) + # Test that real `thread_local` works. @no_fastcomp('thread_local is only supported on WASM backend') @requires_threads From 2033daeb04564a363182e3b61f45b219ccbce086 Mon Sep 17 00:00:00 2001 From: Guanzhong Chen Date: Fri, 26 Jul 2019 15:29:15 -0700 Subject: [PATCH 2/2] Actually add the test cpp file --- tests/pthread/test_pthread_stack_bounds.cpp | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/pthread/test_pthread_stack_bounds.cpp diff --git a/tests/pthread/test_pthread_stack_bounds.cpp b/tests/pthread/test_pthread_stack_bounds.cpp new file mode 100644 index 0000000000000..0155c6c5b7ed6 --- /dev/null +++ b/tests/pthread/test_pthread_stack_bounds.cpp @@ -0,0 +1,22 @@ +#include +#include + +void thread(void) { + bool passed; + size_t stack_base = EM_ASM_INT({ return STACK_BASE; }); + size_t stack_max = EM_ASM_INT({ return STACK_MAX; }); + size_t current = (size_t) &passed; +#if __asmjs__ + passed = stack_base < current && current < stack_max; +#else + passed = stack_base > current && current > stack_max; +#endif +#ifdef REPORT_RESULT + REPORT_RESULT(passed ? 1 : 0); +#endif +} + +int main(void) { + std::thread t(thread); + t.detach(); +}