Skip to content

Commit 519986b

Browse files
authored
More emscripten_out/err use in test code. NFC (#19972)
Some instances that I missed in #19524
1 parent 6b6f7e7 commit 519986b

7 files changed

+32
-36
lines changed

test/core/test_asyncify_during_exit.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33

4-
#include <emscripten.h>
4+
#include <emscripten/emscripten.h>
5+
#include <emscripten/console.h>
56

67
void during_exit() {
78
// An attempt to sleep during exit, which is not allowed (the exit process is
89
// done in synchronous JS).
9-
EM_ASM({ out("during_exit 1") });
10+
emscripten_out("during_exit 1");
1011
#ifndef NO_ASYNC
1112
emscripten_sleep(100);
1213
#endif
13-
EM_ASM({ out("during_exit 2") });
14+
emscripten_out("during_exit 2");
1415
}
1516

1617
int main() {

test/core/test_dlmalloc_partial_2.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
#include <stdio.h>
99
#include <stdlib.h>
10-
#include <emscripten.h>
10+
#include <emscripten/console.h>
11+
1112
void *malloc(size_t size) { return (void *)123; }
1213
int main() {
1314
void *x = malloc(10);
14-
EM_ASM({ out("got 0x" + $0.toString(16)) }, x);
15+
emscripten_outf("got %p", x);
1516
free(0);
16-
EM_ASM({ out("freed a fake") });
17+
emscripten_outf("freed a fake");
1718
return 1;
1819
}

test/core/test_embind_5.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// University of Illinois/NCSA Open Source License. Both these licenses can be
44
// found in the LICENSE file.
55

6-
#include <emscripten.h>
6+
#include <emscripten/em_asm.h>
7+
#include <emscripten/console.h>
78
#include <emscripten/bind.h>
89

910
using namespace emscripten;
@@ -12,26 +13,26 @@ using namespace emscripten;
1213
class MyFoo {
1314
public:
1415
MyFoo() {
15-
EM_ASM({out("constructing my foo");});
16+
emscripten_out("constructing my foo");
1617
}
1718
virtual void doit() {
18-
EM_ASM({out("doing it");});
19+
emscripten_out("doing it");
1920
}
2021
virtual ~MyFoo() {
21-
EM_ASM({out("destructing my foo");});
22+
emscripten_out("destructing my foo");
2223
}
2324
};
2425

2526
class MyBar : public MyFoo {
2627
public:
2728
MyBar() {
28-
EM_ASM({out("constructing my bar");});
29+
emscripten_out("constructing my bar");
2930
}
3031
void doit() override {
31-
EM_ASM({out("doing something else");});
32+
emscripten_out("doing something else");
3233
}
3334
virtual ~MyBar() override {
34-
EM_ASM({out("destructing my bar");});
35+
emscripten_out("destructing my bar");
3536
}
3637
};
3738

test/other/test_pthread_out_err.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
#include <stdio.h>
2-
#include <emscripten/em_asm.h>
3-
4-
void out(const char* msg) {
5-
EM_ASM({ out(UTF8ToString($0)); }, msg);
6-
}
7-
8-
void err(const char* msg) {
9-
EM_ASM({ err(UTF8ToString($0)); }, msg);
10-
}
2+
#include <emscripten/console.h>
113

124
// Test that stdout/printf and emscripten JS logging functions (out()
135
// and err()) are interleaved as expected and all arrive at the console.
146
// See https://github.com/emscripten-core/emscripten/issues/14804
157
int main() {
16-
printf("printf 1\n");
17-
out ("out 1");
18-
err ("err 1");
19-
printf("printf 2\n");
20-
out ("out 2");
21-
err ("err 2");
22-
printf("printf 3\n");
23-
out ("out 3");
24-
err ("err 3");
8+
printf ("printf 1\n");
9+
emscripten_out("out 1");
10+
emscripten_err("err 1");
11+
printf ("printf 2\n");
12+
emscripten_out("out 2");
13+
emscripten_err("err 2");
14+
printf ("printf 3\n");
15+
emscripten_out("out 3");
16+
emscripten_err("err 3");
2517
printf("done\n");
2618
return 0;
2719
}

test/pthread/test_pthread_create.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void *ThreadMain(void *arg)
4949
int numGood = 0;
5050
for(unsigned int i = 0; i < N; ++i)
5151
if (n[i] == i) ++numGood;
52-
else EM_ASM(err('n['+$0+']='+$1), i, n[i]);
52+
else emscripten_errf("n[%d]=%d", i, n[i]);
5353

5454
emscripten_outf("Thread idx %ld with param %d: all done with result %d.", idx, param, numGood);
5555
pthread_exit((void*)numGood);
@@ -84,7 +84,7 @@ int main()
8484
int status;
8585
int rc = pthread_join(thread[i], (void**)&status);
8686
assert(rc == 0);
87-
EM_ASM(err('Main: Joined thread idx ' + $0 + ' (param ' + $1 + ') with status ' + $2), i, global_shared_data[i], (int)status);
87+
emscripten_errf("Main: Joined thread idx %d (param %d) with status %d", i, global_shared_data[i], (int)status);
8888
assert(status == N);
8989
thread[i] = 0;
9090
if (numThreadsToCreate > 0)

test/pthread/test_pthread_sbrk.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <pthread.h>
77
#include <emscripten.h>
8+
#include <emscripten/console.h>
89
#include <assert.h>
910
#include <stdlib.h>
1011
#include <stdio.h>
@@ -72,7 +73,7 @@ static void *thread_start(void *arg)
7273
{
7374
++return_code; // Failed! (but run to completion so that the barriers will all properly proceed without hanging)
7475
if (!reported_once) {
75-
EM_ASM(err('Memory corrupted! mem[i]: ' + $0 + ' != ' + $1 + ', i: ' + $2 + ', j: ' + $3), allocated_buffers[i][j], id, i, j);
76+
emscripten_errf("Memory corrupted! mem[i]: %d != %d, i: %d, j: %d", allocated_buffers[i][j], id, i, j);
7677
reported_once = 1; // Avoid print flood that makes debugging hard.
7778
}
7879
}

test/pthread/test_pthread_thread_local_storage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void *ThreadMain(void *arg)
2525
for(int i = 0; i < NUM_KEYS; ++i)
2626
{
2727
local_keys[i] = (uintptr_t)pthread_getspecific(keys[i]);
28-
// EM_ASM(err('Thread ' + $0 + ': Read value ' + $1 + ' from TLS for key at index ' + $2), pthread_self(), (int)local_keys[i], i);
28+
// emscripten_errf("Thread %d: Read value %d from TLS for key at index %d", pthread_self(), (int)local_keys[i], i);
2929
}
3030

3131
for(int i = 0; i < NUM_KEYS; ++i)
@@ -38,7 +38,7 @@ void *ThreadMain(void *arg)
3838
for(int i = 0; i < NUM_KEYS; ++i)
3939
{
4040
local_keys[i] = (uintptr_t)pthread_getspecific(keys[i]);
41-
// EM_ASM(err('Thread ' + $0 + ' final verify: Read value ' + $1 + ' from TLS for key at index ' + $2), pthread_self(), (int)local_keys[i], i);
41+
// emscripten_errf("Thread %d final verify: Read value %d from TLS for key at index %d", pthread_self(), (int)local_keys[i], i);
4242
assert(local_keys[i] == NUM_ITERS);
4343
}
4444
return 0;

0 commit comments

Comments
 (0)