diff options
-rwxr-xr-x | check.py | 2 | ||||
-rw-r--r-- | test/control_flow.cpp | 47 | ||||
-rw-r--r-- | test/control_flow.emcc | 1 | ||||
-rw-r--r-- | test/control_flow.post.js | 20 | ||||
-rw-r--r-- | test/control_flow.txt | 35 |
5 files changed, 105 insertions, 0 deletions
@@ -83,6 +83,8 @@ for c in tests: 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) diff --git a/test/control_flow.cpp b/test/control_flow.cpp new file mode 100644 index 000000000..9536d0504 --- /dev/null +++ b/test/control_flow.cpp @@ -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; +} + +} + diff --git a/test/control_flow.emcc b/test/control_flow.emcc new file mode 100644 index 000000000..40c421eee --- /dev/null +++ b/test/control_flow.emcc @@ -0,0 +1 @@ +["-s", "ASSERTIONS=0"] diff --git a/test/control_flow.post.js b/test/control_flow.post.js new file mode 100644 index 000000000..90349b051 --- /dev/null +++ b/test/control_flow.post.js @@ -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'); + diff --git a/test/control_flow.txt b/test/control_flow.txt new file mode 100644 index 000000000..e3ef200d9 --- /dev/null +++ b/test/control_flow.txt @@ -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 |