Skip to content

Commit

Permalink
add control flow tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Nov 1, 2015
1 parent 0da541c commit dd26c6d
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
2 changes: 2 additions & 0 deletions check.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def fail(actual, expected):
if post:
open('a.normal.js', 'a').write(post)
open('a.wasm.js', 'a').write(post)
else:
print ' (no post)'
for which in ['normal', 'wasm']:
print '....', which
proc = subprocess.Popen(['nodejs', 'a.' + which + '.js'], stdout=subprocess.PIPE)
Expand Down
47 changes: 47 additions & 0 deletions test/control_flow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <cmath>
#include <algorithm>
#include <emscripten.h>

extern "C" {

int EMSCRIPTEN_KEEPALIVE check_if(int x) {
if (x < 10) x++;
return x;
}

int EMSCRIPTEN_KEEPALIVE check_loop(int x) {
while (x < 100) x *= 2;
return x;
}

int EMSCRIPTEN_KEEPALIVE check_loop_break(int x) {
while (x < 100) {
x *= 2;
if (x > 30) break;
x++;
}
return x;
}

int EMSCRIPTEN_KEEPALIVE check_loop_continue(int x) {
while (x < 100) {
x *= 2;
if (x > 30) continue;
x++;
}
return x;
}

int EMSCRIPTEN_KEEPALIVE check_do_loop(int x) {
do {
x *= 2;
if (x > 1000) break;
x--;
if (x > 30) continue;
x++;
} while (x < 100);
return x;
}

}

1 change: 1 addition & 0 deletions test/control_flow.emcc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["-s", "ASSERTIONS=0"]
20 changes: 20 additions & 0 deletions test/control_flow.post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

function test(name) {
Module.print(name);
function doTest(x) {
Module.print(' ' + [x] + ' ==> ' + Module['_check_' + name](x));
}
doTest(1);
doTest(2);
doTest(3);
doTest(4);
doTest(11);
doTest(90);
}

test('if');
test('loop');
test('loop_break');
test('loop_continue');
test('do_loop');

35 changes: 35 additions & 0 deletions test/control_flow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
if
1 ==> 2
2 ==> 3
3 ==> 4
4 ==> 5
11 ==> 11
90 ==> 90
loop
1 ==> 128
2 ==> 128
3 ==> 192
4 ==> 128
11 ==> 176
90 ==> 180
loop_break
1 ==> 62
2 ==> 46
3 ==> 62
4 ==> 38
11 ==> 46
90 ==> 180
loop_continue
1 ==> 124
2 ==> 184
3 ==> 124
4 ==> 152
11 ==> 184
90 ==> 180
do_loop
1 ==> 121
2 ==> 121
3 ==> 185
4 ==> 121
11 ==> 169
90 ==> 179

0 comments on commit dd26c6d

Please sign in to comment.