diff options
Diffstat (limited to 'scripts/digest_compare.py')
| -rwxr-xr-x | scripts/digest_compare.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/digest_compare.py b/scripts/digest_compare.py new file mode 100755 index 0000000..b4144fe --- /dev/null +++ b/scripts/digest_compare.py @@ -0,0 +1,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)) |
