e4981aa2f6
AGENTS.md stopped being the store of record for build steps, Python env, hardware pins, doc conventions, log cost and task ownership. Those facts already live in docs, skills and role files; the entry file now only points at them. This commit moves every reference that used to name the entry file to the authoritative landing point, so a reader who follows a link arrives at the fact instead of at a sentence that no longer exists. What changed is links and prose, not behaviour. Code, scripts and tests only have comment and docstring lines touched; the only non-comment edit in the whole changeset is one note string inside the generated pin table JSON, and its generator was changed in the same step so the two stay byte-identical. New landing points created before the references were retargeted: - The console single-writer log design doc, section 7.1, is now the single authority for log cost: about 90 B flash and 216 B stack per DBG_ line, and the rule that deep call chains must predefine DBG_LINE_BUF_MAX. It also carries the full list of the twelve translation units that have tightened it, plus the grep command that decides the truth if the list and the code ever disagree. - The document writing standard, section 2, now holds the BOM list. - keil-build skill gains an exit code table: 0 success, 1 build failure, 2 BuildEnvError, 3 usage, 4 build lock held. This corrects a belief that was never actually written down anywhere: exit 2 does not simply mean environment error, argparse also exits 2 and the wrapper script was remapped so the two no longer collide. Regenerated and checked byte for byte: - The end-to-end architecture SVG in docs/images from its generator. - tools/netlist_semantics/pinout_kb.json from gen_kb.py. Both are idempotent; running the generators again produces no diff. Deliberately not touched, because machines read them: - scripts/check_bom_drift.py joins every line containing BOM and asserts four paths are present, so the entry file BOM line must stay one line. - scripts/gen_task_table.py reads the TASK_TABLE anchors directly. - scripts/rename_maps and scripts/archive keep their historical wording; they describe what happened, not what is true now. Verified: doc links report the same six pre-existing findings as the base commit and no new ones, generated-fresh passes, bom drift is clean across 101 files, and AGENTS.md itself is unchanged in this commit.
77 lines
3.8 KiB
Python
77 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""IEC 104 上行服务生命周期(iec104_serv)主机侧纯逻辑单元测试运行器(纯标准库)。
|
||
|
||
做什么:
|
||
用本机 MSVC 编译 test/host/iec104_serv/iec104_serv_test.c(以 #include 纳入生产源
|
||
App/task/iec104_serv.c),离线驱动它的全部 static 辅助函数(**不跑 never-returning
|
||
的任务主循环**),验证监听建立与失败回收、网络代次一变就重建监听、accept 门控与
|
||
表项失效自愈、单连接 socket 的断线语义、连续短写判死、活性分频探活、协议掉回 IDLE
|
||
时丢弃重生,以及时钟桥接的两个溢出边界。
|
||
|
||
为什么要主机侧单测(而不是只用台架):
|
||
104 主站掉线重连是现场最常见故障形态,但台架无法按需制造"改 IP 时正好有连接"
|
||
"对端 FIN 与 RST 的区别""连续三次短写";这几条处理错的后果都是端口永久失联或
|
||
会话卡死,只能等主站侧超时才发现。判死用**连续**短写计数(成功即复位),写成累计
|
||
就会把偶发拥塞误判成断线;时钟桥接的 >4G 秒必须拒绝、未对时必须回哨兵而不是 0;
|
||
活性分频写错就成了每轮多一次系统调用或 TESTFR 迟迟不发。
|
||
|
||
桩的边界:iec104_link.h / iec104_pts.h / prot_set.h / sys_clock.h / sys_events.h /
|
||
task_watchdog.h / net_types.h 用真实头(iec104_state_t、cfg 的函数指针签名、
|
||
TASK_WD_IEC104=7、SYS_EVT_* 位值一改即编译期报错);链路层与 pts 层给假件——链路
|
||
协议本身有 test/host/iec104 的 97 条专测,本模块只管服务怎么活、怎么死、怎么重生;
|
||
socket 面给可控假件(连 socket 号、发送返回、错误码、代次、门控都能注入)。
|
||
|
||
用法(仓库根目录):
|
||
python test/host/iec104_serv/run_unit_test.py
|
||
|
||
退出码:0=PASS / 1=测试失败 / 2=环境错误。
|
||
|
||
设计依据:docs/子系统设计/*104* 设计文档、docs/网络/网络自愈架构设计.md §4.10(单连接 socket 断开语义、
|
||
错误码经任务通知值回传)、docs/测试说明/单元测试/主机单测覆盖率口径.md §9
|
||
创建日期:2026-10-23
|
||
"""
|
||
import os
|
||
import sys
|
||
|
||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(HERE)))
|
||
sys.path.insert(0, os.path.join(ROOT, "test", "host", "common"))
|
||
|
||
from unit_test_harness import TestBuild, run_host_unit_test # noqa: E402
|
||
|
||
|
||
def _header_dirs(base):
|
||
"""收集 base 下所有**真的放着 .h** 的目录。
|
||
|
||
104 服务要 include 的 iec104_serv.h / iec104_link.h / iec104_pts.h /
|
||
task_watchdog.h / sys_clock.h / sys_events.h / prot_set.h 散在 App 的多个
|
||
子目录里,逐个手写列表一定会漏(漏一个就是 C1083,而且报错落在被测源上,
|
||
很容易被误读成生产代码坏了)。这里按目录实际内容自动收集,多给几个 /I
|
||
对编译没有代价,却把"漏目录"这类脆错误消掉。
|
||
"""
|
||
dirs = []
|
||
for root, _sub, files in os.walk(base):
|
||
if any(f.endswith(".h") for f in files):
|
||
dirs.append(root)
|
||
return sorted(dirs)
|
||
|
||
|
||
BUILD = TestBuild(
|
||
name="IEC104 SERV Tests",
|
||
src=os.path.join(HERE, "iec104_serv_test.c"),
|
||
include_dirs=[
|
||
os.path.join(HERE, "stub"), # 必须先于真头目录(覆盖 net_socket.h 等)
|
||
] + _header_dirs(os.path.join(ROOT, "App")) +
|
||
# sys_clock.h 会拉 sd2506.h(Drivers/BSP/SD2506),BSP 的头也散在多个子目录里,
|
||
# 同样按实际内容收集。注意 stub 目录排在最前,桩依然优先于这些真头。
|
||
_header_dirs(os.path.join(ROOT, "Drivers", "BSP")) + [
|
||
os.path.join(ROOT, "Drivers", "BSP", "NET"),
|
||
HERE,
|
||
],
|
||
summary_marker="=== IEC104 SERV Tests:",
|
||
)
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(run_host_unit_test(BUILD))
|