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 / net-mutant.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Read-only verification: wrong host-word mutants must fail real Omega fixtures. |
| 3 | |
| 4 | Python orchestrates compiler invocations only; it does not implement a host word. |
| 5 | Run with nice -n 19 ionice -c3. OMC selects the seed compiler used to compile |
| 6 | candidate sources, not the candidate compiler being qualified. |
| 7 | """ |
| 8 | from pathlib import Path |
| 9 | import os |
| 10 | import subprocess |
| 11 | import tempfile |
| 12 | |
| 13 | ROOT = Path(__file__).resolve().parents[2] |
| 14 | SEED = Path(os.environ.get("OMC", ROOT / "seed/out/omc")).resolve() |
| 15 | SOURCE = ROOT / "seed/omc/omc.om" |
| 16 | |
| 17 | |
| 18 | def compile_unit(compiler, source, target): |
| 19 | result = subprocess.run([str(compiler)], input=source, capture_output=True, timeout=30) |
| 20 | if result.returncode != 0 or result.stderr: |
| 21 | raise RuntimeError(f"compile refused rc={result.returncode}: {result.stderr.decode(errors='replace')}") |
| 22 | target.write_bytes(result.stdout) |
| 23 | target.chmod(0o700) |
| 24 | |
| 25 | |
| 26 | def exercise(source, fixture, directory): |
| 27 | compiler = directory / "omc" |
| 28 | program = directory / "fixture" |
| 29 | compile_unit(SEED, source, compiler) |
| 30 | compile_unit(compiler, (ROOT / "seed/host/tests" / fixture).read_bytes(), program) |
| 31 | return subprocess.run([str(program)], cwd=directory, capture_output=True, timeout=10) |
| 32 | |
| 33 | |
| 34 | def main(): |
| 35 | original = SOURCE.read_bytes() |
| 36 | mutations = [ |
| 37 | ("parent-pid-wrong-syscall", "netpeer.om", b"if eq c 154\nret 173\n", b"if eq c 154\nret 110\n"), |
| 38 | ("ignored-option-refusal", "netdata.om", b"matconst 0 sub ulong 0 92\n", b"matconst 0 0\n"), |
| 39 | ("peer-local-wrong-syscall", "peername.om", b"if eq c 224\nhsys 205\n", b"if eq c 224\nhsys 204\n"), |
| 40 | ] |
| 41 | with tempfile.TemporaryDirectory(prefix="net-mutants-") as scratch: |
| 42 | for name, fixture, needle, replacement in mutations: |
| 43 | if original.count(needle) != 1: |
| 44 | raise RuntimeError(f"mutation anchor not unique: {name}") |
| 45 | positive = Path(scratch) / (name + "-positive") |
| 46 | positive.mkdir() |
| 47 | result = exercise(original, fixture, positive) |
| 48 | if result.returncode != 0 or not result.stdout.startswith(b"PASS "): |
| 49 | raise RuntimeError(f"positive fixture failed: {name}: rc={result.returncode}") |
| 50 | negative = Path(scratch) / (name + "-mutant") |
| 51 | negative.mkdir() |
| 52 | result = exercise(original.replace(needle, replacement), fixture, negative) |
| 53 | if result.returncode != 1: |
| 54 | raise RuntimeError(f"mutant not caught by assertion: {name}: rc={result.returncode}") |
| 55 | print(f"PASS caught {name} via real {fixture} assertion", flush=True) |
| 56 | print("PASS native networking wrong-word mutants") |
| 57 | |
| 58 | |
| 59 | if __name__ == "__main__": |
| 60 | main() |