drivers/freshness: hardened + 100% MC/DC (Tier-1, the UI stale-number guard)

freshness.c (ADR-0004 freshness-contract engine) is pure logic via produce/render
callbacks — no hardware seam needed, the callbacks are the seam. Host harness reaches
100% MC/DC (66/66 conditions, 100% lines, 27 checks) by driving warden_fresh_decide
directly + the bind/tick/invalidate/min-budget state machine through fakes, with
-DFRESH_MAX=2 so the table-full and unused/hidden-slot arms are reachable. Directly
serves future-features-2's "never a stale number in the UI" requirement. The CI mcdc
job now enforces relays + freshness.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017wB8KB3MMQztRDXCMCkPrf
This commit is contained in:
BFE Engineering
2026-08-25 15:18:51 -06:00
co-authored by Claude Opus 4.8
parent e07db1d87e
commit 35829eaccb
5 changed files with 540 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
# MC/DC unit harness for drivers/freshness/freshness.c (the UI stale-number guard).
#
# make check — build, run, FAIL unless freshness.c hits 100% MC/DC + all checks.
# make report — per-condition gcov annotation.
# make clean
#
# FRESH_MAX is forced to 2 so the "binding table full -> NULL" path is reachable
# with two binds (the production default is 96). Requires gcc >= 14.
CC ?= gcc
GCOV ?= gcov
CFLAGS := -O0 -g -Wall -Wextra -I.. -DFRESH_MAX=2
COVFLAGS := --coverage -fcondition-coverage
BUILD := build
.PHONY: check report clean
.DEFAULT_GOAL := check
$(BUILD):
@mkdir -p $(BUILD)
$(BUILD)/test: test_freshness.c ../freshness.c ../freshness.h | $(BUILD)
@$(CC) $(CFLAGS) $(COVFLAGS) -c ../freshness.c -o $(BUILD)/freshness.o
@$(CC) $(CFLAGS) -c test_freshness.c -o $(BUILD)/test_freshness.o
@$(CC) $(COVFLAGS) $(BUILD)/freshness.o $(BUILD)/test_freshness.o -o $(BUILD)/test
check: $(BUILD)/test
@echo "== running freshness MC/DC harness =="
@rm -f $(BUILD)/freshness.gcda
@$(BUILD)/test; echo $$? > $(BUILD)/test.rc
@echo
@echo "== MC/DC (condition) coverage of freshness.c =="
@$(GCOV) --conditions --branch-probabilities -o $(BUILD) ../freshness.c >$(BUILD)/gcov.log 2>&1 || true
@mv -f *.gcov $(BUILD)/ 2>/dev/null || true
@bash enforce-mcdc.sh $(BUILD)/gcov.log $(BUILD)/freshness.c.gcov $(BUILD)/test.rc
report: check
@grep -nE "condition.*not covered|conditions covered" $(BUILD)/freshness.c.gcov || true
clean:
@rm -rf $(BUILD)