From 976910a0522882001bc0660932aef0c47c186ae5 Mon Sep 17 00:00:00 2001 From: sunliang98 <1700011430@pku.edu.cn> Date: Fri, 21 Nov 2025 16:59:42 +0800 Subject: [PATCH 1/7] Fix: Fix coverage test --- .github/workflows/coverage.yml | 73 ++++++++++++++++--- CMakeLists.txt | 8 +- source/source_cell/test_pw/CMakeLists.txt | 2 +- .../module_operator_lcao/test/CMakeLists.txt | 8 +- tests/integrate/CMakeLists.txt | 17 +++-- 5 files changed, 85 insertions(+), 23 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index c664bf796c..6f00d06b39 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -1,6 +1,9 @@ name: Coverage Analysis on: + pull_request: + branches: + - develop workflow_dispatch: push: tags: @@ -13,24 +16,76 @@ jobs: steps: - name: Checkout uses: actions/checkout@v5 - - name: Install Requirements for Coverage Testing + with: + submodules: recursive + + - name: Install Perl Dependencies and Coverage Tools run: | - apt update && apt install -y lcov gpg curl jq ca-certificates - - name: Building + apt update && apt install -y curl jq ca-certificates python3-pip + apt install -y lcov perl-modules + apt install -y libcapture-tiny-perl libdatetime-perl libjson-perl libperlio-gzip-perl + lcov --version + + - name: Building with Coverage run: | - cmake -B build -DENABLE_COVERAGE=ON -DBUILD_TESTING=ON -DENABLE_MLALGO=ON -DENABLE_LIBXC=ON -DENABLE_LIBRI=ON -DENABLE_GOOGLEBENCH=ON -DENABLE_RAPIDJSON=ON - cmake --build build -j`nproc` - cmake --install build + rm -rf build/ + rm -f CMakeCache.txt + + mkdir -p build + chmod -R 755 build/ + + cmake -B build \ + -DENABLE_COVERAGE=ON \ + -DBUILD_TESTING=ON \ + -DENABLE_MLALGO=ON \ + -DENABLE_LIBXC=ON \ + -DENABLE_LIBRI=ON \ + -DENABLE_GOOGLEBENCH=ON \ + -DENABLE_RAPIDJSON=ON \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_FLAGS="--coverage -fprofile-arcs -ftest-coverage" \ + -DCMAKE_EXE_LINKER_FLAGS="--coverage" + cmake --build build -j`nproc` || echo "Some tests failed but continuing for coverage" + cmake --install build || echo "Some tests failed but continuing for coverage" + - name: Testing env: OMP_NUM_THREADS: 1 run: | - cmake --build build --target test ARGS="-V --timeout 21600" || exit 0 + chmod -R 755 build/ + cmake --build build --target test ARGS="-V --timeout 21600" || echo "Some tests failed but continuing for coverage" + + - name: Generate Coverage Data + run: | + cd build + + lcov --directory . --capture --output-file coverage.info + + lcov --remove coverage.info '/usr/*' '*/test/*' '*/external/*' '*/build/*' --output-file coverage.filtered.info || echo "lcov filtering failed" + + genhtml coverage.filtered.info --output-directory coverage-report || echo "genhtml failed" + + cd .. + - name: Upload Coverage to Codecov uses: codecov/codecov-action@v5 if: ${{ ! cancelled() }} with: - fail_ci_if_error: true + fail_ci_if_error: false token: ${{ secrets.CODECOV_TOKEN }} - skip_validation: true + files: ./build/coverage.xml,./build/coverage.info + directory: ./build/ + flags: unittests + name: codecov-umbrella verbose: true + + - name: Upload Coverage Report Artifact + uses: actions/upload-artifact@v4 + if: always() + with: + name: coverage-report + path: | + build/coverage-report/ + build/coverage.info + build/coverage.xml + retention-days: 30 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ac95e45fd..e1819cedbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,15 +151,19 @@ endif() list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) if(ENABLE_COVERAGE) - find_package(codecov) + find_package(codecov QUIET) if(NOT codecov_FOUND) include(FetchContent) FetchContent_Declare( cmakecodecov - URL https://github.com/baixiaokuang/CMake-codecov/archive/refs/heads/master.zip + GIT_REPOSITORY https://github.com/RWTH-HPC/CMake-codecov.git + GIT_TAG master + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE ) FetchContent_Populate(cmakecodecov) list(APPEND CMAKE_MODULE_PATH ${cmakecodecov_SOURCE_DIR}/cmake) + set(CMAKE_MODULE_PATH "${cmakecodecov_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) find_package(codecov REQUIRED) endif() endif() diff --git a/source/source_cell/test_pw/CMakeLists.txt b/source/source_cell/test_pw/CMakeLists.txt index 68818a25ca..48893a14ae 100644 --- a/source/source_cell/test_pw/CMakeLists.txt +++ b/source/source_cell/test_pw/CMakeLists.txt @@ -15,7 +15,7 @@ AddTest( ../read_stru.cpp ../read_atom_species.cpp ../read_pp_vwr.cpp ../read_pp_blps.cpp ../../source_io/output.cpp ../../source_estate/read_pseudo.cpp ../../source_estate/cal_nelec_nband.cpp - ../../source_estate/read_orb.cpp ../../source_cell/print_cell.cpp + ../../source_estate/read_orb.cpp ../print_cell.cpp ../../source_estate/cal_wfc.cpp ../sep.cpp ../sep_cell.cpp ) diff --git a/source/source_lcao/module_operator_lcao/test/CMakeLists.txt b/source/source_lcao/module_operator_lcao/test/CMakeLists.txt index e39a3dac19..7d48538c5c 100644 --- a/source/source_lcao/module_operator_lcao/test/CMakeLists.txt +++ b/source/source_lcao/module_operator_lcao/test/CMakeLists.txt @@ -9,8 +9,8 @@ AddTest( ../../../source_basis/module_ao/parallel_orbitals.cpp ../../../source_basis/module_ao/ORB_atomic_lm.cpp tmp_mocks.cpp ../../../source_hamilt/operator.cpp - ../../../source_lcao/module_rt/td_info.cpp - ../../../source_lcao/module_rt/td_folding.cpp + ../../module_rt/td_info.cpp + ../../module_rt/td_folding.cpp ../../../source_estate/module_pot/H_TDDFT_pw.cpp ) @@ -22,8 +22,8 @@ AddTest( ../../../source_basis/module_ao/parallel_orbitals.cpp ../../../source_basis/module_ao/ORB_atomic_lm.cpp tmp_mocks.cpp ../../../source_hamilt/operator.cpp - ../../../source_lcao/module_rt/td_info.cpp - ../../../source_lcao/module_rt/td_folding.cpp + ../../module_rt/td_info.cpp + ../../module_rt/td_folding.cpp ../../../source_estate/module_pot/H_TDDFT_pw.cpp ) diff --git a/tests/integrate/CMakeLists.txt b/tests/integrate/CMakeLists.txt index 8da79197aa..d64accef36 100644 --- a/tests/integrate/CMakeLists.txt +++ b/tests/integrate/CMakeLists.txt @@ -1,5 +1,14 @@ find_program(BASH bash) find_package(Python3 REQUIRED) + +add_executable(sum_cube ${ABACUS_TEST_DIR}/integrate/tools/sum_cube.cpp) +install(TARGETS sum_cube DESTINATION ${ABACUS_TEST_DIR}/integrate/tools/) +message(STATUS "Target sum_cube has been defined in ${CMAKE_CURRENT_SOURCE_DIR}") # 添加此行 + +if(ENABLE_COVERAGE) + add_coverage(sum_cube) +endif() + if(ENABLE_ASAN) add_test( NAME integrated_test_with_asan @@ -13,10 +22,4 @@ else() COMMAND ${BASH} Autotest.sh -a ${ABACUS_BIN_PATH} -n 4 WORKING_DIRECTORY ${ABACUS_TEST_DIR}/integrate ) - add_executable(sum_cube.exe ${ABACUS_TEST_DIR}/integrate/tools/sum_cube.cpp) - install(TARGETS sum_cube.exe DESTINATION ${ABACUS_TEST_DIR}/integrate/tools/) - - if(ENABLE_COVERAGE) - add_coverage(sum_cube.exe) - endif() -endif() +endif() \ No newline at end of file From c830aae80d0880b43d1f912650fdcb2fec253b46 Mon Sep 17 00:00:00 2001 From: sunliang98 <1700011430@pku.edu.cn> Date: Fri, 21 Nov 2025 19:28:27 +0800 Subject: [PATCH 2/7] Fix: Fix tests/integrate/CMakeLists.txt --- tests/integrate/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integrate/CMakeLists.txt b/tests/integrate/CMakeLists.txt index d64accef36..f3e5d226cb 100644 --- a/tests/integrate/CMakeLists.txt +++ b/tests/integrate/CMakeLists.txt @@ -1,12 +1,12 @@ find_program(BASH bash) find_package(Python3 REQUIRED) -add_executable(sum_cube ${ABACUS_TEST_DIR}/integrate/tools/sum_cube.cpp) -install(TARGETS sum_cube DESTINATION ${ABACUS_TEST_DIR}/integrate/tools/) -message(STATUS "Target sum_cube has been defined in ${CMAKE_CURRENT_SOURCE_DIR}") # 添加此行 +add_executable(sum_cube.exe ${ABACUS_TEST_DIR}/integrate/tools/sum_cube.cpp) +install(TARGETS sum_cube.exe DESTINATION ${ABACUS_TEST_DIR}/integrate/tools/) +message(STATUS "Target sum_cube.exe has been defined in ${CMAKE_CURRENT_SOURCE_DIR}") # 添加此行 if(ENABLE_COVERAGE) - add_coverage(sum_cube) + add_coverage(sum_cube.exe) endif() if(ENABLE_ASAN) From 0027a5da987216fc26974f3636c44971918a8ae9 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Fri, 21 Nov 2025 19:38:27 +0800 Subject: [PATCH 3/7] Update CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1819cedbb..1b28936399 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,7 +151,7 @@ endif() list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) if(ENABLE_COVERAGE) - find_package(codecov QUIET) + find_package(codecov) if(NOT codecov_FOUND) include(FetchContent) FetchContent_Declare( From 31d2f4257e8c62fc8805826b495f18bdd1a2afc0 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Fri, 21 Nov 2025 19:43:12 +0800 Subject: [PATCH 4/7] Refactor coverage workflow for improved error handling --- .github/workflows/coverage.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 6f00d06b39..949f586a4c 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -45,8 +45,8 @@ jobs: -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_CXX_FLAGS="--coverage -fprofile-arcs -ftest-coverage" \ -DCMAKE_EXE_LINKER_FLAGS="--coverage" - cmake --build build -j`nproc` || echo "Some tests failed but continuing for coverage" - cmake --install build || echo "Some tests failed but continuing for coverage" + cmake --build build -j`nproc` + cmake --install build - name: Testing env: @@ -61,9 +61,9 @@ jobs: lcov --directory . --capture --output-file coverage.info - lcov --remove coverage.info '/usr/*' '*/test/*' '*/external/*' '*/build/*' --output-file coverage.filtered.info || echo "lcov filtering failed" + lcov --remove coverage.info '/usr/*' '*/test/*' '*/external/*' '*/build/*' --output-file coverage.filtered.info - genhtml coverage.filtered.info --output-directory coverage-report || echo "genhtml failed" + genhtml coverage.filtered.info --output-directory coverage-report cd .. @@ -71,7 +71,7 @@ jobs: uses: codecov/codecov-action@v5 if: ${{ ! cancelled() }} with: - fail_ci_if_error: false + fail_ci_if_error: true token: ${{ secrets.CODECOV_TOKEN }} files: ./build/coverage.xml,./build/coverage.info directory: ./build/ @@ -88,4 +88,4 @@ jobs: build/coverage-report/ build/coverage.info build/coverage.xml - retention-days: 30 \ No newline at end of file + retention-days: 30 From f0147f1b751ae697e506dfc93aa6a95e8de5c4fc Mon Sep 17 00:00:00 2001 From: sunliang98 <1700011430@pku.edu.cn> Date: Fri, 21 Nov 2025 20:12:57 +0800 Subject: [PATCH 5/7] Fix: rename sum_cube.exe as sum_cube --- tests/integrate/CMakeLists.txt | 8 ++++---- tests/integrate/clean.sh | 2 +- tests/integrate/tools/catch_properties.sh | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integrate/CMakeLists.txt b/tests/integrate/CMakeLists.txt index f3e5d226cb..d64accef36 100644 --- a/tests/integrate/CMakeLists.txt +++ b/tests/integrate/CMakeLists.txt @@ -1,12 +1,12 @@ find_program(BASH bash) find_package(Python3 REQUIRED) -add_executable(sum_cube.exe ${ABACUS_TEST_DIR}/integrate/tools/sum_cube.cpp) -install(TARGETS sum_cube.exe DESTINATION ${ABACUS_TEST_DIR}/integrate/tools/) -message(STATUS "Target sum_cube.exe has been defined in ${CMAKE_CURRENT_SOURCE_DIR}") # 添加此行 +add_executable(sum_cube ${ABACUS_TEST_DIR}/integrate/tools/sum_cube.cpp) +install(TARGETS sum_cube DESTINATION ${ABACUS_TEST_DIR}/integrate/tools/) +message(STATUS "Target sum_cube has been defined in ${CMAKE_CURRENT_SOURCE_DIR}") # 添加此行 if(ENABLE_COVERAGE) - add_coverage(sum_cube.exe) + add_coverage(sum_cube) endif() if(ENABLE_ASAN) diff --git a/tests/integrate/clean.sh b/tests/integrate/clean.sh index 8738266bd8..0d182f5e39 100755 --- a/tests/integrate/clean.sh +++ b/tests/integrate/clean.sh @@ -55,7 +55,7 @@ for directory in `ls | grep $module`; do #-------------------------------------------- # delete exec files in tools directory (if it exists) #-------------------------------------------- - sumfile1="$directory/sum_cube.exe" + sumfile1="$directory/sum_cube" test -e "$sumfile1" && rm -rf $sumfile1 #-------------------------------------------- diff --git a/tests/integrate/tools/catch_properties.sh b/tests/integrate/tools/catch_properties.sh index 654f43f7d3..ba4e1f535e 100755 --- a/tests/integrate/tools/catch_properties.sh +++ b/tests/integrate/tools/catch_properties.sh @@ -3,7 +3,7 @@ # mohan add 2025-05-03 # this compare script is used in different integrate tests COMPARE_SCRIPT="../../integrate/tools/CompareFile.py" -SUM_CUBE_EXE="../../integrate/tools/sum_cube.exe" +SUM_CUBE_EXE="../../integrate/tools/sum_cube" sum_file(){ From 21059367bdb60bef152045e9950477816d5e620b Mon Sep 17 00:00:00 2001 From: sunliang98 <1700011430@pku.edu.cn> Date: Fri, 21 Nov 2025 21:08:02 +0800 Subject: [PATCH 6/7] Fix: Update source/source_lcao/module_deepks/test/CMakeLists.txt --- .../module_deepks/test/CMakeLists.txt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source/source_lcao/module_deepks/test/CMakeLists.txt b/source/source_lcao/module_deepks/test/CMakeLists.txt index 93574f4106..36327d3f1d 100644 --- a/source/source_lcao/module_deepks/test/CMakeLists.txt +++ b/source/source_lcao/module_deepks/test/CMakeLists.txt @@ -29,18 +29,18 @@ add_executable( ../../../source_estate/cal_nelec_nband.cpp ../../../source_estate/module_dm/density_matrix.cpp ../../../source_estate/module_dm/density_matrix_io.cpp - ../../../source_lcao/module_hcontainer/base_matrix.cpp - ../../../source_lcao/module_hcontainer/hcontainer.cpp - ../../../source_lcao/module_hcontainer/atom_pair.cpp - ../../../source_lcao/module_hcontainer/func_transfer.cpp - ../../../source_lcao/module_hcontainer/func_folding.cpp - ../../../source_lcao/module_hcontainer/transfer.cpp - ../../../source_lcao/module_hcontainer/output_hcontainer.cpp - ../../../source_lcao/module_operator_lcao/deepks_lcao.cpp - ../../../source_lcao/module_operator_lcao/operator_lcao.cpp + ../../module_hcontainer/base_matrix.cpp + ../../module_hcontainer/hcontainer.cpp + ../../module_hcontainer/atom_pair.cpp + ../../module_hcontainer/func_transfer.cpp + ../../module_hcontainer/func_folding.cpp + ../../module_hcontainer/transfer.cpp + ../../module_hcontainer/output_hcontainer.cpp + ../../module_operator_lcao/deepks_lcao.cpp + ../../module_operator_lcao/operator_lcao.cpp ../../../source_hamilt/operator.cpp - ../../../source_lcao/module_rt/td_info.cpp - ../../../source_lcao/module_rt/td_folding.cpp + ../../module_rt/td_info.cpp + ../../module_rt/td_folding.cpp ../../../source_estate/module_pot/H_TDDFT_pw.cpp ) From ee7cda3213ca8fc8f4426b41c417809a42259d7c Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 22 Nov 2025 07:24:59 +0800 Subject: [PATCH 7/7] Update coverage.yml to remove pull request trigger Removed pull request trigger for coverage analysis. --- .github/workflows/coverage.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 949f586a4c..cf1ee7f370 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -1,9 +1,6 @@ name: Coverage Analysis on: - pull_request: - branches: - - develop workflow_dispatch: push: tags: