#!/usr/bin/env python3 """Bitwise comparison of the draft traces (LELEKA_TRACE_DRAFT=1 'DRAFT ...' lines: position, accepted row, cell, ids, IEEE bits of the probabilities) of two replay logs. python3 -I draftround-idcmp.py LOG_A LOG_B [LOG_A2] Lines are compared in order; the logs of one job run the same arms in the same order, so line i of A is the same draft round as line i of B. With LOG_A2 (a second process of the same configuration as A) the run-to-run control is printed too. Exit 0 when A and B are identical (same number of lines, every line equal). """ import sys def draft_lines(p): return [ln.rstrip("\n") for ln in open(p, errors="replace") if ln.startswith("DRAFT ")] def cmp(a, b, label): n = min(len(a), len(b)) diff = [i for i in range(n) if a[i] != b[i]] print("%s: lines A %d, B %d, compared %d, identical %d, different %d" % (label, len(a), len(b), n, n - len(diff), len(diff))) for i in diff[:5]: print(" line %d\n A %s\n B %s" % (i, a[i], b[i])) return len(a) == len(b) and not diff and n > 0 def main(): if len(sys.argv) < 3: print(__doc__) sys.exit(2) a, b = draft_lines(sys.argv[1]), draft_lines(sys.argv[2]) ok = cmp(a, b, "B against A") if len(sys.argv) > 3: cmp(a, draft_lines(sys.argv[3]), "control (A2 against A)") half = len(a) // 2 if len(a) % 2 == 0 and half: # arms I1 and I2 of one process are the same configuration: the A/A inside the process cmp(a[:half], a[half:], "arm I2 against arm I1 inside A") print("DRAFT VERDICT:", "IDENTICAL" if ok else "DIFFERENT") sys.exit(0 if ok else 1) if __name__ == "__main__": main()