diff --git a/CMakeLists.txt b/CMakeLists.txt index 2be5620e..6cd18240 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,41 +88,37 @@ target_link_libraries(libneo add_subdirectory(src) add_subdirectory(tests) -add_test(Test_Build_Code make) +## Standard tests according to standard libneo Fortran test convention. + +function (add_fortran_test name) + add_test(NAME ${name} COMMAND tests/${name}.x) + set_tests_properties(${name} PROPERTIES FAIL_REGULAR_EXPRESSION "STOP") +endfunction() + +add_fortran_test(test_binsrc) +add_fortran_test(test_boozer_class) +add_fortran_test(test_efit_class) +add_fortran_test(test_geqdsk_tools) +add_fortran_test(test_hdf5_tools) + +## Custom tests + # This requires an additional call to test_arnoldi.py, so use the script # instead of calling the executable directly. # \note Maybe this could be solved with test_arnoldi.py && test_arnoldi.x. # Afterwards fail condition is set: test will fail if the output # contains 'STOP'. -add_test(NAME Test_arnoldi +add_test(NAME test_arnoldi COMMAND ../tests/python_scripts/test_arnoldi.py && tests/test_arnoldi.x) -set_tests_properties(Test_arnoldi PROPERTIES FAIL_REGULAR_EXPRESSION "STOP") - -add_test(NAME Test_binsrc - COMMAND "tests/test_binsrc.x") -set_tests_properties(Test_binsrc PROPERTIES FAIL_REGULAR_EXPRESSION "STOP") - -add_test(NAME Test_boozer - COMMAND tests/test_boozer_class.x) -set_tests_properties(Test_boozer PROPERTIES FAIL_REGULAR_EXPRESSION "STOP") -add_test(NAME Test_efit - COMMAND tests/test_efit_class.x) -set_tests_properties(Test_efit PROPERTIES FAIL_REGULAR_EXPRESSION "STOP") - -add_test(NAME Test_geqdsk_tools - COMMAND tests/test_geqdsk_tools.x) -set_tests_properties(Test_geqdsk_tools PROPERTIES FAIL_REGULAR_EXPRESSION "STOP") - -add_test(NAME Test_hdf5_tools - COMMAND "tests/test_hdf5_tools.x") -set_tests_properties(Test_hdf5_tools PROPERTIES FAIL_REGULAR_EXPRESSION "STOP") - -add_test(NAME Test_mympilib - COMMAND tests/test_mympilib.x) -set_tests_properties(Test_mympilib PROPERTIES PASS_REGULAR_EXPRESSION "Derived initMaster") -add_test(NAME Test_system_utility +set_tests_properties(test_arnoldi PROPERTIES FAIL_REGULAR_EXPRESSION "STOP") + +add_test(NAME test_mympilib + COMMAND tests/test_mympilib.x) +set_tests_properties(test_mympilib PROPERTIES PASS_REGULAR_EXPRESSION "Derived initMaster") +add_test(NAME test_system_utility COMMAND tests/test_system_utility.x) -set_tests_properties(Test_system_utility PROPERTIES FAIL_REGULAR_EXPRESSION "WARNING: resource usage could not be determined.") +set_tests_properties(test_system_utility PROPERTIES FAIL_REGULAR_EXPRESSION "WARNING: resource usage could not be determined.") + # MacOS RPATH specifics # see https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling @@ -145,8 +141,3 @@ list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" if("${isSystemDir}" STREQUAL "-1") set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") endif("${isSystemDir}" STREQUAL "-1") - - -#~ # For testing purposes, e.g. printing the environment. -#~ add_test(NAME run_xterm - #~ COMMAND xterm) diff --git a/CMakeSources.in b/CMakeSources.in index 7c525e7f..158247dc 100644 --- a/CMakeSources.in +++ b/CMakeSources.in @@ -11,6 +11,7 @@ set(SOURCE_FILES src/rusage_type.f90 src/solve_systems.f90 src/system_utility.f90 + src/util.f90 # VMEC src/canonical_coordinates_mod.f90 diff --git a/src/util.f90 b/src/util.f90 new file mode 100644 index 00000000..a072f378 --- /dev/null +++ b/src/util.f90 @@ -0,0 +1,32 @@ +module util + implicit none + +contains + + subroutine arange(a, b, dx, x) + real(8), intent(in) :: a, b, dx + real(8), dimension(:), intent(out) :: x + + integer :: i, n + + n = int((b - a) / dx) + 1 + do i = 1, n + x(i) = a + (i - 1) * dx + end do + end subroutine arange + + subroutine linspace(a, b, n, x) + real(8), intent(in) :: a, b + integer, intent(in) :: n + real(8), dimension(:), intent(out) :: x + + real(8) :: dx + integer :: i + + dx = (b - a) / (n - 1) + do i = 1, n + x(i) = a + (i - 1) * dx + end do + end subroutine linspace + +end module util diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4bd402c3..9586edbc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -41,63 +41,58 @@ execute_process(COMMAND nc-config --flibs OUTPUT_VARIABLE NETCDF_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE) +set (COMMON_LIBS ${MAIN_LIB} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${NETCDF_LIBRARIES}) + add_executable(test_arnoldi.x source/test_arnoldi.f90) target_link_libraries(test_arnoldi.x - ${MAIN_LIB} + ${COMMON_LIBS} MyMPILib ${MPI_Fortran_LIBRARIES} - ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} - ${NETCDF_LIBRARIES} - ) +) add_executable(test_binsrc.x source/test_binsrc.f90) target_link_libraries(test_binsrc.x - ${MAIN_LIB} - ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} - ${NETCDF_LIBRARIES} - ) + ${COMMON_LIBS} +) add_executable(test_boozer_class.x source/test_boozer_class.f90) target_link_libraries(test_boozer_class.x - ${MAIN_LIB} - ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} - ${NETCDF_LIBRARIES} - ) + ${COMMON_LIBS} +) add_executable(test_efit_class.x source/test_efit_class.f90) target_link_libraries(test_efit_class.x - ${MAIN_LIB} - ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} - ${NETCDF_LIBRARIES} - ) + ${COMMON_LIBS} +) add_executable(test_geqdsk_tools.x source/test_geqdsk_tools.f90) target_link_libraries(test_geqdsk_tools.x ${MAIN_LIB} ${MAGFIE_LIB} - ) +) add_executable(test_hdf5_tools.x source/test_hdf5_tools.f90) target_link_libraries(test_hdf5_tools.x ${HDF5_TOOLS_LIB} ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES} - ) +) add_executable(test_mympilib.x source/test_mympilib.f90 source/derived_scheduler_module.f90 - ) +) target_link_libraries(test_mympilib.x MyMPILib ${MPI_Fortran_LIBRARIES} - ) +) add_executable(test_system_utility.x source/test_system_utility.f90 ../src/local_rusage.c) target_link_libraries(test_system_utility.x - ${MAIN_LIB} - ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} - ${NETCDF_LIBRARIES} - ) + ${COMMON_LIBS} +) + +add_executable(test_util.x source/test_util.f90) +target_link_libraries(test_util.x ${COMMON_LIBS}) diff --git a/tests/source/test_util.f90 b/tests/source/test_util.f90 new file mode 100644 index 00000000..24c77946 --- /dev/null +++ b/tests/source/test_util.f90 @@ -0,0 +1,31 @@ +program test_interpolate + implicit none + + call test_arange + call test_linspace + +contains + + subroutine test_arange + use util, only : arange + + real(8), dimension(5) :: expected, actual + + expected = (/ 0.0d0, 1.0d0, 2.0d0, 3.0d0, 4.0d0 /) + call arange(0.0d0, 5.0d0, 1.0d0, actual) + + if (any(expected /= actual)) error stop + end subroutine test_arange + + subroutine test_linspace + use util, only : linspace + + real(8), dimension(5) :: expected, actual + + expected = (/ 0.0d0, 1.0d0, 2.0d0, 3.0d0, 4.0d0 /) + call linspace(0.0d0, 4.0d0, 5, actual) + + if (any(expected /= actual)) error stop + end subroutine test_linspace + +end program test_interpolate