Files
cnc_wams/wasm-port/tests/browser/interp_smoke.html
wangdequan e5697970df 按规划继续工作
结论:解释器 Node WASM 与浏览器 smoke 已统一使用共享 fixture 矩阵,聚合 host/WASM/browser 验证通过。
2026-06-08 07:28:50 +08:00

118 lines
4.1 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>LinuxCNC Interpreter Browser Smoke</title>
</head>
<body>
<pre id="status">running</pre>
<script type="module">
import { createLinuxCncInterpSdk } from "../../runtime/sdk/src/index.js";
import {
INTERP_BROWSER_FILE_FIXTURES,
INTERP_BROWSER_MDI_FIXTURES,
INTERP_ERROR_FIXTURES,
INTERP_INI_FIXTURE,
INTERP_POSITION_PARAMS_FILE_FIXTURE,
} from "../fixtures/interp-fixture-matrix.mjs";
const status = document.getElementById("status");
async function fetchText(path) {
const response = await fetch(path);
if (!response.ok) {
throw new Error(`${path}: HTTP ${response.status}`);
}
return response.text();
}
function verifyExpectedOutput(fixtureName, output, expectedText) {
const expectedLines = expectedText.split("\n").filter(Boolean);
for (const expectedLine of expectedLines) {
if (expectedLine.startsWith("absent=")) {
const forbidden = expectedLine.slice("absent=".length);
if (output.includes(forbidden)) {
throw new Error(`${fixtureName}: unexpected ${forbidden}`);
}
continue;
}
if (!output.includes(expectedLine)) {
throw new Error(`${fixtureName}: missing ${expectedLine}`);
}
}
}
try {
const interp = await createLinuxCncInterpSdk({
locateFile(path) {
if (path === "linuxcnc_interp.wasm") {
return "../../build/wasm/core/linuxcnc_interp.wasm";
}
return path;
},
print() {},
printErr(message) {
console.error(message);
},
});
for (const fixtureName of INTERP_BROWSER_MDI_FIXTURES) {
const programText = await fetchText(`../fixtures/gcode/${fixtureName}.ngc`);
const expectedText = await fetchText(`../fixtures/canon/${fixtureName}.events`);
verifyExpectedOutput(fixtureName, interp.runProgram(programText), expectedText.trimEnd());
}
for (const errorFixtureName of INTERP_ERROR_FIXTURES) {
verifyExpectedOutput(
errorFixtureName,
interp.runProgram(await fetchText(`../fixtures/gcode_errors/${errorFixtureName}.ngc`)),
(await fetchText(`../fixtures/canon_errors/${errorFixtureName}.expected`)).trimEnd(),
);
}
const positionParamsText = await fetchText(
`../fixtures/gcode/${INTERP_POSITION_PARAMS_FILE_FIXTURE}.ngc`,
);
const positionParamsPath = `/work/${INTERP_POSITION_PARAMS_FILE_FIXTURE}.ngc`;
interp.writeTextFile(positionParamsPath, positionParamsText);
verifyExpectedOutput(
`${INTERP_POSITION_PARAMS_FILE_FIXTURE}_file`,
interp.runFile(positionParamsPath),
(
await fetchText(
`../fixtures/canon_file/${INTERP_POSITION_PARAMS_FILE_FIXTURE}.events`,
)
).trimEnd(),
);
for (const fileFixtureName of INTERP_BROWSER_FILE_FIXTURES) {
const programPath = `/work/${fileFixtureName}.ngc`;
interp.writeTextFile(programPath, await fetchText(`../fixtures/gcode/${fileFixtureName}.ngc`));
verifyExpectedOutput(
`${fileFixtureName}_file`,
interp.runFile(programPath),
(await fetchText(`../fixtures/canon/${fileFixtureName}.events`)).trimEnd(),
);
}
const namedParamIniPath = "/work/namedparams.ini";
interp.writeTextFile(namedParamIniPath, await fetchText("../fixtures/ini/namedparams.ini"));
const namedParamPath = `/work/${INTERP_INI_FIXTURE}.ngc`;
interp.writeTextFile(
namedParamPath,
await fetchText(`../fixtures/gcode/${INTERP_INI_FIXTURE}.ngc`),
);
verifyExpectedOutput(
`${INTERP_INI_FIXTURE}_file`,
interp.runFileWithIni(namedParamPath, namedParamIniPath),
(await fetchText(`../fixtures/canon/${INTERP_INI_FIXTURE}.events`)).trimEnd(),
);
status.textContent = "browser_interp_smoke=ok";
} catch (error) {
status.textContent = `browser_interp_smoke=fail ${error.stack || error.message}`;
}
</script>
</body>
</html>