Repository navigation
Expand file tree
/
Copy pathretest.py
More file actions
114 lines (94 loc) · 4.18 KB
/
Copy pathretest.py
File metadata and controls
114 lines (94 loc) · 4.18 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os
import subprocess
import json
import time
import sys
from collections import Counter
CONVERT_BIN = "target/release/examples/convert_pdfa"
VALIDATE_BIN = "target/release/xfa-cli"
TIMEOUT = 120
def run_test(pdf_path):
output_pdf = "/tmp/retest_out.pdf"
if os.path.exists(output_pdf):
os.remove(output_pdf)
start_time = time.time()
try:
# Conversion
res = subprocess.run([CONVERT_BIN, pdf_path, output_pdf],
capture_output=True, timeout=TIMEOUT)
if res.returncode != 0:
err = res.stderr.decode('utf-8', errors='ignore').strip()
return "FAIL", err.split('\n')[-1] if err else "Conversion error"
# Validation
res = subprocess.run([VALIDATE_BIN, "validate", "--json", output_pdf],
capture_output=True, timeout=TIMEOUT)
if res.returncode == 0:
return "PASS", None
try:
report = json.loads(res.stdout)
errors = [i['rule'] + ": " + i['message'] for i in report.get('issues', []) if i.get('severity') == 'Error']
if not errors:
errors = [i['rule'] + ": " + i['message'] for i in report.get('issues', [])]
return "FAIL", errors[0] if errors else "Validation failed"
except Exception as e:
return "FAIL", f"Failed to parse validation JSON"
except subprocess.TimeoutExpired:
return "TIMEOUT", None
except Exception as e:
return "FAIL", str(e)
finally:
if os.path.exists(output_pdf):
try: os.remove(output_pdf)
except: pass
def main():
if not os.path.exists("retest_list.txt"):
print("retest_list.txt not found!")
return
with open("retest_list.txt", "r") as f:
paths = [line.strip() for line in f if line.strip()]
results = []
print(f"Testing {len(paths)} PDFs...")
for i, local_path in enumerate(paths):
status, detail = run_test(local_path)
results.append((status, detail))
print(f"[{i+1}/{len(paths)}] {status} {detail if detail else ''}")
sys.stdout.flush()
if not results:
print("No results collected!")
return
# Report
total = len(results)
pass_count = sum(1 for r in results if r[0] == "PASS")
fail_count = sum(1 for r in results if r[0] == "FAIL")
timeout_count = sum(1 for r in results if r[0] == "TIMEOUT")
print("\n" + "="*40)
print("RETEST RESULTS")
print("="*40)
print(f"Total tested: {total}")
print(f"Pass: {pass_count} ({pass_count/total*100:.1f}%)")
print(f"Fail: {fail_count} ({fail_count/total*100:.1f}%)")
print(f"Timeout: {timeout_count} ({timeout_count/total*100:.1f}%)")
print("\nTOP REMAINING PATTERNS:")
fail_details = [r[1] for r in results if r[0] == "FAIL"]
def normalize_error(e):
if not e: return "Unknown error"
if "6.1.13" in e: return "6.1.13: Content stream contains real value exceeding 32767"
if "6.2.11.8" in e: return "6.2.11.8: Content stream contains reference to .notdef glyph"
if "6.9" in e: return "6.9: File specification has no /EF key"
if "6.1.4" in e: return "6.1.4: Cross-reference streams (/Type /XRef) shall not be used"
if "6.1.7.1" in e: return "6.1.7.1: Stream dictionary contains /F file specification"
if "6.1.6" in e: return "6.1.6: Hexadecimal string contains non-hex characters"
if "6.2.11.7" in e: return "6.2.11.7: ToUnicode CMap missing or forbidden mappings"
return e[:100]
norm_fails = [normalize_error(e) for e in fail_details]
counts = Counter(norm_fails).most_common(10)
for err, count in counts:
print(f"{count:3d} x {err}")
# Estimate based on 11,160 total failures
total_failures_before = 11160
failure_rate_among_failing = fail_count / total
estimated_remaining = total_failures_before * failure_rate_among_failing
print(f"\nESTIMATED TOTAL REMAINING FAILURES (on 342K): {int(estimated_remaining)}")
print(f"(Based on {failure_rate_among_failing*100:.1f}% recurrence rate among previously failing files)")
if __name__ == "__main__":
main()