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
omega-mv / seed / omc / mutants-ir-trap.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Reference-only compiled mutation gate for L524. Compile errors never count as kills.""" |
| 3 | from pathlib import Path |
| 4 | import hashlib |
| 5 | import os |
| 6 | import re |
| 7 | import subprocess |
| 8 | |
| 9 | root = Path(__file__).resolve().parents[2] |
| 10 | os.chdir(root) |
| 11 | out = root/'build/seed/ir-trap-mutants' |
| 12 | out.mkdir(parents=True, exist_ok=True) |
| 13 | src = (root/'seed/omc/omc.om').read_text() |
| 14 | |
| 15 | |
| 16 | def site(n): |
| 17 | """The two diagnostic-v2 instrumentation lines of site n, exactly as seed/omc/omc.om carries them |
| 18 | between a refusal's condition and its fail line; a mutant anchor keeps them so only the code mutates.""" |
| 19 | m = re.search(r'^note d2site %d\|[^\n]*\nput d2site 0 %d\n' % (n, n), src, re.M) |
| 20 | assert m, 'diagnostic site %d not found in seed/omc/omc.om' % n |
| 21 | return m.group(0) |
| 22 | |
| 23 | |
| 24 | mutants = [ |
| 25 | ('wrong-code', 'ir_op 12 code 0 0 0', 'ir_op 12 1 0 0 0', 'FAIL trap03 Wolfram boundary outputs'), |
| 26 | ('void-tag', 'if eq get ir_ret 0 76\nemitb 0', 'if eq get ir_ret 0 76\nemitb 76', 'FAIL void exact C-oracle IR'), |
| 27 | ('unchecked-code', 'if or lt code 1 gt code 14\n' + site(528) + 'fail 8', 'if false\n' + site(528) + 'fail 8', |
| 28 | 'FAIL too_large refused error 8'), |
| 29 | ('eol-code', 'if eq k 0\n' + site(70) + 'fail eolc', 'if eq k 0\n' + site(70) + 'fail 16', |
| 30 | 'FAIL missing refused error 4'), |
| 31 | ('name-code', 'end\nend\nend\nend\n' + site(72) + 'fail 16\nret 0', 'end\nend\nend\nend\n' + site(72) + 'fail 4\nret 0', |
| 32 | 'FAIL named refused error 16'), |
| 33 | ] |
| 34 | for name, old, new, marker in mutants: |
| 35 | assert src.count(old) == 1, name |
| 36 | path = out/(name+'.om') |
| 37 | path.write_text(src.replace(old, new)) |
| 38 | env = dict(os.environ, OMC_SOURCE=str(path)) |
| 39 | p = subprocess.run(['python3','seed/omc/gate-ir-trap.py','--build-only'],env=env,capture_output=True,timeout=30) |
| 40 | (out/(name+'-build.log')).write_bytes(p.stdout+p.stderr) |
| 41 | # Outside the kill classification: a refusal, crash or empty shell is never a kill. |
| 42 | assert p.returncode == 0, f'{name}: compilation/fixpoint failure is NOT caught' |
| 43 | elf = root/'build/seed/ir-trap/stage3' |
| 44 | data = elf.read_bytes() |
| 45 | assert len(data) >= 64 and data[:4] == b'\x7fELF' and data[18:20] == b'\xb7\x00' |
| 46 | p = subprocess.run(['python3','seed/omc/gate-ir-trap.py'],env=env,capture_output=True,timeout=60) |
| 47 | (out/(name+'-test.log')).write_bytes(p.stdout+p.stderr) |
| 48 | assert p.returncode == 1 and marker.encode() in p.stdout and b'CHECKS=67 ' in p.stdout, (name,p.stdout,p.stderr) |
| 49 | print(f'CAUGHT {name}: compiled ELF sha256={hashlib.sha256(data).hexdigest()}; {marker}',flush=True) |
| 50 | print(f'COMPILED_MUTANTS={len(mutants)} CAUGHT={len(mutants)} RC=0') |