MONC
Functions/Subroutines | Variables
test_registry_mod Module Reference

Functions/Subroutines

subroutine test_register ()
 
subroutine test_deregister ()
 
subroutine test_component_information ()
 
subroutine test_component_removal_callbacks ()
 
subroutine test_component_callbacks ()
 
subroutine test_component_replacement_callbacks ()
 
integer function calculate_remaining_calls (orig_value, a, b)
 
subroutine insert_component_callbacks (init_callbacks, timestep_callbacks, consolidation_callbacks, modelDump_callbacks, finalisation_callbacks)
 
subroutine generate_dummy_callbacks (init_callbacks, timestep_callbacks, consolidation_callbacks, modelDump_callbacks, finalisation_callbacks)
 
subroutine internal_test_init (current_state)
 
subroutine internal_test_timestep (current_state)
 
subroutine internal_test_consolidation (current_state)
 
subroutine internal_test_modeldump (current_state)
 
subroutine internal_test_finalisation (current_state)
 
character(len=15) function str (k)
 
subroutine init_random_seed ()
 
subroutine clear_counters ()
 

Variables

integer init_calls = 0
 
integer timestep_calls = 0
 
integer consolidation_calls = 0
 
integer modeldump_calls = 0
 
integer finalisation_calls = 0
 

Function/Subroutine Documentation

◆ calculate_remaining_calls()

integer function test_registry_mod::calculate_remaining_calls ( integer, intent(in)  orig_value,
integer, intent(in)  a,
integer, intent(in)  b 
)

Definition at line 210 of file test_registry.F90.

211  integer, intent(in) :: orig_value, a, b
212 
213  if (orig_value .ge. a) then
214  calculate_remaining_calls = orig_value - merge(orig_value - a+1, a+1, orig_value .le. b)
215  else
216  calculate_remaining_calls = orig_value
217  end if
Here is the caller graph for this function:

◆ clear_counters()

subroutine test_registry_mod::clear_counters

Definition at line 327 of file test_registry.F90.

328  init_calls = 0
329  timestep_calls = 0
330  consolidation_calls = 0
331  modeldump_calls = 0
332  finalisation_calls = 0
Here is the caller graph for this function:

◆ generate_dummy_callbacks()

subroutine test_registry_mod::generate_dummy_callbacks ( integer, intent(in)  init_callbacks,
integer, intent(in)  timestep_callbacks,
integer, intent(in)  consolidation_callbacks,
integer, intent(in)  modelDump_callbacks,
integer, intent(in)  finalisation_callbacks 
)

Definition at line 247 of file test_registry.F90.

249 
250  integer, intent(in) :: init_callbacks, timestep_callbacks, consolidation_callbacks, &
251  modelDump_callbacks, finalisation_callbacks
252  type(component_descriptor_type), pointer :: descriptor
253  integer :: i
254 
255  do i=1,100
256  allocate(descriptor)
257  descriptor%name="Test "//str(i)
258  descriptor%version=100-i
259  if (i .le. init_callbacks) descriptor%initialisation=>internal_test_init
260  if (i .le. timestep_callbacks) descriptor%timestep=>internal_test_timestep
261  if (i .le. consolidation_callbacks) descriptor%consolidation=>internal_test_consolidation
262  if (i .le. modeldump_callbacks) descriptor%modeldump=>internal_test_modeldump
263  if (i .le. finalisation_callbacks) descriptor%finalisation=>internal_test_finalisation
264  call register_component(descriptor)
265  end do
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_random_seed()

subroutine test_registry_mod::init_random_seed

Definition at line 311 of file test_registry.F90.

312  integer :: i, n, clock
313  integer, dimension(:), allocatable :: seed
314 
315  call random_seed(size = n)
316  allocate(seed(n))
317 
318  call system_clock(count=clock)
319 
320  seed = clock + 37 * (/ (i - 1, i = 1, n) /)
321  call random_seed(put = seed)
322 
323  deallocate(seed)
Here is the caller graph for this function:

◆ insert_component_callbacks()

subroutine test_registry_mod::insert_component_callbacks ( integer, intent(out)  init_callbacks,
integer, intent(out)  timestep_callbacks,
integer, intent(out)  consolidation_callbacks,
integer, intent(out)  modelDump_callbacks,
integer, intent(out)  finalisation_callbacks 
)

