181 lines
8.2 KiB
HTML
181 lines
8.2 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>xyzbc-trt browser smoke</title>
|
|
</head>
|
|
<body>
|
|
<pre id="result">xyzbc_trt_browser_smoke=pending</pre>
|
|
<iframe id="app-frame" title="xyzbc-trt app"></iframe>
|
|
<script type="module">
|
|
const result = document.querySelector("#result");
|
|
const frame = document.querySelector("#app-frame");
|
|
const appSrc = new URLSearchParams(window.location.search).get("app") || "../../app/index.html";
|
|
frame.src = appSrc;
|
|
|
|
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
|
async function runSmoke() {
|
|
await new Promise((resolve, reject) => {
|
|
frame.addEventListener("load", resolve, { once: true });
|
|
frame.addEventListener("error", reject, { once: true });
|
|
});
|
|
|
|
const win = frame.contentWindow;
|
|
const doc = frame.contentDocument;
|
|
const runtimeErrors = [];
|
|
win.addEventListener("error", (event) => {
|
|
runtimeErrors.push(event.message || String(event.error || "window error"));
|
|
});
|
|
win.addEventListener("unhandledrejection", (event) => {
|
|
runtimeErrors.push(event.reason?.message || String(event.reason || "unhandled rejection"));
|
|
});
|
|
|
|
await waitFor(() => win.webRtcp5AxisSimulation, "public simulation API");
|
|
const api = win.webRtcp5AxisSimulation;
|
|
const [kinematics, interpreter, taskHal] = await Promise.all([
|
|
api.kinematicsRuntimeReady,
|
|
api.interpreterRuntimeReady,
|
|
api.taskHalRuntimeReady,
|
|
]);
|
|
|
|
assertRuntime(kinematics, {
|
|
name: "kinematics",
|
|
moduleId: "xyzbc-trt",
|
|
required: ["loaded"],
|
|
});
|
|
if (kinematics.executionContext !== "worker") {
|
|
throw new Error(`kinematics runtime should run in worker: ${JSON.stringify(kinematics)}`);
|
|
}
|
|
assertRuntime(interpreter, {
|
|
name: "interpreter",
|
|
required: ["loaded", "runProgramReady", "plannerRuntimeReady"],
|
|
});
|
|
if (interpreter.executionContext !== "worker") {
|
|
throw new Error(`interpreter runtime should run in worker: ${JSON.stringify(interpreter)}`);
|
|
}
|
|
assertRuntime(taskHal, {
|
|
name: "task/HAL",
|
|
required: ["loaded", "taskRuntimeReady", "motionRuntimeReady", "halRuntimeReady"],
|
|
});
|
|
if (taskHal.executionContext !== "worker") {
|
|
throw new Error(`task/HAL runtime should run in worker: ${JSON.stringify(taskHal)}`);
|
|
}
|
|
|
|
await api.machineFileSeedReady;
|
|
await waitFor(() => {
|
|
const state = api.getState();
|
|
return !state.interpreterExecutionPending
|
|
&& state.programExecution?.sourceMode === "linuxcnc-interpreter-wasm"
|
|
&& state.machineFileStaging?.status === "staged";
|
|
}, "default xyzbc program preview");
|
|
|
|
const state = api.getState();
|
|
if (state.machineProfile !== "xyzbc-trt" || state.profile?.traj?.coordinates !== "XYZBC") {
|
|
throw new Error(`default profile mismatch: ${state.machineProfile}/${state.profile?.traj?.coordinates}`);
|
|
}
|
|
if (state.profile?.kinematicsModuleId !== "xyzbc-trt") {
|
|
throw new Error(`profile kinematics module mismatch: ${state.profile?.kinematicsModuleId}`);
|
|
}
|
|
if (state.machineFileStaging?.profileId !== "xyzbc-trt") {
|
|
throw new Error(`staging profile mismatch: ${state.machineFileStaging?.profileId}`);
|
|
}
|
|
if (!state.machineFileStaging?.gcodeSources?.some((source) => source.filename === "xyzbc_switchkins.ngc")) {
|
|
throw new Error("staged sources missing xyzbc_switchkins.ngc");
|
|
}
|
|
if (!state.machineFileStaging?.gcodeSources?.some((source) => source.filename === "boat-xyzbc.ngc")) {
|
|
throw new Error("staged sources missing boat-xyzbc.ngc");
|
|
}
|
|
if (state.programExecution?.summary?.motionEventCount < 1) {
|
|
throw new Error(`default program did not produce canonical motion: ${JSON.stringify(state.programExecution?.summary)}`);
|
|
}
|
|
|
|
const canvas = await waitFor(() => doc.querySelector("[data-five-axis-canvas]"), "preview canvas");
|
|
await waitFor(() => canvas.dataset.threeReady === "true" && Number(canvas.dataset.threePathPoints || 0) > 0, "Three.js dataset");
|
|
if (
|
|
canvas.dataset.threeRenderer !== "webgl" ||
|
|
canvas.dataset.threeFrameApi !== "web-rtcp-5axis-motion-frame" ||
|
|
canvas.dataset.threeSceneMode !== "program-preview-and-tool-execution" ||
|
|
canvas.dataset.threeMachineReferenceModel !== "webgl-five-axis-reference" ||
|
|
canvas.dataset.threePreviewScope !== "machine-reference-and-toolpath" ||
|
|
canvas.dataset.threeProgramPreviewSource !== "linuxcnc-interpreter-wasm" ||
|
|
canvas.dataset.threeVismachPinDrivenModel !== "web_threejs_vismach_equivalent_driven_by_xyzbc_trt_hal_pins"
|
|
) {
|
|
throw new Error(`unexpected canvas dataset: ${JSON.stringify(canvas.dataset)}`);
|
|
}
|
|
if (Number(canvas.dataset.threeSceneObjects || 0) < 12) {
|
|
throw new Error(`scene object count too low: ${canvas.dataset.threeSceneObjects}`);
|
|
}
|
|
const vismachPins = JSON.parse(canvas.dataset.threeVismachPins || "{}");
|
|
for (const pin of ["table-x", "saddle-y", "spindle-z", "tilt-b", "rotate-c", "tool-offset", "x-offset", "z-offset"]) {
|
|
if (!Number.isFinite(Number(vismachPins[pin]))) {
|
|
throw new Error(`missing Vismach pin ${pin}: ${JSON.stringify(vismachPins)}`);
|
|
}
|
|
}
|
|
const vismachTransforms = JSON.parse(canvas.dataset.threeVismachTransforms || "{}");
|
|
if (
|
|
vismachTransforms.table?.sourcePins?.[0] !== "table-x" ||
|
|
vismachTransforms.saddle?.sourcePins?.[0] !== "saddle-y" ||
|
|
vismachTransforms.spindle?.sourcePins?.[0] !== "spindle-z" ||
|
|
vismachTransforms.tilt?.sourcePins?.[0] !== "tilt-b" ||
|
|
vismachTransforms.rotary?.sourcePins?.[0] !== "rotate-c" ||
|
|
!vismachTransforms.tool?.sourcePins?.includes("tool-offset")
|
|
) {
|
|
throw new Error(`Vismach transform source pins mismatch: ${JSON.stringify(vismachTransforms)}`);
|
|
}
|
|
assertCanvasNonblank(canvas);
|
|
|
|
if (runtimeErrors.length > 0) {
|
|
throw new Error(`runtime errors: ${runtimeErrors.join(" | ")}`);
|
|
}
|
|
result.textContent = "xyzbc_trt_browser_smoke=ok";
|
|
}
|
|
|
|
function assertRuntime(readiness, { name, moduleId = null, required }) {
|
|
for (const key of required) {
|
|
if (readiness?.[key] !== true) {
|
|
throw new Error(`${name} runtime missing ${key}: ${JSON.stringify(readiness)}`);
|
|
}
|
|
}
|
|
if (moduleId && readiness?.moduleId !== moduleId) {
|
|
throw new Error(`${name} runtime module mismatch: ${JSON.stringify(readiness)}`);
|
|
}
|
|
}
|
|
|
|
async function waitFor(predicate, label) {
|
|
for (let attempt = 0; attempt < 240; attempt += 1) {
|
|
const value = predicate();
|
|
if (value) return value;
|
|
await wait(50);
|
|
}
|
|
throw new Error(`timed out waiting for ${label}`);
|
|
}
|
|
|
|
function assertCanvasNonblank(canvas) {
|
|
const context = canvas.getContext("webgl2") || canvas.getContext("webgl") || canvas.getContext("2d");
|
|
if (!context) {
|
|
throw new Error("preview canvas has no readable context");
|
|
}
|
|
const width = canvas.width;
|
|
const height = canvas.height;
|
|
if (width <= 0 || height <= 0) {
|
|
throw new Error(`preview canvas has invalid size ${width}x${height}`);
|
|
}
|
|
if (context.readPixels) {
|
|
const pixels = new Uint8Array(4);
|
|
context.readPixels(Math.floor(width / 2), Math.floor(height / 2), 1, 1, context.RGBA, context.UNSIGNED_BYTE, pixels);
|
|
if (pixels.some((value) => value !== 0)) return;
|
|
}
|
|
const imageData = canvas.toDataURL("image/png");
|
|
if (!imageData || imageData.length < 2000) {
|
|
throw new Error("preview canvas appears blank");
|
|
}
|
|
}
|
|
|
|
runSmoke().catch((error) => {
|
|
result.textContent = `xyzbc_trt_browser_smoke=fail ${error.stack || error.message || error}`;
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|