685a366890
原来 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」状态词。冻结历史证据(带日期戳的台架日志)与 编号别名登记表里的旧路径按原样保留。
89 lines
3.5 KiB
Python
89 lines
3.5 KiB
Python
# -*- coding: utf-8 -*-
|
||
# TRAP-NET-17 复现探针:快速重连到设备监听器: rapid reconnect to a device listener.
|
||
#
|
||
# Failure under test (original report): after a rapid reconnect (<~1s) on a
|
||
# relistened socket, the chip completes the handshake but the MCU never gets
|
||
# standalone accept -> the socket stays LISTENING -> later the chip auto-closes it
|
||
# -> THE LISTENER DIES PERMANENTLY (all later SYNs refused, no self-recovery).
|
||
#
|
||
# Judgement is purely client-side (no firmware probes):
|
||
# * every round must (re)connect successfully within --timeout
|
||
# * on failure the probe keeps retrying for --recover-s to distinguish
|
||
# "transient" from "permanently dead listener"
|
||
#
|
||
# Usage: tcp_reconnect_probe.py [--host <设备IP>] [--port 21] [--rounds 50]
|
||
# [--gap-ms 600] [--timeout 3] [--recover-s 10]
|
||
# [--banner] (read one line after connect, e.g. FTP 220)
|
||
# Output:
|
||
# TS <epoch>
|
||
# ROUND <n> gap=<ms> connect=<OK|FAIL:reason> recovered=<na|yes|no>
|
||
# SUMMARY rounds=<n> ok=<n> fail=<n> unrecovered=<n>
|
||
# Exit: 0 all rounds connected / 1 any failure / 2 usage
|
||
import argparse, os, socket, sys, time
|
||
|
||
# 台架连接默认值单一真源在 test/host/bench/bench_defaults.py(跨目录:补 sys.path 后 import)
|
||
_sys_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
|
||
"..", "test", "host", "bench")
|
||
if _sys_path not in sys.path:
|
||
sys.path.insert(0, _sys_path)
|
||
import bench_defaults # noqa: E402
|
||
|
||
def log(m):
|
||
sys.stdout.write(m + "\n"); sys.stdout.flush()
|
||
|
||
def try_connect(host, port, timeout, banner):
|
||
s = socket.create_connection((host, port), timeout=timeout)
|
||
if banner:
|
||
s.settimeout(timeout)
|
||
try:
|
||
s.recv(256) # e.g. FTP "220 ..." greeting
|
||
except socket.timeout:
|
||
pass
|
||
return s
|
||
|
||
def main():
|
||
ap = argparse.ArgumentParser()
|
||
ap.add_argument("--host", default=bench_defaults.DEVICE_IP)
|
||
ap.add_argument("--port", type=int, default=21)
|
||
ap.add_argument("--rounds", type=int, default=50)
|
||
ap.add_argument("--gap-ms", type=int, default=600)
|
||
ap.add_argument("--timeout", type=float, default=3.0)
|
||
ap.add_argument("--recover-s", type=float, default=10.0)
|
||
ap.add_argument("--banner", action="store_true")
|
||
a = ap.parse_args()
|
||
|
||
nok = nfail = nunrec = 0
|
||
for n in range(1, a.rounds + 1):
|
||
log("TS %d" % int(time.time()))
|
||
res = "OK"
|
||
recovered = "na"
|
||
try:
|
||
s = try_connect(a.host, a.port, a.timeout, a.banner)
|
||
s.close()
|
||
except Exception as e:
|
||
res = "FAIL:%s" % type(e).__name__
|
||
# keep probing: transient (relisten window) or permanently dead?
|
||
t0 = time.time()
|
||
recovered = "no"
|
||
while time.time() - t0 < a.recover_s:
|
||
time.sleep(0.5)
|
||
try:
|
||
s = try_connect(a.host, a.port, a.timeout, a.banner)
|
||
s.close()
|
||
recovered = "yes"
|
||
break
|
||
except Exception:
|
||
pass
|
||
ok = (res == "OK")
|
||
nok += 1 if ok else 0
|
||
nfail += 0 if ok else 1
|
||
if not ok and recovered != "yes":
|
||
nunrec += 1
|
||
log("ROUND %d gap=%d connect=%s recovered=%s" % (n, a.gap_ms, res, recovered))
|
||
if a.gap_ms > 0 and n < a.rounds:
|
||
time.sleep(a.gap_ms / 1000.0)
|
||
log("SUMMARY rounds=%d ok=%d fail=%d unrecovered=%d" % (a.rounds, nok, nfail, nunrec))
|
||
return 0 if nfail == 0 else 1
|
||
|
||
sys.exit(main())
|