修复了虚拟机内测试脚本的格式问题
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# run_vm_tests.sh - 用于在 RISC-V 虚拟机内部汇编、链接和测试 SysY 程序的脚本
|
||||
# 此脚本应该在Riscv64架构的机器上运行,依赖:gcc。
|
||||
# 此脚本应位于您的项目根目录 (例如 /home/ubuntu/debug)
|
||||
# 假设当前运行环境已经是 RISC-V 64 位架构,可以直接执行编译后的程序。
|
||||
# 脚本的目录结构应该为:
|
||||
# .
|
||||
# ├── runit.sh
|
||||
@@ -17,8 +18,9 @@ TMP_DIR="${SCRIPT_DIR}/tmp"
|
||||
LIB_DIR="${SCRIPT_DIR}/lib"
|
||||
TESTDATA_DIR="${SCRIPT_DIR}/testdata"
|
||||
|
||||
# 定义编译器
|
||||
# 定义编译器 (这里假设 gcc 在 VM 内部是可用的)
|
||||
GCC_NATIVE="gcc" # VM 内部的 gcc
|
||||
# 不再需要 QEMU_RISCV64,因为直接执行
|
||||
|
||||
# 显示帮助信息的函数
|
||||
show_help() {
|
||||
@@ -33,7 +35,7 @@ show_help() {
|
||||
echo "执行步骤:"
|
||||
echo "1. 遍历 'tmp/' 目录下的所有 .s 汇编文件。"
|
||||
echo "2. 使用 VM 内部的 gcc 将 .s 文件汇编并链接为可执行文件 (链接 -L./lib -lsysy_riscv -static)。"
|
||||
echo "3. 直接运行编译后的可执行文件 (使用 ./ 方式)。"
|
||||
echo "3. 直接运行编译后的可执行文件。"
|
||||
echo "4. 根据对应的 testdata/*.out 文件内容(最后一行是否为整数)决定是进行返回值比较、标准输出比较,或两者都进行。"
|
||||
echo "5. 如果没有对应的 .in/.out 文件,则打印可执行文件的返回值。"
|
||||
echo "6. 输出比较时会忽略行尾多余的换行符。"
|
||||
@@ -85,10 +87,17 @@ find "${TMP_DIR}" -maxdepth 1 -name "*.s" | while read s_file; do
|
||||
# 从 .s 文件名中提取原始的测试用例名称部分
|
||||
# 例如:从 functional_21_if_test2_sysyc_riscv64.s 提取 functional_21_if_test2
|
||||
base_name_from_s_file=$(basename "$s_file" .s)
|
||||
# 这一步得到的是 'functional_21_if_test2' 或 'performance_2024-2D0-22'
|
||||
original_test_name_underscored=$(echo "$base_name_from_s_file" | sed 's/_sysyc_riscv64$//')
|
||||
|
||||
# 将下划线转换回斜杠,以构建原始的相对路径(例如:functional/21_if_test2)
|
||||
original_relative_path=$(echo "$original_test_name_underscored" | tr '_' '/')
|
||||
# 将 `original_test_name_underscored` 分割成类别和文件名
|
||||
# 例如:'functional_21_if_test2' 分割为 'functional' 和 '21_if_test2'
|
||||
category=$(echo "$original_test_name_underscored" | cut -d'_' -f1)
|
||||
# cut -d'_' -f2- 会从第二个下划线开始获取所有剩余部分
|
||||
test_file_base=$(echo "$original_test_name_underscored" | cut -d'_' -f2-)
|
||||
|
||||
# 构建原始的相对路径,例如:'functional/21_if_test2'
|
||||
original_relative_path="${category}/${test_file_base}"
|
||||
|
||||
# 定义可执行文件、输入文件、参考输出文件和实际输出文件的路径
|
||||
executable_file="${TMP_DIR}/${base_name_from_s_file}"
|
||||
@@ -111,7 +120,7 @@ find "${TMP_DIR}" -maxdepth 1 -name "*.s" | while read s_file; do
|
||||
|
||||
# 步骤 2: 执行编译后的文件并比较/报告结果
|
||||
# 直接执行可执行文件,不再通过 qemu-riscv64
|
||||
echo " 正在执行: ./\"${executable_file}\""
|
||||
echo " 正在执行: \"${executable_file}\"" # 修改点:移除多余的 ./
|
||||
|
||||
# 检查是否存在 .out 文件
|
||||
if [ -f "${output_reference_file}" ]; then
|
||||
@@ -140,9 +149,9 @@ find "${TMP_DIR}" -maxdepth 1 -name "*.s" | while read s_file; do
|
||||
# 执行程序,捕获实际返回码和实际标准输出
|
||||
if [ -f "${input_file}" ]; then
|
||||
echo " 使用输入文件: ${input_file}"
|
||||
"./${executable_file}" < "${input_file}" > "${output_actual_file}"
|
||||
"${executable_file}" < "${input_file}" > "${output_actual_file}" # 修改点:移除多余的 ./
|
||||
else
|
||||
"./${executable_file}" > "${output_actual_file}"
|
||||
"${executable_file}" > "${output_actual_file}" # 修改点:移除多余的 ./
|
||||
fi
|
||||
ACTUAL_RETURN_CODE=$? # 捕获执行状态
|
||||
|
||||
@@ -169,9 +178,9 @@ find "${TMP_DIR}" -maxdepth 1 -name "*.s" | while read s_file; do
|
||||
# 执行程序,并将输出重定向到临时文件
|
||||
if [ -f "${input_file}" ]; then
|
||||
echo " 使用输入文件: ${input_file}"
|
||||
"./${executable_file}" < "${input_file}" > "${output_actual_file}"
|
||||
"${executable_file}" < "${input_file}" > "${output_actual_file}" # 修改点:移除多余的 ./
|
||||
else
|
||||
"./${executable_file}" > "${output_actual_file}"
|
||||
"${executable_file}" > "${output_actual_file}" # 修改点:移除多余的 ./
|
||||
fi
|
||||
EXEC_STATUS=$? # 捕获执行状态
|
||||
|
||||
@@ -192,13 +201,13 @@ find "${TMP_DIR}" -maxdepth 1 -name "*.s" | while read s_file; do
|
||||
# 只有 .in 文件存在,使用输入运行并报告退出码(无参考输出)
|
||||
echo " 使用输入文件: ${input_file}"
|
||||
echo " 没有 .out 文件进行比较。正在运行并报告返回码。"
|
||||
"./${executable_file}" < "${input_file}"
|
||||
"${executable_file}" < "${input_file}" # 修改点:移除多余的 ./
|
||||
EXEC_STATUS=$?
|
||||
echo " ${original_relative_path}.sy 的返回码: ${EXEC_STATUS}"
|
||||
else
|
||||
# .in 和 .out 文件都不存在,只运行并报告退出码
|
||||
echo " 未找到 .in 或 .out 文件。正在运行并报告返回码。"
|
||||
"./${executable_file}"
|
||||
"${executable_file}" # 修改点:移除多余的 ./
|
||||
EXEC_STATUS=$?
|
||||
echo " ${original_relative_path}.sy 的返回码: ${EXEC_STATUS}"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user