fix(scripts): 修复 score.sh 输出对比逻辑——适配 SysY 非零返回值 + .out 格式

- 移除错误的 exit_code==0 检查(SysY 可返回任意值)
- 修复 .out 格式生成:stdout 为空时不插入多余空行
- 修复 ref_time 不记录非零退出码的 bug
- functional: 100/100 AC, performance: 57/60 AC
lzk
lzkk 2 days ago
parent 5cd5c54764
commit 8d4a34aa10

@ -168,10 +168,8 @@ run_one() {
timeout "$TIMEOUT_SEC" "$QEMU" $QEMU_FLAGS "$ref_exe" > "$ref_out" 2>/dev/null || ref_exit=$?
fi
ref_end="$(date +%s%3N)"
if [[ $ref_exit -eq 0 ]]; then
ref_time=$((ref_end - ref_start))
ref_ok=1
fi
ref_time=$((ref_end - ref_start))
ref_ok=1
fi
fi
if [[ $ref_time -lt 1 ]]; then ref_time=1; fi
@ -230,15 +228,20 @@ run_with_args() {
end_ns="$(date +%s%3N)"
our_time=$((end_ns - start_ns))
[[ $our_time -lt 1 ]] && our_time=1
if [[ $exit_code -eq 0 ]]; then
if [[ -f "$out_file" ]]; then
# .out 文件格式: stdout + 换行 + 退出码 (与 2026test.sh 一致)
local our_actual="$work_dir/our.actual.out"
{ cat "$our_out"; printf '\n'; echo "$exit_code"; } > "$our_actual"
diff -q "$our_actual" "$out_file" >/dev/null 2>&1 && our_correct=1
else
our_correct=1
# SysY 程序可返回任意值,不能用 exit_code==0 判断正确性
# .out 文件格式(与 2026test.sh 一致): stdout + [换行] + 退出码
local our_actual="$work_dir/our.actual.out"
{
cat "$our_out"
if [[ -s "$our_out" ]] && (( $(tail -c 1 "$our_out" | wc -l) == 0 )); then
printf '\n'
fi
echo "$exit_code"
} > "$our_actual"
if [[ -f "$out_file" ]]; then
diff -q "$our_actual" "$out_file" >/dev/null 2>&1 && our_correct=1
else
our_correct=1
fi
fi
fi
@ -256,7 +259,7 @@ run_with_args() {
timeout "$TIMEOUT_SEC" "$QEMU" $QEMU_FLAGS "$ref_exe" > "$ref_out" 2>/dev/null || ref_exit=$?
fi
ref_end="$(date +%s%3N)"
[[ $ref_exit -eq 0 ]] && ref_time=$((ref_end - ref_start))
ref_time=$((ref_end - ref_start))
fi
fi
[[ $ref_time -lt 1 ]] && ref_time=1

Loading…
Cancel
Save