Skip to content

Code coverage support for CacheLib #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cachelib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ set(CMAKE_MODULE_PATH
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

if(COVERAGE_ENABLED)
# Add code coverage
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
endif()

# include(fb_cxx_flags)
message(STATUS "Update CXXFLAGS: ${CMAKE_CXX_FLAGS}")

Expand Down
20 changes: 20 additions & 0 deletions run_code_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

#Build CacheLib with flag -DCOVERAGE_ENABLED=ON

# Track coverage
lcov -c -i -b . -d . -o Coverage.baseline
./run_tests.sh
lcov -c -d . -b . -o Coverage.out
lcov -a Coverage.baseline -a Coverage.out -o Coverage.combined

# Generate report
COVERAGE_DIR='coverage_report'
genhtml Coverage.combined -o ${COVERAGE_DIR}
COVERAGE_REPORT="${COVERAGE_DIR}.tgz"
tar -zcvf ${COVERAGE_REPORT} ${COVERAGE_DIR}
echo "Created coverage report ${COVERAGE_REPORT}"

# Cleanup
rm Coverage.baseline Coverage.out Coverage.combined
rm -rf ${COVERAGE_DIR}