diff --git a/.github/action/setup-ccache/action.yml b/.github/action/setup-ccache/action.yml index 6130c0f..fd92c88 100644 --- a/.github/action/setup-ccache/action.yml +++ b/.github/action/setup-ccache/action.yml @@ -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 diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index ae84066..b923ab0 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -7,7 +7,7 @@ on: - main jobs: - test: + Linux_test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -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 diff --git a/scripts/build_instrumentation.js b/scripts/build_instrumentation.js index 9c4dc85..4585e4b 100644 --- a/scripts/build_instrumentation.js +++ b/scripts/build_instrumentation.js @@ -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", diff --git a/tests/cpp/CMakeLists.txt b/tests/cpp/CMakeLists.txt index 614a74b..34c2d43 100644 --- a/tests/cpp/CMakeLists.txt +++ b/tests/cpp/CMakeLists.txt @@ -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 diff --git a/tests/cpp/fuzz.cpp b/tests/cpp/fuzz.cpp index c3077a6..febd898 100644 --- a/tests/cpp/fuzz.cpp +++ b/tests/cpp/fuzz.cpp @@ -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); diff --git a/tests/cpp/lit.cpp b/tests/cpp/lit.cpp index c897670..b59e8d6 100644 --- a/tests/cpp/lit.cpp +++ b/tests/cpp/lit.cpp @@ -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"); @@ -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 = ""; @@ -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 = ""; diff --git a/tests/ts/test/core/instrument.test.ts b/tests/ts/test/core/instrument.test.ts index 6989ef4..6f48e61 100644 --- a/tests/ts/test/core/instrument.test.ts +++ b/tests/ts/test/core/instrument.test.ts @@ -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);