diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index c664bf796c..cf1ee7f370 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -13,24 +13,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 + 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` cmake --install build + - 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 + + genhtml coverage.filtered.info --output-directory coverage-report + + cd .. + - name: Upload Coverage to Codecov uses: codecov/codecov-action@v5 if: ${{ ! cancelled() }} with: fail_ci_if_error: true 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ac95e45fd..1b28936399 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,10 +156,14 @@ if(ENABLE_COVERAGE) 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_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 ) 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 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(){