diff --git a/test/pthread/emscripten_thread_sleep.c b/test/pthread/emscripten_thread_sleep.c deleted file mode 100644 index d0183fb121da1..0000000000000 --- a/test/pthread/emscripten_thread_sleep.c +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -#include -#include -#include - -void Sleep(double msecs) -{ - double t1 = emscripten_get_now(); - emscripten_thread_sleep(msecs); - double t2 = emscripten_get_now(); - printf("emscripten_thread_sleep() slept for %f msecs.\n", t2 - t1); - - assert(t2 - t1 >= 0.9 * msecs); // Should have slept ~ the requested time. -} - -void *thread_main(void *arg) -{ - emscripten_out("hello from thread!"); - - Sleep(1); - Sleep(10); - Sleep(100); - Sleep(1000); - Sleep(5000); - - emscripten_force_exit(0); - return NULL; -} - -int main() -{ - // Bad bad bad to sleep on the main thread, but test that it works. - Sleep(1); - Sleep(10); - Sleep(100); - Sleep(1000); - Sleep(5000); - pthread_t thread; - pthread_create(&thread, NULL, thread_main, NULL); - emscripten_exit_with_live_runtime(); - __builtin_trap(); -} diff --git a/test/pthread/test_emscripten_thread_sleep.c b/test/pthread/test_emscripten_thread_sleep.c new file mode 100644 index 0000000000000..268ec2ed272f9 --- /dev/null +++ b/test/pthread/test_emscripten_thread_sleep.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include + +void do_sleep(double msecs) { + double t1 = emscripten_get_now(); + emscripten_thread_sleep(msecs); + double t2 = emscripten_get_now(); + emscripten_outf("emscripten_thread_sleep() slept for %f msecs.\n", t2 - t1); + + assert(t2 - t1 >= 0.9 * msecs); // Should have slept ~ the requested time. +} + +void* thread_main(void* arg) { + emscripten_out("hello from thread!"); + + do_sleep(1); + do_sleep(10); + do_sleep(100); + do_sleep(1000); + do_sleep(5000); + + emscripten_force_exit(0); + return NULL; +} + +int main() { + // Bad bad bad to sleep on the main thread, but test that it works. + do_sleep(1); + do_sleep(10); + do_sleep(100); + do_sleep(1000); + do_sleep(5000); + pthread_t thread; + pthread_create(&thread, NULL, thread_main, NULL); + emscripten_exit_with_live_runtime(); + __builtin_trap(); +} diff --git a/test/test_browser.py b/test/test_browser.py index bf76a59441722..a28805e0bedd8 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4815,7 +4815,7 @@ def test_unicode_html_shell(self): # Tests the functionality of the emscripten_thread_sleep() function. def test_emscripten_thread_sleep(self): - self.btest_exit('pthread/emscripten_thread_sleep.c', cflags=['-pthread']) + self.btest_exit('pthread/test_emscripten_thread_sleep.c', cflags=['-pthread']) # Tests that Emscripten-compiled applications can be run from a relative path in browser that is different than the address of the current page def test_browser_run_from_different_directory(self):