From 18e1caa6a6595f6ae7fc0d3c0128a7ba12e0384e Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 11 May 2021 04:45:55 -0400 Subject: [PATCH 1/6] add coverage report for c/c++ api --- source/api_cc/tests/CMakeLists.txt | 10 ++++++++++ source/install/test_cc.sh | 2 ++ source/lib/tests/CMakeLists.txt | 10 ++++++++++ 3 files changed, 22 insertions(+) diff --git a/source/api_cc/tests/CMakeLists.txt b/source/api_cc/tests/CMakeLists.txt index 3cdddd0d56..498da4b4c3 100644 --- a/source/api_cc/tests/CMakeLists.txt +++ b/source/api_cc/tests/CMakeLists.txt @@ -21,6 +21,16 @@ set(LIB_BASE_DIR ${CMAKE_SOURCE_DIR}/../../lib) include_directories(${LIB_BASE_DIR}/include) file(GLOB LIB_SRC ${LIB_BASE_DIR}/src/*.cc ${LIB_BASE_DIR}/src/*.cpp) add_library(${libname} SHARED ${LIB_SRC}) +target_compile_options(${libname} INTERFACE + -O0 # no optimization + -g # generate debug info + --coverage # sets all required flags +) +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + target_link_options(${libname} INTERFACE --coverage) +else() + target_link_libraries(${libname} INTERFACE --coverage) +endif() set(apiname "deepmd_api") set(API_BASE_DIR ${CMAKE_SOURCE_DIR}/../) diff --git a/source/install/test_cc.sh b/source/install/test_cc.sh index f28bff9e7b..8b83fe1fc1 100755 --- a/source/install/test_cc.sh +++ b/source/install/test_cc.sh @@ -15,6 +15,7 @@ make -j${NPROC} #------------------ ${BUILD_TMP_DIR}/runUnitTests +bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" #------------------ @@ -30,4 +31,5 @@ make -j${NPROC} #------------------ cd ${SCRIPT_PATH}/../api_cc/tests ${BUILD_TMP_DIR}/runUnitTests +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..106a69b843 100644 --- a/source/lib/tests/CMakeLists.txt +++ b/source/lib/tests/CMakeLists.txt @@ -11,6 +11,16 @@ file(GLOB LIB_SRC ${LIB_BASE_DIR}/src/*.cc ${LIB_BASE_DIR}/src/*.cpp) message(status ${LIB_SRC}) # add_library(${libname} SHARED ${LIB_SRC}) add_library(${libname} ${LIB_SRC}) +target_compile_options(${libname} INTERFACE + -O0 # no optimization + -g # generate debug info + --coverage # sets all required flags +) +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + target_link_options(${libname} INTERFACE --coverage) +else() + target_link_libraries(${libname} INTERFACE --coverage) +endif() message(status "${CMAKE_SOURCE_DIR}") From 478ee0dfc49fa23323348d778d6a47324ee52411 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 11 May 2021 04:52:51 -0400 Subject: [PATCH 2/6] uploading once is enough --- source/install/test_cc.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/install/test_cc.sh b/source/install/test_cc.sh index 8b83fe1fc1..60463c5bc9 100755 --- a/source/install/test_cc.sh +++ b/source/install/test_cc.sh @@ -15,7 +15,6 @@ make -j${NPROC} #------------------ ${BUILD_TMP_DIR}/runUnitTests -bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" #------------------ @@ -31,5 +30,9 @@ 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" From 2fa34cdb3e7059c28fe3a1a8d85833b8796effe6 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 11 May 2021 05:43:28 -0400 Subject: [PATCH 3/6] change options --- source/api_cc/tests/CMakeLists.txt | 21 +++++++++++---------- source/lib/tests/CMakeLists.txt | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/source/api_cc/tests/CMakeLists.txt b/source/api_cc/tests/CMakeLists.txt index 498da4b4c3..5513f397ed 100644 --- a/source/api_cc/tests/CMakeLists.txt +++ b/source/api_cc/tests/CMakeLists.txt @@ -21,16 +21,6 @@ set(LIB_BASE_DIR ${CMAKE_SOURCE_DIR}/../../lib) include_directories(${LIB_BASE_DIR}/include) file(GLOB LIB_SRC ${LIB_BASE_DIR}/src/*.cc ${LIB_BASE_DIR}/src/*.cpp) add_library(${libname} SHARED ${LIB_SRC}) -target_compile_options(${libname} INTERFACE - -O0 # no optimization - -g # generate debug info - --coverage # sets all required flags -) -if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) - target_link_options(${libname} INTERFACE --coverage) -else() - target_link_libraries(${libname} INTERFACE --coverage) -endif() set(apiname "deepmd_api") set(API_BASE_DIR ${CMAKE_SOURCE_DIR}/../) @@ -89,6 +79,17 @@ endif() file(GLOB TEST_SRC test_*.cc) add_executable( runUnitTests ${TEST_SRC} ) +target_compile_options(runUnitTests INTERFACE + -O0 # no optimization + -g # generate debug info + --coverage # sets all required flags +) +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + target_link_options(runUnitTests INTERFACE --coverage) +else() + target_link_libraries(runUnitTests INTERFACE --coverage) +endif() + if (USE_CUDA_TOOLKIT) target_link_libraries(runUnitTests gtest gtest_main ${libname} pthread deepmd_op_cuda) else() diff --git a/source/lib/tests/CMakeLists.txt b/source/lib/tests/CMakeLists.txt index 106a69b843..a323e431bb 100644 --- a/source/lib/tests/CMakeLists.txt +++ b/source/lib/tests/CMakeLists.txt @@ -11,16 +11,6 @@ file(GLOB LIB_SRC ${LIB_BASE_DIR}/src/*.cc ${LIB_BASE_DIR}/src/*.cpp) message(status ${LIB_SRC}) # add_library(${libname} SHARED ${LIB_SRC}) add_library(${libname} ${LIB_SRC}) -target_compile_options(${libname} INTERFACE - -O0 # no optimization - -g # generate debug info - --coverage # sets all required flags -) -if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) - target_link_options(${libname} INTERFACE --coverage) -else() - target_link_libraries(${libname} INTERFACE --coverage) -endif() message(status "${CMAKE_SOURCE_DIR}") @@ -53,6 +43,17 @@ endif() file(GLOB TEST_SRC test_*.cc) add_executable( runUnitTests ${TEST_SRC} ) +target_compile_options(runUnitTests INTERFACE + -O0 # no optimization + -g # generate debug info + --coverage # sets all required flags +) +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + target_link_options(runUnitTests INTERFACE --coverage) +else() + target_link_libraries(runUnitTests INTERFACE --coverage) +endif() + find_package(Threads) # find openmp find_package(OpenMP) From cbc2621d8304e1ec876878df7ecb66dbaebd44c0 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 11 May 2021 05:54:08 -0400 Subject: [PATCH 4/6] Apply suggestions from code review --- source/api_cc/tests/CMakeLists.txt | 7 ++++--- source/lib/tests/CMakeLists.txt | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/api_cc/tests/CMakeLists.txt b/source/api_cc/tests/CMakeLists.txt index 5513f397ed..00fa69f9f0 100644 --- a/source/api_cc/tests/CMakeLists.txt +++ b/source/api_cc/tests/CMakeLists.txt @@ -79,15 +79,16 @@ endif() file(GLOB TEST_SRC test_*.cc) add_executable( runUnitTests ${TEST_SRC} ) -target_compile_options(runUnitTests INTERFACE +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(runUnitTests INTERFACE --coverage) + target_link_options(coverage_config INTERFACE --coverage) else() - target_link_libraries(runUnitTests INTERFACE --coverage) + target_link_libraries(coverage_config INTERFACE --coverage) endif() if (USE_CUDA_TOOLKIT) diff --git a/source/lib/tests/CMakeLists.txt b/source/lib/tests/CMakeLists.txt index a323e431bb..0a37d5f50f 100644 --- a/source/lib/tests/CMakeLists.txt +++ b/source/lib/tests/CMakeLists.txt @@ -43,15 +43,16 @@ endif() file(GLOB TEST_SRC test_*.cc) add_executable( runUnitTests ${TEST_SRC} ) -target_compile_options(runUnitTests INTERFACE +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(runUnitTests INTERFACE --coverage) + target_link_options(coverage_config INTERFACE --coverage) else() - target_link_libraries(runUnitTests INTERFACE --coverage) + target_link_libraries(coverage_config INTERFACE --coverage) endif() find_package(Threads) From eaa774fc2a9dbb2f6690a4094ee5cf0e97e4f7e7 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 11 May 2021 06:01:15 -0400 Subject: [PATCH 5/6] link coverage_config --- source/api_cc/tests/CMakeLists.txt | 4 ++-- source/lib/tests/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/api_cc/tests/CMakeLists.txt b/source/api_cc/tests/CMakeLists.txt index 00fa69f9f0..cfa0d1d4ec 100644 --- a/source/api_cc/tests/CMakeLists.txt +++ b/source/api_cc/tests/CMakeLists.txt @@ -92,9 +92,9 @@ else() 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} ${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/lib/tests/CMakeLists.txt b/source/lib/tests/CMakeLists.txt index 0a37d5f50f..03242ba8dd 100644 --- a/source/lib/tests/CMakeLists.txt +++ b/source/lib/tests/CMakeLists.txt @@ -64,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 ) From 31707c2ffe4c8ec889f460c1df3c7154155dd4c2 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 11 May 2021 09:44:07 -0400 Subject: [PATCH 6/6] Ignore tests --- codecov.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 codecov.yml 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"