增加解释器WASM文件入口
结论:解释器核心WASM新增基于LinuxCNC Interp::open/read/execute的文件运行入口,并覆盖file_open_reset、percent_file_finish和oword_subroutine夹具。
This commit is contained in:
@@ -27,6 +27,29 @@ function runProgram(mod, programText) {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
function verifyExpectedOutput(fixtureName, output, expectedText) {
|
||||
const expectedLines = expectedText.split("\n").filter(Boolean);
|
||||
|
||||
@@ -110,4 +133,26 @@ for (const fixtureName of errorFixtureNames) {
|
||||
|
||||
verifyExpectedOutput(fixtureName, runProgram(interp, programText), expectedOutput);
|
||||
}
|
||||
|
||||
const fileFixtureNames = [
|
||||
"file_open_reset",
|
||||
"percent_file_finish",
|
||||
"oword_subroutine",
|
||||
];
|
||||
|
||||
ensureDir(interp, "/work");
|
||||
for (const fixtureName of fileFixtureNames) {
|
||||
const programPath = `/work/${fixtureName}.ngc`;
|
||||
const programText = readFileSync(
|
||||
resolve(rootDir, `tests/fixtures/gcode/${fixtureName}.ngc`),
|
||||
"utf8",
|
||||
);
|
||||
const expectedEvents = readFileSync(
|
||||
resolve(rootDir, `tests/fixtures/canon/${fixtureName}.events`),
|
||||
"utf8",
|
||||
).trimEnd();
|
||||
|
||||
interp.FS.writeFile(programPath, programText, { encoding: "utf8" });
|
||||
verifyExpectedOutput(fixtureName, runFile(interp, programPath), expectedEvents);
|
||||
}
|
||||
console.log("interp_wasm_node_smoke=ok");
|
||||
|
||||
Reference in New Issue
Block a user