This commit adds tooling to measure how many branches the random simulation reaches during execution, which helps understand code coverage and identify untested code paths. Changes: - Add coverage build target to Makefile with --coverage flags - Create measure_coverage.sh script to build, run, and report branch coverage - Add signal handlers (SIGINT/SIGTERM) to main_test.c for clean shutdown - Update clean target to remove coverage files (*.gcda, *.gcno) The script runs the simulation for a specified duration (default 5 seconds), then uses gcov to analyze which branches were executed. In a 3-second run, the simulation reaches approximately 32% of all branches (781/2431). Usage: ./measure_coverage.sh [duration_in_seconds] Example output shows per-file and total branch coverage statistics.
58 lines
1.5 KiB
Makefile
58 lines
1.5 KiB
Makefile
|
|
CFLAGS = -Wall -Wextra -ggdb
|
|
COVERAGE_CFLAGS = $(CFLAGS) --coverage
|
|
COVERAGE_LFLAGS = --coverage
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
LFLAGS = -lws2_32
|
|
EXT = .exe
|
|
else
|
|
LFLAGS =
|
|
EXT = .out
|
|
endif
|
|
|
|
CFILES = $(shell find src -name '*.c')
|
|
HFILES = $(shell find src -name '*.h')
|
|
OFILES = $(CFILES:.c=.o)
|
|
|
|
.PHONY: all clean coverage
|
|
|
|
all: mousefs$(EXT) mousefs_random_test$(EXT) example_client$(EXT) libmousefs.a
|
|
|
|
coverage: mousefs_random_test_coverage$(EXT)
|
|
|
|
mousefs$(EXT): $(CFILES) $(HFILES)
|
|
gcc -o $@ $(CFILES) $(CFLAGS) $(LFLAGS) -Iinc -DBUILD_SERVER
|
|
|
|
mousefs_random_test$(EXT): $(CFILES) $(HFILES)
|
|
gcc -o $@ $(CFILES) $(CFLAGS) $(LFLAGS) -Iinc -DBUILD_TEST
|
|
|
|
mousefs_random_test_coverage$(EXT): $(CFILES) $(HFILES)
|
|
gcc -o $@ $(CFILES) $(COVERAGE_CFLAGS) $(LFLAGS) $(COVERAGE_LFLAGS) -Iinc -DBUILD_TEST
|
|
|
|
example_client$(EXT): libmousefs.a
|
|
gcc -o $@ examples/main.c $(CFLAGS) -lmousefs $(LFLAGS) -Iinc -L.
|
|
|
|
%.o: %.c $(HFILES)
|
|
gcc -c -o $@ $< $(CFLAGS) -Iinc
|
|
|
|
libmousefs.a: $(OFILES)
|
|
ar rcs $@ $^
|
|
|
|
clean:
|
|
rm -f \
|
|
mousefs.exe \
|
|
mousefs.out \
|
|
mousefs_random_test.exe \
|
|
mousefs_random_test.out \
|
|
mousefs_random_test_coverage.exe \
|
|
mousefs_random_test_coverage.out \
|
|
example_client.exe \
|
|
example_client.out \
|
|
libmousefs.a \
|
|
src/*.o \
|
|
src/*.gcda \
|
|
src/*.gcno \
|
|
*.gcda \
|
|
*.gcno
|