Remove native-launcher fallbacks for the four Dockerized fixtures — Docker is the only supported path for Modbus / S7 / AB CIP / OpcUaClient integration. Native paths stay in place only where Docker isn't compatible (Galaxy: MXAccess COM + Windows-only; TwinCAT: Beckhoff runtime vs Hyper-V; FOCAS: closed-source Fanuc Fwlib32.dll; AB Legacy: PCCC has no OSS simulator). Simplifies the fixture landscape + removes the "which path do I run" ambiguity; removes two full native-launcher directories + the AB CIP native-spawn path; removes the parallel profile-as-CLI-arg-builder code from AbServerFixture.

Modbus — deletes tests/.../Modbus.IntegrationTests/Pymodbus/ (serve.ps1, standard.json, dl205.json, mitsubishi.json, s7_1500.json, README.md). Profile JSONs live only under Docker/profiles/ now. Docker/README.md loses its "Native-Python fallback" section; docs/drivers/Modbus-Test-Fixture.md "What the fixture is" bullet flipped from "primary launcher is Docker, native fallback under Pymodbus/" to "Docker is the only supported launch path".

S7 — deletes tests/.../S7.IntegrationTests/PythonSnap7/ (server.py, s7_1500.json, serve.ps1, README.md). Docker/README.md loses "Native-Python fallback"; docs/drivers/S7-Test-Fixture.md updated to match.

AB CIP — the biggest simplification because the native-binary spawn had the most code. AbServerFixture.cs rewrites: drops Process management (no more Process _proc + Kill/WaitForExit), drops LocateBinary() PATH lookup, drops the IAsyncLifetime initialize-spawns-server behavior. Fixture is now a thin TCP probe against localhost:44818 (or AB_SERVER_ENDPOINT override) — same shape as Snap7ServerFixture / ModbusSimulatorFixture / OpcPlcFixture. IsServerAvailable() simplifies to a single 500 ms probe. AbServerProfile.cs drops AbServerPlcArg + SeedTags + BuildCliArgs + ToCliSpec + the entire AbServerSeedTag record — the compose file is the canonical source of truth for which tags + which --plc mode each family gets; the profile record now carries just Family + ComposeProfile (matches the docker-compose service key) + Notes. KnownProfiles.ForFamily + .All stay for tests that iterate families. AbServerProfileTests.cs rewrites to match: drops BuildCliArgs_* + ToCliSpec_* + SeedTags_* tests; keeps the family-coverage contract tests + verifies the ComposeProfile strings match compose-file service names (a typo in either surfaces as a unit-test failure, not a silent "wrong family booted" at runtime). Docker/README.md loses "Native-binary fallback" section; docs/drivers/AbServer-Test-Fixture.md "What the fixture is" flipped to Docker-only with clearer skip rules.

dev-environment.md §Docker fixtures — the "Native fallbacks" subsection goes away; replaced with a one-line note that Docker is the only supported path for these four fixtures + a fresh clone needs Docker Desktop and nothing else.

