Files
periscope/tests/pcb/test_protocol_pdf_pack.py
T
michele d32af5627a Fill 1000BASE-T from IEEE 802.3-2012 Section Three Clause 40 (2.78.0).
Cable 100 Ω / 100 m / 570 ns / 50 ns skew stay CABLE. MDI 16 dB and 0.67 V are PHY. L2 PCB Zdiff UNKNOWN. 1000BASE-X 1000 Mb/s from Clause 36.
2026-09-22 18:03:44 +02:00

230 lines
9.8 KiB
Python

"""Recovered-PDF pack: USB Electrical CTS, Type-C FTS, DVI 1.0, IEEE 802.3-2012 §2."""
from __future__ import annotations
import json
from backend.periscopex.models import (
Component,
ComponentType,
DesignGraph,
Net,
NetType,
PinConnection,
)
from backend.periscopex.protocol_catalog import load_catalog
from backend.periscopex.protocol_recognize import recognize_physical_buses
def _cite_ok(c) -> None:
assert c.value_kind == "NUMERIC"
assert c.value is not None
src = c.source
assert src is not None
assert src.document
assert src.organization
assert src.revision
assert src.page
assert src.section or src.table
def test_usb_cts_hs_numeric_cited_no_zdiff_90():
cat = load_catalog()
hs = next(p for p in cat.physical_interfaces if p.id == "usb2-hs-dpair")
by = {c.parameter: c for c in hs.constraints}
_cite_ok(by["data_rate"])
assert by["data_rate"].value == 480.00
assert by["data_rate"].unit == "Mb/s"
assert by["data_rate"].source.document == "Universal Serial Bus Specification"
assert "2.0" in by["data_rate"].source.revision
assert by["data_rate"].source.section == "7.1.11"
assert by["rise_time"].value == 300.0
assert by["fall_time"].value == 300.0
assert by["pull_up"].value == 1500.0
assert by["dc_resistance"].value == 17.0
assert by["dc_resistance_captive_cable_device"].value == 23.0
assert by["dc_resistance_host_hub_downstream"].value == 13.0
for key in (
"data_rate", "rise_time", "fall_time", "pull_up", "dc_resistance",
"dc_resistance_captive_cable_device", "dc_resistance_host_hub_downstream",
"cable_differential_impedance", "pcb_trace_nominal_zdiff",
):
_cite_ok(by[key])
assert by["cable_differential_impedance"].value == 90.0
assert by["cable_differential_impedance"].source_type == "CABLE"
assert by["pcb_trace_nominal_zdiff"].value == 90.0
assert by["pcb_trace_nominal_zdiff"].mandatory == "RECOMMENDED"
assert by["pcb_trace_nominal_zdiff"].source_type == "PCB"
z = by["differential_impedance"]
assert z.value_kind == "UNKNOWN"
assert z.value is None
ls = next(p for p in cat.physical_interfaces if p.id == "usb2-ls-dpair")
ls_rate = next(c for c in ls.constraints if c.parameter == "data_rate")
_cite_ok(ls_rate)
assert ls_rate.value == 1.50
fs = next(p for p in cat.physical_interfaces if p.id == "usb2-fs-dpair")
fs_rate = next(c for c in fs.constraints if c.parameter == "data_rate")
_cite_ok(fs_rate)
assert fs_rate.value == 12.000
blob = json.dumps(z.model_dump())
assert "90" not in blob
def test_type_c_rp_rd_from_cabcon_r25_vbus_volts_unknown():
cat = load_catalog()
rec = next(p for p in cat.physical_interfaces if p.id == "usb-c-receptacle")
by = {c.parameter: c for c in rec.constraints}
_cite_ok(by["rp"])
assert by["rp"].value == 56000.0
assert by["rp"].source.table == "Table 4-27"
assert by["rp"].source.revision == "Release 2.5, March 2026"
assert by["rp"].source_type == "CONNECTOR"
_cite_ok(by["rd"])
assert by["rd"].value == 5100.0
assert by["rd"].source.table == "Table 4-28"
_cite_ok(by["ra"])
assert by["ra"].value == 800.0
assert by["ra"].source_type == "CABLE"
_cite_ok(by["voltage"])
assert by["voltage"].value == 4.75
assert by["voltage"].unit == "V"
assert by["voltage"].source.table == "Figure 4-39"
assert by["voltage"].source.page == "233"
assert "2.5" in by["voltage"].source.revision
assert by["voltage"].source_type == "CABLE"
assert any("not USB PD vSafe5V" in x for x in by["voltage"].conditions)
_cite_ok(by["vbus_requirements"])
assert by["vbus_requirements"].value == 4.0
assert by["vbus_requirements"].source.table == "Figure 4-39"
_cite_ok(by["electrical_thresholds"])
assert by["electrical_thresholds"].value == 1.50
assert by["electrical_thresholds"].source.table == "Table 4-32"
assert by["electrical_thresholds"].source.page == "240"
assert "August 2019" in by["electrical_thresholds"].source.revision
assert by["electrical_thresholds"].source_type == "PCB"
_cite_ok(by["vopen_source_default"])
assert by["vopen_source_default"].value == 1.65
_cite_ok(by["vra_source_default_max"])
assert by["vra_source_default_max"].value == 0.15
_cite_ok(by["vrd_detect_threshold_default"])
assert by["vrd_detect_threshold_default"].value == 1.60
_cite_ok(by["termination"])
assert by["termination"].value == 126000.0
assert by["termination"].source.table == "Table 4-30"
assert "2.5" in by["termination"].source.revision
assert by["termination"].source_type == "CONNECTOR"
_cite_ok(by["timing"])
assert by["timing"].value == 100.0
assert by["timing"].source.table == "Table 4-34"
assert "2.5" in by["timing"].source.revision
_cite_ok(by["t_vbuson_max"])
assert by["t_vbuson_max"].value == 275.0
assert by["t_vbuson_max"].source.table == "Table 4-32"
assert by["t_vbuson_max"].source.page == "247"
assert "2.5" in by["t_vbuson_max"].source.revision
assert by["vsafe5v"].value_kind == "UNKNOWN"
assert "vSafe5V" in (by["vsafe5v"].needed_document or "")
_cite_ok(by["gnd_ir_drop_cable"])
assert by["gnd_ir_drop_cable"].value == 250.0
assert by["gnd_ir_drop_cable"].source_type == "CABLE"
assert by["gnd_ir_drop_cable"].mandatory == "OPTIONAL"
_cite_ok(by["vbus_ir_drop_cable"])
assert by["vbus_ir_drop_cable"].value == 500.0
assert "Functional Test" in by["vbus_ir_drop_cable"].source.document
def test_dvi_not_hdmi_numeric_from_dvi_10():
cat = load_catalog()
logical = {p.id for p in cat.logical_protocols}
assert "dvi" in logical
assert "mini-hdmi" not in logical
dvi = next(p for p in cat.physical_interfaces if p.id == "dvi-1.0-tmds")
assert dvi.logical_protocol_id == "dvi"
assert dvi.connector == "DVI"
by = {c.parameter: c for c in dvi.constraints}
_cite_ok(by["termination"])
assert by["termination"].value == 50.0
assert by["termination"].source.table == "Table 4-2"
_cite_ok(by["differential_impedance"])
assert by["differential_impedance"].value == 100.0
assert by["differential_impedance"].source.table == "Table 4-7"
assert by["differential_impedance"].source.organization == "DDWG"
hdmi = next(p for p in cat.physical_interfaces if p.id == "hdmi-1.4-tmds-type-a")
hz = next(c for c in hdmi.constraints if c.parameter == "differential_impedance")
assert hz.value_kind == "UNKNOWN"
g = DesignGraph(
components={
"J3": Component(
reference="J3", value="DVI-D receptacle",
footprint="DVI_D",
component_type=ComponentType.CONNECTOR,
pins={"1": "TX0+"},
),
},
nets={"TX0+": Net(
name="TX0+", net_type=NetType.SIGNAL,
pins=[PinConnection(component_ref="J3", pin_number="1")],
)},
)
insts = recognize_physical_buses(g)
logs = {i.logical_protocol_id for i in insts}
assert "dvi" in logs
assert "hdmi-1.4" not in logs
assert "hdmi-2.0" not in logs
def test_ieee8023_section2_100base_tx_not_10base_or_1000():
cat = load_catalog()
tx = next(p for p in cat.physical_interfaces if p.id == "100base-tx-mdi")
by = {c.parameter: c for c in tx.constraints}
_cite_ok(by["data_rate"])
assert by["data_rate"].value == 100.0
assert by["data_rate"].source.document.startswith("IEEE Std 802.3-2012")
assert by["data_rate"].source.revision == "2012"
assert by["data_rate"].source.section == "21.1"
_cite_ok(by["cable_channel"])
assert by["cable_channel"].value == 100.0
assert by["cable_channel"].source_type == "CABLE"
assert by["cable_channel"].source.section == "25.4.9.2.2"
z = by["differential_impedance"]
assert z.value_kind == "UNKNOWN"
assert "TP-PMD" in (z.needed_document or "")
ten = next(p for p in cat.physical_interfaces if p.id == "10base-t-mdi")
tby = {c.parameter: c for c in ten.constraints}
_cite_ok(tby["data_rate"])
assert tby["data_rate"].value == 10.0
assert tby["data_rate"].source.revision == "2015"
assert tby["data_rate"].source.section == "14.1.1"
assert tby["data_rate"].source.page == "374"
_cite_ok(tby["cable_channel"])
assert tby["cable_channel"].value == 100.0
assert tby["cable_channel"].source_type == "CABLE"
assert tby["cable_channel"].source.section == "14.4.2.2"
assert tby["differential_impedance"].value_kind == "UNKNOWN"
assert "PCB" in (tby["differential_impedance"].needed_document or "")
gbe = next(p for p in cat.physical_interfaces if p.id == "1000base-t-mdi")
gby = {c.parameter: c for c in gbe.constraints}
_cite_ok(gby["data_rate"])
assert gby["data_rate"].value == 1000.0
assert gby["data_rate"].source.revision == "2012"
assert gby["data_rate"].source.section == "40.1"
assert gby["data_rate"].source.page == "179"
_cite_ok(gby["cable_channel"])
assert gby["cable_channel"].value == 100.0
assert gby["cable_channel"].source_type == "CABLE"
assert gby["cable_channel"].source.section == "40.7.2.2"
assert gby["differential_impedance"].value_kind == "UNKNOWN"
_cite_ok(gby["peak_differential_output"])
assert gby["peak_differential_output"].value == 0.67
assert gby["peak_differential_output"].source_type == "PHY"
x = next(p for p in cat.physical_interfaces if p.id == "1000base-x-pcb")
xr = next(c for c in x.constraints if c.parameter == "data_rate")
_cite_ok(xr)
assert xr.value == 1000.0
assert xr.source.section == "36.1.1"
fx = next(p for p in cat.physical_interfaces if p.id == "100base-fx-pcb")
fxr = next(c for c in fx.constraints if c.parameter == "data_rate")
_cite_ok(fxr)
assert fxr.value == 100.0
assert fxr.source.section == "26.1"