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>
7 lines
14 KiB
JSON
7 lines
14 KiB
JSON
{
|
|
"pin.h": "#ifndef PIN_H\n#define PIN_H\n#include <stddef.h>\n#include <stdio.h>\n#define PIN_CAPACITY 32\n#define PIN_MAX_BATCH 16\n#define PIN_AGAIN (-11)\n#define PIN_IO (-5)\n#define PIN_PROTOCOL (-71)\n#define PIN_TIMEOUT (-110)\nenum pin_stage {\n PIN_DONE = 0,\n PIN_EXPORT = 1,\n PIN_READY = 2,\n PIN_DIRECTION = 3,\n PIN_VALUE = 4\n};\nstruct pin_request {\n unsigned pin;\n unsigned value;\n unsigned ready_delay;\n unsigned export_busy;\n unsigned direction_busy;\n unsigned value_busy;\n unsigned fatal_stage;\n};\nstruct pin_result {\n int rc;\n unsigned stage;\n};\nstruct pin_observation {\n unsigned exported;\n unsigned ready;\n unsigned output;\n unsigned value;\n unsigned exports;\n unsigned waits;\n unsigned directions;\n unsigned values;\n unsigned releases;\n unsigned illegal;\n};\nstruct pin_bus;\nstruct pin_bus *pin_bus_create(void);\nvoid pin_bus_destroy(struct pin_bus *bus);\nint pin_bus_configure(struct pin_bus *bus,\n const struct pin_request *requests, size_t count);\nint pin_export(struct pin_bus *bus, unsigned pin);\nint pin_wait_ready(struct pin_bus *bus, unsigned pin);\nint pin_set_output(struct pin_bus *bus, unsigned pin);\nint pin_set_value(struct pin_bus *bus, unsigned pin, unsigned value);\nint pin_release(struct pin_bus *bus, unsigned pin);\nint pin_observe(const struct pin_bus *bus, unsigned pin,\n struct pin_observation *observation);\nint pin_bringup(struct pin_bus *bus, const struct pin_request *requests,\n size_t count, unsigned budget, struct pin_result *results);\nvoid pin_print_observation(FILE *stream, unsigned sequence, unsigned pin,\n const struct pin_result *result,\n const struct pin_observation *observation);\n#endif\n",
|
|
"sim.c": "#include \"pin.h\"\n#include <stdlib.h>\n#include <string.h>\nstruct simulated_pin {\n struct pin_request plan;\n struct pin_observation seen;\n unsigned configured;\n unsigned export_left;\n unsigned ready_left;\n unsigned direction_left;\n unsigned value_left;\n};\nstruct pin_bus {\n struct simulated_pin lines[PIN_CAPACITY];\n};\nstruct pin_bus *pin_bus_create(void)\n{\n return calloc(1, sizeof(struct pin_bus));\n}\nvoid pin_bus_destroy(struct pin_bus *bus)\n{\n free(bus);\n}\nstatic struct simulated_pin *find_pin(struct pin_bus *bus, unsigned pin)\n{\n if (bus == NULL || pin >= PIN_CAPACITY) {\n return NULL;\n }\n if (!bus->lines[pin].configured) {\n return NULL;\n }\n return &bus->lines[pin];\n}\nstatic int valid_request(const struct pin_request *request)\n{\n if (request->pin >= PIN_CAPACITY || request->value > 1) {\n return 0;\n }\n if (request->ready_delay > 8 || request->export_busy > 8) {\n return 0;\n }\n if (request->direction_busy > 8 || request->value_busy > 8) {\n return 0;\n }\n return request->fatal_stage <= PIN_VALUE;\n}\nint pin_bus_configure(struct pin_bus *bus,\n const struct pin_request *requests, size_t count)\n{\n unsigned occupied[PIN_CAPACITY] = {0};\n size_t index;\n if (bus == NULL || count > PIN_MAX_BATCH) {\n return -1;\n }\n if (count != 0 && requests == NULL) {\n return -1;\n }\n for (index = 0; index < count; ++index) {\n unsigned pin = requests[index].pin;\n if (!valid_request(&requests[index])) {\n return -1;\n }\n if (occupied[pin]) {\n return -1;\n }\n occupied[pin] = 1;\n }\n memset(bus, 0, sizeof(*bus));\n for (index = 0; index < count; ++index) {\n const struct pin_request *request = &requests[index];\n struct simulated_pin *line = &bus->lines[request->pin];\n line->plan = *request;\n line->configured = 1;\n line->export_left = request->export_busy;\n line->ready_left = request->ready_delay;\n line->direction_left = request->direction_busy;\n line->value_left = request->value_busy;\n }\n return 0;\n}\nstatic int transient(unsigned *remaining)\n{\n if (*remaining == 0) {\n return 0;\n }\n --*remaining;\n return PIN_AGAIN;\n}\nstatic int illegal(struct simulated_pin *line)\n{\n ++line->seen.illegal;\n return PIN_PROTOCOL;\n}\nint pin_export(struct pin_bus *bus, unsigned pin)\n{\n struct simulated_pin *line = find_pin(bus, pin);\n int rc;\n if (line == NULL) {\n return PIN_PROTOCOL;\n }\n ++line->seen.exports;\n if (line->seen.exported) {\n return illegal(line);\n }\n if (line->plan.fatal_stage == PIN_EXPORT) {\n return PIN_IO;\n }\n rc = transient(&line->export_left);\n if (rc != 0) {\n return rc;\n }\n line->seen.exported = 1;\n return 0;\n}\nint pin_wait_ready(struct pin_bus *bus, unsigned pin)\n{\n struct simulated_pin *line = find_pin(bus, pin);\n int rc;\n if (line == NULL) {\n return PIN_PROTOCOL;\n }\n ++line->seen.waits;\n if (!line->seen.exported || line->seen.ready) {\n return illegal(line);\n }\n if (line->plan.fatal_stage == PIN_READY) {\n return PIN_IO;\n }\n rc = transient(&line->ready_left);\n if (rc != 0) {\n return rc;\n }\n line->seen.ready = 1;\n return 0;\n}\nint pin_set_output(struct pin_bus *bus, unsigned pin)\n{\n struct simulated_pin *line = find_pin(bus, pin);\n int rc;\n if (line == NULL) {\n return PIN_PROTOCOL;\n }\n ++line->seen.directions;\n if (!line->seen.exported || !line->seen.ready || line->seen.output) {\n return illegal(line);\n }\n if (line->plan.fatal_stage == PIN_DIRECTION) {\n return PIN_IO;\n }\n rc = transient(&line->direction_left);\n if (rc != 0) {\n return rc;\n }\n line->seen.output = 1;\n return 0;\n}\nint pin_set_value(struct pin_bus *bus, unsigned pin, unsigned value)\n{\n struct simulated_pin *line = find_pin(bus, pin);\n int rc;\n if (line == NULL) {\n return PIN_PROTOCOL;\n }\n ++line->seen.values;\n if (!line->seen.output || !line->seen.ready || value > 1) {\n return illegal(line);\n }\n if (line->plan.fatal_stage == PIN_VALUE) {\n return PIN_IO;\n }\n rc = transient(&line->value_left);\n if (rc != 0) {\n return rc;\n }\n line->seen.value = value;\n return 0;\n}\nint pin_release(struct pin_bus *bus, unsigned pin)\n{\n struct simulated_pin *line = find_pin(bus, pin);\n if (line == NULL) {\n return PIN_PROTOCOL;\n }\n ++line->seen.releases;\n if (!line->seen.exported) {\n return illegal(line);\n }\n line->seen.exported = 0;\n line->seen.ready = 0;\n line->seen.output = 0;\n line->seen.value = 0;\n return 0;\n}\nint pin_observe(const struct pin_bus *bus, unsigned pin,\n struct pin_observation *observation)\n{\n if (bus == NULL || pin >= PIN_CAPACITY || observation == NULL) {\n return -1;\n }\n if (!bus->lines[pin].configured) {\n return -1;\n }\n *observation = bus->lines[pin].seen;\n return 0;\n}\nvoid pin_print_observation(FILE *stream, unsigned sequence, unsigned pin,\n const struct pin_result *result,\n const struct pin_observation *observation)\n{\n fprintf(stream, \"P %u %u %d %u\", sequence, pin, result->rc, result->stage);\n fprintf(stream, \" %u %u %u %u\", observation->exported,\n observation->ready, observation->output, observation->value);\n fprintf(stream, \" %u %u %u %u %u %u\\n\", observation->exports,\n observation->waits, observation->directions, observation->values,\n observation->releases, observation->illegal);\n}\n",
|
|
"console.c": "#include \"pin.h\"\n#include <limits.h>\n#include <stdlib.h>\n#include <string.h>\n#define LINE_CAPACITY 4096\n#define TOKEN_CAPACITY 128\nstruct token {\n const unsigned char *start;\n size_t length;\n};\nstatic int space(unsigned char value)\n{\n return value == ' ' || value == '\\t' || value == '\\r' || value == '\\n';\n}\nstatic int tokenize(const unsigned char *line, size_t length,\n struct token *tokens, size_t *count)\n{\n size_t offset = 0;\n size_t used = 0;\n while (offset < length) {\n size_t begin;\n while (offset < length && space(line[offset])) {\n ++offset;\n }\n if (offset == length) {\n break;\n }\n if (used == TOKEN_CAPACITY) {\n return -1;\n }\n begin = offset;\n while (offset < length && !space(line[offset])) {\n if (line[offset] < 33 || line[offset] > 126) {\n return -1;\n }\n ++offset;\n }\n tokens[used].start = line + begin;\n tokens[used].length = offset - begin;\n ++used;\n }\n *count = used;\n return 0;\n}\nstatic int number(const struct token *token, unsigned maximum, unsigned *value)\n{\n unsigned result = 0;\n size_t index;\n if (token->length == 0) {\n return -1;\n }\n for (index = 0; index < token->length; ++index) {\n unsigned char byte = token->start[index];\n unsigned digit;\n if (byte < '0' || byte > '9') {\n return -1;\n }\n digit = (unsigned)(byte - '0');\n if (result > maximum / 10 ||\n (result == maximum / 10 && digit > maximum % 10)) {\n return -1;\n }\n result = result * 10 + digit;\n }\n *value = result;\n return 0;\n}\nstatic int parse(const unsigned char *line, size_t length, unsigned *budget,\n size_t *count, struct pin_request *requests)\n{\n struct token tokens[TOKEN_CAPACITY];\n unsigned size;\n unsigned occupied[PIN_CAPACITY] = {0};\n size_t used;\n size_t index;\n static const unsigned limits[7] = {31, 1, 8, 8, 8, 8, 4};\n if (tokenize(line, length, tokens, &used) != 0 || used < 3) {\n return -1;\n }\n if (tokens[0].length != 1 || tokens[0].start[0] != 'B') {\n return -1;\n }\n if (number(&tokens[1], 8, budget) != 0 || *budget == 0 ||\n number(&tokens[2], PIN_MAX_BATCH, &size) != 0) {\n return -1;\n }\n if (used != 3 + (size_t)size * 7) {\n return -1;\n }\n for (index = 0; index < size; ++index) {\n unsigned values[7];\n size_t field;\n for (field = 0; field < 7; ++field) {\n if (number(&tokens[3 + index * 7 + field], limits[field],\n &values[field]) != 0) {\n return -1;\n }\n }\n if (occupied[values[0]]) {\n return -1;\n }\n occupied[values[0]] = 1;\n requests[index].pin = values[0];\n requests[index].value = values[1];\n requests[index].ready_delay = values[2];\n requests[index].export_busy = values[3];\n requests[index].direction_busy = values[4];\n requests[index].value_busy = values[5];\n requests[index].fatal_stage = values[6];\n }\n *count = size;\n return 0;\n}\nstatic int execute(unsigned sequence, const unsigned char *line, size_t length)\n{\n struct pin_request requests[PIN_MAX_BATCH];\n struct pin_result results[PIN_MAX_BATCH];\n struct pin_bus *bus;\n unsigned budget;\n size_t count;\n size_t index;\n unsigned completed = 0;\n unsigned failed = 0;\n int rc;\n if (parse(line, length, &budget, &count, requests) != 0) {\n printf(\"REJECT %u\\n\", sequence);\n return 0;\n }\n bus = pin_bus_create();\n if (bus == NULL) {\n return -1;\n }\n if (pin_bus_configure(bus, requests, count) != 0) {\n pin_bus_destroy(bus);\n return -1;\n }\n memset(results, 0, sizeof(results));\n rc = pin_bringup(bus, requests, count, budget, results);\n for (index = 0; index < count; ++index) {\n if (results[index].rc == 0) {\n ++completed;\n } else {\n ++failed;\n }\n }\n printf(\"R %u %d %u %u\\n\", sequence, rc, completed, failed);\n for (index = 0; index < count; ++index) {\n struct pin_observation observation;\n if (pin_observe(bus, requests[index].pin, &observation) != 0) {\n pin_bus_destroy(bus);\n return -1;\n }\n pin_print_observation(stdout, sequence, requests[index].pin,\n &results[index], &observation);\n }\n pin_bus_destroy(bus);\n return 0;\n}\nint main(void)\n{\n unsigned char line[LINE_CAPACITY];\n size_t length = 0;\n unsigned sequence = 0;\n int overflow = 0;\n int byte;\n while ((byte = getchar()) != EOF) {\n if (byte == '\\n') {\n ++sequence;\n if (overflow) {\n printf(\"REJECT %u\\n\", sequence);\n } else if (execute(sequence, line, length) != 0) {\n return 2;\n }\n length = 0;\n overflow = 0;\n } else if (length < sizeof(line)) {\n line[length++] = (unsigned char)byte;\n } else {\n overflow = 1;\n }\n }\n if (length != 0 || overflow) {\n ++sequence;\n if (overflow) {\n printf(\"REJECT %u\\n\", sequence);\n } else if (execute(sequence, line, length) != 0) {\n return 2;\n }\n }\n return ferror(stdin) ? 2 : 0;\n}\n",
|
|
"Makefile": "CC = gcc\nCFLAGS = -std=c11 -O2 -Wall -Wextra -Werror -pedantic\nall: pin-console\npin-console: bringup.c sim.c console.c pin.h\n\t$(CC) $(CFLAGS) bringup.c sim.c console.c -o $@\ndemo: pin-console\n\t./pin-console < demo.txt\nclean:\n\trm -f pin-console\n.PHONY: all demo clean\n"
|
|
}
|