From a4ca3d14c1ae8297c286626fa347125ed2c30297 Mon Sep 17 00:00:00 2001 From: Corey Tabaka Date: Sat, 6 Jan 2018 13:11:52 -0800 Subject: [PATCH] Add simple coverage report rule usng lcov and genhtml. --- Makefile | 14 ++++++++++++-- test/nop_tests.cpp | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1a9a54a..20a1e1c 100644 --- a/Makefile +++ b/Makefile @@ -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 \ @@ -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: diff --git a/test/nop_tests.cpp b/test/nop_tests.cpp index aff17f3..2e7ce9a 100644 --- a/test/nop_tests.cpp +++ b/test/nop_tests.cpp @@ -14,3 +14,7 @@ #include +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}