Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial coverage collection #1887

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

3 changes: 3 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
40 changes: 40 additions & 0 deletions scripts/coverage.sh
Original file line number Diff line number Diff line change
@@ -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