Skip to content

Commit

Permalink
Add simple coverage report rule usng lcov and genhtml.
Browse files Browse the repository at this point in the history
  • Loading branch information
eieio committed Jan 22, 2018
1 parent c945565 commit a4ca3d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ ALL :=
DEPS :=

M_NAME := test
M_CFLAGS := -I$(GTEST_INCLUDE)
M_LDFLAGS := -L$(GTEST_LIB) -lgtest -lgtest_main
M_CFLAGS := -I$(GTEST_INCLUDE) --coverage -O0 -g
M_LDFLAGS := -L$(GTEST_LIB) -lgtest
M_OBJS := \
test/nop_tests.o \
test/encoding_tests.o \
Expand Down Expand Up @@ -81,6 +81,16 @@ clean::
@echo clean
@rm -rf $(OUT)

# Generate coverage report with lcov and genhtml. A bit hacky but works okay.
$(OUT)/coverage.info: $(OUT)/test
$(QUIET)find $(OUT) -name "*.gcda" -exec rm {} \+
$(QUIET)$(OUT)/test
lcov --capture --directory $(OUT_HOST_OBJ)/test/test/ --output-file $@ --no-external --base-directory .
mkdir -p $(OUT)/coverage
genhtml -o $(OUT)/coverage $@

coverage:: $(OUT)/coverage.info

all:: $(ALL)

# we generate .d as a side-effect of compiling. override generic rule:
Expand Down
4 changes: 4 additions & 0 deletions test/nop_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@

#include <gtest/gtest.h>

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit a4ca3d1

Please sign in to comment.