Files
DronePlanning/tools/test_validate/run_tests.py
2026-02-26 19:37:55 +08:00

158 lines
5.1 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import time
import subprocess
# Add current directory to path so modules can be imported
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from modules.interactive_test import run_interactive_test
from modules.batch_runner import run_batch_test
from modules.json_visualizer import run_json_visualization
from modules.stage_debugger import run_stage_debug_single, run_stage_debug_batch
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')
def print_header():
clear_screen()
print("=" * 60)
print(" Drone Planning 系统测试工具箱 (Unified)")
print("=" * 60)
print(f"当前工作目录: {os.getcwd()}")
print("-" * 60)
def run_legacy_module(module_name, args=None):
"""运行旧的独立 Python 脚本 (用于 LLM 测试和上传工具)"""
script_path = os.path.join(os.path.dirname(__file__), "modules", module_name)
if not os.path.exists(script_path):
print(f"❌ 错误: 找不到脚本 {script_path}")
input("\n按回车键继续...")
return
cmd = [sys.executable, script_path]
if args:
cmd.extend(args)
print(f"\n🚀 正在启动: {module_name} ...\n")
try:
# 保持当前环境变量
env = os.environ.copy()
# 确保 PYTHONPATH 包含当前目录
env["PYTHONPATH"] = os.path.dirname(__file__) + os.pathsep + env.get("PYTHONPATH", "")
subprocess.run(cmd, env=env, check=False)
except KeyboardInterrupt:
print("\n\n⚠️ 操作已取消")
except Exception as e:
print(f"\n❌ 运行出错: {e}")
input("\n按回车键返回菜单...")
def _run_stage_debug_menu():
"""Stage 分阶段调试子菜单"""
while True:
print_header()
print("Stage 分阶段调试")
print("-" * 60)
print("1. 单条指令调试 - 输入指令,选择 Stage查看该 Stage 输出")
print("2. 批量指令调试 - 从文件读取指令,批量运行到选定 Stage")
print("0. 返回主菜单")
print("-" * 60)
sub = input("请选择 [0-2]: ").strip()
if sub == "1":
try:
run_stage_debug_single()
except Exception as e:
print(f"❌ 运行出错: {e}")
input("\n按回车键返回...")
elif sub == "2":
try:
run_stage_debug_batch()
except Exception as e:
print(f"❌ 运行出错: {e}")
input("\n按回车键返回...")
elif sub == "0":
break
else:
print("❌ 无效选项")
def menu_drone_upload():
print("\n[3] 上传任务到无人机")
print("说明: 将生成的任务文件上传到无人机 (Ground Station Client)。")
ip = input("\n请输入无人机 IP 地址 (默认: 127.0.0.1): ").strip() or "127.0.0.1"
file_path = input("请输入任务文件路径 (.json): ").strip()
if not file_path:
print("❌ 必须提供文件路径!")
time.sleep(1)
return
if not os.path.exists(file_path):
print(f"❌ 文件不存在: {file_path}")
time.sleep(1)
return
run_legacy_module("drone_uploader.py", [ip, file_path])
def main():
# 切换到脚本所在目录
os.chdir(os.path.dirname(os.path.abspath(__file__)))
while True:
print_header()
print("请选择测试模式:")
print("1. 交互式单次测试 (Interactive Single Test)")
print(" - 手动输入指令,即时查看结果和可视化")
print("2. 批量/场景测试 (Batch/Scenario Test)")
print(" - 读取指令文件,支持多轮压力测试,生成统计报告")
print("3. 上传任务到无人机 (Drone Uploader)")
print("4. LLM 服务连通性测试 (LLM Tester)")
print("5. JSON 文件可视化 (Visualize JSON File)")
print("6. Stage 分阶段调试 (Stage Debug)")
print(" - 单条/批量运行到指定 Stage查看中间输出")
print("0. 退出")
print("-" * 60)
choice = input("请输入选项 [0-6]: ").strip()
if choice == '1':
try:
run_interactive_test()
except Exception as e:
print(f"❌ 运行出错: {e}")
input("\n按回车键返回菜单...")
elif choice == '2':
try:
run_batch_test()
except Exception as e:
print(f"❌ 运行出错: {e}")
input("\n按回车键返回菜单...")
elif choice == '3':
menu_drone_upload()
elif choice == '4':
run_legacy_module("llm_tester.py")
elif choice == '5':
run_json_visualization()
elif choice == '6':
_run_stage_debug_menu()
elif choice == '0':
print("\n👋 再见!")
break
else:
print("\n❌ 无效选项,请重试")
time.sleep(1)
if __name__ == "__main__":
main()