From f31c6e3645e2a11949925eb8e598cc5be08eacdf Mon Sep 17 00:00:00 2001 From: Bill Sacks Date: Fri, 11 Aug 2017 13:22:38 -0600 Subject: [PATCH] Allow running infnan unit tests even in DEBUG mode --- .../test/unit/shr_infnan_test/CMakeLists.txt | 23 +++---------------- .../test/unit/shr_infnan_test/test_infnan.F90 | 17 ++++++++++++++ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/share/test/unit/shr_infnan_test/CMakeLists.txt b/src/share/test/unit/shr_infnan_test/CMakeLists.txt index aa0bcafe327..fa40ba40688 100644 --- a/src/share/test/unit/shr_infnan_test/CMakeLists.txt +++ b/src/share/test/unit/shr_infnan_test/CMakeLists.txt @@ -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) diff --git a/src/share/test/unit/shr_infnan_test/test_infnan.F90 b/src/share/test/unit/shr_infnan_test/test_infnan.F90 index 3a1851cab70..01123ee2393 100644 --- a/src/share/test/unit/shr_infnan_test/test_infnan.F90 +++ b/src/share/test/unit/shr_infnan_test/test_infnan.F90 @@ -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) @@ -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) @@ -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)