Skip to content

Commit dd5ae0f

Browse files
authored
Remove EM_JS version of console_log in test code. NFC (#19329)
These is no need to re-implement this everywhere since `emscripten_console_log` does just this. This pattern seems to have been copied around so removing it everywhere should avoid future copies.
1 parent ca1d374 commit dd5ae0f

16 files changed

+123
-188
lines changed

test/minimal_hello.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
#include <emscripten.h>
2-
3-
EM_JS(void, console_log, (char* str), {
4-
console.log(UTF8ToString(str));
5-
});
1+
#include <emscripten/console.h>
62

73
int main()
84
{
9-
console_log("minimal hello!");
5+
emscripten_console_log("minimal hello!");
106
return 0;
117
}

test/wasm_worker/cancel_all_wait_asyncs.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,72 @@
55

66
// Test emscripten_atomic_cancel_all_wait_asyncs() function.
77

8-
EM_JS(void, console_log, (char* str), {
9-
console.log(UTF8ToString(str));
10-
});
11-
128
volatile int32_t addr = 1;
139

1410
EM_BOOL testSucceeded = 1;
1511

1612
void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData)
1713
{
18-
console_log("asyncWaitFinishedShouldNotBeCalled");
14+
emscripten_console_log("asyncWaitFinishedShouldNotBeCalled");
1915
testSucceeded = 0;
2016
assert(0); // We should not reach here
2117
}
2218

2319
void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData)
2420
{
25-
console_log("asyncWaitFinishedShouldBeCalled");
21+
emscripten_console_log("asyncWaitFinishedShouldBeCalled");
2622
#ifdef REPORT_RESULT
2723
REPORT_RESULT(testSucceeded);
2824
#endif
2925
}
3026

3127
int main()
3228
{
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");
3430
ATOMICS_WAIT_TOKEN_T ret = emscripten_atomic_wait_async((int32_t*)&addr, 1, asyncWaitFinishedShouldNotBeCalled, (void*)42, EMSCRIPTEN_WAIT_ASYNC_INFINITY);
3531
assert(EMSCRIPTEN_IS_VALID_WAIT_TOKEN(ret));
3632

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");
3834
ATOMICS_WAIT_TOKEN_T ret2 = emscripten_atomic_wait_async((int32_t*)&addr, 1, asyncWaitFinishedShouldNotBeCalled, (void*)42, EMSCRIPTEN_WAIT_ASYNC_INFINITY);
3935
assert(EMSCRIPTEN_IS_VALID_WAIT_TOKEN(ret2));
4036

41-
console_log("Canceling all async waits should return the number of waits cancelled");
37+
emscripten_console_log("Canceling all async waits should return the number of waits cancelled");
4238
int numCancelled = emscripten_atomic_cancel_all_wait_asyncs();
4339
assert(numCancelled == 2);
4440

45-
console_log("Canceling an async wait that has already been cancelled should give an invalid param");
41+
emscripten_console_log("Canceling an async wait that has already been cancelled should give an invalid param");
4642
EMSCRIPTEN_RESULT r = emscripten_atomic_cancel_wait_async(ret);
4743
assert(r == EMSCRIPTEN_RESULT_INVALID_PARAM);
4844

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");
5046
r = emscripten_atomic_cancel_wait_async(ret2);
5147
assert(r == EMSCRIPTEN_RESULT_INVALID_PARAM);
5248

53-
console_log("Notifying an async wait should not trigger the callback function");
49+
emscripten_console_log("Notifying an async wait should not trigger the callback function");
5450
int64_t numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
5551

56-
console_log("Notifying an async wait should return 0 threads woken");
52+
emscripten_console_log("Notifying an async wait should return 0 threads woken");
5753
assert(numWoken == 0);
5854

5955
addr = 2;
60-
console_log("Notifying an async wait even after changed value should not trigger the callback function");
56+
emscripten_console_log("Notifying an async wait even after changed value should not trigger the callback function");
6157
numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
6258

63-
console_log("Notifying an async wait should return 0 threads woken");
59+
emscripten_console_log("Notifying an async wait should return 0 threads woken");
6460
assert(numWoken == 0);
6561

66-
console_log("Async waiting on address should give a wait token");
62+
emscripten_console_log("Async waiting on address should give a wait token");
6763
ret = emscripten_atomic_wait_async((int32_t*)&addr, 2, asyncWaitFinishedShouldBeCalled, (void*)42, EMSCRIPTEN_WAIT_ASYNC_INFINITY);
6864
assert(EMSCRIPTEN_IS_VALID_WAIT_TOKEN(ret));
6965

7066
#if 0
71-
console_log("Notifying an async wait without value changing should still trigger the callback");
67+
emscripten_console_log("Notifying an async wait without value changing should still trigger the callback");
7268
numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
7369
assert(numWoken == 1);
7470
#else
7571
// TODO: Switch to the above test instead after the Atomics.waitAsync() polyfill is dropped.
7672
addr = 3;
77-
console_log("Notifying an async wait after value changing should trigger the callback");
73+
emscripten_console_log("Notifying an async wait after value changing should trigger the callback");
7874
numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
7975
#endif
8076
}

