Skip to content

Commit

Permalink
Merge pull request espressomd#2268 from jngrad/unit-test-cmake
Browse files Browse the repository at this point in the history
Unit testing cmake
  • Loading branch information
KaiSzuttor authored and RudolfWeeber committed Oct 17, 2018
1 parent 312b4b2 commit a6fb1f7
Show file tree
Hide file tree
Showing 148 changed files with 1,051 additions and 194 deletions.
4 changes: 3 additions & 1 deletion maintainer/CI/build_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ fi

cmake_params="-DCMAKE_BUILD_TYPE=$build_type -DPYTHON_EXECUTABLE=$(which python$python_version) -DWARNINGS_ARE_ERRORS=ON -DTEST_NP:INT=$check_procs $cmake_params"
cmake_params="$cmake_params -DCMAKE_CXX_FLAGS=$cxx_flags"
cmake_params="$cmake_params -DCMAKE_INSTALL_PREFIX=/tmp/espresso-unit-tests"

if $insource; then
builddir=$srcdir
Expand Down Expand Up @@ -231,12 +232,13 @@ if $make_check; then
done
fi
cmd "make -j${build_procs} check_unit_tests $make_params" || exit 1
cmd "make check_cmake_install $make_params" || exit 1

end "TEST"
else
start "TEST"

cmd "mpiexec -n $check_procs ./pypresso $srcdir/testsuite/particle.py" || exit 1
cmd "mpiexec -n $check_procs ./pypresso $srcdir/testsuite/python/particle.py" || exit 1

end "TEST"
fi
Expand Down
2 changes: 1 addition & 1 deletion src/python/pypresso.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ case $1 in
exec cuda-memcheck ${options} @PYTHON_FRONTEND@ $@
;;
*)
exec @PYTHON_FRONTEND@ $@
exec @PYTHON_FRONTEND@ "$@"
;;
esac
194 changes: 2 additions & 192 deletions testsuite/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,192 +1,2 @@
if(NOT DEFINED TEST_NP)
include(ProcessorCount)
ProcessorCount(NP)
math(EXPR TEST_NP "${NP}/2 + 1")
endif()

if(EXISTS ${MPIEXEC})
# OpenMPI 3.0 and higher checks the number of processes against the number of CPUs
execute_process(COMMAND ${MPIEXEC} --version RESULT_VARIABLE mpi_version_result OUTPUT_VARIABLE mpi_version_output ERROR_VARIABLE mpi_version_output)
if (mpi_version_result EQUAL 0 AND mpi_version_output MATCHES "\\(Open(RTE| MPI)\\) ([3-9]\\.|1[0-9])")
set(MPIEXEC_OVERSUBSCRIBE "-oversubscribe")
else()
set(MPIEXEC_OVERSUBSCRIBE "")
endif()
endif()

