Skip to content

Commit

Permalink
build: add coverage check (#1436)
Browse files Browse the repository at this point in the history
* build: add coverage check

* docs: add doc for generating code coverage report.

* build: remove install path parameter.
  • Loading branch information
baixiaokuang committed Oct 25, 2022
1 parent 7d40992 commit 3be893a
Show file tree
Hide file tree
Showing 36 changed files with 290 additions and 92 deletions.
48 changes: 40 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,40 @@ option(ENABLE_ASAN "Enable AddressSanitizer" OFF)
option(BUILD_TESTING "Build ABACUS unit tests" OFF)
option(GENERATE_TEST_REPORTS "Enable test report generation" OFF)
option(INFO "Enable gathering of math library information" OFF)
option(ENABLE_COVERAGE "Enable coverage build." OFF)

if(ENABLE_LCAO)
set(ABACUS_BIN_NAME abacus)
else()
set(ABACUS_BIN_NAME abacus_pw)
endif()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

if(ENABLE_COVERAGE)
find_package(codecov)
if(NOT codecov)
include(FetchContent)
FetchContent_Declare(
cmakecodecov
URL https://github.com/RWTH-HPC/CMake-codecov/archive/refs/heads/master.zip
)
FetchContent_Populate(cmakecodecov)
list(APPEND CMAKE_MODULE_PATH ${cmakecodecov_SOURCE_DIR}/cmake)
find_package(codecov REQUIRED)
endif()
endif()

set(ABACUS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/source)
set(ABACUS_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
set(ABACUS_BIN_PATH ${CMAKE_CURRENT_BINARY_DIR}/${ABACUS_BIN_NAME})
include_directories(${ABACUS_SOURCE_DIR})

add_executable(${ABACUS_BIN_NAME} source/main.cpp)
if(ENABLE_COVERAGE)
add_coverage(${ABACUS_BIN_NAME})
endif()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
Expand All @@ -52,14 +74,18 @@ endif()
# Other default configurations are also available, see:
# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#default-and-custom-configurations
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
add_compile_options(-O2 -g) # default flag
if(NOT ENABLE_COVERAGE)
add_compile_options(-O2 -g) # default flag
else()
add_compile_options(-g)
endif()
endif()

if(ENABLE_LCAO)
find_package(Cereal REQUIRED)
include_directories(${CEREAL_INCLUDE_DIR})
add_compile_definitions(USE_CEREAL_SERIALIZATION)

find_package(ELPA REQUIRED)
include_directories(${ELPA_INCLUDE_DIR})
target_link_libraries(${ABACUS_BIN_NAME} ELPA::ELPA)
Expand Down Expand Up @@ -261,13 +287,13 @@ endif()

if(DEFINED DeePMD_DIR)
add_compile_definitions(
__DPMD
__DPMD
HIGH_PREC
)
add_compile_options(-Wl,--no-as-needed)
find_package(DeePMD REQUIRED)
include_directories(${DeePMD_DIR}/include)
target_link_libraries(${ABACUS_BIN_NAME}
target_link_libraries(${ABACUS_BIN_NAME}
DeePMD::deepmd_cc
DeePMD::deepmd_op
DeePMD::deepmd_op_cuda
Expand Down Expand Up @@ -325,6 +351,11 @@ IF (BUILD_TESTING)
function(AddTest) # function for UT
cmake_parse_arguments(UT "DYN" "TARGET" "LIBS;DYN_LIBS;STATIC_LIBS;SOURCES;DEPENDS" ${ARGN})
add_executable(${UT_TARGET} ${UT_SOURCES})

if(ENABLE_COVERAGE)
add_coverage(${UT_TARGET})
endif()

#dependencies & link library
target_link_libraries(${UT_TARGET} ${UT_LIBS}
Threads::Threads GTest::gtest_main GTest::gmock_main)
Expand Down Expand Up @@ -375,7 +406,8 @@ if(ENABLE_LCAO)
)
endif()

install(PROGRAMS ${ABACUS_BIN_PATH}
TYPE BIN
#DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if(ENABLE_COVERAGE)
coverage_evaluate()
endif()


25 changes: 25 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,31 @@ AddTest(
- Build with `-D BUILD_TESTING=1` flag. You can find built testing programs under `build/source/<module_name>/test`.
- Follow the installing procedure of CMake. The tests will move to `build/test`.

## Generating code coverage report

We use gcov and lcov to generate code coverage report, and only support gcc.

1. Add -DENABLE_COVERAGE=ON for cmake:
```
cmake -B build -DENABLE_COVERAGE=ON
```

2. Build ABACUS.
```
cmake --build build -j`nproc`
cmake --install build
```

3. Use ``build/abacus`` to run test cases.

4. Generate html report.
```
cd build/
make lcov
```

Now you can copy build/lcov to your local device, and view build/lcov/html/all_targets/index.html

## Submitting a Pull Request

1. [Fork](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) the ABACUS repo.
Expand Down
4 changes: 4 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ add_library(
input_conv.cpp
input_update.cpp
)

if(ENABLE_COVERAGE)
add_coverage(driver)
endif()
6 changes: 5 additions & 1 deletion source/module_base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ add_library(
ylm.cpp
)

IF (BUILD_TESTING)
if(ENABLE_COVERAGE)
add_coverage(base)
endif()

if(BUILD_TESTING)
add_subdirectory(test)
endif()
5 changes: 5 additions & 0 deletions source/module_cell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ add_library(
read_cell_pseudopots.cpp
setup_nonlocal.cpp
)

if(ENABLE_COVERAGE)
add_coverage(cell)
endif()

43 changes: 23 additions & 20 deletions source/module_deepks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
if(ENABLE_DEEPKS)
list(APPEND objects
LCAO_deepks.cpp
LCAO_deepks_fdelta.cpp
LCAO_deepks_odelta.cpp
LCAO_deepks_io.cpp
LCAO_deepks_mpi.cpp
LCAO_deepks_pdm.cpp
LCAO_deepks_psialpha.cpp
LCAO_deepks_torch.cpp
LCAO_deepks_vdelta.cpp
)

add_library(
deepks
OBJECT
${objects}
)
list(APPEND objects
LCAO_deepks.cpp
LCAO_deepks_fdelta.cpp
LCAO_deepks_odelta.cpp
LCAO_deepks_io.cpp
LCAO_deepks_mpi.cpp
LCAO_deepks_pdm.cpp
LCAO_deepks_psialpha.cpp
LCAO_deepks_torch.cpp
LCAO_deepks_vdelta.cpp
)

IF (BUILD_TESTING)
add_subdirectory(test)
endif()
add_library(
deepks
OBJECT
${objects}
)

if(ENABLE_COVERAGE)
add_coverage(deepks)
endif()

if(BUILD_TESTING)
add_subdirectory(test)
endif()
endif()

4 changes: 4 additions & 0 deletions source/module_deepks/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ add_executable(
main_deepks.cpp klist_1.cpp LCAO_deepks_test_prep.cpp LCAO_deepks_test.cpp nnr.cpp parallel_orbitals.cpp
)

if(ENABLE_COVERAGE)
add_coverage(test_deepks)
endif()

get_target_property(ABACUS_LINK_LIBRARIES ${ABACUS_BIN_NAME} LINK_LIBRARIES)
target_link_libraries(
test_deepks
Expand Down
6 changes: 5 additions & 1 deletion source/module_elecstate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ add_library(
${objects}
)

IF (BUILD_TESTING)
if(ENABLE_COVERAGE)
add_coverage(elecstate)
endif()

if(BUILD_TESTING)
add_subdirectory(test)
endif()
44 changes: 25 additions & 19 deletions source/module_elecstate/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,37 @@ if(ENABLE_LCAO)
AddTest(
TARGET EState_updaterhok_pw
LIBS ${math_libs} planewave_serial base_serial
SOURCES updaterhok_pw_test.cpp ../../src_pw/charge.cpp ../../src_parallel/parallel_reduce.cpp
../../src_pw/structure_factor.cpp ../../src_pw/pw_complement.cpp
../../src_pw/klist.cpp ../../src_parallel/parallel_kpoints.cpp ../../src_pw/occupy.cpp
../../module_elecstate/elecstate_pw.cpp ../../module_elecstate/elecstate.cpp
SOURCES updaterhok_pw_test.cpp
../elecstate_pw.cpp ../elecstate.cpp
../../src_pw/charge.cpp ../../src_parallel/parallel_reduce.cpp
../../src_pw/structure_factor.cpp ../../src_pw/pw_complement.cpp
../../src_pw/klist.cpp ../../src_parallel/parallel_kpoints.cpp ../../src_pw/occupy.cpp
)

install(DIRECTORY support DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

AddTest(
TARGET EState_psiToRho_lcao
LIBS ${math_libs} ELPA::ELPA base orb cell neighbor planewave
SOURCES elecstate_lcao_test.cpp ../elecstate_lcao.cpp ../dm2d_to_grid.cpp
../../src_parallel/parallel_global.cpp ../../src_parallel/parallel_common.cpp ../../src_parallel/parallel_reduce.cpp
../../src_lcao/local_orbital_charge.cpp ../../src_lcao/DM_gamma.cpp ../../src_lcao/DM_k.cpp
../../src_lcao/local_orbital_wfc.cpp
../../module_gint/grid_technique.cpp ../../module_gint/grid_meshball.cpp ../../module_gint/grid_bigcell.cpp
../../src_parallel/parallel_global.cpp ../../src_parallel/parallel_common.cpp ../../src_parallel/parallel_reduce.cpp
../../src_lcao/local_orbital_charge.cpp ../../src_lcao/DM_gamma.cpp ../../src_lcao/DM_k.cpp
../../src_lcao/local_orbital_wfc.cpp
../../module_gint/grid_technique.cpp ../../module_gint/grid_meshball.cpp ../../module_gint/grid_bigcell.cpp
../../module_gint/grid_meshcell.cpp ../../module_gint/grid_meshk.cpp
../../module_gint/gint_tools.cpp ../../module_gint/gint_k_pvpr.cpp ../../module_gint/gint_tau.cpp
../../src_lcao/dm_2d.cpp ../../src_lcao/LCAO_matrix.cpp
../../src_lcao/record_adj.cpp ../../src_lcao/LCAO_nnr.cpp
../../module_gint/gint.cpp ../../module_gint/gint_gamma.cpp
../../module_gint/gint_fvl.cpp ../../module_gint/gint_rho.cpp
../../module_gint/gint_vl.cpp
../../src_pw/charge.cpp
../../src_pw/charge.cpp
../../src_pdiag/pdiag_common.cpp
../../src_io/output.cpp ../../src_pw/soc.cpp ../../src_io/read_rho.cpp
)
target_compile_definitions(EState_psiToRho_lcao PRIVATE __MPI)
install(FILES elecstate_lcao_parallel_test.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

find_program(BASH bash)
add_test(NAME EState_psiToRho_lcao_parallel
COMMAND ${BASH} elecstate_lcao_parallel_test.sh
Expand Down Expand Up @@ -86,13 +87,18 @@ add_library(
planewave_serial
OBJECT
../../module_pw/fft.cpp
../../module_pw/pw_basis.cpp
../../module_pw/pw_basis_k.cpp
../../module_pw/pw_distributeg.cpp
../../module_pw/pw_distributeg_method1.cpp
../../module_pw/pw_basis.cpp
../../module_pw/pw_basis_k.cpp
../../module_pw/pw_distributeg.cpp
../../module_pw/pw_distributeg_method1.cpp
../../module_pw/pw_distributeg_method2.cpp
../../module_pw/pw_distributer.cpp
../../module_pw/pw_init.cpp
../../module_pw/pw_transform.cpp
../../module_pw/pw_transform_k.cpp
../../module_pw/pw_distributer.cpp
../../module_pw/pw_init.cpp
../../module_pw/pw_transform.cpp
../../module_pw/pw_transform_k.cpp
)

if(ENABLE_COVERAGE)
add_coverage(base_serial)
add_coverage(planewave_serial)
endif()
3 changes: 3 additions & 0 deletions source/module_esolver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ add_library(
${objects}
)

if(ENABLE_COVERAGE)
add_coverage(esolver)
endif()

4 changes: 4 additions & 0 deletions source/module_gint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ add_library(
OBJECT
${objects}
)

if(ENABLE_COVERAGE)
add_coverage(gint)
endif()
5 changes: 4 additions & 1 deletion source/module_hamilt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ list(APPEND objects
ks_pw/veff_pw.cpp
ks_pw/nonlocal_pw.cpp
ks_pw/meta_pw.cpp
ks_pw/velocity_pw.cpp
ks_pw/velocity_pw.cpp
)

if(ENABLE_LCAO)
Expand All @@ -30,3 +30,6 @@ add_library(
${objects}
)

if(ENABLE_COVERAGE)
add_coverage(hamilt)
endif()
4 changes: 4 additions & 0 deletions source/module_hamilt/ks_lcao/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ add_library(
overlap_lcao.cpp
deepks_lcao.cpp
)

if(ENABLE_COVERAGE)
add_coverage(operator_ks_lcao)
endif()
4 changes: 4 additions & 0 deletions source/module_hamilt/ks_pw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ add_library(
meta_pw.cpp
velocity_pw.cpp
)

if(ENABLE_COVERAGE)
add_coverage(operator_ks_pw)
endif()
4 changes: 4 additions & 0 deletions source/module_hsolver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ add_library(
${objects}
)

if(ENABLE_COVERAGE)
add_coverage(hsolver)
endif()

if(ENABLE_LCAO)
add_subdirectory(genelpa)
endif()
Expand Down
4 changes: 4 additions & 0 deletions source/module_hsolver/genelpa/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
add_library(genelpa OBJECT elpa_new.cpp elpa_new_real.cpp elpa_new_complex.cpp utils.cpp)

if(ENABLE_COVERAGE)
add_coverage(genelpa)
endif()

0 comments on commit 3be893a

Please sign in to comment.