#!/usr/bin/env bash output_file="test_results.txt" test_dirs=("test/test_case/functional" "test/test_case/performance") # 初始化输出文件 { echo "开始批量测试..." echo "测试时间: $(date)" echo "========================================" echo "" } > "$output_file" total=0 passed=0 failed=0 skipped=0 for test_dir in "${test_dirs[@]}"; do if [[ ! -d "$test_dir" ]]; then continue fi echo "测试目录: $test_dir" | tee -a "$output_file" echo "----------------------------------------" >> "$output_file" # 使用简单的 for 循环 for test_file in "$test_dir"/*.sy; do if [[ ! -f "$test_file" ]]; then continue fi ((total++)) name=$(basename "$test_file" .sy) # 显示当前测试 echo -n "测试 $name ... " echo "" # 根据目录设置输出路径和超时时间 if [[ "$test_dir" == *"functional"* ]]; then out_dir="test/test_result/function/asm" timeout_sec=60 else out_dir="test/test_result/performance/asm" timeout_sec=600 # 性能测试增加到 3 分钟 fi # 运行测试 temp_output=$(mktemp) if timeout ${timeout_sec}s ./scripts/verify_asm.sh "$test_file" "$out_dir" --run > "$temp_output" 2>&1; then # 提取并保存关键信息到文件 { grep "运行 " "$temp_output" || echo "运行 $out_dir/$name ..." grep "退出码:" "$temp_output" || echo "退出码: 失败" if grep -q "输出匹配:" "$temp_output"; then grep "输出匹配:" "$temp_output" echo "" ((passed++)) echo "✓" echo "" elif grep -q "输出不匹配:" "$temp_output"; then grep "输出不匹配:" "$temp_output" echo "" ((failed++)) echo "✗ (输出不匹配)" elif grep -q "未找到预期输出文件" "$temp_output"; then echo "未找到预期输出文件,跳过比对" echo "" ((skipped++)) echo "⊘ (无期望输出)" else echo "测试完成" echo "" ((passed++)) echo "✓" echo "" fi } >> "$output_file" else # 测试失败或超时 { echo "运行 $out_dir/$name ..." echo "退出码: 超时或失败" echo "测试失败" echo "" } >> "$output_file" ((failed++)) echo "✗ (失败/超时)" fi rm -f "$temp_output" done echo "" >> "$output_file" done # 输出统计 echo "" echo "========================================" echo "测试统计:" echo " 总计: $total" echo " 通过: $passed" echo " 失败: $failed" echo " 跳过: $skipped" if [[ $total -gt 0 ]]; then pass_rate=$(awk "BEGIN {printf \"%.1f\", ($passed/$total)*100}") echo " 通过率: ${pass_rate}%" fi echo "" echo "详细结果已保存到: $output_file" # 保存统计到文件 { echo "========================================" echo "测试统计:" echo " 总计: $total" echo " 通过: $passed" echo " 失败: $failed" echo " 跳过: $skipped" if [[ $total -gt 0 ]]; then pass_rate=$(awk "BEGIN {printf \"%.1f\", ($passed/$total)*100}") echo " 通过率: ${pass_rate}%" fi } >> "$output_file" # 返回状态码 if [[ $failed -eq 0 ]]; then exit 0 else exit 1 fi