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>
268 lines
15 KiB
Python
268 lines
15 KiB
Python
import os
|
|
from pathlib import Path
|
|
import random
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
OBSERVER = '#include "engine.hpp"\n#include <charconv>\n#include <iostream>\n#include <sstream>\n#include <string>\n#include <vector>\n#include <map>\nusing namespace ordered;\nstatic void print_job(const JobView& v) {\n std::cout << \' \' << v.id << \' \' << static_cast<int>(v.state) << \' \' << v.total\n << \' \' << v.remaining << \' \' << v.value << \' \' << v.ticket;\n}\nint main() {\n Engine engine;\n const std::map<std::string, std::size_t> arities = {\n {"C", 2}, {"S", 4}, {"W", 2}, {"X", 2}, {"F", 2},\n {"D", 1}, {"J", 2}, {"Q", 1}, {"L", 1}, {"E", 2}\n };\n std::string line;\n while (std::getline(std::cin, line)) {\n std::istringstream stream(line);\n std::vector<std::string> tokens;\n std::string token;\n while (stream >> token) tokens.push_back(token);\n if (tokens.empty()) {\n std::cout << "INPUT\\n";\n continue;\n }\n auto arity = arities.find(tokens[0]);\n if (arity == arities.end() || tokens.size() != arity->second + 1) {\n std::cout << "INPUT\\n";\n continue;\n }\n std::vector<Number> v;\n bool parsed = true;\n for (std::size_t i = 1; i < tokens.size(); ++i) {\n Number number = 0;\n const auto& item = tokens[i];\n auto result = std::from_chars(item.data(), item.data() + item.size(), number);\n if (result.ec != std::errc{} || result.ptr != item.data() + item.size()) {\n parsed = false;\n }\n v.push_back(number);\n }\n if (!parsed) {\n std::cout << "INPUT\\n";\n continue;\n }\n const auto& op = tokens[0];\n if (op == "C" || op == "S" || op == "X" || op == "F") {\n Code r = Code::Ok;\n if (op == "C") r = engine.create(v[0], v[1]);\n if (op == "S") r = engine.submit(v[0], v[1], v[2], v[3]);\n if (op == "X") r = engine.cancel(v[0], v[1]);\n if (op == "F") r = engine.release(v[0], v[1]);\n std::cout << "R " << static_cast<int>(r) << \'\\n\';\n } else if (op == "W" || op == "D") {\n auto r = op == "W" ? engine.work(v[0], v[1]) : engine.destroy(v[0]);\n std::cout << "W " << static_cast<int>(r.code) << \' \' << r.spent << \' \' << r.finished << \'\\n\';\n } else if (op == "J") {\n auto r = engine.job(v[0], v[1]);\n std::cout << "J " << static_cast<int>(r.code);\n print_job(r);\n std::cout << \'\\n\';\n } else if (op == "Q") {\n auto s = engine.stats(v[0]);\n std::cout << "Q " << static_cast<int>(s.code) << \' \' << s.capacity << \' \' << s.closed\n << \' \' << s.accepted << \' \' << s.started << \' \' << s.completed\n << \' \' << s.cancelled << \' \' << s.released << \' \' << s.waiting\n << \' \' << s.running << \' \' << s.retained << \' \' << s.ticks << \' \' << s.total_value << \'\\n\';\n } else if (op == "L") {\n auto r = engine.jobs(v[0]);\n std::cout << "L " << static_cast<int>(r.code) << \' \' << r.entries.size();\n for (const auto& j : r.entries) print_job(j);\n std::cout << \'\\n\';\n } else if (op == "E") {\n auto r = engine.events(v[0], v[1]);\n std::cout << "E " << static_cast<int>(r.code) << \' \' << r.entries.size();\n for (const auto& e : r.entries) {\n std::cout << \' \' << e.serial << \' \' << e.queue << \' \' << e.job << \' \'\n << static_cast<int>(e.kind) << \' \' << e.ticket << \' \' << e.remaining\n << \' \' << e.ticks << \' \' << e.value;\n }\n std::cout << \'\\n\';\n }\n }\n}\n'
|
|
|
|
class Model:
|
|
def __init__(self):
|
|
self.queues = {}
|
|
self.history = []
|
|
|
|
def log(self, q, j, kind):
|
|
self.history.append([len(self.history) + 1, q['id'], j['id'] if j else 0,
|
|
kind, j['ticket'] if j else 0, j['remaining'] if j else 0,
|
|
q['ticks'], j['value'] if j else 0])
|
|
|
|
def advance(self, q, budget):
|
|
spent = finished = 0
|
|
while budget:
|
|
live = [j for j in q['jobs'].values() if j['state'] in (1, 2)]
|
|
if not live:
|
|
break
|
|
j = min(live, key=lambda x: (x['state'] != 2, x['ticket']))
|
|
if j['state'] == 1:
|
|
j['state'] = 2
|
|
q['started'] += 1
|
|
self.log(q, j, 2)
|
|
delta = min(budget, j['remaining'])
|
|
j['remaining'] -= delta
|
|
budget -= delta
|
|
spent += delta
|
|
q['ticks'] += delta
|
|
if not j['remaining']:
|
|
j['state'] = 3
|
|
q['completed'] += 1
|
|
q['total_value'] += j['value']
|
|
finished += 1
|
|
self.log(q, j, 3)
|
|
return ['W', 0, spent, finished]
|
|
|
|
@staticmethod
|
|
def jfields(j):
|
|
return [j[k] for k in ('id', 'state', 'total', 'remaining', 'value', 'ticket')]
|
|
|
|
def call(self, text):
|
|
t = text.split()
|
|
sizes = dict(C=2, S=4, W=2, X=2, F=2, D=1, J=2, Q=1, L=1, E=2)
|
|
if not t or t[0] not in sizes or len(t) != sizes[t[0]] + 1:
|
|
return ['INPUT']
|
|
op = t[0]
|
|
v = []
|
|
for token in t[1:]:
|
|
digits = token[1:] if token.startswith('-') else token
|
|
if not digits or any(c not in '0123456789' for c in digits):
|
|
return ['INPUT']
|
|
value = int(token)
|
|
if not -(1 << 63) <= value < (1 << 63):
|
|
return ['INPUT']
|
|
v.append(value)
|
|
def error(c):
|
|
if op in ('C', 'S', 'X', 'F'):
|
|
return ['R', c]
|
|
if op in ('W', 'D'):
|
|
return ['W', c, 0, 0]
|
|
if op == 'J':
|
|
return ['J', c, 0, 1, 0, 0, 0, 0]
|
|
if op == 'Q':
|
|
return ['Q', c] + [0] * 12
|
|
return [op, c, 0]
|
|
if op == 'E':
|
|
after, limit = v
|
|
if after < 0 or not 0 <= limit <= 256:
|
|
return error(1)
|
|
entries = [e for e in self.history if e[0] > after][:limit]
|
|
return ['E', 0, len(entries)] + [x for e in entries for x in e]
|
|
qid = v[0]
|
|
bad = not 1 <= qid <= 8
|
|
if op in ('S', 'X', 'F', 'J'):
|
|
bad |= not 1 <= v[1] <= 1000000000
|
|
if op == 'S':
|
|
bad |= not 1 <= v[2] <= 1000000 or not -1000000000 <= v[3] <= 1000000000
|
|
if op == 'C':
|
|
bad |= not 1 <= v[1] <= 64
|
|
if op == 'W':
|
|
bad |= not 0 <= v[1] <= 1000000
|
|
if bad:
|
|
return error(1)
|
|
q = self.queues.get(qid)
|
|
if op == 'C':
|
|
if q:
|
|
return error(3)
|
|
self.queues[qid] = dict(id=qid, capacity=v[1], closed=0, accepted=0, started=0,
|
|
completed=0, cancelled=0, released=0, ticks=0,
|
|
total_value=0, next=1, jobs={})
|
|
return error(0)
|
|
if q is None:
|
|
return error(2)
|
|
records = q['jobs']
|
|
if op == 'S':
|
|
_, jid, units, value = v
|
|
if q['closed']:
|
|
return error(4)
|
|
if jid in records:
|
|
return error(3)
|
|
live = sum(j['state'] in (1, 2) for j in records.values())
|
|
if live >= q['capacity'] or len(records) >= 256:
|
|
return error(5)
|
|
j = dict(id=jid, state=1, total=units, remaining=units, value=value, ticket=q['next'])
|
|
q['next'] += 1
|
|
records[jid] = j
|
|
q['accepted'] += 1
|
|
self.log(q, j, 1)
|
|
return error(0)
|
|
if op == 'W':
|
|
if q['closed']:
|
|
return error(4)
|
|
return self.advance(q, v[1])
|
|
if op == 'D':
|
|
if q['closed']:
|
|
return error(0)
|
|
remaining = sum(j['remaining'] for j in records.values() if j['state'] in (1, 2))
|
|
result = self.advance(q, remaining)
|
|
q['closed'] = 1
|
|
self.log(q, None, 6)
|
|
return result
|
|
if op in ('J', 'X', 'F'):
|
|
j = records.get(v[1])
|
|
if j is None:
|
|
return error(6)
|
|
if op == 'J':
|
|
return ['J', 0] + self.jfields(j)
|
|
if op == 'X':
|
|
if j['state'] == 2:
|
|
return error(7)
|
|
if j['state'] != 1:
|
|
return error(8)
|
|
j['state'] = 4
|
|
q['cancelled'] += 1
|
|
self.log(q, j, 4)
|
|
else:
|
|
if j['state'] in (1, 2):
|
|
return error(7)
|
|
self.log(q, j, 5)
|
|
del records[v[1]]
|
|
q['released'] += 1
|
|
return error(0)
|
|
if op == 'L':
|
|
entries = sorted(records.values(), key=lambda j: j['ticket'])
|
|
return ['L', 0, len(entries)] + [x for j in entries for x in self.jfields(j)]
|
|
waiting = sum(j['state'] == 1 for j in records.values())
|
|
running = sum(j['state'] == 2 for j in records.values())
|
|
return ['Q', 0] + [q[k] for k in ('capacity', 'closed', 'accepted', 'started', 'completed',
|
|
'cancelled', 'released')] + [waiting, running, len(records), q['ticks'], q['total_value']]
|
|
|
|
|
|
def cases():
|
|
yield ['C 1 3', 'S 1 41 1 12', 'S 1 7 1 -8', 'S 1 99 1 23', 'W 1 3', 'E 0 32', 'Q 1']
|
|
yield ['C 2 4', 'S 2 9 8 91', 'S 2 3 4 -4', 'S 2 6 7 2', 'W 2 2', 'J 2 9',
|
|
'X 2 9', 'F 2 9', 'X 2 6', 'X 2 6', 'F 2 6', 'S 2 6 2 9', 'L 2',
|
|
'D 2', 'Q 2', 'L 2', 'D 2', 'W 2 0', 'S 2 9 1 0', 'X 2 9',
|
|
'F 2 9', 'F 2 9', 'J 2 9', 'C 2 4', 'E 0 256', 'E 5 4', 'E 999999 2']
|
|
yield ['C 1 1', 'W 1 0', 'S 1 8 6 -1000000000', 'W 1 0', 'S 1 2 1 8',
|
|
'W 1 5', 'Q 1', 'S 1 2 1 8', 'W 1 1', 'Q 1', 'J 1 8', 'S 1 2 1 8',
|
|
'W 1 1', 'W 1 1000000', 'F 1 8', 'S 1 8 1 1000000000', 'D 1', 'Q 1', 'L 1', 'E 0 256']
|
|
boundary = ['J 1 1', 'S 1 1 1 1', 'D 1', 'Q 9', 'C 0 1', 'C 9 2', 'C 1 0',
|
|
'C 1 65', 'C 1 64', 'C 1 0', 'S 1 0 1 0', 'S 1 1000000001 1 0',
|
|
'S 1 1 0 0', 'S 1 1 1000001 0', 'S 1 1 1 -1000000001',
|
|
'S 1 1 1 1000000001', 'W 1 -1', 'W 1 1000001', 'E -1 1', 'E 0 257',
|
|
'E 0 -1', 'E 0 0', 'E 9223372036854775807 256', 'S 1 1 1000000 -1000000000',
|
|
'S 1 1 0 0', 'S 1 1 1 1', 'J 1 1', 'X 1 1', 'F 1 1', 'D 1',
|
|
'S 1 1 0 0', 'W 1 -1', 'X 1 0', 'J 1 1', 'L 1', 'Q 1', 'E 0 256']
|
|
yield boundary
|
|
# Full retained-record table, ownership release, ticket reuse, and pagination.
|
|
bulk = ['C 1 1']
|
|
for i in range(1, 257):
|
|
bulk += [f'S 1 {i} 1 {i - 128}', 'W 1 1']
|
|
bulk += ['S 1 999 1 9', 'F 1 17', 'S 1 17 2 6', 'W 1 1', 'L 1', 'J 1 17',
|
|
'S 1 998 1 9', 'D 1', 'Q 1', 'F 1 17', 'Q 1', 'E 0 0', 'E 0 256',
|
|
'E 256 256', 'E 512 256', 'E 768 256', 'E 1024 256']
|
|
yield bulk
|
|
huge = ['C 8 64'] + [f'S 8 {1000 - i} 1000000 {(-1)**i * 1000000000}' for i in range(64)]
|
|
huge += ['S 8 1 1 1', 'W 8 1', 'W 8 999999', 'Q 8', 'D 8', 'L 8', 'Q 8', 'E 0 256', 'E 15 9']
|
|
yield huge
|
|
yield ['', 'C', 'C 1', 'C 1 2 3', 'C 1x 1', 'C +1 1', 'C 9223372036854775808 1',
|
|
'C -9223372036854775809 1', 'C 1 1 junk', 'C --1 2', 'Z 1', 'C 1 1',
|
|
'S 1 1 1 0 extra', 'S 1 1 1 -0', 'W 1 1x', 'Q 1', 'W 1 1', 'E 0 256']
|
|
rng = random.Random(33177019)
|
|
for scene in range(7):
|
|
commands = [f'C {q} {rng.randint(2, 12)}' for q in range(1, 9)]
|
|
for i in range(650):
|
|
q = rng.randint(1, 8)
|
|
j = rng.randint(1, 30)
|
|
action = rng.randrange(14)
|
|
if action < 5:
|
|
commands.append(f'S {q} {j} {rng.choice([1,2,3,7,19,1000000])} {rng.randint(-1000000000,1000000000)}')
|
|
elif action < 8:
|
|
commands.append(f'W {q} {rng.choice([0,1,2,5,31,1000000])}')
|
|
elif action == 8:
|
|
commands.append(f'X {q} {j}')
|
|
elif action == 9:
|
|
commands.append(f'F {q} {j}')
|
|
elif action == 10:
|
|
commands.append(f'J {q} {j}')
|
|
elif action == 11:
|
|
commands.append(f'L {q}')
|
|
elif action == 12:
|
|
commands.append(f'Q {q}')
|
|
else:
|
|
commands.append(f'E {rng.randint(0, 250)} {rng.choice([0,1,17,256])}')
|
|
if i == 480:
|
|
commands.append(f'D {scene + 1}')
|
|
commands += [f'D {q}' for q in range(1, 9)]
|
|
commands += [f'Q {q}' for q in range(1, 9)]
|
|
commands += [f'L {q}' for q in range(1, 9)]
|
|
commands += [f'E {cursor} 256' for cursor in range(0, 2048, 256)]
|
|
yield commands
|
|
|
|
|
|
def main():
|
|
candidate = Path(sys.argv[1])
|
|
# Complete every scratch read/write before the first compiler child. Never inspect or
|
|
# clean scratch after a child starts; the outer wrapper owns its containing directory.
|
|
source_h = (candidate / 'engine.hpp').read_bytes()
|
|
source_cpp = (candidate / 'engine.cpp').read_bytes()
|
|
traces = list(cases())
|
|
expectations = []
|
|
for trace in traces:
|
|
model = Model()
|
|
expectations.append([[str(x) for x in model.call(line)] for line in trace])
|
|
scratch = Path(tempfile.mkdtemp(prefix='ordered-workqueue-', dir=os.getcwd()))
|
|
(scratch / 'engine.hpp').write_bytes(source_h)
|
|
(scratch / 'engine.cpp').write_bytes(source_cpp)
|
|
(scratch / 'observer.cpp').write_text(OBSERVER)
|
|
executable = str(scratch / 'observe')
|
|
compiled = subprocess.run(['g++', '-std=c++17', '-O2', '-Wall', '-Wextra',
|
|
str(scratch / 'engine.cpp'), str(scratch / 'observer.cpp'),
|
|
'-o', executable], capture_output=True, text=True, timeout=35, cwd=str(scratch))
|
|
if compiled.returncode:
|
|
sys.stderr.write(compiled.stderr[-2000:])
|
|
print('FAIL build')
|
|
return 1
|
|
checked = 0
|
|
for n, (trace, expected) in enumerate(zip(traces, expectations)):
|
|
result = subprocess.run([executable], input='\n'.join(trace) + '\n',
|
|
capture_output=True, text=True, timeout=8, cwd=str(scratch))
|
|
observed = [line.split() for line in result.stdout.splitlines()]
|
|
if result.returncode or observed != expected:
|
|
difference = next((i for i, pair in enumerate(zip(observed, expected)) if pair[0] != pair[1]),
|
|
min(len(observed), len(expected)))
|
|
sys.stderr.write(f'trace={n} line={difference} returncode={result.returncode}\n')
|
|
print('FAIL behavior')
|
|
return 1
|
|
checked += len(trace)
|
|
sys.stderr.write(f'validated {checked} API/observer observations across {len(traces)} fresh Engines\n')
|
|
print('PASS')
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
raise SystemExit(main())
|
|
except subprocess.TimeoutExpired:
|
|
print('FAIL timeout')
|
|
raise SystemExit(1)
|