按建议,继续完成后续工作
结论:已新增 INI WASM Node smoke 验证,确认 vendored LinuxCNC inifile.cc 构建出的 WASM 模块可通过导出 C ABI 查询 INI 内容,并同步更新兼容性与漂移文档。
This commit is contained in:
77
wasm-port/tests/wasm/node/verify_ini_wasm.mjs
Normal file
77
wasm-port/tests/wasm/node/verify_ini_wasm.mjs
Normal file
@@ -0,0 +1,77 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import createLinuxCncIniModule from "../../../runtime/ui/ini-panel/linuxcnc_ini.js";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const rootDir = resolve(__dirname, "../../..");
|
||||
const wasmPath = resolve(rootDir, "runtime/ui/ini-panel/linuxcnc_ini.wasm");
|
||||
|
||||
const mod = await createLinuxCncIniModule({
|
||||
wasmBinary: readFileSync(wasmPath),
|
||||
print() {},
|
||||
printErr(message) {
|
||||
console.error(message);
|
||||
},
|
||||
});
|
||||
|
||||
function allocCString(value) {
|
||||
const bytes = mod.lengthBytesUTF8(value) + 1;
|
||||
const ptr = mod._malloc(bytes);
|
||||
mod.stringToUTF8(value, ptr, bytes);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
function queryIni(path, section, tag) {
|
||||
const pathPtr = allocCString(path);
|
||||
const sectionPtr = allocCString(section);
|
||||
const tagPtr = allocCString(tag);
|
||||
const outSize = 256;
|
||||
const outPtr = mod._malloc(outSize);
|
||||
|
||||
try {
|
||||
const rc = mod._lcini_get_string(pathPtr, sectionPtr, tagPtr, outPtr, outSize);
|
||||
return { rc, value: rc === 0 ? mod.UTF8ToString(outPtr) : null };
|
||||
} finally {
|
||||
mod._free(pathPtr);
|
||||
mod._free(sectionPtr);
|
||||
mod._free(tagPtr);
|
||||
mod._free(outPtr);
|
||||
}
|
||||
}
|
||||
|
||||
mod.FS.mkdir("/work");
|
||||
mod.FS.writeFile(
|
||||
"/work/node-smoke.ini",
|
||||
`[EMC]
|
||||
MACHINE = wasm-node-smoke
|
||||
|
||||
[TRAJ]
|
||||
LINEAR_UNITS = mm
|
||||
COORDINATES = X Y Z A B
|
||||
|
||||
[KINS]
|
||||
KINEMATICS = xyzbc-trt-kins
|
||||
JOINTS = 5
|
||||
`,
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
|
||||
assert.deepEqual(queryIni("/work/node-smoke.ini", "EMC", "MACHINE"), {
|
||||
rc: 0,
|
||||
value: "wasm-node-smoke",
|
||||
});
|
||||
assert.deepEqual(queryIni("/work/node-smoke.ini", "TRAJ", "LINEAR_UNITS"), {
|
||||
rc: 0,
|
||||
value: "mm",
|
||||
});
|
||||
assert.deepEqual(queryIni("/work/node-smoke.ini", "KINS", "KINEMATICS"), {
|
||||
rc: 0,
|
||||
value: "xyzbc-trt-kins",
|
||||
});
|
||||
assert.notEqual(queryIni("/work/node-smoke.ini", "TRAJ", "MISSING").rc, 0);
|
||||
|
||||
console.log("ini_wasm_node_smoke=ok");
|
||||
7
wasm-port/tests/wasm/node/verify_ini_wasm.sh
Executable file
7
wasm-port/tests/wasm/node/verify_ini_wasm.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "$0")/../../.." && pwd)"
|
||||
|
||||
"$ROOT_DIR/tools/build_ini_panel.sh"
|
||||
node "$ROOT_DIR/tests/wasm/node/verify_ini_wasm.mjs"
|
||||
Reference in New Issue
Block a user