memgraph coverage (lcov setup in progress...)

Summary: first version of coverage (will be polished)

Reviewers: dgleich, mferencevic, florijan, teon.banek

Reviewed By: dgleich

Subscribers: pullbot, buda

Differential Revision: https://phabricator.memgraph.io/D76
This commit is contained in:
Marko Budiselic 2017-03-07 18:25:49 +01:00
parent 57740bcf95
commit b834cdc94a
7 changed files with 69 additions and 7 deletions

View File

@ -9,12 +9,15 @@ if(NOT UNIX)
message(FATAL "Unsupported operating system.")
endif()
#look for ccache and set it up
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
# ccache setup
# ccache isn't enabled all the time because it makes some problem
# during the code coverage process
option(USE_CCACHE "ccache:" ON)
message(STATUS "CCache: ${USE_CCACHE}")
if(CCACHE_FOUND AND USE_CCACHE)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
endif(CCACHE_FOUND AND USE_CCACHE)
# choose a compiler
# NOTE: must be choosen before use of project() or enable_language() ----------

37
coverage Executable file
View File

@ -0,0 +1,37 @@
#!/bin/bash
working_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# coverage applies only on unit tests
unit_test_dir='build/tests/unit'
coverage_dir='build/coverage'
coverage_file='coverage.info'
# execute unit tests to generate coverage files
pushd ${unit_test_dir}
ctest -R unit
popd
# generate coverage info files for each unit test binary
# + exclude stl, tests and libs
binary_path="${unit_test_dir}/CMakeFiles"
all_coverage_info=""
for dir in $binary_path/*.dir; do
pushd ${dir}
lcov --gcov-tool ${working_dir}/llvm-gcov -c -d . -o ${coverage_file}
lcov -r ${coverage_file} '/usr/*' '*/libs/*' -o ${coverage_file}
all_coverage_info+=" -a ${working_dir}/${dir}/${coverage_file}"
popd
done
# merge all info files into total coverage info and generate html
echo ${all_coverage_info}
mkdir -p ${coverage_dir}
pushd ${coverage_dir}
lcov ${all_coverage_info} -o ${coverage_file}
genhtml ${coverage_file}
popd
# generage coberatura xml file (compatible with Jenkins)
python libs/lcov-to-cobertura-xml/lcov_cobertura/lcov_cobertura.py \
${coverage_dir}/${coverage_file} -o ${coverage_dir}/coverage.xml

View File

@ -3,10 +3,16 @@
# This scrips runs clang-format recursively on all files under specified
# directories. Formatting configuration is defined in .clang-format.
# Format isn't enforced. Code reviewer has to ensure that a code format is
# valid and appropriate for the project.
clang_format="clang-format"
for directory in src tests
do
# If somebody wants to exclude a file from default formating here is a place
# for that
echo "formatting code under $directory/"
find "$directory" \( -name '*.hpp' -or -name '*.cpp' \) -print0 | xargs -0 "${clang_format}" -i
done

View File

@ -1,7 +1,9 @@
#!/bin/bash
echo "START"
# install all dependencies on debian based operating systems
for pkg in wget git cmake uuid-dev clang-3.8; do
for pkg in wget git cmake uuid-dev clang-3.8 llvm-3.8 clang-format-3.8 doxygen; do
dpkg -s $pkg 2>/dev/null >/dev/null || sudo apt-get -y install $pkg
done

View File

@ -46,3 +46,10 @@ yaml_cpp_tag="519d33fea3fbcbe7e1f89f97ee0fa539cec33eb7" # master 18 Aug 2016
cd yaml-cpp
git checkout ${yaml_cpp_tag}
cd ..
# lcov-to-coberatura-xml
git clone https://github.com/eriwen/lcov-to-cobertura-xml.git
lcov_to_xml_tag="59584761cb5da4687693faec05bf3e2b74e9dde9" # Dec 6, 2016
cd lcov-to-cobertura-xml
git checkout ${lcov_to_xml_tag}
cd ..

3
llvm-gcov Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
exec llvm-cov-3.8 gcov "$@"

View File

@ -19,6 +19,8 @@ foreach(test_cpp ${test_type_cpps})
# build exec file
add_executable(${target_name} ${test_cpp})
set_property(TARGET ${target_name} PROPERTY CXX_STANDARD ${cxx_standard})
set_target_properties(${target_name} PROPERTIES COMPILE_FLAGS "-g -O0 -Wall --coverage -fprofile-arcs -ftest-coverage")
set_target_properties(${target_name} PROPERTIES LINK_FLAGS "--coverage -fprofile-arcs -ftest-coverage")
# OUTPUT_NAME sets the real name of a target when it is built and can be
# used to help create two targets of the same name even though CMake
@ -38,10 +40,12 @@ foreach(test_cpp ${test_type_cpps})
target_link_libraries(${target_name} fmt)
# yaml parser lib
target_link_libraries(${target_name} yaml-cpp)
# antlr
target_link_libraries(${target_name} antlr_opencypher_parser_lib)
# antlr
target_link_libraries(${target_name} antlr_opencypher_parser_lib)
# dynamic lib
target_link_libraries(${target_name} dl)
# for code coverage
target_link_libraries(${target_name} gcov)
# register test
set(output_path ${CMAKE_BINARY_DIR}/test_results/unit/${target_name}.xml)