From b834cdc94ab1efeaf40126d5650c9536dcdb4104 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Tue, 7 Mar 2017 18:25:49 +0100 Subject: [PATCH] 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 --- CMakeLists.txt | 11 +++++++---- coverage | 37 +++++++++++++++++++++++++++++++++++++ format.sh => format | 6 ++++++ init.sh => init | 4 +++- libs/setup.sh | 7 +++++++ llvm-gcov | 3 +++ tests/unit/CMakeLists.txt | 8 ++++++-- 7 files changed, 69 insertions(+), 7 deletions(-) create mode 100755 coverage rename format.sh => format (63%) rename init.sh => init (73%) create mode 100755 llvm-gcov diff --git a/CMakeLists.txt b/CMakeLists.txt index 68ffa5e34..14cbb72bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() ---------- diff --git a/coverage b/coverage new file mode 100755 index 000000000..fbd38174a --- /dev/null +++ b/coverage @@ -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 diff --git a/format.sh b/format similarity index 63% rename from format.sh rename to format index 2c2243fec..727999857 100755 --- a/format.sh +++ b/format @@ -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 + diff --git a/init.sh b/init similarity index 73% rename from init.sh rename to init index e7d6f2626..9711c9c30 100755 --- a/init.sh +++ b/init @@ -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 diff --git a/libs/setup.sh b/libs/setup.sh index 19c5b15a2..666021c28 100755 --- a/libs/setup.sh +++ b/libs/setup.sh @@ -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 .. diff --git a/llvm-gcov b/llvm-gcov new file mode 100755 index 000000000..20665e156 --- /dev/null +++ b/llvm-gcov @@ -0,0 +1,3 @@ +#!/bin/bash + +exec llvm-cov-3.8 gcov "$@" diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 6c1aec109..549e3f832 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -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)