test/wasm_worker/cancel_all_wait_asyncs_at_address.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,76 @@
55

66
// Test emscripten_atomic_cancel_all_wait_asyncs() function.
77

8-
EM_JS(void, console_log, (char* str), {
9-
console.log(UTF8ToString(str));
10-
});
11-
128
volatile int32_t addr = 1;
139

1410
EM_BOOL testSucceeded = 1;
1511

1612
void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData)
1713
{
18-
console_log("asyncWaitFinishedShouldNotBeCalled");
14+
emscripten_console_log("asyncWaitFinishedShouldNotBeCalled");
1915
testSucceeded = 0;
2016
assert(0); // We should not reach here
2117
}
2218

2319
void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData)
2420
{
25-
console_log("asyncWaitFinishedShouldBeCalled");
21+
emscripten_console_log("asyncWaitFinishedShouldBeCalled");
2622
#ifdef REPORT_RESULT
2723
REPORT_RESULT(testSucceeded);
2824
#endif
2925
}
3026

3127
int main()
3228
{
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");
3430
ATOMICS_WAIT_TOKEN_T ret = emscripten_atomic_wait_async((int32_t*)&addr, 1, asyncWaitFinishedShouldNotBeCalled, (void*)42, EMSCRIPTEN_WAIT_ASYNC_INFINITY);
3531
assert(EMSCRIPTEN_IS_VALID_WAIT_TOKEN(ret));
3632

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");
3834
ATOMICS_WAIT_TOKEN_T ret2 = emscripten_atomic_wait_async((int32_t*)&addr, 1, asyncWaitFinishedShouldNotBeCalled, (void*)42, EMSCRIPTEN_WAIT_ASYNC_INFINITY);
3935
assert(EMSCRIPTEN_IS_VALID_WAIT_TOKEN(ret2));
4036

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");
4238
int numCancelled = emscripten_atomic_cancel_all_wait_asyncs_at_address((int32_t*)&addr);
4339
assert(numCancelled == 2);
4440

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");
4642
numCancelled = emscripten_atomic_cancel_all_wait_asyncs_at_address((int32_t*)0xbad);
4743
assert(numCancelled == 0);
4844

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");
5046
EMSCRIPTEN_RESULT r = emscripten_atomic_cancel_wait_async(ret);
5147
assert(r == EMSCRIPTEN_RESULT_INVALID_PARAM);
5248

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");
5450
r = emscripten_atomic_cancel_wait_async(ret2);
5551
assert(r == EMSCRIPTEN_RESULT_INVALID_PARAM);
5652

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");
5854
int64_t numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
5955

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");
6157
assert(numWoken == 0);
6258

6359
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");
6561
numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
6662

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");
6864
assert(numWoken == 0);
6965

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");
7167
ret = emscripten_atomic_wait_async((int32_t*)&addr, 2, asyncWaitFinishedShouldBeCalled, (void*)42, EMSCRIPTEN_WAIT_ASYNC_INFINITY);
7268
assert(EMSCRIPTEN_IS_VALID_WAIT_TOKEN(ret));
7369

7470
#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");
7672
numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
7773
assert(numWoken == 1);
7874
#else
7975
// TODO: Switch to the above test instead after the Atomics.waitAsync() polyfill is dropped.
8076
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");
8278
numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
8379
#endif
8480
}

test/wasm_worker/cancel_wait_async.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,64 @@
55

66
// Test emscripten_cancel_wait_async() function.
77

