From df93f805b5ff61a5c1600db09db02c145e4f601b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Thu, 27 Jun 2024 21:06:24 +0200 Subject: [PATCH] Adjust code coverage workflow Extract lcov setup to a stand-alone file. Remove obsolete check on gcov symbols. Forward code coverage flags to ccache to regenerate .gcno files when building CUDA object files. --- cmake/FindCUDACompilerNVCC.cmake | 2 ++ maintainer/CI/build_cmake.sh | 18 ++----------- maintainer/CI/run_lcov.sh | 45 ++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 16 deletions(-) create mode 100755 maintainer/CI/run_lcov.sh diff --git a/cmake/FindCUDACompilerNVCC.cmake b/cmake/FindCUDACompilerNVCC.cmake index 030dc0f312..d9600ecf6d 100644 --- a/cmake/FindCUDACompilerNVCC.cmake +++ b/cmake/FindCUDACompilerNVCC.cmake @@ -50,6 +50,8 @@ target_compile_options( $<$:-Xptxas=-O3 -Xcompiler=-Og,-g,--coverage,-fprofile-abs-path> $<$:-Xptxas=-O3 -Xcompiler=-O3,-g> $<$:-Xcompiler=-isysroot;-Xcompiler=${CMAKE_OSX_SYSROOT}> + # workaround for https://github.com/espressomd/espresso/issues/4943 + $<$:$<$:--coverage -fprofile-abs-path>> ) function(espresso_add_gpu_library) diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index dc99d8c826..c38ef93f6f 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -261,9 +261,8 @@ end "BUILD" # library. See details in https://github.com/espressomd/espresso/issues/2249 # Can't do this check on CUDA though because nvcc creates a host function # that just calls exit() for each device function, and can't do this with -# coverage because gcov 9.0 adds code that calls exit(), and can't do this # with walberla because the library calls exit() in assertions. -if [[ "${with_coverage}" == false && ( "${with_cuda}" == false || "${with_cuda_compiler}" != "nvcc" ) && "${with_walberla}" != "true" ]]; then +if [[ ( "${with_cuda}" == false || "${with_cuda_compiler}" != "nvcc" ) && "${with_walberla}" != "true" ]]; then if nm -o -C $(find . -name '*.so') | grep '[^a-z]exit@@GLIBC'; then echo "Found calls to exit() function in shared libraries." exit 1 @@ -355,20 +354,7 @@ if [ "${with_coverage}" = true ] || [ "${with_coverage_python}" = true ]; then if [ "${with_coverage}" = true ]; then echo "Running lcov and gcov..." codecov_opts="${codecov_opts} --gcov" - lcov --gcov-tool "${GCOV:-gcov}" \ - --quiet \ - --ignore-errors graph,mismatch,mismatch,gcov,unused \ - --directory . \ - --filter brace,blank,range,region \ - --capture \ - --rc lcov_json_module="JSON::XS" \ - --exclude "/usr/*" \ - --exclude "$(realpath .)/_deps/*" \ - --exclude "$(realpath .)/src/python/espressomd/*" \ - --exclude "$(realpath "${srcdir}")/src/walberla_bridge/src/*/generated_kernels/*" \ - --exclude "$(realpath "${srcdir}")/libs/*" \ - --exclude "*/tmpxft_*cudafe1.stub.*" \ - --output-file coverage.info + ./run_lcov.sh coverage.info fi if [ "${with_coverage_python}" = true ]; then echo "Running python3-coverage..." diff --git a/maintainer/CI/run_lcov.sh b/maintainer/CI/run_lcov.sh new file mode 100755 index 0000000000..22052acf45 --- /dev/null +++ b/maintainer/CI/run_lcov.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env sh +# +# Copyright (C) 2017-2024 The ESPResSo project +# +# This file is part of ESPResSo. +# +# ESPResSo is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ESPResSo is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +set -e + +output="${1:-coverage.info}" +bindir="$(realpath .)" +srcdir="$(sed -nr "s/^ESPResSo_SOURCE_DIR:STATIC=(.+)/\1/p" "${bindir}/CMakeCache.txt")" + +if [ "${srcdir}" = "" ]; then + echo "Cannot extract ESPResSo_SOURCE_DIR variable from the CMake cache" >&2 + exit 2 +fi + +lcov --gcov-tool "${GCOV:-gcov}" \ + --quiet \ + --ignore-errors graph,mismatch,mismatch,gcov,unused \ + --directory . \ + --filter brace,blank,range,region \ + --capture \ + --rc lcov_json_module="JSON::XS" \ + --exclude "/usr/*" \ + --exclude "*/tmpxft_*cudafe1.stub.*" \ + --exclude "${bindir}/_deps/*" \ + --exclude "${bindir}/src/python/espressomd/*" \ + --exclude "${srcdir}/src/walberla_bridge/src/*/generated_kernels/*" \ + --exclude "${srcdir}/libs/*" \ + --output-file "${output}"