Skip to content

Commit fbcc7eb

Browse files
committed
added code coverage support in CacheLib
1 parent 265c312 commit fbcc7eb

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

cachelib/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ set(CMAKE_MODULE_PATH
8585
set(CMAKE_CXX_STANDARD 17)
8686
set(CMAKE_CXX_STANDARD_REQUIRED True)
8787

88+
if(COVERAGE_ENABLED)
89+
# Add code coverage
90+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
91+
endif()
92+
8893
# include(fb_cxx_flags)
8994
message(STATUS "Update CXXFLAGS: ${CMAKE_CXX_FLAGS}")
9095

run_code_coverage.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
BUILD_DIR='build-cachelib'
4+
mkdir ${BUILD_DIR}
5+
cd ${BUILD_DIR}
6+
cmake ../cachelib -DBUILD_TESTS=ON -DCMAKE_INSTALL_PREFIX=/opt -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE_ENABLED=ON
7+
make install -j
8+
cd -
9+
10+
# Track coverage
11+
lcov -c -i -b . -d . -o Coverage.baseline
12+
./run_tests.sh
13+
lcov -c -d . -b . -o Coverage.out
14+
lcov -a Coverage.baseline -a Coverage.out -o Coverage.combined
15+
16+
# Generate report
17+
COVERAGE_DIR='coverage_report'
18+
genhtml Coverage.combined -o ${COVERAGE_DIR}
19+
COVERAGE_REPORT="${COVERAGE_DIR}.tgz"
20+
tar -zcvf ${COVERAGE_REPORT} ${COVERAGE_DIR}
21+
echo "Created coverage report ${COVERAGE_REPORT}"
22+
23+
# Cleanup
24+
rm Coverage.baseline Coverage.out Coverage.combined
25+
rm -rf ${COVERAGE_DIR}

0 commit comments

Comments
 (0)