Skip to content

Commit 04a61db

Browse files
committed
Convert more btests to btest_exit. NFC
There are still many more to convert.. perhaps we should be more systematic about it.
1 parent 0195e98 commit 04a61db

33 files changed

+173
-249
lines changed

src/library.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3667,7 +3667,8 @@ LibraryManager.library = {
36673667
#endif
36683668
_exit(EXITSTATUS);
36693669
} catch (e) {
3670-
if (e instanceof ExitStatus) {
3670+
// These are expected so we don't re-throw them.
3671+
if (e instanceof ExitStatus || e == 'unwind') {
36713672
return;
36723673
}
36733674
throw e;
Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
#include <emscripten/html5.h>
22
#include <stdio.h>
3+
#include <stdlib.h>
34

4-
void timeout(void *userData)
5-
{
6-
printf("Got timeout handler\n");
7-
#ifdef REPORT_RESULT
8-
// Test passed
9-
REPORT_RESULT(1);
10-
#endif
5+
void timeout(void *userData) {
6+
printf("Got timeout handler\n");
7+
// Test passed
8+
exit(0);
119
}
1210

13-
int main()
14-
{
15-
emscripten_set_timeout(timeout, 2000, 0);
16-
emscripten_unwind_to_js_event_loop();
17-
printf("This should not be called!\n");
18-
#ifdef REPORT_RESULT
19-
// Should not reach here
20-
REPORT_RESULT(-1);
21-
#endif
11+
int main() {
12+
emscripten_set_timeout(timeout, 2000, 0);
13+
emscripten_unwind_to_js_event_loop();
14+
printf("This should not be called!\n");
15+
// Should not reach here
16+
return 99;
2217
}

tests/canvas_animate_resize.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ void tick()
8181
emscripten_webgl_make_context_current(0);
8282
emscripten_webgl_destroy_context(ctx);
8383
printf("quit\n");
84-
#ifdef REPORT_RESULT
85-
REPORT_RESULT(1);
86-
#endif
8784
exit(0);
8885
}
8986
}
@@ -154,4 +151,5 @@ int main()
154151
usleep(16*1000);
155152
}
156153
#endif
154+
return 99;
157155
}

tests/cstdio/test_remove.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,5 @@ int main() {
6464
atexit(cleanup);
6565
setup();
6666
test();
67-
68-
#ifdef REPORT_RESULT
69-
REPORT_RESULT(0);
70-
#endif
71-
return EXIT_SUCCESS;
67+
return 0;
7268
}

tests/emscripten_api_browser.cpp renamed to tests/emscripten_api_browser.c

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

6+
#include <stdbool.h>
67
#include <stdio.h>
78
#include <math.h>
89
#include <stdlib.h>
910
#include <SDL.h>
1011
#include <emscripten.h>
1112
#include <assert.h>
1213

14+
bool exit_ok = false;
1315
int last = 0;
1416

