Batch 28 commit de6f2ac gave ESP FAT image short names and libuv timer turns as MEDIUM; the ESP HTTP response task is being topped up. Batch 28 has 3 MEDIUM and no HARD in 20 measured so far, below batches 26 and 29. Each task comes from the commit Qwen measured, its digest matches, and it is still present at the batch branch head. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
246 lines
10 KiB
Python
246 lines
10 KiB
Python
"""Parent-side timer contract oracle. Candidates only emit observations."""
|
|
import json
|
|
import random
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tarfile
|
|
import tempfile
|
|
|
|
MAX64 = 2**64 - 1
|
|
INTMAX = 2**31 - 1
|
|
EINVAL = -22
|
|
|
|
|
|
class Model:
|
|
def __init__(self):
|
|
self.now = 100
|
|
self.timers = {}
|
|
self.serial = 0
|
|
self.closes = []
|
|
self.lines = ['K -22']
|
|
|
|
def emit(self, *items):
|
|
self.lines.append(' '.join(map(str, items)))
|
|
|
|
def active(self):
|
|
return sum(t['active'] and t['ref'] for t in self.timers.values())
|
|
|
|
def stop(self, timer):
|
|
timer['active'] = False
|
|
timer['pending'] = False
|
|
return 0
|
|
|
|
def start(self, timer, delay, repeat, null=False):
|
|
if null or timer['closing']:
|
|
return EINVAL
|
|
self.stop(timer)
|
|
timer.update(active=True, callback=True, due=min(MAX64, self.now + delay),
|
|
repeat=repeat, serial=self.serial)
|
|
self.serial += 1
|
|
return 0
|
|
|
|
def again(self, timer):
|
|
if not timer['callback']:
|
|
return EINVAL
|
|
if timer['repeat']:
|
|
self.start(timer, timer['repeat'], timer['repeat'])
|
|
return 0
|
|
|
|
def close(self, ident):
|
|
timer = self.timers[ident]
|
|
timer['closing'] = True
|
|
self.stop(timer)
|
|
self.closes.insert(0, ident)
|
|
|
|
def run(self):
|
|
if self.active() or self.closes:
|
|
ready = sorted((t['due'], t['serial'], ident)
|
|
for ident, t in self.timers.items()
|
|
if t['active'] and t['due'] <= self.now)
|
|
for _, _, ident in ready:
|
|
self.timers[ident].update(active=False, pending=True)
|
|
for _, _, ident in ready:
|
|
t = self.timers[ident]
|
|
if not t['pending']:
|
|
continue
|
|
t['pending'] = False
|
|
self.again(t)
|
|
t['calls'] += 1
|
|
self.emit('E', ident, t['calls'], self.now)
|
|
kind, target, delay, repeat, limit, stop = t['action']
|
|
if t['calls'] < limit:
|
|
rc = 0
|
|
if kind == 1:
|
|
rc = self.start(t, delay, repeat)
|
|
elif kind == 2:
|
|
rc = self.start(self.timers[target], delay, repeat)
|
|
elif kind == 3:
|
|
rc = self.stop(self.timers[target])
|
|
elif kind == 4:
|
|
self.close(target)
|
|
elif kind == 5:
|
|
t['repeat'] = repeat
|
|
elif kind == 6:
|
|
rc = self.again(self.timers[target])
|
|
if kind:
|
|
self.emit('D', ident, kind, rc)
|
|
for ident in self.closes:
|
|
self.emit('C', ident)
|
|
self.closes = []
|
|
self.emit('R', int(bool(self.active() or self.closes)))
|
|
|
|
def command(self, line):
|
|
parts = line.split()
|
|
op = parts[0]
|
|
nums = list(map(int, parts[1:]))
|
|
ident = nums[0] if nums else None
|
|
if op == 'I':
|
|
self.timers[ident] = dict(active=False, pending=False, ref=True, closing=False,
|
|
callback=False, repeat=0, calls=0,
|
|
action=(0, 0, 0, 0, 0, 0))
|
|
self.emit('I', ident, 0)
|
|
elif op == 'F':
|
|
self.timers[ident].update(action=tuple(nums[1:]), calls=0)
|
|
self.emit('F', ident)
|
|
elif op == 'T':
|
|
self.now = ident
|
|
self.emit('T', self.now)
|
|
elif op in ('S', 'N'):
|
|
self.emit(op, ident, self.start(self.timers[ident], nums[1], nums[2], op == 'N'))
|
|
elif op == 'X':
|
|
self.emit(op, ident, self.stop(self.timers[ident]))
|
|
elif op == 'A':
|
|
self.emit(op, ident, self.again(self.timers[ident]))
|
|
elif op == 'P':
|
|
self.timers[ident]['repeat'] = nums[1]
|
|
self.emit(op, ident)
|
|
elif op == 'Q':
|
|
t = self.timers[ident]
|
|
self.emit(op, ident, int(t['active']), int(t['closing']), t['repeat'], self.active())
|
|
elif op == 'Z':
|
|
self.close(ident)
|
|
self.emit(op, ident)
|
|
elif op in ('U', 'V'):
|
|
self.timers[ident]['ref'] = op == 'U'
|
|
self.emit(op, ident)
|
|
elif op == 'B':
|
|
if not self.active() or self.closes:
|
|
wait = 0
|
|
else:
|
|
due = [t['due'] for t in self.timers.values() if t['active']]
|
|
wait = min(INTMAX, max(0, min(due)-self.now)) if due else -1
|
|
self.emit('B', wait)
|
|
elif op == 'R':
|
|
self.run()
|
|
else:
|
|
raise ValueError(op)
|
|
|
|
|
|
def cases():
|
|
result = []
|
|
|
|
def add(name, commands):
|
|
if isinstance(commands, str):
|
|
commands = commands.strip().splitlines()
|
|
model = Model()
|
|
for command in commands:
|
|
model.command(command)
|
|
result.append((name, '\n'.join(commands)+'\n', '\n'.join(model.lines)+'\n'))
|
|
|
|
add('normal_smoke', 'I 0\nS 0 5 0\nR\nT 105\nR\nQ 0\nZ 0\nR')
|
|
for active in (False, True):
|
|
for delay, repeat in ((0, 0), (7, 0), (13, 29), (MAX64, MAX64)):
|
|
cmds = ['I 0']
|
|
if active:
|
|
cmds += ['S 0 25 11']
|
|
cmds += ['Z 0', 'Q 0', 'B', 'S 0 %d %d' % (delay, repeat), 'Q 0', 'B', 'R']
|
|
add('closing_%s_%s_%s' % (active,delay,repeat), cmds)
|
|
add('null_and_again', 'I 0\nA 0\nN 0 0 0\nQ 0\nS 0 9 7\nN 0 0 99\nQ 0\nB\nT 109\nR\nQ 0\nB\nX 0\nX 0\nR')
|
|
for stop in (0, 1):
|
|
for delay in (0, 1, 17):
|
|
cmds = ['I 0', 'F 0 1 0 %d 0 4 %d' % (delay,stop), 'S 0 0 0']
|
|
for tick in (100, 100, 101, 117, 134, 151):
|
|
cmds += ['T %d' % tick, 'R', 'Q 0', 'B']
|
|
cmds += ['X 0','R']
|
|
add('self_rearm_%s_%s' % (delay,stop), cmds)
|
|
for kind in (2, 3, 4, 6):
|
|
for target in (1, 3):
|
|
for delay in ((0, 7) if kind == 2 else (0,)):
|
|
cmds = ['I %d' % i for i in range(4)]
|
|
cmds += ['F 0 %d %d %d 0 2 1' % (kind,target,delay)]
|
|
cmds += ['S %d 0 %d' % (i, 5 if kind == 6 and i == target else 0) for i in range(4)]
|
|
cmds += ['R'] + ['Q %d' % i for i in range(4) if not (kind == 4 and i == target)]
|
|
cmds += ['B','R','T 107','R'] + ['X %d' % i for i in range(4) if not (kind == 4 and i == target)] + ['R']
|
|
add('callback_mutation_%s_%s_%s' % (kind,target,delay),cmds)
|
|
add('new_child', 'I 0\nI 1\nF 0 2 1 0 0 2 0\nS 0 0 0\nR\nQ 1\nR\nQ 1\nR')
|
|
add('cross_replace', 'I 0\nI 1\nI 2\nF 0 2 1 0 0 2 0\nF 1 2 2 0 0 2 0\nS 0 0 0\nS 1 0 0\nS 2 0 0\nR\nR\nR\nQ 2')
|
|
add('self_close', 'I 0\nI 1\nF 0 4 0 0 0 2 1\nS 0 0 0\nS 1 0 0\nR\nQ 1\nR')
|
|
add('repeat_and_changes', 'I 0\nS 0 4 6\nB\nT 103\nR\nT 104\nR\nQ 0\nB\nT 140\nR\nQ 0\nB\nP 0 9\nB\nA 0\nB\nT 149\nR\nQ 0\nP 0 0\nB\nA 0\nB\nT 158\nR\nQ 0\nA 0\nR')
|
|
for repeat in (0, 3, MAX64):
|
|
add('repeat_callback_change_%d' % repeat,
|
|
'I 0\nF 0 5 0 0 %d 2 0\nS 0 0 5\nR\nQ 0\nB\nT 105\nR\nQ 0\nB\nT 108\nR\nQ 0\nX 0\nR' % repeat)
|
|
for delay in (0,1,INTMAX-1,INTMAX,INTMAX+1,MAX64-100,MAX64-99,MAX64):
|
|
add('deadline_%d' % delay, 'I 0\nS 0 %d 0\nB\nQ 0\nR\nT 101\nB\nR\nX 0\nB\nR' % delay)
|
|
add('references', 'I 0\nI 1\nS 0 0 0\nV 0\nB\nR\nQ 0\nU 0\nB\nR\nQ 0\nS 0 0 0\nV 0\nS 1 3 0\nR\nQ 0\nQ 1\nT 103\nR\nQ 1\nZ 0\nZ 1\nR')
|
|
rng = random.Random(281103)
|
|
for batch in range(8):
|
|
cmds = ['I %d' % i for i in range(32)]
|
|
for i in rng.sample(list(range(32)),32):
|
|
cmds += ['S %d %d 0' % (i,rng.randrange(0,8))]
|
|
for i in rng.sample(list(range(32)),10):
|
|
cmds += ['X %d' % i,'S %d %d 0' % (i,rng.randrange(0,8))]
|
|
for i in rng.sample(list(range(32)),8):
|
|
cmds += ['X %d' % i]
|
|
for tick in range(100,109):
|
|
cmds += ['T %d' % tick,'B','R']
|
|
cmds += ['Q %d' % i for i in range(32)]
|
|
add('ordering_and_removal_%d' % batch,cmds)
|
|
return result
|
|
|
|
|
|
def main():
|
|
candidate = Path(sys.argv[1])
|
|
observations = cases()
|
|
with tempfile.TemporaryDirectory(prefix='libuv-timer-check-') as temporary:
|
|
work = Path(temporary)
|
|
with tarfile.open(Path(__file__).with_name('support.tar')) as archive:
|
|
for entry in archive.getmembers():
|
|
name = Path(entry.name)
|
|
if not entry.isfile() or name.is_absolute() or '..' in name.parts:
|
|
raise ValueError('invalid private support archive')
|
|
out = work/name
|
|
out.parent.mkdir(parents=True, exist_ok=True)
|
|
out.write_bytes(archive.extractfile(entry).read())
|
|
for name in ('src/timer.c','include/uv/unix.h'):
|
|
out = work/name
|
|
out.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copyfile(candidate/name,out)
|
|
# All source/input material is written before the first candidate process.
|
|
command = ['gcc','-std=gnu99','-O1','-D_GNU_SOURCE','-ffunction-sections','-fdata-sections',
|
|
'-Iinclude','-Isrc','-Isrc/unix','-Itools','src/timer.c','src/uv-common.c',
|
|
'src/unix/core.c','src/unix/loop-watcher.c','tools/clock-backend.c',
|
|
'tools/observe.c','-Wl,--gc-sections','-o','observe']
|
|
result = subprocess.run(command,cwd=work,capture_output=True,text=True,timeout=20)
|
|
if result.returncode:
|
|
print('FAIL build');return 1
|
|
for name, inputs, expected in observations:
|
|
try:
|
|
result = subprocess.run([str(work/'observe')],input=inputs,capture_output=True,
|
|
text=True,cwd=work,timeout=2)
|
|
except subprocess.TimeoutExpired:
|
|
print('FAIL timeout '+name);return 1
|
|
if result.returncode or result.stdout != expected:
|
|
print('FAIL behavior '+name)
|
|
# Diagnostic observations stay in the protected grade.stderr.
|
|
print(json.dumps({'case':name,'returncode':result.returncode,
|
|
'expected':expected[:1600],'observed':result.stdout[:1600]}),file=sys.stderr)
|
|
return 1
|
|
print('PASS')
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
raise SystemExit(main())
|