按规划继续工作
结论:解释器 WASM、SDK 统一入口、浏览器解释器 smoke 与兼容性文档已闭环,native 和 host/WASM/browser 验证全部通过。
This commit is contained in:
@@ -3,69 +3,7 @@ import { fileURLToPath } from "node:url";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import createLinuxCncInterpModule from "../../../build/wasm/core/linuxcnc_interp.js";
|
||||
|
||||
function allocCString(mod, value) {
|
||||
const bytes = mod.lengthBytesUTF8(value) + 1;
|
||||
const ptr = mod._malloc(bytes);
|
||||
mod.stringToUTF8(value, ptr, bytes);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
function runProgram(mod, programText) {
|
||||
const programPtr = allocCString(mod, programText);
|
||||
let resultPtr = 0;
|
||||
try {
|
||||
resultPtr = mod._lcinterp_run_program(programPtr);
|
||||
assert.notEqual(resultPtr, 0);
|
||||
return mod.UTF8ToString(resultPtr);
|
||||
} finally {
|
||||
if (resultPtr) {
|
||||
mod._lcinterp_free_string(resultPtr);
|
||||
}
|
||||
mod._free(programPtr);
|
||||
}
|
||||
}
|
||||
|
||||
function runProgramWithIni(mod, programText, iniPath) {
|
||||
const programPtr = allocCString(mod, programText);
|
||||
const iniPathPtr = allocCString(mod, iniPath);
|
||||
let resultPtr = 0;
|
||||
try {
|
||||
resultPtr = mod._lcinterp_run_program_with_ini(programPtr, iniPathPtr);
|
||||
assert.notEqual(resultPtr, 0);
|
||||
return mod.UTF8ToString(resultPtr);
|
||||
} finally {
|
||||
if (resultPtr) {
|
||||
mod._lcinterp_free_string(resultPtr);
|
||||
}
|
||||
mod._free(programPtr);
|
||||
mod._free(iniPathPtr);
|
||||
}
|
||||
}
|
||||
|
||||
function ensureDir(mod, path) {
|
||||
try {
|
||||
mod.FS.mkdir(path);
|
||||
} catch {
|
||||
// Directory already exists.
|
||||
}
|
||||
}
|
||||
|
||||
function runFile(mod, path) {
|
||||
const pathPtr = allocCString(mod, path);
|
||||
let resultPtr = 0;
|
||||
try {
|
||||
resultPtr = mod._lcinterp_run_file(pathPtr);
|
||||
assert.notEqual(resultPtr, 0);
|
||||
return mod.UTF8ToString(resultPtr);
|
||||
} finally {
|
||||
if (resultPtr) {
|
||||
mod._lcinterp_free_string(resultPtr);
|
||||
}
|
||||
mod._free(pathPtr);
|
||||
}
|
||||
}
|
||||
import { createLinuxCncInterpSdk } from "../../../runtime/sdk/src/index.js";
|
||||
|
||||
function verifyExpectedOutput(fixtureName, output, expectedText) {
|
||||
const expectedLines = expectedText.split("\n").filter(Boolean);
|
||||
@@ -94,7 +32,7 @@ const __dirname = dirname(__filename);
|
||||
const rootDir = resolve(__dirname, "../../..");
|
||||
const wasmPath = resolve(rootDir, "build/wasm/core/linuxcnc_interp.wasm");
|
||||
|
||||
const interp = await createLinuxCncInterpModule({
|
||||
const interp = await createLinuxCncInterpSdk({
|
||||
wasmBinary: readFileSync(wasmPath),
|
||||
print() {},
|
||||
printErr(message) {
|
||||
@@ -139,15 +77,13 @@ for (const fixtureName of fixtureNames) {
|
||||
"utf8",
|
||||
).trimEnd();
|
||||
|
||||
verifyExpectedOutput(fixtureName, runProgram(interp, programText), expectedEvents);
|
||||
verifyExpectedOutput(fixtureName, interp.runProgram(programText), expectedEvents);
|
||||
}
|
||||
|
||||
ensureDir(interp, "/work");
|
||||
const namedParamIniPath = "/work/namedparams.ini";
|
||||
interp.FS.writeFile(
|
||||
interp.writeTextFile(
|
||||
namedParamIniPath,
|
||||
readFileSync(resolve(rootDir, "tests/fixtures/ini/namedparams.ini"), "utf8"),
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
const namedParamProgramText = readFileSync(
|
||||
resolve(rootDir, "tests/fixtures/gcode/namedparam_semantics.ngc"),
|
||||
@@ -159,7 +95,7 @@ const namedParamExpected = readFileSync(
|
||||
).trimEnd();
|
||||
verifyExpectedOutput(
|
||||
"namedparam_semantics",
|
||||
runProgramWithIni(interp, namedParamProgramText, namedParamIniPath),
|
||||
interp.runProgramWithIni(namedParamProgramText, namedParamIniPath),
|
||||
namedParamExpected,
|
||||
);
|
||||
|
||||
@@ -185,7 +121,7 @@ for (const fixtureName of errorFixtureNames) {
|
||||
"utf8",
|
||||
).trimEnd();
|
||||
|
||||
verifyExpectedOutput(fixtureName, runProgram(interp, programText), expectedOutput);
|
||||
verifyExpectedOutput(fixtureName, interp.runProgram(programText), expectedOutput);
|
||||
}
|
||||
|
||||
const fileFixtureNames = [
|
||||
@@ -228,7 +164,29 @@ for (const fixtureName of fileFixtureNames) {
|
||||
"utf8",
|
||||
).trimEnd();
|
||||
|
||||
interp.FS.writeFile(programPath, programText, { encoding: "utf8" });
|
||||
verifyExpectedOutput(fixtureName, runFile(interp, programPath), expectedEvents);
|
||||
interp.writeTextFile(programPath, programText);
|
||||
verifyExpectedOutput(fixtureName, interp.runFile(programPath), expectedEvents);
|
||||
}
|
||||
|
||||
const namedParamFilePath = "/work/namedparam_semantics.ngc";
|
||||
interp.writeTextFile(namedParamFilePath, namedParamProgramText);
|
||||
verifyExpectedOutput(
|
||||
"namedparam_semantics_file",
|
||||
interp.runFileWithIni(namedParamFilePath, namedParamIniPath),
|
||||
namedParamExpected,
|
||||
);
|
||||
|
||||
const positionParamsFilePath = "/work/position_params.ngc";
|
||||
interp.writeTextFile(
|
||||
positionParamsFilePath,
|
||||
readFileSync(resolve(rootDir, "tests/fixtures/gcode/position_params.ngc"), "utf8"),
|
||||
);
|
||||
verifyExpectedOutput(
|
||||
"position_params_file",
|
||||
interp.runFile(positionParamsFilePath),
|
||||
readFileSync(
|
||||
resolve(rootDir, "tests/fixtures/canon_file/position_params.events"),
|
||||
"utf8",
|
||||
).trimEnd(),
|
||||
);
|
||||
console.log("interp_wasm_node_smoke=ok");
|
||||
|
||||
Reference in New Issue
Block a user