fortrangoingonforty/fgof-devloop / d0b6c98

Browse files

Test devloop watch policy

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
d0b6c98ac5f097044f86d7cc6a48a114949d1ff1
Parents
c5b2e60
Tree
85501db

2 changed files

StatusFile+-
A test/test_devloop_watch.f90 102 0
M test/test_scaffold.f90 18 1
test/test_devloop_watch.f90added
@@ -0,0 +1,102 @@
1
+program test_devloop_watch
2
+  use fgof_devloop, only : &
3
+    FGOF_DEVLOOP_TRIGGER_CHANGE, &
4
+    FGOF_DEVLOOP_TRIGGER_NONE, &
5
+    begin_devloop_cycle, &
6
+    clear_devloop_options, &
7
+    devloop_summarize_watch_events, &
8
+    devloop_watch_failure_summary, &
9
+    devloop_watch_options, &
10
+    devloop_watch_trigger, &
11
+    start_devloop
12
+  use fgof_devloop_types, only : &
13
+    devloop_cycle, &
14
+    devloop_options, &
15
+    devloop_state, &
16
+    devloop_trigger, &
17
+    devloop_watch_summary
18
+  use fgof_watch_types, only : &
19
+    FGOF_WATCH_EVT_CREATED, &
20
+    FGOF_WATCH_EVT_MODIFIED, &
21
+    FGOF_WATCH_EVT_MOVED, &
22
+    FGOF_WATCH_EVT_NONE, &
23
+    FGOF_WATCH_EVT_REMOVED, &
24
+    watch_event, &
25
+    watch_options
26
+  implicit none
27
+
28
+  type(watch_event) :: events(5)
29
+  type(devloop_watch_summary) :: summary
30
+  type(devloop_options) :: options
31
+  type(devloop_trigger) :: trigger
32
+  type(devloop_state) :: state
33
+  type(devloop_cycle) :: cycle
34
+  type(watch_options) :: watch_config
35
+
36
+  events(1)%kind = FGOF_WATCH_EVT_CREATED
37
+  events(1)%path = "src/main.f90"
38
+  events(2)%kind = FGOF_WATCH_EVT_MODIFIED
39
+  events(2)%path = "src/lib.f90"
40
+  events(3)%kind = FGOF_WATCH_EVT_REMOVED
41
+  events(3)%path = "build"
42
+  events(3)%is_directory = .true.
43
+  events(4)%kind = FGOF_WATCH_EVT_MOVED
44
+  events(4)%path = "test/new.f90"
45
+  events(4)%previous_path = "test/old.f90"
46
+  events(5)%kind = FGOF_WATCH_EVT_NONE
47
+
48
+  summary = devloop_summarize_watch_events(events)
49
+  if (summary%event_count /= 5) error stop "watch summary should preserve event count"
50
+  if (summary%change_count /= 4) error stop "watch summary should count meaningful changes"
51
+  if (summary%file_change_count /= 3) error stop "watch summary should count file changes"
52
+  if (summary%directory_change_count /= 1) error stop "watch summary should count directory changes"
53
+  if (summary%created_count /= 1) error stop "watch summary should count creates"
54
+  if (summary%modified_count /= 1) error stop "watch summary should count modifies"
55
+  if (summary%removed_count /= 1) error stop "watch summary should count removes"
56
+  if (summary%moved_count /= 1) error stop "watch summary should count moves"
57
+  if (summary%ignored_none_count /= 1) error stop "watch summary should ignore none events"
58
+  if (.not. summary%has_changes) error stop "watch summary should report changes"
59
+
60
+  options = clear_devloop_options()
61
+  options%debounce_polls = 2
62
+  options%ignore_hidden = .true.
63
+  options%restart_on_directory_change = .false.
64
+  watch_config = devloop_watch_options(options)
65
+  if (watch_config%debounce_polls /= 2) error stop "watch options should carry debounce policy"
66
+  if (.not. watch_config%ignore_hidden) error stop "watch options should carry hidden-path policy"
67
+  if (watch_config%emit_directory_events) error stop "watch options should suppress directory events when requested"
68
+
69
+  options%debounce_polls = -3
70
+  watch_config = devloop_watch_options(options)
71
+  if (watch_config%debounce_polls /= 0) error stop "watch options should clamp negative debounce"
72
+
73
+  trigger = devloop_watch_trigger(summary)
74
+  if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_CHANGE) error stop "watch changes should create a change trigger"
75
+  if (trigger%change_count /= 4) error stop "watch trigger should carry the change count"
76
+
77
+  options = clear_devloop_options()
78
+  options%restart_on_directory_change = .false.
79
+  options%min_restart_changes = 4
80
+  trigger = devloop_watch_trigger(summary, options)
81
+  if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_NONE) then
82
+    error stop "directory-filtered changes below threshold should not restart"
83
+  end if
84
+
85
+  options%min_restart_changes = 3
86
+  trigger = devloop_watch_trigger(summary, options, "filtered watch")
87
+  if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_CHANGE) error stop "file changes at threshold should restart"
88
+  if (trigger%change_count /= 3) error stop "filtered watch trigger should carry file count"
89
+  if (trigger%reason /= "filtered watch") error stop "watch trigger should preserve custom reason"
90
+
91
+  summary = devloop_watch_failure_summary(7, "snapshot failed")
92
+  if (.not. summary%watch_failed) error stop "watch failure summary should record failure"
93
+  trigger = devloop_watch_trigger(summary)
94
+  if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_NONE) error stop "watch failures should not force restart triggers"
95
+
96
+  call start_devloop(state)
97
+  summary = devloop_summarize_watch_events(events(1:2))
98
+  trigger = devloop_watch_trigger(summary)
99
+  cycle = begin_devloop_cycle(state, trigger)
100
+  if (.not. cycle%started) error stop "watch trigger should drive the devloop cycle model"
101
+  if (cycle%change_count /= 2) error stop "watch cycle should preserve trigger change count"
102
+end program test_devloop_watch
test/test_scaffold.f90modified
@@ -7,8 +7,15 @@ program test_scaffold
77
     clear_devloop_options, &
