Files
wasm-simulator/web/test-browser-wasm-smoke.html
cnc 1498d9830d 继续推进:浏览器批量验证LinuxCNC配置入口
结论:浏览器 WASM smoke 已读取 LinuxCNC 生成的 64 个 switchkins 配置用例,覆盖 config/MACHINE/KINEMATICS/HALFILE 入口;native 与 source-link 验证通过。
2026-05-30 10:19:32 +08:00

88 lines
3.4 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>CNC WASM Browser Smoke</title>
</head>
<body>
<pre id="result">pending</pre>
<script src="/public/cnc_sim.js"></script>
<script type="module">
import { createWasmSimulator } from "/src/wasm-core.js";
const result = document.querySelector("#result");
const near = (actual, expected) => Math.abs(actual - expected) < 1e-6;
try {
const simulator = await createWasmSimulator({
locateFile: (file) => `/public/${file}`,
print: () => {},
printErr: () => {},
});
try {
const events = simulator.parse("G21 G90\nG0 X0\nG1 X5 F100\nM30\n", "linuxcnc", {
backend: "linuxcnc-rs274",
});
const sawFeed = events.some((event) => event.type === "linear-feed" && near(event.end.x, 5));
const sawEnd = events.some((event) => event.type === "program-end");
if (!sawFeed || !sawEnd) {
throw new Error("missing expected LinuxCNC WASM browser events");
}
const switchEvents = simulator.parse("M428\nM429\nM430\n", "linuxcnc", {
backend: "linuxcnc-rs274",
switchkins: "scara",
});
for (const [line, kinstype] of [
[1, 0],
[2, 1],
[3, 2],
]) {
const sawSwitch = switchEvents.some(
(event) => event.type === "kinematics-switch" && event.line === line && event.reserved === kinstype,
);
if (!sawSwitch) {
throw new Error(`missing LinuxCNC WASM browser M${427 + line} switchkins type ${kinstype}`);
}
}
const configCaseResponse = await fetch("/public/linuxcnc_switchkins_remap_config_cases.json");
if (!configCaseResponse.ok) {
throw new Error(`failed to load LinuxCNC switchkins config cases: ${configCaseResponse.status}`);
}
const configCases = await configCaseResponse.json();
if (!Array.isArray(configCases) || configCases.length === 0) {
throw new Error("missing LinuxCNC switchkins config cases");
}
for (const configCase of configCases) {
const options = {
backend: "linuxcnc-rs274",
[configCase.field]: configCase.value,
};
const program = configCase.m430 >= 0 ? "M428\nM429\nM430\n" : "M428\nM429\n";
const configEvents = simulator.parse(program, "linuxcnc", options);
for (const [line, kinstype] of [
[1, configCase.m428],
[2, configCase.m429],
...(configCase.m430 >= 0 ? [[3, configCase.m430]] : []),
]) {
const sawSwitch = configEvents.some(
(event) => event.type === "kinematics-switch" && event.line === line && event.reserved === kinstype,
);
if (!sawSwitch) {
throw new Error(
`missing LinuxCNC WASM browser generated ${configCase.field}=${configCase.value} line ${line} switchkins type ${kinstype}`,
);
}
}
}
result.textContent = "browser wasm smoke passed";
} finally {
simulator.dispose();
}
} catch (error) {
result.textContent = `browser wasm smoke failed: ${error && error.stack ? error.stack : error}`;
}
</script>
</body>
</html>