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) 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)