interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / tools / trit / mutate-daily.py

66 lines · 3168 bytes Raw Blame History
1#!/usr/bin/env python3
2"""External mutation instrument for daily-interface assertions; no runtime role."""
3import hashlib
4import json
5import os
6from pathlib import Path
7import re
8import subprocess
9import tempfile
10
11ROOT = Path(__file__).resolve().parents[2]
12OMC = Path(os.environ.get('OMC', ROOT / 'seed/out/omc')).resolve()
13SOURCE = Path(os.environ.get('COMPOSED', ROOT / 'build/trit/trit.full.om')).resolve()
14WORK = Path(tempfile.mkdtemp(prefix='daily-mutants-', dir=os.environ.get('TMPDIR')))
15source = SOURCE.read_text()
16cases = [
17 ('baseline', None, None),
18 ('stop-promoted', 'put outb o 49', 'put outb o add uchar open t 48'),
19 ('receipt-leak', 'if consume\nzap\nret 0', 'if consume\nreceipt\nzap\nret 0'),
20 ('next-wake-leak', 'if consume\nzap\nret 0', 'if consume\nz = emit state\nzap\nret 0'),
21 ('consume-bypassed', 'doack ulong tn\nif consume', 'note omitted consumption\nif consume'),
22]
23records = []
24failed = False
25for name, before, after in cases:
26 d = WORK / name
27 d.mkdir()
28 if before is not None and source.count(before) != 1:
29 records.append({'name':name, 'verdict':'NOT_APPLIED'})
30 failed = True
31 break
32 text = source if before is None else source.replace(before, after)
33 (d/'input.om').write_text(text)
34 binary = d/'trit'
35 with binary.open('wb') as output:
36 p = subprocess.run([str(OMC)], input=text.encode(), stdout=output, stderr=subprocess.PIPE)
37 (d/'compiler.stderr').write_bytes(p.stderr)
38 item = {'name':name, 'compile_command':[str(OMC)], 'compile_exit':p.returncode,
39 'input_sha256':hashlib.sha256(text.encode()).hexdigest()}
40 records.append(item)
41 if p.returncode:
42 item['verdict'] = 'INVALID'
43 failed = True
44 break
45 binary.chmod(0o755)
46 cmd = ['python3', str(ROOT/'tools/trit/test-daily.py')]
47 p = subprocess.run(cmd, env=dict(os.environ, BIN=str(binary), TMPDIR=str(d)), capture_output=True)
48 (d/'test.stdout').write_bytes(p.stdout)
49 (d/'test.stderr').write_bytes(p.stderr)
50 totals = re.findall(rb'^DAILY checks=([0-9]+) failed=([0-9]+) receipt=.+$', p.stdout, re.M)
51 good = False
52 if len(totals) == 1 and int(totals[0][0]) > 0:
53 failures = int(totals[0][1])
54 good = (p.returncode == 0 and failures == 0) if before is None else (
55 p.returncode == 1 and failures > 0 and re.search(rb'^FAIL ', p.stdout, re.M) is not None)
56 item.update(test_command=cmd, test_exit=p.returncode, binary_sha256=hashlib.sha256(binary.read_bytes()).hexdigest(),
57 stdout_sha256=hashlib.sha256(p.stdout).hexdigest(), stderr_sha256=hashlib.sha256(p.stderr).hexdigest(),
58 verdict=('BASELINE_PASS' if before is None else 'KILLED') if good else 'REJECTED')
59 print(name, item['verdict'])
60 if not good:
61 failed = True
62 break
63(WORK/'receipt.json').write_text(json.dumps({'compiler_sha256':hashlib.sha256(OMC.read_bytes()).hexdigest(),
64 'composed_input_sha256':hashlib.sha256(SOURCE.read_bytes()).hexdigest(), 'records':records}, indent=2)+'\n')
65print(f'DAILY-MUTATIONS {"FAIL" if failed else "PASS"} receipt={WORK}/receipt.json')
66raise SystemExit(bool(failed))