diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml new file mode 100644 index 0000000..0a22ec0 --- /dev/null +++ b/.github/workflows/integration.yml @@ -0,0 +1,45 @@ +name: integration +# SIM-08: this commit's modsim and modpoll against each other, with the conformance model of +# modpoll-wot, over Modbus TCP and RTU on a virtual serial port. + +on: + push: + branches: [v2] + paths: + - packages/** + - integration/** + - pyproject.toml + - uv.lock + - .github/workflows/integration.yml + pull_request: + paths: + - packages/** + - integration/** + - pyproject.toml + - uv.lock + - .github/workflows/integration.yml + +permissions: + contents: read + +jobs: + conformance: + name: integration conformance + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6 + with: + version: 0.11.19 + python-version: '3.12' + enable-cache: true + cache-dependency-glob: uv.lock + - name: Install every workspace member + run: uv sync --locked --all-packages --all-extras --all-groups + - name: Read modsim with modpoll + run: uv run --locked --no-sync pytest -q integration --junitxml=integration-results.xml + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 + if: always() + with: + name: integration + path: integration-results.xml diff --git a/.github/workflows/modsim-acceptance.yml b/.github/workflows/modsim-acceptance.yml index 53bf30e..9ae1a27 100644 --- a/.github/workflows/modsim-acceptance.yml +++ b/.github/workflows/modsim-acceptance.yml @@ -5,6 +5,7 @@ on: branches: [v2] paths: - packages/modsim/** + - packages/modpoll/** - packages/modpoll-wot/** - pyproject.toml - uv.lock @@ -13,6 +14,7 @@ on: pull_request: paths: - packages/modsim/** + - packages/modpoll/** - packages/modpoll-wot/** - pyproject.toml - uv.lock @@ -70,20 +72,18 @@ jobs: - uses: ./.github/actions/setup-uv with: package: modsim - # Unchanged by TOOL-01: the independent clients stay pinned to the modpoll commit and release they used. - - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - with: - repository: top-maker/modpoll - ref: 93daa74bc859fe8a5704f3e94e4f6eb0df797ec2 - path: packages/modsim/.interop/modpoll + # SIM-08: the independent clients are this commit's modpoll, installed from its wheels apart + # from modsim, and modpoll's pinned node-wot reader. - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: '24' - - run: npm ci --prefix .interop/modpoll/tools/wot-interop --ignore-scripts --no-audit --no-fund - - name: Install independent public modpoll + - run: npm ci --prefix ../modpoll/tools/wot-interop --ignore-scripts --no-audit --no-fund + - name: Install this commit's modpoll in its own environment run: | + uv build --wheel --no-sources --package modpoll --out-dir "$RUNNER_TEMP/modpoll-dist" + uv build --wheel --no-sources --package modpoll-wot --out-dir "$RUNNER_TEMP/modpoll-dist" uv venv "$RUNNER_TEMP/modpoll" - uv pip install --python "$RUNNER_TEMP/modpoll/bin/python" 'modpoll==2.0.0a2' + uv pip install --python "$RUNNER_TEMP/modpoll/bin/python" "$RUNNER_TEMP"/modpoll-dist/*.whl - name: Test fixed public model with independent clients run: | uv build --wheel --no-sources --out-dir dist @@ -93,7 +93,7 @@ jobs: mkdir -p "$RUNNER_TEMP/catalog-acceptance/tools" "$RUNNER_TEMP/catalog-acceptance/examples" cp tools/catalog-interop.py tools/fetch-models.py "$RUNNER_TEMP/catalog-acceptance/tools/" cp examples/model-source.yaml "$RUNNER_TEMP/catalog-acceptance/examples/" - reader="$PWD/.interop/modpoll/tools/wot-interop/read-write.cjs" + reader="$PWD/../modpoll/tools/wot-interop/read-write.cjs" cd "$RUNNER_TEMP/catalog-acceptance" "$RUNNER_TEMP/modsim/bin/python" tools/fetch-models.py --output "$RUNNER_TEMP/catalog-acceptance/inputs" "$RUNNER_TEMP/modsim/bin/python" tools/catalog-interop.py --modpoll-python "$RUNNER_TEMP/modpoll/bin/python" --node-reader "$reader" --output "$RUNNER_TEMP/catalog-interop.json" diff --git a/.github/workflows/modsim.yml b/.github/workflows/modsim.yml index c34f42e..d3929db 100644 --- a/.github/workflows/modsim.yml +++ b/.github/workflows/modsim.yml @@ -5,6 +5,7 @@ on: branches: [v2] paths: - packages/modsim/** + - packages/modpoll/** - packages/modpoll-wot/** - pyproject.toml - uv.lock @@ -15,6 +16,7 @@ on: types: [opened, synchronize, reopened, ready_for_review] paths: - packages/modsim/** + - packages/modpoll/** - packages/modpoll-wot/** - pyproject.toml - uv.lock @@ -88,10 +90,13 @@ jobs: with: package: modsim - - name: Install an independent released modpoll + # SIM-08: the client is this commit's modpoll, installed from its wheels apart from modsim. + - name: Install this commit's modpoll in its own environment run: | + uv build --wheel --no-sources --package modpoll --out-dir "$RUNNER_TEMP/modpoll-dist" + uv build --wheel --no-sources --package modpoll-wot --out-dir "$RUNNER_TEMP/modpoll-dist" uv venv "$RUNNER_TEMP/modpoll" - uv pip install --python "$RUNNER_TEMP/modpoll/bin/python" 'modpoll==2.0.0a5' + uv pip install --python "$RUNNER_TEMP/modpoll/bin/python" "$RUNNER_TEMP"/modpoll-dist/*.whl - name: Export with modpoll and replay with modsim env: diff --git a/README.md b/README.md index cae208d..af15322 100644 --- a/README.md +++ b/README.md @@ -19,5 +19,7 @@ uv sync --all-packages --all-extras --all-groups cd packages/modpoll && uv run pytest ``` -Each package keeps its own `Makefile`, tests and release notes. A release is a tag named after the package, +Each package keeps its own `Makefile`, tests and release notes. `integration/` runs this commit's modsim and +modpoll against each other with modpoll-wot's conformance model, over Modbus TCP and RTU on a virtual serial +port (`uv run pytest integration` after the sync above). A release is a tag named after the package, for example `modsim-v2.0.0a13`, which runs that package's release workflow. diff --git a/integration/conftest.py b/integration/conftest.py new file mode 100644 index 0000000..3107dc1 --- /dev/null +++ b/integration/conftest.py @@ -0,0 +1,121 @@ +"""Run the workspace's own modsim and modpoll against each other (SIM-08).""" + +from contextlib import contextmanager +import json +import os +from pathlib import Path +import re +import socket +import subprocess +import sys +import time + +import pytest + +ROOT = Path(__file__).resolve().parents[1] +FIXTURES = ROOT / "packages/modpoll-wot/tests/fixtures" +MODEL = FIXTURES / "conformance.tm.json" +DATA = FIXTURES / "conformance.data.json" + + +def free_port(): + with socket.socket() as reservation: + reservation.bind(("127.0.0.1", 0)) + return reservation.getsockname()[1] + + +@contextmanager +def simulator(tmp_path, transport, model=MODEL, data=DATA): + """Start modsim on a free TCP port or a virtual serial port; yield the client's address.""" + log_path = tmp_path / f"modsim-{transport}.log" + command = [ + sys.executable, + "-m", + "modsim", + "--config", + str(model), + "--data", + str(data), + ] + port = free_port() if transport == "tcp" else None + command += ["--port", str(port)] if port else ["--serial", "pty"] + with log_path.open("w+") as log: + process = subprocess.Popen(command, stdout=log, stderr=log, cwd=tmp_path) + try: + deadline = time.monotonic() + 30 + while True: + if process.poll() is not None: + log.seek(0) + pytest.fail(log.read()) + if port: + try: + socket.create_connection(("127.0.0.1", port), timeout=1).close() + address = port + break + except OSError: + pass + else: + log.seek(0) + found = re.search( + r"Virtual serial port for the client: (\S+)", log.read() + ) + if found: + address = found.group(1) + break + if time.monotonic() > deadline: + pytest.fail(f"modsim did not start over {transport}") + time.sleep(0.1) + yield address + finally: + process.terminate() + try: + process.wait(timeout=10) + except subprocess.TimeoutExpired: + process.kill() + process.wait() + + +def endpoint_arguments(transport, address): + if transport == "tcp": + return ["--tcp", "127.0.0.1", "--tcp-port", str(address)] + return ["--rtu", address, "--rtu-baud", "9600"] + + +def run_modpoll(tmp_path, arguments): + result = subprocess.run( + [sys.executable, "-m", "modpoll", "--once", *arguments], + capture_output=True, + text=True, + timeout=60, + cwd=tmp_path, + stdin=subprocess.DEVNULL, + ) + return result + + +def read_values(tmp_path, transport, address, model=MODEL): + output = tmp_path / f"values-{transport}.json" + result = run_modpoll( + tmp_path, + [ + *endpoint_arguments(transport, address), + "--config", + str(model), + "--export", + str(output), + ], + ) + assert result.returncode == 0, result.stdout + result.stderr + (values,) = json.loads(output.read_text()).values() + return values + + +TRANSPORTS = [ + "tcp", + pytest.param( + "rtu", + marks=pytest.mark.skipif( + os.name == "nt", reason="virtual serial ports need POSIX" + ), + ), +] diff --git a/integration/test_conformance.py b/integration/test_conformance.py new file mode 100644 index 0000000..296dadb --- /dev/null +++ b/integration/test_conformance.py @@ -0,0 +1,154 @@ +"""modpoll reads what modsim serves from the conformance model, over TCP and RTU (SIM-08).""" + +import copy +import json +import struct + +import modpoll_wot +from pymodbus.client import ModbusTcpClient +import pytest + +from conftest import ( + DATA, + FIXTURES, + MODEL, + ROOT, + TRANSPORTS, + endpoint_arguments, + run_modpoll, + simulator, +) + +EXPECTED = json.loads(DATA.read_text())["initial"] + + +def words(raw): + return [int.from_bytes(raw[i : i + 2], "big") for i in range(0, len(raw), 2)] + + +def swap_words(registers): + return registers[::-1] + + +def swap_bytes(registers): + return [((word & 0xFF) << 8) | (word >> 8) for word in registers] + + +# The holding registers modsim must put on the wire, worked out here from the Modbus byte and word +# order rules rather than by either tool's codec. +U32 = words(struct.pack(">I", EXPECTED["u32_be"])) +WIRE = { + 0: U32, + 2: swap_words(U32), + 4: swap_bytes(U32), + 6: swap_bytes(swap_words(U32)), + 8: swap_words(words(struct.pack(">f", EXPECTED["f32_word_swap"]))), + 10: words(struct.pack(">h", round(EXPECTED["i16_scaled"] / 0.1))), + 11: words(EXPECTED["label"].encode() + b"\0"), + 14: [1 << 3], + 15: words(struct.pack(">e", EXPECTED["half"])), +} + + +@pytest.mark.parametrize("transport", TRANSPORTS) +def test_every_point_reads_back_its_simulation_value(tmp_path, transport): + with simulator(tmp_path, transport) as address: + output = tmp_path / "values.json" + result = run_modpoll( + tmp_path, + [ + *endpoint_arguments(transport, address), + "--config", + str(MODEL), + "--export", + str(output), + ], + ) + assert result.returncode == 0, result.stdout + result.stderr + (values,) = json.loads(output.read_text()).values() + assert values == EXPECTED + + +def test_modsim_puts_the_independently_encoded_registers_on_the_wire(tmp_path): + with simulator(tmp_path, "tcp") as port: + client = ModbusTcpClient("127.0.0.1", port=port, timeout=5) + assert client.connect() + try: + reply = client.read_holding_registers(0, count=16, device_id=1) + finally: + client.close() + assert not reply.isError() + for address, expected in WIRE.items(): + assert reply.registers[address : address + len(expected)] == expected, address + + +@pytest.mark.parametrize("transport", TRANSPORTS) +def test_a_full_read_report_matches_its_model(tmp_path, transport): + report_path = tmp_path / "report.json" + with simulator(tmp_path, transport) as address: + result = run_modpoll( + tmp_path, + [ + *endpoint_arguments(transport, address), + "--config", + str(MODEL), + "--report", + str(report_path), + ], + ) + assert report_path.is_file(), result.stdout + result.stderr + report = json.loads(report_path.read_text()) + modpoll_wot.validate_report(report, model=MODEL.read_bytes()) + assert report["transport"] == transport + assert {point["read"] for point in report["points"]} == {"ok"} + assert len(report["points"]) == len(EXPECTED) + + +def test_an_address_the_device_does_not_serve_is_reported_as_exception_02(tmp_path): + model = json.loads(MODEL.read_text()) + extended = copy.deepcopy(model) + form = {**model["properties"]["u32_be"]["forms"][0], "modv:address": 100} + extended["properties"]["unserved"] = { + "type": "integer", + "readOnly": True, + "forms": [form], + } + extended["modpoll:acquisition"].append( + { + "modv:entity": "HoldingRegister", + "modv:address": 100, + "modv:quantity": 2, + "modpoll:members": ["unserved"], + } + ) + client_model = tmp_path / "extended.tm.json" + client_model.write_text(json.dumps(extended)) + report_path = tmp_path / "report.json" + with simulator(tmp_path, "tcp") as port: + result = run_modpoll( + tmp_path, + [ + *endpoint_arguments("tcp", port), + "--config", + str(client_model), + "--report", + str(report_path), + ], + ) + assert report_path.is_file(), result.stdout + result.stderr + points = { + point["property"]: point + for point in json.loads(report_path.read_text())["points"] + } + assert (points["unserved"]["read"], points["unserved"].get("exceptionCode")) == ( + "exception", + 2, + ) + assert {point["read"] for name, point in points.items() if name != "unserved"} == { + "ok" + } + + +def test_the_shared_fixture_has_no_drifting_copy(): + shared = (FIXTURES / "modsim.tm.json").read_bytes() + assert (ROOT / "packages/modpoll/examples/modsim.tm.json").read_bytes() == shared diff --git a/packages/modpoll-wot/profile.md b/packages/modpoll-wot/profile.md index 90d4183..162a9c8 100644 --- a/packages/modpoll-wot/profile.md +++ b/packages/modpoll-wot/profile.md @@ -211,6 +211,9 @@ do not contribute. pins the canonical strings, point fingerprints and model fingerprint of the 37-property fixture for other implementations. Changing either canonical form requires a new prefix. +[tests/fixtures/conformance.fingerprints.json](tests/fixtures/conformance.fingerprints.json) does the same for +`conformance.tm.json`, which covers every byte and word order and each Form extension; with +`conformance.data.json` it is also what the workspace integration tests serve with modsim and read with modpoll. ## Verification reports diff --git a/packages/modpoll-wot/tests/fixtures/conformance.data.json b/packages/modpoll-wot/tests/fixtures/conformance.data.json new file mode 100644 index 0000000..f4e41de --- /dev/null +++ b/packages/modpoll-wot/tests/fixtures/conformance.data.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "initial": { + "u32_be": 16909060, + "u32_word_swap": 16909060, + "u32_byte_swap": 16909060, + "u32_both_swap": 16909060, + "f32_word_swap": 230.2, + "i16_scaled": -12.3, + "label": "ABCDE", + "flag_bit3": true, + "half": 1.5, + "packed_coils": 4660 + } +} diff --git a/packages/modpoll-wot/tests/fixtures/conformance.fingerprints.json b/packages/modpoll-wot/tests/fixtures/conformance.fingerprints.json new file mode 100644 index 0000000..9794e63 --- /dev/null +++ b/packages/modpoll-wot/tests/fixtures/conformance.fingerprints.json @@ -0,0 +1,47 @@ +{ + "model": "conformance.tm.json", + "version": "pf1+mf1", + "fingerprint": "mf1:9734b3d68662e9381eb34a9fd7f682ed98c76b121ba60d0fd6a646420669a004", + "points": { + "u32_be": { + "canonical": "{\"modv:address\":0,\"modv:entity\":\"HoldingRegister\",\"modv:mostSignificantByte\":true,\"modv:mostSignificantWord\":true,\"modv:quantity\":2,\"modv:type\":\"xsd:unsignedInt\",\"type\":\"integer\"}", + "fingerprint": "pf1:e76d712016a2e139ef9e1d040b6e9c987fc5db1cb004719f71f804988a3d9c7e" + }, + "u32_word_swap": { + "canonical": "{\"modv:address\":2,\"modv:entity\":\"HoldingRegister\",\"modv:mostSignificantByte\":true,\"modv:mostSignificantWord\":false,\"modv:quantity\":2,\"modv:type\":\"xsd:unsignedInt\",\"type\":\"integer\"}", + "fingerprint": "pf1:26a40fad3299451018146debae91203d0f20313b066eab6caca1470cad82980e" + }, + "u32_byte_swap": { + "canonical": "{\"modv:address\":4,\"modv:entity\":\"HoldingRegister\",\"modv:mostSignificantByte\":false,\"modv:mostSignificantWord\":true,\"modv:quantity\":2,\"modv:type\":\"xsd:unsignedInt\",\"type\":\"integer\"}", + "fingerprint": "pf1:f88ae861eb7833f7aafa53e90520b742d6fd29ba9bc43db7a7542cde6783146c" + }, + "u32_both_swap": { + "canonical": "{\"modv:address\":6,\"modv:entity\":\"HoldingRegister\",\"modv:mostSignificantByte\":false,\"modv:mostSignificantWord\":false,\"modv:quantity\":2,\"modv:type\":\"xsd:unsignedInt\",\"type\":\"integer\"}", + "fingerprint": "pf1:08dc02f6136c44928c62f93a96e2a645d75a4a0b35ab79522e9ae33871ce743e" + }, + "f32_word_swap": { + "canonical": "{\"modv:address\":8,\"modv:entity\":\"HoldingRegister\",\"modv:mostSignificantByte\":true,\"modv:mostSignificantWord\":false,\"modv:quantity\":2,\"modv:type\":\"xsd:float\",\"type\":\"number\"}", + "fingerprint": "pf1:2593aca018b58711c600a44951271bde9b8a969b749acafb94a2280c260456e7" + }, + "i16_scaled": { + "canonical": "{\"modpoll:multiplier\":\"0.1\",\"modv:address\":10,\"modv:entity\":\"HoldingRegister\",\"modv:mostSignificantByte\":true,\"modv:mostSignificantWord\":true,\"modv:quantity\":1,\"modv:type\":\"xsd:short\",\"type\":\"number\"}", + "fingerprint": "pf1:21b24d28bad0be40835294ba7f777a2ac9f3c6ccf9b3d49f93f5bbe4063805c4" + }, + "label": { + "canonical": "{\"modpoll:byteLength\":5,\"modv:address\":11,\"modv:entity\":\"HoldingRegister\",\"modv:mostSignificantByte\":true,\"modv:mostSignificantWord\":true,\"modv:quantity\":3,\"modv:type\":\"xsd:string\",\"type\":\"string\"}", + "fingerprint": "pf1:24d7e4210406c8add96bf96c24565da1adf226aeed48e7f0174b296f80d3a60f" + }, + "flag_bit3": { + "canonical": "{\"modpoll:bit\":3,\"modv:address\":14,\"modv:entity\":\"HoldingRegister\",\"modv:mostSignificantByte\":true,\"modv:mostSignificantWord\":true,\"modv:quantity\":1,\"modv:type\":\"xsd:unsignedShort\",\"type\":\"boolean\"}", + "fingerprint": "pf1:e534b297aa25a8f52c97cc78d244997d7083b7f09e8730bf04d4349f5e0e8fd0" + }, + "half": { + "canonical": "{\"modpoll:codec\":\"float16\",\"modv:address\":15,\"modv:entity\":\"HoldingRegister\",\"modv:mostSignificantByte\":true,\"modv:mostSignificantWord\":true,\"modv:quantity\":1,\"modv:type\":\"xsd:hexBinary\",\"type\":\"number\"}", + "fingerprint": "pf1:5f13e6b33c19000d7ecc48fcfd6a892f0727973abd5bfba18421accd692887c0" + }, + "packed_coils": { + "canonical": "{\"modpoll:bitPacking\":\"legacy-msb\",\"modv:address\":0,\"modv:entity\":\"Coil\",\"modv:mostSignificantByte\":true,\"modv:mostSignificantWord\":true,\"modv:quantity\":16,\"modv:type\":\"xsd:unsignedShort\",\"type\":\"integer\"}", + "fingerprint": "pf1:a7dcaf6a928482445357a82449d60c55f75814cfbb4bf191a673deb6db1a6569" + } + } +} diff --git a/packages/modpoll-wot/tests/fixtures/conformance.tm.json b/packages/modpoll-wot/tests/fixtures/conformance.tm.json new file mode 100644 index 0000000..88c9582 --- /dev/null +++ b/packages/modpoll-wot/tests/fixtures/conformance.tm.json @@ -0,0 +1,212 @@ +{ + "@context": [ + "https://www.w3.org/2022/wot/td/v1.1", + { + "modpoll": "https://top-maker.github.io/modpoll/vocab/wot-modbus#", + "modv": "https://www.w3.org/2019/wot/modbus", + "xsd": "http://www.w3.org/2001/XMLSchema#" + } + ], + "@type": "tm:ThingModel", + "title": "conformance", + "description": "SIM-08 conformance fixture: every byte and word order and each profile extension, read by modpoll from modsim over TCP and RTU.", + "modpoll:version": "0.2", + "properties": { + "u32_be": { + "type": "integer", + "readOnly": true, + "forms": [ + { + "op": [ + "readproperty" + ], + "contentType": "application/octet-stream", + "modv:entity": "HoldingRegister", + "modv:address": 0, + "modv:quantity": 2, + "modv:type": "xsd:unsignedInt" + } + ] + }, + "u32_word_swap": { + "type": "integer", + "readOnly": true, + "forms": [ + { + "op": [ + "readproperty" + ], + "contentType": "application/octet-stream", + "modv:entity": "HoldingRegister", + "modv:address": 2, + "modv:quantity": 2, + "modv:type": "xsd:unsignedInt", + "modv:mostSignificantWord": false + } + ] + }, + "u32_byte_swap": { + "type": "integer", + "readOnly": true, + "forms": [ + { + "op": [ + "readproperty" + ], + "contentType": "application/octet-stream", + "modv:entity": "HoldingRegister", + "modv:address": 4, + "modv:quantity": 2, + "modv:type": "xsd:unsignedInt", + "modv:mostSignificantByte": false + } + ] + }, + "u32_both_swap": { + "type": "integer", + "readOnly": true, + "forms": [ + { + "op": [ + "readproperty" + ], + "contentType": "application/octet-stream", + "modv:entity": "HoldingRegister", + "modv:address": 6, + "modv:quantity": 2, + "modv:type": "xsd:unsignedInt", + "modv:mostSignificantByte": false, + "modv:mostSignificantWord": false + } + ] + }, + "f32_word_swap": { + "type": "number", + "readOnly": true, + "forms": [ + { + "op": [ + "readproperty" + ], + "contentType": "application/octet-stream", + "modv:entity": "HoldingRegister", + "modv:address": 8, + "modv:quantity": 2, + "modv:type": "xsd:float", + "modv:mostSignificantWord": false + } + ] + }, + "i16_scaled": { + "type": "number", + "readOnly": true, + "forms": [ + { + "op": [ + "readproperty" + ], + "contentType": "application/octet-stream", + "modv:entity": "HoldingRegister", + "modv:address": 10, + "modv:quantity": 1, + "modv:type": "xsd:short", + "modpoll:multiplier": "0.1" + } + ] + }, + "label": { + "type": "string", + "readOnly": true, + "forms": [ + { + "op": [ + "readproperty" + ], + "contentType": "application/octet-stream", + "modv:entity": "HoldingRegister", + "modv:address": 11, + "modv:quantity": 3, + "modv:type": "xsd:string", + "modpoll:byteLength": 5 + } + ] + }, + "flag_bit3": { + "type": "boolean", + "readOnly": true, + "forms": [ + { + "op": [ + "readproperty" + ], + "contentType": "application/octet-stream", + "modv:entity": "HoldingRegister", + "modv:address": 14, + "modv:quantity": 1, + "modv:type": "xsd:unsignedShort", + "modpoll:bit": 3 + } + ] + }, + "half": { + "type": "number", + "readOnly": true, + "forms": [ + { + "op": [ + "readproperty" + ], + "contentType": "application/octet-stream", + "modv:entity": "HoldingRegister", + "modv:address": 15, + "modv:quantity": 1, + "modv:type": "xsd:hexBinary", + "modpoll:codec": "float16" + } + ] + }, + "packed_coils": { + "type": "integer", + "readOnly": true, + "forms": [ + { + "op": [ + "readproperty" + ], + "contentType": "application/octet-stream", + "modv:entity": "Coil", + "modv:address": 0, + "modv:quantity": 16, + "modv:type": "xsd:unsignedShort", + "modpoll:bitPacking": "legacy-msb" + } + ] + } + }, + "modpoll:acquisition": [ + { + "modv:entity": "HoldingRegister", + "modv:address": 0, + "modv:quantity": 16, + "modpoll:members": [ + "u32_be", + "u32_word_swap", + "u32_byte_swap", + "u32_both_swap", + "f32_word_swap", + "i16_scaled", + "label", + "flag_bit3", + "half" + ] + }, + { + "modv:entity": "Coil", + "modv:address": 0, + "modv:quantity": 16, + "modpoll:members": [ + "packed_coils" + ] + } + ] +} diff --git a/packages/modpoll-wot/tests/test_verification.py b/packages/modpoll-wot/tests/test_verification.py index 85680c6..5437a20 100644 --- a/packages/modpoll-wot/tests/test_verification.py +++ b/packages/modpoll-wot/tests/test_verification.py @@ -27,8 +27,13 @@ def numeric(): return json.loads(NUMERIC.read_bytes()) -def test_shared_vectors_pin_the_canonical_encoding(): - vectors = json.loads((FIXTURES / "modsim.fingerprints.json").read_bytes()) +# modsim.tm.json is the 37-point fixture modpoll compares with 1.x; conformance.tm.json (SIM-08) +# adds every byte and word order and each profile extension. +@pytest.mark.parametrize( + "vector_file", ["modsim.fingerprints.json", "conformance.fingerprints.json"] +) +def test_shared_vectors_pin_the_canonical_encoding(vector_file): + vectors = json.loads((FIXTURES / vector_file).read_bytes()) _, effective = instantiate(json.loads((FIXTURES / vectors["model"]).read_bytes())) for name, expected in vectors["points"].items(): point = canonical_point(effective["properties"][name]) diff --git a/packages/modsim/tests/test_snapshot_replay.py b/packages/modsim/tests/test_snapshot_replay.py index c0938c0..8f20ca7 100644 --- a/packages/modsim/tests/test_snapshot_replay.py +++ b/packages/modsim/tests/test_snapshot_replay.py @@ -145,7 +145,10 @@ def test_exported_snapshot_replays_unchanged(tmp_path): first = serve_and_read(tmp_path, model, data, "first") exported = json.loads(first.read_text())["replay-meter"] - assert exported["VOLTAGE"] == float(2301) * 0.1 != 230.1 + # modpoll exports the exact decimal of a scaled reading. Releases up to 2.0.0a5 exported + # float(raw) * multiplier (230.10000000000002); modpoll-wot's scaled_raw property tests + # show that form maps back to the same raw value too. + assert exported["VOLTAGE"] == 230.1 assert exported["STATUS"] == 4660 replayed = serve_and_read(tmp_path, model, first, "replay")