Skip to content

Commit

Permalink
fix proxy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
doehyunbaek committed Aug 20, 2024
1 parent 4f2107a commit 0e5262d
Show file tree
Hide file tree
Showing 46 changed files with 447 additions and 174 deletions.
8 changes: 6 additions & 2 deletions src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ export const filter = {
'rust-game-of-life', // fail only at CI
],
proxy: [
// Regressions: revisit after unit
"external-call",
// TODO: fix these regressions
"basic-new-Instance-module", // TypeError: Cannot read properties of undefined (reading 'forEach')
"basic-new-Instance-compile", // TypeError: Cannot read properties of undefined (reading 'forEach')
"basic-new-Instance-compileStreaming", // TypeError: Cannot read properties of undefined (reading 'forEach')
"external-call", // SyntaxError: Identifier 'wasm' has already been declared
"multiple-worker-different-name", // SyntaxError: Identifier 'MEM_PAGE_SIZE' has already been declared
],
online: [
"heatmap", // works fine, but too long so we skip it
Expand Down
10 changes: 9 additions & 1 deletion tests/proxy/basic-instantiate/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
fetch("add.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => WebAssembly.instantiate(bytes, {}))
.then((result) => console.log(`1 + 2 = ${result.instance.exports.add(1, 2)}`));
.then((result) => {
const startTime = performance.now();
console.log(`1 + 2 = ${result.instance.exports.add(1, 2)}`)
const endTime = performance.now();
const executionTime = endTime - startTime;
const executionTimeElement = document.createElement('p');
executionTimeElement.textContent = `Execution time: ${executionTime} milliseconds`;
document.body.appendChild(executionTimeElement);
});
</script>
</body>

Expand Down
7 changes: 0 additions & 7 deletions tests/proxy/basic-instantiateStreaming/test.js

This file was deleted.

10 changes: 9 additions & 1 deletion tests/proxy/basic-instantiateStreaming/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
<body>
<script>
WebAssembly.instantiateStreaming(fetch("add.wasm"), {})
.then((result) => console.log(`1 + 2 = ${result.instance.exports.add(1, 2)}`));
.then((result) => {
const startTime = performance.now();
console.log(`1 + 2 = ${result.instance.exports.add(1, 2)}`)
const endTime = performance.now();
const executionTime = endTime - startTime;
const executionTimeElement = document.createElement('p');
executionTimeElement.textContent = `Execution time: ${executionTime} milliseconds`;
document.body.appendChild(executionTimeElement);
});
</script>
</body>

Expand Down
7 changes: 0 additions & 7 deletions tests/proxy/basic-new-Instance-compile/test.js

This file was deleted.

6 changes: 6 additions & 0 deletions tests/proxy/basic-new-Instance-compile/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
.then((response) => response.arrayBuffer())
.then((bytes) => WebAssembly.compile(bytes))
.then((module) => {
const startTime = performance.now();
const instance = new WebAssembly.Instance(module, {})
console.log(`1 + 2 = ${instance.exports.add(1, 2)}`)
const endTime = performance.now();
const executionTime = endTime - startTime;
const executionTimeElement = document.createElement('p');
executionTimeElement.textContent = `Execution time: ${executionTime} milliseconds`;
document.body.appendChild(executionTimeElement);
})
</script>
</body>
Expand Down
2 changes: 2 additions & 0 deletions tests/proxy/basic-new-Instance-compileStreaming/reference.r3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EC;0;add;1,2
ER
7 changes: 0 additions & 7 deletions tests/proxy/basic-new-Instance-compileStreaming/test.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
<script>
WebAssembly.compileStreaming(fetch("add.wasm"))
.then((module) => {
const startTime = performance.now();
const instance = new WebAssembly.Instance(module, {})
console.log(`1 + 2 = ${instance.exports.add(1, 2)}`)
const endTime = performance.now();
const executionTime = endTime - startTime;
const executionTimeElement = document.createElement('p');
executionTimeElement.textContent = `Execution time: ${executionTime} milliseconds`;
document.body.appendChild(executionTimeElement);
})
</script>
</body>
Expand Down
2 changes: 2 additions & 0 deletions tests/proxy/basic-new-Instance-module/reference.r3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EC;0;add;1,2
ER
7 changes: 0 additions & 7 deletions tests/proxy/basic-new-Instance-module/test.js

This file was deleted.

7 changes: 0 additions & 7 deletions tests/proxy/external-call/test.js

This file was deleted.

2 changes: 2 additions & 0 deletions tests/proxy/frame-in-frame/reference.r3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EC;0;add;1,2
ER
7 changes: 0 additions & 7 deletions tests/proxy/frame-in-frame/test.js

This file was deleted.

18 changes: 18 additions & 0 deletions tests/proxy/frame-in-frame/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@

<body>
<iframe src="frame1.html"></iframe>
<script>
(async function () {
const startTime = performance.now();

// Simulating some asynchronous operation, like loading the iframe
await new Promise(resolve => {
const iframe = document.querySelector('iframe');
iframe.onload = resolve;
});

const endTime = performance.now();
const executionTime = endTime - startTime;

const executionTimeElement = document.createElement('p');
executionTimeElement.textContent = `Execution time: ${executionTime} milliseconds`;
document.body.appendChild(executionTimeElement);
})();
</script>
</body>

</html>
2 changes: 2 additions & 0 deletions tests/proxy/frames/reference.r3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EC;0;add;1,2
ER
7 changes: 0 additions & 7 deletions tests/proxy/frames/test.js

This file was deleted.

18 changes: 18 additions & 0 deletions tests/proxy/frames/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@
<body>
<iframe src="frame1.html"></iframe>
<iframe src="frame2.html"></iframe>
<script>
(async function () {
const startTime = performance.now();

// Simulating some asynchronous operation, like loading the iframe
await new Promise(resolve => {
const iframe = document.querySelector('iframe');
iframe.onload = resolve;
});

const endTime = performance.now();
const executionTime = endTime - startTime;

const executionTimeElement = document.createElement('p');
executionTimeElement.textContent = `Execution time: ${executionTime} milliseconds`;
document.body.appendChild(executionTimeElement);
})();
</script>
</body>

</html>
2 changes: 2 additions & 0 deletions tests/proxy/multiple-wasm-files/reference.r3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EC;0;mul;3,3
ER
7 changes: 0 additions & 7 deletions tests/proxy/multiple-wasm-files/test.js

This file was deleted.

65 changes: 50 additions & 15 deletions tests/proxy/multiple-wasm-files/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,55 @@

<body>
<script>
fetch("add.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => WebAssembly.instantiate(bytes, {}))
.then((result) => console.log(`10 + 2 = ${result.instance.exports.add(10, 2)}`));
fetch("add.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => WebAssembly.instantiate(bytes, {}))
.then((result) => console.log(`10 + 2 = ${result.instance.exports.add(1, 1)}`));
fetch("sub.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => WebAssembly.instantiate(bytes, {}))
.then((result) => console.log(`9 - 3 = ${result.instance.exports.sub(9, 3)}`));
new Worker('worker.js')
</script>
</body>
(async function() {
const startTime = performance.now();

// Function to load and instantiate a WASM module
async function loadWasm(url) {
const response = await fetch(url);
const bytes = await response.arrayBuffer();
return WebAssembly.instantiate(bytes, {});
}

try {
// Load and execute add.wasm (first instance)
const add1 = await loadWasm("add.wasm");
console.log(`10 + 2 = ${add1.instance.exports.add(10, 2)}`);

// Load and execute add.wasm (second instance)
const add2 = await loadWasm("add.wasm");
console.log(`1 + 1 = ${add2.instance.exports.add(1, 1)}`);

// Load and execute sub.wasm
const sub = await loadWasm("sub.wasm");
console.log(`9 - 3 = ${sub.instance.exports.sub(9, 3)}`);

// Create a new Worker
const worker = new Worker('worker.js');

// Wait for the worker to initialize (if needed)
await new Promise(resolve => {
worker.onmessage = (e) => {
if (e.data === 'finished') {
resolve();
}
};
});

const endTime = performance.now();
const executionTime = endTime - startTime;

console.log(`Total execution time: ${executionTime} milliseconds`);

// Create and append execution time element to the body
const executionTimeElement = document.createElement('p');
executionTimeElement.textContent = `Total execution time: ${executionTime.toFixed(2)} milliseconds`;
document.body.appendChild(executionTimeElement);

} catch (error) {
console.error("An error occurred:", error);
}
})();
</script>
</body>
</html>
29 changes: 21 additions & 8 deletions tests/proxy/multiple-wasm-files/website/worker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
fetch("mul.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => WebAssembly.instantiate(bytes, {}))
.then((result) => console.log(`3 x 3 = ${result.instance.exports.mul(3, 3)}`));
fetch("div.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => WebAssembly.instantiate(bytes, {}))
.then((result) => console.log(`3 / 3 = ${result.instance.exports.div(3, 3)}`));
Promise.all([
fetch("mul.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => WebAssembly.instantiate(bytes, {}))
.then((result) => {
console.log(`3 x 3 = ${result.instance.exports.mul(3, 3)}`);
return result;
}),
fetch("div.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => WebAssembly.instantiate(bytes, {}))
.then((result) => {
console.log(`3 / 3 = ${result.instance.exports.div(3, 3)}`);
return result;
})
]).then(() => {
self.postMessage('finished');
}).catch((error) => {
console.error("An error occurred:", error);
self.postMessage('error');
});
2 changes: 2 additions & 0 deletions tests/proxy/multiple-worker-different-name/reference.r3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EC;0;add;1,2
ER
7 changes: 0 additions & 7 deletions tests/proxy/multiple-worker-different-name/test.js

This file was deleted.

2 changes: 2 additions & 0 deletions tests/proxy/multiple-worker/reference.r3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EC;0;add;1,2
ER
7 changes: 0 additions & 7 deletions tests/proxy/multiple-worker/test.js

This file was deleted.

36 changes: 31 additions & 5 deletions tests/proxy/multiple-worker/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,36 @@
</head>

<body>
<script>
var worker = new Worker('worker.js');
var worker2 = new Worker('second-worker.js');
</script>
</body>
<script>
const startTime = performance.now();
let workersCompleted = 0;

function checkCompletion() {
workersCompleted++;
if (workersCompleted === 2) {
const endTime = performance.now();
const executionTime = endTime - startTime;
console.log(`Total execution time: ${executionTime} milliseconds`);
const executionTimeElement = document.createElement('p');
executionTimeElement.textContent = `Total execution time: ${executionTime.toFixed(2)} milliseconds`;
document.body.appendChild(executionTimeElement);
}
}

function createWorker(scriptName, id) {
const worker = new Worker(scriptName);
worker.onmessage = function(e) {
if (e.data.status === 'completed') {
console.log(`Worker ${id} result:`, e.data.result);
console.log(`Worker ${id} execution time:`, e.data.executionTime.toFixed(2), 'milliseconds');
checkCompletion();
}
};
return worker;
}

const worker1 = createWorker('worker.js', 1);
const worker2 = createWorker('second-worker.js', 2);
</script>
</body>
</html>
Loading

0 comments on commit 0e5262d

Please sign in to comment.