Verified: whole-solution build 0 errors, AB CIP profile unit tests 6/6, AB CIP Docker smoke 4/4 (all family theory rows), S7 Docker smoke 3/3. Container lifecycle clean. The deleted native code surface was already redundant — every fixture the native paths served is now covered by Docker; keeping them invited drift between the two paths (the original AB CIP native profile had three undetected bugs per the #162 commit message: case-sensitive --plc, bracket tag notation, --path=1,0 requirement — noise the Docker path now avoids by never running the buggy code).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-04-20 12:27:44 -04:00
parent 27d135bd59
commit 0e1dcc119e
22 changed files with 133 additions and 1307 deletions

View File

@@ -1,10 +1,9 @@
# S7 integration-test fixture — python-snap7 (Docker)
# S7 integration-test fixture — python-snap7
[python-snap7](https://github.com/gijzelaerr/python-snap7) `Server` class
wrapped in a pinned `python:3.12-slim-bookworm` image. Docker is the
primary launcher; the native-Python fallback under
[`../PythonSnap7/`](../PythonSnap7/) is kept for contributors who prefer
to avoid Docker locally.
only supported launch path — a fresh clone needs Docker Desktop and
nothing else.
| File | Purpose |
|---|---|
@@ -86,15 +85,8 @@ Not exercised here — needs a lab rig:
See [`docs/drivers/S7-Test-Fixture.md`](../../../docs/drivers/S7-Test-Fixture.md)
for the full coverage map.
## Native-Python fallback
[`../PythonSnap7/`](../PythonSnap7/) has the same `server.py` + profile
JSON launched via local Python install (`pip install python-snap7`).
Kept for contributors who prefer native.
## References
- [python-snap7 GitHub](https://github.com/gijzelaerr/python-snap7)
- [`../PythonSnap7/README.md`](../PythonSnap7/README.md) — native launcher
- [`docs/drivers/S7-Test-Fixture.md`](../../../docs/drivers/S7-Test-Fixture.md) — coverage map
- [`docs/v2/dev-environment.md`](../../../docs/v2/dev-environment.md) §Docker fixtures

View File

@@ -1,110 +0,0 @@
# python-snap7 server profiles
JSON-driven seed profiles for `snap7.server.Server` from
[python-snap7](https://github.com/gijzelaerr/python-snap7) (MIT). Shape
mirrors the pymodbus profiles under
`tests/ZB.MOM.WW.OtOpcUa.Driver.Modbus.IntegrationTests/Pymodbus/` — a
PowerShell launcher + per-family JSON + a Python shim that the launcher
exec's.
| File | What it seeds | Test category |
|---|---|---|
| [`s7_1500.json`](s7_1500.json) | DB1 (1024 bytes) with smoke values at known offsets (i16 @ DBW10, i32 @ DBD20, f32 @ DBD30, bool @ DBX50.3, scratch word @ DBW100, STRING "Hello" @ 200) + MB (256 bytes) with probe marker at MW0. | `Trait=Integration, Device=S7_1500` |
Default port **1102** (non-privileged; sidesteps Windows Firewall prompt +
Linux's root-required bind on port 102). The fixture
(`Snap7ServerFixture`) defaults to `localhost:1102`. Override via
`S7_SIM_ENDPOINT` to point at a real S7 CPU on port 102. The S7 driver
threads `_options.Port` through to S7netplus's 5-arg `Plc` ctor, so the
non-standard port works end-to-end.
## Install
```powershell
pip install "python-snap7>=2.0"
```
`python-snap7` wraps the upstream `snap7` C library; the install pulls
platform-specific binaries automatically. Requires Python ≥ 3.10.
Windows Firewall will prompt on first bind; allow Private network.
## Run
Foreground (Ctrl+C to stop):
```powershell
.\serve.ps1 -Profile s7_1500
```
Non-default port:
```powershell
.\serve.ps1 -Profile s7_1500 -Port 102
```
Or invoke the Python shim directly:
```powershell
python .\server.py .\s7_1500.json --port 1102
```
## Run the integration tests
In a separate shell with the simulator running:
```powershell
cd C:\Users\dohertj2\Desktop\lmxopcua
dotnet test tests\ZB.MOM.WW.OtOpcUa.Driver.S7.IntegrationTests
```
Tests auto-skip with a clear `SkipReason` when `localhost:1102` isn't
reachable within 2 seconds.
## What's encoded in `s7_1500.json`
| Address | Type | Seed | Purpose |
|---|---|---|---|
| `DB1.DBW0` | u16 | `4242` | read-back probe |
| `DB1.DBW10` | i16 | `-12345` | smoke i16 read |
| `DB1.DBD20` | i32 | `1234567890` | smoke i32 read |
| `DB1.DBD30` | f32 | `3.14159` | smoke f32 read (big-endian) |
| `DB1.DBX50.3` | bool | `true` | smoke bool read at bit 3 |
| `DB1.DBW100` | u16 | `0` | scratch for write-then-read |
| `DB1.STRING[200]` | S7 STRING | `"Hello"` (max 32, cur 5) | smoke string read |
| `MW0` | u16 | `1` | `S7ProbeOptions.ProbeAddress` default |
Seed types supported by `server.py`: `u8`, `i8`, `u16`, `i16`, `u32`,
`i32`, `f32`, `bool` (with `"bit": 0..7`), `ascii` (S7 STRING type with
configurable `max_len`).
## Known limitations (python-snap7 upstream)
The `snap7.server.Server` docstring admits:
> "Legacy S7 server implementation. Emulates a Siemens S7 PLC for testing
> and development purposes. [...] pure Python emulator implementation that
> simulates PLC behaviour for protocol compliance testing rather than
> full industrial-grade functionality."
What that means in practice — things this fixture does NOT cover:
- **S7-1500 Optimized-DB symbolic access** — the real S7-1500 with TIA Portal
optimization enabled uses symbolic addressing that's wire-incompatible with
absolute DB addressing. Our driver targets non-optimized DBs; so does
snap7's server. Rig test required to verify against an Optimized CPU.
- **PG / OP / S7-Basic session types** — S7netplus uses OP session; the
simulator accepts whatever session type is requested, unlike real CPUs
that allocate session slots differently.
- **SCL variant-specific behaviour** — e.g. S7-1200 missing certain PDU
types, S7-300's older handshake, S7-400 multi-CPU racks with non-zero
slot. Simulator collapses all into one generic CPU emulation.
- **PUT/GET-disabled-by-default** — real S7-1200/1500 CPUs refuse reads
when PUT/GET is off in TIA Portal hardware config; the driver maps that
to `BadDeviceFailure`. Simulator has no such toggle + always accepts.
## References
- [python-snap7 GitHub](https://github.com/gijzelaerr/python-snap7) — source + install
- [snap7.server API](https://python-snap7.readthedocs.io/en/latest/API/server.html) — `Server` class reference
- [`docs/drivers/S7-Test-Fixture.md`](../../../docs/drivers/S7-Test-Fixture.md) — coverage map + gap inventory
- [`docs/v2/s7.md`](../../../docs/v2/s7.md) — driver-side addressing + family notes

View File

@@ -1,35 +0,0 @@
{
"_description": "S7-1500 profile — single DB1 (1024 bytes) + MB (256 bytes) with well-known seeds at named offsets for the smoke + byte-order + string tests. Big-endian Siemens wire order throughout.",
"areas": [
{
"area": "DB",
"index": 1,
"size": 1024,
"seeds": [
{ "_desc": "DB1.DBW0 — read-back probe, S7Driver default ProbeAddress target is MW0; this shadows it",
"offset": 0, "type": "u16", "value": 4242 },
{ "_desc": "DB1.DBW10 — i16 smoke value for SmokeI16 read path",
"offset": 10, "type": "i16", "value": -12345 },
{ "_desc": "DB1.DBD20 — i32 smoke value for SmokeI32 read path",
"offset": 20, "type": "i32", "value": 1234567890 },
{ "_desc": "DB1.DBD30 — f32 smoke value for SmokeF32 read path (IEEE-754 big-endian)",
"offset": 30, "type": "f32", "value": 3.14159 },
{ "_desc": "DB1.DBX50.3 — bool bit at byte-50 bit-3 for SmokeBool read path",
"offset": 50, "type": "bool", "value": true, "bit": 3 },
{ "_desc": "DB1.DBW100 — scratch for write-then-read round-trip tests; seeded 0",
"offset": 100, "type": "u16", "value": 0 },
{ "_desc": "DB1.STRING[200] — S7 string 'Hello' (max 32, cur 5)",
"offset": 200, "type": "ascii", "value": "Hello", "max_len": 32 }
]
},
{
"area": "MK",
"index": 0,
"size": 256,
"seeds": [
{ "_desc": "MW0 — probe target for S7ProbeOptions.ProbeAddress default",
"offset": 0, "type": "u16", "value": 1 }
]
}
]
}

View File

@@ -1,56 +0,0 @@
<#
.SYNOPSIS
Launches the python-snap7 S7 server with one of the integration-test
profiles. Foreground process — Ctrl+C to stop. Mirrors the pymodbus
`serve.ps1` wrapper in tests\...\Modbus.IntegrationTests\Pymodbus\.
.PARAMETER Profile
Which profile JSON to load: currently only 's7_1500' ships. Additional
families (S7-1200, S7-300) can drop in as new JSON files alongside.
.PARAMETER Port
TCP port to bind. Default 1102 (non-privileged; matches
Snap7ServerFixture default endpoint). Pass 102 to match S7 standard —
requires root on Linux + triggers Windows Firewall prompt.
.EXAMPLE
.\serve.ps1 -Profile s7_1500
.EXAMPLE
.\serve.ps1 -Profile s7_1500 -Port 102
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)] [ValidateSet('s7_1500')] [string]$Profile,
[int]$Port = 1102
)
$ErrorActionPreference = 'Stop'
$here = $PSScriptRoot
# python-snap7 installs the `snap7` Python package; we call via `python -m`
# or via the server.py shim in this folder. Shim path is simpler to diagnose.
$python = Get-Command python -ErrorAction SilentlyContinue
if (-not $python) { $python = Get-Command py -ErrorAction SilentlyContinue }
if (-not $python) {
Write-Error "python not found on PATH. Install Python 3.10+ and 'pip install python-snap7'."
exit 1
}
# Verify python-snap7 is installed so failures surface here, not in a
# confusing ImportError from server.py.
& $python.Source -c "import snap7.server" 2>$null
if ($LASTEXITCODE -ne 0) {
Write-Error "python-snap7 not importable. Install with: pip install 'python-snap7>=2.0'"
exit 1
}
$jsonFile = Join-Path $here "$Profile.json"
if (-not (Test-Path $jsonFile)) {
Write-Error "Profile config not found: $jsonFile"
exit 1
}
Write-Host "Starting python-snap7 server: profile=$Profile TCP=localhost:$Port"
Write-Host "Ctrl+C to stop."
& $python.Source (Join-Path $here "server.py") $jsonFile --port $Port

View File

@@ -1,150 +0,0 @@
"""python-snap7 S7 server for integration tests.
Reads a JSON profile from argv[1], allocates bytearrays for each declared area
(DB / MB / EB / AB), poke-seeds values at declared offsets, then starts the
snap7 Server on the configured port + blocks until Ctrl+C. Shape intentionally
mirrors the pymodbus `serve.ps1 + *.json` pattern one directory over so
someone familiar with the Modbus fixture can read this without re-learning.
The snap7.server.Server class is the MIT-licensed S7 PLC emulator wrapped by
python-snap7 (https://github.com/gijzelaerr/python-snap7). Its own docstring
admits "protocol compliance testing rather than full industrial-grade
functionality" — good enough for ISO-on-TCP wire-level round-trip but NOT
for S7-1500 Optimized-DB symbolic access, SCL variant-specific behaviour, or
PG/OP/S7-Basic session differentiation.
"""
from __future__ import annotations
import argparse
import ctypes
import json
import signal
import sys
import time
from pathlib import Path
# python-snap7 installs as `snap7` package; Server class lives under `snap7.server`.
import snap7
from snap7.type import SrvArea
# Map JSON area names → SrvArea enum values. PE = inputs (I/E), PA = outputs
# (Q/A), MK = memory (M), DB = data blocks, TM = timers, CT = counters.
AREA_MAP: dict[str, int] = {
"PE": SrvArea.PE,
"PA": SrvArea.PA,
"MK": SrvArea.MK,
"DB": SrvArea.DB,
"TM": SrvArea.TM,
"CT": SrvArea.CT,
}
def seed_buffer(buf: bytearray, seeds: list[dict]) -> None:
"""Poke seed values into the area buffer at declared byte offsets.
Each seed is {"offset": int, "type": str, "value": int|float|bool|str}
where type ∈ {u8, i8, u16, i16, u32, i32, f32, bool, ascii}. Endianness is
big-endian (Siemens wire format).
"""
for seed in seeds:
off = int(seed["offset"])
t = seed["type"]
v = seed["value"]
if t == "u8":
buf[off] = int(v) & 0xFF
elif t == "i8":
buf[off] = int(v) & 0xFF
elif t == "u16":
buf[off:off + 2] = int(v).to_bytes(2, "big", signed=False)
elif t == "i16":
buf[off:off + 2] = int(v).to_bytes(2, "big", signed=True)
elif t == "u32":
buf[off:off + 4] = int(v).to_bytes(4, "big", signed=False)
elif t == "i32":
buf[off:off + 4] = int(v).to_bytes(4, "big", signed=True)
elif t == "f32":
import struct
buf[off:off + 4] = struct.pack(">f", float(v))
elif t == "bool":
bit = int(seed.get("bit", 0))
if bool(v):
buf[off] |= (1 << bit)
else:
buf[off] &= ~(1 << bit) & 0xFF
elif t == "ascii":
# Siemens STRING type: byte 0 = max length, byte 1 = current length,
# bytes 2+ = payload. Seeds supply the payload text; we fill max/cur.
payload = str(v).encode("ascii")
max_len = int(seed.get("max_len", 254))
buf[off] = max_len
buf[off + 1] = len(payload)
buf[off + 2:off + 2 + len(payload)] = payload
else:
raise ValueError(f"Unknown seed type '{t}'")
def main() -> int:
parser = argparse.ArgumentParser(description="python-snap7 S7 server for integration tests")
parser.add_argument("profile", help="Path to profile JSON")
parser.add_argument("--port", type=int, default=1102, help="TCP port (default 1102 non-privileged)")
args = parser.parse_args()
profile_path = Path(args.profile)
if not profile_path.is_file():
print(f"profile not found: {profile_path}", file=sys.stderr)
return 1
with profile_path.open() as f:
profile = json.load(f)
server = snap7.server.Server()
# Keep bytearray refs alive for the server's lifetime — snap7 doesn't copy
# the buffer, it takes a pointer. Letting GC collect would corrupt reads.
buffers: list[bytearray] = []
for area_decl in profile.get("areas", []):
area_name = area_decl["area"]
if area_name not in AREA_MAP:
print(f"unknown area '{area_name}' (expected one of {list(AREA_MAP)})", file=sys.stderr)
return 1
index = int(area_decl.get("index", 0)) # DB number for DB area, 0 for MK/PE/PA
size = int(area_decl["size"])
buf = bytearray(size)
seed_buffer(buf, area_decl.get("seeds", []))
buffers.append(buf)
# register_area takes (area, index, c-array); we wrap the bytearray
# into a ctypes char array so the native lib can take &buf[0].
arr_type = ctypes.c_char * size
arr = arr_type.from_buffer(buf)
server.register_area(AREA_MAP[area_name], index, arr)
print(f" seeded {area_name}{index} size={size} seeds={len(area_decl.get('seeds', []))}")
port = int(args.port)
print(f"Starting python-snap7 server on TCP {port} (Ctrl+C to stop)")
server.start(tcp_port=port)
stop = {"sig": False}
def _handle(*_a):
stop["sig"] = True
signal.signal(signal.SIGINT, _handle)
try:
signal.signal(signal.SIGTERM, _handle)
except Exception:
pass # SIGTERM not on all platforms
try:
while not stop["sig"]:
time.sleep(0.25)
finally:
print("stopping python-snap7 server")
try:
server.stop()
except Exception:
pass
return 0
if __name__ == "__main__":
sys.exit(main())

View File

@@ -24,7 +24,6 @@
</ItemGroup>
<ItemGroup>
<None Update="PythonSnap7\**\*" CopyToOutputDirectory="PreserveNewest"/>
<None Update="Docker\**\*" CopyToOutputDirectory="PreserveNewest"/>
</ItemGroup>