Definition at line 222 of file test_registry.F90.

224 
225  integer, intent(out) :: init_callbacks, timestep_callbacks, consolidation_callbacks, &
226  modelDump_callbacks, finalisation_callbacks
227  real :: r
228 
229  call init_random_seed()
230 
231  call random_number(r)
232  init_callbacks = int(r*99)+1
233  call random_number(r)
234  timestep_callbacks = int(r*99)+1
235  call random_number(r)
236  consolidation_callbacks = int(r*99)+1
237  call random_number(r)
238  modeldump_callbacks = int(r*99)+1
239  call random_number(r)
240  finalisation_callbacks = int(r*99)+1
241 
242  call generate_dummy_callbacks(init_callbacks, timestep_callbacks, consolidation_callbacks, &
243  modeldump_callbacks, finalisation_callbacks)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_test_consolidation()

subroutine test_registry_mod::internal_test_consolidation ( type(model_state_type), intent(inout), target  current_state)

Definition at line 283 of file test_registry.F90.

284  type(model_state_type), target, intent(inout) :: current_state
285 
286  consolidation_calls = consolidation_calls + 1
Here is the caller graph for this function:

◆ internal_test_finalisation()

subroutine test_registry_mod::internal_test_finalisation ( type(model_state_type), intent(inout), target  current_state)

Definition at line 297 of file test_registry.F90.

298  type(model_state_type), target, intent(inout) :: current_state
299 
300  finalisation_calls = finalisation_calls + 1
Here is the caller graph for this function:

◆ internal_test_init()

subroutine test_registry_mod::internal_test_init ( type(model_state_type), intent(inout), target  current_state)

Definition at line 269 of file test_registry.F90.

270  type(model_state_type), target, intent(inout) :: current_state
271 
272  init_calls = init_calls + 1
Here is the caller graph for this function:

◆ internal_test_modeldump()

subroutine test_registry_mod::internal_test_modeldump ( type(model_state_type), intent(inout), target  current_state)

Definition at line 290 of file test_registry.F90.

291  type(model_state_type), target, intent(inout) :: current_state
292 
293  modeldump_calls = modeldump_calls + 1
Here is the caller graph for this function:

◆ internal_test_timestep()

subroutine test_registry_mod::internal_test_timestep ( type(model_state_type), intent(inout), target  current_state)

Definition at line 276 of file test_registry.F90.

277  type(model_state_type), target, intent(inout) :: current_state
278 
279  timestep_calls = timestep_calls + 1
Here is the caller graph for this function:

◆ str()

character(len=15) function test_registry_mod::str ( integer, intent(in)  k)

Definition at line 304 of file test_registry.F90.

305  integer, intent(in) :: k
306  write (str, *) k
307  str = adjustl(str)
Here is the caller graph for this function:

◆ test_component_callbacks()

subroutine test_registry_mod::test_component_callbacks

Definition at line 155 of file test_registry.F90.

156  type(model_state_type) :: testing_state
157  integer :: init_callbacks, timestep_callbacks, consolidation_callbacks, modeldump_callbacks, finalisation_callbacks
158 
159  call clear_counters()
160  call free_registry() ! Clear the registry to remove any residue from previous unit tests
161  call insert_component_callbacks(init_callbacks, timestep_callbacks, consolidation_callbacks, &
162  modeldump_callbacks, finalisation_callbacks)
163 
164  ! Call the callbacks for each stage
165  call execute_initialisation_callbacks(testing_state)
166  call execute_timestep_callbacks(testing_state)
167  call execute_consolidation_callbacks(testing_state)
168  call execute_modeldump_callbacks(testing_state)
169  call execute_finalisation_callbacks(testing_state)
170 
171  ! Check that the number of callback calls is consistent with what we expected for each stage
172  call assert_equals(init_callbacks, init_calls, "Number of initialisation call-backs")
173  call assert_equals(timestep_callbacks, timestep_calls, "Number of timestep call-backs")
174  call assert_equals(consolidation_callbacks, consolidation_calls, "Number of consolidation call-backs")
175  call assert_equals(modeldump_callbacks, modeldump_calls, "Number of model dump call-backs")
176  call assert_equals(finalisation_callbacks, finalisation_calls, "Number of finalisation call-backs")
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_component_information()

