结论:接入 vendored LinuxCNC tooldata_common.cc 负责刀具表解析与保存,WASM/SDK/OPFS/UI 仅做运行时边界搬运;native、WASM、OPFS 和浏览器 smoke 验证已通过。
245 lines
7.7 KiB
HTML
245 lines
7.7 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 {
|
|
saveMachineParametersToOpfs,
|
|
} from "../../runtime/opfs/linuxcnc-parameter-bridge.js";
|
|
import {
|
|
saveMachineToolTableToOpfs,
|
|
} from "../../runtime/opfs/linuxcnc-tool-table-bridge.js";
|
|
import {
|
|
loadMachineSessionFromOpfs,
|
|
} from "../../runtime/opfs/linuxcnc-machine-session-bridge.js";
|
|
import {
|
|
loadMachineTextFiles,
|
|
saveMachineTextFiles,
|
|
} from "../../runtime/opfs/machine-file-store.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(),
|
|
);
|
|
|
|
await saveMachineTextFiles("browser-interp", {
|
|
ini: "[EMC]\nMACHINE = browser-interp\n",
|
|
toolTable: "T2 P7 Z3.125 D1.5 I12 J34 Q4 ;browser finish tool\n",
|
|
parameters: [
|
|
"5161 10.5",
|
|
"5162 20.25",
|
|
"5220 1",
|
|
"5221 2.25",
|
|
"5399 44",
|
|
"<_named_param> 123",
|
|
"",
|
|
].join("\n"),
|
|
});
|
|
const loadedSession = await loadMachineSessionFromOpfs(
|
|
interp,
|
|
"browser-interp",
|
|
{
|
|
iniWasmPath: "/work/browser-machine.ini",
|
|
parameterWasmPath: "/work/browser-linuxcnc.var",
|
|
toolTableWasmPath: "/work/browser-tool.tbl",
|
|
},
|
|
);
|
|
verifyExpectedOutput(
|
|
"opfs_restore_parameters",
|
|
loadedSession.parameters.result,
|
|
[
|
|
"restore_parameters=0",
|
|
"parameter_5161=10.5",
|
|
"parameter_5162=20.25",
|
|
"parameter_5221=2.25",
|
|
"parameter_5399=44",
|
|
].join("\n"),
|
|
);
|
|
verifyExpectedOutput(
|
|
"opfs_load_tool_table",
|
|
loadedSession.toolTable.result,
|
|
[
|
|
"tooldata_load=0",
|
|
"tool_1.toolno=2",
|
|
"tool_1.pocketno=7",
|
|
"tool_1.z=3.125",
|
|
"tool_1.diameter=1.5",
|
|
"tool_1.frontangle=12",
|
|
"tool_1.backangle=34",
|
|
"tool_1.orientation=4",
|
|
"tool_1.comment=browser finish tool",
|
|
"tool_index_for_tool_2=1",
|
|
].join("\n"),
|
|
);
|
|
const savedParameters = await saveMachineParametersToOpfs(
|
|
interp,
|
|
"browser-interp",
|
|
{
|
|
5161: 12.34,
|
|
5162: 56.78,
|
|
5220: 1.0,
|
|
5221: 9.87,
|
|
5399: 66.6,
|
|
},
|
|
{ wasmPath: "/work/browser-linuxcnc.var" },
|
|
);
|
|
verifyExpectedOutput(
|
|
"opfs_save_parameters",
|
|
savedParameters.result,
|
|
[
|
|
"save_parameters=0",
|
|
"parameter_5161=12.34",
|
|
"parameter_5162=56.78",
|
|
"parameter_5221=9.87",
|
|
"parameter_5399=66.6",
|
|
].join("\n"),
|
|
);
|
|
const machineFiles = await loadMachineTextFiles("browser-interp");
|
|
verifyExpectedOutput(
|
|
"opfs_saved_parameter_text",
|
|
machineFiles.parameters,
|
|
[
|
|
"5161\t12.340000",
|
|
"5162\t56.780000",
|
|
"5221\t9.870000",
|
|
"5399\t66.600000",
|
|
"absent=<_named_param>",
|
|
].join("\n"),
|
|
);
|
|
const savedToolTable = await saveMachineToolTableToOpfs(
|
|
interp,
|
|
"browser-interp",
|
|
{ wasmPath: "/work/browser-tool.tbl" },
|
|
);
|
|
verifyExpectedOutput(
|
|
"opfs_save_tool_table",
|
|
savedToolTable.result,
|
|
[
|
|
"tooldata_save=0",
|
|
"tool_1.toolno=2",
|
|
"tool_1.pocketno=7",
|
|
].join("\n"),
|
|
);
|
|
const savedMachineFiles = await loadMachineTextFiles("browser-interp");
|
|
verifyExpectedOutput(
|
|
"opfs_saved_tool_table_text",
|
|
savedMachineFiles.toolTable,
|
|
[
|
|
"T2",
|
|
"P7",
|
|
"Z+3.125000",
|
|
"D+1.500000",
|
|
"I+12.000000",
|
|
"J+34.000000",
|
|
"Q4",
|
|
";browser finish tool",
|
|
].join("\n"),
|
|
);
|
|
|
|
status.textContent = "browser_interp_smoke=ok";
|
|
} catch (error) {
|
|
status.textContent = `browser_interp_smoke=fail ${error.stack || error.message}`;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|