106 lines
5.5 KiB
Python
106 lines
5.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Freeze a build/test anchor for the corrected PDFium candidate, before staging."""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import xml.etree.ElementTree as ET
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
RESULTS = ROOT / 'tests/results/pdfium-intent-context'
|
|
PARENT = ROOT / 'tests/results/pdfium-intent-build/record.json'
|
|
PARENT_SHA = '47b4dc2efbf8e671f904610b3047400dbd3ceb0fa10d6bd53fb04f3727943e7e'
|
|
LIBRARY_SHA = 'cb049fe434f4c911b5eb047c0aca572d4dd9f5e405dde329b76c05a6aa771403'
|
|
|
|
|
|
def sha(path):
|
|
with path.open('rb') as stream:
|
|
return hashlib.file_digest(stream, 'sha256').hexdigest()
|
|
|
|
|
|
def rel(path):
|
|
return str(path.relative_to(ROOT))
|
|
|
|
|
|
def check_nested(path):
|
|
data = json.loads(path.read_text())
|
|
for name, digest in data.get('evidenceSha256', {}).items():
|
|
assert sha(path.parent / name) == digest, name
|
|
return data
|
|
|
|
|
|
def main():
|
|
destination = RESULTS / 'record.json'
|
|
assert not destination.exists(), 'The build anchor is immutable; create another version for changed inputs.'
|
|
assert sha(PARENT) == PARENT_SHA
|
|
parent = json.loads(PARENT.read_text())
|
|
source = ROOT / 'build-pdfium-intent-context/source'
|
|
library = source / 'out/patched/libpdfium.so'
|
|
assert sha(library) == LIBRARY_SHA
|
|
patch = json.loads((RESULTS / 'candidate-patch.json').read_text())
|
|
assert patch['success'] and patch['appliesWithoutFuzz'] and patch['appliedSourcesByteIdentical']
|
|
assert patch['parentRecordSha256'] == PARENT_SHA
|
|
assert sha(ROOT / patch['patch']) == sha(ROOT / patch['patchSnapshot']) == patch['patchSha256']
|
|
for row in patch['files']:
|
|
assert sha(source / row['path']) == row['afterSha256'], row['path']
|
|
build = json.loads((RESULTS / 'build-2.json').read_text())
|
|
assert build['exitCode'] == 0
|
|
upstream = json.loads((RESULTS / 'upstream-tests-execution.json').read_text())
|
|
assert upstream['success'] and upstream['librarySha256'] == LIBRARY_SHA
|
|
tests = 0
|
|
for row in upstream['commands']:
|
|
assert row['exitCode'] == 0
|
|
data = row['results']
|
|
assert data['failures'] == data['errors'] == data['disabled'] == 0
|
|
assert sha(Path(row['command'][0])) == row['executableSha256']
|
|
tests += data['tests']
|
|
assert tests == 1979
|
|
arch = check_nested(RESULTS / 'arch/report.json')
|
|
assert arch['candidateTestsPass'] and arch['allBinaryInputsUnchanged']
|
|
assert arch['inputs'][str(library)] == LIBRARY_SHA
|
|
assert arch['intents']['probeCount'] == 600 and arch['transparency']['probeCount'] == 324
|
|
for name in ('cmyk', 'intents', 'transparency'):
|
|
check_nested(RESULTS / 'arch' / name / 'report.json')
|
|
junit = ET.parse(RESULTS / 'arch/tests.xml').getroot()
|
|
cases = list(junit.iter('testcase'))
|
|
assert len(cases) == 22 and not list(junit.iter('failure')) and not list(junit.iter('error'))
|
|
evidence = {rel(path): sha(path) for path in sorted(RESULTS.rglob('*'))
|
|
if path.is_file() and path != destination}
|
|
for name in ('source-materialization', 'tool-materialization', 'provider-patches'):
|
|
path = ROOT / ('tests/results/pdfium-intent-build/' + name + '.json')
|
|
assert sha(path) == parent['evidenceSha256'][rel(path)]
|
|
evidence[rel(path)] = sha(path)
|
|
evidence[rel(PARENT)] = PARENT_SHA
|
|
sources = {name: value for name, value in parent['sourceSha256'].items()
|
|
if name.startswith('resources/licenses/pdfium-supplemental/')}
|
|
for name, value in sources.items():
|
|
assert sha(ROOT / name) == value
|
|
tools = [Path(__file__), ROOT / 'tests/cmyk_lut/export_pdfium_context_patch.py',
|
|
ROOT / 'tests/cmyk_lut/intents.py', ROOT / 'tests/cmyk_lut/transparency.py',
|
|
ROOT / 'tests/cmyk_lut/correct_intent_oracle.py', ROOT / 'tests/cmyk_lut/validate_context_candidate.py',
|
|
ROOT / 'tests/fixtures/pdf/generate_intent_transparency.py']
|
|
sources.update({rel(path): sha(path) for path in tools})
|
|
for folder in ('rendering-intents-context', 'intent-transparency'):
|
|
sources.update({rel(path): sha(path) for path in (ROOT / 'tests/fixtures/pdf' / folder).iterdir() if path.is_file()})
|
|
record = {'schemaVersion': 6, 'goalComplete': False,
|
|
'parent': {'path': rel(PARENT), 'sha256': PARENT_SHA},
|
|
'scope': 'Immutable Linux candidate build and Arch test anchor before staging. Ubuntu, package adoption and release acceptance are recorded separately.',
|
|
'pdfiumRenderingIntentCandidate': {
|
|
'sourceRevision': patch['baseRevision'], 'source': rel(source),
|
|
'library': str(library), 'librarySha256': LIBRARY_SHA,
|
|
'patch': patch['patch'], 'patchSha256': patch['patchSha256'],
|
|
'patchSnapshot': patch['patchSnapshot'], 'report': rel(RESULTS / 'arch/report.json'),
|
|
'reportSha256': sha(RESULTS / 'arch/report.json'),
|
|
'productionDependencyReplaced': False, 'comparisonAccepted': False,
|
|
'candidateProbesPass': True, 'candidateProbeCount': 972,
|
|
'upstreamTestCount': tests, 'docviewCTestGroups': 22,
|
|
'oracleRevision': 2,
|
|
'supersedes': 'The old shading-pattern-inherit expectation was incorrect. The historical v1 pass remains a numerical result against that old expectation, not pattern conformance evidence.'},
|
|
'evidenceSha256': evidence, 'sourceSha256': sources}
|
|
destination.write_text(json.dumps(record, indent=2) + '\n')
|
|
print(json.dumps({'recordSha256': sha(destination), 'evidenceFiles': len(evidence),
|
|
'sourceFiles': len(sources), 'candidateProbeCount': 972}))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|