Commit 893b8ce4 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Merge branch 'JK/coverage' into 'develop'

Code coverage

See merge request !110
parents 46606769 62dd27b5
Loading
Loading
Loading
Loading
+53 −9
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ stages:
    # build targets
    BUILD_TESTS: "no"
    BUILD_MATRIX_TESTS: "no"
    WITH_COVERAGE: "no"
    WITH_COVERAGE: "yes"
    BUILD_DOC: "no"
    BUILD_BENCHMARKS: "no"
    BUILD_EXAMPLES: "no"
@@ -100,6 +100,34 @@ stages:
            - .gitlab-ci.yml
    interruptible: true

# template for collecting code coverage
.coverage_template:
    after_script:
        - mkdir coverage_html
        - if [[ ${CXX} == "clang++" ]]; then
                GCOV_COMMAND="llvm-cov gcov";
          else
                GCOV_COMMAND="gcov";
          fi
        - gcovr --print-summary --html-details coverage_html/coverage.html --xml coverage.xml --xml-pretty --gcov-executable "${GCOV_COMMAND}" --exclude-unreachable-branches --root "${CI_PROJECT_DIR}" --filter "${CI_PROJECT_DIR}/src/TNL/"
    coverage: /^\s*lines:\s*\d+.\d+\%/
    artifacts:
        name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
        expire_in: 7 days
        reports:
            cobertura: coverage.xml
            junit: "builddir/$CI_JOB_NAME/tests-report.xml"
        paths:
            - coverage_html/

# template for registering tests-report.xml as an artifact
.tests_report_template:
    artifacts:
        name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
        expire_in: 7 days
        reports:
            junit: "builddir/$CI_JOB_NAME/tests-report.xml"

# Dummy build job to ensure that a pipeline is created for a merge request, even
# when there were no changes.
dummy build job:
@@ -123,7 +151,9 @@ dummy build job:
# significantly more time than debug builds).

cuda_tests_Debug:
    extends: .build_template
    extends:
        - .build_template
        - .coverage_template
    stage: build:cuda
    tags:
        - docker
@@ -135,7 +165,9 @@ cuda_tests_Debug:
        BUILD_TESTS: "yes"

cuda_tests_Release:
    extends: .build_template
    extends:
        - .build_template
        - .tests_report_template
    stage: build:cuda
    tags:
        - docker
@@ -148,7 +180,9 @@ cuda_tests_Release:


cuda_matrix_tests_Debug:
    extends: .build_template
    extends:
        - .build_template
        - .coverage_template
    stage: build:cuda
    tags:
        - docker
@@ -160,7 +194,9 @@ cuda_matrix_tests_Debug:
        BUILD_MATRIX_TESTS: "yes"

cuda_matrix_tests_Release:
    extends: .build_template
    extends:
        - .build_template
        - .tests_report_template
    stage: build:cuda
    tags:
        - docker
@@ -232,28 +268,36 @@ cuda_mpi_nontests_Release:


default_tests_Debug:
    extends: .build_template
    extends:
        - .build_template
        - .coverage_template
    variables:
        <<: *default_cmake_flags
        BUILD_TYPE: Debug
        BUILD_TESTS: "yes"

default_tests_Release:
    extends: .build_template
    extends:
        - .build_template
        - .tests_report_template
    variables:
        <<: *default_cmake_flags
        BUILD_TYPE: Release
        BUILD_TESTS: "yes"

default_matrix_tests_Debug:
    extends: .build_template
    extends:
        - .build_template
        - .coverage_template
    variables:
        <<: *default_cmake_flags
        BUILD_TYPE: Debug
        BUILD_MATRIX_TESTS: "yes"

default_matrix_tests_Release:
    extends: .build_template
    extends:
        - .build_template
        - .tests_report_template
    variables:
        <<: *default_cmake_flags
        BUILD_TYPE: Release
+10 −36
Original line number Diff line number Diff line
@@ -160,23 +160,28 @@ link_libraries( stdc++fs )
if( ${BUILD_TESTS} OR ${BUILD_MATRIX_TESTS} )
   enable_testing()

   # let CTest write test results in the JUnit XML format
   set( CMAKE_CTEST_ARGUMENTS ${CMAKE_CTEST_ARGUMENTS} --output-junit "${CMAKE_BINARY_DIR}/tests-report.xml" )

   if( ${WITH_SYSTEM_GTEST} OR ${OFFLINE_BUILD} )
      # find gtest installed in the local system
      find_package(GTest REQUIRED)
      if( GTEST_FOUND )
         set( CXX_TESTS_FLAGS ${CXX_TESTS_FLAGS} -DHAVE_GTEST )
         include_directories( ${GTEST_INCLUDE_DIRS} )
         link_libraries( ${GTEST_LIBRARIES} )
      endif( GTEST_FOUND )
   else()
      # build gtest libs
      include( BuildGtest )
   endif()

   set( CXX_TESTS_FLAGS ${CXX_TESTS_FLAGS} -DHAVE_GTEST )
   set( CUDA_TESTS_FLAGS ${CUDA_TESTS_FLAGS} -DHAVE_GTEST )
   set( TESTS_LIBRARIES ${TESTS_LIBRARIES} ${GTEST_LIBRARIES} )

   if( ${WITH_COVERAGE} AND CMAKE_BUILD_TYPE STREQUAL "Debug" )
      # enable code coverage reports
      include( UseCodeCoverage )
      # set compiler flags needed for code coverage
      set( CXX_TESTS_FLAGS ${CXX_TESTS_FLAGS} --coverage )
      set( CUDA_TESTS_FLAGS ${CUDA_TESTS_FLAGS} -Xcompiler --coverage )
      set( TESTS_LINKER_FLAGS ${TESTS_LINKER_FLAGS} --coverage )
   endif()
