"""Normalization: what of a run's log the expected file locks. Only timing (t_*) and diagnostics (d_*: signals, messages, pointers) are dropped; nothing guest-visible is masked (docs/testing.md, section 5.3). Two things are rewritten: - the suspend blob (blob_pgsd) is parsed into the device-state and device-info pairs it carries (section 6.24), so that a change of state reads as one; - the process's end becomes one "outcome" record: completed, died (the host process; "after" is the op of the last observation before it, since a death on another thread races with the op that caused it; the signal is a diagnostic), watchdog (a hang, at op i: the op that never returned), timeout (the orchestrator killed it) or error (a scenario bug). """ import json import struct def strip(o): if isinstance(o, dict): return {k: strip(v) for k, v in o.items() if not (k.startswith("t_") or k.startswith("d_"))} if isinstance(o, list): return [strip(v) for v in o] return o # The blob's format (docs/testing.md, section 6.24; pgtest/suspend_guest.py # builds it): the magic 'RVGS', version 1, then the registers section (tag 1) # and the device-info section (tag 2). BLOB_MAGIC = 0x53475652 BLOB_VERSION = 1 # The device-state key each register is reported under, in the registers # section's order. REGISTER_KEYS = tuple(range(1, 20)) + (21,) def parse_sections(b): """The magic, the version and the sections {tag: payload} of a blob, in order; ValueError where it is not a well-formed blob of ours.""" if len(b) < 8: raise ValueError("short") magic, version = struct.unpack_from(" len(b): raise ValueError("section header") tag, length = struct.unpack_from(" len(b): raise ValueError("section") sections[tag] = b[off + 8:off + 8 + length] off += 8 + length return magic, version, sections def blob_of(record): """The blob a parsed record describes, sections in the order the device writes them.""" regs = dict((k, int(v, 16)) for k, v in record["state"]) registers = struct.pack("<%dI" % len(REGISTER_KEYS), *(regs[k] for k in REGISTER_KEYS)) info = struct.pack("