docs(skills): 按技能审核报告拆分 8 个大主文件并归档 IEC104 探针
技能主文件只留默认路径、成功输出样例、失败索引表与禁令;长尾规程逐字 搬进各技能 reference/,索引键与 reference 小节标题一一对应。 拆分结果(改前 -> 改后,字节): - keil-build 21779 -> 5837,新建 3 篇 reference - task-worktree 24163 -> 11448,新建 4 篇 reference,A-G/C2 节号保号 - draw-diagram 18907 -> 6496,新建 5 篇 reference - mem-budget 13046 -> 8020,新建 4 篇 reference - id-family-semantic-migration 11509 -> 8077,新建 2 篇 reference - stale-doc-count-sweep 8156 -> 6371,新建 1 篇 reference - serial-boot-test 8464 -> 6663,新建 2 篇 reference - board-ui-nav 5350 -> 4364,新建 1 篇 reference 其余 9 个技能补真实成功输出样例(判据串取自本轮实跑或文档原文)。 check_skill_size.py rc=0,17 个主文件无悬空指针。 IEC104 探针入库:ci-artifacts/ 里可复用的三个验收脚本迁入 test/host/iec104_dtu/(纯标准库、argparse、ASCII 输出、exit 0/1/2), 协议逻辑逐字保留,含三处探针自身缺陷修复(GI 漏 3 字节 IOA、I 帧 过滤判反、MEAS 键用 source_addr 而非 IOA)。一次性设计度量按 PROBE_INDEX.md 登记不迁入,运行方法见 PROBE_RUNBOOK.md。
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
"""LAN reachability verification for the IEC 60870-5-104 simulator listener.
|
||||
|
||||
Run after a simulator bind-address change (or before a LAN bench session) to
|
||||
confirm the listener is bound to 0.0.0.0 and answers STARTDT on local IPv4
|
||||
addresses. It starts the local lvgl_sim binary in headless IEC104 duration mode.
|
||||
Prerequisites: simulator/build/Debug/lvgl_sim.exe exists with the IEC104 CLI
|
||||
contract, Get-NetTCPConnection is available, and local IPv4 is configured.
|
||||
A missing binary, wrong bind address, bad STARTDT reply or simulator exits
|
||||
nonzero returns 1; a PowerShell/tooling error returns 2.
|
||||
This checks the same host only: it does not prove another LAN device can pass
|
||||
through a firewall.
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import pathlib
|
||||
import re
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
def parser():
|
||||
p = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
p.add_argument("--exe", type=pathlib.Path,
|
||||
default=pathlib.Path(__file__).resolve().parents[2] / "simulator/build/Debug/lvgl_sim.exe",
|
||||
help="lvgl_sim executable to start")
|
||||
p.add_argument("--output", type=pathlib.Path,
|
||||
default=pathlib.Path(__file__).resolve().parents[2] / "ci-artifacts/iec104-lan",
|
||||
help="directory for report.json")
|
||||
p.add_argument("--duration", type=int, default=12,
|
||||
help="simulator lifetime in seconds")
|
||||
p.add_argument("--lan-ip", default=None,
|
||||
help="extra local IPv4 address to probe; auto-detected when present")
|
||||
return p
|
||||
|
||||
|
||||
def powershell(code):
|
||||
r = subprocess.run(["powershell.exe", "-NoProfile", "-Command", code],
|
||||
capture_output=True, text=True, timeout=15)
|
||||
assert r.returncode == 0, (r.returncode, r.stdout, r.stderr)
|
||||
return r.stdout.strip()
|
||||
|
||||
|
||||
def main():
|
||||
args = parser().parse_args()
|
||||
exe = args.exe.resolve()
|
||||
out = args.output.resolve()
|
||||
if not exe.is_file():
|
||||
print("MISSING exe: %s" % exe)
|
||||
return 2
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
ips = json.loads(powershell(
|
||||
"ConvertTo-Json -Compress -InputObject @(Get-NetIPAddress "
|
||||
"-AddressFamily IPv4 | Select-Object -ExpandProperty IPAddress)"))
|
||||
if args.lan_ip:
|
||||
ips.append(args.lan_ip)
|
||||
process = subprocess.Popen(
|
||||
[str(exe), "--iec104", "--iec104-headless", "--iec104-port", "0",
|
||||
"--iec104-duration", str(args.duration)],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
try:
|
||||
ready = process.stdout.readline().strip()
|
||||
match = re.search(r"port=(\d+)", ready)
|
||||
assert match, ready
|
||||
port = int(match.group(1))
|
||||
listeners = json.loads(powershell(
|
||||
"ConvertTo-Json -Compress -InputObject @(Get-NetTCPConnection "
|
||||
"-State Listen -LocalPort %d | Select-Object LocalAddress,LocalPort,OwningProcess)" % port))
|
||||
assert any(x["LocalAddress"] == "0.0.0.0" and x["OwningProcess"] == process.pid
|
||||
for x in listeners), listeners
|
||||
results = []
|
||||
targets = ["127.0.0.1"] + ([args.lan_ip] if args.lan_ip else [])
|
||||
for host in targets:
|
||||
time.sleep(0.25)
|
||||
with socket.create_connection((host, port), timeout=3) as sock:
|
||||
sock.settimeout(3)
|
||||
sock.sendall(bytes.fromhex("680407000000"))
|
||||
data = b""
|
||||
while len(data) < 6:
|
||||
data += sock.recv(6 - len(data))
|
||||
assert data == bytes.fromhex("68040b000000"), data.hex()
|
||||
results.append({"target": host, "sent": "680407000000",
|
||||
"received": data.hex(), "scope": "same-host only"})
|
||||
stdout, stderr = process.communicate(timeout=args.duration + 10)
|
||||
assert process.returncode == 0, (process.returncode, stderr)
|
||||
leftovers = json.loads(powershell(
|
||||
"ConvertTo-Json -Compress -InputObject @(Get-NetTCPConnection -State Listen "
|
||||
"-LocalPort %d -ErrorAction SilentlyContinue | Where-Object OwningProcess -eq %d)" %
|
||||
(port, process.pid)))
|
||||
assert not leftovers, leftovers
|
||||
report = {"exe": str(exe), "sha256": hashlib.sha256(exe.read_bytes()).hexdigest(),
|
||||
"pid": process.pid, "ready": ready, "local_ipv4": ips,
|
||||
"listeners": listeners, "handshakes": results,
|
||||
"exit_code": process.returncode, "stdout": stdout, "stderr": stderr,
|
||||
"remote_firewall_verified": False, "listener_after_exit": False}
|
||||
(out / "report.json").write_text(json.dumps(report, indent=2), encoding="utf-8")
|
||||
print(json.dumps(report, indent=2))
|
||||
return 0
|
||||
finally:
|
||||
if process.poll() is None:
|
||||
process.terminate()
|
||||
process.communicate(timeout=5)
|
||||
except (OSError, subprocess.SubprocessError, ValueError, AssertionError) as exc:
|
||||
print("FAIL: %s" % type(exc).__name__)
|
||||
print(str(exc)[:1000])
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user