subroutine test_registry_mod::test_component_information

Definition at line 78 of file test_registry.F90.

79  type(model_state_type) :: testing_state
80  type(component_descriptor_type), pointer :: data
81  integer :: init_callbacks, timestep_callbacks, consolidation_callbacks, modeldump_callbacks,&
82  finalisation_callbacks, i
83 
84  call free_registry() ! Clear the registry to eliminate residue of previous unit tests
85  call insert_component_callbacks(init_callbacks, timestep_callbacks, consolidation_callbacks, &
86  modeldump_callbacks, finalisation_callbacks)
87 
88  do i=1,120
89  data => get_component_info("Test "//str(i))
90  if (i .le. 100) then
91  call assert_true(associated(data), "Testing there is some component information if less than 100")
92  call assert_equals("Test "//str(i), data%name, "Compare registered and expected name")
93  call assert_equals(real(100-i), data%version, "Compare registered and expected version")
94  ! Check each callback is associated if i is within range or not if i is not
95  call assert_equals(merge(.true., .false., i .le. init_callbacks), associated(data%initialisation), &
96  "Consistency of initialisation call-back")
97  call assert_equals(merge(.true., .false., i .le. timestep_callbacks), associated(data%timestep), &
98  "Consistency of timestep call-back")
99  call assert_equals(merge(.true., .false., i .le. consolidation_callbacks), associated(data%consolidation), &
100  "Consistency of consolidation call-back")
101  call assert_equals(merge(.true., .false., i .le. modeldump_callbacks), associated(data%modeldump), &
102  "Consistency of model dump call-back")
103  call assert_equals(merge(.true., .false., i .le. finalisation_callbacks), associated(data%finalisation), &
104  "Consistency of finalisation all-back")
105  else
106  call assert_false(associated(data), "No component if greater than 100") ! Not registered i>100 so should be NULL
107  end if
108  end do
109 
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_component_removal_callbacks()

subroutine test_registry_mod::test_component_removal_callbacks

Definition at line 115 of file test_registry.F90.

116  type(model_state_type) :: testing_state
117  integer :: init_callbacks, timestep_callbacks, consolidation_callbacks, modeldump_callbacks,&
118  finalisation_callbacks, i
119 
120  call clear_counters()
121  call free_registry() ! Clear the registry to eliminate residue of previous unit tests
122  call insert_component_callbacks(init_callbacks, timestep_callbacks, consolidation_callbacks, &
123  modeldump_callbacks, finalisation_callbacks)
124 
125  do i=25,50
126  ! Now deregister 25-50 callbacks
127  call deregister_component("Test "//str(i))
128  end do
129 
130  ! In reference to the 25-50 inclusive removals, recalculate the expected number of each stage's callback
131  init_callbacks = calculate_remaining_calls(init_callbacks, 25, 50)
132  timestep_callbacks = calculate_remaining_calls(timestep_callbacks, 25, 50)
133  consolidation_callbacks = calculate_remaining_calls(consolidation_callbacks, 25, 50)
134  modeldump_callbacks = calculate_remaining_calls(modeldump_callbacks, 25, 50)
135  finalisation_callbacks = calculate_remaining_calls(finalisation_callbacks, 25, 50)
136 
137  ! Call the stages
138  call execute_initialisation_callbacks(testing_state)
139  call execute_timestep_callbacks(testing_state)
140  call execute_consolidation_callbacks(testing_state)
141  call execute_modeldump_callbacks(testing_state)
142  call execute_finalisation_callbacks(testing_state)
143 
144  ! Check number of calls in each stages's callbacks are appropriate
145  call assert_equals(init_callbacks, init_calls, "Number of initialisation call-backs post removal")
146  call assert_equals(timestep_callbacks, timestep_calls, "Number of timestep call-backs post removal")
147  call assert_equals(consolidation_callbacks, consolidation_calls, "Number of consolidation call-backs post removal")
148  call assert_equals(modeldump_callbacks, modeldump_calls, "Number of model dump call-backs post removal")
149  call assert_equals(finalisation_callbacks, finalisation_calls, "Number of finalisation call-backs post removal")
150 
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_component_replacement_callbacks()

subroutine test_registry_mod::test_component_replacement_callbacks

Definition at line 181 of file test_registry.F90.

182  type(model_state_type), target :: testing_state
183  integer :: init_callbacks, timestep_callbacks, consolidation_callbacks, modeldump_callbacks, finalisation_callbacks
184 
185  call clear_counters()
186  call free_registry() ! Clear the registry to remove any residue of previous unit tests
187  call insert_component_callbacks(init_callbacks, timestep_callbacks, consolidation_callbacks, &
188  modeldump_callbacks, finalisation_callbacks)
189  ! Recreate our callbacks
190  call generate_dummy_callbacks(init_callbacks, timestep_callbacks, consolidation_callbacks, &
191  modeldump_callbacks, finalisation_callbacks)
192 
193  ! Execute callbacks for each stage
194  call execute_initialisation_callbacks(testing_state)
195  call execute_timestep_callbacks(testing_state)
196  call execute_consolidation_callbacks(testing_state)
197  call execute_modeldump_callbacks(testing_state)
198  call execute_finalisation_callbacks(testing_state)
199 
200  ! Check the number of calls to each callback is consistent with what we initially expected
201  call assert_equals(init_callbacks, init_calls, "Number of initialisation call-backs post replacement")
202  call assert_equals(timestep_callbacks, timestep_calls, "Number of timestep call-backs post replacement")
203  call assert_equals(consolidation_callbacks, consolidation_calls, "Number of consolidation call-backs post replacement")
204  call assert_equals(modeldump_callbacks, modeldump_calls, "Number of model dump call-backs post replacement")
205  call assert_equals(finalisation_callbacks, finalisation_calls, "Number of finalisation call-backs post replacement")
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_deregister()

subroutine test_registry_mod::test_deregister

Definition at line 53 of file test_registry.F90.

54  type(component_descriptor_type), pointer :: descriptor
55  type(map_type) :: component_info
56  integer :: i
57 
58  do i=1,10
59  allocate(descriptor)
60  descriptor%version=100-i
61  descriptor%name="Test "//str(i)
62  call register_component(descriptor)
63  end do
64 
65  component_info = get_all_registered_components()
66  call assert_equals(10, c_size(component_info), "Number of registered components after registrations")
67 
68  do i=1,10
69  call deregister_component("Test "//str(i))
70  component_info = get_all_registered_components()
71  call assert_equals(10-i, c_size(component_info), "Component at i has de-registered")
72  end do
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_register()

subroutine test_registry_mod::test_register

Definition at line 22 of file test_registry.F90.

23  type(component_descriptor_type), pointer :: descriptor
24  type(map_type) :: component_info
25  class(*), pointer :: data
26  integer :: i
27 
28  call set_unit_name('test_register')
29  do i=1,10
30  allocate(descriptor)
31  descriptor%version=100-i
32  descriptor%name="Test "//str(i)
33  call register_component(descriptor)
34  end do
35 
36  component_info = get_all_registered_components()
37  call assert_equals(10, c_size(component_info), "Number of registered components after registrations")
38 
39  do i=1,10
40  call assert_equals("Test "//str(i), c_key_at(component_info, i))
41  data => c_value_at(component_info, i)
42  select type(data)
43  type is (real)
44  call assert_equals(real(100-i), data, "Version number of component at i correct")
45  class default
46  call add_fail("Unknown type")
47  end select
48  end do
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ consolidation_calls

integer test_registry_mod::consolidation_calls = 0

Definition at line 15 of file test_registry.F90.

15  integer :: consolidation_calls = 0

◆ finalisation_calls

integer test_registry_mod::finalisation_calls = 0

Definition at line 17 of file test_registry.F90.

17  integer :: finalisation_calls = 0

◆ init_calls

integer test_registry_mod::init_calls = 0

Definition at line 13 of file test_registry.F90.

13  integer :: init_calls = 0

◆ modeldump_calls

integer test_registry_mod::modeldump_calls = 0

Definition at line 16 of file test_registry.F90.

16  integer :: modeldump_calls = 0

◆ timestep_calls

integer test_registry_mod::timestep_calls = 0

Definition at line 14 of file test_registry.F90.

14  integer :: timestep_calls = 0