100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth range given to batch 22), each with at least one independent contract-edge defect and plain public docs. Claude reviewed 100/100 USABLE against current digests; no ID or source overlap with main or batch 22. Difficulty is unmeasured. progress.md records the wrap-up: all Codex sessions and Qwen schedulers stopped for the user's rollout, Qwen results so far (57 HARD of 373), and what is left on each batch branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
420 lines
18 KiB
Python
420 lines
18 KiB
Python
"""Independent word/queue model; candidate and raw observer run only as children."""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import random
|
|
|
|
SEED = 2779096485
|
|
U32 = 4294967295
|
|
MIN = -(1 << 63)
|
|
MAX = (1 << 63) - 1
|
|
FILES = ['interlock.hpp', 'interlock.cpp', 'console.cpp', 'main.cpp']
|
|
VERBS = ['reset', 'load', 'begin', 'stage', 'capture', 'commit', 'abort',
|
|
'word', 'prepared', 'changed', 'operation', 'state']
|
|
ARITY = [0, 2, 1, 5, 1, 1, 1, 1, 2, 2, 1, 0]
|
|
DOMAINS = {1: [(0, 3), (0, U32)], 2: [(0, 7)],
|
|
3: [(0, 7), (0, 3), (0, 2), (0, U32), (0, U32)],
|
|
4: [(0, 7)], 5: [(0, 7)], 6: [(0, 7)], 7: [(0, 3)],
|
|
8: [(0, 7), (0, 3)], 9: [(0, 7), (0, 3)], 10: [(0, 7)]}
|
|
|
|
|
|
class Model:
|
|
def __init__(self):
|
|
self.words = [0] * 4
|
|
self.generation = 0
|
|
self.clear()
|
|
|
|
def clear(self):
|
|
self.owner = -1
|
|
self.phase = 0
|
|
self.queue = []
|
|
self.sample = [0] * 4
|
|
self.pending = [0] * 4
|
|
|
|
def call(self, code, a):
|
|
value, operation = SEED, [-9, -9, SEED, SEED]
|
|
status = self.apply(code, a)
|
|
if status == 0:
|
|
if code == 7:
|
|
value = self.words[a[0]]
|
|
if code == 8:
|
|
value = self.pending[a[1]]
|
|
if code == 9:
|
|
value = self.sample[a[1]] ^ self.pending[a[1]]
|
|
if code == 10:
|
|
operation = self.queue[a[0]][:]
|
|
return status, value, operation
|
|
|
|
def apply(self, code, a):
|
|
for value, (low, high) in zip(a, DOMAINS.get(code, [])):
|
|
if not low <= value <= high:
|
|
return 1
|
|
if code in (3, 4, 5, 6, 8, 9) and a[0] != self.owner:
|
|
return 3
|
|
if code in (3, 4) and self.phase != 1:
|
|
return 4
|
|
if code in (5, 8, 9) and self.phase != 2:
|
|
return 4
|
|
if code == 0:
|
|
self.words = [0] * 4
|
|
self.generation = 0
|
|
self.clear()
|
|
elif code == 1:
|
|
if self.owner != -1:
|
|
return 2
|
|
self.words[a[0]] = a[1]
|
|
elif code == 2:
|
|
if self.owner != -1:
|
|
return 2
|
|
self.clear()
|
|
self.owner = a[0]
|
|
self.phase = 1
|
|
elif code == 3:
|
|
if len(self.queue) == 8:
|
|
return 5
|
|
self.queue.append(a[1:5])
|
|
elif code == 4:
|
|
if not self.queue:
|
|
return 6
|
|
self.sample = self.words[:]
|
|
self.pending = self.words[:]
|
|
for reg, kind, mask, value in self.queue:
|
|
old = self.pending[reg]
|
|
if kind == 0:
|
|
self.pending[reg] = old | mask
|
|
elif kind == 1:
|
|
self.pending[reg] = old & (U32 ^ mask)
|
|
else:
|
|
self.pending[reg] = (old & (U32 ^ mask)) | (value & mask)
|
|
self.phase = 2
|
|
elif code == 5:
|
|
self.words = self.pending[:]
|
|
self.generation += 1
|
|
self.clear()
|
|
elif code == 6:
|
|
self.clear()
|
|
elif code == 10 and a[0] >= len(self.queue):
|
|
return 6
|
|
return 0
|
|
|
|
def state(self):
|
|
return [self.owner, self.phase, len(self.queue), self.generation]
|
|
|
|
def raw(self, code, a):
|
|
status, value, operation = self.call(code, a)
|
|
fields = [status, value] + operation + self.state()
|
|
for word in self.words:
|
|
fields.extend([0, word])
|
|
for index in range(8):
|
|
if index < len(self.queue):
|
|
fields.extend([0] + self.queue[index])
|
|
else:
|
|
fields.extend([6, -9, -9, SEED, SEED])
|
|
for reg in range(4):
|
|
for read in (8, 9):
|
|
read_status, read_value, _ = self.call(read, [self.owner, reg])
|
|
fields.extend([read_status, read_value])
|
|
return ' '.join(map(str, fields)) + '\n'
|
|
|
|
def cli(self, code, a):
|
|
status, value, operation = self.call(code, a)
|
|
if code == 11:
|
|
fields = ['T'] + self.state()
|
|
elif code in (7, 8, 9):
|
|
fields = [{7: 'W', 8: 'P', 9: 'D'}[code], status, value]
|
|
elif code == 10:
|
|
fields = ['O', status] + operation
|
|
else:
|
|
fields = ['S', status]
|
|
return ' '.join(map(str, fields)) + '\n'
|
|
|
|
|
|
def raw_scene(name, rows):
|
|
models = [Model(), Model()]
|
|
encoded, expected = [], []
|
|
for bank, code, args in rows:
|
|
padded = list(args) + [0] * (5 - len(args))
|
|
encoded.append(' '.join(map(str, [bank, code] + padded)) + '\n')
|
|
expected.append(models[bank].raw(code, padded))
|
|
return name, 'api', ''.join(encoded).encode(), ''.join(expected).encode()
|
|
|
|
|
|
def cli_expected(data):
|
|
models = [Model(), Model()]
|
|
output = []
|
|
lines = data.split(b'\n')
|
|
if lines[-1:] == [b'']:
|
|
lines.pop()
|
|
for index, line in enumerate(lines):
|
|
if index == 4096:
|
|
output.append('LIMIT\n')
|
|
break
|
|
tokens = re.split(b'[ \t\r]+', line.strip(b' \t\r'))
|
|
good = len(line) <= 256 and len(tokens) >= 2
|
|
if good:
|
|
try:
|
|
bank_token = tokens[0]
|
|
verb = tokens[1].decode('ascii')
|
|
code = VERBS.index(verb)
|
|
numbers = [bank_token] + tokens[2:]
|
|
good = len(tokens) == 2 + ARITY[code]
|
|
good = good and all(re.fullmatch(b'-?[0-9]+', n) for n in numbers)
|
|
parsed = [int(n) for n in numbers] if good else []
|
|
good = good and all(MIN <= n <= MAX for n in parsed)
|
|
good = good and parsed[0] in (0, 1)
|
|
except (ValueError, UnicodeDecodeError):
|
|
good = False
|
|
if not good:
|
|
output.append('ERR\n')
|
|
else:
|
|
output.append(models[parsed[0]].cli(code, parsed[1:]))
|
|
return ''.join(output).encode()
|
|
|
|
|
|
def cli_scene(name, data):
|
|
return name, 'cli', data, cli_expected(data)
|
|
|
|
|
|
def generate():
|
|
scenes = []
|
|
smoke = b'0 load 0 16\n0 begin 0\n0 stage 0 0 0 1 0\n0 capture 0\n0 begin 1\n0 state\n0 prepared 0 0\n0 commit 0\n0 word 0\n0 state\n'
|
|
scenes.append(cli_scene('smoke', smoke))
|
|
rows = []
|
|
def add(code, *args, bank=0):
|
|
rows.append((bank, code, list(args)))
|
|
add(11); add(11, bank=1)
|
|
for old, mask, value in [(0, 0, U32), (0xA0, 15, U32),
|
|
(0x80000000, 1, 0x40000001)]:
|
|
add(0); add(1, 0, old); add(2, 0)
|
|
add(3, 0, 0, 2, mask, value); add(10, 0); add(4, 0)
|
|
add(8, 0, 0); add(9, 0, 0); add(5, 0); add(7, 0)
|
|
# Every endpoint succeeds in a live transaction, and words are read directly.
|
|
for bank in (0, 1):
|
|
for actor in (0, 7):
|
|
for reg in (0, 3):
|
|
for kind in (0, 1, 2):
|
|
for mask in (0, U32):
|
|
for value in (0, U32):
|
|
add(0, bank=bank)
|
|
add(1, reg, U32, bank=bank)
|
|
add(1, reg, value, bank=bank)
|
|
add(7, reg, bank=bank)
|
|
add(2, actor, bank=bank)
|
|
add(3, actor, reg, kind, mask, value, bank=bank)
|
|
add(10, 0, bank=bank)
|
|
add(4, actor, bank=bank)
|
|
add(8, actor, reg, bank=bank)
|
|
add(9, actor, reg, bank=bank)
|
|
add(5, actor, bank=bank)
|
|
add(7, reg, bank=bank)
|
|
add(11, bank=bank)
|
|
add(0); add(1, 0, U32); add(2, 0)
|
|
add(3, 0, 0, 2, U32, 0); add(4, 0); add(8, 0, 0)
|
|
add(9, 0, 0); add(5, 0); add(7, 0)
|
|
# Same actor on two simultaneous live instances, different words and phases.
|
|
add(0); add(0, bank=1)
|
|
add(1, 0, 33); add(1, 0, 170, bank=1)
|
|
add(2, 7); add(2, 7, bank=1)
|
|
add(3, 7, 0, 0, 64, 0); add(3, 7, 0, 1, 2, 0, bank=1)
|
|
add(4, 7); add(8, 7, 0); add(7, 0, bank=1)
|
|
add(4, 7, bank=1); add(5, 7, bank=1); add(7, 0, bank=1)
|
|
add(8, 7, 0); add(5, 7); add(7, 0); add(11, bank=1)
|
|
scenes.append(raw_scene('api-ends', rows))
|
|
rows.clear()
|
|
# Full queue ordering, each phase, ownership, isolation and abort/reset recovery.
|
|
for actor in range(8):
|
|
add(0)
|
|
for reg in range(4): add(1, reg, 0xA5A50000 | (actor << 8) | reg)
|
|
add(2, actor); add(2, actor); add(2, (actor + 1) % 8)
|
|
add(1, 0, 0); add(1, 3, 0); add(4, actor); add(5, actor)
|
|
for i in range(8):
|
|
add(3, actor, i % 4, i % 3, [0, 1, U32, 0x80000000][i % 4],
|
|
[U32, 0, 0x80000001, 0x12345678][i % 4])
|
|
add(10, i)
|
|
for pos in range(5):
|
|
args = [actor, 0, 0, 1, 0]; args[pos] = MIN
|
|
add(3, *args)
|
|
add(3, (actor + 1) % 8, 0, 0, 1, 0)
|
|
add(3, actor, 0, 0, 1, 0)
|
|
add(4, actor)
|
|
for other in range(8):
|
|
add(2, other)
|
|
if other != actor:
|
|
add(4, other); add(5, other); add(6, other)
|
|
add(3, other, 0, 0, 1, 0)
|
|
add(8, other, 0); add(9, other, 3)
|
|
add(4, actor); add(3, actor, 0, 0, 1, 0)
|
|
for reg in range(4):
|
|
add(8, actor, reg); add(9, actor, reg); add(7, reg)
|
|
add(1, reg, 0)
|
|
add(5, actor); add(5, actor); add(6, actor)
|
|
for reg in range(4): add(7, reg)
|
|
add(2, actor); add(3, actor, 0, 2, 0, U32); add(6, actor)
|
|
add(2, actor); add(4, actor); add(3, actor, 3, 2, U32, 0)
|
|
add(4, actor); add(8, actor, 3); add(9, actor, 3); add(6, actor)
|
|
add(2, actor); add(3, actor, 3, 0, U32, U32); add(4, actor); add(0)
|
|
add(7, 3); add(10, 7); add(11)
|
|
scenes.append(raw_scene('api-phases', rows))
|
|
rows.clear()
|
|
for phase in (0, 1, 2):
|
|
add(0); add(1, 0, 1234567)
|
|
if phase:
|
|
add(2, 0); add(3, 0, 0, 2, 3, U32)
|
|
if phase == 2: add(4, 0)
|
|
for code, domains in DOMAINS.items():
|
|
base = {1: [0, 0], 2: [0], 3: [0, 0, 0, 1, 0],
|
|
4: [0], 5: [0], 6: [0], 7: [0], 8: [0, 0],
|
|
9: [0, 0], 10: [0]}[code]
|
|
for pos, (low, high) in enumerate(domains):
|
|
for bad in (MIN, MAX, low - 1, high + 1):
|
|
args = base[:]; args[pos] = bad
|
|
add(code, *args)
|
|
# All domains invalid together; RANGE before owner/phase/capacity.
|
|
add(code, *([MIN] * len(domains)))
|
|
for code, args in [(3, [1, 0, 0, 1, 0]), (4, [1]), (5, [1]),
|
|
(6, [1]), (8, [1, 0]), (9, [1, 0])]:
|
|
add(code, *args)
|
|
for i in range(8): add(10, i)
|
|
add(11); add(0)
|
|
scenes.append(raw_scene('api-domain', rows))
|
|
rows.clear()
|
|
rng = random.Random(0xD3C081)
|
|
for i in range(130):
|
|
bank = i % 2
|
|
actor = rng.randrange(8)
|
|
add(0, bank=bank)
|
|
for reg in range(4): add(1, reg, rng.getrandbits(32), bank=bank)
|
|
add(2, actor, bank=bank)
|
|
for j in range(1 + rng.randrange(8)):
|
|
add(3, actor, rng.randrange(4), rng.randrange(3),
|
|
rng.getrandbits(32), rng.getrandbits(32), bank=bank)
|
|
add(4, actor, bank=bank)
|
|
add(2, (actor + 3) % 8, bank=bank)
|
|
for reg in range(4):
|
|
add(8, actor, reg, bank=bank); add(9, actor, reg, bank=bank)
|
|
add(5 if i % 3 else 6, actor, bank=bank)
|
|
for reg in range(4): add(7, reg, bank=bank)
|
|
scenes.append(raw_scene('api-mixed', rows))
|
|
# CLI success dispatch includes all verbs, endpoints, all instance/phase effects.
|
|
lines = []
|
|
def line(bank, verb, *args):
|
|
lines.append(' '.join(map(str, [bank, verb] + list(args))) + '\n')
|
|
for bank in (0, 1):
|
|
line(bank, 'reset')
|
|
for actor in (0, 7):
|
|
for reg in (0, 3):
|
|
line(bank, 'load', reg, U32); line(bank, 'load', reg, 0)
|
|
line(bank, 'word', reg); line(bank, 'begin', actor)
|
|
for i in range(8):
|
|
line(bank, 'stage', actor, reg, i % 3, [0, U32][i % 2], [U32, 0][i % 2])
|
|
line(bank, 'operation', 0); line(bank, 'operation', 7)
|
|
line(bank, 'capture', actor); line(bank, 'prepared', actor, reg)
|
|
line(bank, 'changed', actor, reg); line(bank, 'state')
|
|
line(bank, 'commit', actor); line(bank, 'word', reg)
|
|
line(bank, 'begin', actor); line(bank, 'abort', actor)
|
|
lines.extend(['\t-0\tload\t0003\t00042\r\n', '0 word 3\n', '1 state'])
|
|
scenes.append(cli_scene('cli-dispatch', ''.join(lines).encode()))
|
|
prefix = ['0 load 0 77\n', '1 load 3 99\n', '0 begin 0\n',
|
|
'0 stage 0 0 2 1 0\n', '0 capture 0\n']
|
|
probes = ['0 state\n', '1 state\n', '0 operation 0\n']
|
|
probes += ['%s word %s\n' % (bank, reg) for bank in (0, 1) for reg in range(4)]
|
|
probes += ['0 %s 0 %s\n' % (verb, reg) for verb in ('prepared', 'changed') for reg in range(4)]
|
|
bad_lines = []
|
|
for code, verb in enumerate(VERBS):
|
|
args = [0] * ARITY[code]
|
|
good = ['0', verb] + list(map(str, args))
|
|
bad_lines.append(' '.join(good[:-1]) + '\n')
|
|
bad_lines.append(' '.join(good + ['0']) + '\n')
|
|
for pos in range(ARITY[code]):
|
|
for bad in ('x', '+1', '1x', '9223372036854775808', '-9223372036854775809'):
|
|
tokens = good[:]; tokens[pos + 2] = bad
|
|
bad_lines.append(' '.join(tokens) + '\n')
|
|
for bad in ('-1', '2', str(MIN), str(MAX), 'x', '+0'):
|
|
bad_lines.append(' '.join([bad] + good[1:]) + '\n')
|
|
bad_lines += ['0 state' + ' ' * 249 + '\n', '\n', ' \t\r\n',
|
|
'0 unknown 0\n', '0 STATE\n', '0 state ' + ' ' * 249 + '\n',
|
|
'0 ' + 'x' * 254 + '\n', '0 word \x00\n', '0 word \xff\n']
|
|
lines = prefix[:]
|
|
for bad in bad_lines:
|
|
lines.append(bad); lines.extend(probes)
|
|
lines += ['0 commit 0\n', '0 word 0\n']
|
|
scenes.append(cli_scene('cli-malformed', ''.join(lines).encode('latin1')))
|
|
lines = prefix[:]
|
|
for code, domains in DOMAINS.items():
|
|
for pos, (low, high) in enumerate(domains):
|
|
for bad in (MIN, MAX, low - 1, high + 1):
|
|
args = [0] * len(domains); args[pos] = bad
|
|
lines.append(' '.join(map(str, [0, VERBS[code]] + args)) + '\n')
|
|
lines.extend(probes)
|
|
lines += ['0 commit 0\n', '0 word 0\n']
|
|
scenes.append(cli_scene('cli-domain', ''.join(lines).encode()))
|
|
scenes.append(cli_scene('cli-empty', b''))
|
|
scenes.append(cli_scene('cli-4096', b'0 state\n' * 4096))
|
|
scenes.append(cli_scene('cli-limit', b'1 load 0 29\n' + b'1 word 0\n' * 4095 + b'1 reset\n0 word 0\n'))
|
|
return scenes
|
|
|
|
|
|
def main():
|
|
scenes = generate()
|
|
# All trusted filesystem access is complete before the first compiler starts.
|
|
source = Path(sys.argv[1])
|
|
sources = {name: (source / name).read_bytes() for name in FILES}
|
|
observer = Path(__file__).with_name('observer.cc').read_bytes()
|
|
scratch = Path(tempfile.mkdtemp(prefix='maskwrite-', dir=Path.cwd()))
|
|
for name, content in sources.items():
|
|
(scratch / name).write_bytes(content)
|
|
(scratch / 'observer.cc').write_bytes(observer)
|
|
cli = str(scratch / 'cli')
|
|
api = str(scratch / 'api')
|
|
compiles = [
|
|
['g++', '-std=c++17', '-O2', '-I', str(scratch), str(scratch / 'interlock.cpp'),
|
|
str(scratch / 'console.cpp'), str(scratch / 'main.cpp'), '-o', cli],
|
|
['g++', '-std=c++17', '-O2', '-I', str(scratch), str(scratch / 'interlock.cpp'),
|
|
str(scratch / 'console.cpp'), str(scratch / 'observer.cc'), '-o', api]]
|
|
evidence = {'build': [], 'scene': [], 'reason': 'all required observations match'}
|
|
ok = True
|
|
try:
|
|
for argv in compiles:
|
|
child = subprocess.Popen(argv, cwd=str(scratch), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
out, err = child.communicate(timeout=35)
|
|
evidence['build'].append([child.pid, child.returncode, len(out), len(err)])
|
|
if child.returncode:
|
|
evidence['reason'] = 'build rejected: ' + err.decode(errors='replace')[-500:]
|
|
ok = False
|
|
break
|
|
if ok:
|
|
for name, kind, data, expected in scenes:
|
|
child = subprocess.Popen([api if kind == 'api' else cli], cwd=str(scratch),
|
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
out, err = child.communicate(data, timeout=12)
|
|
evidence['scene'].append([name, child.pid, child.returncode, len(out), len(err),
|
|
hashlib.sha256(out).hexdigest()])
|
|
if child.returncode != 0:
|
|
evidence['reason'] = name + ': exit=' + str(child.returncode) + ' stderr=' + repr(err[:100])
|
|
elif err:
|
|
evidence['reason'] = name + ': stderr must be empty: ' + repr(err[:100])
|
|
elif out != expected:
|
|
first = next((i for i, (a, b) in enumerate(zip(out, expected)) if a != b), min(len(out), len(expected)))
|
|
evidence['reason'] = name + ': stdout bytes differ at ' + str(first) + '; got=' + repr(out[first:first+90]) + '; want=' + repr(expected[first:first+90])
|
|
else:
|
|
continue
|
|
ok = False
|
|
break
|
|
except subprocess.TimeoutExpired:
|
|
child.kill()
|
|
out, err = child.communicate()
|
|
evidence['reason'] = 'child timeout pid=' + str(child.pid)
|
|
ok = False
|
|
print(json.dumps(evidence, separators=(',', ':')), file=sys.stderr)
|
|
print('PASS' if ok else 'FAIL')
|
|
return 0 if ok else 1
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|