按源清理OPFS参数scratch
结论:依据 LinuxCNC rs274ngc_pre.cc restore_parameters() 只读取配置参数文件、interp_internal.hh 默认 rs274ngc.var/.bak 常量,浏览器 OPFS loadParameterFile 在加载存在的参数文件前清理 rs274ngc.var.new/.bak scratch,避免旧 WASM mirror 污染;缺失文件路径继续清空 scratch 并返回 null。 检查:./test-native.sh 通过;./test-linuxcnc-source-link.sh 通过。
This commit is contained in:
@@ -499,6 +499,7 @@ function installOpfsWorkspace(module, options) {
|
||||
assertRelativePath(path);
|
||||
try {
|
||||
const data = await readOpfsFile(workspacePath, path);
|
||||
cleanupLinuxCncParameterFiles(module);
|
||||
writeWasmFileReplacingPath(module, LINUXCNC_DEFAULT_PARAMETER_FILE, data);
|
||||
writeWasmFileReplacingPath(module, `/${LINUXCNC_DEFAULT_PARAMETER_FILE}`, data);
|
||||
return data;
|
||||
|
||||
@@ -3,6 +3,7 @@ export async function runBrowserOpfsParameterSections(context, simulator) {
|
||||
expectErrorContaining,
|
||||
expectEvent,
|
||||
expectIncludes,
|
||||
expectLinuxCncParameterScratchMissing,
|
||||
expectMissingOpfsFile,
|
||||
expectMissingWasmPath,
|
||||
expectNoEvent,
|
||||
@@ -11,12 +12,19 @@ export async function runBrowserOpfsParameterSections(context, simulator) {
|
||||
expectWasmFilesMissing,
|
||||
near,
|
||||
readOpfsText,
|
||||
readWasmText,
|
||||
removeWasmPathIfExists,
|
||||
runSection,
|
||||
withSmokeSimulator,
|
||||
} = context;
|
||||
const backend = { backend: "linuxcnc-rs274" };
|
||||
const parseWithParameters = (program, path) => simulator.parseWithParameterFile(program, path, "linuxcnc", backend);
|
||||
const g28BranchProgram = "G21 G90\nF100\nO10 if [#5161 EQ 1]\nG1 X9\nO10 endif\n";
|
||||
const writeDefaultScratch = (main, temporary, backup) => {
|
||||
simulator.fs.module.FS.writeFile("rs274ngc.var", main);
|
||||
simulator.fs.module.FS.writeFile("rs274ngc.var.new", temporary);
|
||||
simulator.fs.module.FS.writeFile("rs274ngc.var.bak", backup);
|
||||
};
|
||||
|
||||
await runSection("opfs parameter save", async () => {
|
||||
await simulator.parseWithParameterFile("G21 G90\nG0 X1\nG28.1\nM30\n", "parameters/rs274ngc.var", "linuxcnc", backend);
|
||||
@@ -263,37 +271,23 @@ export async function runBrowserOpfsParameterSections(context, simulator) {
|
||||
|
||||
await runSection("opfs stale parameter state cleanup", async () => {
|
||||
await simulator.fs.opfs.writeFile("parameters/stale-state.var", "5161\t1.000000\n");
|
||||
const staleStateEvents = await simulator.parseWithParameterFile(
|
||||
"G21 G90\nF100\nO10 if [#5161 EQ 1]\nG1 X9\nO10 endif\n",
|
||||
"parameters/stale-state.var",
|
||||
"linuxcnc",
|
||||
backend,
|
||||
);
|
||||
expectEvent(staleStateEvents, (event) => event.type === "linear-feed" && near(event.end.x, 9),
|
||||
"LinuxCNC did not honor the loaded OPFS parameter state");
|
||||
const staleStateEvents = await simulator.parseWithParameterFile(g28BranchProgram, "parameters/stale-state.var", "linuxcnc", backend);
|
||||
expectEvent(staleStateEvents, (event) => event.type === "linear-feed" && near(event.end.x, 9), "LinuxCNC did not honor the loaded OPFS parameter state");
|
||||
await simulator.fs.opfs.removeFile("parameters/stale-state.var");
|
||||
const missingStateEvents = await simulator.parseWithParameterFile(
|
||||
"G21 G90\nF100\nO10 if [#5161 EQ 1]\nG1 X9\nO10 endif\n",
|
||||
"parameters/stale-state.var",
|
||||
"linuxcnc",
|
||||
backend,
|
||||
);
|
||||
expectNoEvent(missingStateEvents, (event) => event.type === "linear-feed" && near(event.end.x, 9),
|
||||
"LinuxCNC stale OPFS parameter state was not cleared when the file was missing");
|
||||
// LinuxCNC source basis: rs274ngc_pre.cc restore_parameters()
|
||||
// treats a missing parameter file as OK; the browser OPFS bridge
|
||||
// must not leave stale default parameter files in the WASM mirror.
|
||||
simulator.fs.module.FS.writeFile("rs274ngc.var", "5161\t1.000000\n");
|
||||
simulator.fs.module.FS.writeFile("rs274ngc.var.new", "stale temporary parameter file\n");
|
||||
simulator.fs.module.FS.writeFile("rs274ngc.var.bak", "stale backup parameter file\n");
|
||||
const missingStateEvents = await simulator.parseWithParameterFile(g28BranchProgram, "parameters/stale-state.var", "linuxcnc", backend);
|
||||
expectNoEvent(missingStateEvents, (event) => event.type === "linear-feed" && near(event.end.x, 9), "LinuxCNC stale OPFS parameter state was not cleared when the file was missing");
|
||||
// LinuxCNC source basis: rs274ngc_pre.cc restore_parameters() ignores
|
||||
// missing files and reads only the configured parameter file.
|
||||
writeDefaultScratch("5161\t1.000000\n", "stale temporary parameter file\n", "stale backup parameter file\n");
|
||||
const missingLoad = await simulator.fs.opfs.loadParameterFile("parameters/load-missing.var");
|
||||
if (missingLoad !== null) {
|
||||
throw new Error("missing OPFS parameter file did not return null");
|
||||
}
|
||||
expectWasmFilesMissing(
|
||||
simulator.fs.module.FS,
|
||||
["rs274ngc.var", "rs274ngc.var.new", "rs274ngc.var.bak"],
|
||||
(parameterPath) => `missing OPFS parameter load left stale WASM file ${parameterPath}`,
|
||||
);
|
||||
expectLinuxCncParameterScratchMissing(simulator, (parameterPath) => `missing OPFS parameter load left stale WASM file ${parameterPath}`);
|
||||
writeDefaultScratch("5161\t7.000000\n", "stale successful-load temporary parameter file\n", "stale successful-load backup parameter file\n");
|
||||
await simulator.fs.opfs.writeFile("parameters/load-existing.var", "5161\t2.000000\n");
|
||||
await simulator.fs.opfs.loadParameterFile("parameters/load-existing.var");
|
||||
expectText(readWasmText(simulator, "rs274ngc.var"), "5161\t2.000000\n", "existing OPFS parameter load did not replace the LinuxCNC default parameter file");
|
||||
expectWasmFilesMissing(simulator.fs.module.FS, ["rs274ngc.var.new", "rs274ngc.var.bak"], (parameterPath) => `existing OPFS parameter load left stale WASM file ${parameterPath}`);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user