From ea2c9c2ba9b024c8a9766994d18789911f0cb783 Mon Sep 17 00:00:00 2001 From: cnc Date: Fri, 22 May 2026 17:21:47 +0800 Subject: [PATCH] Cover coordinate offsets in source link tests --- docs/linuxcnc-porting.md | 2 +- test-linuxcnc-source-link.sh | 54 +++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/docs/linuxcnc-porting.md b/docs/linuxcnc-porting.md index c699926..a1bea07 100644 --- a/docs/linuxcnc-porting.md +++ b/docs/linuxcnc-porting.md @@ -192,7 +192,7 @@ This matrix tracks LinuxCNC feature coverage for the web/WASM simulator. A featu | 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` | | Canned cycle `G81/G80` | covered for drilling expand-to-canon path | `tests/gcode/linuxcnc_canned_cycle.ngc` | -| Coordinate offset Canon events | bridge-level covered | `core/tests/linuxcnc_canon_bridge_smoke.cpp` | +| 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` | | Cutter compensation | covered for tool-table `G41/G42 D...` and explicit-radius `G41.1/G42.1/G40` through LinuxCNC native/source backends | `tests/gcode/linuxcnc_cutter_comp.ngc` | | O-word subroutines and calls | covered for numeric `O... sub/call/return/endsub` through LinuxCNC file mode; smoke parser also covers named `O` sub/call/return/endsub | `tests/gcode/smoke_oword_subprogram.ngc` | | Broader canned cycles `G73`, `G82`-`G89` | partially covered: `G73`, `G82`, `G83`, `G85`, `G86`, `G89` | `tests/gcode/linuxcnc_canned_cycles_extended.ngc`, smoke API regression | diff --git a/test-linuxcnc-source-link.sh b/test-linuxcnc-source-link.sh index 80db647..9ee5e8b 100755 --- a/test-linuxcnc-source-link.sh +++ b/test-linuxcnc-source-link.sh @@ -93,7 +93,9 @@ done -o "$build_dir/linuxcnc_rs274_source_dump" var_file="$build_dir/rs274ngc-source.var" -cp "$linuxcnc_root/tests/halui/jogging/sim.var" "$var_file" +base_var_file="$build_dir/rs274ngc-source-base.var" +cp "$linuxcnc_root/tests/halui/jogging/sim.var" "$base_var_file" +cp "$base_var_file" "$var_file" CNC_SIM_RS274_VAR="$var_file" \ "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/basic_mill.ngc \ @@ -116,6 +118,14 @@ CNC_SIM_RS274_VAR="$var_file" \ CNC_SIM_RS274_FILE_MODE=1 CNC_SIM_RS274_VAR="$var_file" \ "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/smoke_oword_subprogram.ngc \ >/tmp/cnc_sim_linuxcnc_source_oword_subprogram.json +cp "$base_var_file" "$var_file" +CNC_SIM_RS274_VAR="$var_file" \ + "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_coordinate_offsets.ngc \ + >/tmp/cnc_sim_linuxcnc_source_coordinate_offsets.json +cp "$base_var_file" "$var_file" +CNC_SIM_RS274_VAR="$var_file" \ + "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_coordinate_l20.ngc \ + >/tmp/cnc_sim_linuxcnc_source_coordinate_l20.json python3 - <<'PY' import json @@ -265,6 +275,46 @@ if any( for event in oword ): raise SystemExit("source-linked O-word return should skip remaining subprogram body") + +coords = json.loads(Path("/tmp/cnc_sim_linuxcnc_source_coordinate_offsets.json").read_text()) +g5x = [event for event in coords if event["type"] == "set-g5x-offset"] +g92 = [event for event in coords if event["type"] == "set-g92-offset"] +rot = [event for event in coords if event["type"] == "set-xy-rotation"] +if not any( + event["line"] == 2 and + event["tool"] == 1 and + event["start"]["x"] == 12.5 and + event["start"]["y"] == -3 and + event["start"]["z"] == 4 + for event in g5x +): + raise SystemExit("missing source-linked G10 L2 G5X offset event") +if not any(event["feed"] == 30 for event in rot): + raise SystemExit("missing source-linked G10 L2 XY rotation event") +if not any( + event["line"] == 4 and + event["start"]["x"] == 0 and + event["start"]["y"] == 0 and + event["start"]["z"] == 0 + for event in g92 +): + raise SystemExit("missing source-linked G92.1 clear offset event") +if not any(event["type"] == "program-end" and event["line"] == 5 for event in coords): + raise SystemExit("missing source-linked coordinate program end line number") + +l20 = json.loads(Path("/tmp/cnc_sim_linuxcnc_source_coordinate_l20.json").read_text()) +if not any( + event["type"] == "set-g5x-offset" and + event["line"] == 4 and + event["tool"] == 2 and + event["start"]["x"] == 4 and + event["start"]["y"] == 4 and + event["start"]["z"] == 4 + for event in l20 +): + raise SystemExit("missing source-linked G10 L20 P2 offset event after G55 selection") +if not any(event["type"] == "program-end" and event["line"] == 5 for event in l20): + raise SystemExit("missing source-linked G10 L20 program end line number") PY echo "linuxcnc rs274 source link smoke passed (${#objects[@]} local objects)" @@ -275,3 +325,5 @@ echo "dumped /tmp/cnc_sim_linuxcnc_source_canned_cycle.json" echo "dumped /tmp/cnc_sim_linuxcnc_source_canned_cycles_extended.json" echo "dumped /tmp/cnc_sim_linuxcnc_source_cutter_comp.json" echo "dumped /tmp/cnc_sim_linuxcnc_source_oword_subprogram.json" +echo "dumped /tmp/cnc_sim_linuxcnc_source_coordinate_offsets.json" +echo "dumped /tmp/cnc_sim_linuxcnc_source_coordinate_l20.json"