#!/usr/bin/env python3 """Small parser smoke tests. Does not connect to any device.""" from linux_ptp_exporter import parse_pmc from nexus_ptp_exporter import parse_clock, parse_parent, parse_brief PMC_SAMPLE = """ sending: GET TIME_STATUS_NP 141877.fffe.3b4c2c-0 seq 0 RESPONSE MANAGEMENT TIME_STATUS_NP master_offset -13 ingress_time 1788117645030216721 cumulativeScaledRateOffset +0.000000000 scaledLastGmPhaseChange 0 gmTimeBaseIndicator 0 lastGmPhaseChange 0x0000'0000000000000000.0000 gmPresent true gmIdentity 88a29e.fffe.826ce6 """ NEXUS_CLOCK = """ PTP Device Type : boundary-clock PTP Source IP Address : 10.255.254.255 Clock Identity : 28:6f:7f:ff:fe:21:0f:8d Clock Domain: 0 Number of PTP ports: 2 Priority1 : 255 Priority2 : 255 Clock Quality: Class : 248 Accuracy : 254 Offset (log variance) : 65535 Offset From Master : 40 Mean Path Delay : 226 Steps removed : 2 PTP Clock state : Locked """ NEXUS_PARENT = """ Parent Clock: Parent Clock Identity: 14:18:77:ff:fe:3b:4c:2c Parent Port Number: 4 Parent IP: 10.255.255.8 Grandmaster Clock: Grandmaster Clock Identity: 88:a2:9e:ff:fe:82:6c:e6 Grandmaster Clock Quality: Class: 6 Accuracy: 254 Offset (log variance): 65535 Priority1: 128 Priority2: 128 """ NEXUS_BRIEF = """ Port State --------------------- ------------ Eth1/5 Slave Eth1/6 Passive """ blocks = parse_pmc(PMC_SAMPLE) assert blocks[0]["master_offset"] == -13.0 assert blocks[0]["gmPresent"] == 1.0 assert blocks[0]["gmIdentity"] == "88a29e.fffe.826ce6" clock = parse_clock(NEXUS_CLOCK) assert clock["Offset From Master"] == "40" assert clock["Clock Quality Class"] == "248" assert clock["PTP Clock state"] == "Locked" parent = parse_parent(NEXUS_PARENT) assert parent["Parent IP"] == "10.255.255.8" assert parent["Grandmaster Clock Identity"] == "88:a2:9e:ff:fe:82:6c:e6" assert parent["GM Priority1"] == "128" brief = parse_brief(NEXUS_BRIEF) assert brief == [("Eth1/5", "slave"), ("Eth1/6", "passive")] print("parser smoke tests: OK")