Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/universal/translation/go_selftest.py # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / universal / translation / go_selftest.py` 622 lines ยท 43649 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Go lane (#741) author self-test: TESTED evidence only (translation-v1 section 10), never QUALIFIED. 3 4 For every F2-go fixture: Go import, independent decode, #621 v2 codec `sa identity|decode|replay` 5 (build/L832, or NOT_RUN), cross-importer identity against the C import of the F1 source, export of the 6 unit and of R(U, M) for all six family members (identical bytes, gofmt-clean), re-import identity 7 (translation-compose-v1 section 4.1), and Go 1.27.3 DIFFERENTIAL (original and exported Go) against a 8 bigint evaluation of the records. The untyped-constant rule of go-u64-v1.md section 1.1 is checked 9 against `go build` on the refusal fixtures and on seeded random constant/variable trees. Compositions 10 C->Go and Go->C (R(U, M) in test code, or tools/adapters/retarget via --retarget, cross-checked byte for 11 byte; the G1 C exporter accepts v1 C units only), with the native realization lower(N(U_A)) when the lowering, omc `734f0a39` and the 12 bridge are present (otherwise NOT_RUN). 13 """ 14 from pathlib import Path 15 import argparse,hashlib,json,os,random,shutil,struct,subprocess,sys,tempfile 16 ROOT=Path(__file__).resolve().parents[3] 17 MASK=(1<<64)-1 18 SEMDOM=b'omega.source.semantic.v1' 19 CONTRACT=hashlib.sha256((ROOT/'spec/universal/semantics.md').read_bytes()).digest() 20 # translation-compose-v2 section 1: OMSA version, language, profile, arithmetic obligations (dialect = language) 21 MEMBERS={'C':(1,1,1,1),'Rust':(1,2,2,1),'Python':(1,3,4,5),'C++':(2,5,7,1),'Zig':(2,6,8,1),'Go':(2,7,9,1)} 22 BOUNDARY=[0,1,2,(1<<32)-1,1<<32,(1<<63)-1,1<<63,MASK-1,MASK] 23 IMPORT=ROOT/'tools/adapters/go-import';EXPORT=ROOT/'tools/adapters/go-export' 24 OMC_PIN='`734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61`' 25 BRIDGE_COMMIT='`012860dbf26ee62a9838594b9dfd1e3e94a540a9`' 26 NATIVE_OM_PIN='`2c2c53f61d4ab302f1a2092c3c32189335dd53f6cf2b388f47a475f99f2c3940`' 27 H=b'package main\n\n' 28 29 class Fail(Exception):pass 30 def check(c,msg): 31 if not c:raise Fail(msg) 32 33 def run(cmd,data,cwd=None,timeout=60,env=None): 34 return subprocess.run(cmd,input=data,capture_output=True,timeout=timeout,cwd=cwd,env=env) 35 36 def py(tool,data):return run([sys.executable,str(tool)],data) 37 38 # ---- independent envelope model (not the #621 core) ---- 39 def split(env): 40 check(len(env)>=13 and env[:5]==b'OMSB\x01','bad envelope magic') 41 ns,np_=struct.unpack_from('=3 and ops[n-2][0]==1 and ops[n-2][3]==0 and ops[n-1][0]==2 and ops[n-1][2]==n-2 and ops[n-1][1]\n#include \nint main(void){'+body+'return 0;}\n').encode()) 157 r=run(['nice','-n','19',s.cc,'-std=c17','-O2','-Wall','-Wextra','-Werror','-Wno-unused-parameter',str(f),'-o',str(exe)],None,timeout=180) 158 check(r.returncode==0,'cc oracle compile failed: '+r.stderr.decode(errors='replace')[-800:]) 159 s.compiles+=1;s.cache[key]=exe;return exe 160 def values(s,kind,text,name,vectors): 161 nargs=len(vectors[0]);exe=s.build(kind,text,name,nargs) 162 r=run([str(exe)],''.join(' '.join(map(str,v))+'\n' for v in vectors).encode(),timeout=60) 163 check(r.returncode==0,kind+' oracle run failed: '+r.stderr.decode(errors='replace')[-400:]) 164 return [int(x) for x in r.stdout.split()] 165 def gofmt_clean(s,text): 166 r=run([s.gofmt],text);s.gofmt_runs+=1 167 return r.returncode==0 and r.stdout==text 168 169 class Native: 170 """lower(N(U)) -> omc `734f0a39` function mode -> bridge native.om binding -> C caller (translation-v1 section 5).""" 171 def __init__(s,out,lower,omc,bridge,cc): 172 s.out=out/'native';s.out.mkdir();s.lower=lower;s.omc=omc;s.cc=cc;s.cache={};s.calls=0 173 check(hashlib.sha256(Path(omc).read_bytes()).hexdigest()==OMC_PIN,'omc sha256 pin') 174 src=subprocess.run(['git','-C',bridge,'show',f'{BRIDGE_COMMIT}:src/native.om'],capture_output=True,check=True).stdout 175 check(hashlib.sha256(src).hexdigest()==NATIVE_OM_PIN,'bridge native.om sha256 pin') 176 r=run([omc],src);check(r.returncode==0,'bridge native.om compile') 177 s.gen=s.out/'native-gen';s.gen.write_bytes(r.stdout);s.gen.chmod(0o700) 178 def values(s,nsem,vectors): 179 key=identity(nsem);nargs=len(vectors[0]) 180 if key not in s.cache: 181 d=s.out/key[:24];d.mkdir() 182 r=py(s.lower,semonly(nsem));check(r.returncode==0,'lower refused N(U) rc=%d %s'%(r.returncode,r.stderr)) 183 unit=r.stdout;(d/'unit.om').write_bytes(unit) 184 c=run([s.omc],unit);check(c.returncode==0 and c.stdout,'omc function-mode compile failed') 185 b=run([str(s.gen)],unit+b'\0'+b'%08d'%len(c.stdout)+c.stdout);check(b.returncode==0 and b.stdout,'bridge binding failed') 186 params=''.join(', uint64_t i%d'%i for i in range(nargs));args=''.join(', a[%d]'%i for i in range(nargs)) 187 caller=('#include \n#include \n#include \nuint32_t omega_calc(uint64_t *result%s);\n' 188 'int main(void){char line[512];while(fgets(line,sizeof line,stdin)){char *p=line;uint64_t a[6]={0};' 189 'for(int i=0;i<%d;i++)a[i]=strtoull(p,&p,10);(void)a;(void)p;uint64_t r=UINT64_C(`6148914691236517205`);' 190 'uint32_t st=omega_calc(&r%s);printf("%%" PRIu32 " %%" PRIu64 "\\n",st,r);}return 0;}\n')%(params,nargs,args) 191 (d/'omega_native.c').write_bytes(b.stdout);(d/'caller.c').write_text(caller) 192 k=run([s.cc,'-std=gnu11','-O2','-Wall','-Wextra','-Werror','-pthread',str(d/'caller.c'),str(d/'omega_native.c'),'-o',str(d/'caller')],None,timeout=180) 193 check(k.returncode==0,'native caller compile: '+k.stderr.decode(errors='replace')[-400:]) 194 s.cache[key]=d/'caller' 195 r=run([str(s.cache[key])],''.join(' '.join(map(str,v))+'\n' for v in vectors).encode()) 196 lines=r.stdout.decode().split('\n')[:-1];check(r.returncode==0 and len(lines)==len(vectors),'native caller run') 197 out=[] 198 for line in lines: 199 st,val=line.split();check(st=='0','native status '+st);out.append(int(val)) 200 s.calls+=len(lines);return out 201 202 def vectors(nargs,rng): 203 if nargs==0:return [()] 204 if nargs<=2:base=[(x,) for x in BOUNDARY] if nargs==1 else [(x,y) for x in BOUNDARY for y in BOUNDARY] 205 else:base=[tuple(BOUNDARY[(j+k)%len(BOUNDARY)] for k in range(nargs)) for j in range(len(BOUNDARY))] 206 return base+[tuple(rng.getrandbits(64) for _ in range(nargs)) for _ in range(32)] 207 208 # ---- random constant/variable trees for the untyped-constant rule ---- 209 CONSTS=[0,1,2,3,(1<<32)-1,1<<32,(1<<63)-1,1<<63,MASK-1,MASK] 210 def rtree(rng,d): 211 if d==0 or rng.random()<0.3: 212 return ('v',rng.randrange(2)) if rng.random()<0.35 else ('c',rng.choice(CONSTS)) 213 return (rng.choice('+-*'),rtree(rng,d-1),rtree(rng,d-1)) 214 def isconst(t):return t[0]=='c' or (t[0] in '+-*' and isconst(t[1]) and isconst(t[2])) 215 def exact(t): 216 if t[0]=='c':return t[1] 217 a,b=exact(t[1]),exact(t[2]);return a+b if t[0]=='+' else a-b if t[0]=='-' else a*b 218 def profile_ok(t): 219 """go-u64-v1 section 1.1: every constant-only node of the tree evaluates exactly within 0..2^64-1.""" 220 if t[0]=='v':return True 221 if t[0]=='c':return 0<=t[1]<=MASK 222 return profile_ok(t[1]) and profile_ok(t[2]) and (not isconst(t) or 0<=exact(t)<=MASK) 223 def bigconst(t): 224 """types2 rejects any untyped integer constant operation result wider than 512 bits (constant overflow).""" 225 if t[0]!='c' and isconst(t):return abs(exact(t)).bit_length()>512 or bigconst(t[1]) or bigconst(t[2]) 226 return False 227 def go_ok(t): 228 """The Go rule: every maximal constant expression (operand of a uint64 operation, or the returned value) 229 is exact and must be representable as uint64; intermediate constant values are unbounded up to 512 bits.""" 230 if t[0]=='v':return True 231 if isconst(t):return 0<=exact(t)<=MASK and not bigconst(t) 232 return go_ok(t[1]) and go_ok(t[2]) 233 PREC={'+':4,'-':4,'*':5} 234 def text(t,lang,parent=None,side=None): 235 if t[0]=='v':return 'ab'[t[1]] 236 if t[0]=='c':return str(t[1])+('ULL' if lang=='c' else '') 237 p=PREC[t[0]];s=text(t[1],lang,p,'l')+' '+t[0]+' '+text(t[2],lang,p,'r') 238 if parent is not None and (p0 and t.isascii() and t.decode().isidentifier(),'input span') 337 else:check(t=={2:b'+',3:b'-',4:b'*'}[op],'operator span') 338 codec_checks(env,sem,src) 339 if f1src is not None: 340 c=run([str(cimp)],f1src);bump('c_import_runs');check(c.returncode==0,'C import of F1 refused') 341 csem,_,_=decode(c.stdout,'C');check(N(sem)==N(csem),'cross-importer identity: N(import_Go(F2)) != N(import_C(F1))') 342 exported=export_checks(sem,env,tag) 343 sem_b,_=reimport_identity(sem,exported,tag) 344 check(sem_b==sem,'same-language round trip changed the semantic bytes') 345 vec=vectors(nargs,rng);ref=[evaluate(ops,v) for v in vec] 346 check(O.values('go',src,name,vec)==ref,'go(original Go) != reference') 347 check(O.values('go',exported,'calc',vec)==ref,'go(exported Go) != reference') 348 bump('go_observations',2*len(vec)) 349 if f1src is not None:check(O.values('c',f1src,f1name,vec)==ref,'cc(F1 C) != reference');bump('cc_observations',len(vec)) 350 s2=strip(sem);q=gexport(semonly(s2));check(q.returncode==0,'export of stripped unit refused') 351 r2=gimport(q.stdout);check(r2.returncode==0,'re-import of stripped export refused') 352 _,_,ops2=decode(r2.stdout,'Go');sops=[(o[2],o[8],o[9],o[10]) for o in ops_of(s2)] 353 check([evaluate(ops2,v) for v in vec]==[evaluate(sops,v) for v in vec],'stripped round trip evaluation differs') 354 item.update(result='PASS',ops=len(ops),vectors=len(vec),semantic_identity=identity(sem),N_identity=identity(N(sem)),exported=exported.decode()) 355 return item 356 357 rows=[] 358 for fx in f2['positives']: 359 try: 360 src=fx['source'].encode();check(hashlib.sha256(src).hexdigest()==fx['sha256'],'fixture sha') 361 p1=f1pos[fx['f1_id']];check(p1['sha256']==fx['f1_sha256'] and p1['inputs']==fx['inputs'] and p1['name']==fx['name'],'F1 link') 362 rows.append(go_positive(fx['id'],src,fx['name'],fx['inputs'],p1['source'].encode(),p1['name'])) 363 except (Fail,ValueError,KeyError,IndexError,struct.error,subprocess.TimeoutExpired) as e: 364 it={'id':fx['id'],'result':'FAIL','failure':str(e)};failures.append(it);rows.append(it) 365 extra_rows=[] 366 for fx in f2['extra_positives']: 367 try: 368 src=fx['source'].encode();check(hashlib.sha256(src).hexdigest()==fx['sha256'],'fixture sha') 369 extra_rows.append(go_positive(fx['id'],src,fx['function'],fx['inputs'])) 370 except (Fail,ValueError,KeyError,IndexError,struct.error,subprocess.TimeoutExpired) as e: 371 it={'id':fx['id'],'result':'FAIL','failure':str(e)};failures.append(it);extra_rows.append(it) 372 373 # ---- Go import refusals; go_build records what Go itself does with the refused file ---- 374 refusals=[] 375 for fx in f2['refusals']: 376 src=bytes.fromhex(fx['source_hex']) if 'source_hex' in fx else fx['source'].encode() 377 r=gimport(src);ok=hashlib.sha256(src).hexdigest()==fx['sha256'] and r.returncode==fx['status'] and r.stdout==b'' and r.stderr.startswith(b'GO_IMPORT_') 378 it={'id':fx['id'],'name':fx['name'],'want':fx['status'],'exit':r.returncode,'stderr':r.stderr.decode(errors='replace').strip()} 379 if fx.get('go_build') in ('accept','reject'): 380 acc,err=O.gobare(src);it['go_build']='accept' if acc else 'reject' 381 if not acc:it['go_error']=err.splitlines()[-1][:200] if err else '' 382 ok=ok and it['go_build']==fx['go_build'] 383 it['result']='PASS' if ok else 'FAIL' 384 if not ok:failures.append(it) 385 refusals.append(it) 386 387 # ---- untyped-constant rule on seeded random trees (go-u64-v1 section 1.1) ---- 388 crow={'trees':0,'profile_accepted':0,'profile_refused':0,'go_accepts_profile_refused':0,'go_rejects':0,'exporter_refusals_67':0,'failures':0} 389 seen=set() 390 while crow['trees']\nuint64_t calc(uint64_t a, uint64_t b) { return '+text(t,'c').encode()+b'; }\n');bump('c_import_runs') 410 check(c.returncode==0,'C import of the tree refused') 411 x=gexport(c.stdout) 412 if pok:check(x.returncode==0,'exporter refused a profile-accepted tree');csem,_=split(c.stdout);reimport_identity(csem,x.stdout,'tree') 413 else:check(x.returncode==67 and not x.stdout and x.stderr==b'GO_EXPORT_LIMIT\n','exporter must refuse 67, got %d'%x.returncode);crow['exporter_refusals_67']+=1 414 except (Fail,ValueError,struct.error,subprocess.TimeoutExpired) as e: 415 it.update(result='FAIL',failure=str(e));failures.append(it);crow['failures']+=1 416 417 # ---- import boundary controls (exact and over capacity), each accepted one exported and re-imported ---- 418 head=H+b'func calc(a uint64, b uint64) uint64 { return ' 419 base=head+b'a + b }' 420 chain=lambda k:head+b'a'+b' + a'*k+b' }' 421 parens=lambda k:head+b'('*k+b'a'+b')'*k+b' }' 422 controls=[('exact-source-capacity',base+b' '*(4096-len(base)),0,12),('comment-at-capacity',base+b'// '+b'x'*(4096-len(base)-3),0,12), 423 ('operation-capacity',chain(60),0,61*5),('nesting-limit',parens(16),0,5), 424 ('over-source-capacity',base+b' '*(4097-len(base)),67,None),('over-operation-capacity',chain(61),67,None), 425 ('over-nesting-limit',parens(17),67,None)] 426 ctl=[] 427 for name,src,want,value in controls: 428 it={'name':name,'source_bytes':len(src)} 429 try: 430 r=gimport(src) 431 if want:check(r.returncode==want and not r.stdout and r.stderr==b'GO_IMPORT_LIMIT\n','%s rc=%d'%(name,r.returncode)) 432 else: 433 check(r.returncode==0,'%s refused rc=%d %s'%(name,r.returncode,r.stderr));sem,side,ops=decode(r.stdout,'Go');sidecar(sem,side,src,len(ops)) 434 check(evaluate(ops,[5,7])==value,name+' value');codec_checks(r.stdout,sem,src);exported=export_checks(sem,r.stdout,name) 435 sem_b,_=reimport_identity(sem,exported,name);check(sem_b==sem,name+' round trip') 436 vec=vectors(2,rng);ref=[evaluate(ops,v) for v in vec] 437 check(O.values('go',src,'calc',vec)==ref and O.values('go',exported,'calc',vec)==ref,name+' go differential') 438 it.update(ops=len(ops),exported_bytes=len(exported)) 439 it.update(result='PASS',exit=r.returncode) 440 except (Fail,ValueError,struct.error) as e:it.update(result='FAIL',failure=str(e));failures.append(it) 441 ctl.append(it) 442 r=subprocess.run([str(ROOT/'build/L741/go-import')],stdin=subprocess.DEVNULL,capture_output=True,preexec_fn=lambda:os.close(0),timeout=10) 443 ctl.append({'name':'import-closed-stdin','exit':r.returncode,'result':'PASS' if r.returncode==77 and not r.stdout and r.stderr==b'GO_IMPORT_IO\n' else 'FAIL'}) 444 r=subprocess.run([str(ROOT/'build/L741/go-export')],stdin=subprocess.DEVNULL,capture_output=True,preexec_fn=lambda:os.close(0),timeout=10) 445 ctl.append({'name':'export-closed-stdin','exit':r.returncode,'result':'PASS' if r.returncode==77 and not r.stdout and r.stderr==b'GO_EXPORT_IO\n' else 'FAIL'}) 446 for tool in (IMPORT,EXPORT): 447 r=run([sys.executable,str(tool),'unexpected'],base);ctl.append({'name':tool.name+'-arguments-refused','exit':r.returncode,'result':'PASS' if r.returncode==64 and not r.stdout and b'BAD_COMMAND' in r.stderr else 'FAIL'}) 448 r=run([sys.executable,str(IMPORT)],base);d=run([str(ROOT/'build/L741/go-import')],base) 449 ctl.append({'name':'public-import-identical-to-native','result':'PASS' if r.returncode==0 and r.stdout==d.stdout else 'FAIL'}) 450 closure=['src/source-aware/vendor/sha256.om','src/source-aware/core-v2.om','src/adapters/go-u64-import.om','src/adapters/go-u64-export.om','build/L741/build.json','build/L741/go-import','build/L741/go-export'] 451 for tool,victims in ((IMPORT,['src/adapters/go-u64-import.om','src/source-aware/vendor/sha256.om','build/L741/go-import']),(EXPORT,['src/adapters/go-u64-export.om','src/source-aware/core-v2.om','build/L741/go-export'])): 452 for victim in victims: 453 with tempfile.TemporaryDirectory(prefix='closed-build-',dir=out) as td: 454 t=Path(td) 455 for rel in ['tools/adapters/'+tool.name]+closure: 456 p=t/rel;p.parent.mkdir(parents=True,exist_ok=True);shutil.copyfile(ROOT/rel,p);p.chmod(0o700) 457 with (t/victim).open('ab') as f:f.write(b'changed') 458 r=run([sys.executable,str(t/'tools/adapters'/tool.name)],base) 459 ok=r.returncode==78 and not r.stdout and b'STALE_OR_MISSING_BUILD' in r.stderr 460 ctl.append({'name':tool.name+'-stale-'+victim,'exit':r.returncode,'result':'PASS' if ok else 'FAIL'}) 461 failures+=[c for c in ctl if c['result']=='FAIL' and c not in failures] 462 463 # ---- exporter refusals and accepted exporter boundaries ---- 464 good=gimport(base).stdout 465 def unit(ver,lang,prof,runtime,abi,ops,typ=1): 466 sem=b'OMSA'+bytes([ver,lang,prof,1,runtime,abi])+struct.pack('64:continue 538 drow['units']+=1;env=unit(ver,lang,prof,0,1,recs);sem,_=split(env);it={'member':m,'ops':len(ops)} 539 try: 540 root=len(ops)-1 541 if normalized(ops):root=ops[-1][1] 542 nops,depth,cok=model(ops,root,ni);ok=nops<=64 and depth<=16 and cok 543 r=gexport(env) 544 if not ok:check(r.returncode==67 and not r.stdout,'model predicts 67 (ops %d depth %d constants %s), got %d'%(nops,depth,cok,r.returncode));drow['refused_67']+=1;continue 545 check(r.returncode==0,'model predicts export, got %d %s'%(r.returncode,r.stderr));drow['exported']+=1 546 check(O.gofmt_clean(r.stdout),'random unit export is not gofmt-clean') 547 q=gimport(r.stdout);check(q.returncode==0,'re-import refused %d'%q.returncode);_,_,ops2=decode(q.stdout,'Go') 548 check(len(ops2)==nops,'re-import operation count %d != model %d'%(len(ops2),nops)) 549 vec=vectors(ni,rng)[:20];ref=[evaluate(ops,v) for v in vec];check([evaluate(ops2,v) for v in vec]==ref,'re-import evaluation differs') 550 if drow['go_checked']<16:check(O.values('go',r.stdout,'calc',vec)==ref,'go(export) != reference');drow['go_checked']+=1 551 except (Fail,ValueError,struct.error) as e:it.update(result='FAIL',failure=str(e));failures.append(it);drow['failures']+=1 552 553 # ---- composition C -> Go: F1 positives and the four accepted C import boundary controls ---- 554 ch=b'#include \nuint64_t calc(uint64_t a,uint64_t b){return a+b;}' 555 cctl=[('C-exact-source-capacity',ch+b' '*(4096-len(ch)),'calc',2),('C-comment-at-capacity',ch+b'//'+b'x'*(4096-len(ch)-2),'calc',2), 556 ('C-operation-capacity',b'#include \nuint64_t calc(uint64_t a,uint64_t b){return '+b'+'.join([b'a']*61)+b';}','calc',2), 557 ('C-nesting-limit',b'#include \nuint64_t calc(uint64_t a,uint64_t b){return '+b'('*16+b'a'+b')'*16+b';}','calc',2)] 558 comp=[] 559 for tag,csrc,name,nargs in [(p['id'],p['source'].encode(),p['name'],p['inputs']) for p in f1['positives']]+cctl: 560 it={'id':'C->Go '+tag} 561 try: 562 c=run([str(cimp)],csrc);bump('c_import_runs');check(c.returncode==0,'C import refused') 563 sem_a,_,ops_a=decode(c.stdout,'C') 564 src_b=export_checks(sem_a,c.stdout,tag) 565 sem_b,ops_b=reimport_identity(sem_a,src_b,tag) 566 vec=vectors(nargs,rng);ref=[evaluate(ops_a,v) for v in vec] 567 check(O.values('c',csrc,name,vec)==ref,'cc(original C) != reference(U_A)') 568 check(O.values('go',src_b,'calc',vec)==ref,'go(src_B) != reference(U_A)') 569 check([evaluate(ops_b,v) for v in vec]==ref,'reference(U_B) != reference(U_A)') 570 if native:check(native.values(N(sem_a),vec)==ref,'native lower(N(U_A)) != reference(U_A)') 571 it.update(result='PASS',identity=identity(N(strip(sem_a))),vectors=len(vec),native_realization='PASS' if native else native_state) 572 except (Fail,ValueError,struct.error) as e:it.update(result='FAIL',failure=str(e));failures.append(it) 573 comp.append(it) 574 575 # ---- composition Go -> C: R(U, C) in test code (retarget not landed), then the #622 C exporter ---- 576 gc_rows=[];go_to_c='NOT_RUN (no c-export)' 577 if cexp: 578 go_to_c='RUN' 579 for fx in f2['positives']: 580 it={'id':'Go->C '+fx['id']} 581 try: 582 src=fx['source'].encode();r=gimport(src);check(r.returncode==0,'Go import refused');sem_a,_,ops_a=decode(r.stdout,'Go') 583 rc_env=R(r.stdout,sem_a,'C');q=py(cexp,rc_env);bump('c_export_runs');check(q.returncode==0,'c-export refused R(U,C) rc=%d %s'%(q.returncode,q.stderr)) 584 q2=py(cexp,semonly(sem_a));check(q2.returncode!=0 and not q2.stdout,'v1-core c-export accepted a v2 unit');bump('c_export_v2_refusal_status_%d'%q2.returncode) 585 c=run([str(cimp)],q.stdout);bump('c_import_runs');check(c.returncode==0,'C import of exported C refused') 586 sem_b,_,ops_b=decode(c.stdout,'C');check(N(strip(sem_b))==N(strip(sem_a)),'identity N(strip(U_B)) != N(strip(U_A))') 587 vec=vectors(fx['inputs'],rng);ref=[evaluate(ops_a,v) for v in vec] 588 check(O.values('go',src,fx['name'],vec)==ref,'go(original Go) != reference') 589 check(O.values('c',q.stdout,'calc',vec)==ref,'cc(src_B) != reference') 590 check([evaluate(ops_b,v) for v in vec]==ref,'reference(U_B) != reference(U_A)') 591 if native:check(native.values(N(sem_a),vec)==ref,'native lower(N(U_A)) != reference(U_A)') 592 it.update(result='PASS',vectors=len(vec),exported_c=q.stdout.decode(),native_realization='PASS' if native else native_state) 593 except (Fail,ValueError,struct.error) as e:it.update(result='FAIL',failure=str(e));failures.append(it) 594 gc_rows.append(it) 595 596 def ver(cmd): 597 try:return subprocess.check_output(cmd,text=True,env=O.env).strip() 598 except (OSError,subprocess.CalledProcessError) as e:return 'unavailable: '+str(e) 599 report={'schema':'omega.go-u64.selftest.v1','result':'FAIL' if failures else 'PASS','status_flags':'TESTED (author self-test), not QUALIFIED', 600 'evidence':'REFERENCE + DIFFERENTIAL (go/cc NATIVE AArch64%s); no PROOF'%(', Omega native realization' if native else ''), 601 'source_commit':subprocess.check_output(['git','-C',str(ROOT),'rev-parse','HEAD'],text=True).strip(), 602 'build':json.loads((ROOT/'build/L741/build.json').read_text()),'go':ver([a.go,'version']),'go_sha256':hashlib.sha256(Path(a.go).read_bytes()).hexdigest(), 603 'gofmt_sha256':hashlib.sha256(Path(a.gofmt).read_bytes()).hexdigest(),'cc':ver([a.cc,'--version']).splitlines()[0], 604 'c_import_sha256':hashlib.sha256(cimp.read_bytes()).hexdigest(),'sa1_sha256':hashlib.sha256(sa1.read_bytes()).hexdigest(), 605 'codec_v2':codec_v2,'sa2_sha256':hashlib.sha256((sa2root/'build/L832/sa').read_bytes()).hexdigest() if have_sa2 else None, 606 'c_export':str(cexp) if cexp else None,'retarget_tool':('RUN '+str(rtool)+' sha256 '+hashlib.sha256(rtool.read_bytes()).hexdigest()) if rtool else 'NOT_RUN (Python R only)','native_realization':native_state, 607 'positives':len(rows),'positives_passed':sum(r['result']=='PASS' for r in rows),'not_in_profile':len(f2['not_in_profile']), 608 'extra_positives':len(extra_rows),'extra_positives_passed':sum(r['result']=='PASS' for r in extra_rows), 609 'refusals':len(refusals),'refusals_passed':sum(r['result']=='PASS' for r in refusals), 610 'refusals_go_checked':sum('go_build' in r for r in refusals),'constant_rule':crow,'random_units':drow, 611 'controls':len(ctl),'controls_passed':sum(r['result']=='PASS' for r in ctl),'export_cases':len(xrows),'export_cases_passed':sum(r['result']=='PASS' for r in xrows), 612 'c_to_go':len(comp),'c_to_go_passed':sum(r['result']=='PASS' for r in comp),'go_to_c':go_to_c,'go_to_c_cases':len(gc_rows),'go_to_c_passed':sum(r['result']=='PASS' for r in gc_rows), 613 'native_calls':native.calls if native else 0,'oracle_compiles':O.compiles,'go_builds':O.go_builds,'gofmt_runs':O.gofmt_runs,'counts':counts, 614 'cases':rows,'extra_cases':extra_rows,'refusal_cases':refusals,'control_cases':ctl,'export_rows':xrows,'c_to_go_cases':comp,'go_to_c_rows':gc_rows,'failures':failures} 615 (out/'result.json').write_text(json.dumps(report,indent=1)+'\n') 616 keys=['positives','positives_passed','not_in_profile','extra_positives','extra_positives_passed','refusals','refusals_passed','refusals_go_checked','controls','controls_passed', 617 'export_cases','export_cases_passed','c_to_go','c_to_go_passed','go_to_c','go_to_c_cases','go_to_c_passed','codec_v2','retarget_tool','native_realization','native_calls','oracle_compiles','go_builds','gofmt_runs'] 618 print(report['result'],' '.join('%s=%s'%(k,report[k]) for k in keys),'constant_rule='+json.dumps(crow,separators=(',',':')),'random_units='+json.dumps(drow,separators=(',',':')),' '.join('%s=%s'%kv for kv in counts.items())) 619 for f in failures[:20]:print('FAIL',json.dumps(f)[:600]) 620 return 1 if failures else 0 621 622 if __name__=='__main__':raise SystemExit(main())