|
5 | 5 |
|
6 | 6 | // Test emscripten_atomic_cancel_all_wait_asyncs() function.
|
7 | 7 |
|
8 |
| -EM_JS(void, console_log, (char* str), { |
9 |
| - console.log(UTF8ToString(str)); |
10 |
| -}); |
11 |
| - |
12 | 8 | volatile int32_t addr = 1;
|
13 | 9 |
|
14 | 10 | EM_BOOL testSucceeded = 1;
|
15 | 11 |
|
16 | 12 | void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData)
|
17 | 13 | {
|
18 |
| - console_log("asyncWaitFinishedShouldNotBeCalled"); |
| 14 | + emscripten_console_log("asyncWaitFinishedShouldNotBeCalled"); |
19 | 15 | testSucceeded = 0;
|
20 | 16 | assert(0); // We should not reach here
|
21 | 17 | }
|
22 | 18 |
|
23 | 19 | void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData)
|
24 | 20 | {
|
25 |
| - console_log("asyncWaitFinishedShouldBeCalled"); |
| 21 | + emscripten_console_log("asyncWaitFinishedShouldBeCalled"); |
26 | 22 | #ifdef REPORT_RESULT
|
27 | 23 | REPORT_RESULT(testSucceeded);
|
28 | 24 | #endif
|
29 | 25 | }
|
30 | 26 |
|
31 | 27 | int main()
|
32 | 28 | {
|
33 |
| - console_log("Async waiting on address should give a wait token"); |
| 29 | + emscripten_console_log("Async waiting on address should give a wait token"); |
34 | 30 | ATOMICS_WAIT_TOKEN_T ret = emscripten_atomic_wait_async((int32_t*)&addr, 1, asyncWaitFinishedShouldNotBeCalled, (void*)42, EMSCRIPTEN_WAIT_ASYNC_INFINITY);
|
35 | 31 | assert(EMSCRIPTEN_IS_VALID_WAIT_TOKEN(ret));
|
36 | 32 |
|
37 |
| - console_log("Async waiting on address should give a wait token"); |
| 33 | + emscripten_console_log("Async waiting on address should give a wait token"); |
38 | 34 | ATOMICS_WAIT_TOKEN_T ret2 = emscripten_atomic_wait_async((int32_t*)&addr, 1, asyncWaitFinishedShouldNotBeCalled, (void*)42, EMSCRIPTEN_WAIT_ASYNC_INFINITY);
|
39 | 35 | assert(EMSCRIPTEN_IS_VALID_WAIT_TOKEN(ret2));
|
40 | 36 |
|
41 |
| - console_log("Canceling all async waits at wait address should return the number of waits cancelled"); |
| 37 | + emscripten_console_log("Canceling all async waits at wait address should return the number of waits cancelled"); |
42 | 38 | int numCancelled = emscripten_atomic_cancel_all_wait_asyncs_at_address((int32_t*)&addr);
|
43 | 39 | assert(numCancelled == 2);
|
44 | 40 |
|
45 |
| - console_log("Canceling all async waits at some other address should return 0"); |
| 41 | + emscripten_console_log("Canceling all async waits at some other address should return 0"); |
46 | 42 | numCancelled = emscripten_atomic_cancel_all_wait_asyncs_at_address((int32_t*)0xbad);
|
47 | 43 | assert(numCancelled == 0);
|
48 | 44 |
|
49 |
| - console_log("Canceling an async wait that has already been cancelled should give an invalid param"); |
| 45 | + emscripten_console_log("Canceling an async wait that has already been cancelled should give an invalid param"); |
50 | 46 | EMSCRIPTEN_RESULT r = emscripten_atomic_cancel_wait_async(ret);
|
51 | 47 | assert(r == EMSCRIPTEN_RESULT_INVALID_PARAM);
|
52 | 48 |
|
53 |
| - console_log("Canceling an async wait that has already been cancelled should give an invalid param"); |
| 49 | + emscripten_console_log("Canceling an async wait that has already been cancelled should give an invalid param"); |
54 | 50 | r = emscripten_atomic_cancel_wait_async(ret2);
|
55 | 51 | assert(r == EMSCRIPTEN_RESULT_INVALID_PARAM);
|
56 | 52 |
|
57 |
| - console_log("Notifying an async wait should not trigger the callback function"); |
| 53 | + emscripten_console_log("Notifying an async wait should not trigger the callback function"); |
58 | 54 | int64_t numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
|
59 | 55 |
|
60 |
| - console_log("Notifying an async wait should return 0 threads woken"); |
| 56 | + emscripten_console_log("Notifying an async wait should return 0 threads woken"); |
61 | 57 | assert(numWoken == 0);
|
62 | 58 |
|
63 | 59 | addr = 2;
|
64 |
| - console_log("Notifying an async wait even after changed value should not trigger the callback function"); |
| 60 | + emscripten_console_log("Notifying an async wait even after changed value should not trigger the callback function"); |
65 | 61 | numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
|
66 | 62 |
|
67 |
| - console_log("Notifying an async wait should return 0 threads woken"); |
| 63 | + emscripten_console_log("Notifying an async wait should return 0 threads woken"); |
68 | 64 | assert(numWoken == 0);
|
69 | 65 |
|
70 |
| - console_log("Async waiting on address should give a wait token"); |
| 66 | + emscripten_console_log("Async waiting on address should give a wait token"); |
71 | 67 | ret = emscripten_atomic_wait_async((int32_t*)&addr, 2, asyncWaitFinishedShouldBeCalled, (void*)42, EMSCRIPTEN_WAIT_ASYNC_INFINITY);
|
72 | 68 | assert(EMSCRIPTEN_IS_VALID_WAIT_TOKEN(ret));
|
73 | 69 |
|
74 | 70 | #if 0
|
75 |
| - console_log("Notifying an async wait without value changing should still trigger the callback"); |
| 71 | + emscripten_console_log("Notifying an async wait without value changing should still trigger the callback"); |
76 | 72 | numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
|
77 | 73 | assert(numWoken == 1);
|
78 | 74 | #else
|
79 | 75 | // TODO: Switch to the above test instead after the Atomics.waitAsync() polyfill is dropped.
|
80 | 76 | addr = 3;
|
81 |
| - console_log("Notifying an async wait after value changing should trigger the callback"); |
| 77 | + emscripten_console_log("Notifying an async wait after value changing should trigger the callback"); |
82 | 78 | numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
|
83 | 79 | #endif
|
84 | 80 | }
|
0 commit comments