8-
EM_JS(void, console_log, (char* str), {
9-
console.log(UTF8ToString(str));
10-
});
11-
128
volatile int32_t addr = 1;
139

1410
EM_BOOL testSucceeded = 1;
1511

1612
void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData)
1713
{
18-
console_log("asyncWaitFinishedShouldNotBeCalled");
14+
emscripten_console_log("asyncWaitFinishedShouldNotBeCalled");
1915
testSucceeded = 0;
2016
assert(0); // We should not reach here
2117
}
2218

2319
void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData)
2420
{
25-
console_log("asyncWaitFinishedShouldBeCalled");
21+
emscripten_console_log("asyncWaitFinishedShouldBeCalled");
2622
#ifdef REPORT_RESULT
2723
REPORT_RESULT(testSucceeded);
2824
#endif
2925
}
3026

3127
int main()
3228
{
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");
3430
ATOMICS_WAIT_TOKEN_T ret = emscripten_atomic_wait_async((int32_t*)&addr, 1, asyncWaitFinishedShouldNotBeCalled, (void*)42, EMSCRIPTEN_WAIT_ASYNC_INFINITY);
3531
assert(EMSCRIPTEN_IS_VALID_WAIT_TOKEN(ret));
3632

37-
console_log("Canceling an async wait should succeed");
33+
emscripten_console_log("Canceling an async wait should succeed");
3834
EMSCRIPTEN_RESULT r = emscripten_atomic_cancel_wait_async(ret);
3935
assert(r == EMSCRIPTEN_RESULT_SUCCESS);
4036

41-
console_log("Canceling an async wait a second time should give invalid param");
37+
emscripten_console_log("Canceling an async wait a second time should give invalid param");
4238
r = emscripten_atomic_cancel_wait_async(ret);
4339
assert(r == EMSCRIPTEN_RESULT_INVALID_PARAM);
4440

45-
console_log("Notifying an async wait should not trigger the callback function");
41+
emscripten_console_log("Notifying an async wait should not trigger the callback function");
4642
int64_t numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
4743

48-
console_log("Notifying an async wait should return 0 threads woken");
44+
emscripten_console_log("Notifying an async wait should return 0 threads woken");
4945
assert(numWoken == 0);
5046

5147
addr = 2;
52-
console_log("Notifying an async wait even after changed value should not trigger the callback function");
48+
emscripten_console_log("Notifying an async wait even after changed value should not trigger the callback function");
5349
numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
5450

55-
console_log("Notifying an async wait should return 0 threads woken");
51+
emscripten_console_log("Notifying an async wait should return 0 threads woken");
5652
assert(numWoken == 0);
5753

58-
console_log("Async waiting on address should give a wait token");
54+
emscripten_console_log("Async waiting on address should give a wait token");
5955
ret = emscripten_atomic_wait_async((int32_t*)&addr, 2, asyncWaitFinishedShouldBeCalled, (void*)42, EMSCRIPTEN_WAIT_ASYNC_INFINITY);
6056
assert(EMSCRIPTEN_IS_VALID_WAIT_TOKEN(ret));
6157

6258
#if 0
63-
console_log("Notifying an async wait without value changing should still trigger the callback");
59+
emscripten_console_log("Notifying an async wait without value changing should still trigger the callback");
6460
numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
6561
assert(numWoken == 1);
6662
#else
6763
// TODO: Switch to the above test instead after the Atomics.waitAsync() polyfill is dropped.
6864
addr = 3;
69-
console_log("Notifying an async wait after value changing should trigger the callback");
65+
emscripten_console_log("Notifying an async wait after value changing should trigger the callback");
7066
numWoken = emscripten_wasm_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
7167
#endif
7268
}

test/wasm_worker/lock_async_acquire.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
// Tests emscripten_lock_async_acquire() function.
88

9-
EM_JS(void, console_log, (char* str), {
10-
console.log(UTF8ToString(str));
11-
});
12-
139
emscripten_lock_t lock = EMSCRIPTEN_LOCK_T_STATIC_INITIALIZER;
1410

1511
// Two shared variables, always a delta distance of one from each other.
@@ -23,7 +19,7 @@ int numTimesWasmWorkerAcquiredLock = 0;
2319

