Advance native LaTeX execution and preview
This commit is contained in:
1 parent
91f9d76b16
commit
2741546ca8
414 files changed
+99872
-933
No files matched your search
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Actual paragraph diagnostics/channels and unchanged multi-page native PDF."""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import importlib.util
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
spec = importlib.util.spec_from_file_location("paragraph_trace_oracle", ROOT / "scripts/check-native-statistics.py")
|
||||
ORACLE = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(ORACLE)
|
||||
|
||||
|
||||
def blocks(text):
|
||||
return [text[m.start():].split("\n\n", 1)[0] for m in re.finditer(r"(?m)^@firstpass\n", text)]
|
||||
|
||||
|
||||
def case(binary, out, level, online):
|
||||
name = f"paragraphs{level}-online{online}"
|
||||
d = out / name
|
||||
native, reference = d / "native", d / "reference"
|
||||
native.mkdir(parents=True, exist_ok=True)
|
||||
reference.mkdir(parents=True, exist_ok=True)
|
||||
original = ROOT / "examples/native-bootstrap/native-job.tex"
|
||||
original_sha = ORACLE.sha(original.read_bytes())
|
||||
source = d / "source.tex"
|
||||
source.write_text(r"\catcode123=1\catcode125=2\pdfoutput=1\pdfpkresolution=600"
|
||||
+ f"\\tracingparagraphs={level}\\tracingonline={online}\\input {original}\n")
|
||||
source_sha = ORACLE.sha(source.read_bytes())
|
||||
env = os.environ.copy()
|
||||
env["TFMFONTS"] = str(ROOT / "crates/texrra-tex-core/assets")
|
||||
env["T1FONTS"] = str(ROOT / "assets/fonts")
|
||||
env["TEXINPUTS"] = str(ROOT / "examples/native-bootstrap") + ":"
|
||||
env["TEXFONTMAPS"] = str(Path(subprocess.check_output(["kpsewhich", "pdftex.map"], text=True).strip()).parent)
|
||||
ns, nt = ORACLE.run([binary, "native", "--job", "--initex", "--etex", "--resource-manifest",
|
||||
native / "resources.json", source, native / "job.pdf"], native, env)
|
||||
rt, re_ = ORACLE.run(["pdftex", "-ini", "-etex", "-interaction=nonstopmode", "-halt-on-error", source], reference, env)
|
||||
(native / "stdout.log").write_bytes(ns)
|
||||
(native / "terminal.log").write_bytes(nt)
|
||||
(reference / "terminal.log").write_bytes(rt + re_)
|
||||
nl, rl = (native / "job.log").read_text(), (reference / "source.log").read_text()
|
||||
traces = [blocks(s) for s in [nl, rl, nt.decode(), rt.decode()]]
|
||||
assert traces[0] == traces[1], f"{name}: actual log paragraph decisions/short lists differ"
|
||||
assert traces[2] == traces[3], f"{name}: actual terminal paragraph diagnostics differ"
|
||||
if level > 0:
|
||||
assert traces[0]
|
||||
assert (traces[2] == traces[0]) if online else not traces[2]
|
||||
else:
|
||||
assert not any(traces)
|
||||
pdf, ref_pdf = native / "job.pdf", reference / "source.pdf"
|
||||
words = [ORACLE.WORDS.words(p) for p in [pdf, ref_pdf]]
|
||||
assert len(words[0]) == len(words[1]) == 4
|
||||
labels = [[w[0] for page in pages for w in page] for pages in words]
|
||||
assert labels[0] == labels[1]
|
||||
flat = [[w for page in pages for w in page] for pages in words]
|
||||
errors = {k: max(abs(a[1][k] - b[1][k]) for a, b in zip(*flat)) for k in ["xMin", "xMax", "yMin", "yMax"]}
|
||||
ink = [ORACLE.INK.ink_report(ORACLE.INK.raster(pdf, native / f"page-{i}", i),
|
||||
ORACLE.INK.raster(ref_pdf, reference / f"page-{i}", i)) for i in range(1, 5)]
|
||||
aux_equal = (native / "pages.aux").read_bytes() == (reference / "pages.aux").read_bytes()
|
||||
unchanged = ORACLE.sha(source.read_bytes()) == source_sha and ORACLE.sha(original.read_bytes()) == original_sha
|
||||
passed = max(errors.values()) <= .02 and all(i["passed"] for i in ink) and aux_equal and unchanged
|
||||
result = dict(id=name, passed=passed, pages=4, level=level, tracingonline=online,
|
||||
paragraph_reports=len(traces[0]), decision_lines=sum(len(re.findall(r"(?m)^@", s)) for s in traces[0]),
|
||||
exact_paragraph_diagnostics=True, max_word_box_errors_bp=errors, ink=ink,
|
||||
aux_equal=aux_equal, source_unchanged=unchanged, source_sha256=source_sha,
|
||||
native_pdf_sha256=ORACLE.sha(pdf.read_bytes()))
|
||||
(d / "audit.json").write_text(json.dumps(result, indent=2) + "\n")
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--binary", type=Path, required=True)
|
||||
parser.add_argument("--output-dir", type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
out = args.output_dir.resolve()
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
results = []
|
||||
for level in [-1, 0, 1, 2]:
|
||||
for online in [0, 1]:
|
||||
r = case(args.binary.resolve(), out, level, online)
|
||||
results.append(r)
|
||||
print(r["id"], "passed" if r["passed"] else "FAILED", flush=True)
|
||||
assert len({r["native_pdf_sha256"] for r in results}) == 1, "paragraph tracing changed PDF bytes"
|
||||
report = dict(passed=all(r["passed"] for r in results), cases=len(results), pages=sum(r["pages"] for r in results),
|
||||
byte_identical_across_trace_controls=True, binary_sha256=ORACLE.sha(args.binary.resolve().read_bytes()),
|
||||
reference_version=subprocess.check_output(["pdftex", "--version"], text=True).splitlines()[0], results=results)
|
||||
(out / "audit.json").write_text(json.dumps(report, indent=2) + "\n")
|
||||
if not report["passed"]:
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user