Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .github/action/setup-ccache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ runs:
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_CLEANUP: 1

- if: runner.os == 'Windows'
shell: bash
run: |
choco install ccache ninja -y

- uses: actions/cache@v4
with:
path: build_cache
Expand Down
37 changes: 36 additions & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- main

jobs:
test:
Linux_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -53,3 +53,38 @@ jobs:
run: |
set -e
ccache --show-stats

Windows_test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-node@v3
with:
node-version: 22
cache: "npm"
- run: npm ci

- name: cache emsdk
uses: actions/cache@v4
with:
path: |
third_party/emsdk/node
third_party/emsdk/python
third_party/emsdk/upstream
third_party/emsdk/.emscripten
key: cache-${{ runner.os }}-emsdk-${{ hashFiles('scripts/**') }}

- uses: ./.github/action/setup-ccache
with:
size: 128M
key: ccache-${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
ccache-${{ runner.os }}-build-

- run: npm run build

- name: run test for windows
run: |
npm run test:as
2 changes: 1 addition & 1 deletion scripts/build_instrumentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function initEmscripten() {

initEmscripten();

execSync("emcmake cmake -B build_wasm -S .", { encoding: "utf8", stdio: "inherit", env });
execSync("emcmake cmake -G Ninja -B build_wasm -S .", { encoding: "utf8", stdio: "inherit", env });
execSync(`cmake --build build_wasm --parallel ${parallelJobs} --target wasm-instrumentation`, {
encoding: "utf8",
stdio: "inherit",
Expand Down
4 changes: 3 additions & 1 deletion tests/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
find_package(GTest REQUIRED)
enable_testing()

find_package(GTest REQUIRED CONFIG)
include(FetchContent)

file(GLOB test_sources CONFIGURE_DEPENDS *.cpp ./utils/*.cpp) # innclude lit test by default
Expand Down
15 changes: 10 additions & 5 deletions tests/cpp/fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ TEST(fuzz, asc) {
const std::filesystem::path targetExpectInfoPath =
build_path / "assemblyscript.debug.wasm.expectinfo.json";
const char *reportName = "assembly/env/traceExpression";
const std::string wasmPathStr = wasmPath.string();
const std::string targetDebugInfoPathStr = targetDebugInfoPath.string();
const std::string mapPathStr = mapPath.string();
const std::string targetPathStr = targetPath.string();
const std::string targetExpectInfoPathStr = targetExpectInfoPath.string();
wasmInstrumentation::InstrumentationConfig config;
config.fileName = wasmPath.c_str();
config.debugInfoOutputFilePath = targetDebugInfoPath.c_str();
config.sourceMap = mapPath.c_str();
config.targetName = targetPath.c_str();
config.expectInfoOutputFilePath = targetExpectInfoPath.c_str();
config.fileName = wasmPathStr;
config.debugInfoOutputFilePath = targetDebugInfoPathStr;
config.sourceMap = mapPathStr;
config.targetName = targetPathStr;
config.expectInfoOutputFilePath = targetExpectInfoPathStr;
config.reportFunction = reportName;
wasmInstrumentation::CoverageInstru instrumentor(&config);
ASSERT_EQ(instrumentor.instrument(), wasmInstrumentation::InstrumentationResponse::NORMAL);
Expand Down
33 changes: 22 additions & 11 deletions tests/cpp/lit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ TEST(lit, coverageInstrumentation) {
const char *include = "[\"main\",\"assembly/.*\"]";
Json::Reader jsonReader;
// step 3, instrument , run and check;
for (Json::String const &wast : wastFiles) {
for (std::filesystem::path const &wastPath : wastFiles) {
const std::string wast = wastPath.string();
const std::filesystem::path wasmFile = tmpDir / (wast + ".out.wasm");
const std::filesystem::path wasmFileMap = tmpDir / (wast + ".out.wasm.map");
const std::filesystem::path wasmTarget = tmpDir / (wast + ".instrumented.wasm");
Expand All @@ -55,11 +56,16 @@ TEST(lit, coverageInstrumentation) {
const char *traceFunName = "assembly/env/traceExpression";
wasmInstrumentation::InstrumentationConfig config;
std::cout << "running lit - " << fixtureFolder << "/" << wast << std::endl;
config.fileName = wasmFile.c_str();
config.debugInfoOutputFilePath = debugTarget.c_str();
config.expectInfoOutputFilePath = expectTarget.c_str();
config.sourceMap = wasmFileMap.c_str();
config.targetName = wasmTarget.c_str();
const std::string wasmFileStr = wasmFile.string();
const std::string debugTargetStr = debugTarget.string();
const std::string expectTargetStr = expectTarget.string();
const std::string wasmFileMapStr = wasmFileMap.string();
const std::string wasmTargetStr = wasmTarget.string();
config.fileName = wasmFileStr;
config.debugInfoOutputFilePath = debugTargetStr;
config.expectInfoOutputFilePath = expectTargetStr;
config.sourceMap = wasmFileMapStr;
config.targetName = wasmTargetStr;
config.reportFunction = traceFunName;
config.includes = include;
config.excludes = "";
Expand Down Expand Up @@ -103,11 +109,16 @@ TEST(lit, expectInstrumentation) {
const std::filesystem::path wasmTarget = tmpDir / "expect.test.instrumented.wasm";
const char *traceFunName = "assembly/env/traceExpression";
const char *include = "[\"tests-as\",\"assembly/.*\"]";
config.fileName = wasmFile.c_str();
config.sourceMap = wasmFileMap.c_str();
config.debugInfoOutputFilePath = debugTarget.c_str();
config.expectInfoOutputFilePath = expectTarget.c_str();
config.targetName = wasmTarget.c_str();
const std::string wasmFileStr = wasmFile.string();
const std::string wasmFileMapStr = wasmFileMap.string();
const std::string debugTargetStr = debugTarget.string();
const std::string expectTargetStr = expectTarget.string();
const std::string wasmTargetStr = wasmTarget.string();
config.fileName = wasmFileStr;
config.sourceMap = wasmFileMapStr;
config.debugInfoOutputFilePath = debugTargetStr;
config.expectInfoOutputFilePath = expectTargetStr;
config.targetName = wasmTargetStr;
config.reportFunction = traceFunName;
config.includes = include;
config.excludes = "";
Expand Down
10 changes: 5 additions & 5 deletions tests/ts/test/core/instrument.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ function cleanDirSync(path: string) {
test("Instrument", async () => {
cleanDirSync(outputDir);
await compile([fixturePath], { outputFolder: outputDir, flags: "--memoryBase 16 --exportTable", isolated: true });
const base = join(outputDir, "constructor");
const wasmPath = join(outputDir, "constructor.wasm");
const base = join(outputDir, "constructor").replaceAll(/\\/g, "/");
const wasmPath = base.concat(".wasm");
const sourceCodePath = "tests/ts/fixture/constructor.ts";
const results = await instrument([wasmPath], [sourceCodePath], true);
expect(results.length).toEqual(1);
const result = results[0]!;
const instrumentedWasm = join(outputDir, "constructor.instrumented.wasm");
const debugInfo = join(outputDir, "constructor.debugInfo.json");
const expectInfo = join(outputDir, "constructor.expectInfo.json");
const instrumentedWasm = base.concat(".instrumented.wasm");
const debugInfo = base.concat(".debugInfo.json");
const expectInfo = base.concat(".expectInfo.json");
expect(result.baseName).toEqual(base);
expect(result.sourceWasm).toEqual(wasmPath);
expect(result.instrumentedWasm).toEqual(instrumentedWasm);
Expand Down