Add branch coverage measurement for random simulation
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.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
|
||||
CFLAGS = -Wall -Wextra -ggdb
|
||||
COVERAGE_CFLAGS = $(CFLAGS) --coverage
|
||||
COVERAGE_LFLAGS = --coverage
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
LFLAGS = -lws2_32
|
||||
@@ -13,16 +15,21 @@ CFILES = $(shell find src -name '*.c')
|
||||
HFILES = $(shell find src -name '*.h')
|
||||
OFILES = $(CFILES:.c=.o)
|
||||
|
||||
.PHONY: all clean
|
||||
.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.
|
||||
|
||||
@@ -33,12 +40,18 @@ libmousefs.a: $(OFILES)
|
||||
ar rcs $@ $^
|
||||
|
||||
clean:
|
||||
rm -f \
|
||||
mousefs.exe \
|
||||
mousefs.out \
|
||||
mousefs_random_test.exe \
|
||||
mousefs_random_test.out \
|
||||
example_client.exe \
|
||||
example_client.out \
|
||||
libmousefs.a \
|
||||
src/*.o
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user