Artifact 77d8723bec93de5338375d2d077e46c37f228d8513624cff62e439e5ab6136d7:
- File
test/replay.c
— part of check-in
[f96cbc3342]
at
2026-11-13 03:51:02
on branch trunk
— Phase 4a: outfits limited to a machine, and instruction files joined
suit machine shows or sets this machine's name. An outfit worn with machine=NAME applies on that machine and nowhere else, and where it and an unlimited outfit supply the same destination the machine's wins.
A harness has one instruction file per scope. When the unlimited and the machine-limited outfit both supply instructions, suit writes one file with the unlimited text first and the machine's after it, and links the harness to that. It is rewritten when either source changes and removed when no longer needed. This is the one case where an edit in the store reaches a harness only after suit's next run.
The ledger gains an entry for a file suit wrote, so suit off removes the joined file too.
420 unit checks, 227 shell cases, 146 store cases, 612 placement cases, under clang and under gcc 16. 100% coverage in all 16 source files. The no-change run costs about 0.46 ms over an empty program quiet and 0.66 to 0.79 ms loaded.
The checked-in fuzz corpus now includes inputs grown for the ledger reader (61) and more for the stamp reader (108), beside the config parser's 300. The replay tool's input table grew, because fuzzing had filled the old one on the development machine. (user: dmestas, size: 4194) [annotate] [blame] [check-ins using]
// Replays fuzz inputs through a target without libFuzzer, so the coverage // gate and the Fil-C run can use them. With --mutate N, also runs N // mutations of the inputs from a fixed seed. // // replay [--mutate N] FILE_OR_DIR... #include <dirent.h> #include <fcntl.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <unistd.h> int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); constexpr size_t INPUT_MAX = 2u << 20; constexpr size_t SEEDS_MAX = 65536; static uint8_t *seeds[SEEDS_MAX]; static size_t seed_len[SEEDS_MAX]; static size_t nseeds; static int report = -1; // the real stdout static uint64_t rng_state = 0x9E3779B97F4A7C15u; static uint64_t rng(void) { rng_state ^= rng_state << 13; rng_state ^= rng_state >> 7; rng_state ^= rng_state << 17; return rng_state; } static void add_file(const char *path) { FILE *f = fopen(path, "rb"); if (f == nullptr || nseeds == SEEDS_MAX) { dprintf(report, "replay: cannot use %s\n", path); exit(2); } uint8_t *buf = malloc(INPUT_MAX); size_t n = fread(buf, 1, INPUT_MAX, f); fclose(f); seeds[nseeds] = buf; seed_len[nseeds++] = n; } static void add_path(const char *path) { struct stat st; if (stat(path, &st) != 0) return; // a corpus folder that does not exist yet if (!S_ISDIR(st.st_mode)) { add_file(path); return; } DIR *d = opendir(path); struct dirent *de; while ((de = readdir(d)) != nullptr) { if (de->d_name[0] == '.') continue; char child[4096]; snprintf(child, sizeof child, "%s/%s", path, de->d_name); add_path(child); } closedir(d); } static size_t mutate(uint8_t *work, size_t len, size_t cap) { static const char dict[] = "[]#= \t\n\r*/.:@~-_xyz0123456789"; int rounds = 1 + (int)(rng() % 6); for (int r = 0; r < rounds; r++) { size_t at = len > 0 ? (size_t)(rng() % len) : 0; switch (rng() % 5) { case 0: if (len > 0) work[at] ^= (uint8_t)(1u << (rng() % 8)); break; case 1: if (len > 0) work[at] = (uint8_t)rng(); break; case 2: if (len + 1 < cap) { memmove(work + at + 1, work + at, len - at); work[at] = (uint8_t)dict[rng() % (sizeof dict - 1)]; len++; } break; case 3: if (len > 0) { memmove(work + at, work + at + 1, len - at - 1); len--; } break; default: if (len > 8 && len * 2 < cap) { // duplicate a slice size_t n = 1 + (size_t)(rng() % 64); if (at + n > len) n = len - at; memmove(work + at + n, work + at, len - at); len += n; } } } return len; } int main(int argc, char **argv) { // Targets talk to stdout and stderr; keep a handle on the real stdout // for the summary and send both to /dev/null. report = dup(STDOUT_FILENO); int null = open("/dev/null", O_WRONLY); dup2(null, STDOUT_FILENO); dup2(null, STDERR_FILENO); long mutations = 0; int first = 1; if (argc > 2 && strcmp(argv[1], "--mutate") == 0) { mutations = atol(argv[2]); first = 3; } for (int i = first; i < argc; i++) add_path(argv[i]); if (nseeds == 0) { dprintf(report, "replay: no inputs\n"); return 2; } for (size_t i = 0; i < nseeds; i++) LLVMFuzzerTestOneInput(seeds[i], seed_len[i]); dprintf(report, "replay: %zu inputs", nseeds); if (mutations > 0) { uint8_t *work = malloc(64u << 10); for (long m = 0; m < mutations; m++) { size_t s = (size_t)(rng() % nseeds); size_t len = seed_len[s] < (32u << 10) ? seed_len[s] : (32u << 10); memcpy(work, seeds[s], len); len = mutate(work, len, 64u << 10); LLVMFuzzerTestOneInput(work, len); } dprintf(report, ", %ld mutations", mutations); free(work); } dprintf(report, "\n"); return 0; }