b584601174
技能主文件只留默认路径、成功输出样例、失败索引表与禁令;长尾规程逐字 搬进各技能 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。
121 lines
5.1 KiB
Python
121 lines
5.1 KiB
Python
"""Simulator duration-mode evidence: refused command, clock sync, clean STOP.
|
|
|
|
Run when IEC104 simulator STOP-summary evidence is needed, especially because
|
|
run_tcp_test.py terminates the process before it prints simulated_actions.
|
|
This probe uses --iec104-duration so the headless loop exits on its own.
|
|
Prerequisites: a simulator binary supporting --iec104-headless and
|
|
--iec104-duration is available and the chosen port is free.
|
|
Exit 0 = refusals/completion/clock checks passed and simulator exited 0;
|
|
1 = a behavioural check failed; 2 = simulator could not be started or read.
|
|
"""
|
|
import argparse
|
|
import pathlib
|
|
import socket
|
|
import struct
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(ROOT / "test" / "host" / "iec104_dtu"))
|
|
|
|
from wire import Client, asdu, cp56, header, u24 # noqa: E402
|
|
|
|
|
|
def wait_listen(host, port, deadline_s=15.0):
|
|
deadline = time.monotonic() + deadline_s
|
|
while time.monotonic() < deadline:
|
|
try:
|
|
with socket.create_connection((host, port), 0.2):
|
|
return
|
|
except OSError:
|
|
time.sleep(0.05)
|
|
raise TimeoutError("simulator did not listen")
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
parser.add_argument("--exe", type=pathlib.Path, required=True)
|
|
parser.add_argument("--host", default="127.0.0.1")
|
|
parser.add_argument("--port", type=int, default=24040)
|
|
parser.add_argument("--duration", type=int, default=10)
|
|
parser.add_argument("--output", type=pathlib.Path,
|
|
default=ROOT / "ci-artifacts/iec104-tests/duration-evidence")
|
|
args = parser.parse_args()
|
|
|
|
args.output.mkdir(parents=True, exist_ok=True)
|
|
log_path = args.output / "simulator.log"
|
|
trace = []
|
|
problems = []
|
|
|
|
try:
|
|
with log_path.open("w", encoding="utf-8") as log:
|
|
process = subprocess.Popen(
|
|
[str(args.exe), "--iec104", "--iec104-headless",
|
|
"--iec104-port", str(args.port), "--iec104-duration", str(args.duration)],
|
|
cwd=str(args.output), stdout=log, stderr=subprocess.STDOUT)
|
|
try:
|
|
wait_listen(args.host, args.port)
|
|
client = Client(args.host, args.port, trace)
|
|
client.start()
|
|
|
|
# 1) SELECT then EXECUTE on a command point: both must be refused.
|
|
client.request(asdu(46, u24(0x6002) + bytes((2 | 128,))))
|
|
data = client.response(46, 7, pn=True)
|
|
assert header(data)["cot"] == 7, data.hex()
|
|
print("REFUSED select ioa=0x6002 cot=%d pn=%s" %
|
|
(header(data)["cot"], header(data)["pn"]))
|
|
|
|
client.request(asdu(46, u24(0x6002) + bytes((2,))))
|
|
data = client.response(46, 7, pn=True)
|
|
assert header(data)["cot"] == 7, data.hex()
|
|
print("REFUSED execute ioa=0x6002 cot=%d pn=%s" %
|
|
(header(data)["cot"], header(data)["pn"]))
|
|
|
|
# 2) One clock sync so clock_sets is exercised (device-only, no OS clock).
|
|
stamp = struct.pack("<HBBBBB", 30000, 22, 11, 17, 6, 35)
|
|
client.request(asdu(103, u24(0) + stamp))
|
|
client.response(103, 7)
|
|
client.request(asdu(103, u24(0) + bytes(7), cot=5))
|
|
reply = client.response(103, 5)
|
|
print("CLOCK sync iso=%s" % cp56(reply[-7:])["iso"])
|
|
|
|
# 3) Confirm no ACT_TERM / no return-info followed the refusals.
|
|
start = len(client.asdus)
|
|
deadline = time.monotonic() + 0.5
|
|
try:
|
|
while time.monotonic() < deadline:
|
|
client.frame(deadline)
|
|
except (socket.timeout, TimeoutError):
|
|
pass
|
|
for item in client.asdus[start:]:
|
|
item_header = header(item)
|
|
assert not (item_header["type"] == 46 and item_header["cot"] == 10), item.hex()
|
|
assert item_header["cot"] != 11, item.hex()
|
|
print("NO_COMPLETION verified (no COT 10, no COT 11)")
|
|
|
|
client.close()
|
|
print("CLIENT closed, waiting for graceful stop...", flush=True)
|
|
rc = process.wait(timeout=args.duration + 30)
|
|
print("SIMULATOR exit=%d" % rc)
|
|
if rc != 0:
|
|
problems.append("simulator exit %d" % rc)
|
|
finally:
|
|
if process.poll() is None:
|
|
process.terminate()
|
|
try:
|
|
process.wait(timeout=10)
|
|
except subprocess.TimeoutExpired:
|
|
process.kill()
|
|
print("\n===== simulator.log =====")
|
|
print(log_path.read_text(encoding="utf-8").strip())
|
|
except (OSError, subprocess.SubprocessError, socket.timeout, TimeoutError,
|
|
AssertionError, ValueError) as exc:
|
|
print("FAIL %s: %s" % (type(exc).__name__, str(exc)[:500]))
|
|
return 2
|
|
return 1 if problems else 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|