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>
232 lines
11 KiB
Python
232 lines
11 KiB
Python
"""Independent contract interpreter; candidate execution is subprocess-only."""
|
|
from pathlib import Path
|
|
import json
|
|
import random
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
FIELDS = 'id generation state oneshot priority mode ready running masked pending ticket token received hard none handled wakes masked_arrivals begun ended replays'.split()
|
|
COUNTS = 'ready running pending masked received hard none handled wakes masked_arrivals begun ended replays'.split()
|
|
|
|
class Oracle:
|
|
def __init__(self):
|
|
self.lines = {}
|
|
self.tokens = {}
|
|
self.step = 0
|
|
self.ticket = 1
|
|
self.token = 1
|
|
|
|
def ready(self):
|
|
return sorted((i for i,v in self.lines.items() if v['ready']), key=lambda i:(self.lines[i]['priority'],self.lines[i]['ticket']))
|
|
|
|
def queue(self,v):
|
|
if v['ready'] or v['running']:
|
|
v['pending'] = 1
|
|
else:
|
|
v['ready'] = 1
|
|
v['ticket'] = self.ticket
|
|
self.ticket += 1
|
|
v['masked'] = v['oneshot']
|
|
|
|
def top(self,v):
|
|
v['hard'] += 1
|
|
v[['none','handled','wakes'][v['mode']]] += 1
|
|
if v['mode'] == 2:
|
|
self.queue(v)
|
|
|
|
def close(self,v):
|
|
if v['state'] == 2 and not any(v[k] for k in ('ready','running','pending')):
|
|
v['state'] = 3
|
|
v['masked'] = v['ticket'] = 0
|
|
self.tokens[v['token']] = 1
|
|
|
|
def summary(self):
|
|
values=list(self.lines.values())
|
|
return [len(values)]+[sum(v['state']==s for v in values) for s in (1,2,3)]+[sum(v[k] for v in values) for k in COUNTS]+[sum(not x for x in self.tokens.values()),sum(self.tokens.values())]
|
|
|
|
def view(self,v=None):
|
|
return [-1]+[0]*20 if v is None else [v[k] for k in FIELDS]
|
|
|
|
@staticmethod
|
|
def csv(items):
|
|
return ','.join(map(str,items))
|
|
|
|
def render(self):
|
|
out=f'S {self.step} {self.ticket} {self.token}\n'
|
|
for i in sorted(self.lines):
|
|
out+='L '+self.csv(self.view(self.lines[i]))+'\n'
|
|
out+='Q'+''.join(' '+str(i) for i in self.ready())+'\n'
|
|
out+='T'+''.join(f' {i}:{done}' for i,done in sorted(self.tokens.items()))+'\n'
|
|
out+='A '+self.csv(self.summary())+'\nI 1\n'
|
|
return out
|
|
|
|
def command(self,text):
|
|
words=text.split(); op=words[0]; args=list(map(int,words[1:])); extra=''
|
|
code,value=0,0
|
|
i=args[0] if args else 0
|
|
v=self.lines.get(i)
|
|
def access(closing=False):
|
|
if not 0<=i<8: return 1
|
|
if v is None: return 3
|
|
if v['state']==3: return 4
|
|
if v['state']==2 and not closing: return 5
|
|
return 0
|
|
if op=='open':
|
|
i,oneshot,priority,mode=args
|
|
if not(0<=i<8 and 0<=oneshot<=1 and 0<=priority<=7 and 0<=mode<=2): code=1
|
|
elif v and v['state']!=3: code=2
|
|
else:
|
|
generation=1 if v is None else v['generation']+1
|
|
v={k:0 for k in FIELDS};v.update(id=i,generation=generation,state=1,oneshot=oneshot,priority=priority,mode=mode)
|
|
self.lines[i]=v;self.step+=1;value=generation
|
|
elif op in ('mode','arrive'):
|
|
n=args[1]
|
|
if not 0<=i<8 or not 0<=n<=(2 if op=='mode' else 32): code=1
|
|
else: code=access()
|
|
if not code:
|
|
if op=='mode': v['mode']=n
|
|
else:
|
|
value=n
|
|
for _ in range(n):
|
|
v['received']+=1
|
|
if v['masked']:
|
|
v['masked_arrivals']+=1;v['pending']=1
|
|
else: self.top(v)
|
|
self.step+=1
|
|
elif op in ('begin','end','next'):
|
|
if op=='next':
|
|
ready=self.ready()
|
|
if not ready: code=8
|
|
else: i=ready[0];v=self.lines[i]
|
|
if not code: code=access(True)
|
|
if not code:
|
|
if op in ('begin','next'):
|
|
if v['running']: code=6
|
|
elif not v['ready']: code=7
|
|
else:
|
|
v['ready']=v['ticket']=0;v['running']=1;v['begun']+=1
|
|
else:
|
|
if not v['running']: code=7
|
|
else:
|
|
v['running']=0;v['ended']+=1;v['masked']=0
|
|
if v['pending']:
|
|
v['pending']=0;v['replays']+=1;self.top(v)
|
|
self.close(v)
|
|
if not code: self.step+=1;value=i
|
|
elif op=='free':
|
|
if not 0<=i<8: code=1
|
|
elif v is None: code=3
|
|
elif v['state']!=1: value=v['token']
|
|
else:
|
|
value=self.token;self.token+=1;self.tokens[value]=0
|
|
v['token']=value;v['state']=2;self.step+=1;self.close(v)
|
|
elif op=='poll':
|
|
if not 1<=i<=10000: code=1
|
|
elif i not in self.tokens: code=9
|
|
else: value=self.tokens[i]
|
|
elif op=='get':
|
|
if not 0<=i<8: code=1
|
|
elif v is None: code=3
|
|
extra='V '+self.csv(self.view(v if not code else None))+'\n'
|
|
elif op=='summary': extra='U '+self.csv(self.summary())+'\n'
|
|
elif op=='audit': value=1
|
|
return f'R {code} {value}\n'+extra+self.render()
|
|
|
|
|
|
def cases():
|
|
fixed=[
|
|
('empty','show\nsummary\naudit\nnext\nget 0\nbegin 0\nend 0\nfree 0\npoll 1\n'),
|
|
('smoke-free','open 3 1 4 2\narrive 3 1\nbegin 3\nfree 3\npoll 1\nend 3\npoll 1\n'),
|
|
('oneshot-exact','open 0 1 0 2\narrive 0 1\narrive 0 32\nget 0\nbegin 0\narrive 0 2\nend 0\nget 0\nbegin 0\nend 0\nnext\nsummary\n'),
|
|
('close-pending','open 7 1 7 2\narrive 7 32\nfree 7\nfree 7\npoll 1\narrive 7 0\nmode 7 0\nnext\nend 7\npoll 1\nnext\nend 7\npoll 1\nfree 7\n'),
|
|
('plain-coalesce','open 4 0 3 2\narrive 4 32\nbegin 4\narrive 4 32\nbegin 4\nend 4\nbegin 4\nend 4\nnext\naudit\n'),
|
|
('mode-replay','open 2 1 5 2\narrive 2 4\nmode 2 1\nbegin 2\nend 2\nmode 2 2\narrive 2 2\nbegin 2\nmode 2 0\nend 2\nfree 2\npoll 1\n'),
|
|
('top-results','open 0 1 0 0\narrive 0 32\nmode 0 1\narrive 0 32\nmode 0 2\narrive 0 0\narrive 0 1\nnext\nend 0\nfree 0\n'),
|
|
('fifo-priority','open 0 1 5 2\nopen 1 1 2 2\nopen 2 0 2 2\narrive 0 1\narrive 2 1\narrive 1 1\narrive 2 1\nnext\nend 2\nnext\nnext\nnext\nend 0\nend 1\nend 2\n'),
|
|
('generation-tokens','open 1 1 0 0\nfree 1\npoll 1\nfree 1\nopen 1 0 7 2\npoll 1\narrive 1 1\nfree 1\nget 1\nnext\nend 1\npoll 2\nopen 1 1 3 1\nfree 1\npoll 1\npoll 2\npoll 3\nsummary\n'),
|
|
]
|
|
bounds=['show','open 2 1 4 2','arrive 2 1','begin 2','free 2']
|
|
for i in [-9223372036854775808,-1,0,2,7,8,9223372036854775807]:
|
|
for op in ('begin','end','free','get'): bounds.append(f'{op} {i}')
|
|
for n in (-1,0,1,2,7,8,32,33,9223372036854775807):
|
|
bounds += [f'arrive {i} {n}',f'mode {i} {n}',f'open {i} {n} {n} {n}']
|
|
for token in (-9223372036854775808,-1,0,1,2,10000,10001,9223372036854775807): bounds.append(f'poll {token}')
|
|
fixed.append(('range-precedence','\n'.join(bounds)+'\n'))
|
|
isolated=[]
|
|
for oneshot in (0,1):
|
|
for priority in (0,7):
|
|
for mode in (0,1,2):
|
|
isolated += [f'open 6 {oneshot} {priority} {mode}','arrive 6 0','arrive 6 32','begin 6','end 6','begin 6','end 6','free 6','poll 1']
|
|
fixed.append(('all-configurations','\n'.join(isolated)+'\n'))
|
|
for seed in (17031,20817,618033,900001):
|
|
rng=random.Random(seed)
|
|
commands=[f'open {i} {rng.randrange(2)} {rng.randrange(8)} {rng.randrange(3)}' for i in range(8)]
|
|
for _ in range(260):
|
|
op=rng.choice(['open','mode','arrive','arrive','begin','end','next','free','poll','get','summary','audit','show'])
|
|
i=rng.randrange(-1,9)
|
|
if op=='open': text=f'{op} {i} {rng.randrange(-1,3)} {rng.randrange(-1,9)} {rng.randrange(-1,4)}'
|
|
elif op=='mode': text=f'{op} {i} {rng.randrange(-1,4)}'
|
|
elif op=='arrive': text=f'{op} {i} {rng.choice([-1,0,1,2,5,32,33])}'
|
|
elif op in ('begin','end','free','get'): text=f'{op} {i}'
|
|
elif op=='poll': text=f'{op} {rng.randrange(0,15)}'
|
|
else: text=op
|
|
commands.append(text)
|
|
fixed.append((f'random-{seed}','\n'.join(commands)+'\n'))
|
|
# Guaranteed lifecycle-heavy valid transitions, including reopen and replay under closing.
|
|
rng=random.Random(771910)
|
|
commands=[]
|
|
token=0
|
|
for cycle in range(25):
|
|
i=cycle%8;oneshot=rng.randrange(2)
|
|
commands += [f'open {i} {oneshot} {rng.randrange(8)} 2',f'arrive {i} {rng.randrange(2,33)}',f'begin {i}',f'arrive {i} {rng.randrange(1,33)}',f'free {i}']
|
|
token+=1
|
|
commands += [f'poll {token}',f'end {i}',f'begin {i}',f'end {i}',f'poll {token}',f'get {i}']
|
|
fixed.append(('drain-stress','\n'.join(commands)+'\n'))
|
|
return fixed
|
|
|
|
|
|
def main():
|
|
root=Path(__file__).resolve().parent
|
|
candidate=Path(sys.argv[1])
|
|
tests=[]
|
|
for name,data in cases():
|
|
oracle=Oracle()
|
|
expected=''.join(oracle.command(line) for line in data.splitlines()).encode('ascii')
|
|
tests.append((name,data.encode('ascii'),expected))
|
|
scratch=Path(tempfile.mkdtemp(prefix='irq-cycle-',dir=Path.cwd()))
|
|
sources=['irq_registry.cpp','irq_dispatch.cpp','irq_query.cpp','irq_internal.hpp']
|
|
for name in sources:
|
|
shutil.copyfile(candidate/name,scratch/name)
|
|
shutil.copyfile(root/'api.hpp',scratch/'irq_cycle.hpp')
|
|
shutil.copyfile(root/'observer.cc',scratch/'observer.cpp')
|
|
argv=['g++','-std=c++17','-O2','-Wall','-Wextra','-I',str(scratch)]+[str(scratch/x) for x in sources if x.endswith('.cpp')]+[str(scratch/'observer.cpp'),'-o',str(scratch/'observe')]
|
|
# All trusted filesystem access is now complete. Compilation and runs use pipes only.
|
|
build=subprocess.run(argv,capture_output=True,timeout=35)
|
|
if build.returncode:
|
|
sys.stderr.write(json.dumps({'build_rc':build.returncode,'stderr':build.stderr.decode('utf8','replace')[-1800:]})+'\n')
|
|
print('build failed');return 1
|
|
observations=[]
|
|
for name,data,expected in tests:
|
|
try:
|
|
result=subprocess.run([str(scratch/'observe')],input=data,capture_output=True,timeout=8,cwd=scratch)
|
|
ok=result.returncode==0 and result.stdout==expected
|
|
item={'case':name,'run_rc':result.returncode,'match':ok}
|
|
if result.stderr: item['stderr']=result.stderr.decode('utf8','replace')[-300:]
|
|
if not ok:
|
|
a=result.stdout;b=expected
|
|
at=next((i for i,(x,y) in enumerate(zip(a,b)) if x!=y),min(len(a),len(b)))
|
|
item.update(byte=at,observed=a[at:at+65].decode('ascii','replace'),expected=b[at:at+65].decode('ascii','replace'))
|
|
observations.append(item)
|
|
except subprocess.TimeoutExpired:
|
|
observations.append({'case':name,'run_rc':'timeout','match':False})
|
|
sys.stderr.write(json.dumps({'build_rc':0,'cases':observations},separators=(',',':'))+'\n')
|
|
failures=[x for x in observations if not x['match']]
|
|
if failures:
|
|
print('behavior rejected: '+','.join(x['case'] for x in failures));return 1
|
|
print('PASS');return 0
|
|
|
|
if __name__=='__main__':
|
|
sys.exit(main())
|