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」状态词。冻结历史证据(带日期戳的台架日志)与 编号别名登记表里的旧路径按原样保留。
131 lines
5.5 KiB
Python
131 lines
5.5 KiB
Python
# -*- coding: utf-8 -*-
|
||
# Trustworthy TC-NET-604 freeze reproduction via the REAL production path.
|
||
#
|
||
# Why this one is trustworthy (unlike the 2026-09-22 probe batteries):
|
||
# * Production firmware, no in-firmware readers/probes -> the "a test reader ate the
|
||
# peer's bytes and the PC saw a short stream" artifact class cannot occur.
|
||
# * Judgement = the FTP client's own protocol result (STOR/RETR replies) plus an
|
||
# end-to-end SHA-256 taken from a RETR of the uploaded file (content ground truth).
|
||
# * Data-channel stall vs whole-net-layer stall is distinguished by a NOOP on the
|
||
# CONTROL channel (a different socket) while the data channel is stuck.
|
||
# * Only the device's own production logs are used for the device-side timeline
|
||
# (window them by the per-round "TS <epoch>" line printed here).
|
||
#
|
||
# Usage: ftp_freeze_probe.py [--ip <设备IP>] [--port 21] [--size 65536]
|
||
# [--rounds 10] [--gap 3] [--keep]
|
||
# Output lines (machine-auditable):
|
||
# TS <epoch>
|
||
# ROUND <n> size=<bytes> stor=<OK|FAIL:reason> t_stor=<s> retr=<OK|FAIL:reason>
|
||
# t_retr=<s> hash=<MATCH|MISMATCH|NA> [ctrl=<alive|dead|na>]
|
||
# SUMMARY rounds=<n> pass=<n> fail=<n>
|
||
# Exit: 0 all pass / 1 any failure / 2 usage or connect error.
|
||
import argparse, hashlib, io, os, random, socket, sys, time
|
||
from ftplib import FTP, error_reply, error_temp, error_perm, all_errors
|
||
|
||
# 台架连接默认值单一真源在 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
|
||
|
||
# Device-side FTP auth: lftpd validates against /config.ini [ftp] (user / pwd_hash).
|
||
# This device has NO anonymous channel (USER anonymous -> 530), so the probe must log
|
||
# in with the factory account. Override with --user/--password if it was changed.
|
||
FTP_USER = "admin"
|
||
FTP_PASS = "admin"
|
||
|
||
|
||
def log(msg):
|
||
sys.stdout.write(msg + "\n")
|
||
sys.stdout.flush()
|
||
|
||
def liveness(ip, port, timeout=3.0):
|
||
"""Control-channel liveness on a FRESH connection (production lftpd control path)."""
|
||
try:
|
||
f = FTP()
|
||
f.connect(ip, port, timeout=timeout)
|
||
f.login(FTP_USER, FTP_PASS)
|
||
f.voidcmd("NOOP")
|
||
f.quit()
|
||
return "alive"
|
||
except Exception:
|
||
return "dead"
|
||
|
||
def main():
|
||
global FTP_USER, FTP_PASS # 两处登录点都读模块常量,命令行覆盖后即刻生效
|
||
ap = argparse.ArgumentParser()
|
||
ap.add_argument("--ip", default=bench_defaults.DEVICE_IP)
|
||
ap.add_argument("--port", type=int, default=21)
|
||
ap.add_argument("--size", type=int, default=65536)
|
||
ap.add_argument("--rounds", type=int, default=10)
|
||
ap.add_argument("--gap", type=float, default=3.0)
|
||
ap.add_argument("--keep", action="store_true", help="do not DELE the uploaded file")
|
||
ap.add_argument("--seed", type=int, default=604)
|
||
ap.add_argument("--user", default="admin",
|
||
help="FTP user (device auth; this device has no anonymous channel)")
|
||
ap.add_argument("--password", default="admin", help="FTP password (factory default)")
|
||
a = ap.parse_args()
|
||
FTP_USER, FTP_PASS = a.user, a.password
|
||
|
||
rng = random.Random(a.seed)
|
||
npass = nfail = 0
|
||
for n in range(1, a.rounds + 1):
|
||
data = bytes(rng.getrandbits(8) for _ in range(a.size))
|
||
want = hashlib.sha256(data).hexdigest()
|
||
name = "/fz%04d.bin" % n
|
||
log("TS %d" % int(time.time()))
|
||
f = FTP()
|
||
stor = retr = "NA"
|
||
t_stor = t_retr = 0.0
|
||
got_hash = "NA"
|
||
ctrl = "na"
|
||
try:
|
||
f.connect(a.ip, a.port, timeout=15.0)
|
||
f.login(FTP_USER, FTP_PASS)
|
||
t0 = time.time()
|
||
try:
|
||
f.storbinary("STOR " + name, io.BytesIO(data), blocksize=8192)
|
||
stor = "OK"
|
||
except all_errors as e:
|
||
stor = "FAIL:%s" % type(e).__name__
|
||
ctrl = liveness(a.ip, a.port)
|
||
t_stor = time.time() - t0
|
||
if stor == "OK":
|
||
buf = bytearray()
|
||
t0 = time.time()
|
||
try:
|
||
f.retrbinary("RETR " + name, buf.extend, blocksize=8192)
|
||
retr = "OK"
|
||
got_hash = "MATCH" if hashlib.sha256(bytes(buf)).hexdigest() == want else "MISMATCH"
|
||
except all_errors as e:
|
||
retr = "FAIL:%s" % type(e).__name__
|
||
ctrl = liveness(a.ip, a.port)
|
||
t_retr = time.time() - t0
|
||
if not a.keep:
|
||
try:
|
||
f.delete(name)
|
||
except all_errors:
|
||
pass
|
||
try:
|
||
f.quit()
|
||
except all_errors:
|
||
try:
|
||
f.close()
|
||
except Exception:
|
||
pass
|
||
except all_errors as e:
|
||
stor = "FAIL:connect-%s" % type(e).__name__
|
||
ctrl = liveness(a.ip, a.port)
|
||
ok = (stor == "OK" and retr == "OK" and got_hash == "MATCH")
|
||
npass += 1 if ok else 0
|
||
nfail += 0 if ok else 1
|
||
log("ROUND %d size=%d stor=%s t_stor=%.2f retr=%s t_retr=%.2f hash=%s ctrl=%s" %
|
||
(n, a.size, stor, t_stor, retr, t_retr, got_hash, ctrl))
|
||
if a.gap > 0 and n < a.rounds:
|
||
time.sleep(a.gap)
|
||
log("SUMMARY rounds=%d pass=%d fail=%d" % (a.rounds, npass, nfail))
|
||
return 0 if nfail == 0 else 1
|
||
|
||
sys.exit(main())
|