mirror of
https://github.com/bdbrown4/peltier.io.git
synced 2026-11-07 10:58:28 +00:00
phase3: generalize trust layer for C/C++; wire cJSON target
Trust-layer generalization (zero-regression verified on tokei):
- TargetSpec [build] uses an explicit {out} isolation-dir placeholder
instead of injected CARGO_TARGET_DIR, plus optional sanitizer/
sanitizer_binary templates. Nothing assumes cargo anymore.
- verdict rebuild_pristine_baseline, sanitizer_check, and harnessd
run_verdict candidate build all use {out} substitution. A target with
no sanitizer build caps accepts at needs-human-review.
- tokei/comrak target.toml migrated to the {out} form (CARGO_TARGET_DIR=
{out} + nightly ASan sanitizer command).
cJSON C target (v1.7.19, MIT):
- harness.c bench/golden driver (trust-layer; agent can patch workspace
cJSON.c but not the rig), compiled with clang against the patched tree.
- 5.6 MB deterministic corpus (gen-corpus.sh) + MANIFEST/GOLDEN pins.
- gates = hermetic Unity/CTest suite (19 tests pass); sanitizer =
ASan+UBSan; scripts/diff-fuzz-cjson.py for differential fuzzing.
coz causal profiler integration (SPEC §12):
- harness.c optional -DHOTPATH_COZ throughput progress point.
- scripts/install-coz.sh, coz-profile.sh, coz-summary.py; just coz/install-coz.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EcKPWQ3MQD4NdEHwar96u2
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
/* hotpath bench/golden driver for the cjson target.
|
||||
*
|
||||
* TRUST-LAYER CODE — lives outside targets/cjson/workspace, so the agent's
|
||||
* propose_patch allowlist (workspace-relative paths only) cannot touch it.
|
||||
* It is compiled together with the (patched) workspace cJSON.c, so a patch
|
||||
* changes the parser/printer under test but never this measurement rig.
|
||||
*
|
||||
* Workload: parse a JSON document `iters` times, serialize it unformatted
|
||||
* each time, and fold every serialized byte into a rolling checksum so the
|
||||
* optimizer cannot elide the work. Deterministic: the last serialization
|
||||
* plus the checksum are written to stdout, giving golden-replay a
|
||||
* byte-exact signal over both the parse AND the print path.
|
||||
*
|
||||
* cjson-bench <file.json> [iters=40]
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "cJSON.h"
|
||||
|
||||
/* coz causal profiling (SPEC §12): compile with -DHOTPATH_COZ and link
|
||||
* libcoz to mark each parse+print iteration as a throughput progress
|
||||
* point, so `coz run` can measure which source lines, if sped up, would
|
||||
* actually raise end-to-end throughput. A no-op in normal builds. */
|
||||
#ifdef HOTPATH_COZ
|
||||
#include <coz.h>
|
||||
#define HOTPATH_PROGRESS() COZ_PROGRESS
|
||||
#else
|
||||
#define HOTPATH_PROGRESS() ((void)0)
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "usage: %s <file.json> [iters]\n", argv[0]);
|
||||
return 2;
|
||||
}
|
||||
long iters = (argc >= 3) ? atol(argv[2]) : 40;
|
||||
if (iters < 1) iters = 1;
|
||||
|
||||
FILE *f = fopen(argv[1], "rb");
|
||||
if (!f) { perror("fopen"); return 2; }
|
||||
fseek(f, 0, SEEK_END);
|
||||
long n = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
if (n < 0) { fclose(f); return 2; }
|
||||
char *buf = (char *)malloc((size_t)n + 1);
|
||||
if (!buf) { fclose(f); return 2; }
|
||||
if (fread(buf, 1, (size_t)n, f) != (size_t)n) { free(buf); fclose(f); return 2; }
|
||||
buf[n] = '\0';
|
||||
fclose(f);
|
||||
|
||||
unsigned long acc = 1469598103934665603UL; /* FNV-ish rolling checksum */
|
||||
char *last = NULL;
|
||||
for (long i = 0; i < iters; i++) {
|
||||
cJSON *root = cJSON_Parse(buf);
|
||||
if (!root) { fprintf(stderr, "parse failed\n"); free(buf); return 3; }
|
||||
char *out = cJSON_PrintUnformatted(root);
|
||||
if (!out) { cJSON_Delete(root); free(buf); return 3; }
|
||||
for (char *p = out; *p; p++) acc = (acc ^ (unsigned char)*p) * 1099511628211UL;
|
||||
if (i == iters - 1) last = out;
|
||||
else free(out);
|
||||
cJSON_Delete(root);
|
||||
HOTPATH_PROGRESS(); /* one parse+print = one throughput unit (coz) */
|
||||
}
|
||||
|
||||
if (last) {
|
||||
fwrite(last, 1, strlen(last), stdout);
|
||||
free(last);
|
||||
}
|
||||
printf("\nchecksum=%lu\n", acc);
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
# cJSON — ultralightweight JSON parser/printer (C)
|
||||
# Selection vs SPEC §6: CPU-bound parse+serialize; hermetic Unity/CTest
|
||||
# suite vendored in-tree; deterministic scripted workload; MIT license;
|
||||
# active but deliberately "simple", no dedicated perf team — the richer
|
||||
# legacy-C hunting ground Phase 3 calls for.
|
||||
|
||||
[source]
|
||||
repo = "https://github.com/DaveGamble/cJSON.git"
|
||||
commit = "c859b25da02955fef659d658b8f324b5cde87be3" # v1.7.19
|
||||
license = "MIT"
|
||||
|
||||
[fetch]
|
||||
# targets/*/workspace is gitignored; reproduce it with:
|
||||
# git clone https://github.com/DaveGamble/cJSON.git workspace
|
||||
# git -C workspace checkout v1.7.19
|
||||
# The bench/golden driver targets/cjson/harness.c and the Unity suite in
|
||||
# workspace/tests/ (unity vendored in-tree) are hermetic — no submodules.
|
||||
|
||||
[build]
|
||||
# Compile the trust-layer harness against the (patched) workspace cJSON.c.
|
||||
# {out} is the isolation dir; the agent may patch only workspace/*, never
|
||||
# harness.c, so the measurement rig is fixed across baseline/candidate.
|
||||
baseline = "mkdir -p {out} && clang -O2 -DNDEBUG -I targets/cjson/workspace -o {out}/cjson-bench targets/cjson/harness.c targets/cjson/workspace/cJSON.c"
|
||||
binary = "{out}/cjson-bench"
|
||||
# ASan + UBSan (C/C++ analogue of the Rust nightly ASan path); run on
|
||||
# every would-be accept (SPEC §8), halting on any leak/UB.
|
||||
sanitizer = "mkdir -p {out} && clang -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all -I targets/cjson/workspace -o {out}/cjson-asan targets/cjson/harness.c targets/cjson/workspace/cJSON.c"
|
||||
sanitizer_binary = "{out}/cjson-asan"
|
||||
|
||||
[bench]
|
||||
command = "{binary} corpora/cjson/input/big.json 2 > /dev/null"
|
||||
workload = "5.6 MB synthetic JSON (20k records: nested objects/arrays, escaped/unicode strings, ints, dense floats), parsed+serialized 2x, single thread"
|
||||
|
||||
[gates]
|
||||
# Upstream Unity suite via CTest — parse_number/string/array/object,
|
||||
# print_*, misc_tests, compare/minify. Tests the PATCHED cJSON.c.
|
||||
tests = "cmake -S targets/cjson/workspace -B targets/cjson/testbuild -DENABLE_CJSON_TEST=On -DCMAKE_BUILD_TYPE=Debug >/dev/null 2>&1 && cmake --build targets/cjson/testbuild -j >/dev/null 2>&1 && ctest --test-dir targets/cjson/testbuild --output-on-failure"
|
||||
# Golden: full re-serialization + checksum of the corpus, byte-hashed.
|
||||
golden = "{binary} corpora/cjson/input/big.json 1"
|
||||
|
||||
[corpus]
|
||||
manifest = "corpora/cjson/MANIFEST.sha256"
|
||||
root = "corpora/cjson/input"
|
||||
golden_sha256 = "corpora/cjson/GOLDEN.sha256"
|
||||
@@ -18,8 +18,10 @@ license = "BSD-2-Clause"
|
||||
# git clone <submodule repo> workspace/vendor/progit && git -C ... checkout <commit>
|
||||
|
||||
[build]
|
||||
baseline = "cargo build --release --manifest-path targets/comrak/workspace/Cargo.toml"
|
||||
binary = "targets/comrak/workspace/target/release/comrak"
|
||||
baseline = "CARGO_TARGET_DIR={out} cargo build --release --manifest-path targets/comrak/workspace/Cargo.toml"
|
||||
binary = "{out}/release/comrak"
|
||||
sanitizer = "CARGO_TARGET_DIR={out} RUSTFLAGS='-Zsanitizer=address' cargo +nightly build --target x86_64-unknown-linux-gnu --manifest-path targets/comrak/workspace/Cargo.toml"
|
||||
sanitizer_binary = "{out}/x86_64-unknown-linux-gnu/debug/comrak"
|
||||
|
||||
[bench]
|
||||
# Upstream workload (benches/bench.sh): full Pro Git book through the
|
||||
|
||||
@@ -9,8 +9,10 @@ commit = "fa44e5194060305576514d59b850353643afbfc8" # v14.0.0
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[build]
|
||||
baseline = "cargo build --release --manifest-path targets/tokei/workspace/Cargo.toml"
|
||||
binary = "targets/tokei/workspace/target/release/tokei"
|
||||
baseline = "CARGO_TARGET_DIR={out} cargo build --release --manifest-path targets/tokei/workspace/Cargo.toml"
|
||||
binary = "{out}/release/tokei"
|
||||
sanitizer = "CARGO_TARGET_DIR={out} RUSTFLAGS='-Zsanitizer=address' cargo +nightly build --target x86_64-unknown-linux-gnu --manifest-path targets/tokei/workspace/Cargo.toml"
|
||||
sanitizer_binary = "{out}/x86_64-unknown-linux-gnu/debug/tokei"
|
||||
|
||||
[bench]
|
||||
# Single rayon thread: measurement first (SPEC conventions); the
|
||||
|
||||
Reference in New Issue
Block a user