Skip to content

Commit 8659483

Browse files
authored
Cleanup test_emscripten_thread_sleep. NFC (#26637)
- Rename file - clang-format - Consistent naming and usage of emscripten_out
1 parent 2b98693 commit 8659483

File tree

3 files changed

+42
-45
lines changed

3 files changed

+42
-45
lines changed

test/pthread/emscripten_thread_sleep.c

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <assert.h>
2+
#include <emscripten.h>
3+
#include <emscripten/console.h>
4+
#include <emscripten/threading.h>
5+
#include <pthread.h>
6+
#include <stdio.h>
7+
8+
void do_sleep(double msecs) {
9+
double t1 = emscripten_get_now();
10+
emscripten_thread_sleep(msecs);
11+
double t2 = emscripten_get_now();
12+
emscripten_outf("emscripten_thread_sleep() slept for %f msecs.\n", t2 - t1);
13+
14+
assert(t2 - t1 >= 0.9 * msecs); // Should have slept ~ the requested time.
15+
}
16+
17+
void* thread_main(void* arg) {
18+
emscripten_out("hello from thread!");
19+
20+
do_sleep(1);
21+
do_sleep(10);
22+
do_sleep(100);
23+
do_sleep(1000);
24+
do_sleep(5000);
25+
26+
emscripten_force_exit(0);
27+
return NULL;
28+
}
29+
30+
int main() {
31+
// Bad bad bad to sleep on the main thread, but test that it works.
32+
do_sleep(1);
33+
do_sleep(10);
34+
do_sleep(100);
35+
do_sleep(1000);
36+
do_sleep(5000);
37+
pthread_t thread;
38+
pthread_create(&thread, NULL, thread_main, NULL);
39+
emscripten_exit_with_live_runtime();
40+
__builtin_trap();
41+
}

test/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4815,7 +4815,7 @@ def test_unicode_html_shell(self):
48154815

48164816
# Tests the functionality of the emscripten_thread_sleep() function.
48174817
def test_emscripten_thread_sleep(self):
4818-
self.btest_exit('pthread/emscripten_thread_sleep.c', cflags=['-pthread'])
4818+
self.btest_exit('pthread/test_emscripten_thread_sleep.c', cflags=['-pthread'])
48194819

48204820
# Tests that Emscripten-compiled applications can be run from a relative path in browser that is different than the address of the current page
48214821
def test_browser_run_from_different_directory(self):

0 commit comments

Comments
 (0)