diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2021-09-19 22:09:23 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2021-09-19 22:11:29 +0200 |
commit | cd735a144ccac75282179af8dad056b5e5c0a83d (patch) | |
tree | 29a0b3747c8981a5788bf9c19f9b43b574dc5f3d /Makefile | |
parent | 03a5fa0dfcf98fc006d90c821d2a10eafbcdc330 (diff) | |
download | dns-cd735a144ccac75282179af8dad056b5e5c0a83d.tar.gz |
Makefile: Coverage
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 32 |
1 files changed, 24 insertions, 8 deletions
@@ -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 |