Skip to content

Commit

Permalink
Merge pull request #1810 from billsacks/infnan_unit_test
Browse files Browse the repository at this point in the history
Allow running infnan unit tests even in DEBUG mode
Up until now, we have been skipping the shr_infnan unit tests when
building in DEBUG mode. Since we pretty much always build the unit tests
in DEBUG mode, that means that we're pretty much never running the
shr_infnan unit tests.

In trying (and failing) to solve #1763, I came up with a way to get the
shr_infnan unit tests to run and pass even when building in debug
mode. That is implemented here.

Test suite: ./scripts_regression_tests.py N_TestUnitTest on cheyenne
Also, cime fortran unit tests on my mac (with gnu)
Test baseline: N/A
Test namelist changes: none
Test status: bit for bit

Fixes #1809

User interface changes?: no

Update gh-pages html (Y/N)?: N

Code review:jedwards
  • Loading branch information
jedwards4b authored Aug 11, 2017
2 parents d3bcd58 + f31c6e3 commit f814ef3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
23 changes: 3 additions & 20 deletions src/share/test/unit/shr_infnan_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,7 @@ add_executable(infnan_test_exe ${test_sources})

declare_generated_dependencies(infnan_test_exe "${share_genf90_sources}")

if("${CMAKE_BUILD_TYPE}" MATCHES CESM_DEBUG)
set(FPES_ARE_TRAPPED TRUE)
endif()
# Add the actual test.
add_test(infnan infnan_test_exe)

if(NOT FPES_ARE_TRAPPED)

# Add the actual test.
add_test(infnan infnan_test_exe)

define_Fortran_stop_failure(infnan)

else()

# CESM_DEBUG turns on floating point trapping, causing checks in this
# test to fail. We'd like the users to be able to see that the test
# was skipped but didn't fail, but CTest has no mechanism for this.
# Instead, hack around it by adding a test that will always pass but
# is likely to stand out as a skipped test.
add_test(SKIPPED_infnan true)

endif()
define_Fortran_stop_failure(infnan)
17 changes: 17 additions & 0 deletions src/share/test/unit/shr_infnan_test/test_infnan.F90
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ program test_infnan
use shr_kind_mod, only: r4 => shr_kind_r4
use shr_kind_mod, only: i8 => shr_kind_i8
use shr_kind_mod, only: i4 => shr_kind_i4
use, intrinsic :: ieee_exceptions, only : ieee_status_type, ieee_get_status, ieee_set_status
use, intrinsic :: ieee_exceptions, only : ieee_set_halting_mode
use, intrinsic :: ieee_exceptions, only : ieee_invalid, ieee_divide_by_zero
use shr_infnan_mod

implicit none

type(ieee_status_type) :: status_value
real(r8) :: x, zero
real(r4) :: y
real(r8) :: r8array(100), r82Darray(10,10), r83Darray(4,4,4)
Expand All @@ -30,6 +34,12 @@ program test_infnan
integer(i4), parameter :: spnanspat = int(Z'7FC10000',i4)
intrinsic :: count

! Get initial ieee status so we can restore it later
call ieee_get_status(status_value)

! Need to turn off ieee_invalid checks for some of these tests to pass
call ieee_set_halting_mode([ieee_invalid, ieee_divide_by_zero], .false.)

inf = transfer(dpinfpat,inf)
nan = transfer(dpnanpat,nan)
nans = transfer(dpnanspat,nans)
Expand Down Expand Up @@ -141,6 +151,13 @@ program test_infnan
y = shr_infnan_to_r4(shr_infnan_neginf)
call assert( shr_infnan_isneginf( y ), "Test that shr_infnan_to_r4(shr_infnan_neginf) sets r4 to -inf" )

! Restore original status
!
! At least with gfortran, this restoration prevents floating point exceptions from being
! raised at the end of the run. Alternatively, we could probably set various flags to
! .false., using ieee_set_flag.
call ieee_set_status(status_value)

contains

subroutine assert(val, msg)
Expand Down

0 comments on commit f814ef3

Please sign in to comment.