bootstrap_cross_host_smoke.py (2886B)
1 #!/usr/bin/env python3 2 """Observe the post-generation program on Zig against independent complete trees. 3 Requires the Haskell post-acceptance smoke and cross-host reproduction evidence. 4 Compilation of this program was Haskell-executed; compiler bundles are bit-identical. 5 """ 6 import argparse 7 import hashlib 8 import json 9 from pathlib import Path 10 import sys 11 from bootstrap_smoke import smoke_cases 12 from bootstrap_acceptance import sha 13 from process_rss import run_guarded 14 15 ROOT=Path(__file__).resolve().parent.parent 16 17 18 def main(): 19 p=argparse.ArgumentParser(description=__doc__) 20 p.add_argument('experiment',type=Path) 21 p.add_argument('--library',type=Path,required=True) 22 p.add_argument('--directory',type=Path,required=True) 23 a=p.parse_args(); a.directory.mkdir(parents=True,exist_ok=False) 24 accepted=json.loads((a.experiment/'accepted-cross-host.json').read_text()) 25 hs=a.experiment/'haskell-smoke' 26 previous=json.loads((hs/'report.json').read_text()) 27 assert accepted['accepted'] and previous['complete'] 28 assert sha(a.library)==accepted['zig_inputs']['runtime_sha256'] 29 assert previous['compiler_sha256']==accepted['artifacts']['build-stable.arboricx'] 30 assert sha(hs/'program.arboricx')==previous['bundle_sha256'] 31 report=dict(complete=False,compiler_sha256=previous['compiler_sha256'], 32 bundle_sha256=previous['bundle_sha256'],runtime_sha256=sha(a.library), 33 acceptance_sha256=sha(a.experiment/'accepted-cross-host.json'), 34 compilation_host='haskell',execution_host='zig', 35 observer_sha256=sha(ROOT/'test/zig_observe.py'),cases=[]) 36 try: 37 for i,(export,argument,expected) in enumerate(smoke_cases()): 38 input_path=a.directory/(str(i)+'.input.tree'); input_path.write_bytes(argument) 39 output=a.directory/(str(i)+'.output.tree') 40 reply,peak=run_guarded([sys.executable,str(ROOT/'test/zig_observe.py'), 41 '--library',str(a.library),'--bundle',str(hs/'program.arboricx'), 42 '--export',export,'--argument',str(input_path),'--output',str(output)], 43 memory_mib=512,seconds=65) 44 (a.directory/(str(i)+'.log')).write_text(reply) 45 assert output.read_bytes()==expected, (export,i) 46 assert sha(output)==previous['cases'][i]['output_sha256'] 47 report['cases'].append(dict(export=export,input_sha256=sha(input_path),output_sha256=sha(output),peak_kib=peak)) 48 report.update(complete=True,wrong_output_rejected=(output.read_bytes()!=b'\0')) 49 assert report['wrong_output_rejected'] 50 print('PASS: 12 complete results on Zig, including recursive lists and invoice totals/text') 51 finally: (a.directory/'report.json').write_text(json.dumps(report,indent=2)+'\n') 52 53 54 if __name__=='__main__': main()