-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CNPhenology (and other?) unit tests not being run #3015
Comments
Commenting out lines in various cd src/unit_tests.temp/__command_line_test__/__command_line_test__
ctest -VV --output-on-failure gives:
with exit code 0. So something seems to be wrong with the building of the tests. |
If I do
but it returns exit code 0. A different such executable—
|
I'm looking at this.... |
Okay, I think I partially understand why this is failing, and have at least a partial solution. The clue is in the ESMF errors you saw in a few places. By looking through output of various tests (in I don't understand why this leads to a silent crash of the CTest / PFUnit code, but given that ESMF probably does various low-level things in its initialization and finalization, I guess I'm not too surprised. My feeling is that trying to track down the cause of that might be a long exercise. However, I will reach out to Tom Clune - the lead developer of PFUnit, who also uses ESMF extensively - to see if he has any insight. There's a simple fix that solves your issue: diff --git a/src/unit_test_shr/unittestTimeManagerMod.F90 b/src/unit_test_shr/unittestTimeManagerMod.F90
index 8e1cdb3f3..bb2e1beeb 100644
--- a/src/unit_test_shr/unittestTimeManagerMod.F90
+++ b/src/unit_test_shr/unittestTimeManagerMod.F90
@@ -48,7 +48,7 @@ contains
! Should be called once for every test that uses the time manager.
!
! !USES:
- use ESMF, only : ESMF_Initialize, ESMF_SUCCESS
+ use ESMF, only : ESMF_Initialize, ESMF_IsInitialized, ESMF_SUCCESS
use clm_time_manager, only : set_timemgr_init, timemgr_init, NO_LEAP_C, GREGORIAN_C
!
! !ARGUMENTS:
@@ -59,6 +59,7 @@ contains
integer :: l_dtime ! local version of dtime
logical :: l_use_gregorian_calendar ! local version of use_gregorian_calendar
character(len=:), allocatable :: calendar
+ logical :: esmf_is_initialized
integer :: rc ! return code
integer, parameter :: dtime_default = 1800 ! time step (seconds)
@@ -89,9 +90,15 @@ contains
l_use_gregorian_calendar = .false.
end if
- call ESMF_Initialize(rc=rc)
+ esmf_is_initialized = ESMF_IsInitialized(rc=rc)
if (rc /= ESMF_SUCCESS) then
- stop 'Error in ESMF_Initialize'
+ stop 'Error in ESMF_IsInitialized'
+ end if
+ if (.not. esmf_is_initialized) then
+ call ESMF_Initialize(rc=rc)
+ if (rc /= ESMF_SUCCESS) then
+ stop 'Error in ESMF_Initialize'
+ end if
end if
if (l_use_gregorian_calendar) then
@@ -219,10 +226,12 @@ contains
call timemgr_reset()
- call ESMF_Finalize(rc=rc)
- if (rc /= ESMF_SUCCESS) then
- stop 'Error in ESMF_Finalize'
- end if
+ ! If this is the end of the executable, we should call
+ ! ESMF_Finalize. But the timemgr setup and teardown routines can
+ ! be called multiple times within a single unit test executable,
+ ! and it's an error to re-call ESMF_Initialize after calling
+ ! ESMF_Finalize. So for now we just won't attempt to do an
+ ! ESMF_Finalize.
end subroutine unittest_timemgr_teardown With that diff, errors are reported as expected in CNPhenologyMod (when adding However, as you thought, @samsrabin , there are now some failures in other unit test modules that had been going unreported before. I'll look into this, since I think they're tests I wrote. I'll open a draft CTSM PR with these changes for further discussion / work. (As a side note: I see that, under some circumstances, a failure in the setUp method does cause a test failure. For example, I commented out all but the first test, and then inserted a second call to |
Oh excellent, thanks for tracking this down @billsacks! |
Draft PR here: #3017 I'll leave it as draft until I fix the unit tests that are now failing more visibly than before. |
ESMF was being repeatedly initialized in unittestTimeManagerMod.F90, which is an error. This led to unit tests failing silently. This commit fixes the issue by checking if ESMF is already initialized before calling ESMF_Initialize, and not calling ESMF_Finalize at the end of each unit test. Currently this skips any calls to ESMF_Finalize, as it is an error to re-call ESMF_Initialize after calling ESMF_Finalize. A better solution would be to only call ESMF_Initialize and ESMF_Finalize once per unit test executable. I am looking into whether that's possible. I'm not sure if it will cause any problems to not do the ESMF_Finalize. See ESCOMP#3015 (comment) for details. Resolves ESCOMP#3015
…te to NOT call ESMF_Finalize, see ESCOMP#3015 and ESCOMP#3017
Brief summary of bug
I noticed that I couldn't get tests in test_CNPhenology.pf to fail, even if I did something like
@assertTrue(.false.)
. @ekluzek figured out that this is because it's failing insetUp()
atcall clm_varcon_init( is_simple_buildtemp = .true.)
. Specifically, it seems like something is not getting correctly deallocated between tests.Steps to resolution:
test_CNPhenology.pf
'ssetUp()
.setUp()
.General bug information
CTSM version you are using: ctsm5.3.031
Does this bug cause significantly incorrect results in the model's science? No, but it might be hiding bugs that would.
Important details of your setup / configuration so we can reproduce the bug
Testing on Derecho.
If I comment out all the tests except
check_doonset_normal
(the first one), then add@assertTrue( .false. )
at the end of that test, it fails successfully.If I uncomment the next test (
check_doonset_vegdepend_buttemperate
), neither test fails.If I re-comment the latter and then uncomment the last test (
test_was_sown_in_this_window_sameday
), neither test fails.If I add a call of
endrun()
at the end ofsetUp()
, I get the following:I thought maybe
tearDown()
wasn't getting called, but when I paste the contents oftearDown()
at the end of the first test, it doesn't make a difference.The text was updated successfully, but these errors were encountered: