继续按 align-linuxcnc 约束:补 block reader 源码错误覆盖

结论:覆盖 LinuxCNC interp_read.cc/read_dollar()/read_one_item() 的重复 $、非法起始字符和中途 N word 错误,以及 interp_check.cc/check_m_codes() 的 M 码数量错误;未扩展 smoke。

验证:./test-linuxcnc-source-link.sh;./test-native.sh。
This commit is contained in:
cnc
2026-06-02 17:00:55 +08:00
parent b83bc47c45
commit 7bd1dc640f
6 changed files with 43 additions and 0 deletions

View File

@@ -732,6 +732,44 @@ for case in "${gm_reader_error_cases[@]}"; do
grep -q "$expected" "$output_dir/cnc_sim_linuxcnc_source_$fixture.err"
done
# Source basis: LinuxCNC src/emc/rs274ngc/interp_read.cc
# read_dollar() rejects repeated spindle-choice words while filling a block.
if CNC_SIM_RS274_FILE_MODE=1 CNC_SIM_RS274_VAR="$var_file" \
"$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_multiple_spindle_choice_words_error.ngc \
>"$output_dir/cnc_sim_linuxcnc_source_multiple_spindle_choice_words_error.json" 2>"$output_dir/cnc_sim_linuxcnc_source_multiple_spindle_choice_words_error.err"; then
echo "expected linuxcnc_multiple_spindle_choice_words_error.ngc to fail" >&2
exit 1
fi
grep -Fq "Multiple spindle choice (\$) words on one line" \
"$output_dir/cnc_sim_linuxcnc_source_multiple_spindle_choice_words_error.err"
# Source basis: LinuxCNC src/emc/rs274ngc/interp_read.cc
# read_one_item() uses the default reader table from interp_array.cc and
# rejects unknown item-start characters, including middle-of-line N words.
bad_character_error_cases=(
"linuxcnc_bad_character_bang_error|Bad character '!' used"
"linuxcnc_bad_character_middle_n_word_error|Bad character 'n' used"
)
for case in "${bad_character_error_cases[@]}"; do
fixture=${case%%|*}
expected=${case#*|}
if CNC_SIM_RS274_FILE_MODE=1 CNC_SIM_RS274_VAR="$var_file" \
"$build_dir/linuxcnc_rs274_source_dump" "tests/gcode/$fixture.ngc" \
>"$output_dir/cnc_sim_linuxcnc_source_$fixture.json" 2>"$output_dir/cnc_sim_linuxcnc_source_$fixture.err"; then
echo "expected $fixture.ngc to fail" >&2
exit 1
fi
grep -q "$expected" "$output_dir/cnc_sim_linuxcnc_source_$fixture.err"
done
# Source basis: LinuxCNC src/emc/rs274ngc/interp_check.cc
# check_m_codes() rejects blocks with more than MAX_EMS M-codes.
if CNC_SIM_RS274_FILE_MODE=1 CNC_SIM_RS274_VAR="$var_file" \
"$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_too_many_m_codes_error.ngc \
>"$output_dir/cnc_sim_linuxcnc_source_too_many_m_codes_error.json" 2>"$output_dir/cnc_sim_linuxcnc_source_too_many_m_codes_error.err"; then
echo "expected linuxcnc_too_many_m_codes_error.ngc to fail" >&2
exit 1
fi
grep -q "Too many m codes on line" \
"$output_dir/cnc_sim_linuxcnc_source_too_many_m_codes_error.err"
# Source basis: LinuxCNC src/emc/rs274ngc/interp_read.cc
# the word-specific reader functions reject repeated words while
# filling a single block.
multiple_word_error_cases=(