Files
DronePlanning/tools/test_validate/run_tests.py

119 lines
3.7 KiB
Python
Executable File

#!/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
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 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("0. 退出")
print("-" * 60)
choice = input("请输入选项 [0-4]: ").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 == '0':
print("\n👋 再见!")
break
else:
print("\n❌ 无效选项,请重试")
time.sleep(1)
if __name__ == "__main__":
main()