diff --git a/Makefile b/Makefile index 7100cca04..ac5036b68 100644 --- a/Makefile +++ b/Makefile @@ -281,6 +281,21 @@ $(RX_TEST): $(RX_SRCS) src/runtime/rx_caproot.h src/runtime/rx_world.h \ test-r3: $(RX_TEST) ./$(RX_TEST) +# HD-09 resource contract v0, first enforcement cut: a declared deadline is +# enforced before publishing (late reaction cancelled, nothing published, +# charge refunded once). CPU only, same links as R3 minus the heartbeat test. +RX_DEADLINE_SRCS = src/runtime/rx_caproot.c src/runtime/rx_world.c src/runtime/rx_coherent.c \ + src/sha256.c src/omega_evidence.c tests/runtime/rx_deadline_cancel.c +RX_DEADLINE_TEST = $(OUT_DIR)/rx_deadline_cancel + +$(RX_DEADLINE_TEST): $(RX_DEADLINE_SRCS) src/runtime/rx_caproot.h src/runtime/rx_world.h \ + src/runtime/omega_shared_world_abi.h | $(OUT_DIR) + $(CC) $(CFLAGS) -pthread -o $@ $(RX_DEADLINE_SRCS) + +.PHONY: test-rx-deadline-cancel +test-rx-deadline-cancel: $(RX_DEADLINE_TEST) + ./$(RX_DEADLINE_TEST) + # Omega semantic variables and incremental recomputation # (gate OMEGA_INCREMENTAL_SEMANTICS_PASS). CPU only, same links as R3. RX_SEM_SRCS = src/runtime/rx_caproot.c src/runtime/rx_world.c src/runtime/rx_coherent.c \ diff --git a/src/runtime/rx_world.c b/src/runtime/rx_world.c index 43f9f35d9..1d5327d8a 100644 --- a/src/runtime/rx_world.c +++ b/src/runtime/rx_world.c @@ -114,6 +114,7 @@ const char *rx_crumb_kind_name(RxCrumbKind k) { case RX_CRUMB_NOOP: return "NOOP"; case RX_CRUMB_RETIRE: return "RETIRE"; case RX_CRUMB_QUARANTINE: return "QUARANTINE"; + case RX_CRUMB_CANCELLED: return "CANCELLED"; default: return "?"; } } @@ -1470,6 +1471,23 @@ static void run_one(RxWorld *w, uint32_t rid, uint32_t worker) { return; } + /* HD-09 resource contract v0, first enforcement cut (aien-architecture + * docs/hardening/resource-contract-v0.md section 5): a declared deadline + * is enforced before publishing. Same comparison as charge(): strictly + * greater than the logical tick. The proposals in ctx.out are never + * staged, so nothing late is published; end_activation refunds the + * charge once. A function that never returns is not covered here. */ + if (d->need.deadline && w->budget.logical_tick > d->need.deadline) { + set_state(w, r, RX_CANCELLED); + k.kind = RX_CRUMB_CANCELLED; + k.reason = RX_ERR_DEADLINE; + k.t_end_ns = now_ns(); + crumb_append(w, &k); + w->stats.deadline_cancelled++; + end_activation(w, rid); + return; + } + set_state(w, r, RX_PUBLISHING); /* 1. Versioned reads still valid? */ bool stale = false; diff --git a/src/runtime/rx_world.h b/src/runtime/rx_world.h index 897c90bf5..1d794f7a3 100644 --- a/src/runtime/rx_world.h +++ b/src/runtime/rx_world.h @@ -98,7 +98,9 @@ typedef enum { RX_CRUMB_FAILED, RX_CRUMB_NOOP, /* ran, proposed no change: fixed point */ RX_CRUMB_RETIRE, - RX_CRUMB_QUARANTINE /* an R6 limit stopped this reaction; reason names it */ + RX_CRUMB_QUARANTINE, /* an R6 limit stopped this reaction; reason names it */ + RX_CRUMB_CANCELLED /* HD-09: ran past its declared deadline; nothing + published; reason RX_ERR_DEADLINE */ } RxCrumbKind; /* Which R6 limit engaged (reason of a QUARANTINE crumb). */ @@ -124,6 +126,7 @@ enum { RX_CONTAIN_BUDGET = 1, RX_CONTAIN_OSCILLATION, RX_CONTAIN_LIVELOCK, #define RX_ERR_IDENTITY -27 /* caller credential absent, forged, stale or revoked */ #define RX_ERR_BINDING -28 /* a bound field's external reference was refused (COMPOSITION-2) */ #define RX_ERR_BUSY -29 /* the reaction still has work pending (rx_world_remove_reaction) */ +#define RX_ERR_DEADLINE -30 /* the logical tick passed the declared deadline (RX_CRUMB_CANCELLED) */ /* Reaction notices carried in the frozen 128-byte descriptor. * The older transform request/result values stay in the frozen layout and @@ -469,6 +472,11 @@ typedef struct { uint64_t seq_pulses; /* sequential reference only: pulses run */ uint64_t seq_polls; /* sequential reference only: readiness polls */ uint64_t seq_runs; /* sequential reference only: stages run */ + /* HD-09 resource contract v0, first enforcement cut: activations whose + * function returned after the logical tick passed need.deadline (strictly + * greater). Each was cancelled before publishing; its charge was refunded + * once by end_activation. */ + uint64_t deadline_cancelled; } RxStats; /* R15 timing sample, recorded only when a timing buffer is installed diff --git a/tests/model/world_model.c b/tests/model/world_model.c index f2cc1df31..ffe76da05 100644 --- a/tests/model/world_model.c +++ b/tests/model/world_model.c @@ -215,6 +215,16 @@ uint32_t wm_step(const WmProfile *p, WmState *s, WmOp op) { end_activation(p, s, r, 1); break; case OP_FIN: + if (wm_deadline[r] && s->tick > wm_deadline[r]) { + /* run_one (HD-09 first enforcement cut): fn returned past its + * declared deadline -> RUNNING -> CANCELLED, nothing staged or + * published, no wake, charge refunded by end_activation. This + * is enforcement at return only; I4 (surfaced while running) + * is still not met by the as-built World. */ + s->st[r] = WM_ENDING; + end_activation(p, s, r, 0); + break; + } if (s->stale[r]) { /* PUBLISHING -> INVALIDATED */ s->invalidations++; s->yield[r] = backoff(s->yield[r]); diff --git a/tests/runtime/rx_deadline_cancel.c b/tests/runtime/rx_deadline_cancel.c new file mode 100644 index 000000000..2b25929fc --- /dev/null +++ b/tests/runtime/rx_deadline_cancel.c @@ -0,0 +1,325 @@ +/* + * HD-09 resource contract v0, first enforcement cut (aien-architecture + * docs/hardening/resource-contract-v0.md section 5): a reaction that declared + * a deadline and whose function returns after the World's logical tick has + * passed it is cancelled before publishing. + * + * Two reactions, both triggered by one outside object E, run in their own + * functions at tick 0 and are held there by a gate: + * D deadline 5, memory 64, energy 3, writes OD field 0 + * H no deadline, memory 32, energy 5, writes OH field 0 (the holder: it + * keeps its charge while D ends, so a missing or a double refund of D's + * charge is visible instead of being hidden by the clamp at zero) + * + * late tick moved to 6 while D is held, then D released: + * D has zero commits, OD field 0 and version unchanged, no COMMIT + * crumb of D anywhere, D's last crumb is CANCELLED with reason + * RX_ERR_DEADLINE, deadline_cancelled == 1; right after D ends + * the footprint is exactly H's charge (slots 1, memory 32, + * energy 5); after H ends it is back to the pre-admit zero; + * rx_world_verify_crumbs returns 0. + * control tick moved only to 5 (the comparison is strictly greater): + * D commits exactly once, OD holds its value, no CANCELLED crumb, + * deadline_cancelled == 0, same footprint checks, chain verifies. + * + * Mutations that must make this test fail (none is applied by the build; + * tests/runtime/rx_deadline_cancel_mutants.sh applies M1-M4 to a temp copy + * and requires every one to fail). A second uncharge is not claimed: uncharge + * returns early once the reaction no longer holds a charge, so it is not + * observable. + * M1 `>` changed to `>=` in the run_one check: control cancels -> FAIL + * (control: commits 0, CANCELLED crumb present). + * M2 the run_one check deleted: late commits -> FAIL (late: commits 1, + * OD changed, no CANCELLED crumb). + * M3 cancel, but stage/commit the proposed writes anyway: late -> FAIL + * (OD field/version changed, COMMIT crumb of D present). + * M4 cancel without end_activation's refund (charge marked released first): + * late -> FAIL (footprint after D ends is not exactly H's charge). + * + * Host only, CPU only. Exit 0 = PASS. + */ +#include "runtime/rx_caproot.h" +#include "runtime/rx_world.h" + +#include +#include +#include +#include +#include +#include + +enum { RD = 0, RH = 1, NR = 2 }; + +static const uint64_t k_mem[NR] = { 64, 32 }; +static const uint64_t k_energy[NR] = { 3, 5 }; +static const uint64_t k_value[NR] = { 0xD0D0u, 0x4040u }; + +/* ---- gate: each function parks until released --------------------------- */ + +static struct { + pthread_mutex_t mu; + pthread_cond_t cv; + int in_fn[NR]; + int go[NR]; +} g = { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, {0}, {0} }; + +static RxObjRef g_out[NR]; +static uint32_t g_idx[NR] = { RD, RH }; + +static int fn_gate(RxCtx *ctx) { + uint32_t i = *(const uint32_t *)ctx->user; + pthread_mutex_lock(&g.mu); + g.in_fn[i] = 1; + pthread_cond_broadcast(&g.cv); + while (!g.go[i]) pthread_cond_wait(&g.cv, &g.mu); + g.go[i] = 0; + g.in_fn[i] = 0; + pthread_mutex_unlock(&g.mu); + ctx->n_out = 1; + ctx->out[0].obj = g_out[i]; + ctx->out[0].field = 0; + ctx->out[0].value = k_value[i]; + return 0; +} + +static void release(uint32_t i) { + pthread_mutex_lock(&g.mu); + g.go[i] = 1; + pthread_cond_broadcast(&g.cv); + pthread_mutex_unlock(&g.mu); +} + +static uint64_t ms_since(const struct timespec *t0) { + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + return (uint64_t)((now.tv_sec - t0->tv_sec) * 1000L + (now.tv_nsec - t0->tv_nsec) / 1000000L); +} + +/* Bounded wait (5 s) until both functions are parked in the gate. */ +static int wait_both_in_fn(void) { + struct timespec t0; + clock_gettime(CLOCK_MONOTONIC, &t0); + for (;;) { + pthread_mutex_lock(&g.mu); + int ok = g.in_fn[RD] && g.in_fn[RH]; + pthread_mutex_unlock(&g.mu); + if (ok) return 0; + if (ms_since(&t0) > 5000) return -1; + struct timespec ts = { 0, 100000 }; + nanosleep(&ts, NULL); + } +} + +/* Bounded wait (5 s) until D's activation has ended (DORMANT, H still in flight). */ +static int wait_d_ended(RxWorld *w) { + struct timespec t0; + clock_gettime(CLOCK_MONOTONIC, &t0); + for (;;) { + pthread_mutex_lock(&w->mu); + int ok = w->reactions[RD].state == RX_DORMANT && w->in_flight == 1; + pthread_mutex_unlock(&w->mu); + if (ok) return 0; + if (ms_since(&t0) > 5000) return -1; + struct timespec ts = { 0, 100000 }; + nanosleep(&ts, NULL); + } +} + +/* ---- authority stand-in: every reference is valid ------------------------ */ + +static int g_auth_ctx; +static int auth_ok(const void *c, RxCapRef ref, uint32_t subject, uint64_t resource, + uint32_t rights, RxCapEntry *out) { + (void)c; (void)ref; (void)subject; (void)resource; (void)rights; + if (out) memset(out, 0, sizeof *out); + return RX_CAP_OK; +} +static int auth_inspect(const void *c, RxCapRef ref, RxCapEntry *out) { + (void)c; (void)ref; (void)out; + return RX_CAP_ERR_STATE; +} + +/* ---- checks ----------------------------------------------------------------- */ + +static int g_fail; +#define CHECK(cond, ...) do { \ + if (cond) { printf(" ok "); printf(__VA_ARGS__); printf("\n"); } \ + else { printf(" FAIL "); printf(__VA_ARGS__); printf("\n"); g_fail++; } \ + } while (0) + +static void budget(RxResourceBudget *b, uint64_t tick) { + memset(b, 0, sizeof *b); + b->slots = 4; + b->memory_bytes = 1024; + b->energy_budget = 1024; + b->offered_locality = UINT32_MAX; + b->offered_accel = UINT32_MAX; + b->compute_mask = UINT32_MAX; + b->logical_tick = tick; +} + +static void footprint_is(RxWorld *w, uint32_t slots, uint64_t mem, uint64_t energy, + const char *when) { + RxFootprint fp; + rx_world_footprint(w, &fp); + CHECK(fp.used_slots == slots && fp.used_memory == mem && fp.used_energy == energy, + "%s: used_slots=%u used_memory=%llu used_energy=%llu (want %u/%llu/%llu)", when, + fp.used_slots, (unsigned long long)fp.used_memory, (unsigned long long)fp.used_energy, + slots, (unsigned long long)mem, (unsigned long long)energy); +} + +/* One run. final_tick 6 = late case, 5 = control case. */ +static int run_case(uint64_t final_tick) { + const int late = final_tick > 5; + printf("%s: deadline 5, tick 0 -> %llu while D is held\n", late ? "late" : "control", + (unsigned long long)final_tick); + memset(g.in_fn, 0, sizeof g.in_fn); + memset(g.go, 0, sizeof g.go); + + RxWorld *w = calloc(1, sizeof *w); + if (!w) return -1; + if (rx_world_init_with_auth(w, NULL, &g_auth_ctx, auth_ok, auth_inspect, 2, 1u << 12) != RX_OK) { + free(w); + return -1; + } + w->external_subject = 100; + RxResourceBudget b; + budget(&b, 0); + rx_world_set_resources(w, &b); + + RxObjRef e; + int rc = rx_world_create(w, 1, RX_PERSIST_RESIDENT, 1, NULL, &e); + for (uint32_t i = 0; i < NR && rc == RX_OK; i++) + rc = rx_world_create(w, 1, RX_PERSIST_RESIDENT, 1, NULL, &g_out[i]); + for (uint32_t i = 0; i < NR && rc == RX_OK; i++) { + RxReactionDesc d; + memset(&d, 0, sizeof d); + d.name = i == RD ? "D" : "H"; + d.faculty = i + 1; + d.subject = 1; + d.priority = RX_PRIO_FOREGROUND; + d.need.memory_bytes = k_mem[i]; + d.need.energy_cost = k_energy[i]; + d.need.deadline = i == RD ? 5 : 0; + d.n_triggers = 1; + d.triggers[0].obj = e; + d.triggers[0].mask = RX_FIELD(0); + d.n_writes = 1; + d.writes[0].obj = g_out[i]; + d.writes[0].mask = RX_FIELD(0); + d.n_caps = 1; + d.caps[0].ref = (RxCapRef){ 1, 1 }; + d.caps[0].resource = 1; + d.caps[0].rights = RX_RIGHT_READ | RX_RIGHT_WRITE; + d.fn = fn_gate; + d.user = &g_idx[i]; + uint32_t rid = UINT32_MAX; + rc = rx_world_add_reaction(w, &d, &rid); + if (rc == RX_OK && rid != i) rc = RX_ERR_ARG; + } + if (rc != RX_OK) { + printf(" FAIL setup rc=%d\n", rc); + g_fail++; + rx_world_destroy(w); + free(w); + return -1; + } + + RxObject od0; + memset(&od0, 0, sizeof od0); + rx_world_read(w, g_out[RD], &od0); + footprint_is(w, 0, 0, 0, "before admission"); + + RxMutation m = { e, 0, 1 }; + int64_t ext = rx_world_publish_external(w, (RxCapRef){ 1, 1 }, &m, 1); + CHECK(ext > 0, "outside publication at tick 0 (crumb %lld)", (long long)ext); + int parked = wait_both_in_fn(); + CHECK(parked == 0, "D and H are both inside their functions"); + if (parked != 0) { + release(RD); + release(RH); + rx_world_wait_quiescent(w, 5000); + rx_world_destroy(w); + free(w); + return -1; + } + footprint_is(w, 2, k_mem[RD] + k_mem[RH], k_energy[RD] + k_energy[RH], "both running"); + + budget(&b, final_tick); + rx_world_set_resources(w, &b); + release(RD); + CHECK(wait_d_ended(w) == 0, "D's activation ended while H is still held"); + /* Exactly H's charge: D refunded once, not zero times, not twice. */ + footprint_is(w, 1, k_mem[RH], k_energy[RH], "after D ended, H still held"); + + release(RH); + CHECK(rx_world_wait_quiescent(w, 5000) == 0, "World quiescent after H released"); + footprint_is(w, 0, 0, 0, "after quiescence (pre-admission values)"); + + RxObject od; + memset(&od, 0, sizeof od); + rx_world_read(w, g_out[RD], &od); + RxObject oh; + memset(&oh, 0, sizeof oh); + rx_world_read(w, g_out[RH], &oh); + uint64_t d_commits, h_commits, cancelled, d_commit_crumbs = 0, cancel_crumbs = 0; + const RxCrumb *d_last = NULL; + pthread_mutex_lock(&w->mu); + d_commits = w->reactions[RD].commits; + h_commits = w->reactions[RH].commits; + cancelled = w->stats.deadline_cancelled; + for (uint64_t i = 0; i < w->n_crumbs; i++) { + const RxCrumb *c = &w->crumbs[i]; + if (c->reaction != RD) continue; + d_last = c; + if (c->kind == RX_CRUMB_COMMIT) d_commit_crumbs++; + if (c->kind == RX_CRUMB_CANCELLED) cancel_crumbs++; + } + int d_last_kind = d_last ? (int)d_last->kind : -1; + int d_last_reason = d_last ? d_last->reason : 0; + pthread_mutex_unlock(&w->mu); + + CHECK(h_commits == 1 && oh.field[0] == k_value[RH], "H (no deadline) committed once"); + if (late) { + CHECK(d_commits == 0, "D commits == 0 (got %llu)", (unsigned long long)d_commits); + CHECK(d_commit_crumbs == 0, "no COMMIT crumb of D (got %llu)", + (unsigned long long)d_commit_crumbs); + CHECK(od.field[0] == od0.field[0] && od.version == od0.version && + od.field_version[0] == od0.field_version[0], + "OD unchanged: field0 %llu -> %llu, version %llu -> %llu", + (unsigned long long)od0.field[0], (unsigned long long)od.field[0], + (unsigned long long)od0.version, (unsigned long long)od.version); + CHECK(d_last_kind == RX_CRUMB_CANCELLED && d_last_reason == RX_ERR_DEADLINE, + "D's last crumb is CANCELLED/RX_ERR_DEADLINE (got kind %d reason %d)", + d_last_kind, d_last_reason); + CHECK(cancel_crumbs == 1, "exactly one CANCELLED crumb of D (got %llu)", + (unsigned long long)cancel_crumbs); + CHECK(cancelled == 1, "stats.deadline_cancelled == 1 (got %llu)", + (unsigned long long)cancelled); + } else { + CHECK(d_commits == 1, "D commits == 1 (got %llu)", (unsigned long long)d_commits); + CHECK(od.field[0] == k_value[RD], "OD holds D's value"); + CHECK(cancel_crumbs == 0 && d_last_kind == RX_CRUMB_COMMIT, + "no CANCELLED crumb of D; last is COMMIT (kind %d)", d_last_kind); + CHECK(cancelled == 0, "stats.deadline_cancelled == 0 (got %llu)", + (unsigned long long)cancelled); + } + uint64_t checked = 0; + int vr = rx_world_verify_crumbs(w, &checked); + CHECK(vr == 0, "crumb chain verifies (rc %d, %llu crumbs)", vr, (unsigned long long)checked); + + rx_world_destroy(w); + free(w); + return 0; +} + +int main(void) { + run_case(6); + run_case(5); + if (g_fail) { + printf("RX_DEADLINE_CANCEL: FAIL (%d checks)\n", g_fail); + return 1; + } + printf("RX_DEADLINE_CANCEL: PASS\n"); + return 0; +} diff --git a/tests/runtime/rx_deadline_cancel_mutants.sh b/tests/runtime/rx_deadline_cancel_mutants.sh new file mode 100755 index 000000000..8ad6e7462 --- /dev/null +++ b/tests/runtime/rx_deadline_cancel_mutants.sh @@ -0,0 +1,97 @@ +#!/bin/sh +# HD-09 mutant proof for tests/runtime/rx_deadline_cancel.c. +# +# Copies the tracked tree to a temp dir (the real tree is never modified), +# builds and runs the unmutated test there first (it must PASS, otherwise no +# kill means anything), then applies each mutant M1-M4 to the copy's +# src/runtime/rx_world.c, rebuilds only the test binary, and requires the +# test to FAIL. A mutant that does not apply or does not build is reported +# as NOT_APPLIED / BUILD_FAIL and counts as a survivor. +# +# M1 `>` -> `>=` in the run_one deadline check +# M2 the run_one deadline check removed (condition forced false) +# M3 cancel recorded, but the activation falls through to publishing +# (writes staged and committed) +# M4 cancel without refund (charge marked released before end_activation, +# so uncharge skips it) +# +# Prints MUTANTS_KILLED k/4; exit 0 only when k == 4. +set -u + +root=$(cd "$(dirname "$0")/../.." && pwd) +tmp=$(mktemp -d "${TMPDIR:-/tmp}/rx_deadline_mut.XXXXXX") || exit 1 +trap 'rm -rf "$tmp"' EXIT INT TERM + +base="$tmp/base" +mkdir -p "$base" +(cd "$root" && git ls-files) > "$tmp/files" || { echo "MUTANTS: cannot list tree"; exit 1; } +(cd "$root" && tar -cf - -T "$tmp/files") | (cd "$base" && tar -xf -) || + { echo "MUTANTS: copy failed"; exit 1; } + +src=src/runtime/rx_world.c +check='if (d->need.deadline .. w->budget.logical_tick > d->need.deadline) {' # BRE; '..' matches the && +grep -q 'if (d->need.deadline && w->budget.logical_tick > d->need.deadline) {' "$base/$src" || + { echo "MUTANTS: deadline check not found in $src"; exit 1; } + +build_run() { # dir -> 0 pass, 1 fail, 2 build error + # PHYSICS_DIR / PHYSICS_LOCK_CHECK are passed through explicitly when set + # (host-only runs use PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0). + set -- "$1" + [ -n "${PHYSICS_DIR+x}" ] && set -- "$@" "PHYSICS_DIR=$PHYSICS_DIR" + [ -n "${PHYSICS_LOCK_CHECK+x}" ] && set -- "$@" "PHYSICS_LOCK_CHECK=$PHYSICS_LOCK_CHECK" + dir=$1; shift + make -C "$dir" --no-print-directory "$@" build/rx_deadline_cancel > "$dir/.mut_build.log" 2>&1 || return 2 + set -- "$dir" + (cd "$1" && ./build/rx_deadline_cancel) > "$1/.mut_run.log" 2>&1 && return 0 + return 1 +} + +build_run "$base"; rc=$? +if [ $rc -ne 0 ]; then + echo "BASELINE: FAIL (rc $rc); mutants not judged" + tail -n 20 "$base/.mut_build.log" "$base/.mut_run.log" 2>/dev/null + echo "MUTANTS_KILLED 0/4" + exit 1 +fi +echo "BASELINE: PASS" + +# Apply mutant $1 to the copy in $2. Edits only inside the HD-09 block +# (from the deadline check line to the first line that is exactly " }"). +mutate() { + f="$2/$src" + case "$1" in + M1) sed "s/$check/if (d->need.deadline \&\& w->budget.logical_tick >= d->need.deadline) {/" "$f" > "$f.new" ;; + M2) sed "s/$check/if (0) {/" "$f" > "$f.new" ;; + M3) awk -v pat='if (d->need.deadline && w->budget.logical_tick > d->need.deadline) {' ' + index($0, pat) { inb = 1; print; next } + inb && $0 == " }" { inb = 0; print; next } + inb && ($0 ~ /set_state\(w, r, RX_CANCELLED\);/ || $0 ~ /end_activation\(w, rid\);/ || + $0 ~ /^[ ]*return;[ ]*$/) { next } + { print }' "$f" > "$f.new" ;; + M4) awk -v pat='if (d->need.deadline && w->budget.logical_tick > d->need.deadline) {' ' + index($0, pat) { inb = 1; print; next } + inb && $0 == " }" { inb = 0; print; next } + inb && $0 ~ /end_activation\(w, rid\);/ { print " r->holding = false;" } + { print }' "$f" > "$f.new" ;; + esac + if cmp -s "$f" "$f.new"; then rm -f "$f.new"; return 1; fi + mv "$f.new" "$f" +} + +killed=0 +for m in M1 M2 M3 M4; do + d="$tmp/$m" + mkdir -p "$d" + (cd "$base" && tar -cf - -T "$tmp/files") | (cd "$d" && tar -xf -) + if ! mutate "$m" "$d"; then echo "$m: NOT_APPLIED (survivor)"; continue; fi + build_run "$d"; rc=$? + case $rc in + 1) killed=$((killed + 1)); echo "$m: KILLED ($(grep -c ' FAIL ' "$d/.mut_run.log") failed checks)" ;; + 0) echo "$m: SURVIVED" ;; + *) echo "$m: BUILD_FAIL (survivor)"; tail -n 5 "$d/.mut_build.log" ;; + esac + rm -rf "$d" +done + +echo "MUTANTS_KILLED $killed/4" +[ "$killed" -eq 4 ]