86 lines
5.2 KiB
Python
86 lines
5.2 KiB
Python
"""Acceptance through public verification interfaces; fixture/native evidence are labelled."""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
import shutil
|
|
import sys
|
|
import time
|
|
from threading import Event
|
|
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'src'))
|
|
from dx_productivity.trial_task_center.store import TaskStore
|
|
from dx_productivity.trial_task_center.verification.service import VerificationService
|
|
from dx_productivity.trial_task_center import native_netlist,netlist_verification
|
|
from dx_productivity.trial_task_center.batch_resources import write_record
|
|
from verification_closed_loop import freeze_inputs,verify_closed_loop
|
|
|
|
|
|
def main(argv=None):
|
|
parser=argparse.ArgumentParser(description=__doc__)
|
|
group=parser.add_mutually_exclusive_group(required=True)
|
|
group.add_argument('--fixture-root',type=Path)
|
|
group.add_argument('--native-before',type=Path)
|
|
parser.add_argument('--native-after',type=Path);parser.add_argument('--output',type=Path,required=True)
|
|
parser.add_argument('--expect-verdict',choices=('CONSISTENT','WARNING','DIFFERENT'),default='CONSISTENT',
|
|
help='Expected conclusion fixed before running; defaults to CONSISTENT')
|
|
args=parser.parse_args(argv)
|
|
if args.native_before and not args.native_after:parser.error('--native-after is required')
|
|
root=args.output.resolve()
|
|
if root.exists():parser.error('output must be a new directory')
|
|
root.mkdir(parents=True)
|
|
store=TaskStore(root/'tasks.db');service=VerificationService(store,root/'data')
|
|
original=netlist_verification._export_saved_capture
|
|
try:
|
|
if args.fixture_root:
|
|
fixture=args.fixture_root.resolve();before=next((fixture/'before').rglob('*.prj'));after=next((fixture/'after').rglob('*.prj'))
|
|
def controlled(capture,output,*,stop_event):
|
|
phase='before' if capture['project']==str(before.resolve()) else 'after'
|
|
source=fixture/phase;output.mkdir(parents=True,exist_ok=True)
|
|
for name in ('effective.txt','design.kyn'):shutil.copyfile(source/name,output/name)
|
|
graph=native_netlist.read_graph(output/'effective.txt',output/'design.kyn')
|
|
return {'status':'success','complete':True,'graph':graph,'capture':capture,
|
|
'outputs':{'effective':str(output/'effective.txt'),'keyin':str(output/'design.kyn')},
|
|
'runs':[],'evidence_kind':'controlled-format-fixture'}
|
|
netlist_verification._export_saved_capture=controlled
|
|
evidence_kind='controlled-format-fixture'
|
|
else:before,after=args.native_before.resolve(),args.native_after.resolve();evidence_kind='native-read-only'
|
|
# Capture verifies source stability. Record live bytes to prove no mutation as well.
|
|
from dx_productivity.trial_task_center.native_inventory import _project_options
|
|
paths=[before,after,Path(_project_options(before)[3]),Path(_project_options(after)[3])]
|
|
initial={str(p):native_netlist._hash(p) for p in paths}
|
|
task=service.create_task('独立校验验收',request_id='acceptance-create')['task_id']
|
|
accepted=service.import_pair(task,before,after,request_id='acceptance-import',stop_event=Event())
|
|
if not accepted['accepted']:raise ValueError('No input accepted')
|
|
frozen=freeze_inputs(service,task,expected_count=1)
|
|
expectations={row['item_id']:args.expect_verdict for row in frozen['items']}
|
|
write_record(root/'frozen-scope.json',dict(frozen,expected_verdicts=expectations,evidence_kind=evidence_kind))
|
|
run=service.start(task,request_id='acceptance-run')
|
|
deadline=time.monotonic()+900
|
|
while service.busy:
|
|
if time.monotonic()>deadline:raise TimeoutError('Native acceptance timed out')
|
|
time.sleep(.05)
|
|
current=service.read_task(task);report=service.export_task(task,root/'reports',request_id='acceptance-report')
|
|
unchanged=all(native_netlist._hash(Path(p))==sha for p,sha in initial.items())
|
|
closed_loop=verify_closed_loop(service,task,frozen,run,report,expected_verdicts=expectations)
|
|
write_record(root/'closed-loop.json',closed_loop)
|
|
summary={'evidence_kind':evidence_kind,'task_id':task,'run':run,'summary':current['summary'],
|
|
'input_sha256':initial,'inputs_unchanged':unchanged,'report':str(report),
|
|
'policy':'verification-v1','closed_loop':closed_loop,
|
|
'replacement_operations':store._connection.execute('SELECT COUNT(*) FROM execution_operations').fetchone()[0]}
|
|
write_record(root/'acceptance.json',summary);print(json.dumps(summary,ensure_ascii=False))
|
|
if not unchanged:return 4
|
|
if not closed_loop['passed']:return 3
|
|
return 0
|
|
except Exception as error:
|
|
write_record(root/'failure.json',{'error':type(error).__name__,'reason':str(error)})
|
|
print(str(error),file=sys.stderr);return 1
|
|
finally:
|
|
service.begin_shutdown()
|
|
deadline=time.monotonic()+10
|
|
while service.busy and time.monotonic()<deadline:time.sleep(.05)
|
|
netlist_verification._export_saved_capture=original
|
|
if not service.busy:store.close()
|
|
|
|
|
|
if __name__=='__main__':raise SystemExit(main())
|