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>
544 lines
30 KiB
Python
544 lines
30 KiB
Python
from pathlib import Path
|
|
import json
|
|
import random
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
CANDIDATES = ['minor_router.hpp', 'minor_directory.cpp', 'minor_io.cpp', 'minor_query.cpp']
|
|
MASK = (1 << 64) - 1
|
|
|
|
def hexbytes(data):
|
|
return bytes(data).hex() or '-'
|
|
|
|
def seedfields(seed, kind):
|
|
u = seed & MASK
|
|
return [seed, u, u, u, u, u] if kind == 'I' else [seed, seed, u, u, u, u, seed, seed, seed, u]
|
|
|
|
class Model:
|
|
def __init__(self):
|
|
self.reset()
|
|
def reset(self):
|
|
self.routes = {}
|
|
self.fds = {}
|
|
self.versions = {}
|
|
def live_sessions(self):
|
|
return {id(s): s for s in self.fds.values()}.values()
|
|
def objects(self):
|
|
values = list(self.routes.values()) + [s['o'] for s in self.fds.values()]
|
|
return list({id(o): o for o in values}.values())
|
|
def newfd(self):
|
|
return next((fd for fd in range(3, 19) if fd not in self.fds), -24)
|
|
def access(self, fd, bit=0):
|
|
if fd not in self.fds:
|
|
return -9
|
|
if bit and not self.fds[fd]['mode'] & bit:
|
|
return -13
|
|
return 0
|
|
def di(self, o):
|
|
streams = [s for s in self.live_sessions() if s['o'] is o]
|
|
handles = [s for s in self.fds.values() if s['o'] is o]
|
|
return [o['minor'], o['gen'], o['cap'], len(o['data']), len(streams), len(handles)]
|
|
def si(self, fd):
|
|
s = self.fds[fd]
|
|
o = s['o']
|
|
return [fd, o['minor'], o['gen'], o['cap'], len(o['data']), s['pos'], s['mode'], s['append'], int(o['linked']), sum(x is s for x in self.fds.values())]
|
|
def extract(self, o, at, count):
|
|
return o['data'][at:at + count]
|
|
def store(self, o, at, data):
|
|
n = min(len(data), o['cap'] - at)
|
|
if n:
|
|
end = at + n
|
|
o['data'].extend([0] * max(0, end - len(o['data'])))
|
|
o['data'][at:end] = data[:n]
|
|
return n
|
|
def command(self, op, *a):
|
|
r = 0
|
|
payload = None
|
|
if op == 'Z':
|
|
self.reset()
|
|
elif op == 'C':
|
|
minor, cap = a
|
|
if not 0 <= minor <= 7 or not 1 <= cap <= 4096:
|
|
r = -22
|
|
elif minor in self.routes:
|
|
r = -17
|
|
else:
|
|
gen = self.versions.get(minor, 0) + 1
|
|
self.versions[minor] = gen
|
|
self.routes[minor] = dict(minor=minor, gen=gen, cap=cap, data=[], linked=True)
|
|
elif op == 'D':
|
|
minor, = a
|
|
if not 0 <= minor <= 7:
|
|
r = -22
|
|
elif minor not in self.routes:
|
|
r = -2
|
|
else:
|
|
self.routes.pop(minor)['linked'] = False
|
|
elif op == 'O':
|
|
minor, mode, append = a
|
|
if not 0 <= minor <= 7 or mode not in (1, 2, 3) or append not in (0, 1):
|
|
r = -22
|
|
elif minor not in self.routes:
|
|
r = -2
|
|
else:
|
|
r = self.newfd()
|
|
if r >= 0:
|
|
self.fds[r] = dict(o=self.routes[minor], pos=0, mode=mode, append=append)
|
|
elif op == 'U':
|
|
fd, = a
|
|
r = self.access(fd)
|
|
if not r:
|
|
r = self.newfd()
|
|
if r >= 0:
|
|
self.fds[r] = self.fds[fd]
|
|
elif op == 'X':
|
|
fd, = a
|
|
r = self.access(fd)
|
|
if not r:
|
|
del self.fds[fd]
|
|
elif op == 'A':
|
|
fd, flag = a
|
|
r = self.access(fd)
|
|
if not r:
|
|
if flag not in (0, 1):
|
|
r = -22
|
|
else:
|
|
self.fds[fd]['append'] = flag
|
|
elif op in ('R', 'P', 'K'):
|
|
if op == 'R':
|
|
fd, count, initial = a
|
|
r = self.access(fd, 1)
|
|
if not r:
|
|
s = self.fds[fd]
|
|
o, at = s['o'], s['pos']
|
|
elif op == 'P':
|
|
fd, at, count, initial = a
|
|
r = self.access(fd, 1)
|
|
if not r:
|
|
o = self.fds[fd]['o']
|
|
if at > o['cap']:
|
|
r = -22
|
|
else:
|
|
minor, at, count, initial = a
|
|
if not 0 <= minor <= 7:
|
|
r = -22
|
|
elif minor not in self.routes:
|
|
r = -2
|
|
else:
|
|
o = self.routes[minor]
|
|
if at > o['cap']:
|
|
r = -22
|
|
payload = list(initial)
|
|
if not r:
|
|
payload = self.extract(o, at, count)
|
|
r = len(payload)
|
|
if op == 'R':
|
|
s['pos'] += r
|
|
return f'B {r} {hexbytes(payload)}'
|
|
elif op in ('W', 'T'):
|
|
fd = a[0]
|
|
at, data = (None, a[1]) if op == 'W' else (a[1], a[2])
|
|
r = self.access(fd, 2)
|
|
if not r:
|
|
s = self.fds[fd]
|
|
o = s['o']
|
|
if op == 'T' and at > o['cap'] or len(data) > 4096:
|
|
r = -22
|
|
elif op == 'W' and not data:
|
|
r = 0
|
|
else:
|
|
if op == 'W':
|
|
at = len(o['data']) if s['append'] else s['pos']
|
|
r = self.store(o, at, data)
|
|
if op == 'W':
|
|
s['pos'] = at + r
|
|
return f'R {r} {hexbytes(data)}'
|
|
elif op == 'S':
|
|
fd, whence, delta = a
|
|
r = self.access(fd)
|
|
if not r:
|
|
s = self.fds[fd]
|
|
if whence not in (0, 1, 2):
|
|
r = -22
|
|
else:
|
|
base = (0, s['pos'], len(s['o']['data']))[whence]
|
|
value = base + delta
|
|
if not 0 <= value <= s['o']['cap']:
|
|
r = -22
|
|
else:
|
|
s['pos'] = value
|
|
r = value
|
|
elif op in ('L', 'E'):
|
|
fd = a[0]
|
|
r = self.access(fd, 2)
|
|
if not r:
|
|
o = self.fds[fd]['o']
|
|
length = 0 if op == 'E' else a[1]
|
|
if length > o['cap']:
|
|
r = -22
|
|
else:
|
|
o['data'] = o['data'][:length] + [0] * max(0, length - len(o['data']))
|
|
elif op == 'I':
|
|
minor, seed = a
|
|
fields = seedfields(seed, 'I')
|
|
if not 0 <= minor <= 7:
|
|
r = -22
|
|
elif minor not in self.routes:
|
|
r = -2
|
|
else:
|
|
fields = self.di(self.routes[minor])
|
|
return ' '.join(map(str, ['I', r] + fields))
|
|
elif op == 'Q':
|
|
fd, seed = a
|
|
r = self.access(fd)
|
|
fields = seedfields(seed, 'Q') if r else self.si(fd)
|
|
return ' '.join(map(str, ['Q', r] + fields))
|
|
elif op == 'V':
|
|
rows = [self.di(self.routes[m]) for m in sorted(self.routes)]
|
|
return ' '.join(map(str, ['V', len(rows)] + sum(rows, [])))
|
|
elif op == 'N':
|
|
rows = [self.si(fd) for fd in sorted(self.fds)]
|
|
return ' '.join(map(str, ['N', len(rows)] + sum(rows, [])))
|
|
elif op == 'H':
|
|
objects = self.objects()
|
|
values = [len(self.routes), sum(not o['linked'] for o in objects), len(list(self.live_sessions())), len(self.fds), sum(len(o['data']) for o in objects), sum(o['cap'] for o in objects)]
|
|
return ' '.join(map(str, ['H'] + values))
|
|
else:
|
|
raise ValueError(op)
|
|
return f'R {r}'
|
|
|
|
class Workload:
|
|
def __init__(self):
|
|
self.banks = [Model(), Model()]
|
|
self.selected = 0
|
|
self.lines = []
|
|
self.expected = []
|
|
self.labels = []
|
|
self.ops = {}
|
|
@property
|
|
def model(self):
|
|
return self.banks[self.selected]
|
|
def add(self, label, op, *args):
|
|
if op == 'B':
|
|
self.selected = args[0]
|
|
result = f'B {self.selected}'
|
|
else:
|
|
result = self.model.command(op, *args)
|
|
words = [hexbytes(x) if isinstance(x, (bytes, list)) else str(x) for x in args]
|
|
self.lines.append(' '.join([op] + words))
|
|
self.expected.append(result)
|
|
self.labels.append(label)
|
|
self.ops[op] = self.ops.get(op, 0) + 1
|
|
return result
|
|
def audit(self, label):
|
|
for op, args in [('H', ()), ('V', (31,)), ('N', (-13,))]:
|
|
self.add(label, op, *args)
|
|
for minor in range(8):
|
|
self.add(label, 'I', minor, -31)
|
|
for fd in range(3, 19):
|
|
self.add(label, 'Q', fd, 47)
|
|
|
|
def workload():
|
|
w = Workload()
|
|
a = w.add
|
|
# Public smoke demonstrates only routing, and requests exactly the stored size.
|
|
for op, args in [('C',(0,16)),('C',(3,16)),('O',(0,3,0)),('W',(3,[65,66,67])),('O',(3,1,0)),('R',(4,3,[]))]:
|
|
a('smoke-routing', op, *args)
|
|
a('short-completion', 'Z')
|
|
for op, args in [('C',(7,32)),('O',(7,3,1)),('W',(3,[19,0,255])),('O',(7,1,0)),('R',(4,10,[42])),('W',(3,[77,88])),('R',(4,2,[42])),('R',(4,MASK,[42])),('W',(3,[99])),('R',(4,1,[42]))]:
|
|
a('short-completion', op, *args)
|
|
w.audit('short-completion-state')
|
|
a('empty-direct-apis', 'Z')
|
|
w.audit('empty-direct-apis')
|
|
for minor in (-2147483648, -1, 0, 7, 8, 2147483647):
|
|
a('minor-domain-errors', 'D', minor)
|
|
a('minor-domain-errors', 'I', minor, -2147483648)
|
|
a('minor-domain-errors', 'K', minor, MASK, MASK, [0,255])
|
|
for cap in (0, 4097, MASK):
|
|
a('minor-domain-errors', 'C', minor, cap)
|
|
for fd in (-2147483648, -1, 0, 2, 3, 18, 19, 2147483647):
|
|
for op,args in [('U',(fd,)),('X',(fd,)),('A',(fd,2)),('R',(fd,MASK,[2,0,255])),('W',(fd,[9])),('P',(fd,MASK,MASK,[5])),('T',(fd,MASK,[9])),('S',(fd,3,-9223372036854775808)),('L',(fd,MASK)),('E',(fd,)),('Q',(fd,-1))]:
|
|
a('fd-domain-errors', op, *args)
|
|
w.audit('error-atomicity')
|
|
a('peek-without-descriptor','C',1,5)
|
|
a('peek-without-descriptor','K',1,0,MASK,[0,255])
|
|
a('peek-without-descriptor','O',1,3,0)
|
|
a('peek-without-descriptor','W',3,[4,0,255])
|
|
a('peek-without-descriptor','X',3)
|
|
a('peek-without-descriptor','K',1,0,MASK,[33])
|
|
a('peek-without-descriptor','I',1,33)
|
|
a('peek-without-descriptor','D',1)
|
|
a('peek-without-descriptor','Z')
|
|
for minor, cap in enumerate((1,2,7,16,31,256,4095,4096)):
|
|
a('all-minors-capacities', 'C', minor, cap)
|
|
a('create-priority-generation', 'C', minor, 0)
|
|
a('create-priority-generation', 'C', minor, cap)
|
|
a('all-minors-capacities', 'O', minor, 3, 0)
|
|
a('all-minors-capacities', 'W', 3+minor, [minor, 255-minor, 0])
|
|
for offset in (0,cap,cap+1,MASK):
|
|
a('peek-endpoints', 'K', minor, offset, MASK, [35,0,255])
|
|
w.audit('eight-routes-direct')
|
|
for minor in (-2147483648, -1, 0, 7, 8, 2147483647):
|
|
for mode in (-2147483648,-1,0,1,2,3,4,2147483647):
|
|
for append in (-1,0,1,2):
|
|
a('open-priority-domain-table', 'O', minor, mode, append)
|
|
a('full-table-missing-route', 'D', 7)
|
|
a('full-table-missing-route', 'O', 7, 3, 0)
|
|
a('full-table-invalid-duplicate', 'U', -1)
|
|
a('full-table-valid-duplicate', 'U', 3)
|
|
w.audit('full-table-atomicity')
|
|
a('fd-reuse', 'X', 18)
|
|
a('fd-reuse', 'U', 3)
|
|
a('fd-reuse', 'X', 3)
|
|
a('fd-reuse', 'O', 0, 2, 0)
|
|
w.audit('fd-reuse-direct')
|
|
a('permissions', 'Z')
|
|
a('permissions', 'C', 7, 4096)
|
|
for mode in (1,2,3):
|
|
a('permissions', 'O', 7, mode, 0)
|
|
too_big = list(bytes(range(256)) * 16) + [255]
|
|
maximum = list(bytes(range(256)) * 16)
|
|
for fd in (3,4,5,-1):
|
|
for op,args in [('R',(fd,0,[17])),('P',(fd,MASK,MASK,[17])),('W',(fd,[])),('W',(fd,too_big)),('T',(fd,MASK,too_big)),('L',(fd,MASK)),('E',(fd,)),('S',(fd,0,4096)),('A',(fd,1)),('A',(fd,-1))]:
|
|
a('permissions-priority-atomicity', op, *args)
|
|
for fd in (-2147483648, 3, 4, 5, 2147483647):
|
|
for flag in (-2147483648, 2147483647):
|
|
a('append-int-endpoints', 'A', fd, flag)
|
|
for seed in (-2147483648, -1, 0, 2147483647):
|
|
for minor in (0,7):
|
|
a('output-field-seed-endpoints','I',minor,seed)
|
|
for fd in (3,4,5,18):
|
|
a('output-field-seed-endpoints','Q',fd,seed)
|
|
a('output-field-seed-endpoints','V',seed)
|
|
a('output-field-seed-endpoints','N',seed)
|
|
a('output-vector-seed-endpoints','R',3,0,list(bytes(range(256))*32))
|
|
a('output-vector-seed-endpoints','P',-1,MASK,MASK,list(bytes(range(256))*32))
|
|
w.audit('permissions-direct')
|
|
a('write-size-endpoints','S',5,0,0)
|
|
for length in (0,1,4095,4096,4097,8192):
|
|
data = (maximum * 2)[:length]
|
|
a('write-size-endpoints','E',5)
|
|
a('write-size-endpoints','S',5,0,0)
|
|
a('write-size-endpoints','A',5,0)
|
|
a('write-size-endpoints','W',5,data)
|
|
a('write-size-endpoints','K',7,0,MASK,[222])
|
|
a('write-size-endpoints','Q',5,33)
|
|
a('positional-write-size','T',5,0,data)
|
|
a('positional-write-size','K',7,0,MASK,[222])
|
|
a('positional-write-size','Q',5,33)
|
|
a('cursor-alias','E',5)
|
|
a('cursor-alias','S',5,0,0)
|
|
a('cursor-alias','W',5,[0,255,31,77,9])
|
|
a('cursor-alias','U',5)
|
|
a('cursor-alias','O',7,3,0)
|
|
a('cursor-alias','S',6,0,1)
|
|
a('cursor-alias','R',5,2,[4])
|
|
a('cursor-alias','R',6,1,[4])
|
|
a('cursor-alias','R',7,1,[4])
|
|
a('cursor-alias','A',6,1)
|
|
a('cursor-alias','W',5,[])
|
|
a('cursor-alias','W',6,[8])
|
|
w.audit('cursor-alias-direct')
|
|
for at in (0,1,5,4095,4096,4097,MASK):
|
|
for count in (0,1,4096,MASK):
|
|
a('pread-peek-endpoints','P',5,at,count,[0,255,3])
|
|
a('pread-peek-endpoints','K',7,at,count,[0,255,3])
|
|
a('pwrite-offset-endpoints','T',5,at,[0,255])
|
|
a('pwrite-offset-endpoints','T',5,at,[])
|
|
w.audit('positional-no-cursor-effects')
|
|
for whence in (-2147483648,-1,0,1,2,3,2147483647):
|
|
for delta in (-9223372036854775808,-4097,-4096,-1,0,1,4096,4097,9223372036854775807):
|
|
a('seek-overflow-domain', 'S',5,whence,delta)
|
|
a('seek-overflow-domain', 'Q',5,99)
|
|
for length in (0,1,1,4095,4096,4096,4097,MASK,2,0):
|
|
a('resize-endpoints', 'L',5,length)
|
|
a('resize-endpoints', 'K',7,0,MASK,[1])
|
|
a('resize-endpoints', 'Q',5,33)
|
|
a('clear-repeat','E',6)
|
|
a('clear-repeat','E',6)
|
|
w.audit('clear-cursor-retention')
|
|
# Gap fill and clamped writes at both capacity endpoints.
|
|
a('gap-and-clamped-write','S',5,0,4095)
|
|
a('gap-and-clamped-write','A',5,0)
|
|
a('gap-and-clamped-write','W',5,[0,255])
|
|
a('gap-and-clamped-write','W',5,[22])
|
|
a('gap-and-clamped-write','K',7,0,MASK,[23])
|
|
a('gap-and-clamped-write','L',5,2)
|
|
a('gap-and-clamped-write','W',5,[])
|
|
a('gap-and-clamped-write','A',5,1)
|
|
a('gap-and-clamped-write','W',5,[])
|
|
a('gap-and-clamped-write','W',5,[81])
|
|
w.audit('gap-clamp-append-state')
|
|
# Interleaved writers must reevaluate append; full short writes still set cursor.
|
|
a('append-interleaving-zero-room','Z')
|
|
a('append-interleaving-zero-room','C',2,8)
|
|
a('append-interleaving-zero-room','O',2,3,1)
|
|
a('append-interleaving-zero-room','O',2,3,0)
|
|
a('empty-positional-no-extension','T',4,7,[])
|
|
a('empty-positional-no-extension','K',2,0,MASK,[44])
|
|
a('empty-positional-no-extension','I',2,44)
|
|
a('append-interleaving-zero-room','W',4,[11,12])
|
|
a('append-interleaving-zero-room','W',3,[22])
|
|
a('append-interleaving-zero-room','T',4,6,[77])
|
|
a('append-interleaving-zero-room','S',3,0,0)
|
|
a('append-interleaving-zero-room','W',3,[88])
|
|
a('append-interleaving-zero-room','S',3,0,0)
|
|
a('append-empty-full-cursor','W',3,[])
|
|
a('append-empty-full-cursor','Q',3,44)
|
|
a('append-interleaving-zero-room','W',3,[99])
|
|
a('append-interleaving-zero-room','Q',3,44)
|
|
a('append-interleaving-zero-room','K',2,0,MASK,[44])
|
|
a('read-beyond-shrunken-end','S',3,0,7)
|
|
a('read-beyond-shrunken-end','L',4,2)
|
|
a('read-beyond-shrunken-end','R',3,9,[44])
|
|
a('read-beyond-shrunken-end','Q',3,44)
|
|
w.audit('append-interleaving-direct-state')
|
|
# Multiple retained generations: mutate each through its original sessions.
|
|
a('retained-generations','Z')
|
|
for generation in range(1,5):
|
|
a('retained-generations','C',3,16+generation)
|
|
a('retained-generations','O',3,3,1)
|
|
a('retained-generations','W',generation+2,[generation,0,255])
|
|
a('retained-generations','U',generation+2)
|
|
a('retained-generations','X',generation+3)
|
|
a('retained-generations','D',3)
|
|
a('retained-generations','D',3)
|
|
a('retained-generations','O',3,3,0)
|
|
a('retained-generations','I',3,42)
|
|
w.audit('retained-generations-state')
|
|
a('retained-generations','C',3,31)
|
|
a('retained-generations','O',3,3,0)
|
|
for fd in sorted(w.model.fds):
|
|
a('detached-local-io','S',fd,0,0)
|
|
a('detached-local-io','P',fd,0,MASK,[42])
|
|
a('detached-local-io','R',fd,1,[42])
|
|
a('detached-local-io','T',fd,1,[fd])
|
|
a('detached-local-io','A',fd,0)
|
|
a('detached-local-io','L',fd,7)
|
|
a('detached-local-io','E',fd)
|
|
a('detached-local-io','Q',fd,42)
|
|
w.audit('detached-local-io-state')
|
|
for fd in list(sorted(w.model.fds)):
|
|
a('retired-last-close','X',fd)
|
|
a('retired-last-close','X',fd)
|
|
w.audit('retired-last-close-state')
|
|
a('generation-after-failed-create','C',3,0)
|
|
a('generation-after-failed-create','D',3)
|
|
a('generation-after-failed-create','C',3,1)
|
|
a('generation-after-failed-create','I',3,31)
|
|
# Every method on the other Router; reset and generation counters are instance-local.
|
|
a('cross-instance','B',1)
|
|
w.audit('cross-instance-empty')
|
|
a('cross-instance','C',0,8)
|
|
a('cross-instance','O',0,3,0)
|
|
a('cross-instance','W',3,[255,0,23])
|
|
a('cross-instance','U',3)
|
|
a('cross-instance','A',4,1)
|
|
a('cross-instance','R',4,0,[33])
|
|
a('cross-instance','S',3,0,0)
|
|
a('cross-instance','P',3,0,MASK,[33])
|
|
a('cross-instance','T',3,1,[99])
|
|
a('cross-instance','L',3,5)
|
|
a('cross-instance','K',0,0,MASK,[33])
|
|
w.audit('cross-instance-filled')
|
|
a('cross-instance','B',0)
|
|
w.audit('cross-instance-first-unchanged')
|
|
a('instance-local-reset','Z')
|
|
a('instance-local-reset','C',3,1)
|
|
a('instance-local-reset','O',3,3,0)
|
|
a('instance-local-reset','I',3,77)
|
|
a('cross-instance','B',1)
|
|
w.audit('cross-instance-second-unchanged')
|
|
a('cross-instance','D',0)
|
|
a('cross-instance','E',4)
|
|
a('cross-instance','X',3)
|
|
a('cross-instance','X',4)
|
|
w.audit('cross-instance-collected')
|
|
a('instance-local-reset','Z')
|
|
a('instance-local-reset','C',0,1)
|
|
a('instance-local-reset','I',0,-1)
|
|
# Fixed-seed combinations of documented transitions, not gold-derived expectations.
|
|
rng = random.Random(0xD3C011)
|
|
for i in range(1100):
|
|
if i % 137 == 0:
|
|
a('random-instance', 'B', rng.randrange(2))
|
|
m = rng.choice([-1,0,1,2,3,4,5,6,7,8])
|
|
fd = rng.choice(list(w.model.fds) * 3 + [2,3,18,19])
|
|
op = rng.choice('CCDOOUUXAARWWPPTSSSLLEIKQQHVN')
|
|
data = [rng.randrange(256) for _ in range(rng.randrange(0,45))]
|
|
seed = [rng.randrange(256) for _ in range(rng.randrange(0,5))]
|
|
count = rng.choice([0,1,2,17,4096,MASK])
|
|
offset = rng.choice([0,1,2,7,15,31,4095,4096,4097,MASK])
|
|
args = {'C':(m,rng.choice([0,1,2,7,16,31,4096,4097])), 'D':(m,), 'O':(m,rng.choice([0,1,2,3,4]),rng.choice([0,1,2])), 'U':(fd,), 'X':(fd,), 'A':(fd,rng.choice([-1,0,1,2])), 'R':(fd,count,seed), 'W':(fd,data), 'P':(fd,offset,count,seed), 'T':(fd,offset,data), 'S':(fd,rng.choice([-1,0,1,2,3]),rng.choice([-9223372036854775808,-1,0,1,7,4096,9223372036854775807])), 'L':(fd,offset), 'E':(fd,), 'I':(m,-17), 'K':(m,offset,count,seed), 'Q':(fd,31), 'H':(), 'V':(31,), 'N':(-31,)}[op]
|
|
a('fixed-seed-combinations',op,*args)
|
|
if i % 29 == 0:
|
|
w.audit('random-state-direct')
|
|
for index in (0,1):
|
|
a('final-instance-reset','B',index)
|
|
a('final-instance-reset','Z')
|
|
w.audit('final-empty-state')
|
|
required = set('CDOUXARWPTSLEIQKVNHZB')
|
|
assert required <= set(w.ops)
|
|
return w
|
|
|
|
# OBSERVER is the public raw stdin/API console, copied verbatim at task freeze.
|
|
OBSERVER = '#include "minor_router.hpp"\n#include <charconv>\n#include <iostream>\n#include <sstream>\n#include <string>\n#include <vector>\nnamespace {\nusing minorio::Bytes;\nusing minorio::DeviceInfo;\nusing minorio::SessionInfo;\nusing U = std::uint64_t;\ntemplate<class T> bool number(const std::string &token, T &out)\n{\n const auto result = std::from_chars(token.data(), token.data() + token.size(), out);\n return result.ec == std::errc{} && result.ptr == token.data() + token.size();\n}\nint nibble(char value)\n{\n if (value >= \'0\' && value <= \'9\') return value - \'0\';\n if (value >= \'a\' && value <= \'f\') return value - \'a\' + 10;\n if (value >= \'A\' && value <= \'F\') return value - \'A\' + 10;\n return -1;\n}\nbool hex(const std::string &text, Bytes &out)\n{\n if (text == "-") return true;\n if (text.empty() || text.size() % 2 || text.size() > 16384) return false;\n for (std::size_t at = 0; at < text.size(); at += 2) {\n const int high = nibble(text[at]);\n const int low = nibble(text[at + 1]);\n if (high < 0 || low < 0) return false;\n out.push_back(static_cast<std::uint8_t>(high * 16 + low));\n }\n return true;\n}\nvoid print(const Bytes &data)\n{\n const char *digits = "0123456789abcdef";\n if (data.empty()) std::cout << \'-\';\n for (auto value : data) std::cout << digits[value >> 4] << digits[value & 15];\n}\nDeviceInfo device_seed(int seed)\n{\n const auto value = static_cast<U>(seed);\n return {seed, value, value, value, value, value};\n}\nSessionInfo session_seed(int seed)\n{\n const auto value = static_cast<U>(seed);\n return {seed, seed, value, value, value, value, seed, seed, seed, value};\n}\nvoid print(const DeviceInfo &value)\n{\n std::cout << \' \' << value.minor << \' \' << value.generation << \' \' << value.capacity\n << \' \' << value.length << \' \' << value.sessions << \' \' << value.handles;\n}\nvoid print(const SessionInfo &value)\n{\n std::cout << \' \' << value.fd << \' \' << value.minor << \' \' << value.generation\n << \' \' << value.capacity << \' \' << value.length << \' \' << value.cursor\n << \' \' << value.mode << \' \' << value.append << \' \' << value.linked << \' \' << value.aliases;\n}\nbool execute(minorio::Router &router, const std::vector<std::string> &a)\n{\n int x = 0;\n int y = 0;\n int z = 0;\n U p = 0;\n U q = 0;\n std::int64_t d = 0;\n Bytes bytes;\n const auto &op = a[0];\n if (op == "C" && a.size() == 3 && number(a[1], x) && number(a[2], p)) {\n std::cout << "R " << router.create(x, p);\n } else if (op == "D" && a.size() == 2 && number(a[1], x)) {\n std::cout << "R " << router.remove(x);\n } else if (op == "O" && a.size() == 4 && number(a[1], x) && number(a[2], y) && number(a[3], z)) {\n std::cout << "R " << router.open(x, y, z);\n } else if (op == "U" && a.size() == 2 && number(a[1], x)) {\n std::cout << "R " << router.duplicate(x);\n } else if (op == "X" && a.size() == 2 && number(a[1], x)) {\n std::cout << "R " << router.close(x);\n } else if (op == "A" && a.size() == 3 && number(a[1], x) && number(a[2], y)) {\n std::cout << "R " << router.set_append(x, y);\n } else if (op == "R" && a.size() == 4 && number(a[1], x) && number(a[2], p) && hex(a[3], bytes)) {\n const int result = router.read(x, p, bytes);\n std::cout << "B " << result << \' \';\n print(bytes);\n } else if (op == "W" && a.size() == 3 && number(a[1], x) && hex(a[2], bytes)) {\n const int result = router.write(x, bytes);\n std::cout << "R " << result << \' \';\n print(bytes);\n } else if (op == "P" && a.size() == 5 && number(a[1], x) && number(a[2], p) && number(a[3], q) && hex(a[4], bytes)) {\n const int result = router.pread(x, p, q, bytes);\n std::cout << "B " << result << \' \';\n print(bytes);\n } else if (op == "T" && a.size() == 4 && number(a[1], x) && number(a[2], p) && hex(a[3], bytes)) {\n const int result = router.pwrite(x, p, bytes);\n std::cout << "R " << result << \' \';\n print(bytes);\n } else if (op == "S" && a.size() == 4 && number(a[1], x) && number(a[2], y) && number(a[3], d)) {\n std::cout << "R " << router.seek(x, y, d);\n } else if (op == "L" && a.size() == 3 && number(a[1], x) && number(a[2], p)) {\n std::cout << "R " << router.resize(x, p);\n } else if (op == "E" && a.size() == 2 && number(a[1], x)) {\n std::cout << "R " << router.clear(x);\n } else if (op == "I" && a.size() == 3 && number(a[1], x) && number(a[2], y)) {\n auto value = device_seed(y);\n const int result = router.device(x, value);\n std::cout << "I " << result;\n print(value);\n } else if (op == "Q" && a.size() == 3 && number(a[1], x) && number(a[2], y)) {\n auto value = session_seed(y);\n const int result = router.session(x, value);\n std::cout << "Q " << result;\n print(value);\n } else if (op == "K" && a.size() == 5 && number(a[1], x) && number(a[2], p) && number(a[3], q) && hex(a[4], bytes)) {\n const int result = router.peek(x, p, q, bytes);\n std::cout << "B " << result << \' \';\n print(bytes);\n } else if (op == "V" && a.size() == 2 && number(a[1], y)) {\n std::vector<DeviceInfo> values{device_seed(y)};\n router.devices(values);\n std::cout << "V " << values.size();\n for (const auto &value : values) print(value);\n } else if (op == "N" && a.size() == 2 && number(a[1], y)) {\n std::vector<SessionInfo> values{session_seed(y)};\n router.sessions(values);\n std::cout << "N " << values.size();\n for (const auto &value : values) print(value);\n } else if (op == "H" && a.size() == 1) {\n const auto value = router.counts();\n std::cout << "H " << value.linked << \' \' << value.retired << \' \' << value.sessions\n << \' \' << value.handles << \' \' << value.bytes << \' \' << value.capacity;\n } else if (op == "Z" && a.size() == 1) {\n router.reset();\n std::cout << "R 0";\n } else {\n return false;\n }\n std::cout << \'\\n\';\n return true;\n}\n}\nint main()\n{\n minorio::Router routers[2];\n unsigned selected = 0;\n std::string line;\n while (std::getline(std::cin, line)) {\n std::istringstream input(line);\n std::vector<std::string> args;\n std::string word;\n while (input >> word) args.push_back(word);\n if (args.empty() || args[0][0] == \'#\') continue;\n if (args[0] == "B") {\n if (args.size() != 2 || !number(args[1], selected) || selected > 1) return 2;\n std::cout << "B " << selected << \'\\n\';\n } else if (!execute(routers[selected], args)) {\n return 2;\n }\n }\n return std::cin.bad() ? 2 : 0;\n}\n'
|
|
|
|
def main():
|
|
w = workload()
|
|
candidate = Path(sys.argv[1])
|
|
scratch = Path(tempfile.mkdtemp(prefix='minor-raw-', dir=Path.cwd()))
|
|
# Complete every root-side scratch read/write before even the compiler runs.
|
|
for name in CANDIDATES:
|
|
(scratch/name).write_bytes((candidate/name).read_bytes())
|
|
(scratch/'minor_console.cpp').write_text(OBSERVER)
|
|
input_text = '\n# observer transport prelude\n\n' + '\n'.join(' '+line+' ' for line in w.lines) + '\n# observer transport end\n\n'
|
|
input_text = input_text.replace('W 3 414243', 'W 003 414243').replace('ff', 'FF')
|
|
expected = list(w.expected)
|
|
labels = list(w.labels)
|
|
build_argv = ['c++','-std=c++17','-O2','-Wall','-Wextra','-pedantic', 'minor_directory.cpp','minor_io.cpp','minor_query.cpp','minor_console.cpp','-o','observer']
|
|
try:
|
|
build = subprocess.run(build_argv, cwd=scratch, capture_output=True, text=True, timeout=35)
|
|
except subprocess.TimeoutExpired:
|
|
print('audit build_timeout', file=sys.stderr)
|
|
print('FAIL build timeout')
|
|
return 1
|
|
print('audit '+json.dumps(dict(phase='build',exitcode=build.returncode,argv=build_argv)), file=sys.stderr)
|
|
if build.returncode:
|
|
print(build.stderr[-2000:], file=sys.stderr)
|
|
print('FAIL build')
|
|
return 1
|
|
try:
|
|
run = subprocess.run([str(scratch/'observer')], input=input_text, cwd=scratch, capture_output=True, text=True, timeout=20)
|
|
except subprocess.TimeoutExpired:
|
|
print('audit run_timeout', file=sys.stderr)
|
|
print('FAIL run timeout')
|
|
return 1
|
|
# Do not open/stat/chmod/delete anything in scratch after candidate execution.
|
|
print('audit '+json.dumps(dict(phase='run',exitcode=run.returncode,observations=len(run.stdout.splitlines()),expected=len(expected),stderr_bytes=len(run.stderr.encode()))), file=sys.stderr)
|
|
if run.returncode:
|
|
print(run.stderr[-1500:], file=sys.stderr)
|
|
print('FAIL execution exit='+str(run.returncode))
|
|
return 1
|
|
if run.stderr:
|
|
print('FAIL stderr-only: empty stderr required', file=sys.stderr)
|
|
print('FAIL stderr-only')
|
|
return 1
|
|
actual = run.stdout.splitlines()
|
|
if len(actual) != len(expected):
|
|
print('FAIL output-record-count', file=sys.stderr)
|
|
print('FAIL output-record-count')
|
|
return 1
|
|
for index, (got, want) in enumerate(zip(actual, expected)):
|
|
if got != want:
|
|
print('audit '+json.dumps(dict(phase='behavior',index=index,case=labels[index],command=w.lines[index][:140],got=got[:240],expected=want[:240])), file=sys.stderr)
|
|
print('FAIL behavior '+labels[index]+' index='+str(index))
|
|
return 1
|
|
print('audit '+json.dumps(dict(phase='behavior',status='PASS',checks=len(expected),direct_api_ops=w.ops)), file=sys.stderr)
|
|
print('PASS')
|
|
return 0
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|