summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-10-29 13:01:03 -0700
committerAlon Zakai <alonzakai@gmail.com>2015-10-29 13:03:46 -0700
commitd455c96f4d4b6289c6a75dd918d138de5129ef04 (patch)
treee1e181ca8b4b6cc90c020a66df338be36f5459c1
parent4fbd4f442a899e1c87cb1a60f52916339d42534c (diff)
downloadbinaryen-d455c96f4d4b6289c6a75dd918d138de5129ef04.tar.gz
binaryen-d455c96f4d4b6289c6a75dd918d138de5129ef04.tar.bz2
binaryen-d455c96f4d4b6289c6a75dd918d138de5129ef04.zip
add testing
-rw-r--r--README.md8
-rwxr-xr-xcheck.py21
-rw-r--r--test/hello_world.wasm13
3 files changed, 42 insertions, 0 deletions
diff --git a/README.md b/README.md
index b702cecef..2c2914b89 100644
--- a/README.md
+++ b/README.md
@@ -39,6 +39,14 @@ Limitations:
* WebAssembly lacks global variables, so `asm2wasm` maps them onto addresses in memory. This requires that you have some reserved space for those variables. You can do that with `emcc -s GLOBAL_BASE=1000`. We still need to write the code to copy the globals there.
* Emscripten emits asm.js and JavaScript, that work together using web APIs to do things like print, render, etc. Not sure if there is a way to test that full output yet.
+## Testing
+
+```
+./check.py
+```
+
+(or `python check.py`) will run `asm2wasm` on the testcases in `test/`, and verify their outputs.
+
## License & Contributing
Same as Emscripten: MIT license. This code is sync'ed with Emscripten's repo.
diff --git a/check.py b/check.py
new file mode 100755
index 000000000..62fa98e9f
--- /dev/null
+++ b/check.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+import os, subprocess, difflib
+
+print 'checking testcases...\n'
+
+for asm in os.listdir('test'):
+ if asm.endswith('.asm.js'):
+ print ' ', asm, ' ',
+ wasm = asm.replace('.asm.js', '.wasm')
+ actual, err = subprocess.Popen([os.path.join('bin', 'asm2wasm'), os.path.join('test', asm)], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
+ assert err == '', 'bad err:' + err
+ expected = open(os.path.join('test', wasm)).read()
+ if actual != expected:
+ raise Exception("Expected to have '%s' == '%s', diff:\n\n%s" % (
+ expected, actual,
+ limit_size(''.join([a.rstrip()+'\n' for a in difflib.unified_diff(x.split('\n'), y.split('\n'), fromfile='expected', tofile='actual')]))
+ ))
+ print 'OK'
+
+print '\nsuccess!'
diff --git a/test/hello_world.wasm b/test/hello_world.wasm
new file mode 100644
index 000000000..66dd61c42
--- /dev/null
+++ b/test/hello_world.wasm
@@ -0,0 +1,13 @@
+(module
+ (export $add "add" $add)
+ (func $add (param $x i32) (param $y i32) (result i32)
+ (block $topmost
+ (break $topmost
+ (i32.add
+ (get_local $x)
+ (get_local $y)
+ )
+ )
+ )
+ )
+)