From 7fe7ea603821af49d5efabea0f9d748649aee660 Mon Sep 17 00:00:00 2001 From: cnc Date: Fri, 22 May 2026 17:54:44 +0800 Subject: [PATCH] Cover M-code states in source link tests --- docs/linuxcnc-porting.md | 1 + test-linuxcnc-source-link.sh | 58 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/docs/linuxcnc-porting.md b/docs/linuxcnc-porting.md index f0e3bee..5c02727 100644 --- a/docs/linuxcnc-porting.md +++ b/docs/linuxcnc-porting.md @@ -191,6 +191,7 @@ This matrix tracks LinuxCNC feature coverage for the web/WASM simulator. A featu | Tool length offset `G43/G49` | covered with nonzero tool-table offset through LinuxCNC native/source backends | `tests/gcode/linuxcnc_tool_length.ngc` | | RTCP controls `G43.4/G43.5/G49` | covered as simulator-owned control lines | `tests/gcode/linuxcnc_rtcp_controls.ngc` | | Kinematics switch `M428/M429/M430` | covered as simulator-owned control lines | `tests/gcode/linuxcnc_rtcp_controls.ngc` | +| Spindle, coolant, program stops, and current tool number `M3/M4/M5`, `M7/M8/M9`, `M0/M1/M60/M30`, `M61 Q...` | covered through LinuxCNC native/source backends | `tests/gcode/linuxcnc_spindle_direction.ngc`, `tests/gcode/linuxcnc_coolant.ngc`, `tests/gcode/linuxcnc_program_stops.ngc`, `tests/gcode/linuxcnc_tool_number.ngc` | | Feed and motion control modes `G93/G94/G95`, `G61/G61.1/G64` | covered through LinuxCNC native/source backends | `tests/gcode/linuxcnc_feed_modes.ngc`, `tests/gcode/linuxcnc_motion_modes.ngc` | | Canned cycle `G81/G80` | covered for drilling expand-to-canon path | `tests/gcode/linuxcnc_canned_cycle.ngc` | | Coordinate offset Canon events `G10 L2`, `G10 L20`, `G92/G92.1` | covered through LinuxCNC native/source backends | `tests/gcode/linuxcnc_coordinate_offsets.ngc`, `tests/gcode/linuxcnc_coordinate_l20.ngc` | diff --git a/test-linuxcnc-source-link.sh b/test-linuxcnc-source-link.sh index 0c3cc15..8b57f82 100755 --- a/test-linuxcnc-source-link.sh +++ b/test-linuxcnc-source-link.sh @@ -103,6 +103,18 @@ CNC_SIM_RS274_VAR="$var_file" \ CNC_SIM_RS274_VAR="$var_file" \ "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_rtcp_controls.ngc \ >/tmp/cnc_sim_linuxcnc_source_rtcp_controls.json +CNC_SIM_RS274_VAR="$var_file" \ + "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_spindle_direction.ngc \ + >/tmp/cnc_sim_linuxcnc_source_spindle_direction.json +CNC_SIM_RS274_VAR="$var_file" \ + "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_tool_number.ngc \ + >/tmp/cnc_sim_linuxcnc_source_tool_number.json +CNC_SIM_RS274_VAR="$var_file" \ + "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_program_stops.ngc \ + >/tmp/cnc_sim_linuxcnc_source_program_stops.json +CNC_SIM_RS274_VAR="$var_file" \ + "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_coolant.ngc \ + >/tmp/cnc_sim_linuxcnc_source_coolant.json CNC_SIM_RS274_VAR="$var_file" \ "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_feed_modes.ngc \ >/tmp/cnc_sim_linuxcnc_source_feed_modes.json @@ -169,6 +181,48 @@ rtcp = [event for event in controls if event["type"] == "rtcp-state"] if [(event["line"], event["tool"], event["feed"]) for event in rtcp] != [(3, 0, 0), (4, 7, 1)]: raise SystemExit("unexpected source-linked RTCP state sequence") +spindle = json.loads(Path("/tmp/cnc_sim_linuxcnc_source_spindle_direction.json").read_text()) +spindle_states = [ + (event["line"], event["spindle"], event["reserved"]) + for event in spindle + if event["type"] == "set-spindle" +] +if (2, 1200, 1) not in spindle_states: + raise SystemExit("missing source-linked M3 clockwise spindle state") +if (3, 1200, 2) not in spindle_states: + raise SystemExit("missing source-linked M4 counterclockwise spindle state") +if (4, 0, 0) not in spindle_states: + raise SystemExit("missing source-linked M5 stopped spindle state") + +tool_number = json.loads(Path("/tmp/cnc_sim_linuxcnc_source_tool_number.json").read_text()) +if not any( + event["type"] == "tool-change" and + event["line"] == 2 and + event["tool"] == 1 + for event in tool_number +): + raise SystemExit("missing source-linked M61 Q1 tool-number event line") + +stops = json.loads(Path("/tmp/cnc_sim_linuxcnc_source_program_stops.json").read_text()) +stop_states = [ + (event["line"], event["reserved"]) + for event in stops + if event["type"] == "program-end" +] +for expected in [(2, 1), (3, 2), (4, 3), (4, 1), (5, 0)]: + if expected not in stop_states: + raise SystemExit(f"missing source-linked program stop state {expected!r}") + +coolant = json.loads(Path("/tmp/cnc_sim_linuxcnc_source_coolant.json").read_text()) +coolant_states = [ + (event["line"], event["reserved"]) + for event in coolant + if event["type"] == "comment" +] +for expected in [(2, 11), (3, 21), (4, 10), (4, 20)]: + if expected not in coolant_states: + raise SystemExit(f"missing source-linked coolant state {expected!r}") + feed_modes = json.loads(Path("/tmp/cnc_sim_linuxcnc_source_feed_modes.json").read_text()) feed_mode_comments = [ (event["line"], event["reserved"]) @@ -370,6 +424,10 @@ PY echo "linuxcnc rs274 source link smoke passed (${#objects[@]} local objects)" echo "dumped /tmp/cnc_sim_linuxcnc_source_basic_mill.json" echo "dumped /tmp/cnc_sim_linuxcnc_source_rtcp_controls.json" +echo "dumped /tmp/cnc_sim_linuxcnc_source_spindle_direction.json" +echo "dumped /tmp/cnc_sim_linuxcnc_source_tool_number.json" +echo "dumped /tmp/cnc_sim_linuxcnc_source_program_stops.json" +echo "dumped /tmp/cnc_sim_linuxcnc_source_coolant.json" echo "dumped /tmp/cnc_sim_linuxcnc_source_feed_modes.json" echo "dumped /tmp/cnc_sim_linuxcnc_source_motion_modes.json" echo "dumped /tmp/cnc_sim_linuxcnc_source_tool_length.json"