Skip to content

Commit

Permalink
Adding new testcases for instantiateStreaming, new Instance and expor…
Browse files Browse the repository at this point in the history
…ts overwrite
  • Loading branch information
jakobgetz committed Dec 6, 2023
1 parent 3fb38e8 commit e45cdaa
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions tests/offline/basic-instantiateStreaming/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { delay } from '../../../dist/tests/test-utils.cjs'

export default async function test(analyser) {
const url = 'http://localhost:8000'
await analyser.start(url, { headless: true })
await delay(100)
return await analyser.stop()
}
Binary file not shown.
15 changes: 15 additions & 0 deletions tests/offline/basic-instantiateStreaming/website/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>

<head>
<title>Worker test</title>
</head>

<body>
<script>
WebAssembly.instantiateStreaming(fetch("add.wasm"), {})
.then((result) => console.log(`1 + 2 = ${result.instance.exports.add(1, 2)}`));
</script>
</body>

</html>
8 changes: 8 additions & 0 deletions tests/offline/basic-new-Instance/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { delay } from '../../../dist/tests/test-utils.cjs'

export default async function test(analyser) {
const url = 'http://localhost:8000'
await analyser.start(url, { headless: true })
await delay(100)
return await analyser.stop()
}
Binary file added tests/offline/basic-new-Instance/website/add.wasm
Binary file not shown.
19 changes: 19 additions & 0 deletions tests/offline/basic-new-Instance/website/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>

<head>
<title>Worker test</title>
</head>

<body>
<script>
fetch("add.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => {
const wasm = new WebAssembly.Instance(bytes, {})
console.log(`1 + 2 = ${wasm.instance.exports.add(1, 2)}`)
})
</script>
</body>

</html>
8 changes: 8 additions & 0 deletions tests/offline/exports-overwrite/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { delay } from '../../../dist/tests/test-utils.cjs'

export default async function test(analyser) {
const url = 'http://localhost:8000'
await analyser.start(url, { headless: true })
await delay(100)
return await analyser.stop()
}
28 changes: 28 additions & 0 deletions tests/offline/exports-overwrite/website/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>

<head>
<title>Worker test</title>
</head>

<body>
<script>
fetch("mem.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => WebAssembly.instantiate(bytes, {}))
fetch("sub.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => WebAssembly.instantiate(bytes, {}))
.then((result) => {
console.log(`9 - 3 = ${result.instance.exports.sub(9, 3)}`)
if (analysis[0].Wasabi.module.memories.length === 0) {
console.log('memory got overwritten')
analysis[0].trace.push('Memory got overwritten! This trace event should not appear. If this test fails, webapps like sqllite will likely not work with wasm-r3')
} else {
console.log('memory is fine')
}
});
</script>
</body>

</html>
Binary file added tests/offline/exports-overwrite/website/mem.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/offline/exports-overwrite/website/mem.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(module
(memory (export "memory") 1)
)
Binary file added tests/offline/exports-overwrite/website/sub.wasm
Binary file not shown.

0 comments on commit e45cdaa

Please sign in to comment.