Skip to content

Commit cbbe6f8

Browse files
committed
add all examples from the WebAssembly explorer as tests
1 parent f59526b commit cbbe6f8

File tree

19 files changed

+140
-0
lines changed

19 files changed

+140
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
it("Q_rsqrt should work", function() {
2+
return import("./Q_rsqrt.wasm").then(function(wasm) {
3+
const result = wasm._Z7Q_rsqrtf(1/1764);
4+
expect(result).toBeGreaterThan(41.9);
5+
expect(result).toBeLessThan(42.1);
6+
});
7+
});
8+
9+
it("testFunction should work", function() {
10+
return import("./testFunction.wasm").then(function(wasm) {
11+
const view = new Int32Array(wasm.memory.buffer);
12+
view[0] = 123;
13+
view[1] = 1;
14+
view[2] = 2;
15+
view[3] = 3;
16+
const result = wasm._Z12testFunctionPii(4, 3);
17+
expect(result).toEqual(6);
18+
});
19+
});
20+
21+
it("fact should work", function() {
22+
return import("./fact.wasm").then(function(wasm) {
23+
const result = wasm._Z4facti(11);
24+
expect(result).toEqual(39916800);
25+
});
26+
});
27+
28+
it("popcnt should work", function() {
29+
return import("./popcnt.wasm").then(function(wasm) {
30+
expect(wasm.main(0xF0F)).toEqual(16);
31+
expect(wasm._Z5countj(0xF0F)).toEqual(8);
32+
});
33+
});
34+
35+
it("fast-math should work", function() {
36+
return import("./fast-math.wasm").then(function(wasm) {
37+
expect(wasm._Z3food(42)).toEqual(14);
38+
expect(wasm._Z9maybe_mindd(42, 24)).toEqual(24);
39+
expect(wasm._Z8call_powd(42)).toEqual(9682651996416);
40+
expect(wasm._Z6do_powd(42)).toEqual(9682651996416);
41+
expect(wasm._Z6factorddd(42, 42, 42)).toEqual(3528);
42+
});
43+
});
44+
45+
it("duff should work", function() {
46+
return import("./duff.wasm").then(function(wasm) {
47+
const view = new Uint8Array(wasm.memory.buffer);
48+
view[0] = 123;
49+
for(let i = 1; i < 100; i++)
50+
view[i] = i;
51+
const result = wasm._Z4sendPcS_m(200, 1, 100);
52+
for(let i = 1; i < 100; i++)
53+
expect(view[199 + i]).toEqual(i);
54+
});
55+
});

test/cases/wasm/wasm-explorer-examples-async/node_modules/env.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly");
2+
3+
module.exports = function(config) {
4+
return supportsWebAssembly();
5+
};
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
it("Q_rsqrt should work", function() {
2+
return import("./tests").then(t => t.run_Q_rsqrt());
3+
});
4+
5+
it("testFunction should work", function() {
6+
return import("./tests").then(t => t.run_testFunction());
7+
});
8+
9+
it("fact should work", function() {
10+
return import("./tests").then(t => t.run_fact());
11+
});
12+
13+
it("popcnt should work", function() {
14+
return import("./tests").then(t => t.run_popcnt());
15+
});
16+
17+
it("fast-math should work", function() {
18+
return import("./tests").then(t => t.run_fastMath());
19+
});
20+
21+
it("duff should work", function() {
22+
return import("./tests").then(t => t.run_duff());
23+
});

test/cases/wasm/wasm-explorer-examples-sync/node_modules/env.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly");
2+
3+
module.exports = function(config) {
4+
return supportsWebAssembly();
5+
};
Binary file not shown.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as Q_rsqrt from "./Q_rsqrt.wasm";
2+
import * as testFunction from "./testFunction.wasm";
3+
import * as fact from "./fact.wasm";
4+
import * as popcnt from "./popcnt.wasm";
5+
import * as fastMath from "./fast-math.wasm";
6+
import * as duff from "./duff.wasm";
7+
8+
export function run_Q_rsqrt() {
9+
const result = Q_rsqrt._Z7Q_rsqrtf(1/1764);
10+
expect(result).toBeGreaterThan(41.9);
11+
expect(result).toBeLessThan(42.1);
12+
}
13+
14+
export function run_testFunction() {
15+
const view = new Int32Array(testFunction.memory.buffer);
16+
view[0] = 123;
17+
view[1] = 1;
18+
view[2] = 2;
19+
view[3] = 3;
20+
const result = testFunction._Z12testFunctionPii(4, 3);
21+
expect(result).toEqual(6);
22+
}
23+
24+
export function run_fact() {
25+
const result = fact._Z4facti(11);
26+
expect(result).toEqual(39916800);
27+
}
28+
29+
export function run_popcnt() {
30+
expect(popcnt.main(0xF0F)).toEqual(16);
31+
expect(popcnt._Z5countj(0xF0F)).toEqual(8);
32+
}
33+
34+
export function run_fastMath() {
35+
expect(fastMath._Z3food(42)).toEqual(14);
36+
expect(fastMath._Z9maybe_mindd(42, 24)).toEqual(24);
37+
expect(fastMath._Z8call_powd(42)).toEqual(9682651996416);
38+
expect(fastMath._Z6do_powd(42)).toEqual(9682651996416);
39+
expect(fastMath._Z6factorddd(42, 42, 42)).toEqual(3528);
40+
}
41+
42+
export function run_duff() {
43+
const view = new Uint8Array(duff.memory.buffer);
44+
view[0] = 123;
45+
for(let i = 1; i < 100; i++)
46+
view[i] = i;
47+
const result = duff._Z4sendPcS_m(200, 1, 100);
48+
for(let i = 1; i < 100; i++)
49+
expect(view[199 + i]).toEqual(i);
50+
}

0 commit comments

Comments
 (0)