endif()

@@ -309,35 +314,6 @@ if( ${WITH_GMP} )
   endif()
endif()

####
# Test for PETSc
if( BUILD_MPI )
   FIND_PATH( PETSC_INCLUDE_DIR petsc.h
      /usr/include/petsc
      ${PETSC_DIR}/${PETSC_ARCH}/include
      ${PETSC_DIR}/include
      DOC "PETSC headers."
   )
   if( ${PETSC_INCLUDE_DIR} STREQUAL "PETSC_INCLUDE_DIR-NOTFOUND" )
      message( "PETSC not found." )
   else()
      message( "PETSC headers found -- ${PETSC_INCLUDE_DIR}" )
      FIND_LIBRARY(PETSC_LIBRARY petsc
                  ${PETSC_INCLUDE_DIR}/../lib
                  /usr/local/lib
                  /usr/lib)
      if( PETSC_LIBRARY )
         #string( REPLACE ";" " " MPI_LIBRARIES "${MPI_CXX_LIBRARIES}" )
         #set( PETSC_LIBRARY "${MPI_LIBRARIES} ${PETSC_LIBRARY}")
         message( "PETSC library found -- ${PETSC_LIBRARY}")
         #list( GET MPI_CXX_INCLUDE_PATH 0 MPI_CXX_PATH )
         #set(PETSC_CXX_FLAGS "-DHAVE_PETSC -I${PETSC_INCLUDE_DIR} -DHAVE_MPI -I${MPI_CXX_PATH}")
         set(PETSC_CXX_FLAGS -DHAVE_PETSC -I${PETSC_INCLUDE_DIR})
         set(PETSC_LINKER_FLAGS ${PETSC_LIBRARY})
      endif()
   endif()
endif()

# configure build paths
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib )
@@ -417,8 +393,6 @@ message( " CMAKE_SHARED_LINKER_FLAGS_RELEASE = ${CMAKE_SHARED_LINKER_FLAGS_REL
message( "   CUDA_NVCC_FLAGS = ${CUDA_NVCC_FLAGS}" )
message( "   CUDA_SAMPLES_FLAGS = ${CUDA_SAMPLES_FLAGS}" )
message( "   GMP_LIBRARIES = ${GMP_LIBRARIES}" )
message( "   PETSC_CXX_FLAGS = ${PETSC_CXX_FLAGS}" )
message( "   PETSC_LINKER_FLAGS = ${PETSC_LINKER_FLAGS}" )

if( MPI_CXX_FOUND AND ${WITH_MPI} )
   message( "   MPI_CXX_COMPILE_OPTIONS = ${MPI_CXX_COMPILE_OPTIONS}" )

cmake/AddCompilerFlag.cmake

deleted100644 → 0
+0 −16
Original line number Diff line number Diff line
include (CheckCCompilerFlag)
include (CheckCXXCompilerFlag)
macro(AddCompilerFlag _flag)
   string(REGEX REPLACE "[+/:= ]" "_" _flag_esc "${_flag}")
   check_c_compiler_flag("${_flag}" check_c_compiler_flag_${_flag_esc})
   check_cxx_compiler_flag("${_flag}" check_cxx_compiler_flag_${_flag_esc})
   if(check_c_compiler_flag_${_flag_esc})
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flag}")
   endif(check_c_compiler_flag_${_flag_esc})
   if(check_cxx_compiler_flag_${_flag_esc})
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}")
   endif(check_cxx_compiler_flag_${_flag_esc})
   if(${ARGC} EQUAL 2)
      set(${ARGV1} "${check_cxx_compiler_flag_${_flag_esc}}")
   endif(${ARGC} EQUAL 2)
endmacro(AddCompilerFlag)
+3 −11
Original line number Diff line number Diff line
@@ -2,17 +2,6 @@
# the projects' build systems, see
# https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project

#find_package( GTest )
#if( GTEST_FOUND )
#   set( CXX_TESTS_FLAGS "${CXX_TESTS_FLAGS} -DHAVE_GTEST" )
#endif( GTEST_FOUND )


# compatibility with the GTest package
set( GTEST_BOTH_LIBRARIES gtest gtest_main )
set( CXX_TESTS_FLAGS ${CXX_TESTS_FLAGS} -DHAVE_GTEST )


# Download and unpack googletest at configure time
configure_file(cmake/Gtest.cmake.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
@@ -47,3 +36,6 @@ add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
if (CMAKE_VERSION VERSION_LESS 2.8.11)
    include_directories("${gtest_SOURCE_DIR}/include")
endif()

# compatibility with the GTest package
set( GTEST_LIBRARIES gtest gtest_main )
+14 −0
Original line number Diff line number Diff line
# CorrectWindowsPaths - this module defines one macro
#
# CONVERT_CYGWIN_PATH( PATH )
#  This uses the command cygpath (provided by cygwin) to convert
#  unix-style paths into paths useable by cmake on windows

macro (CONVERT_CYGWIN_PATH _path)
  if (WIN32)
    EXECUTE_PROCESS(COMMAND cygpath.exe -m ${${_path}}
      OUTPUT_VARIABLE ${_path})
    string (STRIP ${${_path}} ${_path})
  endif (WIN32)
endmacro (CONVERT_CYGWIN_PATH)
Loading