Batch 21 (20261027-A-bos-redo-21) rebuilt 40 of the 53 rejected Bos-qiao environments: hidden assertions that ran inside the candidate's process now run in a trusted parent that reads observations from a low-UID worker; gold bytes are unchanged. 9 were excluded for scope (ROS2, oversize, security core), 3 are blocked because the source requires an exec bit the platform does not freeze, 1 lacks requests/bs4 in trace6. Batch 18 (20261026-C-hwe-codegen-18) adds its last 34 of 134 tasks; the first 100 landed in 2f32624d. Claude reviewed 74/74 USABLE against current digests, canonical families, no ID or source overlap with main, plain public docs. Only the new task directories are taken; the stale pre-batch-20 copies of concur-release-capsule and resource-temp-link on the batch 21 branch and both branches' progress notes stay as main has them. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
732 lines
31 KiB
Python
732 lines
31 KiB
Python
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import random
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
FILES = ['include/buffer_model.hpp', 'src/model_detail.hpp', 'src/resource_store.cpp',
|
|
'src/session_store.cpp', 'src/buffer_engine.cpp', 'src/command_protocol.cpp']
|
|
SOURCES = FILES[2:]
|
|
DOMAINS = {
|
|
'create': [7, 4096], 'drop': [7], 'open': [15, 7], 'close': [15],
|
|
'seek': [15, 4096], 'write': [15, 4096, 255], 'read': [15, 4096],
|
|
'resize': [7, 4096], 'block': [1], 'device': [7], 'session': [15], 'pool': []}
|
|
MINIMUM = -(1 << 63)
|
|
MAXIMUM = (1 << 63) - 1
|
|
NAMES = ['OK', 'RANGE', 'EXISTS', 'ABSENT', 'BUSY', 'NOSPACE']
|
|
|
|
OBSERVER = r'''#include "buffer_model.hpp"
|
|
#include <iomanip>
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <array>
|
|
using namespace buffer_capacity;
|
|
std::string encode(const std::string& bytes) {
|
|
const char* digits = "0123456789abcdef";
|
|
std::string result;
|
|
for (unsigned char byte : bytes) {
|
|
result.push_back(digits[byte >> 4]);
|
|
result.push_back(digits[byte & 15]);
|
|
}
|
|
return result.empty() ? "-" : result;
|
|
}
|
|
std::string decode(const std::string& text) {
|
|
std::string result;
|
|
if (text == "-") return result;
|
|
for (std::size_t i = 0; i < text.size(); i += 2) {
|
|
result.push_back(static_cast<char>(std::stoul(text.substr(i, 2), nullptr, 16)));
|
|
}
|
|
return result;
|
|
}
|
|
int main() {
|
|
std::array<std::unique_ptr<Engine>, 2> engines;
|
|
std::string line;
|
|
while (std::getline(std::cin, line)) {
|
|
std::istringstream command(line);
|
|
int index = 0;
|
|
std::string name;
|
|
command >> index >> name;
|
|
if (name == "new") {
|
|
engines[index].reset(new Engine);
|
|
std::cout << "N\n";
|
|
continue;
|
|
}
|
|
if (name == "destroy") {
|
|
engines[index].reset();
|
|
std::cout << "X\n";
|
|
continue;
|
|
}
|
|
Engine& engine = *engines[index];
|
|
std::int64_t a = 0, b = 0, c = 0;
|
|
if (name == "cli") {
|
|
int flags = 0;
|
|
std::string encoded;
|
|
command >> flags >> encoded;
|
|
std::istringstream input(decode(encoded));
|
|
std::ostringstream output;
|
|
if (flags) {
|
|
output << std::hex << std::showbase << std::showpos << std::uppercase
|
|
<< std::setfill('*') << std::setw(19);
|
|
}
|
|
const int result = run_cli(engine, input, output);
|
|
const std::string bytes = output.str();
|
|
std::cout << "C " << result << " " << bytes.size() << " " << encode(bytes) << "\n";
|
|
} else if (name == "pool") {
|
|
const auto result = engine.pool();
|
|
std::cout << "P " << result.blocked << " " << result.live_count
|
|
<< " " << result.resources.size();
|
|
for (const auto& resource : result.resources) {
|
|
std::cout << " " << resource.allocation << " " << resource.device << " " << resource.capacity;
|
|
}
|
|
std::cout << "\n";
|
|
} else if (name == "device") {
|
|
command >> a;
|
|
const auto result = engine.device(a);
|
|
std::cout << "D " << static_cast<std::int64_t>(result.status) << " " << result.value.id
|
|
<< " " << result.value.capacity << " " << result.value.allocation << "\n";
|
|
} else if (name == "session") {
|
|
command >> a;
|
|
const auto result = engine.session(a);
|
|
std::cout << "H " << static_cast<std::int64_t>(result.status) << " " << result.value.id
|
|
<< " " << result.value.device << " " << result.value.cursor << "\n";
|
|
} else if (name == "read") {
|
|
command >> a >> b;
|
|
const auto result = engine.read(a, b);
|
|
std::string bytes(result.bytes.begin(), result.bytes.end());
|
|
std::cout << "R " << static_cast<std::int64_t>(result.status) << " " << result.bytes.size()
|
|
<< " " << encode(bytes) << "\n";
|
|
} else if (name == "write") {
|
|
command >> a >> b >> c;
|
|
const auto result = engine.write(a, b, c);
|
|
std::cout << "W " << static_cast<std::int64_t>(result.status) << " " << result.count << "\n";
|
|
} else {
|
|
command >> a >> b;
|
|
Status result = Status::OK;
|
|
if (name == "create") result = engine.create(a, b);
|
|
else if (name == "drop") result = engine.drop(a);
|
|
else if (name == "open") result = engine.open(a, b);
|
|
else if (name == "close") result = engine.close(a);
|
|
else if (name == "seek") result = engine.seek(a, b);
|
|
else if (name == "resize") result = engine.resize(a, b);
|
|
else if (name == "block") result = engine.set_allocation_blocked(a);
|
|
std::cout << "S " << static_cast<std::int64_t>(result) << "\n";
|
|
}
|
|
}
|
|
}
|
|
'''
|
|
MAIN = '#include "buffer_model.hpp"\n#include <iostream>\nint main() { buffer_capacity::Engine e; return buffer_capacity::run_cli(e, std::cin, std::cout); }\n'
|
|
|
|
|
|
class Model:
|
|
def __init__(self):
|
|
self.devices = {}
|
|
self.sessions = {}
|
|
self.blocked = 0
|
|
self.cli_calls = []
|
|
|
|
def failure(self, name, status):
|
|
if name == 'write':
|
|
return status, 0
|
|
if name == 'read':
|
|
return status, b''
|
|
if name in ('device', 'session'):
|
|
return status, 0, 0, 0
|
|
return (status,)
|
|
|
|
def free(self):
|
|
occupied = {record[0] for record in self.devices.values()}
|
|
return next(n for n in range(1, 10) if n not in occupied)
|
|
|
|
def call(self, name, *args):
|
|
if any(a < 0 or a > maximum for a, maximum in zip(args, DOMAINS[name])):
|
|
return self.failure(name, 1)
|
|
if name == 'block':
|
|
self.blocked = args[0]
|
|
return (0,)
|
|
if name == 'pool':
|
|
resources = sorted((allocation, d, len(data)) for d, (allocation, data)
|
|
in self.devices.items() if allocation)
|
|
return self.blocked, len(resources), resources
|
|
a = args[0]
|
|
if name == 'create':
|
|
capacity = args[1]
|
|
if a in self.devices:
|
|
return (2,)
|
|
if capacity and self.blocked:
|
|
return (5,)
|
|
allocation = self.free() if capacity else 0
|
|
self.devices[a] = [allocation, bytearray(capacity)]
|
|
return (0,)
|
|
if name in ('drop', 'resize', 'device'):
|
|
if a not in self.devices:
|
|
return self.failure(name, 3)
|
|
allocation, data = self.devices[a]
|
|
if name == 'device':
|
|
return 0, a, len(data), allocation
|
|
if name == 'drop':
|
|
if any(device == a for device, cursor in self.sessions.values()):
|
|
return (4,)
|
|
del self.devices[a]
|
|
return (0,)
|
|
capacity = args[1]
|
|
if capacity == len(data):
|
|
return (0,)
|
|
if capacity and self.blocked:
|
|
return (5,)
|
|
next_id = self.free() if capacity else 0
|
|
self.devices[a] = [next_id, data[:capacity] + bytearray(max(0, capacity - len(data)))]
|
|
return (0,)
|
|
if name == 'open':
|
|
if a in self.sessions:
|
|
return (2,)
|
|
if args[1] not in self.devices:
|
|
return (3,)
|
|
self.sessions[a] = [args[1], 0]
|
|
return (0,)
|
|
if a not in self.sessions:
|
|
return self.failure(name, 3)
|
|
device, cursor = self.sessions[a]
|
|
data = self.devices[device][1]
|
|
if name == 'session':
|
|
return 0, a, device, cursor
|
|
if name == 'close':
|
|
del self.sessions[a]
|
|
return (0,)
|
|
if name == 'seek':
|
|
if args[1] > len(data):
|
|
return (1,)
|
|
self.sessions[a][1] = args[1]
|
|
return (0,)
|
|
if name == 'read':
|
|
amount = max(0, min(args[1], len(data) - cursor))
|
|
result = bytes(data[cursor:cursor + amount])
|
|
self.sessions[a][1] += amount
|
|
return 0, result
|
|
count, byte = args[1:]
|
|
if count == 0:
|
|
return 0, 0
|
|
if cursor > len(data) or count > len(data) - cursor:
|
|
return 5, 0
|
|
data[cursor:cursor + count] = bytes([byte]) * count
|
|
self.sessions[a][1] += count
|
|
return 0, count
|
|
|
|
def cli(self, data):
|
|
self.cli_calls = []
|
|
if not data:
|
|
return b''
|
|
lines = data.split(b'\n')
|
|
if lines[-1] == b'':
|
|
lines.pop()
|
|
output = []
|
|
for index, line in enumerate(lines):
|
|
if index == 4096:
|
|
output.append('ERR LIMIT')
|
|
break
|
|
if len(line) > 256 or any(c != 9 and not 32 <= c <= 126 for c in line):
|
|
output.append('ERR SYNTAX')
|
|
continue
|
|
tokens = re.findall(rb'[^ \t]+', line)
|
|
name = tokens[0].decode('ascii') if tokens else ''
|
|
if name not in DOMAINS or len(tokens) != len(DOMAINS[name]) + 1:
|
|
output.append('ERR SYNTAX')
|
|
continue
|
|
if any(re.fullmatch(rb'-?[0-9]+', token) is None for token in tokens[1:]):
|
|
output.append('ERR SYNTAX')
|
|
continue
|
|
args = [int(token) for token in tokens[1:]]
|
|
if any(value < MINIMUM or value > MAXIMUM for value in args):
|
|
output.append('ERR SYNTAX')
|
|
continue
|
|
result = self.call(name, *args)
|
|
self.cli_calls.append((name, args, result))
|
|
if name == 'pool':
|
|
text = 'OK %d %d' % result[:2]
|
|
text += ''.join(' %d:%d:%d' % resource for resource in result[2])
|
|
elif result[0]:
|
|
text = 'ERR ' + NAMES[result[0]]
|
|
elif name == 'write':
|
|
text = 'OK %d' % result[1]
|
|
elif name == 'read':
|
|
text = 'OK %d %s' % (len(result[1]), result[1].hex() or '-')
|
|
elif name in ('device', 'session'):
|
|
text = 'OK ' + ' '.join(str(n) for n in result[1:])
|
|
else:
|
|
text = 'OK'
|
|
output.append(text)
|
|
return ('\n'.join(output) + '\n').encode('ascii')
|
|
|
|
|
|
def raw(name, result):
|
|
if name == 'pool':
|
|
values = [result[0], result[1], len(result[2])]
|
|
values.extend(value for record in result[2] for value in record)
|
|
return 'P ' + ' '.join(str(value) for value in values) + '\n'
|
|
if name == 'read':
|
|
return 'R %d %d %s\n' % (result[0], len(result[1]), result[1].hex() or '-')
|
|
prefix = {'write': 'W', 'device': 'D', 'session': 'H'}.get(name, 'S')
|
|
return prefix + ' ' + ' '.join(str(value) for value in result) + '\n'
|
|
|
|
|
|
class Script:
|
|
def __init__(self):
|
|
self.models = [None, None]
|
|
self.lines = []
|
|
self.output = []
|
|
self.direct = []
|
|
self.cli_calls = []
|
|
self.cli_invocations = 0
|
|
|
|
def new(self, index):
|
|
self.models[index] = Model()
|
|
self.lines.append('%d new\n' % index)
|
|
self.output.append('N\n')
|
|
|
|
def destroy(self, index):
|
|
self.models[index] = None
|
|
self.lines.append('%d destroy\n' % index)
|
|
self.output.append('X\n')
|
|
|
|
def add(self, index, name, *args):
|
|
self.lines.append('%d %s%s\n' % (index, name, ''.join(' ' + str(a) for a in args)))
|
|
result = self.models[index].call(name, *args)
|
|
self.output.append(raw(name, result))
|
|
self.direct.append((index, name, list(args), result[0] if name != 'pool' else None))
|
|
return result
|
|
|
|
def cli(self, index, data, flags=0):
|
|
self.lines.append('%d cli %d %s\n' % (index, flags, data.hex() or '-'))
|
|
output = self.models[index].cli(data)
|
|
self.output.append('C 0 %d %s\n' % (len(output), output.hex() or '-'))
|
|
self.cli_calls.extend(self.models[index].cli_calls)
|
|
self.cli_invocations += 1
|
|
|
|
def probe(self, index):
|
|
model = self.models[index]
|
|
for device in range(8):
|
|
self.add(index, 'device', device)
|
|
for session in range(16):
|
|
self.add(index, 'session', session)
|
|
self.add(index, 'pool')
|
|
|
|
for session in sorted(model.sessions):
|
|
device, cursor = model.sessions[session]
|
|
capacity = len(model.devices[device][1])
|
|
self.add(index, 'read', session, 7)
|
|
self.add(index, 'session', session)
|
|
if cursor <= capacity:
|
|
self.add(index, 'seek', session, 0)
|
|
self.add(index, 'read', session, 4096)
|
|
self.add(index, 'seek', session, cursor)
|
|
self.add(index, 'session', session)
|
|
self.add(index, 'pool')
|
|
|
|
def allocation_probe(self, index):
|
|
model = self.models[index]
|
|
free_device = next((d for d in range(8) if d not in model.devices), None)
|
|
if free_device is None:
|
|
return
|
|
blocked = model.blocked
|
|
self.add(index, 'block', 0)
|
|
self.add(index, 'create', free_device, 3)
|
|
self.add(index, 'device', free_device)
|
|
self.add(index, 'pool')
|
|
self.add(index, 'drop', free_device)
|
|
self.add(index, 'block', blocked)
|
|
self.add(index, 'pool')
|
|
|
|
|
|
def background(script):
|
|
for index in (0, 1):
|
|
script.new(index)
|
|
script.add(index, 'create', 0, 24 + index)
|
|
script.add(index, 'create', 7, 31 + index)
|
|
for session, device in [(0, 0), (3, 0), (8, 0), (5, 7), (15, 7)]:
|
|
script.add(index, 'open', session, device)
|
|
script.add(index, 'write', 0, 24 + index, 70 + index)
|
|
script.add(index, 'write', 15, 31 + index, 120 + index)
|
|
script.add(index, 'seek', 3, 5)
|
|
script.add(index, 'write', 3, 3, 250)
|
|
for session, cursor in [(0, 2), (3, 7), (8, 11), (5, 5), (15, 13)]:
|
|
script.add(index, 'seek', session, cursor)
|
|
script.add(index, 'block', index)
|
|
|
|
|
|
def endpoint_script(script):
|
|
for device in (0, 7):
|
|
script.new(0)
|
|
script.add(0, 'create', device, 0)
|
|
script.add(0, 'device', device)
|
|
script.add(0, 'open', 0, device)
|
|
script.add(0, 'read', 0, 0)
|
|
script.add(0, 'resize', device, 4096)
|
|
script.add(0, 'read', 0, 4096)
|
|
script.add(0, 'seek', 0, 0)
|
|
script.add(0, 'write', 0, 4096, 255)
|
|
script.add(0, 'seek', 0, 0)
|
|
script.add(0, 'read', 0, 4096)
|
|
script.add(0, 'seek', 0, 0)
|
|
script.add(0, 'write', 0, 4096, 0)
|
|
script.add(0, 'seek', 0, 0)
|
|
script.add(0, 'read', 0, 4096)
|
|
script.add(0, 'session', 0)
|
|
script.add(0, 'close', 0)
|
|
script.add(0, 'drop', device)
|
|
script.add(0, 'create', device, 4096)
|
|
script.add(0, 'open', 15, device)
|
|
script.add(0, 'write', 15, 4096, 255)
|
|
script.add(0, 'seek', 15, 0)
|
|
script.add(0, 'write', 15, 4096, 0)
|
|
script.add(0, 'seek', 15, 0)
|
|
script.add(0, 'read', 15, 4096)
|
|
script.add(0, 'write', 15, 0, 255)
|
|
script.add(0, 'read', 15, 0)
|
|
script.add(0, 'seek', 15, 0)
|
|
script.add(0, 'seek', 15, 4096)
|
|
script.add(0, 'session', 15)
|
|
script.add(0, 'resize', device, 0)
|
|
script.add(0, 'read', 15, 4096)
|
|
script.add(0, 'write', 15, 0, 0)
|
|
script.add(0, 'resize', device, 4096)
|
|
script.add(0, 'seek', 15, 0)
|
|
script.add(0, 'read', 15, 4096)
|
|
script.add(0, 'block', 1)
|
|
script.add(0, 'resize', device, 4096)
|
|
script.add(0, 'pool')
|
|
script.add(0, 'block', 0)
|
|
script.add(0, 'close', 15)
|
|
script.add(0, 'drop', device)
|
|
|
|
|
|
BASE_ARGS = {'create': [4, 9], 'drop': [4], 'open': [2, 4], 'close': [3],
|
|
'seek': [3, 2], 'write': [3, 2, 100], 'read': [3, 2],
|
|
'resize': [0, 16], 'block': [1], 'device': [0], 'session': [3], 'pool': []}
|
|
PRIORITY_CASES = [('create', [0, -1]), ('open', [0, 8]), ('resize', [4, -1]),
|
|
('write', [2, -1, 1]), ('write', [2, 1, -1]), ('write', [0, 0, 256]),
|
|
('write', [2, 0, 0]), ('read', [2, 0]), ('read', [2, -1]),
|
|
('seek', [2, -1]), ('resize', [4, 0])]
|
|
CLI_STATE_ERRORS = [b'create 0 9', b'open 3 7', b'drop 7']
|
|
|
|
|
|
def bad_lines():
|
|
lines = [b'', b' \t', b'unknown', b'CREATE 1 1', b'pool\r', b'pool\x00',
|
|
b'pool\x0b', b'pool\x0c', b'pool\x1f', b'pool\x7f', b'pool\xff',
|
|
b' ' * 253 + b'pool']
|
|
for name, args in BASE_ARGS.items():
|
|
tokens = [name] + [str(value) for value in args]
|
|
lines.append((' '.join(tokens + ['9'])).encode())
|
|
if args:
|
|
lines.append((' '.join(tokens[:-1])).encode())
|
|
for position in range(len(args)):
|
|
for bad in ['x', '+1', '1.0', '1x', '-', str(MINIMUM - 1), str(MAXIMUM + 1)]:
|
|
edited = tokens[:]
|
|
edited[position + 1] = bad
|
|
lines.append(' '.join(edited).encode())
|
|
return lines
|
|
|
|
|
|
def cli_endpoints():
|
|
lines = []
|
|
for device in (0, 7):
|
|
lines += ['create %d 0' % device, 'open 0 %d' % device,
|
|
'device %d' % device, 'session 0', 'read 0 0', 'close 0',
|
|
'resize %d 4096' % device, 'open 15 %d' % device,
|
|
'write 15 4096 255', 'seek 15 0', 'read 15 4096',
|
|
'seek 15 0', 'write 15 4096 0', 'seek 15 0', 'read 15 4096',
|
|
'seek 15 0', 'seek 15 4096', 'read 15 4096', 'write 15 0 255', 'read 15 0',
|
|
'seek 15 0', 'write 15 1 255', 'seek 15 0', 'read 15 1',
|
|
'session 15', 'pool', 'block 1', 'resize %d 4096' % device,
|
|
'block 0', 'resize %d 0' % device, 'read 15 4096',
|
|
'resize %d 4096' % device, 'seek 15 0', 'read 15 4096',
|
|
'close 15', 'drop %d' % device, 'create %d 4096' % device,
|
|
'open 0 %d' % device, 'write 0 4096 255', 'seek 0 0',
|
|
'write 0 4096 0', 'seek 0 0', 'read 0 4096', 'close 0', 'drop %d' % device]
|
|
return ('\n'.join(lines) + '\n').encode()
|
|
|
|
|
|
def limits():
|
|
maximum = ['create 0 4', 'open 0 0', 'write 0 4 255', 'seek 0 0']
|
|
maximum += ['seek 0 0', 'write 0 1 1', 'seek 0 1', 'write 0 1 2'] * 1023
|
|
mixed = [b'create 0 4', b'open 0 0', b'write 0 4 77', b'seek 0 0']
|
|
pattern = [b'', b'unknown', b'write 0', b'write 0 1 x', b'pool\x00',
|
|
b'x' * 257, b'close 14', b'device 0', b'read 0 0', b'pool']
|
|
while len(mixed) < 4095:
|
|
mixed.append(pattern[(len(mixed) - 4) % len(pattern)])
|
|
mixed += [b'write 0 1 0', b'write 0 1 255', b'resize 0 8', b'close 0', b'drop 0']
|
|
return ('\n'.join(maximum) + '\n').encode(), b'\n'.join(mixed)
|
|
|
|
|
|
def build_scenes():
|
|
script = Script()
|
|
script.new(0)
|
|
script.new(1)
|
|
script.probe(0)
|
|
script.probe(1)
|
|
endpoint_script(script)
|
|
failure_args = {'create': [0, 8], 'drop': [0], 'open': [0, 0], 'close': [0],
|
|
'seek': [0, 3], 'write': [0, 2, 0], 'read': [0, 2],
|
|
'resize': [0, 8], 'block': [0], 'device': [0], 'session': [0]}
|
|
for name, maxima in DOMAINS.items():
|
|
for position, maximum in enumerate(maxima):
|
|
for value in [-1, maximum + 1, MINIMUM, MAXIMUM]:
|
|
background(script)
|
|
args = failure_args[name][:]
|
|
args[position] = value
|
|
script.add(0, name, *args)
|
|
script.probe(0)
|
|
script.probe(1)
|
|
script.allocation_probe(0)
|
|
failures = [('create', [0, 9]), ('drop', [4]), ('drop', [0]),
|
|
('open', [0, 4]), ('open', [2, 4]), ('close', [2]),
|
|
('seek', [2, 1]), ('seek', [0, 25]), ('write', [2, 1, 1]),
|
|
('write', [0, 23, 1]), ('read', [2, 1]), ('resize', [4, 8]),
|
|
('device', [4]), ('session', [2])] + PRIORITY_CASES
|
|
for name, args in failures:
|
|
background(script)
|
|
script.add(0, name, *args)
|
|
script.probe(0)
|
|
script.probe(1)
|
|
script.allocation_probe(0)
|
|
for name, args in [('create', [4, 8]), ('resize', [0, 40]), ('resize', [0, 8])]:
|
|
background(script)
|
|
script.add(0, 'block', 1)
|
|
script.add(0, name, *args)
|
|
script.probe(0)
|
|
script.probe(1)
|
|
script.add(0, 'resize', 0, 24)
|
|
script.add(0, 'create', 4, 0)
|
|
script.add(0, 'resize', 0, 0)
|
|
script.probe(0)
|
|
script.add(0, 'resize', 0, 12)
|
|
script.probe(0)
|
|
script.add(0, 'block', 0)
|
|
script.add(0, 'resize', 0, 12)
|
|
script.probe(0)
|
|
background(script)
|
|
script.add(0, 'close', 0)
|
|
script.add(0, 'open', 0, 7)
|
|
script.probe(0)
|
|
script.probe(1)
|
|
background(script)
|
|
for session in (1, 2, 4, 6, 7, 9, 10, 11, 12, 13, 14):
|
|
script.add(0, 'open', session, 0)
|
|
for session in range(16):
|
|
script.add(0, 'seek', session, (session + 1) if session != 15 else 31)
|
|
script.add(0, 'seek', 8, 24)
|
|
script.add(0, 'resize', 0, 8)
|
|
script.probe(0)
|
|
script.probe(1)
|
|
for session in [3, 7, 8, 9, 14]:
|
|
script.add(0, 'write', session, 0, 0)
|
|
script.add(0, 'write', session, 1, 255)
|
|
script.add(0, 'seek', session, 24)
|
|
script.add(0, 'read', session, 4096)
|
|
script.add(0, 'session', session)
|
|
script.probe(0)
|
|
script.add(0, 'resize', 0, 0)
|
|
script.probe(0)
|
|
script.add(0, 'resize', 0, 4096)
|
|
script.probe(0)
|
|
script.new(0)
|
|
for device in range(8):
|
|
script.add(0, 'create', device, device + 1)
|
|
script.add(0, 'open', device, device)
|
|
script.add(0, 'write', device, device + 1, 10 + device)
|
|
script.add(0, 'seek', device, 1)
|
|
script.probe(0)
|
|
script.add(0, 'resize', 0, 9)
|
|
script.probe(0)
|
|
script.add(0, 'resize', 1, 12)
|
|
script.probe(0)
|
|
script.add(0, 'close', 2)
|
|
script.add(0, 'drop', 2)
|
|
script.add(0, 'create', 2, 4)
|
|
script.add(0, 'open', 2, 2)
|
|
script.probe(0)
|
|
script.probe(1)
|
|
script.destroy(0)
|
|
script.probe(1)
|
|
script.new(0)
|
|
rng = random.Random(0x18C104)
|
|
for index in range(600):
|
|
name = rng.choice(list(DOMAINS))
|
|
choices = {'create': [7, 64], 'drop': [7], 'open': [15, 7], 'close': [15],
|
|
'seek': [15, 65], 'write': [15, 66, 255], 'read': [15, 65],
|
|
'resize': [7, 64], 'block': [1], 'device': [7], 'session': [15], 'pool': []}
|
|
args = [rng.randrange(maximum + 1) for maximum in choices[name]]
|
|
script.add(index % 2, name, *args)
|
|
background(script)
|
|
for line in CLI_STATE_ERRORS:
|
|
script.cli(0, line, flags=1)
|
|
script.probe(0)
|
|
script.probe(1)
|
|
script.allocation_probe(0)
|
|
for line in bad_lines():
|
|
script.cli(0, line + b'\n', flags=1)
|
|
script.probe(0)
|
|
script.probe(1)
|
|
script.allocation_probe(0)
|
|
for name, maxima in DOMAINS.items():
|
|
for position, maximum in enumerate(maxima):
|
|
for value in [-1, maximum + 1, MINIMUM, MAXIMUM]:
|
|
args = BASE_ARGS[name][:]
|
|
args[position] = value
|
|
line = (name + ''.join(' ' + str(n) for n in args)).encode()
|
|
script.cli(0, line, flags=1)
|
|
script.probe(0)
|
|
script.probe(1)
|
|
script.allocation_probe(0)
|
|
script.cli(0, b'pool', flags=1)
|
|
for name, args in PRIORITY_CASES:
|
|
script.cli(0, (name + ''.join(' ' + str(n) for n in args)).encode(), flags=1)
|
|
script.probe(0)
|
|
script.probe(1)
|
|
script.allocation_probe(0)
|
|
script.cli(0, b'write 0 x 0', flags=1)
|
|
script.probe(0)
|
|
script.probe(1)
|
|
script.cli(0, b' \tdevice\t0000 \t\nseek -0 -0\nread -0 0003\n' + b' ' * 252 + b'pool\n', flags=1)
|
|
script.cli(0, b'device ' + b'0' * 249 + b'\ndevice -' + b'0' * 248, flags=1)
|
|
script.probe(0)
|
|
script.cli(0, b'', flags=1)
|
|
script.probe(0)
|
|
script.new(0)
|
|
endpoints = cli_endpoints()
|
|
script.cli(0, endpoints, flags=1)
|
|
script.probe(0)
|
|
maximum_input, mixed = limits()
|
|
script.new(0)
|
|
script.cli(0, maximum_input, flags=1)
|
|
script.probe(0)
|
|
script.cli(0, b'seek 0 0\nwrite 0 1 99\nseek 0 0\nread 0 4', flags=1)
|
|
script.probe(0)
|
|
script.new(0)
|
|
script.cli(0, mixed, flags=1)
|
|
script.probe(0)
|
|
script.cli(0, b'seek 0 0\nread 0 4\nwrite 0 0 0\npool', flags=1)
|
|
script.probe(0)
|
|
script.probe(1)
|
|
smoke = b'create 0 6\nopen 0 0\nwrite 0 6 65\nseek 0 0\nblock 1\nresize 0 10\ndevice 0\nsession 0\npool\nread 0 6\nblock 0\nclose 0\ndrop 0\npool\n'
|
|
regular = endpoints + b'create 0 24\ncreate 7 31\nopen 0 0\nopen 3 0\nopen 8 0\nopen 5 7\nopen 15 7\nwrite 0 24 70\nwrite 15 31 120\nseek 0 2\nseek 3 7\nseek 8 11\nseek 5 5\nseek 15 13\n'
|
|
for line in CLI_STATE_ERRORS:
|
|
regular += line + b'\ndevice 0\ndevice 7\nsession 0\nsession 3\nsession 8\nsession 5\nsession 15\npool\n'
|
|
for session, cursor, capacity in [(0, 2, 24), (3, 7, 24), (8, 11, 24), (5, 5, 31), (15, 13, 31)]:
|
|
regular += ('seek %d 0\nread %d %d\nseek %d %d\n' % (session, session, capacity, session, cursor)).encode()
|
|
for line in bad_lines():
|
|
regular += line + b'\ndevice 0\nsession 3\npool\n'
|
|
for name, maxima in DOMAINS.items():
|
|
for position, maximum in enumerate(maxima):
|
|
for value in [-1, maximum + 1, MINIMUM, MAXIMUM]:
|
|
args = BASE_ARGS[name][:]
|
|
args[position] = value
|
|
regular += (name + ''.join(' ' + str(n) for n in args) + '\ndevice 0\nsession 3\npool\n').encode()
|
|
for name, args in PRIORITY_CASES:
|
|
regular += (name + ''.join(' ' + str(n) for n in args) + '\ndevice 0\nsession 3\npool\n').encode()
|
|
regular += b' \tdevice\t0000 \t\nseek -0 -0\nread -0 0003\n' + b' ' * 252 + b'pool\n'
|
|
regular += b'write 0 x 0\nseek 0 0\nread 0 24\nseek 15 0\nread 15 31\npool'
|
|
scenes = [{'name': 'api', 'exe': 2, 'input': ''.join(script.lines).encode(),
|
|
'expected': ''.join(script.output).encode()}]
|
|
cli_statuses = [result[0] for name, args, result in script.cli_calls if name != 'pool']
|
|
for name, data in [('cli', regular), ('empty', b''), ('max', maximum_input), ('mixed', mixed), ('smoke', smoke)]:
|
|
model = Model()
|
|
scenes.append({'name': name, 'exe': 3, 'input': data, 'expected': model.cli(data)})
|
|
cli_statuses.extend(result[0] for method, args, result in model.cli_calls if method != 'pool')
|
|
endpoints_ok = {}
|
|
ranges_ok = {}
|
|
cli_endpoints_ok = {}
|
|
for name, maxima in DOMAINS.items():
|
|
for position, maximum in enumerate(maxima):
|
|
key = name + '.' + str(position)
|
|
endpoints_ok[key] = {str(value): any(method == name and args[position] == value and status == 0
|
|
for engine, method, args, status in script.direct)
|
|
for value in [0, maximum]}
|
|
ranges_ok[key] = {str(value): any(method == name and args[position] == value and status == 1
|
|
for engine, method, args, status in script.direct)
|
|
for value in [-1, maximum + 1, MINIMUM, MAXIMUM]}
|
|
cli_endpoints_ok[key] = {str(value): any(method == name and args[position] == value and result[0] == 0
|
|
for method, args, result in script.cli_calls)
|
|
for value in [0, maximum]}
|
|
coverage = {'direct_calls': len(script.direct), 'cli_invocations': script.cli_invocations,
|
|
'api_endpoints': endpoints_ok, 'api_ranges': ranges_ok, 'cli_endpoints': cli_endpoints_ok,
|
|
'cli_statuses': sorted(set(cli_statuses)),
|
|
'cli_status_counts': {str(status): cli_statuses.count(status) for status in range(6)},
|
|
'trace': script.direct, 'standalone_cli_lines': regular.count(b'\n') + 1}
|
|
return scenes, coverage
|
|
|
|
|
|
def summary(data):
|
|
return [len(data), hashlib.sha256(data).hexdigest()[:16]]
|
|
|
|
|
|
def verify(candidate, selected=None):
|
|
candidate = Path(candidate)
|
|
scenes, coverage = build_scenes()
|
|
if selected is not None:
|
|
scenes = [scene for scene in scenes if scene['name'] in selected]
|
|
for kind in ['api_endpoints', 'api_ranges', 'cli_endpoints']:
|
|
if not all(all(values.values()) for values in coverage[kind].values()):
|
|
raise RuntimeError('incomplete generated coverage: ' + kind)
|
|
if coverage['cli_statuses'] != list(range(6)):
|
|
raise RuntimeError('incomplete actual CLI status coverage')
|
|
scratch = Path(tempfile.mkdtemp(prefix='buffer-', dir=Path.cwd()))
|
|
for name in FILES:
|
|
target = scratch / name
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.write_bytes((candidate / name).read_bytes())
|
|
(scratch / 'api.cpp').write_text(OBSERVER)
|
|
(scratch / 'main.cpp').write_text(MAIN)
|
|
argv = [
|
|
['c++', '-std=c++17', '-O2', '-Iinclude'] + SOURCES + ['api.cpp', '-o', 'observe'],
|
|
['c++', '-std=c++17', '-O2', '-Iinclude'] + SOURCES + ['main.cpp', '-o', 'bufferctl'],
|
|
['./observe'], ['./bufferctl']]
|
|
records = []
|
|
reasons = []
|
|
first = {}
|
|
|
|
def process(name, which, data, expected, seconds, build=False):
|
|
proc = subprocess.Popen(argv[which], cwd=str(scratch), stdin=subprocess.PIPE,
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
timed_out = False
|
|
try:
|
|
out, err = proc.communicate(data, timeout=seconds)
|
|
except subprocess.TimeoutExpired:
|
|
timed_out = True
|
|
proc.kill()
|
|
out, err = proc.communicate()
|
|
records.append([name, proc.pid, which, proc.returncode, int(timed_out),
|
|
summary(data), summary(expected), summary(out), summary(err)])
|
|
if timed_out:
|
|
reasons.append([name, 'timeout'])
|
|
if proc.returncode != 0:
|
|
reasons.append([name, 'exit', proc.returncode])
|
|
if not build:
|
|
if out != expected:
|
|
offset = next((i for i, (a, b) in enumerate(zip(out, expected)) if a != b), min(len(out), len(expected)))
|
|
reasons.append([name, 'out', offset])
|
|
first[name] = [expected[offset:offset + 12].hex(), out[offset:offset + 12].hex()]
|
|
if err:
|
|
reasons.append([name, 'err'])
|
|
return proc.returncode == 0 and not timed_out
|
|
|
|
built_api = process('b0', 0, b'', b'', 30, build=True)
|
|
built_cli = process('b1', 1, b'', b'', 30, build=True)
|
|
for scene in scenes:
|
|
if (scene['exe'] == 2 and built_api) or (scene['exe'] == 3 and built_cli):
|
|
process(scene['name'], scene['exe'], scene['input'], scene['expected'], 35)
|
|
meta = {'v': 1, 'cwd': str(scratch), 'argv': argv, 'p': records, 'why': reasons, 'first': first}
|
|
encoded = json.dumps(meta, separators=(',', ':'), ensure_ascii=True)
|
|
if len(encoded) >= 3900:
|
|
raise RuntimeError('evidence budget exceeded: ' + str(len(encoded)))
|
|
sys.stderr.write(encoded + '\n')
|
|
print('PASS' if not reasons else 'FAIL')
|
|
return 0 if not reasons else 1
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(verify(sys.argv[1]))
|