按规划继续工作

结论:将现有负向 G-code fixture 纳入 upstream rs274 -g side-by-side 基线,校验错误文本和 absent canonical 事件约束,继续保持解释器语义来源于 LinuxCNC。
This commit is contained in:
2026-06-08 12:23:05 +08:00
parent 657eecfcc3
commit 775f0d9c4c
4 changed files with 84 additions and 2 deletions

View File

@@ -5,6 +5,8 @@ ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
UPSTREAM_RS274="$ROOT_DIR/../linuxcnc/bin/rs274"
GCODE_FIXTURE_DIR="$ROOT_DIR/tests/fixtures/gcode"
CANON_FIXTURE_DIR="$ROOT_DIR/tests/fixtures/canon"
GCODE_ERROR_FIXTURE_DIR="$ROOT_DIR/tests/fixtures/gcode_errors"
CANON_ERROR_FIXTURE_DIR="$ROOT_DIR/tests/fixtures/canon_errors"
FIXTURES=(
minimal_linear
@@ -37,6 +39,18 @@ FIXTURES=(
tool_reload
)
ERROR_FIXTURES=(
arc_radius_mismatch
arc_zero_radius
cutter_comp_plane_change
g1_zero_feed
g53_incremental
namedparam_readonly
numbered_param_readonly
tool_length_offset_not_found
tool_not_found
)
if [[ ! -x "$UPSTREAM_RS274" ]]; then
echo "missing upstream rs274 executable: $UPSTREAM_RS274" >&2
exit 1
@@ -807,6 +821,13 @@ filter_to_expected_event_keys() {
' "$expected_norm" -
}
normalize_absent_standalone_event() {
local absent_line="$1"
local event="${absent_line#absent=canon_event=}"
printf 'canon_event=%s\n' "$event" | normalize_standalone_events
}
for name in "${FIXTURES[@]}"; do
gcode_file="$GCODE_FIXTURE_DIR/$name.ngc"
expected_file="$CANON_FIXTURE_DIR/$name.events"
@@ -903,4 +924,53 @@ for name in "${FIXTURES[@]}"; do
fi
done
for name in "${ERROR_FIXTURES[@]}"; do
gcode_file="$GCODE_ERROR_FIXTURE_DIR/$name.ngc"
expected_file="$CANON_ERROR_FIXTURE_DIR/$name.expected"
native_raw="$TMP_DIR/$name.error.rs274.raw"
native_norm="$TMP_DIR/$name.error.rs274.normalized"
if [[ ! -f "$gcode_file" ]]; then
echo "missing negative G-code fixture: $gcode_file" >&2
exit 1
fi
if [[ ! -f "$expected_file" ]]; then
echo "missing negative expected fixture: $expected_file" >&2
exit 1
fi
set +e
"$UPSTREAM_RS274" -g "$gcode_file" > "$native_raw" 2>&1
rs274_rc=$?
set -e
if [[ "$rs274_rc" == "0" ]]; then
echo "upstream rs274 unexpectedly succeeded for negative fixture: $name" >&2
sed -n '1,160p' "$native_raw" >&2
exit 1
fi
normalize_upstream_rs274_output < "$native_raw" > "$native_norm"
while IFS= read -r expected_line; do
[[ -z "$expected_line" ]] && continue
if [[ "$expected_line" == error_text=* ]]; then
expected_error="${expected_line#error_text=}"
if ! grep -Fq "$expected_error" "$native_raw"; then
echo "missing upstream rs274 error text for fixture $name: $expected_error" >&2
sed -n '1,160p' "$native_raw" >&2
exit 1
fi
elif [[ "$expected_line" == absent=canon_event=* ]]; then
absent_norm="$(normalize_absent_standalone_event "$expected_line")"
if grep -Fxq "$absent_norm" "$native_norm"; then
echo "unexpected upstream rs274 event for fixture $name: $absent_norm" >&2
sed -n '1,160p' "$native_raw" >&2
exit 1
fi
fi
done < "$expected_file"
done
echo "native LinuxCNC fixture baseline validation complete"