2420
void work()
2521
{
26-
// console_log("work");
22+
// emscripten_console_log("work");
2723
volatile int x = sharedState0;
2824
volatile int y = sharedState1;
2925
assert(x == y+1 || y == x+1);
@@ -51,7 +47,7 @@ void work()
5147
{
5248
if (!testFinished)
5349
{
54-
console_log("test finished");
50+
emscripten_console_log("test finished");
5551
#ifdef REPORT_RESULT
5652
REPORT_RESULT(0);
5753
#endif
@@ -65,7 +61,7 @@ void schedule_work(void *userData);
6561

6662
void lock_async_acquired(volatile void *addr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData)
6763
{
68-
// console_log("async lock acquired");
64+
// emscripten_console_log("async lock acquired");
6965
assert(addr == &lock);
7066
assert(val == 0 || val == 1);
7167
assert(waitResult == ATOMICS_WAIT_OK);
@@ -82,7 +78,7 @@ void schedule_work(void *userData)
8278
if (emscripten_current_thread_is_wasm_worker() && emscripten_random() > 0.5)
8379
{
8480
emscripten_lock_waitinf_acquire(&lock);
85-
// console_log("sync lock acquired");
81+
// emscripten_console_log("sync lock acquired");
8682
work();
8783
emscripten_lock_release(&lock);
8884
if (!testFinished)

test/wasm_worker/lock_wait_acquire2.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,34 @@
66

77
// Tests emscripten_lock_wait_acquire() between two Wasm Workers.
88

9-
EM_JS(void, console_log, (char* str), {
10-
console.log(UTF8ToString(str));
11-
});
12-
139
emscripten_lock_t lock = EMSCRIPTEN_LOCK_T_STATIC_INITIALIZER;
1410

1511
void worker1_main()
1612
{
17-
console_log("worker1 main try_acquiring lock");
13+
emscripten_console_log("worker1 main try_acquiring lock");
1814
EM_BOOL success = emscripten_lock_try_acquire(&lock); // Expect no contention on free lock.
19-
console_log("worker1 try_acquire lock finished");
15+
emscripten_console_log("worker1 try_acquire lock finished");
2016
assert(success);
21-
console_log("worker1 try_acquire lock success, sleeping 1000 msecs");
17+
emscripten_console_log("worker1 try_acquire lock success, sleeping 1000 msecs");
2218
emscripten_wasm_worker_sleep(1000 * 1000000ull);
2319

24-
console_log("worker1 slept 1000 msecs, releasing lock");
20+
emscripten_console_log("worker1 slept 1000 msecs, releasing lock");
2521
emscripten_lock_release(&lock);
26-
console_log("worker1 released lock");
22+
emscripten_console_log("worker1 released lock");
2723
}
2824

2925
void worker2_main()
3026
{
31-
console_log("worker2 main sleeping 500 msecs");
27+
emscripten_console_log("worker2 main sleeping 500 msecs");
3228
emscripten_wasm_worker_sleep(500 * 1000000ull);
33-
console_log("worker2 slept 500 msecs, try_acquiring lock");
29+
emscripten_console_log("worker2 slept 500 msecs, try_acquiring lock");
3430
EM_BOOL success = emscripten_lock_try_acquire(&lock); // At this time, the other thread should have the lock.
35-
console_log("worker2 try_acquire lock finished");
31+
emscripten_console_log("worker2 try_acquire lock finished");
3632
assert(!success);
3733

3834
// Wait enough time to cover over the time that the other thread held the lock.
3935
success = emscripten_lock_wait_acquire(&lock, 2000 * 1000000ull);
40-
console_log("worker2 wait_acquired lock");
36+
emscripten_console_log("worker2 wait_acquired lock");
4137
assert(success);
4238

4339
#ifdef REPORT_RESULT

test/wasm_worker/malloc_wasm_worker.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44

55
// Test emscripten_malloc_wasm_worker() and emscripten_current_thread_is_wasm_worker() functions
66

7-
EM_JS(void, console_log, (char* str), {
8-
console.log(UTF8ToString(str));
9-
});
10-
117
void worker_main()
128
{
13-
console_log("Hello from wasm worker!");
9+
emscripten_console_log("Hello from wasm worker!");
1410
assert(emscripten_current_thread_is_wasm_worker());
1511
#ifdef REPORT_RESULT
1612
REPORT_RESULT(0);

0 commit comments

Comments
 (0)