Skip to content

Commit

Permalink
Refine CI on to enable WERROR and test on emcc
Browse files Browse the repository at this point in the history
  • Loading branch information
Changqing-JING committed Jan 17, 2024
1 parent 5a7adc1 commit abe3632
Show file tree
Hide file tree
Showing 14 changed files with 1,472 additions and 3 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,18 @@ jobs:
run: |
docker run -di --name emscripten -v $(pwd):/src emscripten/emsdk:latest bash
docker exec emscripten emcc -v
docker exec emscripten emcmake cmake .
docker exec emscripten make -j 2 VERBOSE=1
docker exec emscripten emcmake cmake -B emscripten -DWERROR=ON -DBUILD_TESTS=OFF
docker exec emscripten bash -c "cd /src/emscripten && emmake 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
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion src/c-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ void CWriter::SerializeFuncType(const FuncType& func_type,
*next_byte++ = MangleType(func_type.GetResultType(i));
}

assert(next_byte - mangled_signature == len);
assert(next_byte - mangled_signature == static_cast<ptrdiff_t>(len));

// step 4: SHA-256 the whole string
sha256({mangled_signature, len}, serialized_type);
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

0 comments on commit abe3632

Please sign in to comment.