diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000000..b882b3989c --- /dev/null +++ b/codecov.yml @@ -0,0 +1,2 @@ +ignore: + - "source/**/tests" diff --git a/source/api_cc/tests/CMakeLists.txt b/source/api_cc/tests/CMakeLists.txt index 06c73ae62b..8692f5427d 100644 --- a/source/api_cc/tests/CMakeLists.txt +++ b/source/api_cc/tests/CMakeLists.txt @@ -79,10 +79,22 @@ endif() file(GLOB TEST_SRC test_*.cc) add_executable( runUnitTests ${TEST_SRC} ) +add_library(coverage_config INTERFACE) +target_compile_options(coverage_config INTERFACE + -O0 # no optimization + -g # generate debug info + --coverage # sets all required flags +) +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + target_link_options(coverage_config INTERFACE --coverage) +else() + target_link_libraries(coverage_config INTERFACE --coverage) +endif() + if (USE_CUDA_TOOLKIT) - target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} ${opname} pthread ${TensorFlow_LIBRARY} deepmd_op_cuda) + target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} ${opname} pthread ${TensorFlow_LIBRARY} deepmd_op_cuda coverage_config) else() - target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} ${opname} pthread ${TensorFlow_LIBRARY}) + target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} ${opname} pthread ${TensorFlow_LIBRARY} coverage_config) endif() add_test( runUnitTests runUnitTests ) diff --git a/source/install/test_cc.sh b/source/install/test_cc.sh index f28bff9e7b..60463c5bc9 100755 --- a/source/install/test_cc.sh +++ b/source/install/test_cc.sh @@ -31,3 +31,8 @@ make -j${NPROC} cd ${SCRIPT_PATH}/../api_cc/tests ${BUILD_TMP_DIR}/runUnitTests +#------------------ +# upload to codecov +cd ${SCRIPT_PATH} +bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" + diff --git a/source/lib/tests/CMakeLists.txt b/source/lib/tests/CMakeLists.txt index d03eae2e0e..03242ba8dd 100644 --- a/source/lib/tests/CMakeLists.txt +++ b/source/lib/tests/CMakeLists.txt @@ -43,6 +43,18 @@ endif() file(GLOB TEST_SRC test_*.cc) add_executable( runUnitTests ${TEST_SRC} ) +add_library(coverage_config INTERFACE) +target_compile_options(coverage_config INTERFACE + -O0 # no optimization + -g # generate debug info + --coverage # sets all required flags +) +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + target_link_options(coverage_config INTERFACE --coverage) +else() + target_link_libraries(coverage_config INTERFACE --coverage) +endif() + find_package(Threads) # find openmp find_package(OpenMP) @@ -52,9 +64,9 @@ if (OPENMP_FOUND) endif() if (USE_CUDA_TOOLKIT) - target_link_libraries(runUnitTests gtest gtest_main ${libname} pthread deepmd_op_cuda) + target_link_libraries(runUnitTests gtest gtest_main ${libname} pthread deepmd_op_cuda coverage_config) else() - target_link_libraries(runUnitTests gtest gtest_main ${libname} pthread) + target_link_libraries(runUnitTests gtest gtest_main ${libname} pthread coverage_config) endif() add_test( runUnitTests runUnitTests )