diff --git a/CHANGELOG.md b/CHANGELOG.md index 725e32a..cec3011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.1.1 – 2026-11-16 + +- `itk demo`: the USB step now reports throughput a real test stick could reach (42/138 MB/s + write/read on USB 3, 17.5/34 MB/s on USB 2). It used to time the local disk behind the + simulated sticks and showed up to 4000 MB/s on a 5 Gbit/s port. Real runs were not affected. + ## 0.1.0 – 2026-10-28 First version. diff --git a/pyproject.toml b/pyproject.toml index 1b94078..9df5c2b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "interface-test-kit" -version = "0.1.0" +version = "0.1.1" description = "Operator-guided interface test for Linux embedded and panel PCs: serial with handshake, USB, Ethernet and CAN, with per-variant profiles and reports" readme = "README.md" license = "MIT" diff --git a/src/interface_test_kit/__init__.py b/src/interface_test_kit/__init__.py index 0ad3d50..14a59ad 100644 --- a/src/interface_test_kit/__init__.py +++ b/src/interface_test_kit/__init__.py @@ -1,3 +1,3 @@ """interface-test-kit: operator-guided interface test for Linux embedded PCs.""" -__version__ = "0.1.0" +__version__ = "0.1.1" diff --git a/src/interface_test_kit/sim/world.py b/src/interface_test_kit/sim/world.py index 4b94a5c..fe48e0d 100644 --- a/src/interface_test_kit/sim/world.py +++ b/src/interface_test_kit/sim/world.py @@ -3,7 +3,6 @@ from __future__ import annotations import itertools -import time from pathlib import Path from ..checks.serial import LOOPBACK_TYPES @@ -63,15 +62,37 @@ def open_serial(port: str, baud: int) -> SimLoopback: return SimLoopback(LOOPBACK_TYPES["9pin"]) network = SimCanNetwork(drop={"can0"} if fault == "can_no_ack" else None) - if fault == "usb_slow": - ticks = itertools.count() - clock = lambda: float(next(ticks)) # every reading one second later # noqa: E731 - else: - clock = time.monotonic + # The USB check times a write and a read-back per stick. In the demo the "sticks" are + # folders on the local disk, so a real clock would report the disk (thousands of MB/s). + # Instead the clock steps through the times a real stick would need, in check order. + rates = [STICK_MBS["slow" if fault == "usb_slow" else 5000]] + if len(sticks) > 1: + rates.append(STICK_MBS["slow" if fault == "usb_slow" else speed]) + clock = _stick_clock(rates) runner = FakeRunner({"lsblk -J": lsblk_result(sticks), "ping -c": _ping}) return Context(root=root, run=runner, open_serial=open_serial, open_can=network.open, clock=clock) +# Typical (write, read) MB/s of a test stick on a USB 3 port, on a USB 2 port, and a worn one. +STICK_MBS: dict[int | str, tuple[float, float]] = {5000: (42.0, 138.0), 480: (17.5, 34.0), "slow": (4.2, 9.5)} +DEMO_SIZE_MB = 8 # size_mb of the USB step in profiles/demo.yaml + + +def _stick_clock(rates: list[tuple[float, float]]): + """A clock for the demo: per stick write-start, write-end, read-start, read-end.""" + steps = [] + for write, read in rates: + steps += [0.05, DEMO_SIZE_MB / write, 0.05, DEMO_SIZE_MB / read] + increments = itertools.chain(steps, itertools.repeat(0.05)) + now = 0.0 + + def clock() -> float: + nonlocal now + now += next(increments) + return now + return clock + + class AutoUI(ConsoleUI): """Console output like a real session, with the operator's answers typed in automatically.""" diff --git a/tests/test_cli.py b/tests/test_cli.py index 219e8f2..d608ddf 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -6,4 +6,4 @@ def test_version(capsys): with pytest.raises(SystemExit) as e: main(["--version"]) - assert e.value.code == 0 and "0.1.0" in capsys.readouterr().out + assert e.value.code == 0 and "0.1.1" in capsys.readouterr().out diff --git a/tests/test_demo.py b/tests/test_demo.py index c089706..775a338 100644 --- a/tests/test_demo.py +++ b/tests/test_demo.py @@ -75,3 +75,33 @@ def isatty(self): ui.step_started(Step("led", "Power LED", "confirm", None, None, 1)) ui.ask_yes_no("Is the power LED green?") assert "Power LED\nIs the power LED green? [Y/N] Y\n" in out.getvalue() + + +def usb_measurements(out: Path) -> dict: + usb = next(s for s in result(out)["steps"] if s["id"] == "usb") + return {m["name"]: m["value"] for m in usb["attempts"][-1]["measurements"]} + + +@pytest.mark.parametrize("fault", [None, "usb_wrong_speed", "usb_slow"]) +def test_demo_usb_throughput_is_physically_possible(tmp_path, fault): + # A USB stick cannot move more than its link rate allows (about 80 % of the + # raw bit rate after protocol overhead); the demo used to time the local disk. + args = ["demo", "--out", str(tmp_path)] + (["--fault", fault] if fault else []) + main(args) + values = usb_measurements(tmp_path) + for port in ("1-1", "2-1"): + bus_mbs = values[f"{port} USB speed"] / 8 * 0.8 + assert 0 < values[f"{port} write"] <= values[f"{port} read"] <= bus_mbs, values + + +def test_demo_usb_values_are_reproducible(tmp_path): + main(["demo", "--out", str(tmp_path / "a")]) + main(["demo", "--out", str(tmp_path / "b")]) + assert usb_measurements(tmp_path / "a") == usb_measurements(tmp_path / "b") + + +def test_demo_clock_matches_the_demo_profile(): + from interface_test_kit.sim.world import DEMO_SIZE_MB + demo = Path(__file__).parent.parent / "src/interface_test_kit/profiles/demo.yaml" + usb = next(s for s in load_profile(demo).steps if s.type == "usb") + assert usb.config.size_mb == DEMO_SIZE_MB