Test_RunChild.pf Source File


This file depends on

sourcefile~~test_runchild.pf~~EfferentGraph sourcefile~test_runchild.pf Test_RunChild.pf sourcefile~errorhandling.f90 ErrorHandling.F90 sourcefile~test_runchild.pf->sourcefile~errorhandling.f90 sourcefile~genericgridcomp.f90 GenericGridComp.F90 sourcefile~test_runchild.pf->sourcefile~genericgridcomp.f90 sourcefile~griddedcomponentdriver.f90 GriddedComponentDriver.F90 sourcefile~test_runchild.pf->sourcefile~griddedcomponentdriver.f90 sourcefile~mapl_generic.f90 MAPL_Generic.F90 sourcefile~test_runchild.pf->sourcefile~mapl_generic.f90 sourcefile~outermetacomponent.f90 OuterMetaComponent.F90 sourcefile~test_runchild.pf->sourcefile~outermetacomponent.f90 sourcefile~scratchpad.f90 scratchpad.F90 sourcefile~test_runchild.pf->sourcefile~scratchpad.f90 sourcefile~usersetservices.f90 UserSetServices.F90 sourcefile~test_runchild.pf->sourcefile~usersetservices.f90

Source Code

#include "MAPL_TestErr.h"

module Test_RunChild
   use mapl3g_GenericGridComp
   use mapl3g_Generic
   use mapl3g_GriddedComponentDriver
   use mapl3g_OuterMetaComponent
   use mapl3g_UserSetServices
   use mapl_ErrorHandling
   use esmf
   use pfunit
   use scratchpad, only: log, clear_log
   implicit none

   type(ESMF_GridComp) :: parent_gc
   type(ESMF_GridComp) :: user_gc
   type(OuterMetaComponent), pointer :: parent_meta
   
