amos 8b7616bfd8 Batch 22 (20261027-C-hwe-hard-22): add 63 calibrated HWE hard-design tasks
From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27,
11 canonical families), 38 skipped for scope or duplication. Each task
has at least one independent contract-edge defect, boundary types
rotate, and public docs state trap clauses as plain contract prose.
Claude reviewed 63/63 USABLE against current digests. Difficulty is
unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:14:57 +08:00

6 lines
11 KiB
JSON

{
"console.c": "#include \"dma.h\"\n#include \"sim_device.h\"\n#include <inttypes.h>\n#include <stdio.h>\n#include <string.h>\n\nstatic struct sim_device raw[2];\nstatic struct dma_device devices[2];\n\nstatic void event_list(unsigned slot)\n{\n unsigned index;\n printf(\",%u,%u,%u,%u,[\", devices[slot].streaming_bits,\n devices[slot].coherent_bits, raw[slot].bits[0], raw[slot].bits[1]);\n for (index = 0; index < raw[slot].count && index < SIM_EVENTS; ++index) {\n struct sim_event *event = &raw[slot].events[index];\n if (index) printf(\",\");\n printf(\"[%d,%u,%u,%d]\", event->op, event->first, event->second, event->status);\n }\n printf(\"],%u]\\n\", raw[slot].count);\n}\n\nstatic struct dma_policy read_policy(void)\n{\n struct dma_policy policy;\n unsigned index;\n memset(&policy, 0, sizeof(policy));\n scanf(\"%u%u\", &policy.count, &policy.retries);\n for (index = 0; index < DMA_MAX_WIDTHS; ++index) {\n scanf(\"%u\", &policy.widths[index]);\n }\n return policy;\n}\n\nstatic unsigned decode(const char *hex, char *buffer)\n{\n unsigned length = 0;\n unsigned value;\n if (strcmp(hex, \"-\") == 0) return 0;\n while (hex[0] && hex[1] && length < 1024) {\n if (sscanf(hex, \"%2x\", &value) != 1) break;\n buffer[length++] = (char)value;\n hex += 2;\n }\n return length;\n}\n\nstatic uint64_t hash_bytes(const char *data, unsigned length)\n{\n unsigned index;\n uint64_t hash = UINT64_C(14695981039346656037);\n for (index = 0; index < length; ++index) {\n hash ^= (unsigned char)data[index];\n hash *= UINT64_C(1099511628211);\n }\n return hash;\n}\n\nint main(void)\n{\n char op;\n while (scanf(\" %c\", &op) == 1) {\n unsigned slot, bits, nonce;\n uint64_t address, length, alignment, boundary, value;\n int status;\n if (op == 'I') {\n unsigned sc, cc, sb, cb;\n struct dma_backend backend;\n scanf(\"%u%u%u%u%u\", &slot, &sc, &cc, &sb, &cb);\n sim_init(&raw[slot], sc, cc, sb, cb);\n backend = sim_backend(&raw[slot]);\n status = dma_device_bind(&devices[slot], &backend, sb, cb);\n printf(\"[%d\", status);\n event_list(slot);\n } else if (op == 'F') {\n unsigned channel, failures;\n scanf(\"%u%u%u%u\", &slot, &channel, &bits, &failures);\n raw[slot].transient[channel][bits] = failures;\n printf(\"[0]\\n\");\n } else if (op == 'P') {\n scanf(\"%u%u\", &slot, &bits);\n sim_clear(&raw[slot]);\n status = dma_device_pair(&devices[slot], bits);\n printf(\"[%d\", status);\n event_list(slot);\n } else if (op == 'Q') {\n unsigned streaming_bits, coherent_bits;\n scanf(\"%u%u\", &slot, &nonce);\n streaming_bits = coherent_bits = nonce;\n status = dma_device_state(&devices[slot], &streaming_bits, &coherent_bits);\n printf(\"[%d,%u,%u]\\n\", status, streaming_bits, coherent_bits);\n } else if (op == 'N') {\n struct dma_result result;\n struct dma_policy policy;\n scanf(\"%u%u\", &slot, &nonce);\n policy = read_policy();\n result.status = (int)nonce;\n result.bits = nonce;\n result.selected_index = (int)nonce;\n result.attempts = nonce;\n result.last_error = (int)nonce;\n sim_clear(&raw[slot]);\n status = dma_negotiate(&devices[slot], &policy, &result);\n printf(\"[%d,%d,%u,%d,%u,%d\", status, result.status, result.bits,\n result.selected_index, result.attempts, result.last_error);\n event_list(slot);\n } else if (op == 'L') {\n struct dma_policy policy;\n unsigned limit;\n scanf(\"%u%u\", &nonce, &bits);\n policy = read_policy();\n limit = nonce;\n status = dma_policy_limit(&policy, &limit);\n printf(\"[%d,%d,%u,%d]\\n\", dma_policy_validate(&policy), status,\n limit, dma_policy_contains(&policy, bits));\n } else if (op == 'X') {\n char hex[2200], text[1024];\n unsigned index, size;\n struct dma_policy policy;\n uint64_t before;\n scanf(\"%u%2199s\", &nonce, hex);\n size = decode(hex, text);\n before = hash_bytes(text, size);\n policy.count = nonce;\n policy.retries = nonce;\n for (index = 0; index < DMA_MAX_WIDTHS; ++index) policy.widths[index] = nonce;\n status = dma_policy_parse(text, size, &policy);\n printf(\"[%d,%u,%u\", status, policy.count, policy.retries);\n for (index = 0; index < DMA_MAX_WIDTHS; ++index) printf(\",%u\", policy.widths[index]);\n printf(\",%\" PRIu64 \",%\" PRIu64 \"]\\n\", before, hash_bytes(text, size));\n } else if (op == 'M') {\n scanf(\"%u%\" SCNu64, &bits, &value);\n status = dma_mask(bits, &value);\n printf(\"[%d,%\" PRIu64 \"]\\n\", status, value);\n } else if (op == 'T') {\n scanf(\"%u%\" SCNu64 \"%\" SCNu64, &bits, &address, &length);\n printf(\"[%d]\\n\", dma_fits(bits, address, length));\n } else if (op == 'W') {\n scanf(\"%u%\" SCNu64 \"%\" SCNu64 \"%\" SCNu64 \"%\" SCNu64 \"%\" SCNu64,\n &bits, &address, &length, &alignment, &boundary, &value);\n status = dma_window(bits, address, length, alignment, boundary, &value);\n printf(\"[%d,%\" PRIu64 \"]\\n\", status, value);\n } else if (op == 'J') {\n struct dma_result result;\n char buffer[512];\n unsigned capacity, index;\n scanf(\"%d%u%d%u%d%u\", &result.status, &result.bits, &result.selected_index,\n &result.attempts, &result.last_error, &capacity);\n memset(buffer, 'Z', sizeof(buffer));\n status = dma_result_json(&result, buffer, capacity);\n printf(\"[%d,\\\"\", status);\n for (index = 0; index < sizeof(buffer); ++index) printf(\"%02x\", (unsigned char)buffer[index]);\n printf(\"\\\"]\\n\");\n } else if (op == 'E') {\n int error;\n scanf(\"%d\", &error);\n printf(\"[\\\"%s\\\"]\\n\", dma_error_name(error));\n } else if (op == 'V') {\n struct dma_device empty;\n struct dma_backend backend = sim_backend(&raw[0]);\n struct dma_backend bad;\n struct dma_policy policy = {{32},1,0};\n struct dma_result result = {0,32,0,1,0};\n unsigned sb = 17, cb = 19, index;\n unsigned callbacks_before = raw[0].count;\n int returns[20];\n memset(&empty, 0, sizeof(empty));\n returns[0] = dma_mask(32,NULL);\n returns[1] = dma_window(32,0,1,1,0,NULL);\n returns[2] = dma_policy_parse(NULL,1,&policy);\n returns[3] = dma_policy_parse(\"x\",1,NULL);\n returns[4] = dma_policy_validate(NULL);\n returns[5] = dma_policy_limit(&policy,NULL);\n returns[6] = dma_device_bind(NULL,&backend,0,0);\n returns[7] = dma_device_bind(&empty,NULL,0,0);\n returns[8] = dma_device_pair(&empty,32);\n returns[9] = dma_device_state(&empty,&sb,&cb);\n returns[10] = dma_negotiate(&empty,&policy,&result);\n returns[11] = dma_negotiate(&devices[0],&policy,NULL);\n returns[12] = dma_result_json(&result,NULL,0);\n printf(\"[\");\n for (index = 0; index < 13; ++index) {\n if (index) printf(\",\");\n printf(\"%d\", returns[index]);\n }\n printf(\",%u,%u\", sb, cb);\n bad = backend; bad.streaming = NULL;\n returns[13] = dma_device_bind(&empty,&bad,0,0);\n bad = backend; bad.coherent = NULL;\n returns[14] = dma_device_bind(&empty,&bad,0,0);\n bad = backend; bad.restore = NULL;\n returns[15] = dma_device_bind(&empty,&bad,0,0);\n returns[16] = dma_device_bind(&empty,&backend,65,0);\n returns[17] = dma_device_bind(&empty,&backend,0,65);\n bad = backend; bad.context = NULL;\n returns[18] = dma_device_bind(&empty,&bad,13,17);\n returns[19] = dma_device_state(&empty,&sb,&cb);\n for (index = 13; index < 20; ++index) printf(\",%d\", returns[index]);\n printf(\",%u,%u,%d,%d,%u,%u]\\n\", sb, cb,\n empty.backend.context == NULL, empty.bound, callbacks_before, raw[0].count);\n } else {\n return 2;\n }\n }\n return 0;\n}\n",
"sim_device.c": "#include \"sim_device.h\"\n#include <string.h>\n\nstatic void record(struct sim_device *device, int op, unsigned first,\n unsigned second, int status)\n{\n if (device->count < SIM_EVENTS) {\n struct sim_event *event = &device->events[device->count];\n event->op = op;\n event->first = first;\n event->second = second;\n event->status = status;\n }\n ++device->count;\n}\n\nstatic int set_width(struct sim_device *device, unsigned channel, unsigned bits)\n{\n int status = DMA_OK;\n if (bits < 1 || bits > 64) {\n status = DMA_EINVAL;\n } else if (bits > device->caps[channel]) {\n status = DMA_ENOTSUP;\n } else if (device->transient[channel][bits] > 0) {\n --device->transient[channel][bits];\n status = DMA_EAGAIN;\n } else {\n device->bits[channel] = bits;\n }\n record(device, (int)channel, bits, 0, status);\n return status;\n}\n\nstatic int streaming(void *context, unsigned bits)\n{\n return set_width(context, 0, bits);\n}\n\nstatic int coherent(void *context, unsigned bits)\n{\n return set_width(context, 1, bits);\n}\n\nstatic void restore(void *context, unsigned streaming_bits, unsigned coherent_bits)\n{\n struct sim_device *device = context;\n device->bits[0] = streaming_bits;\n device->bits[1] = coherent_bits;\n record(device, 2, streaming_bits, coherent_bits, 0);\n}\n\nvoid sim_init(struct sim_device *device, unsigned streaming_cap,\n unsigned coherent_cap, unsigned streaming_bits, unsigned coherent_bits)\n{\n memset(device, 0, sizeof(*device));\n device->caps[0] = streaming_cap;\n device->caps[1] = coherent_cap;\n device->bits[0] = streaming_bits;\n device->bits[1] = coherent_bits;\n}\n\nstruct dma_backend sim_backend(struct sim_device *device)\n{\n struct dma_backend backend;\n backend.context = device;\n backend.streaming = streaming;\n backend.coherent = coherent;\n backend.restore = restore;\n return backend;\n}\n\nvoid sim_clear(struct sim_device *device)\n{\n device->count = 0;\n}\n",
"sim_device.h": "#ifndef SIM_DEVICE_H\n#define SIM_DEVICE_H\n#include \"dma.h\"\n#define SIM_EVENTS 256\nstruct sim_event { int op; unsigned first; unsigned second; int status; };\nstruct sim_device {\n unsigned caps[2];\n unsigned bits[2];\n unsigned transient[2][65];\n struct sim_event events[SIM_EVENTS];\n unsigned count;\n};\nvoid sim_init(struct sim_device *, unsigned, unsigned, unsigned, unsigned);\nstruct dma_backend sim_backend(struct sim_device *);\nvoid sim_clear(struct sim_device *);\n#endif\n"
}