refactor(test): 把 test/host 顶层 25 个台架脚本按域收进 bench/

原来 test/host 一层混了三类东西:51 个主机侧单测模块目录、25 个台架驱动
与探针、若干专用目录。台架脚本平铺在顶层,与单测目录并列,看不出哪个是
「连板跑一次的」,也看不出加新脚本该往哪放。

现在按被验对象分域归档,单测模块目录一律不动(22 根 pre-commit 钩子逐个
点名它们,50 个运行器按固定层数推仓库根):

- bench/bench_defaults.py 台架连接默认值单一真源
- bench/ftp/ (10) FTP 功能、速率、鉴权、中止、完整性、背靠背复现
- bench/net/ (9) CH395F socket、keepalive 判死、挂机、复连压力、PASV、
  UDP 队列、链路时延对端
- bench/iec104/ (2) 主站客户端与它的离线样帧自检
- bench/wave/ (1) 录波段文件 PC 侧解码
- bench/screenlink/ (2) 屏板链路顶替与拉帧压测

顶层条目 78 -> 53。逐脚本作用、运行前置与「加新脚本往哪放」写在新建的
test/host/bench/README.md;test/host/README.md 增目录地图表,把原平铺的
网络/FTP 两节压成指针。

配套修正(移动后不修就会坏):
- 17 个脚本加上 bench/ 到 sys.path 的 bootstrap(sys.path[0] 是脚本自身
  目录,不补就 import bench_defaults 失败)
- cal/cal_write.py 本来就坏的(只插 cal/ 到自己 sys.path,import
  bench_defaults 直接 ModuleNotFoundError),补两段路径后可用
- e6_soak 与 wave_read 用 dirname 固定层数推仓库根,多两层后分别指向
  test/test 与 test/ci-artifacts(后者静默写错目录、不报错),层数已改对
- scripts/board_ui_nav.py 与 MDK-ARM 两个探针的 bench_defaults 搜索路径

清理与标注:删掉 test/host/iec104/(旧自研协议层单测退役后只剩一个零引用
的 stub 桩头);文档里对 test/host/iec104 与 iec104_serv 的引用加上「已
删除/已不存在 2026-11-18」状态词。冻结历史证据(带日期戳的台架日志)与
编号别名登记表里的旧路径按原样保留。
This commit is contained in:
2026-11-18 12:46:03 +08:00
parent b584601174
commit 685a366890
70 changed files with 415 additions and 224 deletions
+133
View File
@@ -0,0 +1,133 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
pasv_probe.py — decisive probe for the "storm" signature (self-heal audit E8).
Per FTP round prints: device PASV port, PC data-socket SOURCE port, round
result, and timing. Hypothesis under test: the CH395F reuses the same
ephemeral PASV port for the next data listener while the previous data
connection is still in chip-side TIME_WAIT with the same 4-tuple
(PC source port reused too) -> chip reports CONNECT then RSTs ~10ms later
(serial: "sock4 standalone accept" + "DISCONNECTED chip st=0x00/0x00").
Usage:
python pasv_probe.py --rounds 5 --delay 2 # reproduce (fast rounds)
python pasv_probe.py --rounds 3 --delay 35 # TIME_WAIT window test
"""
import os
import argparse
import re
import socket
import sys
import time
# 台架连接默认值单一真源已随域归档到 test/host/bench/bench_defaults.py:
# Python 的 sys.path[0] 是**脚本自身所在目录**,本脚本在 bench/<域>/ 下直接
# `import bench_defaults` 会 ModuleNotFoundError —— 先把 bench/ 补进 sys.path。
_BENCH_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if _BENCH_DIR not in sys.path:
sys.path.insert(0, _BENCH_DIR)
import bench_defaults # noqa: E402 (台架连接默认值单一真源)
IP_DEFAULT = bench_defaults.DEVICE_IP
def ftp_stor_round(ip, user, pwd, fname, payload):
"""One login -> PASV -> STOR -> verify transfer. Returns (ok, pasv_port,
pc_src_port, detail)."""
c = socket.create_connection((ip, 21), timeout=10)
c.settimeout(10)
pc_src = None
pasv_port = None
try:
def readline():
buf = b""
while not buf.endswith(b"\n"):
ch = c.recv(1)
if not ch:
break
buf += ch
return buf.decode(errors="replace").strip()
def cmd(line):
c.sendall((line + "\r\n").encode())
return readline()
greet = readline()
if not greet.startswith("220"):
return False, None, None, "no greeting: " + greet
r = cmd("USER " + user)
if not r.startswith("331"):
return False, None, None, "USER: " + r
r = cmd("PASS " + pwd)
if not r.startswith("230"):
return False, None, None, "PASS: " + r
r = cmd("PASV")
m = re.search(r"\((\d+),(\d+),(\d+),(\d+),(\d+),(\d+)\)", r)
if not r.startswith("227") or not m:
return False, None, None, "PASV: " + r
g = [int(x) for x in m.groups()]
pasv_port = g[4] * 256 + g[5]
d = socket.create_connection((ip, pasv_port), timeout=8)
pc_src = d.getsockname()[1]
r = cmd("STOR " + fname)
if not r.startswith(("125", "150")):
d.close()
return False, pasv_port, pc_src, "STOR: " + r
d.sendall(payload)
d.close()
# drain until final 2xx (multi-line or single)
final = ""
t0 = time.time()
while time.time() - t0 < 10:
r = readline()
if not r:
break
final = r
if r[:1] in ("2", "4", "5"):
break
ok = final.startswith("2")
cmd("QUIT")
return ok, pasv_port, pc_src, ("OK" if ok else "final: " + final)
finally:
c.close()
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--ip", default=IP_DEFAULT)
ap.add_argument("--rounds", type=int, default=5)
ap.add_argument("--delay", type=float, default=2.0,
help="seconds between rounds")
ap.add_argument("--user", default="admin")
ap.add_argument("--pwd", default="admin")
ap.add_argument("--size", type=int, default=1024)
args = ap.parse_args()
payload = bytes((i * 7 + 3) & 0xFF for i in range(args.size))
ports, srcs, oks = [], [], []
for i in range(args.rounds):
t = time.strftime("%H:%M:%S")
ok, port, src, detail = ftp_stor_round(args.ip, args.user, args.pwd,
"PP%d.BIN" % i, payload)
ports.append(port)
srcs.append(src)
oks.append(ok)
print("[%s] round %d: ok=%-5s pasv_port=%-6s pc_src=%-6s %s"
% (t, i + 1, ok, port, src, detail))
if i + 1 < args.rounds:
time.sleep(args.delay)
print("\nports :", ports)
print("pc_src:", srcs)
print("ok :", oks)
same_port = len(set(p for p in ports if p)) == 1
same_src = len(set(s for s in srcs if s)) == 1
print("PASV port constant: %s | PC source port constant: %s"
% (same_port, same_src))
return 0 if all(oks) else 1
if __name__ == "__main__":
sys.exit(main())