70 lines
1.7 KiB
Python
70 lines
1.7 KiB
Python
|
|
"""
|
||
|
|
边缘端运行测试脚本 - 推理测试
|
||
|
|
运行 main.py 并测试 30 秒
|
||
|
|
"""
|
||
|
|
|
||
|
|
import subprocess
|
||
|
|
import sys
|
||
|
|
import os
|
||
|
|
import time
|
||
|
|
|
||
|
|
def run_test():
|
||
|
|
print("=" * 60)
|
||
|
|
print("边缘端运行测试 - 推理测试")
|
||
|
|
print("=" * 60)
|
||
|
|
print(f"测试时长: 30 秒")
|
||
|
|
print(f"测试时间: {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
||
|
|
print("=" * 60)
|
||
|
|
|
||
|
|
env = os.environ.copy()
|
||
|
|
env['PATH'] = r"C:\Users\16337\miniconda3\envs\yolo;" + env.get('PATH', '')
|
||
|
|
|
||
|
|
cmd = [
|
||
|
|
sys.executable, "main.py"
|
||
|
|
]
|
||
|
|
|
||
|
|
process = subprocess.Popen(
|
||
|
|
cmd,
|
||
|
|
stdout=subprocess.PIPE,
|
||
|
|
stderr=subprocess.STDOUT,
|
||
|
|
text=True,
|
||
|
|
bufsize=1,
|
||
|
|
cwd=os.path.dirname(os.path.abspath(__file__)),
|
||
|
|
env=env
|
||
|
|
)
|
||
|
|
|
||
|
|
output_lines = []
|
||
|
|
start_time = time.time()
|
||
|
|
|
||
|
|
try:
|
||
|
|
while True:
|
||
|
|
line = process.stdout.readline()
|
||
|
|
if not line and process.poll() is not None:
|
||
|
|
break
|
||
|
|
|
||
|
|
if line:
|
||
|
|
output_lines.append(line.strip())
|
||
|
|
print(line.strip())
|
||
|
|
|
||
|
|
elapsed = time.time() - start_time
|
||
|
|
if elapsed >= 30:
|
||
|
|
print(f"\n[INFO] 测试达到 30 秒,停止进程...")
|
||
|
|
process.terminate()
|
||
|
|
try:
|
||
|
|
process.wait(timeout=5)
|
||
|
|
except subprocess.TimeoutExpired:
|
||
|
|
process.kill()
|
||
|
|
break
|
||
|
|
|
||
|
|
except KeyboardInterrupt:
|
||
|
|
print("\n[INFO] 用户中断测试")
|
||
|
|
process.terminate()
|
||
|
|
|
||
|
|
return output_lines
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
run_test()
|
||
|
|
print("\n" + "=" * 60)
|
||
|
|
print("测试完成")
|
||
|
|
print("=" * 60)
|