Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test files for wabtjs #2371

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ jobs:
docker exec emscripten emcc -v
docker exec emscripten emcmake cmake -B emscripten -DWERROR=ON
docker exec -w /src/emscripten emscripten make -j $(nproc)
- uses: actions/setup-node@v3
with:
node-version: "^18.15.0"
- name: test
run: |
cd ./test/wabtjs
npm ci
npm run test

wasi:
name: wasi
Expand Down
1 change: 1 addition & 0 deletions test/wabtjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions test/wabtjs/assembly/module-features.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function add(a: v128, b: v128): v128 {
return v128.add<i32>(a, b);
}
Binary file added test/wabtjs/assembly/module-features.wasm
Binary file not shown.
12 changes: 12 additions & 0 deletions test/wabtjs/assembly/module-features.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(module
(type $v128_v128_=>_v128 (func (param v128 v128) (result v128)))
(memory $0 0)
(table $0 1 funcref)
(export "memory" (memory $0))
(export "add" (func $tests/assembly/module-features/add))
(func $tests/assembly/module-features/add (; 0 ;) (param $0 v128) (param $1 v128) (result v128)
local.get $0
local.get $1
i32x4.add
)
)
3 changes: 3 additions & 0 deletions test/wabtjs/assembly/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function add(a: i32, b: i32): i32 {
return a + b;
}
Binary file added test/wabtjs/assembly/module.wasm
Binary file not shown.
12 changes: 12 additions & 0 deletions test/wabtjs/assembly/module.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(module
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
(memory $0 0)
(table $0 1 funcref)
(export "memory" (memory $0))
(export "add" (func $tests/assembly/module/add))
(func $tests/assembly/module/add (; 0 ;) (param $0 i32) (param $1 i32) (result i32)
local.get $0
local.get $1
i32.add
)
)
6 changes: 6 additions & 0 deletions test/wabtjs/assembly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../node_modules/assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
}
96 changes: 96 additions & 0 deletions test/wabtjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"use strict"
var fs = require("fs");
var test = require("tape");

// This test case exists to catch the most obvious issues before pushing the binary back to GitHub.
// It's not intended to be a full test suite, but feel free to extend it / send a PR if necessary!

require("../../emscripten/libwabt")().then(wabt => {

var mod;
test("loading a binary module", function (test) {
var buffer = new Uint8Array(
fs.readFileSync(__dirname + "/assembly/module.wasm")
);
test.doesNotThrow(function () {
mod = wabt.readWasm(buffer, { readDebugNames: true });
});
test.ok(mod && typeof mod.toBinary === "function", "should return a module");
test.end();
});

test("loading a binary module (with features)", function (test) {
var buffer = new Uint8Array(
fs.readFileSync(__dirname + "/assembly/module-features.wasm")
);
test.doesNotThrow(function () {
mod = wabt.readWasm(buffer, {
readDebugNames: true,
});
});
test.ok(mod && typeof mod.toBinary === "function", "should return a module");
test.end();
});

test("modifying a module", function (test) {
test.doesNotThrow(function () {
mod.generateNames();
mod.applyNames();
});
test.end();
});

test("emitting a module", function (test) {
var text, binaryRes;
test.doesNotThrow(function () {
text = mod.toText({ foldExprs: true, inlineExport: false });
binaryRes = mod.toBinary({ write_debug_names: true });
});
test.ok(
typeof text === "string" && text.length,
"should return a string from calling Module#toText"
);
test.ok(
binaryRes &&
binaryRes.buffer &&
binaryRes.buffer.length &&
typeof binaryRes.log === "string",
"should return a binary result from calling Module#toBinary"
);
test.end();
});

test("destroying a module", function (test) {
test.doesNotThrow(function () {
mod.destroy();
}, "should not throw when calling Module#destroy");
test.end();
});

test("loading a text (wat) module", function (test) {
var str = fs.readFileSync(__dirname + "/assembly/module.wat").toString();
var mod;
test.doesNotThrow(function () {
mod = wabt.parseWat("module.wat", str);
});
test.ok(mod && typeof mod.toBinary === "function", "should return a module");
test.doesNotThrow(function () {
mod.destroy();
}, "should not throw when calling Module#destroy");
test.end();
});

test("loading a text (wat) module with features", function (test) {
var str = fs.readFileSync(__dirname + "/assembly/module-features.wat").toString();
var mod;
test.doesNotThrow(function () {
mod = wabt.parseWat("module-features.wat", str);
});
test.ok(mod && typeof mod.toBinary === "function", "should return a module");
test.doesNotThrow(function () {
mod.destroy();
}, "should not throw when calling Module#destroy");
test.end();
});

});
Loading
Loading