One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
315 lines
46 KiB
Python
315 lines
46 KiB
Python
# Root reviewed execution-only reference, adapted per task before freezing.
|
|
# Contains no business model, input matrix, observer, fixture or verdict expectation.
|
|
# Raw child IO is captured; persisted outer/inner length+SHA facts must be reported honestly.
|
|
# Adapt stage deadlines and diagnostic packaging to this task. Run this task's own
|
|
# current-package production diagnostics and formal gates; old source tests are not transfer evidence.
|
|
SUPERVISOR = "import base64,ctypes,hashlib,json,os,signal,subprocess,sys,time\n\ndef stat_pid(pid):\n try:\n data=open('/proc/%d/stat'%pid,'rb').read()\n except (FileNotFoundError,ProcessLookupError):\n return None\n tail=data[data.rfind(b')')+2:].split()\n return dict(pid=pid,state=tail[0].decode('ascii'),ppid=int(tail[1]),pgid=int(tail[2]),start=int(tail[19]))\n\ndef table():\n result={}\n for name in os.listdir('/proc'):\n if name.isdigit():\n row=stat_pid(int(name))\n if row is not None:result[row['pid']]=row\n return result\n\ndef discover(rows,root,tracked):\n roots={root}\n for pid,start in tracked:\n row=rows.get(pid)\n if row and row['start']==start and row['state'] not in ('Z','X'):roots.add(pid)\n selected=set()\n changed=True\n while changed:\n changed=False\n for pid,row in rows.items():\n if pid!=root and pid not in selected and row['ppid'] in roots:\n selected.add(pid);roots.add(pid);changed=True\n for pid,start in tracked:\n row=rows.get(pid)\n if row and row['start']==start:selected.add(pid)\n return {(pid,rows[pid]['start']) for pid in selected}\n\ndef signal_fresh(token):\n pid,start=token\n row=stat_pid(pid)\n if row and row['start']==start and row['state'] not in ('Z','X'):\n try:os.kill(pid,signal.SIGKILL)\n except ProcessLookupError:pass\n\ndef group_present(rows,pgid):\n return any(row['pgid']==pgid for row in rows.values())\n\ndef main():\n raw_request=sys.stdin.buffer.readline()\n request=json.loads(raw_request)\n begin=time.monotonic();proc=None;tracked=set();errors=[];out=b'';err=b'';timed=False\n payload=b'';leader=None;leader_rc=None;reaped=False;desc_absent=False;pg_absent=False\n own=stat_pid(os.getpid())\n try:\n if ctypes.CDLL(None,use_errno=True).prctl(36,1,0,0,0)!=0:raise OSError(ctypes.get_errno(),'subreaper')\n proc=subprocess.Popen(request['argv'],cwd=request['cwd'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,start_new_session=True)\n leader=stat_pid(proc.pid)\n if leader is None:raise RuntimeError('missing leader identity')\n tracked.add((proc.pid,leader['start']))\n payload=base64.b64decode(request['input'],validate=True)\n first=True\n while True:\n tracked |= discover(table(),os.getpid(),tracked)\n remaining=request['deadline']-(time.monotonic()-begin)\n if remaining<=0:\n timed=True\n break\n try:\n out,err=proc.communicate(payload if first else None,timeout=min(.05,remaining))\n leader_rc=proc.returncode;reaped=True\n break\n except subprocess.TimeoutExpired as partial:\n out=partial.output if partial.output is not None else out\n err=partial.stderr if partial.stderr is not None else err\n first=False\n except BaseException as error:\n errors.append(type(error).__name__+':'+str(error))\n finally:\n settle=time.monotonic()+3\n if proc is not None:\n while time.monotonic()<settle:\n try:\n # own Popen status is collected before any adopted waitpid.\n result=proc.poll()\n if result is not None:\n leader_rc=result;reaped=True\n rows=table();tracked|=discover(rows,os.getpid(),tracked)\n for token in sorted(tracked):signal_fresh(token)\n # Draining is required even after poll reaped the leader: descendants may have held its pipes.\n try:\n out,err=proc.communicate(timeout=.03)\n leader_rc=proc.returncode;reaped=True\n except subprocess.TimeoutExpired as partial:\n out=partial.output if partial.output is not None else out\n err=partial.stderr if partial.stderr is not None else err\n if reaped:\n while True:\n try:\n child,_=os.waitpid(-1,os.WNOHANG)\n if child==0:break\n except ChildProcessError:break\n rows=table();current=discover(rows,os.getpid(),tracked)\n tracked|=current\n desc_absent=not current\n pg_absent=not group_present(rows,leader['pgid']) if leader else False\n if reaped and desc_absent and pg_absent:break\n except BaseException as error:\n errors.append(type(error).__name__+':'+str(error))\n time.sleep(.02)\n try:\n rows=table();desc_absent=not discover(rows,os.getpid(),tracked)\n pg_absent=bool(leader) and not group_present(rows,leader['pgid'])\n except BaseException as error:\n errors.append(type(error).__name__+':'+str(error))\n rc=124 if timed else leader_rc if not errors else 125\n result=dict(request_length=len(raw_request),request_sha256=hashlib.sha256(raw_request).hexdigest(),input_length=len(payload),input_sha256=hashlib.sha256(payload).hexdigest(),nonce=request['nonce'],phase=request['phase'],argv=request['argv'],cwd=request['cwd'],deadline=request['deadline'],supervisor_pid=os.getpid(),supervisor_start=own['start'],leader_pid=leader['pid'] if leader else None,leader_start=leader['start'] if leader else None,leader_pgid=leader['pgid'] if leader else None,uid=os.getuid(),gid=os.getgid(),groups=os.getgroups(),leader_returncode=leader_rc,returncode=rc,leader_reaped=reaped,timeout=timed,descendants_absent=desc_absent,pg_absent=pg_absent,exceptions=errors,elapsed=time.monotonic()-begin)\n for name,data in [('stdout',out),('stderr',err)]:\n result[name]=base64.b64encode(data).decode('ascii');result[name+'_length']=len(data);result[name+'_sha256']=hashlib.sha256(data).hexdigest()\n wire=json.dumps(result,separators=(',',':')).encode()\n sys.stdout.buffer.write(wire);sys.stdout.buffer.flush()\nif __name__=='__main__':main()\n"
|
|
import base64, hashlib, json, math, os, random, re, stat, subprocess, sys, tempfile, time, uuid, zlib
|
|
from pathlib import Path
|
|
LAUNCH = 'import json,sys;exec(json.loads(sys.stdin.buffer.readline())["code"])'
|
|
|
|
def sha(data):
|
|
return hashlib.sha256(data).hexdigest()
|
|
|
|
def proc_start(pid):
|
|
try:
|
|
with open('/proc/%d/stat' % pid, 'rb') as stream:
|
|
data = stream.read()
|
|
except (FileNotFoundError, ProcessLookupError):
|
|
return None
|
|
return int(data[data.rfind(b')') + 2:].split()[19])
|
|
|
|
def safe_read(root, name):
|
|
directory = os.open('/', os.O_RDONLY | os.O_DIRECTORY)
|
|
try:
|
|
for component in Path(os.path.abspath(root)).parts[1:]:
|
|
child = os.open(component, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=directory)
|
|
os.close(directory)
|
|
directory = child
|
|
file = os.open(name, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=directory)
|
|
try:
|
|
info = os.fstat(file)
|
|
if not stat.S_ISREG(info.st_mode) or info.st_size > 1048576:
|
|
raise ValueError('source type/size')
|
|
data = b''
|
|
while len(data) <= 1048576:
|
|
block = os.read(file, min(65536, 1048577 - len(data)))
|
|
if not block:
|
|
break
|
|
data += block
|
|
if len(data) > 1048576:
|
|
raise ValueError('source grew')
|
|
return data
|
|
finally:
|
|
os.close(file)
|
|
finally:
|
|
os.close(directory)
|
|
|
|
def validate_integer(value, positive=False):
|
|
if type(value) is not int or (positive and value <= 0):
|
|
raise ValueError('integer metadata')
|
|
|
|
def validate_wire(wire, request, pid, start, identity, request_bytes, payload):
|
|
if type(wire) is not dict:
|
|
raise ValueError('wire object')
|
|
for name in ['nonce', 'phase', 'argv', 'cwd', 'deadline']:
|
|
if wire[name] != request[name]:
|
|
raise ValueError('request mismatch ' + name)
|
|
for (name, data) in [('request', request_bytes), ('input', payload)]:
|
|
validate_integer(wire[name + '_length'])
|
|
if wire[name + '_length'] != len(data) or wire[name + '_sha256'] != sha(data):
|
|
raise ValueError('inner actual bytes mismatch ' + name)
|
|
if type(wire['deadline']) is not int:
|
|
raise ValueError('deadline metadata')
|
|
for name in ['supervisor_pid', 'supervisor_start', 'leader_pid', 'leader_start', 'leader_pgid']:
|
|
validate_integer(wire[name], True)
|
|
if wire['supervisor_pid'] != pid or wire['supervisor_start'] != start:
|
|
raise ValueError('actual Popen binding')
|
|
if wire['leader_pid'] == pid or wire['leader_pgid'] != wire['leader_pid']:
|
|
raise ValueError('leader identity')
|
|
for name in ['uid', 'gid']:
|
|
validate_integer(wire[name])
|
|
groups = wire['groups']
|
|
if type(groups) is not list or any((type(n) is not int for n in groups)):
|
|
raise ValueError('groups metadata')
|
|
if [wire['uid'], wire['gid'], sorted(groups)] != identity:
|
|
raise ValueError('execution identity')
|
|
elapsed = wire['elapsed']
|
|
if type(elapsed) not in (int, float) or not math.isfinite(elapsed) or (not 0 <= elapsed <= request['deadline'] + 4):
|
|
raise ValueError('elapsed metadata')
|
|
for name in ['timeout', 'leader_reaped', 'descendants_absent', 'pg_absent']:
|
|
if type(wire[name]) is not bool:
|
|
raise ValueError('boolean metadata')
|
|
for name in ['returncode', 'leader_returncode']:
|
|
validate_integer(wire[name])
|
|
if wire['returncode'] != (124 if wire['timeout'] else wire['leader_returncode'] if not wire['exceptions'] else 125):
|
|
raise ValueError('returncode inconsistency')
|
|
if type(wire['exceptions']) is not list or any((type(x) is not str for x in wire['exceptions'])):
|
|
raise ValueError('exceptions metadata')
|
|
raw = {}
|
|
for name in ['stdout', 'stderr']:
|
|
size = wire[name + '_length']
|
|
validate_integer(size)
|
|
if size < 0:
|
|
raise ValueError('negative IO length')
|
|
data = base64.b64decode(wire[name], validate=True)
|
|
if len(data) != size or sha(data) != wire[name + '_sha256']:
|
|
raise ValueError('IO bytes mismatch')
|
|
raw[name] = data
|
|
if wire['timeout'] or wire['returncode'] != 0 or wire['leader_returncode'] != 0 or (not all((wire[n] for n in ['leader_reaped', 'descendants_absent', 'pg_absent']))) or wire['exceptions']:
|
|
raise ValueError('controlled stage failure')
|
|
return raw
|
|
|
|
def run_phase(name, argv, cwd, payload, deadline, logs):
|
|
request = dict(nonce=uuid.uuid4().hex, phase=name, argv=argv, cwd=cwd, input=base64.b64encode(payload).decode(), deadline=deadline)
|
|
request_bytes = (json.dumps(request, separators=(',', ':')) + '\n').encode()
|
|
raw = (json.dumps({'code': SUPERVISOR}, separators=(',', ':')) + '\n').encode() + request_bytes
|
|
actual = [sys.executable, '-I', '-c', LAUNCH]
|
|
evidence = dict(phase=name, nonce=request['nonce'], wrapper_argv=actual, wrapper_cwd='/', request_length=len(raw), request_sha256=sha(raw), input_length=len(payload), input_sha256=sha(payload), deadline=deadline, exceptions=[])
|
|
logs.append(evidence)
|
|
begin = time.monotonic()
|
|
proc = None
|
|
try:
|
|
proc = subprocess.Popen(actual, cwd='/', stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
evidence['popen_pid'] = proc.pid
|
|
evidence['popen_start'] = proc_start(proc.pid)
|
|
try:
|
|
(output, diagnostic) = proc.communicate(raw, timeout=deadline + 5)
|
|
except subprocess.TimeoutExpired as error:
|
|
output = error.output or b''
|
|
diagnostic = error.stderr or b''
|
|
evidence.update(wrapper_rc=None, wire_length=len(output), wire_sha256=sha(output), wrapper_stderr_length=len(diagnostic), wrapper_stderr_sha256=sha(diagnostic), outer_timeout=True, inner_cleanup='unknown')
|
|
raise RuntimeError('outer deadline; partial wire retained as length/digest, inner cleanup unknown')
|
|
evidence.update(wrapper_rc=proc.returncode, wire_length=len(output), wire_sha256=sha(output), wrapper_stderr_length=len(diagnostic), wrapper_stderr_sha256=sha(diagnostic), outer_timeout=False)
|
|
wire = json.loads(output)
|
|
evidence['wire'] = {k: v for (k, v) in wire.items() if k not in ('stdout', 'stderr')} if isinstance(wire, dict) else wire
|
|
if proc.returncode != 0 or diagnostic:
|
|
raise ValueError('supervisor wrapper nonzero/diagnostic')
|
|
isolated = os.environ.get('ROLLOUT_GRADE_ISOLATION') == 'uid65534'
|
|
identity = [65534, 65534, []] if isolated else [os.getuid(), os.getgid(), sorted(os.getgroups())]
|
|
data = validate_wire(wire, request, proc.pid, evidence['popen_start'], identity, request_bytes, payload)
|
|
evidence['inner_cleanup'] = 'confirmed'
|
|
return (data['stdout'], data['stderr'])
|
|
except BaseException as error:
|
|
evidence['exceptions'].append(type(error).__name__ + ':' + str(error))
|
|
raise
|
|
finally:
|
|
evidence['outer_elapsed'] = time.monotonic() - begin
|
|
|
|
|
|
PUBLIC = {'progress.hpp': '#ifndef DEVICE_PROGRESS_HPP\n#define DEVICE_PROGRESS_HPP\n#include <array>\n#include <cstddef>\n#include <cstdint>\n#include <iosfwd>\n#include <vector>\nnamespace progress {\nconstexpr std::uint32_t digest_mod = 1000000007;\nconstexpr std::size_t maximum_lanes = 4;\nstruct Job {\n std::uint32_t lane;\n std::uint32_t units;\n std::uint32_t stride;\n std::uint32_t seed;\n std::uint32_t operation;\n};\nstruct Plan {\n std::uint32_t lanes;\n std::uint32_t modulus;\n std::array<std::uint32_t, maximum_lanes> initial{};\n std::vector<Job> jobs;\n};\nstruct WordMetrics {\n std::uint32_t population = 0;\n std::uint32_t runs = 0;\n std::uint32_t leading = 0;\n std::uint32_t trailing = 0;\n std::uint32_t byte_sum = 0;\n};\nWordMetrics measure_word(std::uint32_t word);\nstd::uint32_t crc_word(std::uint32_t crc, std::uint32_t word);\nstruct Statistics {\n std::uint32_t units = 0;\n std::uint32_t digest = 0;\n std::uint32_t minimum = 0;\n std::uint32_t maximum = 0;\n std::uint32_t parity = 0;\n std::uint32_t population = 0;\n std::uint32_t runs = 0;\n std::uint32_t leading = 0;\n std::uint32_t trailing = 0;\n std::uint32_t byte_sum = 0;\n std::uint32_t crc = 65535;\n std::uint32_t changes = 0;\n std::uint32_t rises = 0;\n std::uint32_t falls = 0;\n std::uint32_t repeats = 0;\n std::uint32_t first = 0;\n std::uint32_t last = 0;\n std::uint32_t weighted = 0;\n std::uint32_t even = 0;\n std::uint32_t odd = 0;\n std::array<std::uint32_t, 4> quartiles{};\n};\nstruct JobResult {\n std::uint32_t lane = 0;\n Statistics statistics;\n};\nstruct Report {\n int status = 0;\n std::array<Statistics, maximum_lanes> lanes{};\n std::vector<JobResult> jobs;\n std::uint32_t units = 0;\n std::uint32_t digest = 0;\n};\nvoid accumulate(Statistics& target, std::uint32_t word);\nstd::uint32_t span(const Statistics& value);\nstd::uint32_t dominant_quartile(const Statistics& value);\nstruct Certificate {\n std::uint32_t job = 0;\n std::uint32_t unit = 0;\n std::uint32_t lane = 0;\n std::uint32_t word = 0;\n std::uint32_t digest = 0;\n};\nstd::vector<std::uint8_t> encode_certificate(const Certificate& certificate);\nclass CertificateReceiver {\npublic:\n void consume(std::uint8_t byte);\n const Certificate& last() const;\n std::uint32_t bytes() const;\n std::uint32_t accepted() const;\n std::uint32_t rejected() const;\n std::uint32_t audit() const;\nprivate:\n void close_frame();\n void append(std::uint8_t byte);\n bool active_ = false;\n bool escaped_ = false;\n bool overflow_ = false;\n std::vector<std::uint8_t> payload_;\n Certificate last_;\n std::uint32_t bytes_ = 0;\n std::uint32_t accepted_ = 0;\n std::uint32_t rejected_ = 0;\n std::uint32_t audit_ = 0;\n};\nclass Device;\nclass ProgressRegister {\npublic:\n std::uint32_t read() const volatile;\n void write(std::uint32_t value) volatile;\nprivate:\n friend class Device;\n Device* device_ = nullptr;\n std::uint32_t lane_ = 0;\n};\nstruct BusState {\n std::uint32_t value = 0;\n std::uint32_t reads = 0;\n std::uint32_t writes = 0;\n std::uint32_t latches = 0;\n std::uint32_t audit = 0;\n};\nclass Device {\npublic:\n Device(const Plan& plan, std::ostream& output);\n volatile ProgressRegister& port(std::uint32_t lane);\n void begin(std::uint32_t job, const Job& descriptor);\n void checkpoint(std::uint32_t job, std::uint32_t unit,\n std::uint32_t lane, std::uint32_t word, std::uint32_t digest);\n void end(std::uint32_t job, std::uint32_t lane, const Statistics& statistics);\n void certificate(const std::vector<std::uint8_t>& bytes);\n void dump();\nprivate:\n friend class ProgressRegister;\n std::uint32_t read(std::uint32_t lane);\n void write(std::uint32_t lane, std::uint32_t value);\n void event_prefix(const char* kind);\n void field(std::uint32_t value);\n void finish_event();\n std::array<ProgressRegister, maximum_lanes> ports_{};\n std::array<BusState, maximum_lanes> bus_{};\n std::ostream& output_;\n std::uint32_t lanes_;\n std::uint32_t modulus_;\n std::uint32_t sequence_ = 0;\n std::uint32_t active_job_ = 0;\n std::uint32_t active_lane_ = 0;\n bool active_ = false;\n CertificateReceiver receiver_;\n};\nstd::uint32_t sample_word(const Job& job, std::uint32_t unit);\nint validate(const Plan& plan);\nReport execute(const Plan& plan, Device& device);\n}\n#endif\n', 'observer.cpp': '#include "progress.hpp"\n#include <ostream>\n#include <stdexcept>\nnamespace progress {\nstd::uint32_t ProgressRegister::read() const volatile {\n return device_->read(lane_);\n}\nvoid ProgressRegister::write(std::uint32_t value) volatile {\n device_->write(lane_, value);\n}\nDevice::Device(const Plan& plan, std::ostream& output)\n : output_(output), lanes_(plan.lanes), modulus_(plan.modulus) {\n for (std::uint32_t lane = 0; lane < lanes_; ++lane) {\n ports_[lane].device_ = this;\n ports_[lane].lane_ = lane;\n bus_[lane].value = plan.initial[lane];\n }\n event_prefix("CONFIG");\n field(lanes_);\n field(modulus_);\n finish_event();\n}\nvoid Device::event_prefix(const char* kind) {\n output_ << kind;\n field(sequence_);\n ++sequence_;\n}\nvoid Device::field(std::uint32_t value) {\n output_ << \' \' << value;\n}\nvoid Device::finish_event() {\n output_ << \'\\n\';\n}\nvolatile ProgressRegister& Device::port(std::uint32_t lane) {\n if (lane >= lanes_) {\n throw std::out_of_range("port lane");\n }\n return ports_[lane];\n}\nstd::uint32_t Device::read(std::uint32_t lane) {\n if (lane >= lanes_) {\n throw std::out_of_range("read lane");\n }\n BusState& state = bus_[lane];\n ++state.reads;\n state.audit = (state.audit * 17ULL + state.value + 1) % digest_mod;\n event_prefix("READ");\n field(lane);\n field(state.value);\n field(state.reads);\n field(state.audit);\n finish_event();\n return state.value;\n}\nvoid Device::write(std::uint32_t lane, std::uint32_t value) {\n if (lane >= lanes_ || value >= modulus_) {\n throw std::out_of_range("write domain");\n }\n BusState& state = bus_[lane];\n const std::uint32_t previous = state.value;\n state.value = value;\n ++state.writes;\n state.audit = (state.audit * 19ULL + value + 3) % digest_mod;\n event_prefix("WRITE");\n field(lane);\n field(previous);\n field(value);\n field(state.writes);\n field(state.audit);\n finish_event();\n}\nvoid Device::begin(std::uint32_t job, const Job& descriptor) {\n if (active_) {\n throw std::logic_error("nested job");\n }\n if (descriptor.lane >= lanes_) {\n throw std::out_of_range("begin lane");\n }\n active_ = true;\n active_job_ = job;\n active_lane_ = descriptor.lane;\n event_prefix("BEGIN");\n field(job);\n field(descriptor.lane);\n field(descriptor.units);\n finish_event();\n}\nvoid Device::checkpoint(std::uint32_t job, std::uint32_t unit,\n std::uint32_t lane, std::uint32_t word, std::uint32_t digest) {\n if (!active_ || job != active_job_ || lane != active_lane_) {\n throw std::logic_error("checkpoint scope");\n }\n BusState& state = bus_[lane];\n ++state.latches;\n state.audit = (state.audit * 23ULL + state.value + word + digest) % digest_mod;\n event_prefix("CHECKPOINT");\n field(job);\n field(unit);\n field(lane);\n field(state.value);\n field(word);\n field(digest);\n field(state.latches);\n field(state.audit);\n finish_event();\n}\nvoid Device::end(std::uint32_t job, std::uint32_t lane, const Statistics& statistics) {\n if (!active_ || job != active_job_ || lane != active_lane_) {\n throw std::logic_error("end scope");\n }\n event_prefix("END");\n field(job);\n field(lane);\n field(statistics.units);\n field(statistics.digest);\n finish_event();\n active_ = false;\n}\nvoid Device::certificate(const std::vector<std::uint8_t>& bytes) {\n for (std::uint8_t byte : bytes) {\n receiver_.consume(byte);\n }\n event_prefix("CERTIFICATE");\n field(bytes.size());\n for (std::uint8_t byte : bytes) {\n field(byte);\n }\n const Certificate& decoded = receiver_.last();\n field(decoded.job);\n field(decoded.unit);\n field(decoded.lane);\n field(decoded.word);\n field(decoded.digest);\n field(receiver_.bytes());\n field(receiver_.accepted());\n field(receiver_.rejected());\n field(receiver_.audit());\n finish_event();\n}\nvoid Device::dump() {\n for (std::uint32_t lane = 0; lane < lanes_; ++lane) {\n const BusState& state = bus_[lane];\n event_prefix("BUS");\n field(lane);\n field(state.value);\n field(state.reads);\n field(state.writes);\n field(state.latches);\n field(state.audit);\n finish_event();\n }\n event_prefix("IDLE");\n field(active_ ? 0 : 1);\n finish_event();\n}\n}\n', 'metrics.cpp': '#include "progress.hpp"\n#include <algorithm>\nnamespace progress {\nnamespace {\nstd::uint32_t population(std::uint32_t word) {\n std::uint32_t count = 0;\n for (unsigned bit = 0; bit != 16; ++bit) {\n if (word & (1U << bit)) {\n ++count;\n }\n }\n return count;\n}\nstd::uint32_t runs(std::uint32_t word) {\n std::uint32_t count = 0;\n bool inside = false;\n for (unsigned bit = 0; bit != 16; ++bit) {\n const bool set = (word & (1U << bit)) != 0;\n if (set && !inside) {\n ++count;\n }\n inside = set;\n }\n return count;\n}\nstd::uint32_t leading(std::uint32_t word) {\n std::uint32_t count = 0;\n for (unsigned bit = 16; bit != 0; --bit) {\n if (word & (1U << (bit - 1))) {\n break;\n }\n ++count;\n }\n return count;\n}\nstd::uint32_t trailing(std::uint32_t word) {\n std::uint32_t count = 0;\n for (unsigned bit = 0; bit != 16; ++bit) {\n if (word & (1U << bit)) {\n break;\n }\n ++count;\n }\n return count;\n}\nstd::uint32_t crc_byte(std::uint32_t crc, std::uint32_t byte) {\n crc ^= byte << 8;\n for (unsigned bit = 0; bit != 8; ++bit) {\n const bool carry = (crc & 32768) != 0;\n crc = (crc << 1) & 65535;\n if (carry) {\n crc ^= 4129;\n }\n }\n return crc;\n}\nvoid observe_order(Statistics& target, std::uint32_t word) {\n if (target.units == 0) {\n target.first = word;\n target.minimum = word;\n target.maximum = word;\n } else {\n target.changes += population(target.last ^ word);\n if (word > target.last) {\n ++target.rises;\n } else if (word < target.last) {\n ++target.falls;\n } else {\n ++target.repeats;\n }\n target.minimum = std::min(target.minimum, word);\n target.maximum = std::max(target.maximum, word);\n }\n target.last = word;\n}\nvoid observe_distribution(Statistics& target, std::uint32_t word) {\n const WordMetrics properties = measure_word(word);\n target.population += properties.population;\n target.runs += properties.runs;\n target.leading += properties.leading;\n target.trailing += properties.trailing;\n target.byte_sum += properties.byte_sum;\n if (word % 2 == 0) {\n ++target.even;\n } else {\n ++target.odd;\n }\n const std::size_t bucket = word / 16384;\n ++target.quartiles[bucket];\n}\n}\nWordMetrics measure_word(std::uint32_t word) {\n WordMetrics result;\n result.population = population(word);\n result.runs = runs(word);\n result.leading = leading(word);\n result.trailing = trailing(word);\n result.byte_sum = (word & 255) + (word >> 8);\n return result;\n}\nstd::uint32_t crc_word(std::uint32_t crc, std::uint32_t word) {\n crc = crc_byte(crc, word & 255);\n return crc_byte(crc, word >> 8);\n}\nvoid accumulate(Statistics& target, std::uint32_t word) {\n observe_order(target, word);\n observe_distribution(target, word);\n ++target.units;\n target.parity ^= word;\n target.crc = crc_word(target.crc, word);\n const std::uint64_t mixed = std::uint64_t(target.digest) * 131 + word;\n target.digest = mixed % digest_mod;\n const std::uint64_t weighted = std::uint64_t(target.units) * word + target.weighted;\n target.weighted = weighted % digest_mod;\n}\nstd::uint32_t span(const Statistics& value) {\n if (value.units == 0) {\n return 0;\n }\n return value.maximum - value.minimum;\n}\nstd::uint32_t dominant_quartile(const Statistics& value) {\n std::uint32_t selected = 0;\n std::uint32_t count = value.quartiles[0];\n for (std::uint32_t bucket = 1; bucket < 4; ++bucket) {\n if (value.quartiles[bucket] > count) {\n count = value.quartiles[bucket];\n selected = bucket;\n }\n }\n return selected;\n}\n}\n', 'certificate.cpp': '#include "progress.hpp"\n#include <stdexcept>\nnamespace progress {\nnamespace {\nvoid put16(std::vector<std::uint8_t>& target, std::uint32_t value) {\n target.push_back(value & 255);\n target.push_back((value >> 8) & 255);\n}\nvoid put32(std::vector<std::uint8_t>& target, std::uint32_t value) {\n put16(target, value & 65535);\n put16(target, value >> 16);\n}\nstd::uint32_t get16(const std::vector<std::uint8_t>& data, std::size_t at) {\n const std::uint32_t low = data.at(at);\n const std::uint32_t high = data.at(at + 1);\n return low | (high << 8);\n}\nstd::uint32_t get32(const std::vector<std::uint8_t>& data, std::size_t at) {\n const std::uint32_t low = get16(data, at);\n const std::uint32_t high = get16(data, at + 2);\n return low | (high << 16);\n}\nstd::uint32_t checksum(const std::vector<std::uint8_t>& data, std::size_t count) {\n std::uint32_t crc = 65535;\n for (std::size_t index = 0; index < count; ++index) {\n crc ^= std::uint32_t(data.at(index)) << 8;\n for (unsigned bit = 0; bit < 8; ++bit) {\n const bool carry = (crc & 32768) != 0;\n crc = (crc << 1) & 65535;\n if (carry) {\n crc ^= 4129;\n }\n }\n }\n return crc;\n}\nvoid escaped_byte(std::vector<std::uint8_t>& frame, std::uint8_t byte) {\n if (byte == 126 || byte == 125) {\n frame.push_back(125);\n frame.push_back(byte ^ 32);\n } else {\n frame.push_back(byte);\n }\n}\n}\nstd::vector<std::uint8_t> encode_certificate(const Certificate& certificate) {\n if (certificate.lane > 3 || certificate.job > 63 || certificate.unit > 31) {\n throw std::out_of_range("certificate position");\n }\n if (certificate.word > 65535 || certificate.digest >= digest_mod) {\n throw std::out_of_range("certificate value");\n }\n std::vector<std::uint8_t> payload;\n payload.reserve(12);\n payload.push_back(1);\n payload.push_back(certificate.lane);\n payload.push_back(certificate.job);\n payload.push_back(certificate.unit);\n put16(payload, certificate.word);\n put32(payload, certificate.digest);\n const std::uint32_t crc = checksum(payload, payload.size());\n put16(payload, crc);\n std::vector<std::uint8_t> frame;\n frame.reserve(26);\n frame.push_back(126);\n for (std::uint8_t byte : payload) {\n escaped_byte(frame, byte);\n }\n frame.push_back(126);\n return frame;\n}\nvoid CertificateReceiver::append(std::uint8_t byte) {\n if (payload_.size() >= 12) {\n overflow_ = true;\n return;\n }\n payload_.push_back(byte);\n}\nvoid CertificateReceiver::close_frame() {\n if (escaped_ || overflow_ || payload_.size() != 12) {\n ++rejected_;\n return;\n }\n if (payload_[0] != 1 || payload_[1] > 3 || payload_[2] > 63 || payload_[3] > 31) {\n ++rejected_;\n return;\n }\n if (get16(payload_, 10) != checksum(payload_, 10)) {\n ++rejected_;\n return;\n }\n const std::uint32_t digest = get32(payload_, 6);\n if (digest >= digest_mod) {\n ++rejected_;\n return;\n }\n last_.lane = payload_[1];\n last_.job = payload_[2];\n last_.unit = payload_[3];\n last_.word = get16(payload_, 4);\n last_.digest = digest;\n ++accepted_;\n}\nvoid CertificateReceiver::consume(std::uint8_t byte) {\n ++bytes_;\n audit_ = (std::uint64_t(audit_) * 29 + byte) % digest_mod;\n if (byte == 126) {\n if (active_) {\n close_frame();\n active_ = false;\n } else {\n active_ = true;\n }\n payload_.clear();\n escaped_ = false;\n overflow_ = false;\n return;\n }\n if (!active_) {\n return;\n }\n if (escaped_) {\n append(byte ^ 32);\n escaped_ = false;\n return;\n }\n if (byte == 125) {\n escaped_ = true;\n return;\n }\n append(byte);\n}\nconst Certificate& CertificateReceiver::last() const {\n return last_;\n}\nstd::uint32_t CertificateReceiver::bytes() const {\n return bytes_;\n}\nstd::uint32_t CertificateReceiver::accepted() const {\n return accepted_;\n}\nstd::uint32_t CertificateReceiver::rejected() const {\n return rejected_;\n}\nstd::uint32_t CertificateReceiver::audit() const {\n return audit_;\n}\n}\n', 'main.cpp': '#include "progress.hpp"\n#include <iostream>\n#include <limits>\n#include <sstream>\n#include <string>\n#include <vector>\nnamespace {\nclass Tokens {\npublic:\n explicit Tokens(std::istream& source) : source_(source) {}\n bool number(std::uint32_t& result) {\n std::string token;\n if (!(source_ >> token)) {\n return false;\n }\n std::size_t cursor = 0;\n if (token[cursor] == \'+\') {\n ++cursor;\n }\n if (cursor == token.size()) {\n return false;\n }\n std::uint32_t value = 0;\n while (cursor < token.size()) {\n const unsigned char character = token[cursor];\n if (character < \'0\' || character > \'9\') {\n return false;\n }\n const std::uint32_t digit = character - \'0\';\n if (value > (std::numeric_limits<std::uint32_t>::max() - digit) / 10) {\n return false;\n }\n value = value * 10 + digit;\n ++cursor;\n }\n result = value;\n return true;\n }\n bool exhausted() {\n std::string extra;\n return !(source_ >> extra);\n }\nprivate:\n std::istream& source_;\n};\nbool read_job(Tokens& tokens, progress::Job& job) {\n if (!tokens.number(job.lane)) {\n return false;\n }\n if (!tokens.number(job.units)) {\n return false;\n }\n if (!tokens.number(job.stride)) {\n return false;\n }\n if (!tokens.number(job.seed)) {\n return false;\n }\n return tokens.number(job.operation);\n}\nbool read_plan(Tokens& tokens, progress::Plan& plan) {\n std::uint32_t count = 0;\n if (!tokens.number(plan.lanes)) {\n return false;\n }\n if (!tokens.number(plan.modulus)) {\n return false;\n }\n if (!tokens.number(count)) {\n return false;\n }\n if (plan.lanes > progress::maximum_lanes || count > 64) {\n if (count > 64) {\n plan.jobs.resize(65);\n }\n return true;\n }\n for (std::uint32_t lane = 0; lane < plan.lanes; ++lane) {\n if (!tokens.number(plan.initial[lane])) {\n return false;\n }\n }\n for (std::uint32_t index = 0; index < count; ++index) {\n progress::Job job{};\n if (!read_job(tokens, job)) {\n return false;\n }\n plan.jobs.push_back(job);\n }\n return tokens.exhausted();\n}\nvoid statistics(std::ostream& output, const progress::Statistics& value) {\n output << \' \' << progress::span(value);\n output << \' \' << progress::dominant_quartile(value);\n output << \' \' << value.units;\n output << \' \' << value.digest;\n output << \' \' << value.minimum;\n output << \' \' << value.maximum;\n output << \' \' << value.parity;\n output << \' \' << value.population;\n output << \' \' << value.runs;\n output << \' \' << value.leading;\n output << \' \' << value.trailing;\n output << \' \' << value.byte_sum;\n output << \' \' << value.crc;\n output << \' \' << value.changes;\n output << \' \' << value.rises;\n output << \' \' << value.falls;\n output << \' \' << value.repeats;\n output << \' \' << value.first;\n output << \' \' << value.last;\n output << \' \' << value.weighted;\n output << \' \' << value.even;\n output << \' \' << value.odd;\n for (std::uint32_t bucket : value.quartiles) {\n output << \' \' << bucket;\n }\n}\nvoid print_report(const progress::Plan& plan, const progress::Report& report) {\n std::cout << "RESULT " << report.status << \'\\n\';\n for (std::size_t index = 0; index < report.jobs.size(); ++index) {\n const progress::JobResult& job = report.jobs[index];\n std::cout << "JOB " << index << \' \' << job.lane;\n statistics(std::cout, job.statistics);\n std::cout << \'\\n\';\n }\n for (std::uint32_t lane = 0; lane < plan.lanes; ++lane) {\n std::cout << "LANE " << lane;\n statistics(std::cout, report.lanes[lane]);\n std::cout << \'\\n\';\n }\n std::cout << "TOTAL " << report.units << \' \' << report.digest << \'\\n\';\n}\n}\nint main() {\n Tokens tokens(std::cin);\n progress::Plan plan{};\n if (!read_plan(tokens, plan)) {\n std::cout << "INPUT_ERROR\\n";\n return 2;\n }\n int status = progress::validate(plan);\n if (status != 0) {\n std::cout << "PLAN_ERROR " << status << \'\\n\';\n return 2;\n }\n try {\n progress::Device device(plan, std::cout);\n progress::Report report = progress::execute(plan, device);\n device.dump();\n print_report(plan, report);\n return report.status == 0 ? 0 : 3;\n } catch (const std::exception& error) {\n std::cerr << error.what() << \'\\n\';\n return 3;\n }\n}\n'}
|
|
COMPILER_DEADLINE = 20
|
|
CANDIDATE_DEADLINE = 15
|
|
CLEANUP_DEADLINE = 8
|
|
ABSENCE_DEADLINE = 8
|
|
DRIVER = 'import base64,hashlib,json,subprocess,sys\nitems=json.load(sys.stdin);results=[]\nfor item in items:\n p=subprocess.run([sys.argv[1]],input=base64.b64decode(item),capture_output=True)\n results.append(dict(rc=p.returncode,stdout=base64.b64encode(p.stdout).decode(),stderr_length=len(p.stderr),stderr_sha256=hashlib.sha256(p.stderr).hexdigest()))\n del p\nprint(json.dumps(results,separators=(",",":")))\n'
|
|
CLEANUP = "import shutil,sys;shutil.rmtree(sys.argv[1])"
|
|
ABSENCE = "import os,sys\ntry:os.lstat(sys.argv[1])\nexcept FileNotFoundError:sys.exit(0)\nsys.exit(1)\n"
|
|
|
|
def new_stats():
|
|
return dict(units=0,digest=0,minimum=0,maximum=0,parity=0,population=0,runs=0,leading=0,trailing=0,byte_sum=0,crc=65535,changes=0,rises=0,falls=0,repeats=0,first=0,last=0,weighted=0,even=0,odd=0,quartiles=[0]*4)
|
|
|
|
def pop(value):
|
|
return bin(value).count('1')
|
|
|
|
def account(s,word):
|
|
if not s['units']:
|
|
s.update(first=word,minimum=word,maximum=word)
|
|
else:
|
|
s['changes']+=pop(s['last']^word)
|
|
s['rises']+=word>s['last'];s['falls']+=word<s['last'];s['repeats']+=word==s['last']
|
|
s['minimum']=min(s['minimum'],word);s['maximum']=max(s['maximum'],word)
|
|
s['last']=word;s['units']+=1
|
|
s['digest']=(s['digest']*131+word)%1000000007
|
|
s['parity']^=word;s['population']+=pop(word)
|
|
s['runs']+=pop(word & ~(word << 1))
|
|
s['leading']+=16-word.bit_length()
|
|
s['trailing']+=16 if not word else (word & -word).bit_length()-1
|
|
s['byte_sum']+=(word&255)+(word>>8)
|
|
for byte in (word&255,word>>8):
|
|
s['crc']^=byte<<8
|
|
for _ in range(8):s['crc']=((s['crc']<<1)^(4129 if s['crc']&32768 else 0))&65535
|
|
s['weighted']=(s['weighted']+s['units']*word)%1000000007
|
|
s['even']+=word%2==0;s['odd']+=word%2!=0;s['quartiles'][word//16384]+=1
|
|
|
|
def summary(s):
|
|
buckets=s['quartiles'];dominant=buckets.index(max(buckets))
|
|
keys=('units','digest','minimum','maximum','parity','population','runs','leading','trailing','byte_sum','crc','changes','rises','falls','repeats','first','last','weighted','even','odd')
|
|
return [s['maximum']-s['minimum'] if s['units'] else 0,dominant]+[s[k] for k in keys]+buckets
|
|
|
|
def word_for(job,unit):
|
|
lane,units,stride,seed,op=job
|
|
b=(seed+unit*109+lane*13)%65536
|
|
if op==0:return ((b&255)*257+(b>>8))%65536
|
|
if op==1:
|
|
value=b^42405;shift=unit%16
|
|
return ((value<<shift)|(value>>(16-shift)))&65535
|
|
return (((b&255)<<8)|(b>>8))^((unit*17)&65535)
|
|
|
|
def expected(plan):
|
|
lanes,modulus,initial,jobs=plan
|
|
lines=[];received_bytes=0;receive_audit=0;accepted=0;states=[dict(value=v,reads=0,writes=0,latches=0,audit=0) for v in initial]
|
|
lane_stats=[new_stats() for _ in initial];job_stats=[];total_units=0;total_digest=0
|
|
def event(kind,*args):lines.append([kind,len(lines),*args])
|
|
event('CONFIG',lanes,modulus)
|
|
for index,job in enumerate(jobs):
|
|
lane,units,stride,seed,op=job;s=new_stats();state=states[lane]
|
|
event('BEGIN',index,lane,units)
|
|
for unit in range(units):
|
|
word=word_for(job,unit);account(s,word);account(lane_stats[lane],word)
|
|
total_units+=1;total_digest=(total_digest*137+word+lane)%1000000007
|
|
old=state['value'];state['reads']+=1;state['audit']=(state['audit']*17+old+1)%1000000007
|
|
event('READ',lane,old,state['reads'],state['audit'])
|
|
value=(old+stride)%modulus;state['value']=value;state['writes']+=1
|
|
state['audit']=(state['audit']*19+value+3)%1000000007
|
|
event('WRITE',lane,old,value,state['writes'],state['audit'])
|
|
state['latches']+=1;state['audit']=(state['audit']*23+value+word+s['digest'])%1000000007
|
|
event('CHECKPOINT',index,unit,lane,value,word,s['digest'],state['latches'],state['audit'])
|
|
payload=bytes([1,lane,index,unit])+word.to_bytes(2,'little')+s['digest'].to_bytes(4,'little')
|
|
crc=65535
|
|
for byte in payload:
|
|
crc^=byte<<8
|
|
for _ in range(8):crc=((crc<<1)^(4129 if crc&32768 else 0))&65535
|
|
frame=[126]
|
|
for byte in payload+crc.to_bytes(2,'little'):
|
|
frame.extend([125,byte^32] if byte in (125,126) else [byte])
|
|
frame.append(126);received_bytes+=len(frame);accepted+=1
|
|
for byte in frame:receive_audit=(receive_audit*29+byte)%1000000007
|
|
event('CERTIFICATE',len(frame),*frame,index,unit,lane,word,s['digest'],received_bytes,accepted,0,receive_audit)
|
|
event('END',index,lane,units,s['digest']);job_stats.append((lane,s))
|
|
for lane,state in enumerate(states):event('BUS',lane,*[state[k] for k in ('value','reads','writes','latches','audit')])
|
|
event('IDLE',1);lines.append(['RESULT',0])
|
|
for index,(lane,s) in enumerate(job_stats):lines.append(['JOB',index,lane,*summary(s)])
|
|
for lane,s in enumerate(lane_stats):lines.append(['LANE',lane,*summary(s)])
|
|
lines.append(['TOTAL',total_units,total_digest]);return lines
|
|
|
|
def cases():
|
|
result=[(1,17,[0],[]),(1,17,[0],[(0,4,1,19,0)]),(2,7,[6,1],[(0,3,5,41,1),(1,0,2,7,0),(0,2,3,99,2)]),
|
|
(4,2,[0,1,0,1],[(i%4,32,31,65535,i%3) for i in range(12)]),
|
|
(4,65536,[65535,0,32768,17],[(i%4,i%33,(i%31)+1,(i*1009)%65536,i%3) for i in range(64)])]
|
|
randomizer=random.Random(27002)
|
|
for i in range(12):
|
|
n=randomizer.randrange(1,5);m=randomizer.choice([3,7,17,257,65521,65536]);initial=[randomizer.randrange(m) for _ in range(n)]
|
|
jobs=[(randomizer.randrange(n),randomizer.randrange(33),randomizer.randrange(1,32),randomizer.randrange(65536),randomizer.randrange(3)) for _ in range(9)]
|
|
result.append((n,m,initial,jobs))
|
|
return result
|
|
|
|
def encode(plan):
|
|
lanes,modulus,initial,jobs=plan
|
|
return (' '.join(map(str,[lanes,modulus,len(jobs),*initial,*[v for job in jobs for v in job]]))+'\n').encode()
|
|
|
|
def decimal(raw):
|
|
if not re.fullmatch(rb'\+?[0-9]+',raw):raise ValueError('decimal token syntax')
|
|
normal=raw.lstrip(b'+').lstrip(b'0') or b'0'
|
|
if len(normal)>12:raise ValueError('numeric observation out of range')
|
|
return int(normal)
|
|
|
|
def observations(raw):
|
|
rows=[]
|
|
# Public C++ classic locale recognizes exactly ASCII HT LF VT FF CR SP.
|
|
for line in raw.split(b'\n'):
|
|
tokens=re.findall(rb'[^\x09\x0b\x0c\x0d\x20]+',line)
|
|
if not tokens:continue
|
|
label=tokens[0].decode('ascii')
|
|
rows.append([label,*[decimal(t) for t in tokens[1:]]])
|
|
return rows
|
|
|
|
def main():
|
|
logs=[];scratch=None;failure=None;business=False;clean=False;absent=False;exceptions=[];checks=0;program_stderr=[]
|
|
try:
|
|
source=safe_read(sys.argv[1],'engine.cpp')
|
|
plans=cases();inputs=[encode(p) for p in plans];answers=[expected(p) for p in plans]
|
|
# Invalid configurations are checked through the same public executable.
|
|
invalid=[(b'0 17 0\n',b'PLAN_ERROR 1\n'),(b'5 17 0\n',b'PLAN_ERROR 1\n'),
|
|
(b'1 1 0 0\n',b'PLAN_ERROR 2\n'),(b'1 1 65\n',b'PLAN_ERROR 2\n'),(b'1 17 65\n',b'PLAN_ERROR 3\n'),
|
|
(b'1 17 0 17\n',b'PLAN_ERROR 4\n'),(b'1 17 1 0 1 1 1 0 0\n',b'PLAN_ERROR 5\n'),
|
|
(b'1 17 1 0 0 33 1 0 0\n',b'PLAN_ERROR 6\n'),(b'1 17 1 0 0 1 0 0 0\n',b'PLAN_ERROR 7\n'),
|
|
(b'1 17 1 0 0 1 1 65536 0\n',b'PLAN_ERROR 8\n'),(b'1 17 1 0 0 1 1 0 3\n',b'PLAN_ERROR 9\n'),
|
|
(b'1_0 17 0\n',b'INPUT_ERROR\n'),(b'-1 17 0\n',b'INPUT_ERROR\n'),(b'1 17 0 0 extra\n',b'INPUT_ERROR\n')]
|
|
payload=json.dumps([base64.b64encode(x).decode() for x in inputs+[x[0] for x in invalid]],separators=(',',':')).encode()
|
|
scratch=tempfile.mkdtemp(prefix='device-visible-progress-')
|
|
build=Path(scratch)/'build';build.mkdir();build.chmod(0o777)
|
|
for name,content in PUBLIC.items():(build/name).write_text(content)
|
|
(build/'engine.cpp').write_bytes(source)
|
|
argv=['g++','-std=c++17','-O2','-Wall','-Wextra','-pedantic','engine.cpp','observer.cpp','metrics.cpp','certificate.cpp','main.cpp','-o','demo']
|
|
run_phase('compiler',argv,str(build),b'',COMPILER_DEADLINE,logs)
|
|
output,diagnostic=run_phase('candidate',[sys.executable,'-I','-c',DRIVER,str(build/'demo')],str(build),payload,CANDIDATE_DEADLINE,logs)
|
|
outcomes=json.loads(output)
|
|
if type(outcomes) is not list or len(outcomes)!=len(inputs)+len(invalid):raise ValueError('result batch shape')
|
|
for outcome in outcomes:
|
|
if type(outcome) is not dict or type(outcome.get('rc')) is not int:
|
|
raise ValueError('per-program returncode metadata')
|
|
size=outcome.get('stderr_length');digest=outcome.get('stderr_sha256')
|
|
if type(size) is not int or size<0 or type(digest) is not str or not re.fullmatch('[0-9a-f]{64}',digest):
|
|
raise ValueError('per-program stderr metadata')
|
|
program_stderr.append(dict(returncode=outcome['rc'],length=size,sha256=digest))
|
|
for index,answer in enumerate(answers):
|
|
actual=outcomes[index]
|
|
if type(actual) is not dict or type(actual.get('rc')) is not int or actual['rc']!=0:raise ValueError('candidate nonzero case '+str(index))
|
|
rows=observations(base64.b64decode(actual['stdout'],validate=True));checks+=len(answer)
|
|
if rows!=answer:
|
|
mismatch=next((i for i,(a,b) in enumerate(zip(rows,answer)) if a!=b),min(len(rows),len(answer)))
|
|
failure='normal observation difference case=%d row=%d actual=%r expected=%r'%(index,mismatch,rows[mismatch:mismatch+1],answer[mismatch:mismatch+1]);break
|
|
if failure is None:
|
|
for result,(_,want) in zip(outcomes[len(inputs):],invalid):
|
|
checks+=1
|
|
if type(result.get('rc')) is not int or result['rc']!=2 or observations(base64.b64decode(result['stdout'],validate=True))!=observations(want):raise ValueError('invalid plan refusal')
|
|
business=True
|
|
except BaseException as error:
|
|
exceptions.append(type(error).__name__+':'+str(error));failure=failure or exceptions[-1]
|
|
finally:
|
|
if scratch is not None:
|
|
try:
|
|
run_phase('cleanup',[sys.executable,'-I','-c',CLEANUP,scratch],'/',b'',CLEANUP_DEADLINE,logs);clean=True
|
|
except BaseException as error:exceptions.append('cleanup:'+type(error).__name__+':'+str(error))
|
|
try:
|
|
run_phase('absence',[sys.executable,'-I','-c',ABSENCE,scratch],'/',b'',ABSENCE_DEADLINE,logs);absent=True
|
|
except BaseException as error:exceptions.append('absence:'+type(error).__name__+':'+str(error))
|
|
evidence=dict(stages=logs,program_stderr=program_stderr,checks=checks,business=business,cleanup=clean,absence=absent,exceptions=exceptions,failure=failure)
|
|
packed=base64.b64encode(zlib.compress(json.dumps(evidence,separators=(',',':')).encode(),9)).decode()
|
|
sys.stderr.write('META64 '+packed+'\n')
|
|
if business and clean and absent and not exceptions and all(not row['exceptions'] for row in logs):
|
|
print('PASS');return 0
|
|
print('FAIL '+str(failure or exceptions or 'incomplete evidence')[:250]);return 1
|
|
if __name__=='__main__':sys.exit(main())
|