Commit d42f5bf9d7ad822c5a87be84d90bd79af0f4b715
add link test
wanderer committed on 4/3/2018, 5:16:16 AMParent: ebf9c8db29ed91f8c1969b8829b315aba47469fc
Files changed
index.js | changed |
tests/index.js | changed |
tests/wasm/storage.wasm | changed |
tests/wasm/link.wasm | added |
tests/wast/storage.wast | changed |
tests/wast/link.json | added |
tests/wast/link.wast | added |
index.js | ||
---|---|---|
@@ -61,8 +61,9 @@ | ||
61 | 61 | module.exports = class WasmContainer { |
62 | 62 | constructor (actor) { |
63 | 63 | this.actor = actor |
64 | 64 | this.refs = new ReferanceMap() |
65 | + this._opsQueue = Promise.resolve() | |
65 | 66 | } |
66 | 67 | |
67 | 68 | static createModule (wasm, id) { |
68 | 69 | if (!WebAssembly.validate(wasm)) { |
@@ -131,11 +132,14 @@ | ||
131 | 132 | const link = {'/': obj} |
132 | 133 | return self.refs.add(link, 'link') |
133 | 134 | }, |
134 | 135 | unwrap: async (ref, cb) => { |
135 | - const obj = self.refs.get(ref, 'link') | |
136 | - const promise = self.actor.tree.graph.tree(obj) | |
137 | - await self._opsQueue.push(promise) | |
136 | + const link = self.refs.get(ref, 'link') | |
137 | + const promise = self.actor.tree.graph.tree(link) | |
138 | + await self.pushOpsQueue(promise) | |
139 | + const obj = (await promise)['/'] | |
140 | + const linkRef = self.refs.add(obj, getType(obj)) | |
141 | + self.instance.exports.table.get(cb)(linkRef) | |
138 | 142 | } |
139 | 143 | }, |
140 | 144 | module: { |
141 | 145 | new: dataRef => { |
tests/index.js | ||
---|---|---|
@@ -402,4 +402,41 @@ | ||
402 | 402 | }).on('execution:error', e => console.log(e)) |
403 | 403 | |
404 | 404 | hypervisor.send(message2) |
405 | 405 | }) |
406 | + | |
407 | +tape('link', async t => { | |
408 | + tester = t | |
409 | + const tree = new RadixTree({db}) | |
410 | + let wasm = fs.readFileSync(WASM_PATH + '/link.wasm') | |
411 | + | |
412 | + const egress = new EgressDriver() | |
413 | + | |
414 | + egress.on('message', msg => { | |
415 | + t.equals(msg.funcArguments[0].toString(), 'hello world') | |
416 | + t.end() | |
417 | + }) | |
418 | + | |
419 | + const hypervisor = new Hypervisor(tree, [TestWasmContainer], [egress]) | |
420 | + | |
421 | + const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) | |
422 | + const funcRef = module.getFuncRef('main') | |
423 | + funcRef.gas = 322000 | |
424 | + | |
425 | + const message = new Message({ | |
426 | + funcRef | |
427 | + }) | |
428 | + | |
429 | + hypervisor.send(message) | |
430 | + | |
431 | + const funcRef2 = module.getFuncRef('load') | |
432 | + funcRef2.gas = 322000 | |
433 | + | |
434 | + await hypervisor.createStateRoot() | |
435 | + | |
436 | + const message2 = new Message({ | |
437 | + funcRef: funcRef2, | |
438 | + funcArguments: [new FunctionRef({actorID: egress.id, params: ['data']})] | |
439 | + }).on('execution:error', e => console.log(e)) | |
440 | + | |
441 | + hypervisor.send(message2) | |
442 | +}) |
tests/wasm/storage.wasm | ||
---|---|---|
@@ -1,2 +1,2 @@ | ||
1 | 1 | asm types`n typeMap ` ` `` ` ` �testcheck testprint memoryexternalize storageget storageset elemexternalize eleminternalize funcinternalize p memory table main load |
2 | -4 A A A6 A A A A AA A ( A hello world | |
2 | +4 A A A6 A A A A AA A ( A A hello world |
tests/wasm/link.wasm | ||
---|---|---|
@@ -1,0 +1,4 @@ | ||
1 | + asm types`n typeMap #` ` `` ` `` � | |
2 | +testcheck testprint memoryexternalize storageget storageset elemexternalize eleminternalize funcinternalize linkwrap linkunwrap p A memory table main | |
3 | +load A | |
4 | +C A A A6 A A $ A A AA ( A A # A A hello world |
tests/wast/storage.wast | ||
---|---|---|
@@ -32,10 +32,8 @@ | ||
32 | 32 | (get_local $egress)) |
33 | 33 | |
34 | 34 | (call_indirect (param i32) |
35 | 35 | (i32.load (i32.const 0)) |
36 | - (get_local $egress)) | |
37 | - | |
38 | - ) | |
36 | + (i32.const 0))) | |
39 | 37 | |
40 | 38 | (export "main" (func $main)) |
41 | 39 | (export "load" (func $load))) |
tests/wast/link.json | ||
---|---|---|
@@ -1,0 +1,12 @@ | ||
1 | +{ | |
2 | + "types": [{ | |
3 | + "form": "func", | |
4 | + "params": [ | |
5 | + "func" | |
6 | + ] | |
7 | + }], | |
8 | + "typeMap": [{ | |
9 | + "func": 1, | |
10 | + "type": 0 | |
11 | + }] | |
12 | +} |
tests/wast/link.wast | ||
---|---|---|
@@ -1,0 +1,52 @@ | ||
1 | +(module | |
2 | + (import "test" "check" (func $check (param i32 i32))) | |
3 | + (import "test" "print" (func $print (param i32))) | |
4 | + (import "memory" "externalize" (func $mem.externalize (param i32 i32) (result i32))) | |
5 | + (import "storage" "get" (func $storage.get (result i32))) | |
6 | + (import "storage" "set" (func $storage.set (param i32))) | |
7 | + (import "elem" "externalize" (func $elem.externalize (param i32 i32) (result i32))) | |
8 | + (import "elem" "internalize" (func $elem.internalize (param i32 i32 i32 i32))) | |
9 | + (import "func" "internalize" (func $func.internalize (param i32 i32))) | |
10 | + (import "link" "wrap" (func $link.wrap (param i32) (result i32))) | |
11 | + (import "link" "unwrap" (func $link.unwrap (param i32 i32))) | |
12 | + | |
13 | + (memory (export "memory") 1) | |
14 | + (data (i32.const 0) "hello world") | |
15 | + (table (export "table") 1 1 anyfunc) | |
16 | + (elem (i32.const 0) $callback) | |
17 | + (global $egressRef (mut i32) (i32.const 0)) | |
18 | + | |
19 | + (func $main | |
20 | + (i32.store | |
21 | + (i32.const 0) | |
22 | + (call $link.wrap | |
23 | + (call $mem.externalize (i32.const 0) (i32.const 11)))) | |
24 | + | |
25 | + (call $storage.set | |
26 | + (call $elem.externalize (i32.const 0) (i32.const 1)))) | |
27 | + | |
28 | + (func $load (param $egress i32) | |
29 | + (set_global $egressRef (get_local $egress)) | |
30 | + | |
31 | + (call $elem.internalize | |
32 | + (call $storage.get) | |
33 | + (i32.const 0) | |
34 | + (i32.const 0) | |
35 | + (i32.const 1)) | |
36 | + | |
37 | + (call $link.unwrap | |
38 | + (i32.load (i32.const 0)) | |
39 | + (i32.const 0))) | |
40 | + | |
41 | + (func $callback (param $ref i32) | |
42 | + (call $func.internalize | |
43 | + (i32.const 0) | |
44 | + (get_global $egressRef)) | |
45 | + | |
46 | + (call_indirect (param i32) | |
47 | + (get_local $ref) | |
48 | + (i32.const 0)) | |
49 | + ) | |
50 | + | |
51 | + (export "main" (func $main)) | |
52 | + (export "load" (func $load))) |
Built with git-ssb-web