aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/scripts/digest_compare.py
blob: b4144fe3cf1ec9d55277cecff52846e961b3cb83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
"""Compare the `digest <frame> <time> <hex>` lines of two run logs (deterministic runs).

Usage: digest_compare.py A.log B.log   → exit 0 when equal, 1 with the first difference.
"""
import sys
from pathlib import Path


def digests(path: str) -> list[str]:
    return [line.strip() for line in Path(path).read_text(errors="replace").splitlines() if line.startswith("digest ")]


def main(argv: list[str]) -> int:
    if len(argv) != 3:
        print(__doc__.strip())
        return 2
    a, b = digests(argv[1]), digests(argv[2])
    if not a and not b:
        print("FAIL: no digest lines")
        return 1
    for k, (x, y) in enumerate(zip(a, b), 1):
        if x != y:
            print(f"FAIL: digest {k} differs\n  {x}\n  {y}")
            return 1
    if len(a) != len(b):
        print(f"FAIL: {len(a)} vs {len(b)} digests")
        return 1
    print(f"ok: {len(a)} digests equal, last {a[-1]}")
    return 0


if __name__ == "__main__":
    sys.exit(main(sys.argv))