Commit 124610c716c1ba494bca1d28f39840fff9c2fa6b
added test for memory ops
wanderer committed on 2/21/2018, 10:37:42 PMParent: 1ffd915b15f2f2a528bc6e5329be0be2c9cab33b
Files changed
actor.js | changed |
tests/wasm/memory.wasm | added |
tests/wasmContainer.js | changed |
tests/wast/memory.wast | added |
wasmContainer.js | changed |
actor.js | ||
---|---|---|
@@ -61,9 +61,9 @@ | ||
61 | 61 | await this.container.onMessage(message) |
62 | 62 | } catch (e) { |
63 | 63 | message.emit('execution:error', e) |
64 | 64 | } |
65 | - message.emit('done') | |
65 | + message.emit('done', this) | |
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * updates the number of ticks that the actor has run |
tests/wasm/memory.wasm | ||
---|---|---|
@@ -1,0 +1,3 @@ | ||
1 | + asm ` `` ` 8testcheck memoryexternalize memoryinternalize memory test | |
2 | + A AA AA | |
3 | + A test |
tests/wasmContainer.js | ||
---|---|---|
@@ -24,16 +24,8 @@ | ||
24 | 24 | } |
25 | 25 | } |
26 | 26 | }) |
27 | 27 | } |
28 | - setState (key, ref) { | |
29 | - const obj = this.refs.get(ref) | |
30 | - this._storage.set(key, obj) | |
31 | - } | |
32 | - getState (key) { | |
33 | - const obj = this._storage.get(key) | |
34 | - return this.refs.add(obj) | |
35 | - } | |
36 | 28 | } |
37 | 29 | |
38 | 30 | tape('basic', async t => { |
39 | 31 | t.plan(2) |
@@ -116,63 +108,33 @@ | ||
116 | 108 | |
117 | 109 | hypervisor.send(message) |
118 | 110 | const stateRoot = await hypervisor.createStateRoot() |
119 | 111 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
120 | - // t.end() | |
121 | 112 | }) |
122 | 113 | |
123 | -tape.skip('two communicating actors with callback', async t => { | |
124 | - t.plan(2) | |
114 | +tape('externalize/internalize memory', async t => { | |
115 | + t.plan(1) | |
125 | 116 | tester = t |
126 | 117 | const expectedState = { |
127 | - '/': Buffer.from('9bf27cf07b75a90e0af530e2df73e3102482b24a', 'hex') | |
118 | + '/': Buffer.from('4494963fb0e02312510e675fbca8b60b6e03bd00', 'hex') | |
128 | 119 | } |
129 | 120 | |
130 | 121 | const tree = new RadixTree({ |
131 | 122 | db |
132 | 123 | }) |
133 | 124 | |
134 | - const recieverWasm = fs.readFileSync('./wasm/funcRef_reciever.wasm') | |
135 | - const callerWasm = fs.readFileSync('./wasm/funcRef_caller.wasm') | |
125 | + const wasm = fs.readFileSync('./wasm/memory.wasm') | |
136 | 126 | |
137 | 127 | const hypervisor = new Hypervisor(tree) |
138 | 128 | hypervisor.registerContainer(TestWasmContainer) |
139 | 129 | |
140 | - const {module: receiverMod} = await hypervisor.createActor(TestWasmContainer.typeId, recieverWasm) | |
141 | - const {module: callerMod} = await hypervisor.createActor(TestWasmContainer.typeId, callerWasm) | |
142 | - | |
143 | - const message = new Message({ | |
144 | - funcRef: callerMod.getFuncRef('call'), | |
145 | - funcArguments: [receiverMod.getFuncRef('receive')] | |
146 | - }) | |
147 | - | |
148 | - hypervisor.send(message) | |
149 | - const stateRoot = await hypervisor.createStateRoot() | |
150 | - t.deepEquals(stateRoot, expectedState, 'expected root!') | |
151 | - t.end() | |
152 | -}) | |
153 | - | |
154 | -// Increment a counter. | |
155 | -tape.skip('increment', async t => { | |
156 | - const tree = new RadixTree({ | |
157 | - db | |
158 | - }) | |
159 | - | |
160 | - const wasm = fs.readFileSync('./wasm/counter.wasm') | |
161 | - | |
162 | - const hypervisor = new Hypervisor(tree) | |
163 | - hypervisor.registerContainer(TestWasmContainer) | |
164 | - | |
165 | 130 | const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) |
166 | 131 | |
167 | 132 | const message = new Message({ |
168 | - funcRef: module.increment, | |
169 | - funcArguments: [] | |
133 | + funcRef: module.getFuncRef('test') | |
134 | + }).on('done', actor => { | |
135 | + const a = actor.container.getMemory(0, 5) | |
136 | + const b = actor.container.getMemory(5, 5) | |
137 | + t.deepEquals(a, b, 'should copy memory correctly') | |
170 | 138 | }) |
171 | 139 | hypervisor.send(message) |
172 | - | |
173 | - const stateRoot = await hypervisor.createStateRoot() | |
174 | - t.end() | |
175 | - | |
176 | - console.log(stateRoot) | |
177 | - | |
178 | 140 | }) |
tests/wast/memory.wast | ||
---|---|---|
@@ -1,0 +1,16 @@ | ||
1 | +(module | |
2 | + (import "test" "check" (func $check (param i32 i32))) | |
3 | + (import "memory" "externalize" (func $externalize (param i32 i32) (result i32))) | |
4 | + (import "memory" "internalize" (func $internalize (param i32 i32 i32 i32))) | |
5 | + (memory (export "memory") 1) | |
6 | + (data (i32.const 0) "test") | |
7 | + (func $test | |
8 | + i32.const 0 | |
9 | + i32.const 4 | |
10 | + call $externalize | |
11 | + i32.const 0 | |
12 | + i32.const 5 | |
13 | + i32.const 4 | |
14 | + call $internalize | |
15 | + ) | |
16 | + (export "test" (func $test))) |
wasmContainer.js | ||
---|---|---|
@@ -148,11 +148,11 @@ | ||
148 | 148 | this.refs = new ReferanceMap() |
149 | 149 | } |
150 | 150 | |
151 | 151 | static async onCreation (wasm, id, cachedb) { |
152 | - if (!WebAssembly.validate(wasm)) { | |
153 | - throw new Error('invalid wasm binary') | |
154 | - } | |
152 | + // if (!WebAssembly.validate(wasm)) { | |
153 | + // throw new Error('invalid wasm binary') | |
154 | + // } | |
155 | 155 | let moduleJSON = wasm2json(wasm) |
156 | 156 | const json = customTypes.mergeTypeSections(moduleJSON) |
157 | 157 | moduleJSON = wasmMetering.meterJSON(moduleJSON, { |
158 | 158 | meterType: 'i32' |
@@ -229,12 +229,12 @@ | ||
229 | 229 | externalize: (index, length) => { |
230 | 230 | const buf = this.getMemory(index, length) |
231 | 231 | return this.refs.add(buf, 'buf') |
232 | 232 | }, |
233 | - internalize: (dataRef, writeOffset, readOffset, length) => { | |
233 | + internalize: (dataRef, srcOffset, sinkOffset, length) => { | |
234 | 234 | let buf = this.refs.get(dataRef, 'buf') |
235 | - buf = buf.subarray(readOffset, length) | |
236 | - const mem = this.getMemory(writeOffset, buf.length) | |
235 | + buf = buf.subarray(srcOffset, length) | |
236 | + const mem = this.getMemory(sinkOffset, buf.length) | |
237 | 237 | mem.set(buf) |
238 | 238 | } |
239 | 239 | }, |
240 | 240 | table: { |
@@ -297,8 +297,11 @@ | ||
297 | 297 | this.instance.exports.table.get(funcRef.indentifier)(...args) |
298 | 298 | } |
299 | 299 | await this.onDone() |
300 | 300 | this.refs.clear() |
301 | + if (this.json.globals.length) { | |
302 | + this.instance.exports.getter_globals() | |
303 | + } | |
301 | 304 | } |
302 | 305 | |
303 | 306 | /** |
304 | 307 | * returns a promise that resolves when the wasm instance is done running |
Built with git-ssb-web