fortrangoingonforty/fgof-devloop / 2bbf869

Browse files

Test devloop model

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
2bbf869e7229cf112d626b6d6188cb8a67031f23
Parents
414cce8
Tree
79792ae

2 changed files

StatusFile+-
A test/test_devloop_model.f90 76 0
M test/test_scaffold.f90 30 2
test/test_devloop_model.f90added
@@ -0,0 +1,76 @@
1
+program test_devloop_model
2
+  use fgof_devloop, only : &
3
+    FGOF_DEVLOOP_DECISION_IDLE, &
4
+    FGOF_DEVLOOP_DECISION_RESTART, &
5
+    FGOF_DEVLOOP_DECISION_STOP, &
6
+    FGOF_DEVLOOP_TRIGGER_CHANGE, &
7
+    FGOF_DEVLOOP_TRIGGER_START, &
8
+    begin_devloop_cycle, &
9
+    clear_devloop_options, &
10
+    clear_devloop_state, &
11
+    devloop_change_trigger, &
12
+    devloop_manual_trigger, &
13
+    devloop_start_trigger, &
14
+    finish_devloop_cycle, &
15
+    should_start_on_open, &
16
+    start_devloop, &
17
+    stop_devloop
18
+  use fgof_devloop_types, only : devloop_cycle, devloop_decision, devloop_options, devloop_state
19
+  implicit none
20
+
21
+  type(devloop_state) :: state
22
+  type(devloop_options) :: options
23
+  type(devloop_cycle) :: cycle
24
+  type(devloop_decision) :: decision
25
+
26
+  state = clear_devloop_state()
27
+  call start_devloop(state)
28
+  if (.not. state%active) error stop "start_devloop should activate the loop"
29
+  if (.not. should_start_on_open(state)) error stop "default options should request a start cycle"
30
+
31
+  cycle = begin_devloop_cycle(state, devloop_start_trigger())
32
+  if (.not. cycle%started) error stop "start trigger should begin a cycle"
33
+  if (cycle%id /= 1) error stop "first cycle should use id one"
34
+  if (cycle%trigger_kind /= FGOF_DEVLOOP_TRIGGER_START) error stop "cycle should record start trigger"
35
+  if (.not. state%running) error stop "begin cycle should mark the loop running"
36
+
37
+  decision = finish_devloop_cycle(state, succeeded=.true., exit_code=0)
38
+  if (decision%kind /= FGOF_DEVLOOP_DECISION_IDLE) error stop "successful cycle should idle"
39
+  if (state%running) error stop "finished cycle should clear running state"
40
+  if (state%last_cycle%exit_code /= 0) error stop "finish should preserve exit code"
41
+
42
+  cycle = begin_devloop_cycle(state, devloop_change_trigger(3, "source changed"))
43
+  if (.not. cycle%started) error stop "change trigger should begin a restart cycle"
44
+  if (cycle%trigger_kind /= FGOF_DEVLOOP_TRIGGER_CHANGE) error stop "change cycle should record trigger kind"
45
+  if (cycle%change_count /= 3) error stop "change cycle should preserve change count"
46
+  decision = finish_devloop_cycle(state, succeeded=.false., exit_code=2)
47
+  if (decision%kind /= FGOF_DEVLOOP_DECISION_RESTART) error stop "failed cycle should restart by default"
48
+  if (.not. decision%should_run) error stop "restart decision should request another run"
49
+  if (state%consecutive_failures /= 1) error stop "failed cycle should increment failure count"
50
+
51
+  options = clear_devloop_options()
52
+  options%restart_on_change = .false.
53
+  call start_devloop(state, options)
54
+  cycle = begin_devloop_cycle(state, devloop_change_trigger(1))
55
+  if (cycle%started) error stop "restart_on_change=false should suppress change cycles"
56
+  cycle = begin_devloop_cycle(state, devloop_manual_trigger())
57
+  if (.not. cycle%started) error stop "manual trigger should still begin a cycle"
58
+
59
+  options = clear_devloop_options()
60
+  options%max_failures = 1
61
+  call start_devloop(state, options)
62
+  cycle = begin_devloop_cycle(state, devloop_start_trigger())
63
+  decision = finish_devloop_cycle(state, succeeded=.false., exit_code=1)
64
+  if (decision%kind /= FGOF_DEVLOOP_DECISION_STOP) error stop "max failures should stop the loop"
65
+  if (.not. decision%should_stop) error stop "stop decision should request stop"
66
+  if (state%active) error stop "failure limit should deactivate the loop"
67
+  if (.not. state%stopped) error stop "failure limit should mark the loop stopped"
68
+
69
+  options = clear_devloop_options()
70
+  options%max_failures = -5
71
+  call start_devloop(state, options)
72
+  if (state%options%max_failures /= 0) error stop "negative max_failures should normalize to unlimited"
73
+
74
+  call stop_devloop(state)
75
+  if (state%active) error stop "stop_devloop should deactivate the loop"
76
+end program test_devloop_model
test/test_scaffold.f90modified
@@ -1,12 +1,40 @@
11
 program test_scaffold
2
-  use fgof_devloop, only : clear_devloop_state, devloop_backend_name
3
-  use fgof_devloop_types, only : devloop_state
2
+  use fgof_devloop, only : &
3
+    FGOF_DEVLOOP_DECISION_IDLE, &
4
+    FGOF_DEVLOOP_TRIGGER_NONE, &
5
+    clear_devloop_cycle, &
6
+    clear_devloop_decision, &
7
+    clear_devloop_options, &
8
+    clear_devloop_state, &
9
+    clear_devloop_trigger, &
10
+    devloop_backend_name
11
+  use fgof_devloop_types, only : devloop_cycle, devloop_decision, devloop_options, devloop_state, devloop_trigger
412
   implicit none
513
 
614
   type(devloop_state) :: state
15
+  type(devloop_options) :: options
16
+  type(devloop_trigger) :: trigger
17
+  type(devloop_cycle) :: cycle
18
+  type(devloop_decision) :: decision
719
 
820
   state = clear_devloop_state()
21
+  options = clear_devloop_options()
22
+  trigger = clear_devloop_trigger()
23
+  cycle = clear_devloop_cycle()
24
+  decision = clear_devloop_decision()
25
+
26
+  if (state%options%max_failures /= 0) error stop "devloop options should start with unlimited failures"
27
+  if (.not. state%options%run_on_start) error stop "devloop should default to run on start"
28
+  if (.not. state%options%restart_on_change) error stop "devloop should default to restart on change"
29
+  if (state%last_cycle%id /= 0) error stop "devloop state should clear the last cycle"
930
   if (state%cycle_count /= 0) error stop "devloop state should start with no cycles"
31
+  if (state%consecutive_failures /= 0) error stop "devloop state should start with no failures"
1032
   if (state%active) error stop "devloop state should start inactive"
33
+  if (state%running) error stop "devloop state should not start running"
34
+  if (state%stopped) error stop "devloop state should not start stopped"
35
+  if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_NONE) error stop "clear trigger should produce no trigger"
36
+  if (cycle%started) error stop "clear cycle should not start a cycle"
37
+  if (decision%kind /= FGOF_DEVLOOP_DECISION_IDLE) error stop "clear decision should idle"
38
+  if (options%stop_on_failure) error stop "clear options should not stop on failure by default"
1139
   if (devloop_backend_name() /= "model") error stop "devloop backend should report model"
1240
 end program test_scaffold