From f977583b6edabad5b06142da62da8f2feba3f93a Mon Sep 17 00:00:00 2001 From: mxr <> Date: Thu, 2 Apr 2026 11:02:15 +0800 Subject: [PATCH] =?UTF-8?q?test(test)=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=84=9A=E6=9C=ACrun.sh=E7=94=A8=E4=BA=8E=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=B5=8B=E8=AF=95ir=E7=94=9F=E6=88=90=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.sh | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/run.sh b/run.sh index e016839..673233a 100755 --- a/run.sh +++ b/run.sh @@ -21,6 +21,13 @@ if [ ! -f "$COMPILER" ]; then exit 1 fi +# 检查 verify_ir.sh 是否存在(可选) +VERIFY_SCRIPT="./scripts/verify_ir.sh" +if [ ! -f "$VERIFY_SCRIPT" ]; then + echo "错误: 验证脚本 $VERIFY_SCRIPT 未找到" + exit 1 +fi + # 如果指定了单个文件,检查文件是否存在 if [ -n "$1" ] && [ ! -f "$1" ]; then echo "错误: 文件 $1 不存在" @@ -32,10 +39,11 @@ fi # 计数器 total=0 +emit_ir=0 passed=0 failed=0 -echo "开始测试 ir out 解析..." +echo "开始测试 IR 生成与验证..." echo "输出将保存到 $RESULT_FILE" echo "------------------------" @@ -58,28 +66,43 @@ for file in "${TEST_FILES[@]}"; do echo "========== $file ==========" >> "$RESULT_FILE" + # 1. 运行编译器生成 IR if [ $VERBOSE -eq 1 ]; then - # "$COMPILER" --emit-parse-tree "$file" 2>&1 | tee -a "$RESULT_FILE" "$COMPILER" --emit-ir "$file" 2>&1 | tee -a "$RESULT_FILE" - result=${PIPESTATUS[0]} + result1=${PIPESTATUS[0]} else - # "$COMPILER" --emit-parse-tree "$file" >> "$RESULT_FILE" 2>&1 "$COMPILER" --emit-ir "$file" >> "$RESULT_FILE" 2>&1 - result=$? + result1=$? fi + echo "" >> "$RESULT_FILE" + # 2. 运行验证脚本 + if [ $VERBOSE -eq 1 ]; then + "$VERIFY_SCRIPT" "$file" test/test_result/function/ir --run 2>&1 | tee -a "$RESULT_FILE" + result2=${PIPESTATUS[0]} + else + "$VERBOSE" "$VERIFY_SCRIPT" "$file" test/test_result/function/ir --run >> "$RESULT_FILE" 2>&1 + result2=$? + fi echo "" >> "$RESULT_FILE" - if [ $result -eq 0 ]; then + # 判断整体通过(两个命令都成功) + if [ $result1 -eq 0 ]; then if [ $VERBOSE -eq 0 ]; then - echo "通过" + echo "生成ir" fi - ((passed++)) + if [ $result2 -eq 0 ]; then + if [ $VERBOSE -eq 0 ]; then + echo "通过" + fi + ((passed++)) + fi + ((emit_ir++)) else if [ $VERBOSE -eq 0 ]; then echo "失败" else - echo ">>> 解析失败: $file" + echo ">>> 测试失败: $file (compiler exit: $result1, verify exit: $result2)" fi ((failed++)) fi @@ -87,6 +110,7 @@ done echo "------------------------" echo "总计: $total" +echo "生成: $emit_ir" echo "通过: $passed" echo "失败: $failed" echo "详细输出已保存至 $RESULT_FILE" @@ -95,4 +119,4 @@ if [ $failed -gt 0 ]; then exit 1 else exit 0 -fi +fi \ No newline at end of file