Skip to content

Commit bb233ad

Browse files
authored
Make more use of emscripten_out/emscripten_err in test code. NFC (#19524)
Using these emscripten wrappers has some advantages. In particular, with workers we have seen issues with writes to console.log/console.error being lost in some cases.
1 parent cdfc80c commit bb233ad

37 files changed

+261
-258
lines changed

test/core/test_em_asm.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int main() {
1212

1313
unsigned long p = 8;
1414
EM_ASM({
15-
console.log("int types:");
15+
out("int types:");
1616
out(" char : " + $0);
1717
out(" signed char : " + $1);
1818
out("unsigned char : " + $2);
@@ -71,35 +71,35 @@ int main() {
7171

7272
// Test mixing ints and doubles
7373
EM_ASM({
74-
console.log("idii");
74+
out("idii");
7575
out("a " + $0);
7676
out("b " + $1);
7777
out("c " + $2);
7878
out("d " + $3);
7979
}, 1, 3.14159, 3, 4);
8080
EM_ASM({
81-
console.log("diii");
81+
out("diii");
8282
out("a " + $0);
8383
out("b " + $1);
8484
out("c " + $2);
8585
out("d " + $3);
8686
}, 3.14159, 2, 3, 4);
8787
EM_ASM({
88-
console.log("iidi");
88+
out("iidi");
8989
out("a " + $0);
9090
out("b " + $1);
9191
out("c " + $2);
9292
out("d " + $3);
9393
}, 1, 2, 3.14159, 4);
9494
EM_ASM({
95-
console.log("ddii");
95+
out("ddii");
9696
out("a " + $0);
9797
out("b " + $1);
9898
out("c " + $2);
9999
out("d " + $3);
100100
}, 3.14159, 2.1828, 3, 4);
101101
EM_ASM({
102-
console.log("iddi");
102+
out("iddi");
103103
out("a " + $0);
104104
out("b " + $1);
105105
out("c " + $2);

test/core/test_em_asm_2.cpp

Lines changed: 92 additions & 92 deletions
Large diffs are not rendered by default.

test/core/test_em_asm_types.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int main(int argc, char **argv) {
1616
// Promotions of arrays, function/member pointers and objects implicitly
1717
// convertible to numbers are excluded because they will not be translated
1818
// to corresponding JS objects.
19-
#define TEST_TYPE(type, value) EM_ASM({console.log(#type, Number($0));}, (type)(value));
19+
#define TEST_TYPE(type, value) EM_ASM({out(#type, Number($0));}, (type)(value));
2020
TEST_TYPE(int*, 0);
2121
TEST_TYPE(float, 1.5f);
2222
TEST_TYPE(double, 2.5);
@@ -39,14 +39,14 @@ int main(int argc, char **argv) {
3939

4040
struct WithBitField w;
4141
w.x = 3;
42-
EM_ASM({ console.log('bit field', $0); }, w.x);
42+
EM_ASM({ out('bit field', $0); }, w.x);
4343

4444
#ifdef __cplusplus
4545
TEST_TYPE(bool, true);
4646
TEST_TYPE(wchar_t, 50);
4747
#else
48-
EM_ASM({console.log('bool 1')});
49-
EM_ASM({console.log('wchar_t 50')});
48+
EM_ASM({out('bool 1')});
49+
EM_ASM({out('wchar_t 50')});
5050
#endif
5151

5252
TEST_TYPE(enum SomeEnum, SIXTY);

test/core/test_em_js_i64.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#include <emscripten.h>
33

44
EM_JS(void, foo, (uint64_t a, int64_t b), {
5-
console.log(typeof a);
6-
console.log(typeof b);
5+
out(typeof a);
6+
out(typeof b);
77

8-
console.log('a:' + a);
9-
console.log('b:' + b);
8+
out('a:' + a);
9+
out('b:' + b);
1010
})
1111

1212
int main() {

test/core/test_get_exported_function.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#include <emscripten.h>
1+
#include <emscripten/emscripten.h>
2+
#include <emscripten/console.h>
23
#include <emscripten/exports.h>
34

45
extern "C" EMSCRIPTEN_KEEPALIVE int foo()
@@ -17,10 +18,10 @@ int main()
1718
{
1819
intfunc f = (intfunc)emscripten_get_exported_function("_foo");
1920
intfunc b = (intfunc)emscripten_get_exported_function("_bar");
20-
EM_ASM(console.log($0 + ' ' + $1), f(), b());
21+
emscripten_outf("%d %d", f(), b());
2122

2223
// Obtaining the same function pointer twice should return the
2324
// same address.
2425
intfunc b2 = (intfunc)emscripten_get_exported_function("_bar");
25-
EM_ASM(console.log($0), b == b2);
26+
emscripten_outf("%d", b == b2);
2627
}

test/embind/embind_jspi_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ EM_ASYNC_JS(void, test, (), {
9797
setTimeout(Module.unsuspend);
9898
await Module.suspend();
9999

100-
console.log('done');
100+
out('done');
101101
} catch (e) {
102-
console.log('Failed: ' + e.stack);
102+
out('Failed: ' + e.stack);
103103
}
104104
});
105105

test/embind/test_float_constants.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ EMSCRIPTEN_BINDINGS(constants) {
1919
}
2020

2121
int main() {
22-
EM_ASM(
23-
console.log("PI (as double) = " + Module['PI']);
24-
console.log("EULER = " + Module['EULER']);
25-
console.log("pi (as float) = " + Module['pi']);
26-
console.log("euler = " + Module['euler']);
27-
);
28-
}
22+
EM_ASM(
23+
out("PI (as double) = " + Module['PI']);
24+
out("EULER = " + Module['EULER']);
25+
out("pi (as float) = " + Module['pi']);
26+
out("euler = " + Module['euler']);
27+
);
28+
}

test/embind/test_negative_constants.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ EMSCRIPTEN_BINDINGS(constants) {
2222

2323
int main() {
2424
EM_ASM(
25-
console.log("NEGATIVE_FLOAT_NUM = " + Module['NEGATIVE_FLOAT_NUM']);
26-
console.log("NEGATIVE_INT_NUM = " + Module['NEGATIVE_INT_NUM']);
27-
console.log("negative_float_num = " + Module['negative_float_num']);
28-
console.log("negative_double_num = " + Module['negative_double_num']);
29-
console.log("negative_int_num = " + Module['negative_int_num']);
25+
out("NEGATIVE_FLOAT_NUM = " + Module['NEGATIVE_FLOAT_NUM']);
26+
out("NEGATIVE_INT_NUM = " + Module['NEGATIVE_INT_NUM']);
27+
out("negative_float_num = " + Module['negative_float_num']);
28+
out("negative_double_num = " + Module['negative_double_num']);
29+
out("negative_int_num = " + Module['negative_int_num']);
3030
);
31-
}
31+
}

test/fetch/sync_xhr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main()
1717
// If an exception is thrown from the user callback, it bubbles up to self.onerror but is otherwise completely
1818
// swallowed by xhr.send.
1919
EM_ASM({self.onerror = function() {
20-
console.log('Got error');
20+
out('Got error');
2121
HEAP32[$0 >> 2] = 2;
2222
};}, &result);
2323
emscripten_fetch_attr_t attr;

test/pthread/hello_thread.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
#include <pthread.h>
99
#include <emscripten.h>
10-
#include <emscripten/html5.h>
10+
#include <emscripten/console.h>
1111

1212
void *thread_main(void *arg)
1313
{
14-
EM_ASM(out('hello from thread!'));
14+
emscripten_out("hello from thread!");
1515
emscripten_force_exit(0);
1616
__builtin_trap();
1717
}

0 commit comments

Comments
 (0)