Skip to content

Commit 006f9e0

Browse files
AbdealiLoKotqchen
authored andcommitted
Makefile: Add CPP code coverage
1 parent 1f2ad36 commit 006f9e0

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ export CXX = $(if $(shell which g++-6),g++-6,$(if $(shell which g++-mp-6),g++-mp
4848
endif
4949

5050
export LDFLAGS= -pthread -lm $(ADD_LDFLAGS) $(DMLC_LDFLAGS) $(PLUGIN_LDFLAGS)
51-
export CFLAGS= -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude $(ADD_CFLAGS) $(PLUGIN_CFLAGS)
51+
export CFLAGS= -std=c++0x -Wall -Wno-unknown-pragmas -Iinclude $(ADD_CFLAGS) $(PLUGIN_CFLAGS)
5252
CFLAGS += -I$(DMLC_CORE)/include -I$(RABIT)/include
5353
#java include path
5454
export JAVAINCFLAGS = -I${JAVA_HOME}/include -I./java
5555

56+
ifeq ($(TEST_COVER), 1)
57+
CFLAGS += -g -O0 -fprofile-arcs -ftest-coverage
58+
else
59+
CFLAGS += -O3 -funroll-loops -msse2
60+
endif
61+
5662
ifndef LINT_LANG
5763
LINT_LANG= "all"
5864
endif
@@ -152,9 +158,14 @@ test: $(ALL_TEST)
152158
check: test
153159
./tests/cpp/xgboost_test
154160

161+
ifeq ($(TEST_COVER), 1)
162+
cover: check
163+
gcov -pbcu $(COVER_OBJ)
164+
endif
165+
155166
clean:
156167
$(RM) -rf build build_plugin lib bin *~ */*~ */*/*~ */*/*/*~ */*.o */*/*.o */*/*/*.o xgboost
157-
$(RM) -rf build_tests tests/cpp/xgboost_test
168+
$(RM) -rf build_tests *.gcov tests/cpp/xgboost_test
158169

159170
clean_all: clean
160171
cd $(DMLC_CORE); $(MAKE) clean; cd $(ROOTDIR)

make/config.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ LIB_RABIT = librabit.a
4747
# path to libjvm.so
4848
LIBJVM=$(JAVA_HOME)/jre/lib/amd64/server
4949

50+
# whether to test with coverage measurement or not. (only used for `make cover`)
51+
# measured with gcov and html report generated with lcov if it is installed.
52+
# this disables optimization to ensure coverage information is correct
53+
TEST_COVER = 1
54+
5055
# path to gtest library (only used when $BUILD_TEST=1)
5156
# there should be an include path in $GTEST_PATH/include and library in $GTEST_PATH/lib
5257
GTEST_PATH =

tests/cpp/xgboost_test.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ UNITTEST_CFLAGS=$(CFLAGS)
1111
UNITTEST_LDFLAGS=$(LDFLAGS) -L$(GTEST_LIB) -lgtest
1212
UNITTEST_DEPS=lib/libxgboost.a $(DMLC_CORE)/libdmlc.a $(RABIT)/lib/$(LIB_RABIT)
1313

14+
COVER_OBJ=$(patsubst %.o, %.gcda, $(ALL_OBJ)) $(patsubst %.o, %.gcda, $(UNITTEST_OBJ))
15+
1416
$(UTEST_OBJ_ROOT)/%.o: $(UTEST_ROOT)/%.cc
1517
@mkdir -p $(@D)
1618
$(CXX) $(UNITTEST_CFLAGS) -I$(GTEST_INC) -o $@ -c $<

0 commit comments

Comments
 (0)