|
|
|
|
@ -10,6 +10,7 @@ fi
|
|
|
|
|
input=$1
|
|
|
|
|
out_dir="test/test_result/asm"
|
|
|
|
|
run_exec=false
|
|
|
|
|
input_dir=$(dirname "$input")
|
|
|
|
|
|
|
|
|
|
shift
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
|
@ -45,6 +46,8 @@ base=$(basename "$input")
|
|
|
|
|
stem=${base%.sy}
|
|
|
|
|
asm_file="$out_dir/$stem.s"
|
|
|
|
|
exe="$out_dir/$stem"
|
|
|
|
|
stdin_file="$input_dir/$stem.in"
|
|
|
|
|
expected_file="$input_dir/$stem.out"
|
|
|
|
|
|
|
|
|
|
"$compiler" --emit-asm "$input" > "$asm_file"
|
|
|
|
|
echo "汇编已生成: $asm_file"
|
|
|
|
|
@ -58,10 +61,36 @@ if [[ "$run_exec" == true ]]; then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
stdout_file="$out_dir/$stem.stdout"
|
|
|
|
|
actual_file="$out_dir/$stem.actual.out"
|
|
|
|
|
echo "运行 $exe ..."
|
|
|
|
|
set +e
|
|
|
|
|
qemu-aarch64 -L /usr/aarch64-linux-gnu "$exe"
|
|
|
|
|
if [[ -f "$stdin_file" ]]; then
|
|
|
|
|
qemu-aarch64 -L /usr/aarch64-linux-gnu "$exe" < "$stdin_file" > "$stdout_file"
|
|
|
|
|
else
|
|
|
|
|
qemu-aarch64 -L /usr/aarch64-linux-gnu "$exe" > "$stdout_file"
|
|
|
|
|
fi
|
|
|
|
|
status=$?
|
|
|
|
|
set -e
|
|
|
|
|
cat "$stdout_file"
|
|
|
|
|
echo "退出码: $status"
|
|
|
|
|
{
|
|
|
|
|
cat "$stdout_file"
|
|
|
|
|
if [[ -s "$stdout_file" ]] && (( $(tail -c 1 "$stdout_file" | wc -l) == 0 )); then
|
|
|
|
|
printf '\n'
|
|
|
|
|
fi
|
|
|
|
|
printf '%s\n' "$status"
|
|
|
|
|
} > "$actual_file"
|
|
|
|
|
|
|
|
|
|
if [[ -f "$expected_file" ]]; then
|
|
|
|
|
if diff -u "$expected_file" "$actual_file"; then
|
|
|
|
|
echo "输出匹配: $expected_file"
|
|
|
|
|
else
|
|
|
|
|
echo "输出不匹配: $expected_file" >&2
|
|
|
|
|
echo "实际输出已保存: $actual_file" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo "未找到预期输出文件,跳过比对: $expected_file"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|