88
     clear_devloop_state, &
99
     clear_devloop_trigger, &
10
+    clear_devloop_watch_summary, &
1011
     devloop_backend_name
11
-  use fgof_devloop_types, only : devloop_cycle, devloop_decision, devloop_options, devloop_state, devloop_trigger
12
+  use fgof_devloop_types, only : &
13
+    devloop_cycle, &
14
+    devloop_decision, &
15
+    devloop_options, &
16
+    devloop_state, &
17
+    devloop_trigger, &
18
+    devloop_watch_summary
1219
   implicit none
1320
 
1421
   type(devloop_state) :: state
@@ -16,16 +23,22 @@ program test_scaffold
1623
   type(devloop_trigger) :: trigger
1724
   type(devloop_cycle) :: cycle
1825
   type(devloop_decision) :: decision
26
+  type(devloop_watch_summary) :: watch_summary
1927
 
2028
   state = clear_devloop_state()
2129
   options = clear_devloop_options()
2230
   trigger = clear_devloop_trigger()
2331
   cycle = clear_devloop_cycle()
2432
   decision = clear_devloop_decision()
33
+  watch_summary = clear_devloop_watch_summary()
2534
 
2635
   if (state%options%max_failures /= 0) error stop "devloop options should start with unlimited failures"
2736
   if (.not. state%options%run_on_start) error stop "devloop should default to run on start"
2837
   if (.not. state%options%restart_on_change) error stop "devloop should default to restart on change"
38
+  if (.not. state%options%restart_on_directory_change) error stop "devloop should restart on directory changes by default"
39
+  if (state%options%ignore_hidden) error stop "devloop should not ignore hidden paths by default"
40
+  if (state%options%min_restart_changes /= 1) error stop "devloop should restart after one change by default"
41
+  if (state%options%debounce_polls /= 0) error stop "devloop should not debounce by default"
2942
   if (state%last_cycle%id /= 0) error stop "devloop state should clear the last cycle"
3043
   if (state%cycle_count /= 0) error stop "devloop state should start with no cycles"
3144
   if (state%consecutive_failures /= 0) error stop "devloop state should start with no failures"
@@ -36,5 +49,9 @@ program test_scaffold
3649
   if (cycle%started) error stop "clear cycle should not start a cycle"
3750
   if (decision%kind /= FGOF_DEVLOOP_DECISION_IDLE) error stop "clear decision should idle"
3851
   if (options%stop_on_failure) error stop "clear options should not stop on failure by default"
52
+  if (options%ignore_hidden) error stop "clear options should not ignore hidden paths by default"
53
+  if (options%debounce_polls /= 0) error stop "clear options should not debounce by default"
54
+  if (watch_summary%has_changes) error stop "clear watch summary should not have changes"
55
+  if (watch_summary%watch_failed) error stop "clear watch summary should not fail"
3956
   if (devloop_backend_name() /= "model") error stop "devloop backend should report model"
4057
 end program test_scaffold