15-
extern "C" {
16-
1717
bool pre1ed = false;
1818
bool pre2ed = false;
1919
void pre1(void *arg) {
@@ -43,7 +43,8 @@ void argey(void* arg) {
4343
printf("argey: %d\n", counter);
4444
if (counter == 5) {
4545
emscripten_cancel_main_loop();
46-
REPORT_RESULT(1);
46+
exit_ok = true;
47+
exit(0);
4748
}
4849
}
4950

@@ -75,22 +76,20 @@ void four(void *arg) {
7576
void __attribute__((used)) third() {
7677
int now = SDL_GetTicks();
7778
printf("thard! %d\n", now);
78-
assert(fabs(now - last - 1000) < 500);
79+
assert(abs(now - last - 1000) < 500);
7980
emscripten_async_call(four, (void*)43, -1); // triggers requestAnimationFrame
8081
}
8182

8283
void second(void *arg) {
8384
int now = SDL_GetTicks();
8485
printf("sacond! %d\n", now);
85-
assert(fabs(now - last - 500) < 250);
86+
assert(abs(now - last - 500) < 250);
8687
last = now;
8788
emscripten_async_run_script("Module._third()", 1000);
8889
}
8990

90-
}
91-
92-
void never() {
93-
REPORT_RESULT(0);
91+
void check_exit_ok() {
92+
assert(exit_ok == true);
9493
}
9594

9695
int main() {
@@ -105,7 +104,7 @@ int main() {
105104

106105
assert(ratio == ratio2);
107106

108-
atexit(never); // should never be called - it is wrong to exit the runtime orderly if we have async calls!
107+
atexit(check_exit_ok);
109108

110109
emscripten_async_call(second, (void*)0, 500);
111110

tests/emscripten_api_browser2.cpp renamed to tests/emscripten_api_browser2.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
// found in the LICENSE file.
55

66
#include <stdio.h>
7+
#include <stdlib.h>
78
#include <string.h>
89
#include <assert.h>
910

1011
#include <emscripten.h>
1112

1213
int value = 0;
1314

14-
extern "C" {
15-
void set(int x) {
16-
printf("set! %d\n", x);
17-
value = x;
18-
}
15+
void set(int x) {
16+
printf("set! %d\n", x);
17+
value = x;
1918
}
2019

2120
void load2() {
@@ -34,8 +33,9 @@ void load2() {
3433
fclose(f);
3534
assert(strcmp(buffer, "second") == 0);
3635

37-
REPORT_RESULT(1);
36+
exit(0);
3837
}
38+
3939
void error2() {
4040
printf("fail2\n");
4141
}
@@ -45,13 +45,12 @@ void load1() {
4545
assert(value == 456);
4646
emscripten_async_load_script("script2.js", load2, error2);
4747
}
48+
4849
void error1() {
4950
printf("fail1\n");
5051
}
5152

5253
int main() {
5354
emscripten_async_load_script("script1.js", load1, error1);
54-
55-
return 1;
55+
return 99;
5656
}
57-

tests/emscripten_api_browser_infloop.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// found in the LICENSE file.
55

66
#include <stdio.h>
7+
#include <stdlib.h>
78
#include <string.h>
89
#include <emscripten.h>
910

@@ -19,8 +20,8 @@ struct Class {
1920
printf("waka %d\n", x++);
2021

2122
if (x == 7 || x < 0) {
22-
REPORT_RESULT(x);
2323
emscripten_cancel_main_loop();
24+
exit(x);
2425
}
2526
}
2627

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
#include <assert.h>
12
#include <stdio.h>
23
#include <emscripten/emscripten.h>
34

4-
int main()
5-
{
6-
double devicePixelRatio = emscripten_get_device_pixel_ratio();
7-
printf("window.devicePixelRatio = %f.\n", devicePixelRatio);
8-
int result = (devicePixelRatio > 0) ? 1 : 0;
9-
if (result) {
10-
printf("Test succeeded!\n");
11-
}
12-
#ifdef REPORT_RESULT
13-
REPORT_RESULT(result);
14-
#endif
5+
int main() {
6+
double devicePixelRatio = emscripten_get_device_pixel_ratio();
7+
printf("window.devicePixelRatio = %f.\n", devicePixelRatio);
8+
assert(devicePixelRatio > 0);
9+
int result = (devicePixelRatio > 0) ? 1 : 0;
10+
if (result) {
11+
printf("Test succeeded!\n");
12+
return 0;
13+
}
14+
return 1;
1515
}

tests/emscripten_main_loop.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ int frame = 0;
1313

1414
void final(void*) {
1515
assert(frame == 110);
16-
#ifdef REPORT_RESULT
1716
printf("Test passed.\n");
18-
REPORT_RESULT(0);
19-
#endif
17+
exit(0);
2018
}
2119

2220
void looper() {
@@ -29,11 +27,8 @@ void looper() {
2927
timesTooSoon++;
3028
if (timesTooSoon >= 10) {
3129
printf("Abort: main loop tick was called too quickly after the previous frame, too many times!\n");
32-
#ifdef REPORT_RESULT
33-
REPORT_RESULT(1);
34-
#endif
3530
emscripten_cancel_main_loop();
36-
exit(0);
31+
exit(1);
3732
}
3833
}
3934
prevTime = curTime;
@@ -42,11 +37,8 @@ void looper() {
4237
timesTooSoon++;
4338
if (timesTooSoon >= 2) {
4439
printf("Abort: With swap interval of 4, we should be running at most 15fps! (or 30fps on 120Hz displays) but seems like swap control is not working and we are running at 60fps!\n");
45-
#ifdef REPORT_RESULT
46-
REPORT_RESULT(2);
47-
#endif
4840
emscripten_cancel_main_loop();
49-
exit(0);
41+
exit(2);
5042
}
5143
}
5244
if (frame > 0 && frame < 90 && frame % 10 == 0) {
@@ -79,4 +71,5 @@ void looper() {
7971

8072
int main() {
8173
emscripten_set_main_loop(looper, 5, 1);
74+
return 99;
8275
}

tests/emscripten_main_loop_and_blocker.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@ bool blockerExecuted = false;
1414

1515
void final(void*) {
1616
assert(frame == 20);
17-
#ifdef REPORT_RESULT
18-
REPORT_RESULT(0);
19-
#else
2017
exit(0);
21-
#endif
2218
}
2319

2420
void looper() {
2521
if (blockerExecuted == false) {
26-
#ifdef REPORT_RESULT
27-
REPORT_RESULT(1);
28-
#else
2922
exit(1);
30-
#endif
3123
}
3224

3325
frame++;

0 commit comments

Comments
 (0)