function(PYTHON_TEST)
cmake_parse_arguments(TEST "" "FILE;MAX_NUM_PROC;RUN_WITH_MPI" "DEPENDENCIES;CONFIGURATIONS" ${ARGN})
get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE)
configure_file(${TEST_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${TEST_FILE})
foreach(dependency IN LISTS TEST_DEPENDENCIES)
configure_file(${dependency} ${CMAKE_CURRENT_BINARY_DIR}/${dependency})
endforeach(dependency)
set(TEST_FILE "${CMAKE_CURRENT_BINARY_DIR}/${TEST_FILE}")

# Default values
if (NOT DEFINED TEST_RUN_WITH_MPI)
set(TEST_RUN_WITH_MPI TRUE)
endif()
if(${TEST_MAX_NUM_PROC} LESS 2)
set(TEST_CONFIGURATIONS ${TEST_CONFIGURATIONS} "serial")
elseif(${TEST_MAX_NUM_PROC} LESS 3)
set(TEST_CONFIGURATIONS ${TEST_CONFIGURATIONS} "serial;parallel")
else()
set(TEST_CONFIGURATIONS ${TEST_CONFIGURATIONS} "serial;parallel;parallel_odd")
endif()

if(${TEST_MAX_NUM_PROC} LESS ${TEST_NP})
set(TEST_NUM_PROC ${TEST_MAX_NUM_PROC})
else()
set(TEST_NUM_PROC ${TEST_NP})
endif()

if(EXISTS ${MPIEXEC} AND ${TEST_RUN_WITH_MPI})
add_test(NAME ${TEST_NAME}
COMMAND
${MPIEXEC} ${MPIEXEC_OVERSUBSCRIBE} ${MPIEXEC_NUMPROC_FLAG} ${TEST_NUM_PROC} ${CMAKE_BINARY_DIR}/pypresso ${TEST_FILE}
CONFIGURATIONS
${TEST_CONFIGURATIONS}
)
else()
add_test(${TEST_NAME} ${CMAKE_BINARY_DIR}/pypresso ${TEST_FILE})
endif()

set(python_tests ${python_tests} ${TEST_FILE} PARENT_SCOPE)
endfunction(PYTHON_TEST)

python_test(FILE save_checkpoint.py MAX_NUM_PROC 4)
python_test(FILE test_checkpoint.py MAX_NUM_PROC 4)
python_test(FILE cellsystem.py MAX_NUM_PROC 4)
python_test(FILE constraint_homogeneous_magnetic_field.py MAX_NUM_PROC 4)
python_test(FILE constraint_shape_based.py MAX_NUM_PROC 2)
python_test(FILE coulomb_cloud_wall.py MAX_NUM_PROC 4)
python_test(FILE coulomb_tuning.py MAX_NUM_PROC 4)
python_test(FILE correlation.py MAX_NUM_PROC 4)
python_test(FILE dawaanr-and-dds-gpu.py MAX_NUM_PROC 1)
python_test(FILE dawaanr-and-bh-gpu.py MAX_NUM_PROC 1)
python_test(FILE electrostaticInteractions.py MAX_NUM_PROC 2)
python_test(FILE engine_langevin.py MAX_NUM_PROC 4)
python_test(FILE engine_lb.py MAX_NUM_PROC 1)
python_test(FILE engine_lbgpu.py MAX_NUM_PROC 1)
python_test(FILE icc.py MAX_NUM_PROC 4)
python_test(FILE magnetostaticInteractions.py MAX_NUM_PROC 1)
python_test(FILE mass-and-rinertia_per_particle.py MAX_NUM_PROC 1)
python_test(FILE interactions_bond_angle.py MAX_NUM_PROC 4)
python_test(FILE interactions_bonded_interface.py MAX_NUM_PROC 4)
python_test(FILE interactions_bonded.py MAX_NUM_PROC 2)
python_test(FILE interactions_non-bonded_interface.py MAX_NUM_PROC 4)
python_test(FILE interactions_non-bonded.py MAX_NUM_PROC 4)
python_test(FILE observables.py MAX_NUM_PROC 4)
python_test(FILE p3m_gpu.py MAX_NUM_PROC 4)
python_test(FILE particle.py MAX_NUM_PROC 4)
python_test(FILE stress.py MAX_NUM_PROC 4)
python_test(FILE scafacos_dipoles_1d_2d.py MAX_NUM_PROC 4)
python_test(FILE tabulated.py MAX_NUM_PROC 2)
python_test(FILE particle_slice.py MAX_NUM_PROC 4)
python_test(FILE rigid_bond.py MAX_NUM_PROC 4)
python_test(FILE rotation_per_particle.py MAX_NUM_PROC 4)
python_test(FILE rotational_inertia.py MAX_NUM_PROC 4)
python_test(FILE script_interface_object_params.py MAX_NUM_PROC 4)
python_test(FILE lbgpu_remove_total_momentum.py MAX_NUM_PROC 4)
python_test(FILE reaction_ensemble.py MAX_NUM_PROC 4)
python_test(FILE constant_pH.py MAX_NUM_PROC 4)
python_test(FILE swimmer_reaction.py MAX_NUM_PROC 1)
python_test(FILE writevtf.py MAX_NUM_PROC 4)
python_test(FILE lb_stokes_sphere_gpu.py MAX_NUM_PROC 1)
python_test(FILE ek_eof_one_species_x.py MAX_NUM_PROC 1)
python_test(FILE ek_eof_one_species_y.py MAX_NUM_PROC 1)
python_test(FILE ek_eof_one_species_z.py MAX_NUM_PROC 1)
python_test(FILE ek_eof_one_species_x_nonlinear.py MAX_NUM_PROC 1)
python_test(FILE ek_eof_one_species_y_nonlinear.py MAX_NUM_PROC 1)
python_test(FILE ek_eof_one_species_z_nonlinear.py MAX_NUM_PROC 1)
python_test(FILE exclusions.py MAX_NUM_PROC 2)
python_test(FILE langevin_thermostat.py MAX_NUM_PROC 1)
python_test(FILE nsquare.py MAX_NUM_PROC 4)
python_test(FILE virtual_sites_relative.py MAX_NUM_PROC 2)
python_test(FILE virtual_sites_tracers.py MAX_NUM_PROC 2)
python_test(FILE virtual_sites_tracers_gpu.py MAX_NUM_PROC 2)
python_test(FILE domain_decomposition.py MAX_NUM_PROC 4)
python_test(FILE layered.py MAX_NUM_PROC 4)
python_test(FILE minimize_energy.py MAX_NUM_PROC 4)
python_test(FILE mmm1d.py MAX_NUM_PROC 4)
python_test(FILE variant_conversion.py MAX_NUM_PROC 1)
python_test(FILE dipolar_mdlc_p3m_scafacos_p2nfft.py MAX_NUM_PROC 1)
python_test(FILE lb.py MAX_NUM_PROC 2)
python_test(FILE lb_gpu_viscous.py MAX_NUM_PROC 2)
python_test(FILE force_cap.py MAX_NUM_PROC 2)
python_test(FILE dpd.py MAX_NUM_PROC 4)
python_test(FILE hat.py MAX_NUM_PROC 4)
python_test(FILE analyze_energy.py MAX_NUM_PROC 2)
python_test(FILE analyze_itensor.py MAX_NUM_PROC 4)
python_test(FILE rdf.py MAX_NUM_PROC 1)
python_test(FILE coulomb_mixed_periodicity.py MAX_NUM_PROC 4)
python_test(FILE coulomb_cloud_wall_duplicated.py MAX_NUM_PROC 4)
python_test(FILE collision_detection.py MAX_NUM_PROC 4)
python_test(FILE lb_get_u_at_pos.py MAX_NUM_PROC 4)
python_test(FILE lj.py MAX_NUM_PROC 4)
python_test(FILE pairs.py MAX_NUM_PROC 4)
python_test(FILE polymer.py MAX_NUM_PROC 4)
python_test(FILE auto_exclusions.py MAX_NUM_PROC 1)
python_test(FILE subt_lj.py MAX_NUM_PROC 2)
python_test(FILE observable_cylindrical.py MAX_NUM_PROC 4)
python_test(FILE unravel_index.py MAX_NUM_PROC 4)
python_test(FILE observable_cylindricalLB.py MAX_NUM_PROC 1)
python_test(FILE analyze_chains.py MAX_NUM_PROC 1)
python_test(FILE analyze_distance.py MAX_NUM_PROC 1)
python_test(FILE comfixed.py MAX_NUM_PROC 2)
python_test(FILE rescale.py MAX_NUM_PROC 2)
python_test(FILE npt.py MAX_NUM_PROC 4)
python_test(FILE elc_vs_mmm2d_neutral.py MAX_NUM_PROC 2)
python_test(FILE elc_vs_mmm2d_nonneutral.py MAX_NUM_PROC 2)
python_test(FILE accumulator.py MAX_NUM_PROC 4)
python_test(FILE wang_landau_reaction_ensemble.py MAX_NUM_PROC 1)
python_test(FILE array_properties.py MAX_NUM_PROC 4)
python_test(FILE analyze_distribution.py MAX_NUM_PROC 1)
python_test(FILE observable_profile.py MAX_NUM_PROC 4)
python_test(FILE observable_profileLB.py MAX_NUM_PROC 1)
python_test(FILE rotate_system.py MAX_NUM_PROC 4)
python_test(FILE random_pairs.py MAX_NUM_PROC 4)
python_test(FILE lb_electrohydrodynamics.py MAX_NUM_PROC 4)
python_test(FILE cluster_analysis.py MAX_NUM_PROC 4)
python_test(FILE pair_criteria.py MAX_NUM_PROC 4)
python_test(FILE actor.py MAX_NUM_PROC 1)
python_test(FILE drude.py MAX_NUM_PROC 2)
python_test(FILE thermalized_bond.py MAX_NUM_PROC 4)
python_test(FILE thole.py MAX_NUM_PROC 4)
python_test(FILE lb_switch.py MAX_NUM_PROC 1)
python_test(FILE lb_boundary_velocity.py MAX_NUM_PROC 1)
python_test(FILE lb_thermo_virtual.py MAX_NUM_PROC 2)
python_test(FILE lb_poiseuille.py MAX_NUM_PROC 4)
python_test(FILE lb_interpolation.py MAX_NUM_PROC 4)
python_test(FILE analyze_gyration_tensor.py MAX_NUM_PROC 1)
python_test(FILE oif_volume_conservation.py MAX_NUM_PROC 2)
python_test(FILE simple_pore.py MAX_NUM_PROC 1)
python_test(FILE field_test.py MAX_NUM_PROC 1)
python_test(FILE lb_boundary.py MAX_NUM_PROC 2)
python_test(FILE lb_streaming.py MAX_NUM_PROC 4)
python_test(FILE lb_shear.py MAX_NUM_PROC 2)

if(PY_H5PY)
python_test(FILE h5md.py MAX_NUM_PROC 2)
endif(PY_H5PY)

add_custom_target(python_test_data
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/data ${CMAKE_CURRENT_BINARY_DIR}/data
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/tests_common.py ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/virtual_sites_tracers_common.py ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/ek_common.py ${CMAKE_CURRENT_BINARY_DIR})

add_custom_target(check_python_serial COMMAND ${CMAKE_CTEST_COMMAND} $(ARGS) -C serial --output-on-failure)
add_dependencies(check_python_serial pypresso python_test_data)

add_custom_target(check_python_parallel COMMAND ${CMAKE_CTEST_COMMAND} $(ARGS) -C parallel --output-on-failure)
add_dependencies(check_python_parallel pypresso python_test_data)

add_custom_target(check_python_parallel_odd COMMAND ${CMAKE_CTEST_COMMAND} $(ARGS) -C parallel_odd --output-on-failure)
add_dependencies(check_python_parallel_odd pypresso python_test_data)

add_custom_target(check_python)
add_dependencies(check_python pypresso python_test_data check_python_serial)

add_dependencies(check check_python)
add_subdirectory(python)
add_subdirectory(cmake)
Loading

0 comments on commit a6fb1f7

Please sign in to comment.