contains

   ! Build a parent gc with 2 children.
   subroutine setup(this, rc)
      class(MpiTestMethod), intent(inout) :: this
      integer, intent(out) :: rc

      type(ESMF_HConfig) :: config
      type(GriddedComponentDriver) :: user_comp
      integer :: status
      type(ESMF_Time) :: t
      type(ESMF_TimeInterval) :: dt
      type(ESMF_Clock) :: clock

      call ESMF_TimeSet(t, h=0)
      call ESMF_TimeIntervalSet(dt, h=1)
      clock = ESMF_ClockCreate(dt, t)

      config = ESMF_HConfigCreate(content='{}', rc=status)
      @assert_that(status, is(0))

      associate (ss_parent => user_setservices('libsimple_parent_gridcomp'))
        parent_gc = create_grid_comp('parent', ss_parent, config, clock, rc=status)
      end associate

      @assert_that(status, is(0))
      parent_meta => get_outer_meta(parent_gc, rc=status)
      @assert_that(status, is(0))

      associate (ss_leaf => user_setservices('libsimple_leaf_gridcomp'))
        call parent_meta%add_child('child_1', ss_leaf, config, rc=status)
        @assert_that(status, is(0))
        call parent_meta%add_child('child_2', ss_leaf, config, rc=status)
        @assert_that(status, is(0))
      end associate

      call ESMF_GridCompSetServices(parent_gc, setServices, rc=status)
      @assert_that(status, is(0))

      user_comp = parent_meta%get_user_gc_driver()
      user_gc = user_comp%get_gridcomp()

      call ESMF_HConfigDestroy(config, rc=status)
      @assert_that(status, is(0))

      call clear_log()
      rc = ESMF_SUCCESS
   end subroutine setup

   subroutine teardown(this)
      class(MpiTestMethod), intent(inout) :: this
      integer :: status
      call ESMF_GridCompDestroy(parent_gc, rc=status)
      @assert_that(status, is(0))
   end subroutine teardown
      

   @test(npes=[0])
   ! MAPL_RunChild() is called from withis _user_ gridcomps.
   subroutine test_MAPL_RunChild(this)
      class(MpiTestMethod), intent(inout) :: this
      integer :: status

      call setup(this, rc=status)
      @assert_that(status, is(0))
      call MAPL_RunChild(user_gc, child_name='child_1', rc=status)
      @assert_that(status, is(0))
      @assertEqual("wasRun_child_1", log)

      call teardown(this)
      
   end subroutine test_MAPL_RunChild

   @test(npes=[0])
   subroutine test_MAPL_RunChild_other_phase(this)
      class(MpiTestMethod), intent(inout) :: this
      integer :: status

      call setup(this, rc=status)
      @assert_that(status, is(0))

      call MAPL_RunChild(user_gc, child_name='child_1', phase_name='extra', rc=status)
      @assert_that(status, is(0))
      @assertEqual("wasRun_extra_child_1", log)

      call teardown(this)
      
   end subroutine test_MAPL_RunChild_other_phase

   @test(npes=[0])
   subroutine test_init_children(this)
      class(MpiTestMethod), intent(inout) :: this
      type(ESMF_State) :: importState, exportState
      type(ESMF_Time) :: t
      type(ESMF_TimeInterval) :: dt
      type(ESMF_Clock) :: clock

      integer :: status

      call ESMF_TimeSet(t, h=0)
      call ESMF_TimeIntervalSet(dt, h=1)
      clock = ESMF_ClockCreate(dt, t)

      call setup(this, rc=status)
      @assert_that(status, is(0))

      call parent_meta%initialize_user(rc=status)
      @assert_that(status, is(0))
      @assertEqual("wasInit :: wasInit_child_1 :: wasInit_child_2", log)

      call teardown(this)

   end subroutine test_init_children


   @test(npes=[0])
   subroutine test_finalize_children(this)
      class(MpiTestMethod), intent(inout) :: this
      type(ESMF_State) :: importState, exportState

      integer :: status
      type(ESMF_Time) :: t
      type(ESMF_TimeInterval) :: dt
      type(ESMF_Clock) :: clock

      call ESMF_TimeSet(t, h=0)
      call ESMF_TimeIntervalSet(dt, h=1)
      clock = ESMF_ClockCreate(dt, t)

      call setup(this, rc=status)
      @assert_that(status, is(0))

      call parent_meta%finalize(importState, exportState, clock, rc=status)
      @assert_that(status, is(0))
      @assertEqual("wasFinal :: wasFinal_child_1 :: wasFinal_child_2", log)

      call teardown(this)

   end subroutine test_finalize_children

   @test(npes=[0])
   subroutine test_MAPL_invalid_name(this)
      class(MpiTestMethod), intent(inout) :: this
      
      type(ESMF_HConfig) :: config
      integer :: status
      type(ESMF_Time) :: t
      type(ESMF_TimeInterval) :: dt
      type(ESMF_Clock) :: clock

      call ESMF_TimeSet(t, h=0)
      call ESMF_TimeIntervalSet(dt, h=1)
      clock = ESMF_ClockCreate(dt, t)

      config = ESMF_HConfigCreate(content='{}', rc=status)
      @assert_that(status, is(0))

      associate (ss_parent => user_setservices('libsimple_parent_gridcomp'))
        parent_gc = create_grid_comp('parent', ss_parent, config, clock, rc=status)
      end associate
      @assert_that(status, is(0))
      parent_meta => get_outer_meta(parent_gc, rc=status)
      @assert_that(status, is(0))
      user_gc = parent_meta%get_gridcomp()

      associate (ss_leaf => user_setservices('libsimple_leaf_gridcomp'))
        ! Empty name
        call parent_meta%add_child('', ss_leaf, config, rc=status)
        @assertExceptionRaised('Child name <> does not conform to GEOS standards.')

        ! Illegal starting character
        call parent_meta%add_child('1A', ss_leaf, config, rc=status)
        @assertExceptionRaised('Child name <1A> does not conform to GEOS standards.')

        ! Illegal character: hyphen
        call parent_meta%add_child('A-1', ss_leaf, config, rc=status)
        @assertExceptionRaised('Child name <A-1> does not conform to GEOS standards.')

      end associate

      call ESMF_HConfigDestroy(config, rc=status)
      @assert_that(status, is(0))
      
   end subroutine test_MAPL_invalid_name

end module Test_RunChild