git ssb

0+

wanderer🌟 / js-primea-wasm-container



Commit 5bd5107d2516fdd050060c58508ee7009ab9489b

added tests

wanderer committed on 7/6/2017, 2:41:58 AM
Parent: 0c6302f3b6cf83783870ae49f570c87c38ddb414

Files changed

index.jschanged
tests/index.jschanged
index.jsView
@@ -12,9 +12,9 @@
1212 this.imports = imports
1313 this.referanceMap = new ReferanceMap()
1414 }
1515
16- async initailize (message) {
16+ async initialize (message) {
1717 if (!WebAssembly.validate(this.kernel.state.code)) {
1818 throw new Error('invalid wasm binary')
1919 }
2020 return this._run(message, 'init')
tests/index.jsView
@@ -1,7 +1,8 @@
11 const tape = require('tape')
22 const fs = require('fs')
33 const Hypervisor = require('primea-hypervisor')
4+const Message = require('primea-message')
45 const WasmContainer = require('../index.js')
56 const testInterface = require('./testInterface.js')
67 const IPFS = require('ipfs')
78 const ReferanceMap = require('../referanceMap.js')
@@ -66,9 +67,11 @@
6667 const main = fs.readFileSync(`${__dirname}/wasm/main.wasm`)
6768 hypervisor.registerContainer('wasm', WasmContainer, {
6869 test: testInterface(t)
6970 })
70- const instance = await hypervisor.createInstance('wasm', main)
71+ const instance = await hypervisor.createInstance('wasm', new Message({
72+ data: main
73+ }))
7174 instance.run(instance.createMessage())
7275 })
7376
7477 tape('wasm container - mem', async t => {
@@ -78,9 +81,11 @@
7881 hypervisor.registerContainer('wasm', WasmContainer, {
7982 env: ContainerTestInterface,
8083 test: testInterface(t)
8184 })
82- await hypervisor.createInstance('wasm', readMem)
85+ await hypervisor.createInstance('wasm', new Message({
86+ data: readMem
87+ }))
8388 })
8489
8590 tape('wasm container - callbacks', async t => {
8691 t.plan(1)
@@ -89,18 +94,27 @@
8994 hypervisor.registerContainer('wasm', WasmContainer, {
9095 env: ContainerTestInterface,
9196 test: testInterface(t)
9297 })
93- hypervisor.createInstance('wasm', callBackWasm)
98+ hypervisor.createInstance('wasm', new Message({
99+ data: callBackWasm
100+ }))
94101 })
95102
96- tape.only('wasm container - invalid', async t => {
103+ tape('wasm container - invalid', async t => {
97104 t.plan(1)
98105 const hypervisor = new Hypervisor(node.dag)
99106 hypervisor.registerContainer('wasm', WasmContainer, {
100107 env: ContainerTestInterface,
101108 test: testInterface(t)
102109 })
103110
104- await hypervisor.createInstance('wasm', Buffer.from([0x00]))
111+ const message = new Message({
112+ data: Buffer.from([0x00])
113+ })
114+
115+ const rp = message.responsePort = {destPort: {messages: []}}
116+
117+ await hypervisor.createInstance('wasm', message)
118+ t.equals(rp.destPort.messages[0].data.exception, true)
105119 })
106120 })

Built with git-ssb-web