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 / seed / omc / tests / size-record.py

51 lines · 1852 bytes Raw Blame History
1#!/usr/bin/env python3
2"""External oracle for the seed-born source/binary size record."""
3import hashlib
4from pathlib import Path
5import subprocess
6import sys
7import tempfile
8
9root = Path(__file__).resolve().parents[1]
10tool = Path(sys.argv[1]).resolve()
11binary = (root.parent / "out" / "omc").read_bytes()
12source = (root / "omc.om").read_bytes()
13passed = 0
14
15with tempfile.TemporaryDirectory(prefix="omega-size-record-") as tmp:
16 tmp = Path(tmp)
17 src, exe = tmp / "source.om", tmp / "compiler"
18 def run(s, b):
19 src.write_bytes(s)
20 exe.write_bytes(b)
21 return subprocess.run([str(tool), str(src), str(exe)],
22 capture_output=True, timeout=20)
23
24 for name, s, b in [
25 ("current", source, binary),
26 ("source-lines", b"fn a\n note fn ignored\nfn b\nfn c", binary),
27 ("binary-content", source, binary[:-1] + bytes([binary[-1] ^ 1])),
28 ]:
29 p = run(s, b)
30 digest = hashlib.sha256(b).hexdigest()
31 expected = "\t".join([
32 "seeded-" + digest[:12], "Generated from seeded source and executable",
33 str(s.count(b"\n")),
34 str(sum(line.startswith(b"fn ") for line in s.split(b"\n"))),
35 str((len(b) - 176) // 4), digest,
36 ]).encode() + b"\n"
37 assert p.returncode == 0 and p.stdout == expected, (name, p.returncode, p.stdout, expected)
38 passed += 1
39
40 for name, b in [
41 ("empty", b""), ("short", binary[:175]),
42 ("unaligned", binary[:-1]), ("magic", b"BAD!" + binary[4:]),
43 ]:
44 p = run(source, b)
45 assert p.returncode == 67 and not p.stdout, (name, p.returncode, p.stdout)
46 passed += 1
47 p = subprocess.run([str(tool)], capture_output=True, timeout=20)
48 assert p.returncode == 60 and not p.stdout
49 passed += 1
50
51print(f"SIZE_RECORD PASS cases={passed}")