From 5644a20b14d5e2eab89f992411e1570ffa5ad0a9 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 3 Oct 2022 21:21:52 -0400 Subject: [PATCH 1/2] enable gcov for Python tests --- .github/workflows/test_python.yml | 1 + setup.py | 3 +++ source/CMakeLists.txt | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/.github/workflows/test_python.yml b/.github/workflows/test_python.yml index 962fd8ccab..b5bca2b544 100644 --- a/.github/workflows/test_python.yml +++ b/.github/workflows/test_python.yml @@ -69,5 +69,6 @@ jobs: CXX: g++-${{ matrix.gcc }} TENSORFLOW_VERSION: ${{ matrix.tf }} SETUPTOOLS_ENABLE_FEATURES: "legacy-editable" + DP_BUILD_TESTING: 1 - run: dp --version - run: pytest --cov=deepmd source/tests && codecov diff --git a/setup.py b/setup.py index 4803b043ee..5564ad4790 100644 --- a/setup.py +++ b/setup.py @@ -56,6 +56,9 @@ else: raise RuntimeError("Unsupported DP_VARIANT option: %s" % dp_variant) +if os.environ.get("DP_BUILD_TESTING", "0") == "1": + cmake_args.append("-DBUILD_TESTING:BOOL=TRUE") + # get tensorflow spec tf_spec = find_spec("tensorflow") diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 769a970f42..6a372818b4 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1,6 +1,12 @@ cmake_minimum_required(VERSION 3.12) project(DeePMD) +option(BUILD_TESTING "Enable converage" OFF) +if(BUILD_TESTING) + enable_testing() + add_subdirectory(${CMAKE_SOURCE_DIR}/cmake/coverage_config coverage_config) +endif() + # build cpp or python interfaces if (NOT DEFINED BUILD_CPP_IF) set(BUILD_CPP_IF TRUE) From 1ef5f5f7bcf34bdbf2d5ebc1808429741ebbc5ff Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 3 Oct 2022 21:32:16 -0400 Subject: [PATCH 2/2] enable gcov for py op library --- source/op/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/op/CMakeLists.txt b/source/op/CMakeLists.txt index eb48fbb7ef..0c3605b8c2 100644 --- a/source/op/CMakeLists.txt +++ b/source/op/CMakeLists.txt @@ -58,6 +58,10 @@ if (BUILD_PY_IF) INSTALL_RPATH $ORIGIN ) endif () + if (CMAKE_TESTING_ENABLED) + target_link_libraries(op_abi PRIVATE coverage_config) + target_link_libraries(op_grads PRIVATE coverage_config) + endif() endif (BUILD_PY_IF) if (BUILD_CPP_IF)