Skip to content

Commit d50ca30

Browse files
Fix: Fix coverage test (#6725)
* Fix: Fix coverage test * Fix: Fix tests/integrate/CMakeLists.txt * Update CMakeLists.txt * Refactor coverage workflow for improved error handling * Fix: rename sum_cube.exe as sum_cube * Fix: Update source/source_lcao/module_deepks/test/CMakeLists.txt * Update coverage.yml to remove pull request trigger Removed pull request trigger for coverage analysis. --------- Co-authored-by: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com>
1 parent 3f4dd49 commit d50ca30

File tree

8 files changed

+91
-32
lines changed

8 files changed

+91
-32
lines changed

.github/workflows/coverage.yml

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,76 @@ jobs:
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v5
16-
- name: Install Requirements for Coverage Testing
16+
with:
17+
submodules: recursive
18+
19+
- name: Install Perl Dependencies and Coverage Tools
1720
run: |
18-
apt update && apt install -y lcov gpg curl jq ca-certificates
19-
- name: Building
21+
apt update && apt install -y curl jq ca-certificates python3-pip
22+
apt install -y lcov perl-modules
23+
apt install -y libcapture-tiny-perl libdatetime-perl libjson-perl libperlio-gzip-perl
24+
lcov --version
25+
26+
- name: Building with Coverage
2027
run: |
21-
cmake -B build -DENABLE_COVERAGE=ON -DBUILD_TESTING=ON -DENABLE_MLALGO=ON -DENABLE_LIBXC=ON -DENABLE_LIBRI=ON -DENABLE_GOOGLEBENCH=ON -DENABLE_RAPIDJSON=ON
28+
rm -rf build/
29+
rm -f CMakeCache.txt
30+
31+
mkdir -p build
32+
chmod -R 755 build/
33+
34+
cmake -B build \
35+
-DENABLE_COVERAGE=ON \
36+
-DBUILD_TESTING=ON \
37+
-DENABLE_MLALGO=ON \
38+
-DENABLE_LIBXC=ON \
39+
-DENABLE_LIBRI=ON \
40+
-DENABLE_GOOGLEBENCH=ON \
41+
-DENABLE_RAPIDJSON=ON \
42+
-DCMAKE_BUILD_TYPE=Debug \
43+
-DCMAKE_CXX_FLAGS="--coverage -fprofile-arcs -ftest-coverage" \
44+
-DCMAKE_EXE_LINKER_FLAGS="--coverage"
2245
cmake --build build -j`nproc`
2346
cmake --install build
47+
2448
- name: Testing
2549
env:
2650
OMP_NUM_THREADS: 1
2751
run: |
28-
cmake --build build --target test ARGS="-V --timeout 21600" || exit 0
52+
chmod -R 755 build/
53+
cmake --build build --target test ARGS="-V --timeout 21600" || echo "Some tests failed but continuing for coverage"
54+
55+
- name: Generate Coverage Data
56+
run: |
57+
cd build
58+
59+
lcov --directory . --capture --output-file coverage.info
60+
61+
lcov --remove coverage.info '/usr/*' '*/test/*' '*/external/*' '*/build/*' --output-file coverage.filtered.info
62+
63+
genhtml coverage.filtered.info --output-directory coverage-report
64+
65+
cd ..
66+
2967
- name: Upload Coverage to Codecov
3068
uses: codecov/codecov-action@v5
3169
if: ${{ ! cancelled() }}
3270
with:
3371
fail_ci_if_error: true
3472
token: ${{ secrets.CODECOV_TOKEN }}
35-
skip_validation: true
73+
files: ./build/coverage.xml,./build/coverage.info
74+
directory: ./build/
75+
flags: unittests
76+
name: codecov-umbrella
3677
verbose: true
78+
79+
- name: Upload Coverage Report Artifact
80+
uses: actions/upload-artifact@v4
81+
if: always()
82+
with:
83+
name: coverage-report
84+
path: |
85+
build/coverage-report/
86+
build/coverage.info
87+
build/coverage.xml
88+
retention-days: 30

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,14 @@ if(ENABLE_COVERAGE)
156156
include(FetchContent)
157157
FetchContent_Declare(
158158
cmakecodecov
159-
URL https://github.com/baixiaokuang/CMake-codecov/archive/refs/heads/master.zip
159+
GIT_REPOSITORY https://github.com/RWTH-HPC/CMake-codecov.git
160+
GIT_TAG master
161+
GIT_SHALLOW TRUE
162+
GIT_PROGRESS TRUE
160163
)
161164
FetchContent_Populate(cmakecodecov)
162165
list(APPEND CMAKE_MODULE_PATH ${cmakecodecov_SOURCE_DIR}/cmake)
166+
set(CMAKE_MODULE_PATH "${cmakecodecov_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
163167
find_package(codecov REQUIRED)
164168
endif()
165169
endif()

source/source_cell/test_pw/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ AddTest(
1515
../read_stru.cpp ../read_atom_species.cpp
1616
../read_pp_vwr.cpp ../read_pp_blps.cpp ../../source_io/output.cpp
1717
../../source_estate/read_pseudo.cpp ../../source_estate/cal_nelec_nband.cpp
18-
../../source_estate/read_orb.cpp ../../source_cell/print_cell.cpp
18+
../../source_estate/read_orb.cpp ../print_cell.cpp
1919
../../source_estate/cal_wfc.cpp ../sep.cpp ../sep_cell.cpp
2020
)
2121

source/source_lcao/module_deepks/test/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ add_executable(
2929
../../../source_estate/cal_nelec_nband.cpp
3030
../../../source_estate/module_dm/density_matrix.cpp
3131
../../../source_estate/module_dm/density_matrix_io.cpp
32-
../../../source_lcao/module_hcontainer/base_matrix.cpp
33-
../../../source_lcao/module_hcontainer/hcontainer.cpp
34-
../../../source_lcao/module_hcontainer/atom_pair.cpp
35-
../../../source_lcao/module_hcontainer/func_transfer.cpp
36-
../../../source_lcao/module_hcontainer/func_folding.cpp
37-
../../../source_lcao/module_hcontainer/transfer.cpp
38-
../../../source_lcao/module_hcontainer/output_hcontainer.cpp
39-
../../../source_lcao/module_operator_lcao/deepks_lcao.cpp
40-
../../../source_lcao/module_operator_lcao/operator_lcao.cpp
32+
../../module_hcontainer/base_matrix.cpp
33+
../../module_hcontainer/hcontainer.cpp
34+
../../module_hcontainer/atom_pair.cpp
35+
../../module_hcontainer/func_transfer.cpp
36+
../../module_hcontainer/func_folding.cpp
37+
../../module_hcontainer/transfer.cpp
38+
../../module_hcontainer/output_hcontainer.cpp
39+
../../module_operator_lcao/deepks_lcao.cpp
40+
../../module_operator_lcao/operator_lcao.cpp
4141
../../../source_hamilt/operator.cpp
42-
../../../source_lcao/module_rt/td_info.cpp
43-
../../../source_lcao/module_rt/td_folding.cpp
42+
../../module_rt/td_info.cpp
43+
../../module_rt/td_folding.cpp
4444
../../../source_estate/module_pot/H_TDDFT_pw.cpp
4545
)
4646

source/source_lcao/module_operator_lcao/test/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ AddTest(
99
../../../source_basis/module_ao/parallel_orbitals.cpp
1010
../../../source_basis/module_ao/ORB_atomic_lm.cpp
1111
tmp_mocks.cpp ../../../source_hamilt/operator.cpp
12-
../../../source_lcao/module_rt/td_info.cpp
13-
../../../source_lcao/module_rt/td_folding.cpp
12+
../../module_rt/td_info.cpp
13+
../../module_rt/td_folding.cpp
1414
../../../source_estate/module_pot/H_TDDFT_pw.cpp
1515
)
1616

@@ -22,8 +22,8 @@ AddTest(
2222
../../../source_basis/module_ao/parallel_orbitals.cpp
2323
../../../source_basis/module_ao/ORB_atomic_lm.cpp
2424
tmp_mocks.cpp ../../../source_hamilt/operator.cpp
25-
../../../source_lcao/module_rt/td_info.cpp
26-
../../../source_lcao/module_rt/td_folding.cpp
25+
../../module_rt/td_info.cpp
26+
../../module_rt/td_folding.cpp
2727
../../../source_estate/module_pot/H_TDDFT_pw.cpp
2828
)
2929

tests/integrate/CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
find_program(BASH bash)
22
find_package(Python3 REQUIRED)
3+
4+
add_executable(sum_cube ${ABACUS_TEST_DIR}/integrate/tools/sum_cube.cpp)
5+
install(TARGETS sum_cube DESTINATION ${ABACUS_TEST_DIR}/integrate/tools/)
6+
message(STATUS "Target sum_cube has been defined in ${CMAKE_CURRENT_SOURCE_DIR}") # 添加此行
7+
8+
if(ENABLE_COVERAGE)
9+
add_coverage(sum_cube)
10+
endif()
11+
312
if(ENABLE_ASAN)
413
add_test(
514
NAME integrated_test_with_asan
@@ -13,10 +22,4 @@ else()
1322
COMMAND ${BASH} Autotest.sh -a ${ABACUS_BIN_PATH} -n 4
1423
WORKING_DIRECTORY ${ABACUS_TEST_DIR}/integrate
1524
)
16-
add_executable(sum_cube.exe ${ABACUS_TEST_DIR}/integrate/tools/sum_cube.cpp)
17-
install(TARGETS sum_cube.exe DESTINATION ${ABACUS_TEST_DIR}/integrate/tools/)
18-
19-
if(ENABLE_COVERAGE)
20-
add_coverage(sum_cube.exe)
21-
endif()
22-
endif()
25+
endif()

tests/integrate/clean.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ for directory in `ls | grep $module`; do
5555
#--------------------------------------------
5656
# delete exec files in tools directory (if it exists)
5757
#--------------------------------------------
58-
sumfile1="$directory/sum_cube.exe"
58+
sumfile1="$directory/sum_cube"
5959
test -e "$sumfile1" && rm -rf $sumfile1
6060

6161
#--------------------------------------------

tests/integrate/tools/catch_properties.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# mohan add 2025-05-03
44
# this compare script is used in different integrate tests
55
COMPARE_SCRIPT="../../integrate/tools/CompareFile.py"
6-
SUM_CUBE_EXE="../../integrate/tools/sum_cube.exe"
6+
SUM_CUBE_EXE="../../integrate/tools/sum_cube"
77

88

99
sum_file(){

0 commit comments

Comments
 (0)