From 54aba781ecc9de444530d136bb06205ba5accf4e Mon Sep 17 00:00:00 2001 From: Evan Harvey Date: Mon, 23 Jan 2023 14:25:28 -0700 Subject: [PATCH] Add initial coverage collection --- .github/workflows/osx.yml | 42 ++++++++++++++++++++++++++++----------- BUILD.md | 3 +++ CMakeLists.txt | 13 ++++++++++++ scripts/coverage.sh | 40 +++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 12 deletions(-) create mode 100755 scripts/coverage.sh diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml index 769957b953..d2684fc973 100644 --- a/.github/workflows/osx.yml +++ b/.github/workflows/osx.yml @@ -38,15 +38,19 @@ jobs: - backend: "SERIAL" cmake_build_type: "RelWithDebInfo" debug_bounds_check: "ON" + coverage: "OFF" - backend: "THREADS" cmake_build_type: "RelWithDebInfo" debug_bounds_check: "ON" + coverage: "OFF" - backend: "SERIAL" cmake_build_type: "Debug" debug_bounds_check: "OFF" + coverage: "ON" - backend: "SERIAL" cmake_build_type: "Release" debug_bounds_check: "ON" + coverage: "OFF" steps: - name: checkout_kokkos_kernels @@ -91,18 +95,19 @@ jobs: -DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \ -DCMAKE_CXX_FLAGS="-Wall -Wshadow -pedantic -Werror -Wsign-compare -Wtype-limits -Wignored-qualifiers -Wempty-body -Wuninitialized" \ -DCMAKE_INSTALL_PREFIX=$PWD/../install \ - -DKokkosKernels_ENABLE_TESTS=ON \ - -DKokkosKernels_ENABLE_EXAMPLES:BOOL=ON \ - -DKokkosKernels_INST_COMPLEX_DOUBLE=ON \ - -DKokkosKernels_INST_DOUBLE=ON \ - -DKokkosKernels_INST_COMPLEX_FLOAT=ON \ - -DKokkosKernels_INST_FLOAT=ON \ - -DKokkosKernels_INST_LAYOUTLEFT:BOOL=ON \ - -DKokkosKernels_INST_LAYOUTRIGHT:BOOL=ON \ - -DKokkosKernels_INST_OFFSET_INT=ON \ - -DKokkosKernels_INST_OFFSET_SIZE_T=ON \ - -DKokkosKernels_ENABLE_TPL_CUSPARSE=OFF \ - -DKokkosKernels_ENABLE_TPL_CUBLAS=OFF \ + -DKokkosKernels_ENABLE_COVERAGE:BOOL=${{ matrix.coverage }} \ + -DKokkosKernels_ENABLE_TESTS:BOOL=ON \ + -DKokkosKernels_ENABLE_EXAMPLES:BOOL:BOOL=ON \ + -DKokkosKernels_INST_COMPLEX_DOUBLE:BOOL=ON \ + -DKokkosKernels_INST_DOUBLE:BOOL=ON \ + -DKokkosKernels_INST_COMPLEX_FLOAT:BOOL=ON \ + -DKokkosKernels_INST_FLOAT:BOOL=ON \ + -DKokkosKernels_INST_LAYOUTLEFT:BOOL:BOOL=ON \ + -DKokkosKernels_INST_LAYOUTRIGHT:BOOL:BOOL=ON \ + -DKokkosKernels_INST_OFFSET_INT:BOOL=ON \ + -DKokkosKernels_INST_OFFSET_SIZE_T:BOOL=ON \ + -DKokkosKernels_ENABLE_TPL_CUSPARSE:BOOL=OFF \ + -DKokkosKernels_ENABLE_TPL_CUBLAS:BOOL=OFF \ .. - name: build_kokkos_kernels @@ -112,3 +117,16 @@ jobs: - name: test working-directory: kokkos-kernels/build run: ctest -j2 --output-on-failure --timeout 3600 + + + - name: coverage + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + working-directory: kokkos-kernels/build + run: | + cd /usr/local/bin + curl -Os https://cli.codecov.io/macos/latest/codecov + chmod +x ./codecov + cd - + $PWD/../scripts/coverage.sh + diff --git a/BUILD.md b/BUILD.md index 5be269bd7c..9f4a877480 100644 --- a/BUILD.md +++ b/BUILD.md @@ -158,6 +158,9 @@ endif() * KokkosKernels_ENABLE_DOCS: BOOL * Whether to build docs. * Default: OFF +* KokkosKernels_ENABLE_COVERASGE: BOOL + * Whether to collect coverage reports. + * Default: OFF * KokkosKernels_ENABLE_TPL_BLAS: BOOL * Whether to enable BLAS * Default: OFF diff --git a/CMakeLists.txt b/CMakeLists.txt index c144a8c107..9918f4f89a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,12 @@ KOKKOSKERNELS_PACKAGE() IF (NOT KOKKOSKERNELS_HAS_TRILINOS) SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") + KOKKOSKERNELS_ADD_OPTION( + "ENABLE_COVERAGE" + OFF + BOOL + "Whether to collect coverage reports. Default: OFF" + ) KOKKOSKERNELS_ADD_OPTION( "ENABLE_EXAMPLES" OFF @@ -431,4 +437,11 @@ ELSE() IF (KokkosKernels_ENABLE_DOCS) ADD_SUBDIRECTORY(docs) ENDIF () + + IF(KokkosKernels_ENABLE_COVERAGE) + # -fprofile-arcs -ftest-coverage + MESSAGE(STATUS "Enabling coverage collection.") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -O0" CACHE STRING "" FORCE) + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage" CACHE STRING "" FORCE) + ENDIF() ENDIF() diff --git a/scripts/coverage.sh b/scripts/coverage.sh new file mode 100755 index 0000000000..d72ffb05b5 --- /dev/null +++ b/scripts/coverage.sh @@ -0,0 +1,40 @@ +#!/bin/bash -el +# This script parses all the generated gcda files and then +# attempts to upload the coverage reports to codecov. +# codecov handles merging of reports across all our +# builds. See https://docs.codecov.com/docs/merging-reports. +if [ ! -e ./CMakeCache.txt ]; then + echo "ERROR: This script must be run from the cmake build directory." +fi + +BUILD_DIR=$PWD +UPLOAD_RETRIES=30 +UPLOAD_COUNTER=0 +mkdir -p Testing/CoverageInfo +date > Testing/CoverageInfo/gcov.log +pushd Testing/CoverageInfo + +# Run gcov on the generated gcda files +for dir in $(cat ${BUILD_DIR}/CMakeFiles/TargetDirectories.txt); do + if [ -d $dir ]; then + gcda_files=$(find $dir -iname '*.gcda') + fi + if [ ! -z $(echo $gcda_files | head -c 1) ]; then + echo "STATUS: processing $dir..." | tee -a gcov.log + gcov -a -m -x $gcda_files 2>&1 >> gcov.log + rm -f $gcda_files + UPLOAD_COUNTER=$UPLOAD_RETRIES + fi +done + +# Upload gcov results to codecov +while [ $UPLOAD_COUNTER -ne 0 ]; do + echo "STATUS: Uploading to codecov attempt $[$UPLOAD_RETRIES-$UPLOAD_COUNTER]..." + codecov -X gcovcodecov -X gcov -t $CODECOV_TOKEN --root $BUILD_DIR --name $JOB_NAME --url TODO-KK-CODECOV-URL + ret=$? + if [ $ret -eq 0]; then + exit 0 + fi + sleep 5s + UPLOAD_COUNTER=$[$UPLOAD_COUNTER-1] +done \ No newline at end of file