Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 101 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test_fms/test-lib.sh.in ${CMAKE_CURRE

# build any helper modules that are used by unit tests
list(APPEND TEST_MODS_SRC
test_fms/common/test_fms.F90
test_fms/diag_manager/testing_utils.F90
test_fms/fms/test_fms.F90
test_fms/fms2_io/argparse.F90
Expand All @@ -613,7 +614,9 @@ add_library(testLibs "${TEST_MODS_SRC}")
target_link_libraries(testLibs FMS::fms)
target_compile_definitions(testLibs PRIVATE TEST_MOS_KIND_=r8_kind)
target_include_directories(testLibs PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/common/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/fms/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/mpp/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/data_override/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/mosaic2
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
Expand Down Expand Up @@ -704,7 +707,6 @@ list(APPEND TEST_SRC_SINGLE_TARGET
test_fms/mpp/test_mpp.F90
test_fms/mpp/test_mpp_gatscat.F90
test_fms/mpp/test_mpp_get_ascii_lines.F90
test_fms/mpp/test_mpp_global_field.F90
test_fms/mpp/test_mpp_global_field_ug.F90
test_fms/mpp/test_mpp_global_sum_ad.F90
test_fms/mpp/test_mpp_init_logfile.F90
Expand Down Expand Up @@ -745,7 +747,7 @@ list(APPEND TEST_SRC_SINGLE_TARGET
test_fms/time_manager/test_time_manager.F90
)
# list any test sources that are used for two executables (r4 and r8)
list(APPEND TEST_SRC_MULTI_TARGET
list(APPEND TEST_SRC_TWO_TARGETS
test_fms/astronomy/test_astronomy.F90
test_fms/axis_utils/test_axis_utils.F90
test_fms/column_diagnostics/test_column_diagnostics.F90
Expand All @@ -771,6 +773,10 @@ list(APPEND TEST_SRC_MULTI_TARGET
test_fms/tracer_manager/test_tracer_manager.F90
test_fms/tridiagonal/test_tridiagonal.F90
)
# list any test sources that are used for four executables (r4, r8, i4, and i8)
list(APPEND TEST_SRC_FOUR_TARGETS
test_fms/mpp/test_mpp_global_field.F90
)

# add all the test executables and set up linking + compile flags
foreach (testFile ${TEST_SRC_SINGLE_TARGET})
Expand All @@ -795,12 +801,13 @@ foreach (testFile ${TEST_SRC_SINGLE_TARGET})
${moduleDir})
target_include_directories(${TName} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/fms/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/mpp/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/data_override/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/mosaic2
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
endforeach ()

foreach (testFile ${TEST_SRC_MULTI_TARGET})
foreach (testFile ${TEST_SRC_TWO_TARGETS})
get_filename_component (TName ${testFile} NAME_WE)

add_executable(${TName}_r8 ${testFile})
Expand Down Expand Up @@ -854,6 +861,97 @@ foreach (testFile ${TEST_SRC_MULTI_TARGET})
target_compile_definitions(${TName}_r4 PRIVATE WRITE_FILES_MOD_=write_files_r4)
endforeach ()

foreach (testFile ${TEST_SRC_FOUR_TARGETS})
get_filename_component (TName ${testFile} NAME_WE)

add_executable(${TName}_r8 ${testFile})
target_compile_definitions(${TName}_r8 PRIVATE "${r8_defs}")
set_target_properties(${TName}_r8 PROPERTIES COMPILE_FLAGS ${r8_flags})
target_link_libraries(${TName}_r8 PUBLIC FMS::fms
PRIVATE testLibs
)

add_executable(${TName}_r4 ${testFile})
target_compile_definitions(${TName}_r4 PRIVATE "${r4_defs}")
# seems counterintuitive but r4 tests use r8 default
# they specify kind values explicitly with the preprocessor where needed (TEST_FMS_KIND_)
set_target_properties(${TName}_r4 PROPERTIES COMPILE_FLAGS ${r8_flags})
target_link_libraries(${TName}_r4 PUBLIC FMS::fms
PRIVATE testLibs
)

add_executable(${TName}_i8 ${testFile})
target_compile_definitions(${TName}_i8 PRIVATE "${r8_defs}")
set_target_properties(${TName}_i8 PROPERTIES COMPILE_FLAGS ${r8_flags})
target_link_libraries(${TName}_i8 PUBLIC FMS::fms
PRIVATE testLibs
)

add_executable(${TName}_i4 ${testFile})
target_compile_definitions(${TName}_i4 PRIVATE "${r8_defs}")
set_target_properties(${TName}_i4 PROPERTIES COMPILE_FLAGS ${r8_flags})
target_link_libraries(${TName}_i4 PUBLIC FMS::fms
PRIVATE testLibs
)

if(WITH_YAML)
target_link_libraries(${TName}_r4 PRIVATE yaml ${LIBYAML_LIBRARIES})
target_link_libraries(${TName}_r8 PRIVATE yaml ${LIBYAML_LIBRARIES})
target_link_libraries(${TName}_i4 PRIVATE yaml ${LIBYAML_LIBRARIES})
target_link_libraries(${TName}_i8 PRIVATE yaml ${LIBYAML_LIBRARIES})
endif()

if(OPENMP)
target_link_libraries(${TName}_r4 PRIVATE OpenMP::OpenMP_Fortran)
target_link_libraries(${TName}_r8 PRIVATE OpenMP::OpenMP_Fortran)
target_link_libraries(${TName}_i4 PRIVATE OpenMP::OpenMP_Fortran)
target_link_libraries(${TName}_i8 PRIVATE OpenMP::OpenMP_Fortran)
endif()

set_target_properties(${TName}_r4 PROPERTIES Fortran_MODULE_DIRECTORY
${moduleDir})
set_target_properties(${TName}_r8 PROPERTIES Fortran_MODULE_DIRECTORY
${moduleDir})
set_target_properties(${TName}_i4 PROPERTIES Fortran_MODULE_DIRECTORY
${moduleDir})
set_target_properties(${TName}_i8 PROPERTIES Fortran_MODULE_DIRECTORY
${moduleDir})
target_include_directories(${TName}_r4 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/fms/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/mpp/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/data_override/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/mosaic2
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(${TName}_r8 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/fms/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/mpp/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/data_override/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/mosaic2
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(${TName}_i4 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/fms/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/mpp/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/data_override/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/mosaic2
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(${TName}_i8 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/fms/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/mpp/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/data_override/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/mosaic2
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

target_compile_definitions(${TName}_r8 PRIVATE FMS_TEST_TYPE_=real)
target_compile_definitions(${TName}_r4 PRIVATE FMS_TEST_TYPE_=real)
target_compile_definitions(${TName}_i8 PRIVATE FMS_TEST_TYPE_=integer)
target_compile_definitions(${TName}_i4 PRIVATE FMS_TEST_TYPE_=integer)

target_compile_definitions(${TName}_r8 PRIVATE FMS_TEST_KIND_=r8_kind)
target_compile_definitions(${TName}_r4 PRIVATE FMS_TEST_KIND_=r4_kind)
target_compile_definitions(${TName}_i8 PRIVATE FMS_TEST_KIND_=i8_kind)
target_compile_definitions(${TName}_i4 PRIVATE FMS_TEST_KIND_=i4_kind)
endforeach ()

# gather all test scripts
file(GLOB_RECURSE TEST_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/*/*.sh)
# leave out scripts that aren't tests
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ AC_CONFIG_FILES([
test_fms/test-lib.sh
test_fms/intel_coverage.sh
test_fms/Makefile
test_fms/common/Makefile
test_fms/astronomy/Makefile
test_fms/diag_manager/Makefile
test_fms/data_override/Makefile
Expand Down
2 changes: 1 addition & 1 deletion test_fms/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
ACLOCAL_AMFLAGS = -I m4

# Make targets will be run in each subdirectory. Order is significant.
SUBDIRS = astronomy coupler diag_manager data_override exchange monin_obukhov drifters \
SUBDIRS = common astronomy coupler diag_manager data_override exchange monin_obukhov drifters \
mosaic2 interpolator fms mpp time_interp time_manager horiz_interp topography \
field_manager axis_utils affinity fms2_io parser string_utils sat_vapor_pres tracer_manager \
random_numbers diag_integral column_diagnostics tridiagonal block_control
Expand Down
26 changes: 26 additions & 0 deletions test_fms/common/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#***********************************************************************
#* Apache License 2.0
#*
#* This file is part of the GFDL Flexible Modeling System (FMS).
#*
#* Licensed under the Apache License, Version 2.0 (the "License");
#* you may not use this file except in compliance with the License.
#* You may obtain a copy of the License at
#*
#* http://www.apache.org/licenses/LICENSE-2.0
#*
#* FMS is distributed in the hope that it will be useful, but WITHOUT
#* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied;
#* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
#* PARTICULAR PURPOSE. See the License for the specific language
#* governing permissions and limitations under the License.
#***********************************************************************

# Find the fms and mpp mod files.
AM_CPPFLAGS = -I$(MODDIR) -I$(top_srcdir)/test_fms/common/include

noinst_LIBRARIES = libtest_fms.a
libtest_fms_a_SOURCES = test_fms.F90 include/test_fms.inc include/test_fms_real.inc

# Clean up
CLEANFILES = *.o *.mod *.a
69 changes: 69 additions & 0 deletions test_fms/common/include/test_fms.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
!***********************************************************************
!* Apache License 2.0
!*
!* This file is part of the GFDL Flexible Modeling System (FMS).
!*
!* Licensed under the Apache License, Version 2.0 (the "License");
!* you may not use this file except in compliance with the License.
!* You may obtain a copy of the License at
!*
!* http://www.apache.org/licenses/LICENSE-2.0
!*
!* FMS is distributed in the hope that it will be useful, but WITHOUT
!* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied;
!* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
!* PARTICULAR PURPOSE. See the License for the specific language
!* governing permissions and limitations under the License.
!***********************************************************************

subroutine ARR_INIT_2D_ (arr)
FMS_TEST_TYPE_ (FMS_TEST_KIND_), intent(out) :: arr(:,:)
real(r8_kind) :: unif(size(arr,1), size(arr,2))
type(randomNumberStream), save :: random_stream
logical, save :: initialized = .false.

if (.not.initialized) then
random_stream = initializeRandomNumberStream(0)
initialized = .true.
endif

call getRandomNumbers(random_stream, unif)

arr = TYPECAST_ (1e9_r8_kind * (unif - 0.5_r8_kind), FMS_TEST_KIND_)
end subroutine ARR_INIT_2D_

subroutine ARR_INIT_3D_ (arr)
FMS_TEST_TYPE_ (FMS_TEST_KIND_), intent(out) :: arr(:,:,:)
integer :: k

do k = 1, size(arr, 3)
call arr_init(arr(:, :, k))
enddo
end subroutine ARR_INIT_3D_

subroutine ARR_COMPARE_2D_ (arr0, arr1, msg)
FMS_TEST_TYPE_ (FMS_TEST_KIND_), intent(in), dimension(:,:) :: arr0, arr1
character(*), intent(in) :: msg

if (any(arr0.ne.arr1)) then
call mpp_error(FATAL, "[2D] Unexpected result: " // msg)
endif
end subroutine ARR_COMPARE_2D_

subroutine ARR_COMPARE_3D_ (arr0, arr1, msg)
FMS_TEST_TYPE_ (FMS_TEST_KIND_), intent(in), dimension(:,:,:) :: arr0, arr1
character(*), intent(in) :: msg

if (any(arr0.ne.arr1)) then
call mpp_error(FATAL, "[3D] Unexpected result: " // msg)
endif
end subroutine ARR_COMPARE_3D_

subroutine ARR_COMPARE_4D_ (arr0, arr1, msg)
FMS_TEST_TYPE_ (FMS_TEST_KIND_), intent(in), dimension(:,:,:,:) :: arr0, arr1
character(*), intent(in) :: msg

if (any(arr0.ne.arr1)) then
call mpp_error(FATAL, "[4D] Unexpected result: " // msg)
endif
end subroutine ARR_COMPARE_4D_
80 changes: 80 additions & 0 deletions test_fms/common/include/test_fms_real.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
!***********************************************************************
!* Apache License 2.0
!*
!* This file is part of the GFDL Flexible Modeling System (FMS).
!*
!* Licensed under the Apache License, Version 2.0 (the "License");
!* you may not use this file except in compliance with the License.
!* You may obtain a copy of the License at
!*
!* http://www.apache.org/licenses/LICENSE-2.0
!*
!* FMS is distributed in the hope that it will be useful, but WITHOUT
!* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied;
!* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
!* PARTICULAR PURPOSE. See the License for the specific language
!* governing permissions and limitations under the License.
!***********************************************************************

subroutine ARR_COMPARE_TOL_2D_ (arr0, arr1, tol, msg)
real(FMS_TEST_KIND_), intent(in), dimension(:,:) :: arr0, arr1
real(FMS_TEST_KIND_), intent(in) :: tol
character(*), intent(in) :: msg

if (any(abs(arr1 - arr0).gt.tol)) then
call mpp_error(FATAL, "[2D] Unexpected result: " // msg)
endif
end subroutine ARR_COMPARE_TOL_2D_

subroutine ARR_COMPARE_TOL_3D_ (arr0, arr1, tol, msg)
real(FMS_TEST_KIND_), intent(in), dimension(:,:,:) :: arr0, arr1
real(FMS_TEST_KIND_), intent(in) :: tol
character(*), intent(in) :: msg

if (any(abs(arr1 - arr0).gt.tol)) then
call mpp_error(FATAL, "[3D] Unexpected result: " // msg)
endif
end subroutine ARR_COMPARE_TOL_3D_

subroutine ARR_COMPARE_TOL_4D_ (arr0, arr1, tol, msg)
real(FMS_TEST_KIND_), intent(in), dimension(:,:,:,:) :: arr0, arr1
real(FMS_TEST_KIND_), intent(in) :: tol
character(*), intent(in) :: msg

if (any(abs(arr1 - arr0).gt.tol)) then
call mpp_error(FATAL, "[4D] Unexpected result: " // msg)
endif
end subroutine ARR_COMPARE_TOL_4D_

subroutine ARR_COMPARE_TOL_2D_SCALAR_ (arr, ans, tol, msg)
real(FMS_TEST_KIND_), intent(in), dimension(:,:) :: arr
real(FMS_TEST_KIND_), intent(in) :: ans
real(FMS_TEST_KIND_), intent(in) :: tol
character(*), intent(in) :: msg

if (any(abs(arr - ans).gt.tol)) then
call mpp_error(FATAL, "[2D] Unexpected result: " // msg)
endif
end subroutine ARR_COMPARE_TOL_2D_SCALAR_

subroutine ARR_COMPARE_TOL_3D_SCALAR_ (arr, ans, tol, msg)
real(FMS_TEST_KIND_), intent(in), dimension(:,:,:) :: arr
real(FMS_TEST_KIND_), intent(in) :: ans
real(FMS_TEST_KIND_), intent(in) :: tol
character(*), intent(in) :: msg

if (any(abs(arr - ans).gt.tol)) then
call mpp_error(FATAL, "[3D] Unexpected result: " // msg)
endif
end subroutine ARR_COMPARE_TOL_3D_SCALAR_

subroutine ARR_COMPARE_TOL_4D_SCALAR_ (arr, ans, tol, msg)
real(FMS_TEST_KIND_), intent(in), dimension(:,:,:,:) :: arr
real(FMS_TEST_KIND_), intent(in) :: ans
real(FMS_TEST_KIND_), intent(in) :: tol
character(*), intent(in) :: msg

if (any(abs(arr - ans).gt.tol)) then
call mpp_error(FATAL, "[4D] Unexpected result: " // msg)
endif
end subroutine ARR_COMPARE_TOL_4D_SCALAR_
Loading
Loading