118 lines
4.1 KiB
HTML
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>
|