Batch 21 (20261027-A-bos-redo-21) rebuilt 40 of the 53 rejected Bos-qiao environments: hidden assertions that ran inside the candidate's process now run in a trusted parent that reads observations from a low-UID worker; gold bytes are unchanged. 9 were excluded for scope (ROS2, oversize, security core), 3 are blocked because the source requires an exec bit the platform does not freeze, 1 lacks requests/bs4 in trace6. Batch 18 (20261026-C-hwe-codegen-18) adds its last 34 of 134 tasks; the first 100 landed in 2f32624d. Claude reviewed 74/74 USABLE against current digests, canonical families, no ID or source overlap with main, plain public docs. Only the new task directories are taken; the stale pre-batch-20 copies of concur-release-capsule and resource-temp-link on the batch 21 branch and both branches' progress notes stay as main has them. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
491 lines
18 KiB
Python
491 lines
18 KiB
Python
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import random
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
OBSERVER = r'''
|
|
#include "adc.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
static void dump(const Adc *a)
|
|
{
|
|
AdcStatus s={-201,-202,-203,-204,-205,-206,-207};
|
|
int c;
|
|
adc_status(a, &s);
|
|
printf(" %d %d %d %d %d %d %d", s.vref, s.mask, s.rounds, s.active,
|
|
s.next_channel, s.completed_rounds, s.frames);
|
|
for (c = 0; c < 8; ++c) {
|
|
AdcReading r = {-101,-102,-103,-104,-105,-106};
|
|
int code = adc_read(a,c,&r);
|
|
printf(" %d %d %d %d %d %d %d",code,r.count,r.sum,r.minimum,r.maximum,r.last,r.microvolts);
|
|
}
|
|
}
|
|
|
|
static void cli(const char *hex, Adc *state)
|
|
{
|
|
FILE *in = tmpfile();
|
|
FILE *out = tmpfile();
|
|
size_t i;
|
|
long length;
|
|
int byte;
|
|
int result;
|
|
if (!in || !out) exit(91);
|
|
if (strcmp(hex,"-") != 0) {
|
|
for (i=0; hex[i]; i+=2) {
|
|
unsigned value;
|
|
if (sscanf(hex+i,"%2x",&value) != 1) exit(92);
|
|
fputc((int)value,in);
|
|
}
|
|
}
|
|
rewind(in);
|
|
result = adc_run_cli(in,out,state);
|
|
fflush(out);
|
|
length = ftell(out);
|
|
rewind(out);
|
|
printf(" %d %ld ",result,length);
|
|
if (!length) putchar('-');
|
|
while ((byte=fgetc(out)) != EOF) printf("%02x",(unsigned char)byte);
|
|
fclose(in);
|
|
fclose(out);
|
|
dump(state);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
Adc a[2];
|
|
Adc cli_state;
|
|
char op;
|
|
int id,x,y,z;
|
|
char hex[150001];
|
|
adc_reset(&a[0]);
|
|
adc_reset(&a[1]);
|
|
while (scanf(" %c", &op) == 1) {
|
|
printf("%c",op);
|
|
if (op == 'L') {
|
|
if (scanf("%150000s",hex)!=1) return 93;
|
|
cli(hex,&cli_state);
|
|
} else if (op == 'E') {
|
|
AdcFrame f = {-11,-12,-13};
|
|
int code;
|
|
if (scanf("%d",&x)!=1) return 93;
|
|
code=adc_encode(x,&f);
|
|
printf(" %d %d %d %d",code,f.b0,f.b1,f.b2);
|
|
} else if (op == 'D') {
|
|
int value=-17;
|
|
int code;
|
|
if (scanf("%d%d%d",&x,&y,&z)!=3) return 93;
|
|
code=adc_decode(x,y,z,&value);
|
|
printf(" %d %d",code,value);
|
|
} else {
|
|
int code=0;
|
|
if (scanf("%d",&id)!=1 || id<0 || id>1) return 93;
|
|
if (op=='R') adc_reset(&a[id]);
|
|
if (op=='C') {
|
|
if (scanf("%d%d%d",&x,&y,&z)!=3) return 93;
|
|
code=adc_config(&a[id],x,y,z);
|
|
}
|
|
if (op=='S') code=adc_start(&a[id]);
|
|
if (op=='F') {
|
|
if (scanf("%d%d%d",&x,&y,&z)!=3) return 93;
|
|
code=adc_feed(&a[id],x,y,z);
|
|
}
|
|
if (op=='A') code=adc_abort(&a[id]);
|
|
if (op=='Z') code=adc_clear(&a[id]);
|
|
if (op=='T') {
|
|
AdcFrame f={-11,-12,-13};
|
|
code=adc_tx(&a[id],&f);
|
|
printf(" %d %d %d %d",code,f.b0,f.b1,f.b2);
|
|
} else if (op=='G') {
|
|
AdcReading r={-101,-102,-103,-104,-105,-106};
|
|
if (scanf("%d",&x)!=1) return 93;
|
|
code=adc_read(&a[id],x,&r);
|
|
printf(" %d %d %d %d %d %d %d",code,r.count,r.sum,r.minimum,r.maximum,r.last,r.microvolts);
|
|
} else if (op=='O') {
|
|
AdcStatus s={-201,-202,-203,-204,-205,-206,-207};
|
|
adc_status(&a[id],&s);
|
|
printf(" %d %d %d %d %d %d %d",s.vref,s.mask,s.rounds,s.active,
|
|
s.next_channel,s.completed_rounds,s.frames);
|
|
} else printf(" %d",code);
|
|
}
|
|
dump(&a[0]);
|
|
dump(&a[1]);
|
|
putchar('\n');
|
|
}
|
|
return 0;
|
|
}
|
|
'''
|
|
|
|
SENTINEL = [-101,-102,-103,-104,-105,-106]
|
|
I32MIN = -2147483648
|
|
I32MAX = 2147483647
|
|
CODES = {0:'OK',1:'RANGE',2:'BUSY',3:'IDLE',4:'EMPTY'}
|
|
CLI_COVERAGE = {}
|
|
CLI_ERROR_CONTEXT = {}
|
|
SMOKE = b'config 3300000 5 2\nstart\nfeed 0 0 0\nfeed 0 0 0\nfeed 0 3 255\nfeed 0 3 255\nread 0\nread 2\nstate\n'
|
|
|
|
class Model:
|
|
def __init__(self):
|
|
self.reset()
|
|
|
|
def reset(self):
|
|
self.vref,self.mask,self.rounds = 3300000,255,1
|
|
self.active = 0
|
|
self.samples = []
|
|
|
|
def width(self):
|
|
return bin(self.mask).count('1')
|
|
|
|
def selected(self):
|
|
return [c for c in range(8) if self.mask & (1 << c)]
|
|
|
|
def state(self):
|
|
return [self.vref,self.mask,self.rounds,self.active,
|
|
self.selected()[len(self.samples)%self.width()] if self.active else -1,
|
|
len(self.samples)//self.width(),len(self.samples)]
|
|
|
|
def reading(self,ch):
|
|
if not 0 <= ch <= 7:
|
|
return [1]+SENTINEL
|
|
selected=self.selected()
|
|
values=[v for i,v in enumerate(self.samples) if selected[i%len(selected)]==ch]
|
|
if not values:
|
|
return [4]+SENTINEL
|
|
return [0,len(values),sum(values),min(values),max(values),values[-1],
|
|
sum(values)*self.vref//(len(values)*1023)]
|
|
|
|
def command(self,op,args):
|
|
if op=='R':
|
|
self.reset()
|
|
return [0]
|
|
if op=='O':
|
|
return self.state()
|
|
if op=='C':
|
|
v,m,r=args
|
|
if not 1<=v<=5000000 or not 1<=m<=255 or not 1<=r<=32:
|
|
return [1]
|
|
if self.active:
|
|
return [2]
|
|
self.vref,self.mask,self.rounds=v,m,r
|
|
self.samples=[]
|
|
return [0]
|
|
if op=='S':
|
|
if self.active:
|
|
return [2]
|
|
self.samples=[]
|
|
self.active=1
|
|
return [0]
|
|
if op=='T':
|
|
return [0,1,128+16*self.state()[4],0] if self.active else [3,-11,-12,-13]
|
|
if op=='F':
|
|
if any(not 0<=v<=255 for v in args):
|
|
return [1]
|
|
if not self.active:
|
|
return [3]
|
|
self.samples.append((args[1]%4)*256+args[2])
|
|
if len(self.samples)==self.width()*self.rounds:
|
|
self.active=0
|
|
return [0]
|
|
if op=='A':
|
|
if not self.active:
|
|
return [3]
|
|
self.active=0
|
|
return [0]
|
|
if op=='G':
|
|
return self.reading(args[0])
|
|
if op=='Z':
|
|
if self.active:
|
|
return [2]
|
|
self.samples=[]
|
|
return [0]
|
|
raise AssertionError(op)
|
|
|
|
def dump(self):
|
|
return self.state()+sum((self.reading(c) for c in range(8)),[])
|
|
|
|
|
|
def run_cli(data):
|
|
model=Model()
|
|
result=[]
|
|
commands={'config':('C',3),'start':('S',0),'tx':('T',0),'feed':('F',3),
|
|
'read':('G',1),'state':('O',0),'abort':('A',0),'clear':('Z',0)}
|
|
lines=data.split(b'\n')
|
|
if lines[-1:]==[b'']:
|
|
lines.pop()
|
|
for n,line in enumerate(lines):
|
|
if n==128:
|
|
result.append('ERR LIMIT\n')
|
|
break
|
|
words=line.replace(b'\t',b' ').split()
|
|
valid=len(line)<=255 and all(b==9 or 32<=b<=126 for b in line)
|
|
verb=words[0].decode('ascii',errors='replace') if words else ''
|
|
spec=commands.get(verb)
|
|
args=[]
|
|
valid=valid and spec is not None and len(words)==spec[1]+1
|
|
if valid:
|
|
for token in words[1:]:
|
|
digits=token[1:] if token.startswith(b'-') else token
|
|
if not digits or any(not 48<=x<=57 for x in digits):
|
|
valid=False
|
|
break
|
|
value=int(token)
|
|
if not I32MIN<=value<=I32MAX:
|
|
valid=False
|
|
break
|
|
args.append(value)
|
|
if not valid:
|
|
result.append('ERR SYNTAX\n')
|
|
CLI_COVERAGE.setdefault('syntax',set()).add(verb)
|
|
continue
|
|
op=spec[0]
|
|
had_nonzero=any(model.samples)
|
|
raw=model.command(op,args)
|
|
code=0 if op=='O' else raw[0]
|
|
CLI_COVERAGE.setdefault(verb,set()).add(CODES[code])
|
|
if code and had_nonzero:
|
|
CLI_ERROR_CONTEXT.setdefault(verb,set()).add(CODES[code])
|
|
if code:
|
|
text='ERR '+CODES[code]
|
|
elif op=='T':
|
|
text='TX '+' '.join(map(str,raw[1:]))
|
|
elif op=='G':
|
|
text='READ '+' '.join(map(str,raw[1:]))
|
|
elif op=='O':
|
|
text='STATE '+' '.join(map(str,raw))
|
|
else:
|
|
text='OK'
|
|
result.append(text+'\n')
|
|
return len(result),''.join(result).encode(),model
|
|
|
|
|
|
def observe(operations):
|
|
objects=[Model(),Model()]
|
|
input_lines=[]
|
|
output=[]
|
|
for op,args in operations:
|
|
if op=='L':
|
|
data=args[0]
|
|
count,body,final=run_cli(data)
|
|
input_lines.append('L '+(data.hex() or '-'))
|
|
prefix='L '+str(count)+' '+str(len(body))+' '+(body.hex() or '-')+' '+' '.join(map(str,final.dump()))
|
|
elif op=='E':
|
|
ch=args[0]
|
|
raw=[0,1,128+16*ch,0] if 0<=ch<=7 else [1,-11,-12,-13]
|
|
prefix='E '+' '.join(map(str,raw))
|
|
input_lines.append('E '+' '.join(map(str,args)))
|
|
elif op=='D':
|
|
raw=[1,-17] if any(not 0<=v<=255 for v in args) else [0,(args[1]%4)*256+args[2]]
|
|
prefix='D '+' '.join(map(str,raw))
|
|
input_lines.append('D '+' '.join(map(str,args)))
|
|
else:
|
|
raw=objects[args[0]].command(op,args[1:])
|
|
prefix=op+' '+' '.join(map(str,raw))
|
|
input_lines.append(op+' '+' '.join(map(str,args)))
|
|
output.append(prefix+' '+' '.join(map(str,objects[0].dump()+objects[1].dump()))+'\n')
|
|
return ('\n'.join(input_lines)+'\n').encode(),''.join(output).encode()
|
|
|
|
|
|
def scenes():
|
|
smoke=SMOKE
|
|
ops=[]
|
|
def add(op,*args):
|
|
ops.append((op,args))
|
|
for ch in [0,7,1,6,-1,8,I32MIN,I32MAX]:
|
|
add('E',ch)
|
|
for b1 in [0,3,4,252,255,128,131]:
|
|
for b0,b2 in [(0,0),(255,255)]:
|
|
add('D',b0,b1,b2)
|
|
for position in range(3):
|
|
for invalid in [-1,256,I32MIN,I32MAX]:
|
|
args=[255,255,255]
|
|
args[position]=invalid
|
|
add('D',*args)
|
|
for v,m,r in [(1,1,1),(5000000,255,32),(1,255,32),(5000000,1,1),(3300000,129,2)]:
|
|
add('C',0,v,m,r)
|
|
add('S',0)
|
|
for i in range(bin(m).count('1')*r):
|
|
add('T',0)
|
|
add('T',0)
|
|
add('F',0,255,252 if i%2==0 else 255,0 if i%2==0 else 255)
|
|
add('O',0)
|
|
for ch in [0,7]:
|
|
add('G',0,ch)
|
|
add('T',0)
|
|
add('F',0,0,0,0)
|
|
add('A',0)
|
|
for obj in range(2):
|
|
add('C',obj,4999999,255,32)
|
|
add('S',obj)
|
|
for i in range(3+obj):
|
|
add('F',obj,0,1+obj,40+i)
|
|
# Both live objects have equal configuration and different partial data.
|
|
for obj in range(2):
|
|
add('O',obj)
|
|
for ch in range(8):
|
|
add('G',obj,ch)
|
|
add('S',obj)
|
|
add('Z',obj)
|
|
add('C',obj,3300000,5,2)
|
|
for position,(lo,hi) in enumerate([(1,5000000),(1,255),(1,32)]):
|
|
for invalid in [lo-1,hi+1,I32MIN,I32MAX]:
|
|
args=[3300000,5,2]
|
|
args[position]=invalid
|
|
add('C',obj,*args)
|
|
for position in range(3):
|
|
for invalid in [-1,256,I32MIN,I32MAX]:
|
|
args=[0,3,255]
|
|
args[position]=invalid
|
|
add('F',obj,*args)
|
|
for ch in [-1,8,I32MIN,I32MAX,0,7]:
|
|
add('G',obj,ch)
|
|
add('A',obj)
|
|
add('A',obj)
|
|
add('T',obj)
|
|
add('F',obj,-1,3,255)
|
|
add('F',obj,255,255,255)
|
|
add('Z',obj)
|
|
add('Z',obj)
|
|
add('S',obj)
|
|
add('F',obj,0,0,0)
|
|
add('G',obj,0)
|
|
add('R',obj)
|
|
add('O',obj)
|
|
rng=random.Random(130111)
|
|
for _ in range(36):
|
|
obj=rng.randrange(2)
|
|
add('A',obj)
|
|
m=rng.randrange(1,256)
|
|
r=rng.randrange(1,5)
|
|
add('C',obj,rng.randrange(1,5000001),m,r)
|
|
add('S',obj)
|
|
for __ in range(bin(m).count('1')*r):
|
|
add('T',obj)
|
|
add('F',obj,rng.randrange(256),rng.randrange(256),rng.randrange(256))
|
|
for ch in range(8):
|
|
add('G',obj,ch)
|
|
direct=observe(ops)
|
|
cli=[]
|
|
def line(data):
|
|
cli.append(('L',(data,)))
|
|
line(b'')
|
|
line(b'state')
|
|
line(b'start\nfeed 255 255 255\nread 0\nstate\n')
|
|
line(b'state\nread 0\ntx\nabort\nfeed 0 0 0\nclear\n')
|
|
line(b'config 5000000 255 32\nstart\nfeed 255 255 255\nconfig 1 1 1\nconfig 0 1 1\nstart\nclear\nread 0\nread 7\nread 8\nfeed -1 0 0\ntx\nstate\nabort\nread 0\nclear\nread 0\n')
|
|
line(b'config 1 1 1\nstart\ntx\nfeed 0 252 0\nread 0\nstate\nconfig 5000000 128 1\nstart\ntx\nfeed 255 255 255\nread 7\nstate\nfeed 0 0 0\nabort\ntx\n')
|
|
verbs={'config':3,'start':0,'tx':0,'feed':3,'read':1,'state':0,'abort':0,'clear':0}
|
|
bad=[b'start',b'feed 0 1 99',b'state']
|
|
for verb,count in verbs.items():
|
|
if count:
|
|
bad.append((verb+' '+' '.join(['0']*(count-1))).encode())
|
|
else:
|
|
bad.append((verb+' 0').encode())
|
|
bad.append((verb+' '+' '.join(['0']*(count+1))).encode())
|
|
if count:
|
|
for pos in range(count):
|
|
for value in ['+1','-','1x','2147483648','-2147483649','9'*100,'1\r']:
|
|
args=['0']*count
|
|
args[pos]=value
|
|
bad.append((verb+' '+' '.join(args)).encode())
|
|
bad += [b'',b'wat',b'state\r',b'state\x00',b'\xff',b' '*256,b'state'+b' '*250,b'state'+b' '*251,b'\t state \t',b'state']
|
|
for i in range(0,len(bad),70):
|
|
line(b'config 3300000 255 32\nstart\nfeed 0 1 99\n'+b'\n'.join(bad[i:i+70])+b'\nread 0\nstate\n')
|
|
for inactive in [False,True]:
|
|
for verb,args,bounds in [('config',[3300000,5,2],[(1,5000000),(1,255),(1,32)]),
|
|
('feed',[0,3,255],[(0,255)]*3),('read',[0],[(0,7)])]:
|
|
for pos,(low,high) in enumerate(bounds):
|
|
for value in [low-1,high+1,I32MIN,I32MAX]:
|
|
values=list(args)
|
|
values[pos]=value
|
|
prefix=b'config 3300000 255 32\nstart\nfeed 0 1 13\n'
|
|
if inactive:
|
|
prefix+=b'abort\n'
|
|
line(prefix+(verb+' '+' '.join(map(str,values))+'\nstate\nread 0\n').encode())
|
|
line(b'config 0001 0001 0001\nstart\nfeed -0 0 0\nread -0\nstate')
|
|
# The last permitted physical line mutates; the following feed is suppressed.
|
|
prefix=[b'config 3300000 1 32',b'start',b'feed 0 0 99']
|
|
prefix += [b'state',b'bad',b'read 7',b'feed -1 0 0']*31
|
|
assert len(prefix)==127
|
|
line(b'\n'.join(prefix+[b'feed 0 3 255']))
|
|
line(b'\n'.join(prefix+[b'feed 0 3 255',b'feed 0 0 0',b'read 0']))
|
|
# Response 128 itself exposes mutation by clearing nonempty data and reading it.
|
|
prefix2=[b'start',b'feed 0 3 255',b'abort']+[b'state',b'bad',b'read 7',b'tx']*30
|
|
assert len(prefix2)==123
|
|
line(b'\n'.join(prefix2+[b'clear',b'start',b'feed 0 0 0',b'abort',b'read 0']))
|
|
line(b'state\n')
|
|
cli_scene=observe(cli)
|
|
expected={'config':{'OK','RANGE','BUSY'},'start':{'OK','BUSY'},'tx':{'OK','IDLE'},
|
|
'feed':{'OK','RANGE','IDLE'},'read':{'OK','RANGE','EMPTY'},'state':{'OK'},
|
|
'abort':{'OK','IDLE'},'clear':{'OK','BUSY'}}
|
|
assert {k:CLI_COVERAGE.get(k,set()) for k in expected}==expected
|
|
assert {k:CLI_ERROR_CONTEXT.get(k,set()) for k,v in expected.items() if v-{'OK'}}=={k:v-{'OK'} for k,v in expected.items() if v-{'OK'}}
|
|
return [('smoke',observe([('L',(smoke,))])),('direct',direct),('cli',cli_scene)]
|
|
|
|
|
|
def digest(data):
|
|
return [len(data),hashlib.sha256(data).hexdigest()[:16]]
|
|
|
|
|
|
def main():
|
|
candidate=Path(sys.argv[1])
|
|
plans=scenes()
|
|
# All trusted scratch IO is finished before the first compiler process.
|
|
scratch=Path(tempfile.mkdtemp(prefix='adc-',dir=Path.cwd()))
|
|
for name in ['adc.h','adc.c','cli.c']:
|
|
(scratch/name).write_bytes((candidate/name).read_bytes())
|
|
(scratch/'observer.c').write_text(OBSERVER)
|
|
(scratch/'demo.c').write_text('#include "adc.h"\nint main(void) { Adc a; adc_run_cli(stdin,stdout,&a); return 0; }\n')
|
|
compiler=shutil.which('gcc')
|
|
if not compiler:
|
|
raise RuntimeError('gcc unavailable')
|
|
argv=[compiler,'-std=c11','-O2','-Wall','-Wextra','-I',str(scratch),str(scratch/'adc.c'),str(scratch/'cli.c'),str(scratch/'observer.c'),'-o',str(scratch/'observe')]
|
|
metadata=[]
|
|
failures=[]
|
|
def execute(name,argv,stdin,expected,seconds):
|
|
proc=subprocess.Popen(argv,cwd=scratch,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
timed=False
|
|
try:
|
|
stdout,stderr=proc.communicate(stdin,timeout=seconds)
|
|
except subprocess.TimeoutExpired:
|
|
timed=True
|
|
proc.kill()
|
|
stdout,stderr=proc.communicate()
|
|
reasons=[]
|
|
if not name.startswith('build') and stdout!=expected:
|
|
reasons.append('stdout')
|
|
if not name.startswith('build') and stderr:
|
|
reasons.append('stderr')
|
|
if proc.returncode!=0:
|
|
reasons.append('exit')
|
|
if timed:
|
|
reasons.append('timeout')
|
|
metadata.append({'n':name,'p':proc.pid,'a':argv,'x':proc.returncode,'t':timed,
|
|
'i':digest(stdin),'e':digest(expected),'o':digest(stdout),'r':digest(stderr),'why':reasons})
|
|
failures.extend(name+':'+reason for reason in reasons)
|
|
return proc.returncode==0 and not timed
|
|
built=execute('build-observer',argv,b'',b'',30)
|
|
public_argv=argv[:-3]+[str(scratch/'demo.c'),'-o',str(scratch/'demo')]
|
|
public_built=execute('build-demo',public_argv,b'',b'',30)
|
|
if built:
|
|
for name,(stdin,expected) in plans:
|
|
execute(name,[str(scratch/'observe')],stdin,expected,12)
|
|
if public_built:
|
|
execute('public-smoke',[str(scratch/'demo')],SMOKE,run_cli(SMOKE)[1],12)
|
|
execute('public-empty',[str(scratch/'demo')],b'',b'',12)
|
|
limit=b'config 3300000 1 32\nstart\nfeed 0 0 99\n'+b'state\nbad\nread 7\nfeed -1 0 0\n'*31+b'feed 0 3 255\nfeed 0 0 0\nread 0'
|
|
execute('public-limit',[str(scratch/'demo')],limit,run_cli(limit)[1],12)
|
|
payload=json.dumps({'cwd':str(scratch),'m':metadata,'fail':failures},separators=(',',':'))
|
|
if len(payload)>=3900:
|
|
raise RuntimeError('metadata exceeds 3900: '+str(len(payload)))
|
|
print(payload,file=sys.stderr)
|
|
print('FAIL '+','.join(failures) if failures else 'PASS')
|
|
return bool(failures)
|
|
|
|
if __name__=='__main__':
|
|
sys.exit(main())
|