diff options
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | Makefile | 32 |
2 files changed, 29 insertions, 8 deletions
@@ -8,3 +8,8 @@ tests/run compile_flags.txt compile_commands.json .cache/ + +*.gcno +*.gcda +*.profraw +*.profdata @@ -1,5 +1,5 @@ CC = clang -CFLAGS = -Wall -std=c89 -D_DEFAULT_SOURCE -Wvla \ +CFLAGS = -Wall -std=c89 -D_DEFAULT_SOURCE -D_GNU_SOURCE -Wvla \ -Wdeclaration-after-statement -Wstrict-prototypes \ -Wunreachable-code -Wsign-compare -Wimplicit-int-conversion \ -Wsign-conversion @@ -9,7 +9,13 @@ SOURCEDIR = src OBJECTDIR = obj TESTDIR = tests -TESTFLAGS = $(CFLAGS) -D_TEST +TESTCFLAGS = -D_TEST -g -Wall -std=c89 -D_DEFAULT_SOURCE -D_GNU_SOURCE -Wvla \ + -Wdeclaration-after-statement -Wstrict-prototypes \ + -Wunreachable-code -Wsign-compare -Wimplicit-int-conversion \ + -Wsign-conversion +TESTLDFLAGS = $(LDFLAGS) -lcheck + +COVCFLAGS = -fprofile-instr-generate -fcoverage-mapping OUTPUT = dnsd @@ -27,21 +33,28 @@ build: dir $(OBJ) @echo [LD] $(OBJ) @$(CC) $(CFLAGS) -o $(BUILDDIR)/$(OUTPUT) $(OBJ) $(LDFLAGS) -debug: CFLAGS += -g -D _DEBUG +debug: CFLAGS += -g -D_DEBUG debug: build; -build_test: LDFLAGS += -lcheck build_test: dir $(TOBJS) $(TSUBS) @echo [LD] $(TOBJS) $(TSUBS) - @$(CC) $(TESTFLAGS) -o $(TESTDIR)/run $(TOBJS) $(TSUBS) $(LDFLAGS) + @$(CC) $(TESTCFLAGS) -o $(TESTDIR)/run $(TOBJS) $(TSUBS) $(TESTLDFLAGS) test: build_test @$(TESTDIR)/run -valgrind_test: CFLAGS += -g valgrind_test: build_test @CK_FORK=no valgrind --leak-check=full $(TESTDIR)/run +coverage: CFLAGS += $(COVCFLAGS) +coverage: TESTLDFLAGS += -fprofile-instr-generate +coverage: clean build_test + @LLVM_PROFILE_FILE="coverage.profraw" $(TESTDIR)/run + @llvm-profdata merge -sparse coverage.profraw -o coverage.profdata + @llvm-cov show $(TESTDIR)/run -instr-profile=coverage.profdata -format=html \ + > coverage.html + @llvm-cov report $(TESTDIR)/run -instr-profile=coverage.profdata + dir: @mkdir -p $(OBJECTDIR) @mkdir -p $(BUILDDIR) @@ -52,7 +65,7 @@ $(OBJECTDIR)/%.o: $(SOURCEDIR)/%.c $(TESTDIR)/%.o: $(TESTDIR)/%.c @echo [TEST] $< - @$(CC) $(TESTFLAGS) -c $< -o $@ + @$(CC) $(TESTCFLAGS) -c $< -o $@ #sudo setcap 'cap_net_bind_service=+ep' /path/to/prog #to allow port access @@ -65,6 +78,9 @@ clean: @echo [RM] $(BUILDDIR)/$(OUTPUT) $(TESTDIR)/run @rm -df $(OBJ) $(TOBJS) $(TESTDIR)/run @rm -Rdf $(BUILDDIR) $(OBJECTDIR) + @rm -f {$(SOURCEDIR),$(TESTDIR)}/*.gc{da,no} + @rm -f *.prof{raw,data} + @rm -f coverage.html .PHONY: all all: clean build @@ -75,6 +91,6 @@ devsetup: echo "{\"directory\":\"$(PWD)\",\"command\":\"$(shell which $(CC)) $(CFLAGS) -c $$file\",\"file\":\"$(PWD)/$$file\"}," >> compile_commands.json;\ done @for file in $(TESTS); do \ - echo "{\"directory\":\"$(PWD)\",\"command\":\"$(shell which $(CC)) $(TESTFLAGS) -c $$file\",\"file\":\"$(PWD)/$$file\"}," >> compile_commands.json;\ + echo "{\"directory\":\"$(PWD)\",\"command\":\"$(shell which $(CC)) $(TESTCFLAGS) -c $$file\",\"file\":\"$(PWD)/$$file\"}," >> compile_commands.json;\ done @echo "]" >> compile_commands.json |