2e9272cc8a
引入成熟 IEC 60870-5-104 子站的只读子集(App/protocol/iec60870,28 个源文件 按原字节复制,UPSTREAM.sha256 记录来源,兼容补丁保留全部断言与容量),在其上 装配单属主共享核心(Start/Poll/Stop/Get_Status),并把标准 DTU 演示点表全量 接入为唯一真源。 - iec104_core:threadless 推进,poll 零等待,通知/交互/COV 扫描全部有界; 生命周期区分失败启动待重试、重复启动拒绝、断线保固化 RAM。 - iec104_dtu_table / iec104_source:标准 DTU 全点表注册,无数据源的点读 0, 遥控只做模拟状态可读回,不触碰实际出口。 - iec104_sim:仅窗口与独立服务模式起真实 TCP,无头黄金模式保持确定性假统计。 - test/host/iec104_dtu:独立真实 TCP 11 项、传输层 10 项、生命周期与借用负例。 验证:lvgl_sim 真实 TCP 11/11、传输 10/10,UI 像素回归未回退;AC5 单 TU 编译 0 错误 0 诊断。板端尚未切换:完整库闭包 RAM 超 92% 门禁净增预算 25730B, 结论为停止转实施,记录在 IEC104_MCU最小可行性验证.md。旧实现与 board 服务 保持原样,未提交 MDK 工程改动,未烧板。
75 lines
5.0 KiB
Python
75 lines
5.0 KiB
Python
"""Original independent Net fixtures compiled ONLY against migrated vendor code."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
from oracle import ROOT
|
|
sys.path.insert(0, str(ROOT / "test/host/common"))
|
|
from unit_test_harness import decode, locate_toolchain
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--output", type=Path, default=ROOT / "ci-artifacts/iec104-tests/transport")
|
|
parser.add_argument("--only", default="")
|
|
args = parser.parse_args()
|
|
output = args.output.resolve()
|
|
output.mkdir(parents=True, exist_ok=True)
|
|
vendor = ROOT / "App/protocol/iec60870"
|
|
original = ROOT / "IEC60870-Slave/test"
|
|
cl, inc, lib = locate_toolchain()
|
|
if not cl:
|
|
raise RuntimeError("MSVC compiler not found")
|
|
env = dict(os.environ, INCLUDE=os.pathsep.join(inc), LIB=os.pathsep.join(lib))
|
|
sources = [vendor / line.split(" ", 1)[1] for line in (vendor / "UPSTREAM.sha256").read_text().splitlines() if line.endswith(".c")]
|
|
# Each fixture includes vendor TcpServer.c and provides the Net implementation.
|
|
sources = [p for p in sources if p.name not in ("IEC104_TcpServer.c", "IEC104_Net_Windows.c")]
|
|
assert len(sources) >= 26 and all(p.is_file() for p in sources)
|
|
include = [vendor / "104", vendor / "104/business", vendor / "common", vendor / "platform", vendor / "examples", original]
|
|
names = ("iec104_response_transport_test", "iec104_ack_tracking_test", "iec104_idle_transport_test", "iec104_strict_priority_transport_test", "iec104_tcp_event_ring_test", "iec104_tcp_scheduler_test", "iec104_remote_parameter_test")
|
|
results = []
|
|
for name in names + ("source_binding_test", "vendor_boundary_test", "core_lifecycle_test"):
|
|
if args.only and args.only not in name:
|
|
continue
|
|
target = output / name
|
|
target.mkdir(exist_ok=True)
|
|
fixture = Path(__file__).parent / (name + ".c") if name in ("source_binding_test", "vendor_boundary_test", "core_lifecycle_test") else original / (name + ".c")
|
|
adaptation = None
|
|
if name == "iec104_idle_transport_test":
|
|
text = fixture.read_text(encoding="utf-8-sig")
|
|
old = " CHECK(IEC104_Receiver_Feed(&sut->connection.receiver, sut->generation, bytes, length, &consumed) =="
|
|
new = " CHECK(length <= UINT32_MAX);\n CHECK(IEC104_Receiver_Feed(&sut->connection.receiver, sut->generation, bytes, (uint32_t)length, &consumed) =="
|
|
assert text.count(old) == 1
|
|
adaptation = {"original_sha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "change": "checked size_t to uint32 length conversion for MSVC x64 only"}
|
|
fixture = target / "idle_fixture_checked.c"
|
|
fixture.write_text(text.replace(old, new), encoding="utf-8")
|
|
extra = []
|
|
if name == "source_binding_test":
|
|
extra = [ROOT / "App/protocol/iec104/iec104_source.c", ROOT / "App/protocol/iec104/iec104_dtu_table.c", vendor / "104/IEC104_Net_Windows.c", vendor / "104/IEC104_TcpServer.c"]
|
|
if name == "core_lifecycle_test":
|
|
extra = [ROOT / "App/protocol/iec104/iec104_core.c", ROOT / "App/protocol/iec104/iec104_source.c", ROOT / "App/protocol/iec104/iec104_dtu_table.c"]
|
|
flags = ["/nologo", "/std:c11", "/O2", "/W3", "/WX", "/utf-8", "/D_CRT_SECURE_NO_WARNINGS"]
|
|
if name == "iec104_remote_parameter_test":
|
|
flags += ["/DIEC104_REMOTE_PARAMETER_TEST_HOOKS", "/DIEC104_TCP_HIGH_CAPACITY=251"]
|
|
command = [cl] + flags + ["/I" + str(p) for p in include] + ["/I" + str(ROOT / "App/protocol/iec104")] + [str(fixture)] + [str(p) for p in sources + extra] + ["/Fe:" + str(target / (name + ".exe"))] + (["/link", "ws2_32.lib"] if extra else [])
|
|
build = subprocess.run(command, cwd=target, env=env, capture_output=True)
|
|
(target / "build.log").write_text(decode(build.stdout) + decode(build.stderr), encoding="utf-8")
|
|
row = {"name": name, "build_rc": build.returncode, "command": command, "fixture_sha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "adaptation": adaptation, "extra_sources_sha256": {str(p.relative_to(ROOT)): hashlib.sha256(p.read_bytes()).hexdigest() for p in extra}}
|
|
if build.returncode == 0:
|
|
run = subprocess.run([str(target / (name + ".exe"))], cwd=target, capture_output=True, timeout=120)
|
|
(target / "run.log").write_text(decode(run.stdout) + decode(run.stderr), encoding="utf-8")
|
|
row["run_rc"] = run.returncode
|
|
results.append(row)
|
|
print(name, row.get("run_rc", "build failed"), flush=True)
|
|
report = {"compiler": cl, "vendor_sources": {str(p.relative_to(ROOT)): hashlib.sha256(p.read_bytes()).hexdigest() for p in sources}, "tcp_source_sha256": hashlib.sha256((vendor / "104/IEC104_TcpServer.c").read_bytes()).hexdigest(), "results": results}
|
|
(output / "report.json").write_text(json.dumps(report, indent=2), encoding="utf-8")
|
|
return 0 if all(r.get("run_rc", -1) == 0 for r in results) else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|