amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
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>
2026-10-27 01:55:56 +08:00

127 lines
3.9 KiB
C++

#include "sampling.hpp"
#include <iostream>
#include <string>
#include <vector>
namespace {
bool horizontal(unsigned char byte) {
return byte == ' ' || byte == '\t' || byte == '\r';
}
bool number(const std::string& token, int& result) {
if (token.empty()) {
return false;
}
std::size_t cursor = 0;
bool negative = false;
if (token[cursor] == '+' || token[cursor] == '-') {
negative = token[cursor] == '-';
++cursor;
}
if (cursor == token.size()) {
return false;
}
int value = 0;
for (; cursor < token.size(); ++cursor) {
unsigned char byte = static_cast<unsigned char>(token[cursor]);
if (byte < '0' || byte > '9') {
return false;
}
int digit = byte - '0';
if (value > 6553 || (value == 6553 && digit > 5)) {
return false;
}
value = value * 10 + digit;
}
result = negative ? -value : value;
return true;
}
bool parse(const std::string& line, sampling::Request& request) {
std::vector<int> values;
std::size_t cursor = 0;
while (cursor < line.size()) {
while (cursor < line.size() && horizontal(static_cast<unsigned char>(line[cursor]))) {
++cursor;
}
if (cursor == line.size()) {
break;
}
std::size_t begin = cursor;
while (cursor < line.size() && !horizontal(static_cast<unsigned char>(line[cursor]))) {
++cursor;
}
int value;
if (!number(line.substr(begin, cursor - begin), value)) {
return false;
}
values.push_back(value);
}
if (values.size() != 10) {
return false;
}
request.device = values[0];
request.length = values[1];
request.limit = values[2];
request.transform = values[3];
request.open_fault = static_cast<sampling::Fault>(values[4]);
request.read_at = values[5];
request.read_fault = static_cast<sampling::Fault>(values[6]);
request.decode_at = values[7];
request.decode_fault = static_cast<sampling::Fault>(values[8]);
request.token = values[9];
return sampling::valid_request(request);
}
void observe(sampling::DeviceBank& bank, const sampling::Request& request, int sequence) {
sampling::Sample sample;
int escape = 0;
int token = 0;
bank.configure(request);
try {
sample = sampling::dispatch(bank, request);
} catch (const sampling::Cancellation& error) {
escape = 1;
token = error.token();
} catch (const sampling::Unexpected& error) {
escape = 2;
token = error.token();
} catch (const std::exception&) {
escape = 3;
} catch (...) {
escape = 4;
}
const sampling::Counters& counters = bank.counters();
std::cout << sequence << ' ' << escape << ' ' << token
<< ' ' << static_cast<int>(sample.status)
<< ' ' << sample.error << ' ' << sample.first
<< ' ' << sample.checksum << ' ' << sample.count
<< ' ' << counters.opens << ' ' << counters.closes
<< ' ' << counters.reads << ' ' << counters.decodes
<< ' ' << counters.errors << ' ' << counters.active
<< ' ' << counters.peak << ' ' << counters.invalid_close;
for (int busy : bank.busy_devices()) {
std::cout << ' ' << busy;
}
std::cout << '\n';
std::cout << sequence << ' ' << bank.events().size();
for (const sampling::Event& event : bank.events()) {
std::cout << ' ' << event.kind << ' ' << event.device << ' ' << event.value;
}
std::cout << '\n';
}
}
int main() {
sampling::DeviceBank bank;
std::string line;
int sequence = 0;
while (std::getline(std::cin, line)) {
sampling::Request request;
if (!parse(line, request)) {
std::cerr << "invalid request\n";
return 2;
}
observe(bank, request, ++sequence);
}
if (std::cin.bad()) {
return 2;
}
return 0;
}