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/seed/modules/tests/check.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 / seed / modules / tests / check.py` 255 lines ยท 18349 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Independent module integration and mutation oracle. No production dependency.""" 3 import hashlib, os, pathlib, struct, subprocess, sys, tempfile 4 P=pathlib.Path 5 repo=P(__file__).resolve().parents[3] 6 compiler=P(sys.argv[1]).resolve() 7 seed=repo/'seed/out/omc' 8 out=P(sys.argv[2]).resolve() if len(sys.argv)>2 else P(tempfile.mkdtemp(prefix='ommodules-')) 9 out.mkdir(parents=True,exist_ok=True) 10 sha=lambda b:hashlib.sha256(b).hexdigest() 11 u=lambda b,p:struct.unpack_from('limit: 213 cases.append((f'n = {lit(n)}\ne = {lit(e)}\nl = {lit(limit)}\nr = growto n e l\nret 0',20,f'growto refuses {n} limit {limit}'));continue 214 res=n+e if e<=limit-n else n 215 cases.append((f'n = {lit(n)}\ne = {lit(e)}\nl = {lit(limit)}\nr = growto n e l\nneed eq r {lit(res)} 90\nret 0',0,f'growto {n} {e} limit {limit}')) 216 # Arena reservations refuse before touching memory when used+request passes the fixed-width boundary. 217 pre='r = ta 1\nr = ba 1\n' 218 for used,n,fn,lim in [(1,MAX,'ba',MAX),(1,2**64-1,'ba',MAX),(MAX,1,'ba',MAX),(MAX-99,100,'ba',MAX),(1,TL,'ta',TL),(1,2**64-1,'ta',TL),(TL,1,'ta',TL),(5,TL-4,'ta',TL)]: 219 idx=0 if fn=='ba' else 1 220 cases.append((pre+f'u = {lit(used)}\nn = {lit(n)}\nput ms {idx} u\nr = {fn} n\nret 0',20,f'{fn} refuses used {used} request {n}')) 221 return cases 222 cases=arith_cases();bad=[] 223 for main,want,label in cases: 224 got=hrun(source.decode(),main) 225 if got!=want:bad.append((label,got,want)) 226 assert not bad,bad[:10] 227 ok(f'{len(cases)} synthetic length-arithmetic boundary cases') 228 # Small real growth path through ba/ta (no boundary allocation). 229 assert hrun(source.decode(),'r = ta 1\nr = ba 1\np = ba 5000\nneed eq p 1 90\nput mb 5000 7\nq = ba 100000\nneed eq q 5001 91\nput mb 105000 9\nneed eq get mb 5000 7 92\nt = ta 100000\nneed eq t 1 93\nput mt 100000 5\nneed eq get mt 100000 5 94\nret 0')==0;ok('small arena growth path preserves data') 230 # SHA-256 bit-length field is a real 64-bit wire boundary, refused before any read. 231 shsrc=(repo/'seed/ng/sha256.om').read_text() 232 def hashharness(n): 233 s=('om2\nglobal mb uchar *\nglobal mt ulong *\nglobal ms ulong 8\nglobal mw uchar 4\nglobal mh uchar 64\ntext err "x\\n"\n'+shsrc.replace('om2\n','',1)+''.join(extract(driver_text,x) for x in ['die','need','hash'])+f'fn main to int\nn = {lit(n)}\nhash 0 n\nret 0\nend\n') 234 return s.encode() 235 driver_text=(repo/'seed/modules/driver.om').read_text() 236 for n,want in [(2**61,20),(2**64-1,20),(2**63,20)]: 237 r=subprocess.run([seed],input=hashharness(n),stdout=subprocess.PIPE,stderr=subprocess.PIPE);assert r.returncode==0,r.stderr 238 e=hdir/f'hash{n}';e.write_bytes(r.stdout);e.chmod(0o755) 239 assert subprocess.run([e],capture_output=True).returncode==want,n 240 ok('SHA-256 length field boundary refused') 241 for old,label in [('need le b div `9223372036854775807` a 20','sizemul overflow'),('need le b sub `9223372036854775807` a 20','sizeadd overflow'),('need le n limit 20','growto limit'),('need le n sub `9223372036854775807` p 20','ba overflow'),('need le n sub `1152921504606846975` p 20','ta overflow')]: 242 mtext=source.decode();assert mtext.count(old)==1,old 243 mtext=mtext.replace(old,'note disabled arithmetic check') 244 killed=any(hrun(mtext,m)!=w for m,w,_ in cases) 245 assert killed,'surviving arithmetic mutant '+label 246 ok('caught arithmetic mutant '+label) 247 # Independent, targeted implementation mutants must fail the corresponding negative assertion. 248 mutants=[(b'need eq rw site want 32',b'note disabled relocation check',mutations[10]),(b'need le cost `8388608` 37',b'note disabled stack check',mutations[11])] 249 for idx,(old,new,(change,label)) in enumerate(mutants): 250 assert source.count(old)==1 251 exe=out/f'mutant-{idx}';compile_driver(source.replace(old,new),exe) 252 try:mutation(root,change,label+' mutant',exe,False) 253 except AssertionError:ok('caught implementation mutant '+str(idx)) 254 else:raise AssertionError('surviving implementation mutant '+str(idx)) 255 print(f'MODULES PASS {len(passed)} compiler={comp} driver={sha(driver.read_bytes())} source={sha(source)}',flush=True)