git ssb

0+

wanderer🌟 / js-primea-wasm-container



Commit d48b7065a388045f96fc7be1588e12150b8de8bb

added reinternalize tests

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 4/1/2018, 8:31:04 PM
Parent: f019f1d8c91c4a7427df520e819cf78f0fdd7a77

Files changed

tests/index.jschanged
tests/wasm/reinternalize.wasmadded
tests/wast/reinternalize.jsonadded
tests/wast/reinternalize.wastadded
typeCheckWrapper.jschanged
tests/index.jsView
@@ -55,8 +55,29 @@
5555 })
5656 hypervisor.send(message)
5757 })
5858
59+tape('reintinalizing', async t => {
60+ t.plan(1)
61+ tester = t
62+ const tree = new RadixTree({db})
63+ let wasm = fs.readFileSync(WASM_PATH + '/reinternalize.wasm')
64+
65+ const hypervisor = new Hypervisor(tree)
66+ hypervisor.registerContainer(TestWasmContainer)
67+
68+ const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm)
69+ const funcRef = module.getFuncRef('main')
70+ funcRef.gas = 322000
71+
72+ const message = new Message({
73+ funcRef
74+ }).on('execution:error', e => {
75+ console.log(e)
76+ })
77+ hypervisor.send(message)
78+})
79+
5980 tape('basic', async t => {
6081 t.plan(1)
6182 tester = t
6283
@@ -83,8 +104,9 @@
83104 // const stateRoot = await hypervisor.createStateRoot()
84105 // t.deepEquals(stateRoot, expectedState, 'expected root!')
85106 })
86107
108+
87109 tape('empty', async t => {
88110 t.plan(1)
89111 tester = t
90112 const expectedState = Buffer.from('bb15867b26293aa36c774b8c82541dd64212ba9a', 'hex')
tests/wasm/reinternalize.wasmView
@@ -1,0 +1,2 @@
1+asm types`~m typeMap!```````~tfunc internalizefunc externalizetestchecktestprintmoduleselfmoduleexportmemory externalizep$memorytablemaincallback
2+5%AAA"AAB A A �  A callback
tests/wast/reinternalize.jsonView
@@ -1,0 +1,13 @@
1+{
2+ "types": [{
3+ "form": "func",
4+ "params": [
5+ "i64",
6+ "data"
7+ ]
8+ }],
9+ "typeMap": [{
10+ "func": 1,
11+ "type": 0
12+ }]
13+}
tests/wast/reinternalize.wastView
@@ -1,0 +1,37 @@
1+(module
2+ (import "func" "internalize" (func $func.internalize (param i32 i32)))
3+ (import "func" "externalize" (func $func.externalize (param i32) (result i32)))
4+ (import "test" "check" (func $check (param i32 i32)))
5+ (import "test" "print" (func $print (param i32)))
6+ (import "module" "self" (func $self (result i32)))
7+ (import "module" "export" (func $exports (param i32 i32) (result i32)))
8+ (import "memory" "externalize" (func $mem.externalize (param i32 i32) (result i32)))
9+ (memory (export "memory") 1)
10+ (data (i32.const 0) "callback")
11+ (table (export "table") 1 1 anyfunc)
12+ (func $main
13+ (local i32)
14+ (call $func.internalize
15+ (i32.const 0)
16+ (call $exports
17+ (call $self)
18+ (tee_local 0
19+ (call $mem.externalize (i32.const 0) (i32.const 8)))))
20+
21+ ;; reinternalize
22+ (call $func.internalize
23+ (i32.const 0)
24+ (call $func.externalize (i32.const 0)))
25+
26+ (call_indirect (param i64 i32)
27+ (i64.const 8)
28+ (get_local 0)
29+ (i32.const 0)))
30+
31+ (func $callback (param i64) (param i32)
32+ (call $check
33+ (i32.const 8)
34+ (i32.wrap/i64 (get_local 0)))
35+ (call $print (get_local 1)))
36+ (export "main" (func $main))
37+ (export "callback" (func $callback)))
typeCheckWrapper.jsView
@@ -187,15 +187,8 @@
187187 }
188188 }
189189 }
190190
191-function typeEntry (params = []) {
192- return {
193- form: 'func',
194- params: params
195- }
196-}
197-
198191 function end () {
199192 return {
200193 name: 'end'
201194 }
@@ -207,22 +200,8 @@
207200 immediates: index
208201 }
209202 }
210203
211-function get_global (index) {
212- return {
213- name: 'get_global',
214- immediates: index
215- }
216-}
217-
218-function set_global (index) {
219- return {
220- name: 'set_global',
221- immediates: index
222- }
223-}
224-
225204 function i32_const (num) {
226205 return {
227206 'return_type': 'i32',
228207 'name': 'const',
@@ -237,19 +216,8 @@
237216 'immediates': num
238217 }
239218 }
240219
241-function i32_store () {
242- return {
243- 'return_type': 'i32',
244- 'name': 'store',
245- 'immediates': {
246- 'flags': 2,
247- 'offset': 0
248- }
249- }
250-}
251-
252220 function shr_u() {
253221 return {
254222 'return_type': 'i64',
255223 'name': 'shr_u'

Built with git-ssb-web