@@ -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 |