Complete 3axis tutorial native and Web/WASM parity tools
This commit is contained in:
26
web/worker/test_wasm_preview.mjs
Normal file
26
web/worker/test_wasm_preview.mjs
Normal file
@@ -0,0 +1,26 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import createModule from "../../build-wasm/linuxcnc-sim-core.js";
|
||||
import { SimSession, CONTEXT_ID } from "./sim-session.mjs";
|
||||
|
||||
const sourcePath = "linuxcnc/nc_files/3dtest.ngc";
|
||||
const source = await readFile(new URL(`../../${sourcePath}`, import.meta.url), "utf8");
|
||||
const core = await createModule({ wasmBinary: await readFile(new URL("../../build-wasm/linuxcnc-sim-core.wasm", import.meta.url)) });
|
||||
const session = new SimSession(core, { sessionId: "wasm-preview" });
|
||||
const base = { schema_version: 1, context_id: CONTEXT_ID, session_id: session.sessionId };
|
||||
let sequence = 0;
|
||||
const send = (kind, operationId, payload = {}) => session.accept({ ...base, kind, seq: ++sequence, operation_id: operationId, payload });
|
||||
|
||||
send("HELLO", "hello");
|
||||
send("SESSION_ATTACH", "attach");
|
||||
send("LOAD_WORKSPACE", "workspace", { root_path: "/workspace" });
|
||||
const loaded = send("PROGRAM_LOAD", "program", { source, path: sourcePath });
|
||||
assert.equal(loaded.payload.preview?.status, "verified");
|
||||
const segments = loaded.payload.preview.segments;
|
||||
assert.equal(segments.length, 49);
|
||||
const arcs = segments.filter((segment) => [6, 23, 39].includes(segment.source_line));
|
||||
assert.equal(arcs.length, 3);
|
||||
assert.ok(arcs.every((segment) => segment.motion_type === 2));
|
||||
assert.deepEqual(arcs.map((segment) => segment.normal), [{ x: 0, y: 0, z: 1 }, { x: 0, y: 1, z: 0 }, { x: 1, y: 0, z: 0 }]);
|
||||
assert.ok(arcs.every((segment) => segment.source === "wasm_interpreter_canonical_motion"));
|
||||
console.log(JSON.stringify({ schema: "wasm-preview.v1", status: "verified", source_path: sourcePath, source_lines: source.split(/\r?\n/).length, segment_count: segments.length, arc_lines: [6, 23, 39], source: "wasm_interpreter_canonical_motion" }));
|
||||
Reference in New Issue
Block a user