Files
STM32F4-Base/MDK-ARM/tcp_reconnect_probe.py
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

89 lines
3.5 KiB
Python
Raw Permalink 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 -*-
# 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_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
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())