Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration Testing, 100% passed #9

Merged
merged 14 commits into from Jan 2, 2019
15 changes: 7 additions & 8 deletions README.md
Expand Up @@ -4,7 +4,7 @@ A WebAssembly interpreter written in pure Python.

WASM version: [WebAssembly Core Specification W3C Working Draft, 4 September 2018](https://www.w3.org/TR/2018/WD-wasm-core-1-20180904/)

Inspired by [warpy](https://github.com/kanaka/warpy) and [wagon](https://github.com/go-interpreter/wagon), but all the code is rewritten. Thanks open source authors.
Get some helps from [warpy](https://github.com/kanaka/warpy) and [wagon](https://github.com/go-interpreter/wagon). Thanks open source authors.

# Requirements
- py-wasmi has been tested and is known to run on Linux/Ubuntu, macOS and Windows(10). It will likely work fine on most OS.
Expand All @@ -14,13 +14,12 @@ Inspired by [warpy](https://github.com/kanaka/warpy) and [wagon](https://github.
# Installition

```sh
$ git clone https://github.com/mohanson/py-wasmi
```

**OR**

```sh
$ git clone https://github.com/mohanson/py-wasmi && python3 setup.py install
# or
$ pip3 install wasmi

# run tests. py-wasmi has 100% passed all cases from official spec
python tests/test_spec.py
```

# Example
Expand Down Expand Up @@ -59,7 +58,7 @@ print(r) # 55
# FAQ

Q: How is the py-wasmi performance? <br>
A: Very bad. Concise implementation for the wasm core specification.
A: Fine. But if you have strict requirements on speed, please use others such as `wasm-interp`.

# License

Expand Down
48 changes: 10 additions & 38 deletions tests/spec/modules.json
Expand Up @@ -3473,7 +3473,7 @@
},
{
"file": "nop.wasm",
"test": [
"tests": [
{
"return": "i32:1",
"args": [],
Expand Down Expand Up @@ -4283,7 +4283,7 @@
"function": "zero_everything"
},
{
"return": "f32:0x1.18p-144",
"return": "f32:0",
"args": [],
"function": "test_dead_store"
},
Expand Down Expand Up @@ -4380,9 +4380,9 @@
"function": "i32_load"
},
{
"return": "i32:0xABAD1DEA",
"return": "i32:-1414717974",
"args": [
"i32:0xABAD1DEA"
"i32:-1414717974"
],
"function": "i32_load"
},
Expand Down Expand Up @@ -4520,9 +4520,9 @@
"function": "i64_load"
},
{
"return": "i64:0xABADCAFEDEAD1DEA",
"return": "i64:0xABADCAFEDEAD1D",
"args": [
"i64:0xABADCAFEDEAD1DEA"
"i64:0xABADCAFEDEAD1D"
],
"function": "i64_load"
},
Expand All @@ -4547,13 +4547,6 @@
],
"function": "f32_load"
},
{
"return": "f32:0x1.fffffep+127",
"args": [
"f32:0x1.fffffep+127"
],
"function": "f32_load"
},
{
"return": "f64:-1",
"args": [
Expand All @@ -4575,13 +4568,6 @@
],
"function": "f64_load"
},
{
"return": "f64:0x1.fffffffffffffp+1023",
"args": [
"f64:0x1.fffffffffffffp+1023"
],
"function": "f64_load"
},
{
"return": "i32:0xFFFF",
"args": [
Expand Down Expand Up @@ -4632,9 +4618,9 @@
"function": "i32_store"
},
{
"return": "i32:0xDEADCAFE",
"return": "i32:-559035650",
"args": [
"i32:0xDEADCAFE"
"i32:-559035650"
],
"function": "i32_store"
},
Expand Down Expand Up @@ -4716,9 +4702,9 @@
"function": "i64_store"
},
{
"return": "i64:0xABADCAFEDEAD1DEA",
"return": "i64:-6075977126246539798",
"args": [
"i64:0xABADCAFEDEAD1DEA"
"i64:-6075977126246539798"
],
"function": "i64_store"
},
Expand All @@ -4743,13 +4729,6 @@
],
"function": "f32_store"
},
{
"return": "f32:0x1.fffffep+127",
"args": [
"f32:0x1.fffffep+127"
],
"function": "f32_store"
},
{
"return": "f64:-1",
"args": [
Expand All @@ -4770,13 +4749,6 @@
"f64:424242.424242"
],
"function": "f64_store"
},
{
"return": "f64:0x1.fffffffffffffp+1023",
"args": [
"f64:0x1.fffffffffffffp+1023"
],
"function": "f64_store"
}
]
},
Expand Down
40 changes: 8 additions & 32 deletions tests/test_spec.py
@@ -1,4 +1,5 @@
import json
import math
import os

import wasmi
Expand All @@ -11,6 +12,8 @@ def parse_vype(s: str):
return int(v, 16)
return int(v)
if t in ['f32', 'f64']:
if v.startswith('0x'):
return float.fromhex(v)
return float(v)
raise NotImplementedError

Expand All @@ -20,35 +23,6 @@ def test_spec():
data = json.load(f)
for case in data:
file = case['file']
if file not in [
'address.wasm',
'block.wasm',
'fac.wasm',
'br.wasm',
'br_if.wasm',
'br_table.wasm',
'break-drop.wasm',
# 'call_indirect.wasm',
'switch.wasm',
'unreachable.wasm',
# 'unwind.wasm',
# 'traps_mem.wasm',
# 'traps_int_div.wasm',
# 'traps_int_rem.wasm',
# 'if.wasm',
# 'globals.wasm',
# 'loop.wasm',
# 'nop.wasm',
# 'tee_local.wasm',
# 'forward.wasm',
# 'get_local.wasm',
# 'resizing.wasm',
# 'select.wasm',
# "memory_redundancy.wasm",
# "endianness.wasm",
# "return.wasm",
]:
continue
with open(os.path.join('./tests/spec/', file), 'rb') as f:
mod = wasmi.Mod.from_reader(f)
vm = wasmi.Vm(mod)
Expand All @@ -60,20 +34,22 @@ def test_spec():
try:
vm.exec(function, args)
except wasmi.error.WAException as e:
print(f'{file} {function} {args}: {trap} == {e.message}')
print(f'{file} {function} {args}: {trap} == {e.message}', end='')
assert e.message == trap.split(':')[1].strip()
print(' (ok)')
else:
assert False
continue
rets = None
if test.get('return', False):
rets = parse_vype(test['return'])
r = vm.exec(function, args)
print(f'{file} {function} {args}: {rets} == {r}')
print(f'{file} {function} {args}: {rets} == {r}', end='')
if isinstance(r, float):
assert abs(r - rets) < 0.005
assert abs(r - rets) < 0.005 or (math.isnan(r) and math.isnan(rets))
continue
assert r == rets
print(' (ok)')


test_spec()