按源验证API百分号文件模式
源依据:LinuxCNC src/emc/rs274ngc/rs274ngc_pre.cc 的 Interp::open() 在首个非空行是 % 时启用 percent-file mode,src/emc/rs274ngc/interp_read.cc read_text() 在匹配 % 处结束读取并忽略后续文本。 结论:native API source-linked smoke 增加 CNC_SIM_RS274_FILE_MODE 下的百分号文件断言,确认 cnc_sim API 文件模式走 LinuxCNC open/read 语义而非逐行桥接或 smoke fallback。 检查:./test-linuxcnc-api-native.sh;./test-native.sh;./test-linuxcnc-source-link.sh。
This commit is contained in:
@@ -303,6 +303,45 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::vector<CncSimEvent> percent_events;
|
||||||
|
CncSimHandle *percent_sim = cnc_sim_create();
|
||||||
|
cnc_sim_set_event_callback(percent_sim, collect_event, &percent_events);
|
||||||
|
ScopedEnv file_mode_env("CNC_SIM_RS274_FILE_MODE", "1");
|
||||||
|
const char percent_program[] =
|
||||||
|
"%\n"
|
||||||
|
"G21 G90\n"
|
||||||
|
"F100\n"
|
||||||
|
"G1 X1\n"
|
||||||
|
"%\n"
|
||||||
|
"G1 X99\n";
|
||||||
|
bool percent_ok = true;
|
||||||
|
percent_ok &= expect(cnc_sim_parse_program(percent_sim,
|
||||||
|
percent_program,
|
||||||
|
sizeof(percent_program) - 1) == 0,
|
||||||
|
cnc_sim_last_error(percent_sim));
|
||||||
|
std::vector<int> feed_lines;
|
||||||
|
std::vector<double> feed_x;
|
||||||
|
for (const auto &event : percent_events) {
|
||||||
|
if (event.type == CNC_SIM_EVENT_LINEAR_FEED) {
|
||||||
|
feed_lines.push_back(event.line);
|
||||||
|
feed_x.push_back(event.end.x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// LinuxCNC source basis: rs274ngc_pre.cc open() enables percent-file
|
||||||
|
// mode when the first nonblank line is '%'; interp_read.cc read_text()
|
||||||
|
// stops at the matching '%', so later program text is ignored.
|
||||||
|
percent_ok &= expect(feed_lines.size() == 1 &&
|
||||||
|
feed_lines[0] == 4 &&
|
||||||
|
feed_x.size() == 1 &&
|
||||||
|
near(feed_x[0], 1.0),
|
||||||
|
"expected LinuxCNC percent-file mode to ignore trailing text");
|
||||||
|
cnc_sim_destroy(percent_sim);
|
||||||
|
if (!percent_ok) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const char config[] =
|
const char config[] =
|
||||||
"{\"backend\":\"linuxcnc-rs274\",\"rtcp\":{\"enabled\":true,\"toolLength\":100,\"toolLengths\":{\"7\":125}}}";
|
"{\"backend\":\"linuxcnc-rs274\",\"rtcp\":{\"enabled\":true,\"toolLength\":100,\"toolLengths\":{\"7\":125}}}";
|
||||||
const char program[] =
|
const char program[] =
|
||||||
|
|||||||
Reference in New Issue
Block a user