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 / host / irq-mutants.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Read-only compiler mutation oracle. Not used by compiler or product binaries.""" |
| 3 | import os |
| 4 | from pathlib import Path |
| 5 | import subprocess |
| 6 | import sys |
| 7 | |
| 8 | root = Path(__file__).resolve().parents[2] |
| 9 | omc, oracle, work = map(Path, sys.argv[1:]) |
| 10 | work.mkdir(parents=True, exist_ok=True) |
| 11 | source = (root / 'seed/omc/omc.om').read_text() |
| 12 | fixture = (root / 'seed/host/tests/vfioirq.om').read_bytes() |
| 13 | # Each edit must build a real mutant compiler and an executable fixture. A build |
| 14 | # failure is INVALID, never a killed mutant. The same runtime oracle challenges it. |
| 15 | mutants = [ |
| 16 | ('device-kind', 'hload x 4 10\nfdcheck 1', 'hload x 4 10\nfdcheck 2', '1'), |
| 17 | ('event-kind', 'skip = mbranch 0\nfdcheck 2', 'skip = mbranch 0\nfdcheck 1', '5'), |
| 18 | ('argsz', 'e3 3942645760 31 4 3\ntrapc 1 3', 'e3 3942645760 31 4 3\nnote removed argsz refusal', '2'), |
| 19 | ('count-bound', 'mimmed 4043309056 31 5 64\ntrapc 8 3', 'mimmed 4043309056 31 5 65\ntrapc 8 3', '3'), |
| 20 | ('range-wrap', 'e3 3942645760 31 6 7\ntrapc 8 3', 'e3 3942645760 31 6 7\nnote removed range refusal', '8'), |
| 21 | ('payload-size', 'matconst 7 4\ne3 2600500224 7 5 7', 'matconst 7 8\ne3 2600500224 7 5 7', '0'), |
| 22 | ('action-allowlist', 'mimmed 4043309056 31 4 17\ntrapc 1 3', 'mimmed 4043309056 31 4 17\nnote removed action refusal', '7'), |
| 23 | ('event-count-condition', 'patch19 event get oc 0\nmimmed 4043309056 31 5 0\ntrapc 0 3', 'patch19 event get oc 0\nmimmed 4043309056 31 5 0\ntrapc 1 3', '0'), |
| 24 | ('disable-start', 'mimmed 4043309056 31 6 0\ntrapc 1 3\ndisdone', 'mimmed 4043309056 31 6 0\nnote removed disable start refusal\ndisdone', '<'), |
| 25 | ('close-invalidation', 'if and ne get progmode 0 0 eq c 100\nhload x 0 10\nfdforget', 'if and ne get progmode 0 0 eq c 100\nhload x 0 10\nnote removed close invalidation', '6'), |
| 26 | ('dup-invalidation', 'hload x 1 10\nfdforget\npatch19 baddup', 'hload x 1 10\nnote removed dup invalidation\npatch19 baddup', ';'), |
| 27 | ('payload-loop', 'mimmed 3506438144 5 5 1\nmimmed 4043309056 31 5 0\nagain = mbranch 1', 'mimmed 3506438144 5 5 1\nmimmed 4043309056 31 5 0\nagain = mbranch 0', 'A'), |
| 28 | ('cloexec', 'matconst 1 526336\nhsys 19', 'matconst 1 2048\nhsys 19', '0'), |
| 29 | ] |
| 30 | for name, old, new, mode in mutants: |
| 31 | if source.count(old) != 1: |
| 32 | raise SystemExit(f'INVALID {name}: mutation site count={source.count(old)}') |
| 33 | compiler = work / (name + '.omc') |
| 34 | altered = source.replace(old, new) |
| 35 | (work / (name + '.om')).write_text(altered) |
| 36 | result = subprocess.run([str(omc)], input=altered.encode(), capture_output=True, timeout=30) |
| 37 | if result.returncode: |
| 38 | raise SystemExit(f'INVALID {name}: compiler build rc={result.returncode} {result.stderr!r}') |
| 39 | compiler.write_bytes(result.stdout) |
| 40 | compiler.chmod(0o700) |
| 41 | result = subprocess.run([str(compiler)], input=fixture, capture_output=True, timeout=30) |
| 42 | if result.returncode: |
| 43 | raise SystemExit(f'INVALID {name}: fixture build rc={result.returncode} {result.stderr!r}') |
| 44 | binary = work / (name + '.elf') |
| 45 | binary.write_bytes(result.stdout) |
| 46 | binary.chmod(0o700) |
| 47 | expected = '0' if mode == '0' else '103' |
| 48 | result = subprocess.run([str(oracle), str(binary), mode, expected, '0'], capture_output=True, timeout=10) |
| 49 | (work / (name + '.log')).write_bytes(result.stdout + result.stderr) |
| 50 | if result.returncode == 0: |
| 51 | raise SystemExit(f'FAIL {name}: mutant survived') |
| 52 | print(f'PASS killed {name} oracle_rc={result.returncode}', flush=True) |
| 53 | print(f'PASS IRQ compiler mutants killed={len(mutants)}') |