Artifact 6e98181fb82645200ed2f901153f5546c3fc61ffde60170c5f07ff70720b8681:
- File
Makefile
— part of check-in
[3f905be4f2]
at
2026-11-12 21:17:36
on branch trunk
— Every branch of suit's own code is tested, and the gates that keep it so
make cover fails unless every function, line, region and branch in src/ is run by a test. Every system call goes through a wrapper in platform.c that a test build can make fail, so failed-call branches are tested too. The release binary carries none of that code, and a test checks it.
Also: ensure() for invariants, a wider warning set as errors, the clang static analyzer, a second fuzz target for the stamp reader, a replay binary for saved fuzz inputs, a release build that the speed budget now measures, and make ci for the forge's Linux runner: the suite under gcc's sanitizers, then under a pinned Fil-C.
210 unit checks and 214 shell cases. The no-change run measured 0.56 to 0.60 ms over an empty program with the release build.
The Fil-C run and the Linux build have not been run yet. They run first on the forge's runner.
Decisions recorded: the wardrobe is two repositories, libfossil is used through its C API with suit's own file writer, and where each gate runs. (user: dmestas, size: 7439) [annotate] [blame] [check-ins using]
# suit: no configure step. Output goes in build/. See docs/quality.md.
CC ?= cc
LLVM_BIN ?= $(if $(wildcard /opt/homebrew/opt/llvm/bin/clang),/opt/homebrew/opt/llvm/bin,$(patsubst %/,%,$(dir $(shell command -v clang))))
UNAME := $(shell uname -s)
# C23 under whichever name this compiler knows it by (GCC 13 has only c2x).
STD := $(firstword $(foreach s,c23 c2x,$(if $(shell echo 'constexpr int x = 1; [[maybe_unused]] static bool b = nullptr == nullptr;' | $(CC) -std=$(s) -x c - -fsyntax-only 2>/dev/null && echo ok),$(s))))
ifeq ($(STD),)
$(error $(CC) does not accept -std=c23 or -std=c2x with constexpr, nullptr and bool; need GCC 13 or Clang 18 or newer)
endif
W := -std=$(STD) -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wshadow \
-Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -Wcast-align -Wformat=2 \
-Wundef -Wvla -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough \
-Werror -D_DEFAULT_SOURCE
SAN := -O1 -g -fno-omit-frame-pointer -fsanitize=address,undefined \
-fno-sanitize-recover=all -DSUIT_TEST
ifeq ($(UNAME),Darwin)
STRIP := -Wl,-x -Wl,-S
SDK := -isysroot $(shell xcrun --show-sdk-path)
else
STRIP := -s
SDK :=
endif
REL := -O2 -flto $(STRIP)
COV := -O0 -g -D_FORTIFY_SOURCE=0 -fprofile-instr-generate -fcoverage-mapping -DSUIT_TEST -DSUIT_COVER
LIB := src/conf.c src/stamp.c src/bench.c src/platform.c
MAIN := src/main.c
HDR := $(wildcard src/*.h)
FUZZ_TIME ?= 30
MUTATE_ITER ?= 200000
.PHONY: suit release check cover analyze check-budget fuzz filc ci all clean
suit: build/dev/suit build/dev/empty
# ---- dev: sanitizers and fault injection -----------------------------------
build/dev/suit: $(LIB) $(MAIN) $(HDR) Makefile
@mkdir -p build/dev
$(CC) $(W) $(SAN) -o $@ $(LIB) $(MAIN)
build/dev/empty: test/empty.c Makefile
@mkdir -p build/dev
$(CC) $(W) -O2 -o $@ test/empty.c
build/dev/unit: test/unit.c $(LIB) $(HDR) Makefile
@mkdir -p build/dev
$(CC) $(W) $(SAN) -Isrc -o $@ test/unit.c $(LIB)
check: build/dev/suit build/dev/empty build/dev/unit build/dev/replay-conf build/dev/replay-stamp
ASAN_OPTIONS=detect_leaks=0 build/dev/unit
ASAN_OPTIONS=detect_leaks=0 SUIT=build/dev/suit sh test/run.sh
ASAN_OPTIONS=detect_leaks=0 sh test/replay.sh build/dev
build/dev/replay-%: test/fuzz_%.c test/replay.c $(LIB) $(HDR) Makefile
@mkdir -p build/dev
$(CC) $(W) $(SAN) -Isrc -o $@ $< test/replay.c $(LIB)
# ---- release: fast, no test code ------------------------------------------
release: build/release/suit build/release/empty
sh test/release_clean.sh build/release/suit build/dev/suit
build/release/suit: $(LIB) $(MAIN) $(HDR) Makefile
@mkdir -p build/release
$(CC) $(W) $(REL) -o $@ $(LIB) $(MAIN)
build/release/empty: test/empty.c Makefile
@mkdir -p build/release
$(CC) $(W) $(REL) -o $@ test/empty.c
check-budget: build/release/suit build/release/empty
SUIT=build/release/suit sh test/budget.sh
# ---- coverage: 100% of src/, or fail ---------------------------------------
build/cover/suit: $(LIB) $(MAIN) $(HDR) Makefile
@mkdir -p build/cover
$(LLVM_BIN)/clang $(W) $(COV) -o $@ $(LIB) $(MAIN)
build/cover/unit: test/unit.c $(LIB) $(HDR) Makefile
@mkdir -p build/cover
$(LLVM_BIN)/clang $(W) $(COV) -Isrc -o $@ test/unit.c $(LIB)
build/cover/replay-%: test/fuzz_%.c test/replay.c $(LIB) $(HDR) Makefile
@mkdir -p build/cover
$(LLVM_BIN)/clang $(W) $(COV) -Isrc -o $@ $< test/replay.c $(LIB)
build/cover/empty: test/empty.c Makefile
@mkdir -p build/cover
$(CC) $(W) -O2 -o $@ test/empty.c
cover: build/cover/suit build/cover/empty build/cover/unit build/cover/replay-conf build/cover/replay-stamp
rm -rf build/cover/prof build/cover/all.profdata
mkdir -p build/cover/prof
LLVM_PROFILE_FILE=$(CURDIR)/build/cover/prof/%p-%m.profraw build/cover/unit
LLVM_PROFILE_FILE=$(CURDIR)/build/cover/prof/%p-%m.profraw SUIT=$(CURDIR)/build/cover/suit sh test/run.sh
LLVM_PROFILE_FILE=$(CURDIR)/build/cover/prof/%p-%m.profraw sh test/replay.sh build/cover
$(LLVM_BIN)/llvm-profdata merge -sparse build/cover/prof/*.profraw -o build/cover/all.profdata
python3 tools/cover_gate.py $(LLVM_BIN)/llvm-cov build/cover/all.profdata build/cover/suit build/cover/unit build/cover/replay-conf build/cover/replay-stamp
# ---- static analysis -------------------------------------------------------
analyze:
$(LLVM_BIN)/clang --analyze -Xclang -analyzer-output=text -Xclang -analyzer-werror $(SDK) $(W) -DSUIT_TEST -Isrc $(LIB) $(MAIN)
$(LLVM_BIN)/clang --analyze -Xclang -analyzer-output=text -Xclang -analyzer-werror $(SDK) $(W) -DSUIT_TEST -DSUIT_COVER -Isrc $(LIB) $(MAIN)
# ---- fuzzing ---------------------------------------------------------------
# libFuzzer from Homebrew's llvm when it works; otherwise a fixed-seed mutation
# loop. Both fuzz targets, seeds in test/corpus/NAME, findings kept in
# build/fuzz/corpus-NAME (replayed by check and cover).
build/fuzz/%: test/fuzz_%.c $(LIB) $(HDR) Makefile
@mkdir -p build/fuzz
$(LLVM_BIN)/clang $(W) -O1 -g -fsanitize=fuzzer,address,undefined \
-fno-sanitize-recover=all -DSUIT_TEST -Isrc -o $@ $< $(LIB)
fuzz: build/dev/replay-conf build/dev/replay-stamp
@mkdir -p build/fuzz
@if printf 'int LLVMFuzzerTestOneInput(const unsigned char *d, unsigned long n) { (void)d; (void)n; return 0; }' \
| "$(LLVM_BIN)/clang" -fsanitize=fuzzer -x c - -o build/fuzz/probe >/dev/null 2>&1; then \
for t in conf stamp; do \
$(MAKE) --no-print-directory build/fuzz/$$t && \
mkdir -p build/fuzz/corpus-$$t && \
{ echo "fuzz $$t: libFuzzer, $(FUZZ_TIME) seconds"; \
ASAN_OPTIONS=detect_leaks=0 build/fuzz/$$t build/fuzz/corpus-$$t test/corpus/$$t \
-max_total_time=$(FUZZ_TIME) -max_len=16384 -timeout=10 -close_fd_mask=3 \
-artifact_prefix=build/fuzz/ -print_final_stats=1 > build/fuzz/$$t.log 2>&1 \
|| { tail -30 build/fuzz/$$t.log; exit 1; }; \
grep number_of_executed_units build/fuzz/$$t.log | sed "s/^stat::/fuzz $$t: /"; } || exit 1; \
done; \
else \
for t in conf stamp; do \
echo "fuzz $$t: mutation loop (no libFuzzer), fixed seed"; \
ASAN_OPTIONS=detect_leaks=0 build/dev/replay-$$t --mutate $(MUTATE_ITER) test/corpus/$$t || exit 1; \
done; \
fi
# ---- Fil-C (Linux only; tools/filc.sh sets up the toolchain) ---------------
filc:
sh tools/filc.sh
# Run by tools/filc.sh with FILCC pointing at the Fil-C compiler.
FILCC ?=
FILC_FLAGS := -O2 -g -DSUIT_TEST
filc-run:
@test -n "$(FILCC)" || { echo "no Fil-C compiler; set FILCC" >&2; exit 1; }
mkdir -p build/filc
$(FILCC) $(W) $(FILC_FLAGS) -o build/filc/suit $(LIB) $(MAIN)
$(FILCC) $(W) -O2 -o build/filc/empty test/empty.c
$(FILCC) $(W) $(FILC_FLAGS) -Isrc -o build/filc/unit test/unit.c $(LIB)
$(FILCC) $(W) $(FILC_FLAGS) -Isrc -o build/filc/replay-conf test/fuzz_conf.c test/replay.c $(LIB)
$(FILCC) $(W) $(FILC_FLAGS) -Isrc -o build/filc/replay-stamp test/fuzz_stamp.c test/replay.c $(LIB)
build/filc/unit
SUIT=build/filc/suit sh test/run.sh
sh test/replay.sh build/filc
# ---- CI: what the Linux runner runs (system cc, no clang, no coverage) -----
ci:
@echo "ci: $(CC) with -std=$(STD)"
$(MAKE) check
$(MAKE) filc
# ---- everything ------------------------------------------------------------
# Every gate, in order, stopping at the first failure.
all:
$(MAKE) suit
$(MAKE) release
$(MAKE) check
$(MAKE) cover
$(MAKE) analyze
$(MAKE) check-budget
$(MAKE) fuzz
$(MAKE) filc
clean:
rm -rf build