Expand LinuxCNC smoke coverage

This commit is contained in:
cnc
2026-05-22 15:11:28 +08:00
parent 44e024e49c
commit 0ff0058417
17 changed files with 3507 additions and 70 deletions

View File

@@ -136,14 +136,21 @@ bool execute_line(InterpBase *interp,
cnc_sim_linuxcnc_set_current_line(line_number);
std::vector<SimulatorGcodeControlAction> control_actions;
if (parse_simulator_gcode_control_line(line, &control_actions)) {
bool simulator_only_line = true;
for (const auto &action : control_actions) {
emit_simulator_gcode_control_action(sink, action, line_number);
if (action.kind == SimulatorGcodeControlKind::RtcpState &&
!action.rtcp_enabled) {
simulator_only_line = false;
}
if (sink.callback_aborted()) {
std::cerr << "event callback aborted parsing\n";
return false;
}
}
return true;
if (simulator_only_line) {
return true;
}
}
if (trace_enabled()) {
@@ -183,6 +190,54 @@ bool execute_line(InterpBase *interp,
return true;
}
bool execute_open_file(InterpBase *interp, const char *path) {
if (trace_enabled()) {
std::cerr << "rs274:open " << path << '\n';
}
int rc = interp->open(path);
if (rc != 0) {
char error[1024]{};
interp->error_text(rc, error, sizeof(error));
std::cerr << "open failed: " << error << '\n';
return false;
}
bool ok = true;
bool program_done = false;
while (!program_done) {
rc = interp->read();
if (rc == INTERP_ENDFILE || rc == INTERP_EXIT) {
break;
}
if (rc != 0) {
char error[1024]{};
interp->error_text(rc, error, sizeof(error));
std::cerr << "read failed: " << error << '\n';
ok = false;
break;
}
cnc_sim_linuxcnc_set_current_line(interp->line());
if (trace_enabled()) {
std::cerr << "rs274:execute file line " << interp->line() << '\n';
}
rc = interp->execute();
if (rc == INTERP_EXIT || rc == INTERP_ENDFILE) {
program_done = true;
} else if (rc == INTERP_EXECUTE_FINISH || rc == INTERP_OK) {
continue;
} else {
char error[1024]{};
interp->error_text(rc, error, sizeof(error));
std::cerr << "execute failed: " << error << '\n';
ok = false;
break;
}
}
interp->close();
return ok;
}
void init_minimal_tooldata() {
tool_mmap_creator(nullptr, 0);
tooldata_reset();
@@ -202,7 +257,10 @@ void init_minimal_tooldata() {
} // namespace
int main(int argc, char **argv) {
const std::string program = read_all(argc > 1 ? argv[1] : "-");
const bool use_file_mode = std::getenv("CNC_SIM_RS274_FILE_MODE") != nullptr &&
argc > 1 &&
std::string(argv[1]) != "-";
const std::string program = use_file_mode ? std::string{} : read_all(argc > 1 ? argv[1] : "-");
if (const char *parameter_file = std::getenv("CNC_SIM_RS274_VAR")) {
SET_PARAMETER_FILE_NAME(parameter_file);
}
@@ -230,16 +288,20 @@ int main(int argc, char **argv) {
std::cerr << "rs274:init done\n";
}
std::istringstream input(program);
std::string line;
bool ok = true;
bool program_done = false;
int line_number = 0;
while (!program_done && std::getline(input, line)) {
++line_number;
if (!execute_line(interp, sink, line, line_number, &program_done)) {
ok = false;
break;
if (use_file_mode) {
ok = execute_open_file(interp, argv[1]);
} else {
std::istringstream input(program);
std::string line;
bool program_done = false;
int line_number = 0;
while (!program_done && std::getline(input, line)) {
++line_number;
if (!execute_line(interp, sink, line, line_number, &program_done)) {
ok = false;
break;
}
}
}
std::cout << "\n]\n";