Files
STM32F4-Base/MDK-ARM/ftp_freeze_probe.py
T
wandering1 7efa58d9a1
CI / 静态门禁 (pre-commit) (push) Failing after 25s
CI / 主机侧单测 (MSVC) (push) Successful in 48s
network: 台架 IP 迁到 192.168.31.100,并把重复写死的值收进单一真源
分两段(用户裁定 2026-11-02):先做地址迁移,再把同类字面量收敛成
单一真源,以后再改地址只动一处。

一、IP 迁移 192.168.1.100 → 192.168.31.100(gw 同步 → .31.1)
- 工厂默认:Drivers/BSP/NETCFG/net_cfg.c 的 NET_CFG_DEF_IP/_GW
- 注释/文档示例、主机与板级测试、台架 py 脚本、两份 sim_config.ini
- 字节序教学点同步换算 hex:0x6401A8C0 → 0x641FA8C0(内存
  C0 A8 1F 64),旧版示例引文与历史 Trap 记录按冻结纪律不动
- UI 黄金基准:网口设置 4 态 + shot_info 共 5 张 .bin 由
  check_content_pages.py --update 重刷(渲染值 IP 变了,属预期变更)
- 保留判定:客户点表引用(IEC104/继电保护规划)、芯片手册摘录、
  日期冻结的变更记录行、已退役台架档案 MDK-ARM/retracted_bench_*

二、单一真源收口(A+B+C+D,用户批准全做)
- 新建 test/host/bench_defaults.py:台架 py 默认值唯一定义点
  (DEVICE_IP/DEVICE_GW/PC_IP/NET_BCAST),22 个脚本改为引用;
  MDK-ARM 两探针与 scripts/board_ui_nav.py 经 sys.path shim 引入
- test/board/net_test_task.h 新增 TEST_PC_PEER_IP,板测三处
  PHASE*_REMOTE_IP 改引该宏(保留 -D 覆盖);Phase1 断言改
  memcmp 数组比较,数组各只出现一次
- simulator/tests/check_content_pages.py 从 net_cfg.c 正则解析
  NET_CFG_DEF_* 推导期望值(解析失败即报错、不静默兜底),
  脚本内台架 IP 字面量清零
- 装饰性注释去具体值(net_cfg.h/net_socket.h/net_socket.c/
  net_socket_sim.c);字节序教学 hex 对刻意保留为唯一写值点
- 刻意不动:主机单测夹具 IP(逐文件钉住的任意值是正确测试
  实践)、文档正文 IP(那是文档内容本身)

顺带:scripts/gen_task_table.py 规范串清掉「,B5」——编号清退提交
72b4b094 改了受管区没重跑生成器,task-table 门禁因此一直红

验证:产品 @build 0/0;CH395F 套件开关构建 0/0 后还原产品态;
6 套主机单测 rc=0;content_pages(含宏推导路径)/菜单 8 态/
推流位比对全 PASS;bom-drift 99 无漂移;doc-links/coding-standard/
cppcheck 绿;py_compile 23 文件 + --help 冒烟(含 shim 绝对路径)
2026-11-02 14:46:42 +08:00

131 lines
5.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- 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_defaults.py(跨目录:补 sys.path 后 import)
_sys_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"..", "test", "host")
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())