aboutsummaryrefslogtreecommitdiff
path: root/ci/compile-tests/005-change-recompile/runtest.el
blob: c5d7f9b3cf2dda9149bf372936ecf342e59e8df8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
;; This file is part of Proof General.
;;
;; © Copyright 2020  Hendrik Tews
;;
;; Authors: Hendrik Tews
;; Maintainer: Hendrik Tews <hendrik@askra.de>
;;
;; License:     GPL (GNU GENERAL PUBLIC LICENSE)

;;; Commentary:
;;
;; Coq Compile Tests (cct) --
;; ert tests for parallel background compilation for Coq
;;
;; Test that the right files are recompiled when changes are made in
;; the dependency hierarchy and that unaffected ancestors are not
;; touched.
;;
;; The following graph shows the file dependencies in this test:
;;
;;           a
;;          / \
;;         b   c
;;        /   / \
;;       d   e   f
;;      / \  |  /
;;     |   \ | /
;;     |    \|/
;;     g     h
;;
;;
;;
;;
;;
;;
;;

;; require cct-lib for the elisp compilation, otherwise this is present already
(require 'cct-lib)

;;; set configuration
(cct-configure-proof-general)

;;; Data and utility functions

(defconst b-ancestors '("./b.v" "./d.v" "./g.v" "./h.v")
  "Ancestors of b.v.")

(defconst c-ancestors '("./c.v" "./e.v" "./f.v")
  "Ancestors of c.v.")

(defconst all-ancestors (append b-ancestors c-ancestors)
  "All ancestors.")

(defconst all-compiled-ancestors
  (mapcar 'cct-library-vo-of-v-file all-ancestors)
  "All vo ancestors files.")
  

(defun cct-replace-last-word (line word)
  "Replace last word in line LINE with WORD.
In current buffer, go to the end of line LINE and one word
backward. Replace the word there with WORD."
  (cct-goto-line line)
  (end-of-line)
  (backward-word)
  (kill-word 1)
  (insert word))

(defun cct-check-main-buffer (vo-times new-sum recompiled-files
                                       other-locked-files)
  "Perform various checks for recompilation in buffer a.v.
Combine all the following tests in this order:
- line 21 in a.v is unlocked
- after replacing the sum on line 28 with NEW-SUM, a.v can be
  processed until line 38
- files in VO-TIMES not listed in RECOMPILED-FILES have the same
  last change time as in VO-TIMES
- files in RECOMPILED-FILES have a newer change time
- the spans in line 22 and 23 hold the ancestors of b and c, respectively.
- all the buffers in OTHER-LOCKED-FILES are locked until line 18."
  (let (splitted)
    (set-buffer "a.v")
    (cct-check-locked 21 'unlocked)
    (cct-replace-last-word 28 new-sum)
    (cct-process-to-line 38)
    (cct-check-locked 37 'locked)
    (setq splitted (cct-split-change-times vo-times recompiled-files))
    (cct-unmodified-change-times (car splitted))
    (cct-older-change-times (cdr splitted))
    (cct-locked-ancestors 22 b-ancestors)
    (cct-locked-ancestors 23 c-ancestors)
    (mapc
     (lambda (b)
       (set-buffer b)
       (cct-check-locked 18 'locked))
     other-locked-files)))


;;; The test itself

(ert-deftest cct-change-recompile ()
  "Test successful recompilation after changes and deletion."
  (find-file "a.v")

  ;; 1. process original content - compile everything
  (message "\n1. process original content - compile everything\n")
  (cct-process-to-line 38)
  (cct-check-locked 37 'locked)
  (cct-locked-ancestors 22 b-ancestors)
  (cct-locked-ancestors 23 c-ancestors)

  (let ((vo-times (cct-record-change-times all-compiled-ancestors))
        other-locked-files)

    ;; 2. retract and process again - nothing should be compiled
    (message "\n2. retract and process again - nothing should be compiled\n")
    (cct-process-to-line 21)
    (cct-check-main-buffer vo-times "35" nil nil)

    ;; 3. change c and process again - only c should be compiled
    (message "\n3. change c and process again - only c should be compiled\n")
    (find-file "c.v")
    (push "c.v" other-locked-files)
    (cct-check-locked 23 'locked)
    (cct-replace-last-word 23 "4")
    (cct-check-main-buffer vo-times "36" '("./c.vo") other-locked-files)

    ;; 4. change h and process again - everything except g should get compiled
    (message (concat "\n4. change h and process again - "
                         "everything except g should get compiled\n"))
    (setq vo-times (cct-record-change-times all-compiled-ancestors))
    (find-file "h.v")
    (push "h.v" other-locked-files)
    (cct-check-locked 21 'locked)
    (cct-replace-last-word 21 "10")
    (cct-check-main-buffer
     vo-times "38" '("./b.vo" "./c.vo" "./d.vo" "./e.vo" "./f.vo" "./h.vo")
     other-locked-files)
    
    ;; 5. change d and f and process again -
    ;; only b, c, d and f should get recompiled
    (message (concat "\n5. change d and f and process again - "
                         "only b, c, d and f should get recompiled"))
    (setq vo-times (cct-record-change-times all-compiled-ancestors))
    (find-file "d.v")
    (push "d.v" other-locked-files)
    (cct-check-locked 23 'locked)
    (cct-replace-last-word 23 "7")
    (find-file "f.v")
    (push "f.v" other-locked-files)
    (cct-check-locked 23 'unlocked)
    (cct-replace-last-word 23 "10")

    (cct-check-main-buffer
     vo-times "45" '("./b.vo" "./c.vo" "./d.vo" "./f.vo") other-locked-files)

    ;; 6. change d and b and process again - only d and b should get compiled
    (message (concat "\n6. change d and b and process again - "
                         "only d and b should get compiled\n"))
    (setq vo-times (cct-record-change-times all-compiled-ancestors))
    (find-file "b.v")
    (push "b.v" other-locked-files)
    (cct-check-locked 23 'locked)
    (cct-replace-last-word 23 "7")
    (set-buffer "d.v")
    (cct-check-locked 23 'unlocked)
    (cct-replace-last-word 23 "13")    ; increase by 6

    (cct-check-main-buffer vo-times "56" '("./b.vo" "./d.vo")
                           other-locked-files)
    
    ;; 7. delete b and process again - only b should get compiled
    (message (concat "\n7. delete b and process again - "
                         "only b should get compiled\n"))
    (setq vo-times (cct-record-change-times all-compiled-ancestors))
    (delete-file "b.vo")
    (set-buffer "a.v")
    (cct-process-to-line 21)
    (cct-check-main-buffer vo-times "56" '("./b.vo") other-locked-files)
    
    ;; 8. delete h and process again - everything except g should get compiled
    (message (concat "\n8. delete h and process again - "
                         "everything except g should get compiled\n"))
    (setq vo-times (cct-record-change-times all-compiled-ancestors))
    (delete-file "h.vo")
    (set-buffer "a.v")
    (cct-process-to-line 21)
    (cct-check-main-buffer
     vo-times "56" '("./b.vo" "./c.vo" "./d.vo" "./e.vo" "./f.vo" "./h.vo")
     other-locked-files)
    
    ;; 9. change d, delete g and process again - only b, d and g should
    ;; get compiled
    (message (concat "\n9. change d, delete g and process again - "
                         "only b, d and g should get compiled\n"))
    (setq vo-times (cct-record-change-times all-compiled-ancestors))
    (set-buffer "d.v")
    (cct-check-locked 23 'locked)
    (cct-replace-last-word 23 "20")     ; increase by 7
    (delete-file "g.vo")
    (set-buffer "a.v")
    (cct-process-to-line 21)
    (cct-check-main-buffer vo-times "63" '("./b.vo" "./d.vo" "./g.vo")
                           other-locked-files)
    
    ;; 10. delete d, change g and process again - only b, d and g should
    ;; get compiled
    (message (concat "\n10. delete d, change g and process again - "
                         "only b, d and g should get compiled\n"))
    (setq vo-times (cct-record-change-times all-compiled-ancestors))
    (delete-file "d.vo")
    (find-file "g.v")
    (push "g.v" other-locked-files)
    (cct-check-locked 21 'locked)
    (cct-replace-last-word 21 "15")     ; increase by 8
    (set-buffer "a.v")
    (cct-process-to-line 21)
    (cct-check-main-buffer vo-times "71" '("./b.vo" "./d.vo" "./g.vo")
                           other-locked-files)
  ))