|
1
|
# |
|
2
|
# Tests that a fossil command interrupted by a power loss or a killed |
|
3
|
# process leaves repositories and check-outs that fossil can use, and |
|
4
|
# does not lose the user's work. |
|
5
|
# |
|
6
|
# tools/powerloss/powerloss.c is a library that fossil loads with |
|
7
|
# LD_PRELOAD. It stops the command at its Nth stop point, and leaves the |
|
8
|
# repository and check-out database files as a power loss or a killed |
|
9
|
# process would at that moment. tools/powerloss/README-POWERLOSS.md |
|
10
|
# describes it. For each command, and each of its stop points in turn, |
|
11
|
# these tests run the command from a fresh copy of the files, stop it |
|
12
|
# there, and check what the user would find. Each check is reported |
|
13
|
# once, with the stop points where it failed. |
|
14
|
# |
|
15
|
# The tests run for a repository in DELETE mode, Fossil's default, and in |
|
16
|
# WAL mode, except the clones, which make a repository in DELETE mode. |
|
17
|
# With a WAL repository, SQLite commits the repository and the check-out |
|
18
|
# database one after the other, so an interrupted command can leave the |
|
19
|
# check-out database one check-in behind the repository, which "fossil |
|
20
|
# update" repairs, or ahead of it, where the check-out can't be used |
|
21
|
# until its database is deleted and it is opened again. |
|
22
|
# |
|
23
|
|
|
24
|
require_no_open_checkout |
|
25
|
|
|
26
|
if {[test_assurance] eq "smoke"} { |
|
27
|
test_skip "powerloss runs only with -assurance ci or stress" |
|
28
|
} |
|
29
|
if {$::tcl_platform(os) ni {Linux FreeBSD NetBSD OpenBSD DragonFly}} { |
|
30
|
test_skip "the power loss library needs LD_PRELOAD, which\ |
|
31
|
$::tcl_platform(os) does not have" |
|
32
|
} |
|
33
|
set shimSource [file join $::testfiledir .. tools powerloss powerloss.c] |
|
34
|
if {![file exists $shimSource]} { |
|
35
|
test_skip "the source tree has no tools/powerloss/powerloss.c" |
|
36
|
} |
|
37
|
set workDir [test_setup ""] |
|
38
|
set cc [expr {[info exists ::env(CC)] ? $::env(CC) : ""}] |
|
39
|
if {$cc eq ""} {set cc cc} |
|
40
|
set shim [file join $workDir powerloss.so] |
|
41
|
if {[catch {exec {*}$cc -shared -fPIC -o $shim $shimSource} err] && |
|
42
|
[catch {exec {*}$cc -shared -fPIC -o $shim $shimSource -ldl} err]} { |
|
43
|
test_skip "$cc cannot build tools/powerloss/powerloss.c: $err" |
|
44
|
} |
|
45
|
|
|
46
|
# Runs fossil with ARGS in directory DIR, with the NAME=VALUE settings of |
|
47
|
# the list ENV added to its environment, and returns a list of its exit |
|
48
|
# status and its output. A stopped command exits with status 77. |
|
49
|
# |
|
50
|
proc pl_exec {env dir args} { |
|
51
|
protOut [list fossil {*}$args] |
|
52
|
set saved [pwd] |
|
53
|
cd $dir |
|
54
|
set rc [catch { |
|
55
|
exec env {*}$env $::fossilexe {*}$args << "" 2>@1 |
|
56
|
} result options] |
|
57
|
cd $saved |
|
58
|
set status 0 |
|
59
|
if {$rc} { |
|
60
|
set status [lindex [dict get $options -errorcode] 2] |
|
61
|
} |
|
62
|
return [list $status [string trim $result]] |
|
63
|
} |
|
64
|
|
|
65
|
# Runs fossil without the power loss library, for set-up and checks. |
|
66
|
# |
|
67
|
proc pl_fossil {dir args} { |
|
68
|
return [pl_exec {} $dir {*}$args] |
|
69
|
} |
|
70
|
|
|
71
|
# Returns what fossil's sqlite3 command prints for SQL on database FILE, |
|
72
|
# which is the error message if the SQL fails. |
|
73
|
# |
|
74
|
proc pl_sql {file sql} { |
|
75
|
return [lindex [pl_fossil . sqlite3 --no-repository -list $file $sql] 1] |
|
76
|
} |
|
77
|
|
|
78
|
# Runs a fossil command that builds a template. A failure is an error. |
|
79
|
# |
|
80
|
proc pl_setup {dir args} { |
|
81
|
set r [pl_fossil $dir {*}$args] |
|
82
|
if {[lindex $r 0] != 0} { |
|
83
|
error "fossil $args: [lindex $r 1]" |
|
84
|
} |
|
85
|
} |
|
86
|
|
|
87
|
# Returns a list of two lines for repository REPO: the hashes, in order, |
|
88
|
# of its artifacts that are neither phantoms nor private, and of its |
|
89
|
# check-ins that are not private. |
|
90
|
# |
|
91
|
proc pl_content {repo} { |
|
92
|
return [split [pl_sql $repo "SELECT 'artifacts', group_concat(uuid, ' ')\ |
|
93
|
FROM (SELECT uuid FROM blob WHERE size>=0 AND rid NOT IN private\ |
|
94
|
ORDER BY uuid);\ |
|
95
|
SELECT 'check-ins', group_concat(uuid, ' ')\ |
|
96
|
FROM (SELECT uuid FROM blob JOIN event ON objid=rid\ |
|
97
|
WHERE type='ci' AND rid NOT IN private ORDER BY uuid)"] \n] |
|
98
|
} |
|
99
|
|
|
100
|
# SQL for the record ID of the latest check-in in a repository. |
|
101
|
# |
|
102
|
set plTipSql "SELECT objid FROM event WHERE type='ci'\ |
|
103
|
ORDER BY mtime DESC, objid DESC LIMIT 1" |
|
104
|
|
|
105
|
# Returns the record ID of the latest check-in in repository REPO. |
|
106
|
# |
|
107
|
proc pl_tip {repo} { |
|
108
|
return [pl_sql $repo $::plTipSql] |
|
109
|
} |
|
110
|
|
|
111
|
# Returns the number of parents of the latest check-in in repository REPO. |
|
112
|
# |
|
113
|
proc pl_tip_parents {repo} { |
|
114
|
return [pl_sql $repo "SELECT count(*) FROM plink WHERE cid=($::plTipSql)"] |
|
115
|
} |
|
116
|
|
|
117
|
# Returns the number of check-ins in repository REPO. |
|
118
|
# |
|
119
|
proc pl_checkins {repo} { |
|
120
|
return [pl_sql $repo "SELECT count(*) FROM event WHERE type='ci'"] |
|
121
|
} |
|
122
|
|
|
123
|
# Makes WORK/template/r.fossil, a repository in journal mode JOURNAL |
|
124
|
# with one check-in of a.txt, b.txt and c.txt, and its check-out |
|
125
|
# WORK/template/ck, and returns the check-out's directory. |
|
126
|
# |
|
127
|
proc pl_template_base {work journal} { |
|
128
|
set run [file join $work template] |
|
129
|
set ck [file join $run ck] |
|
130
|
file delete -force $run |
|
131
|
file mkdir $ck |
|
132
|
pl_setup $run new r.fossil |
|
133
|
if {$journal eq "wal"} { |
|
134
|
pl_setup $run rebuild --wal r.fossil |
|
135
|
} |
|
136
|
pl_setup $ck open ../r.fossil |
|
137
|
write_file [file join $ck a.txt] "one\ntwo\nthree\n" |
|
138
|
write_file [file join $ck b.txt] "bee\n" |
|
139
|
write_file [file join $ck c.txt] "sea\n" |
|
140
|
pl_setup $ck add a.txt b.txt c.txt |
|
141
|
pl_setup $ck commit -m one |
|
142
|
return $ck |
|
143
|
} |
|
144
|
|
|
145
|
# In the check-out, a.txt is edited, d.txt added, b.txt removed and |
|
146
|
# c.txt renamed to e.txt. |
|
147
|
# |
|
148
|
proc pl_template_commit {work journal} { |
|
149
|
set ck [pl_template_base $work $journal] |
|
150
|
write_file [file join $ck a.txt] "second version\n" |
|
151
|
write_file [file join $ck d.txt] "new\n" |
|
152
|
pl_setup $ck add d.txt |
|
153
|
pl_setup $ck rm b.txt |
|
154
|
pl_setup $ck mv --hard c.txt e.txt |
|
155
|
} |
|
156
|
|
|
157
|
# Branch "side" edits b.txt and adds f.txt, trunk edits a.txt, and the |
|
158
|
# check-out is of trunk. |
|
159
|
# |
|
160
|
proc pl_template_merge {work journal} { |
|
161
|
set ck [pl_template_base $work $journal] |
|
162
|
write_file [file join $ck b.txt] "side\n" |
|
163
|
write_file [file join $ck f.txt] "side file\n" |
|
164
|
pl_setup $ck add f.txt |
|
165
|
pl_setup $ck commit -m side --branch side |
|
166
|
pl_setup $ck update trunk |
|
167
|
write_file [file join $ck a.txt] "trunk\n" |
|
168
|
pl_setup $ck commit -m two |
|
169
|
} |
|
170
|
|
|
171
|
# The check-out of the merge template has merged "side". |
|
172
|
# |
|
173
|
proc pl_template_commit_merge {work journal} { |
|
174
|
pl_template_merge $work $journal |
|
175
|
pl_setup [file join $work template ck] merge side |
|
176
|
} |
|
177
|
|
|
178
|
# The merge of the commit_merge template is committed. |
|
179
|
# |
|
180
|
proc pl_template_merged {work journal} { |
|
181
|
pl_template_commit_merge $work $journal |
|
182
|
pl_setup [file join $work template ck] commit -m merged |
|
183
|
} |
|
184
|
|
|
185
|
# The merged template, made in an earlier second than the first run. |
|
186
|
# "fossil rebuild" writes the time in seconds to config rows, and SQLite |
|
187
|
# skips the page if the time is the same as when the template was made. |
|
188
|
# |
|
189
|
proc pl_template_rebuild {work journal} { |
|
190
|
pl_template_merged $work $journal |
|
191
|
set made [clock seconds] |
|
192
|
while {[clock seconds] == $made} {after 50} |
|
193
|
} |
|
194
|
|
|
195
|
# WORK/source.fossil, outside the files that the power loss library |
|
196
|
# tracks, is a copy of the repository with two more check-ins. |
|
197
|
# |
|
198
|
proc pl_template_pull {work journal} { |
|
199
|
pl_template_base $work $journal |
|
200
|
set source [file join $work source.fossil] |
|
201
|
file copy [file join $work template r.fossil] $source |
|
202
|
set ck [file join $work source-ck] |
|
203
|
file mkdir $ck |
|
204
|
pl_setup $ck open $source |
|
205
|
write_file [file join $ck a.txt] "pulled\n" |
|
206
|
pl_setup $ck commit -m pulled |
|
207
|
write_file [file join $ck g.txt] "new in source\n" |
|
208
|
pl_setup $ck add g.txt |
|
209
|
pl_setup $ck commit -m "add g.txt" |
|
210
|
pl_setup $ck close |
|
211
|
file delete -force $ck |
|
212
|
} |
|
213
|
|
|
214
|
# WORK/template/l.fossil is a clone of r.fossil in journal mode JOURNAL, |
|
215
|
# and the check-out is of l.fossil, with two check-ins that r.fossil |
|
216
|
# lacks. |
|
217
|
# |
|
218
|
proc pl_template_push {work journal} { |
|
219
|
set ck [pl_template_base $work $journal] |
|
220
|
set run [file join $work template] |
|
221
|
pl_setup $ck close |
|
222
|
file delete -force $ck |
|
223
|
file mkdir $ck |
|
224
|
pl_setup $run clone r.fossil l.fossil |
|
225
|
if {$journal eq "wal"} { |
|
226
|
pl_setup $run rebuild --wal l.fossil |
|
227
|
} |
|
228
|
pl_setup $ck open ../l.fossil |
|
229
|
pl_setup $ck settings autosync off |
|
230
|
write_file [file join $ck a.txt] "pushed\n" |
|
231
|
pl_setup $ck commit -m pushed |
|
232
|
write_file [file join $ck g.txt] "new in clone\n" |
|
233
|
pl_setup $ck add g.txt |
|
234
|
pl_setup $ck commit -m "add g.txt" |
|
235
|
} |
|
236
|
|
|
237
|
# The second check-in changes the first line of a.txt, adds d.txt, |
|
238
|
# removes b.txt and renames c.txt to e.txt. The check-out is at the |
|
239
|
# first check-in, and the user has added a line to a.txt. |
|
240
|
# |
|
241
|
proc pl_template_update {work journal} { |
|
242
|
set ck [pl_template_base $work $journal] |
|
243
|
write_file [file join $ck a.txt] "ONE TWO\ntwo\nthree\n" |
|
244
|
write_file [file join $ck d.txt] "new\n" |
|
245
|
pl_setup $ck add d.txt |
|
246
|
pl_setup $ck rm --hard b.txt |
|
247
|
pl_setup $ck mv --hard c.txt e.txt |
|
248
|
pl_setup $ck commit -m two |
|
249
|
pl_setup $ck update prev |
|
250
|
write_file [file join $ck a.txt] "one\ntwo\nthree\nlocal\n" |
|
251
|
} |
|
252
|
|
|
253
|
# The user has added a line to a.txt. |
|
254
|
# |
|
255
|
proc pl_template_edit {work journal} { |
|
256
|
set ck [pl_template_base $work $journal] |
|
257
|
write_file [file join $ck a.txt] "one\ntwo\nthree\nlocal\n" |
|
258
|
} |
|
259
|
|
|
260
|
# The user's edit to a.txt is in the stash. |
|
261
|
# |
|
262
|
proc pl_template_stash {work journal} { |
|
263
|
pl_template_edit $work $journal |
|
264
|
pl_setup [file join $work template ck] stash save -m local |
|
265
|
} |
|
266
|
|
|
267
|
# The user's edit to a.txt is reverted, and "fossil undo" can restore it. |
|
268
|
# |
|
269
|
proc pl_template_reverted {work journal} { |
|
270
|
pl_template_edit $work $journal |
|
271
|
pl_setup [file join $work template ck] revert |
|
272
|
} |
|
273
|
|
|
274
|
# The check-out directory is empty. |
|
275
|
# |
|
276
|
proc pl_template_open {work journal} { |
|
277
|
set ck [pl_template_base $work $journal] |
|
278
|
pl_setup $ck close |
|
279
|
file delete -force $ck |
|
280
|
file mkdir $ck |
|
281
|
} |
|
282
|
|
|
283
|
# WORK/source.fossil, outside the files that the power loss library |
|
284
|
# tracks, has the check-ins of the merged template and a private |
|
285
|
# check-in. WORK/template is empty. |
|
286
|
# |
|
287
|
proc pl_template_clone {work journal} { |
|
288
|
pl_template_merged $work $journal |
|
289
|
set ck [file join $work template ck] |
|
290
|
write_file [file join $ck a.txt] "secret\n" |
|
291
|
pl_setup $ck commit -m secret --branch hidden --private |
|
292
|
pl_setup $ck close |
|
293
|
file rename -force [file join $work template r.fossil] \ |
|
294
|
[file join $work source.fossil] |
|
295
|
file delete -force [file join $work template] |
|
296
|
file mkdir [file join $work template] |
|
297
|
} |
|
298
|
|
|
299
|
# Copies WORK/template to WORK/run and runs the fossil command CMD in |
|
300
|
# directory DIR of the copy. powerloss.so stops the command at stop |
|
301
|
# point AT, or never if AT is 0, in MODE, which is "power" or "kill". |
|
302
|
# Returns the stop points that powerloss.so logged, and sets ::plRun to |
|
303
|
# fossil's exit status and output. |
|
304
|
# |
|
305
|
proc pl_run {work dir cmd at mode} { |
|
306
|
set run [file join $work run] |
|
307
|
set log [file join $work log] |
|
308
|
file delete -force $run [file join $work shadow] $log |
|
309
|
file copy [file join $work template] $run |
|
310
|
set preload $::shim |
|
311
|
if {[info exists ::env(LD_PRELOAD)]} { |
|
312
|
append preload : $::env(LD_PRELOAD) |
|
313
|
} |
|
314
|
set ::plRun [pl_exec [list STOP_DIR=$work STOP_AT=$at STOP_MODE=$mode \ |
|
315
|
LD_PRELOAD=$preload] [file join $run $dir] {*}$cmd] |
|
316
|
if {![file exists $log]} {return {}} |
|
317
|
return [split [string trim [read_file $log]] \n] |
|
318
|
} |
|
319
|
|
|
320
|
# Checks that the last pl_run stopped where it was told to. STOPPED is |
|
321
|
# the stop points that run logged, AT is the stop point it was given, |
|
322
|
# and POINT is the log line for AT from the counting run. Returns |
|
323
|
# "stopped", or else what was seen. A run that does not stop would pass |
|
324
|
# every other check, because it leaves the files of a finished command. |
|
325
|
# |
|
326
|
# The stop point must be logged, and the process that logged it must not |
|
327
|
# have logged anything after it. In power mode the other processes must |
|
328
|
# not have logged anything after it either. |
|
329
|
# |
|
330
|
# When one process logged every stop point, the stop point must also be |
|
331
|
# the same call on the same file as in the counting run, and the command |
|
332
|
# must exit with status 77. SQLite gives a super-journal a random name, |
|
333
|
# which differs from run to run, so the end of such a name is not |
|
334
|
# compared. |
|
335
|
# |
|
336
|
# When several processes logged stop points, their order can differ from |
|
337
|
# one run to the next, and the process that stopped may be a child, whose |
|
338
|
# parent can still succeed: "fossil push" exits with status 0 when |
|
339
|
# "fossil http" is killed in its second transaction. So the call, the |
|
340
|
# file and the exit status are not compared. |
|
341
|
# |
|
342
|
proc pl_stop_seen {stopped at point mode} { |
|
343
|
set status [lindex $::plRun 0] |
|
344
|
set last [lindex $stopped [expr {$at-1}]] |
|
345
|
set later [lrange $stopped $at end] |
|
346
|
if {$mode eq "kill"} { |
|
347
|
set later [lsearch -all -inline -exact -index 3 $later [lindex $last 3]] |
|
348
|
} |
|
349
|
if {$last eq "" || [llength $later] > 0} { |
|
350
|
return "[llength $stopped] stop points logged, exit status $status" |
|
351
|
} |
|
352
|
if {[llength [lsort -unique [lmap line $stopped {lindex $line 3}]]] > 1} { |
|
353
|
return stopped |
|
354
|
} |
|
355
|
set seen [regsub -- {-mj[0-9A-F]+$} [lrange $last 1 2] -mj] |
|
356
|
set wanted [regsub -- {-mj[0-9A-F]+$} [lrange $point 1 2] -mj] |
|
357
|
if {$seen ne $wanted} { |
|
358
|
return "stop point $at was [lrange $last 1 2]" |
|
359
|
} |
|
360
|
if {$status != 77} { |
|
361
|
return "exit status $status" |
|
362
|
} |
|
363
|
return stopped |
|
364
|
} |
|
365
|
|
|
366
|
# Records the result of the check CHECK at the current stop point, |
|
367
|
# ::plPoint, of the run ::plName. pl_report reports each check once, |
|
368
|
# with the stop points where it failed. With "knownBug" in CONSTRAINTS, |
|
369
|
# a failure at this stop point is a known bug. ::plResults has two lists |
|
370
|
# for each check, the failures that are known bugs and those that are |
|
371
|
# not. A failure is its stop point and the expected and actual values. |
|
372
|
# |
|
373
|
proc pl_expect {check actual expected {constraints ""}} { |
|
374
|
set key $::plName-$check |
|
375
|
if {![dict exists $::plResults $key]} { |
|
376
|
dict set ::plResults $key {marked 0 failed {} known {}} |
|
377
|
} |
|
378
|
set kind failed |
|
379
|
if {"knownBug" in $constraints} { |
|
380
|
set kind known |
|
381
|
dict set ::plResults $key marked 1 |
|
382
|
} |
|
383
|
if {$actual ne $expected} { |
|
384
|
set failures [dict get $::plResults $key $kind] |
|
385
|
lappend failures [list $::plPoint $expected $actual] |
|
386
|
dict set ::plResults $key $kind $failures |
|
387
|
} |
|
388
|
} |
|
389
|
|
|
390
|
# Reports each check recorded since the last report as one test. The |
|
391
|
# test fails with the stop points where the check failed, and the |
|
392
|
# expected and actual values at the first of them. The failure is a |
|
393
|
# known bug if it is one at every stop point where the check failed. |
|
394
|
# |
|
395
|
proc pl_report {} { |
|
396
|
dict for {key result} $::plResults { |
|
397
|
set failures [dict get $result failed] |
|
398
|
set isKnown [expr {[dict get $result marked] && [llength $failures] == 0}] |
|
399
|
if {$isKnown} {set failures [dict get $result known]} |
|
400
|
set actual "" |
|
401
|
if {[llength $failures] > 0} { |
|
402
|
set points [lmap failure $failures {lindex $failure 0}] |
|
403
|
lassign [lindex $failures 0] at expected got |
|
404
|
set actual "stop points $points; at $at, expected \"$expected\",\ |
|
405
|
got \"$got\"" |
|
406
|
} |
|
407
|
test_eq $key $actual "" [expr {$isKnown ? "knownBug" : ""}] |
|
408
|
} |
|
409
|
set ::plResults [dict create] |
|
410
|
} |
|
411
|
set plResults [dict create] |
|
412
|
|
|
413
|
# Checks that the repository and check-out databases of WORK/run pass |
|
414
|
# PRAGMA integrity_check, that the check-out database does not record a |
|
415
|
# check-in missing from the repository, and that "fossil status" works. |
|
416
|
# Returns 1 when "fossil status" works. CONSTRAINTS apply to the check |
|
417
|
# that the check-out is not ahead of the repository, and to "fossil |
|
418
|
# status" where it is ahead. |
|
419
|
# |
|
420
|
proc pl_check_databases {work {constraints ""}} { |
|
421
|
set run [file join $work run] |
|
422
|
set ck [file join $run ck] |
|
423
|
set found [split [pl_sql [file join $run r.fossil] \ |
|
424
|
"ATTACH '[file join $ck .fslckout]' AS ck;\ |
|
425
|
SELECT count(*) FROM blob WHERE rid=\ |
|
426
|
(SELECT 0+value FROM ck.vvar WHERE name='checkout');\ |
|
427
|
PRAGMA main.integrity_check; PRAGMA ck.integrity_check"] \n] |
|
428
|
pl_expect integrity [lrange $found 1 end] {ok ok} |
|
429
|
set ahead [expr {[lindex $found 0] != 1}] |
|
430
|
pl_expect not-ahead [lindex $found 0] 1 $constraints |
|
431
|
set r [pl_fossil $ck status] |
|
432
|
pl_expect status [lindex $r 0] 0 [expr {$ahead ? $constraints : ""}] |
|
433
|
return [expr {[lindex $r 0] == 0}] |
|
434
|
} |
|
435
|
|
|
436
|
# Checks that repository REPO has the artifacts and check-ins of |
|
437
|
# repository WANTED. CONSTRAINTS apply to the check of the check-ins |
|
438
|
# where REPO has none. |
|
439
|
# |
|
440
|
proc pl_expect_artifacts {repo wanted {constraints ""}} { |
|
441
|
lassign [pl_content $repo] artifacts checkins |
|
442
|
lassign [pl_content $wanted] wantedArtifacts wantedCheckins |
|
443
|
if {$checkins ne "check-ins|"} {set constraints ""} |
|
444
|
pl_expect artifacts $artifacts $wantedArtifacts |
|
445
|
pl_expect checkins $checkins $wantedCheckins $constraints |
|
446
|
} |
|
447
|
|
|
448
|
# Returns "knownBug" for a WAL repository stopped by a power loss, which |
|
449
|
# is where a stopped commit can leave a check-out that cannot be used, and |
|
450
|
# "" otherwise. A power loss just after the check-out database commits |
|
451
|
# loses the repository's unsynced commit, which leaves the check-out |
|
452
|
# ahead of the repository. |
|
453
|
# |
|
454
|
proc pl_wal_commit_bug {} { |
|
455
|
set lost [expr {$::plJournal eq "wal" && $::plMode eq "power"}] |
|
456
|
return [expr {$lost ? "knownBug" : ""}] |
|
457
|
} |
|
458
|
|
|
459
|
# Finishes the check-in that a stopped commit was making, as the user |
|
460
|
# would: "fossil update", then "fossil commit" if changes are pending. |
|
461
|
# Returns the changes that were pending. |
|
462
|
# |
|
463
|
proc pl_finish_commit {ck} { |
|
464
|
pl_fossil $ck update |
|
465
|
set pending [lindex [pl_fossil $ck changes] 1] |
|
466
|
if {$pending ne ""} { |
|
467
|
pl_fossil $ck commit -m retry |
|
468
|
} |
|
469
|
return $pending |
|
470
|
} |
|
471
|
|
|
472
|
# The databases are usable, and once the user finishes the check-in, the |
|
473
|
# latest check-in has the files the user committed, and the repository |
|
474
|
# has one new check-in. |
|
475
|
# |
|
476
|
proc pl_check_commit {work} { |
|
477
|
set ck [file join $work run ck] |
|
478
|
if {![pl_check_databases $work [pl_wal_commit_bug]]} return |
|
479
|
pl_finish_commit $ck |
|
480
|
pl_expect checkin-count [pl_checkins [file join $work run r.fossil]] 3 |
|
481
|
pl_expect tip-files [lindex [pl_fossil $ck ls -r tip] 1] \ |
|
482
|
"a.txt\nd.txt\ne.txt" |
|
483
|
pl_expect content [lindex [pl_fossil $ck cat a.txt -r tip] 1] \ |
|
484
|
"second version" |
|
485
|
} |
|
486
|
|
|
487
|
# The same as pl_check_commit, and the check-in has both parents. |
|
488
|
# |
|
489
|
proc pl_check_commit_merge {work} { |
|
490
|
set ck [file join $work run ck] |
|
491
|
if {![pl_check_databases $work [pl_wal_commit_bug]]} return |
|
492
|
# Where the repository has the merge check-in and the check-out lacks |
|
493
|
# it, "fossil update" leaves the merge pending, and the next commit |
|
494
|
# checks in the same merge again. |
|
495
|
set remerged [regexp {^MERGED_WITH \S+$} [pl_finish_commit $ck]] |
|
496
|
pl_expect checkin-count [pl_checkins [file join $work run r.fossil]] 5 \ |
|
497
|
[expr {$remerged ? "knownBug" : ""}] |
|
498
|
pl_expect parents [pl_tip_parents [file join $work run r.fossil]] 2 |
|
499
|
pl_expect content \ |
|
500
|
[lindex [pl_fossil $ck cat a.txt -r tip] 1]/[lindex \ |
|
501
|
[pl_fossil $ck cat b.txt -r tip] 1] trunk/side |
|
502
|
} |
|
503
|
|
|
504
|
# Checks the files in check-out CK against the list EXPECTED. A command |
|
505
|
# that follows an interrupted one finds the files that the interrupted |
|
506
|
# command wrote, and backs each one up as NAME-original. That is a known |
|
507
|
# bug, which has its own check. |
|
508
|
# |
|
509
|
proc pl_expect_files {ck expected} { |
|
510
|
set files [lsort [glob -nocomplain -tails -directory $ck *]] |
|
511
|
pl_expect backups [lsearch -all -inline -glob $files *-original] {} knownBug |
|
512
|
pl_expect files [lsearch -all -inline -not -glob $files *-original] $expected |
|
513
|
} |
|
514
|
|
|
515
|
# The databases are usable, and after "fossil update" the check-out is at |
|
516
|
# the latest check-in, with the user's edit merged into a.txt. |
|
517
|
# |
|
518
|
proc pl_check_update {work} { |
|
519
|
set ck [file join $work run ck] |
|
520
|
if {![pl_check_databases $work]} return |
|
521
|
pl_expect update [lindex [pl_fossil $ck update] 0] 0 |
|
522
|
set rid [pl_sql [file join $ck .fslckout] \ |
|
523
|
"SELECT value FROM vvar WHERE name='checkout'"] |
|
524
|
pl_expect at-tip $rid [pl_tip [file join $work run r.fossil]] |
|
525
|
pl_expect_files $ck {a.txt d.txt e.txt} |
|
526
|
pl_expect content [read_file [file join $ck a.txt]] \ |
|
527
|
"ONE TWO\ntwo\nthree\nlocal\n" |
|
528
|
} |
|
529
|
|
|
530
|
# The databases are usable, and after "fossil merge" again if the merge |
|
531
|
# is not pending, the check-out has the merged files and nothing else, |
|
532
|
# and the commit has both parents. |
|
533
|
# |
|
534
|
proc pl_check_merge {work} { |
|
535
|
set ck [file join $work run ck] |
|
536
|
if {![pl_check_databases $work]} return |
|
537
|
set pending [pl_sql [file join $ck .fslckout] "SELECT count(*) FROM vmerge"] |
|
538
|
if {$pending == 0} { |
|
539
|
pl_expect merge [lindex [pl_fossil $ck merge side] 0] 0 |
|
540
|
} |
|
541
|
pl_expect_files $ck {a.txt b.txt c.txt f.txt} |
|
542
|
pl_expect content [read_file [file join $ck a.txt]]/[read_file \ |
|
543
|
[file join $ck b.txt]]/[read_file [file join $ck f.txt]] \ |
|
544
|
"trunk\n/side\n/side file\n" |
|
545
|
pl_fossil $ck commit -m merged |
|
546
|
pl_expect parents [pl_tip_parents [file join $work run r.fossil]] 2 |
|
547
|
} |
|
548
|
|
|
549
|
# The databases are usable, and after "fossil pull" again the repository |
|
550
|
# has the artifacts and check-ins of WORK/source.fossil. |
|
551
|
# |
|
552
|
proc pl_check_pull {work} { |
|
553
|
set ck [file join $work run ck] |
|
554
|
set repo [file join $work run r.fossil] |
|
555
|
set source [file join $work source.fossil] |
|
556
|
if {![pl_check_databases $work]} return |
|
557
|
pl_expect pull [lindex [pl_fossil $ck pull $source] 0] 0 |
|
558
|
pl_expect_artifacts $repo $source |
|
559
|
pl_fossil $ck update |
|
560
|
pl_expect content [read_file [file join $ck a.txt]] "pulled\n" |
|
561
|
} |
|
562
|
|
|
563
|
# Both repositories pass PRAGMA integrity_check, and after "fossil push" |
|
564
|
# again r.fossil has the artifacts and check-ins of l.fossil. |
|
565
|
# |
|
566
|
proc pl_check_push {work} { |
|
567
|
set ck [file join $work run ck] |
|
568
|
set remote [file join $work run r.fossil] |
|
569
|
set clone [file join $work run l.fossil] |
|
570
|
pl_expect integrity [pl_sql $remote "ATTACH '$clone' AS l;\ |
|
571
|
PRAGMA main.integrity_check; PRAGMA l.integrity_check"] "ok\nok" |
|
572
|
pl_expect push [lindex [pl_fossil $ck push ../r.fossil] 0] 0 |
|
573
|
pl_expect_artifacts $remote $clone |
|
574
|
} |
|
575
|
|
|
576
|
# For "stash save" and "stash pop": the user's edit is in a.txt or in |
|
577
|
# the stash, and is in a.txt after "fossil stash pop". |
|
578
|
# |
|
579
|
proc pl_check_stash {work} { |
|
580
|
set ck [file join $work run ck] |
|
581
|
if {![pl_check_databases $work]} return |
|
582
|
if {[lindex [pl_fossil $ck stash list] 1] ne "empty stash"} { |
|
583
|
pl_fossil $ck stash pop |
|
584
|
} |
|
585
|
pl_expect content [read_file [file join $ck a.txt]] \ |
|
586
|
"one\ntwo\nthree\nlocal\n" |
|
587
|
} |
|
588
|
|
|
589
|
# Returns the content of FILE, or "" if it does not exist. |
|
590
|
# |
|
591
|
proc pl_read {file} { |
|
592
|
if {![file exists $file]} {return ""} |
|
593
|
return [read_file $file] |
|
594
|
} |
|
595
|
|
|
596
|
# Checks that the user's edit to a.txt is in the file, or that "fossil |
|
597
|
# undo" puts it back. CONSTRAINTS apply where a.txt is left with the |
|
598
|
# content of the check-in. |
|
599
|
# |
|
600
|
proc pl_check_edit_kept {ck {constraints ""}} { |
|
601
|
set edit "one\ntwo\nthree\nlocal\n" |
|
602
|
if {[pl_read [file join $ck a.txt]] ne $edit} { |
|
603
|
pl_fossil $ck undo |
|
604
|
} |
|
605
|
set found [pl_read [file join $ck a.txt]] |
|
606
|
if {$found ne "one\ntwo\nthree\n"} {set constraints ""} |
|
607
|
pl_expect edit $found $edit $constraints |
|
608
|
} |
|
609
|
|
|
610
|
# The databases are usable, and the edit is in a.txt or "fossil undo" |
|
611
|
# puts it back. |
|
612
|
# |
|
613
|
proc pl_check_revert {work} { |
|
614
|
if {![pl_check_databases $work]} return |
|
615
|
# A revert overwrites the files before it commits their undo |
|
616
|
# information, so an interrupted revert loses the user's edits. |
|
617
|
pl_check_edit_kept [file join $work run ck] knownBug |
|
618
|
} |
|
619
|
|
|
620
|
# The databases are usable, and the edit is in a.txt or "fossil undo" |
|
621
|
# again puts it back. |
|
622
|
# |
|
623
|
proc pl_check_undo {work} { |
|
624
|
if {![pl_check_databases $work]} return |
|
625
|
pl_check_edit_kept [file join $work run ck] |
|
626
|
} |
|
627
|
|
|
628
|
# The check-out database is missing or passes PRAGMA integrity_check, |
|
629
|
# and after "fossil open" again where "fossil status" fails, or "fossil |
|
630
|
# update" where it works, the check-out has every file of the check-in, |
|
631
|
# unchanged. |
|
632
|
# |
|
633
|
proc pl_check_open {work} { |
|
634
|
set ck [file join $work run ck] |
|
635
|
set ckout [file join $ck .fslckout] |
|
636
|
if {[file exists $ckout]} { |
|
637
|
pl_expect integrity [pl_sql $ckout {PRAGMA integrity_check}] ok |
|
638
|
} |
|
639
|
if {[lindex [pl_fossil $ck status] 0] == 0} { |
|
640
|
pl_fossil $ck update |
|
641
|
} else { |
|
642
|
# An open interrupted before it records the name of the repository |
|
643
|
# leaves a check-out database that every command rejects. |
|
644
|
lassign [pl_fossil $ck open ../r.fossil] status output |
|
645
|
set unnamed [string match "*unable to find the name of a repo*" $output] |
|
646
|
pl_expect open $status 0 [expr {$unnamed ? "knownBug" : ""}] |
|
647
|
if {$status != 0} return |
|
648
|
} |
|
649
|
pl_expect_files $ck {a.txt b.txt c.txt} |
|
650
|
pl_expect changes [pl_fossil $ck changes] {0 {}} |
|
651
|
pl_expect content [pl_read [file join $ck a.txt]] "one\ntwo\nthree\n" |
|
652
|
} |
|
653
|
|
|
654
|
# The databases are usable, and the repository has the same artifacts |
|
655
|
# and check-ins as before. |
|
656
|
# |
|
657
|
proc pl_check_rebuild {work} { |
|
658
|
set repo [file join $work run r.fossil] |
|
659
|
set original [file join $work template r.fossil] |
|
660
|
if {![pl_check_databases $work]} return |
|
661
|
pl_expect_artifacts $repo $original |
|
662
|
} |
|
663
|
|
|
664
|
# The new repository is missing, or fossil refuses to use it, or it has |
|
665
|
# every public artifact and check-in of the original and no private one. |
|
666
|
# An interrupted clone over a file: URL can leave the private content of |
|
667
|
# the original, and one over HTTP a repository without its check-ins. |
|
668
|
# |
|
669
|
proc pl_check_clone {work} { |
|
670
|
set clone [file join $work run c.fossil] |
|
671
|
set source [file join $work source.fossil] |
|
672
|
if {![file exists $clone] || |
|
673
|
[lindex [pl_fossil [file join $work run] info -R $clone] 0] != 0} { |
|
674
|
return |
|
675
|
} |
|
676
|
set found [split [pl_sql $clone "SELECT count(*) FROM private;\ |
|
677
|
PRAGMA integrity_check"] \n] |
|
678
|
pl_expect integrity [lrange $found 1 end] ok |
|
679
|
set http [expr {$::plTest eq "clone-http"}] |
|
680
|
pl_expect private [lindex $found 0] 0 [expr {$http ? "" : "knownBug"}] |
|
681
|
pl_expect_artifacts $clone $source [expr {$http ? "knownBug" : ""}] |
|
682
|
} |
|
683
|
|
|
684
|
# Runs TEST for a repository in journal mode JOURNAL, from the template |
|
685
|
# TEMPLATE, uninterrupted and then stopped at each stop point in each |
|
686
|
# mode, and reports each check of the procedure CHECK once for each mode. |
|
687
|
# The command CMD runs in directory DIR of the copy of the template. In |
|
688
|
# CMD, SOURCE stands for WORK/source.fossil and PORT for the port of a |
|
689
|
# server of it, which is started for a CMD that has PORT in it. |
|
690
|
# |
|
691
|
proc pl_test {test journal template dir check cmd} { |
|
692
|
set ::plTest $test |
|
693
|
set ::plJournal $journal |
|
694
|
set work [file join $::workDir $test-$journal] |
|
695
|
file mkdir $work |
|
696
|
pl_template_$template $work $journal |
|
697
|
set source [file join $work source.fossil] |
|
698
|
set port "" |
|
699
|
set server "" |
|
700
|
if {[string match *PORT* $cmd]} { |
|
701
|
set server [test_start_server $source stopArg] |
|
702
|
set port [lindex $server 1] |
|
703
|
} |
|
704
|
try { |
|
705
|
set cmd [lmap a $cmd {string map [list SOURCE $source PORT $port] $a}] |
|
706
|
foreach mode {power kill} { |
|
707
|
set ::plMode $mode |
|
708
|
set ::plName powerloss-$test-$journal-$mode |
|
709
|
set points [pl_run $work $dir $cmd 0 $mode] |
|
710
|
test $::plName-points {[llength $points] > 0} |
|
711
|
set ::plPoint none |
|
712
|
$check $work |
|
713
|
foreach point $points { |
|
714
|
set at [lindex $point 0] |
|
715
|
set stopped [pl_run $work $dir $cmd $at $mode] |
|
716
|
protOut "$test stop point $at: [lrange $point 1 end]" |
|
717
|
set ::plPoint $at |
|
718
|
pl_expect stopped [pl_stop_seen $stopped $at $point $mode] stopped |
|
719
|
$check $work |
|
720
|
} |
|
721
|
pl_report |
|
722
|
} |
|
723
|
} finally { |
|
724
|
if {$server ne ""} { |
|
725
|
test_stop_server $stopArg [lindex $server 0] [lindex $server 2] |
|
726
|
} |
|
727
|
file delete -force $work |
|
728
|
} |
|
729
|
} |
|
730
|
|
|
731
|
# A fossil that is statically linked does not load the library. |
|
732
|
file mkdir [file join $workDir probe template] |
|
733
|
if {[pl_run [file join $workDir probe] . {new r.fossil} 0 power] eq ""} { |
|
734
|
test_skip "LD_PRELOAD of powerloss.so has no effect on fossil,\ |
|
735
|
which may be statically linked" |
|
736
|
} |
|
737
|
|
|
738
|
set env(FOSSIL_USER) tester |
|
739
|
# Each row is a test, its template, the directory the command runs in, its |
|
740
|
# check procedure, the journal modes it runs for, and the command. The |
|
741
|
# check procedures mark the known bugs. |
|
742
|
# |
|
743
|
foreach {test template dir check journals cmd} { |
|
744
|
commit commit ck pl_check_commit {delete wal} |
|
745
|
{commit -m two} |
|
746
|
commit-merge commit_merge ck pl_check_commit_merge {delete wal} |
|
747
|
{commit -m merged} |
|
748
|
merge merge ck pl_check_merge {delete wal} |
|
749
|
{merge side} |
|
750
|
update update ck pl_check_update {delete wal} |
|
751
|
{update} |
|
752
|
stash-save edit ck pl_check_stash {delete wal} |
|
753
|
{stash save -m local} |
|
754
|
stash-pop stash ck pl_check_stash {delete wal} |
|
755
|
{stash pop} |
|
756
|
revert edit ck pl_check_revert {delete wal} |
|
757
|
{revert} |
|
758
|
undo reverted ck pl_check_undo {delete wal} |
|
759
|
{undo} |
|
760
|
open open ck pl_check_open {delete wal} |
|
761
|
{open ../r.fossil} |
|
762
|
rebuild rebuild ck pl_check_rebuild {delete wal} |
|
763
|
{rebuild} |
|
764
|
pull pull ck pl_check_pull {delete wal} |
|
765
|
{pull SOURCE} |
|
766
|
push push ck pl_check_push {delete wal} |
|
767
|
{push ../r.fossil} |
|
768
|
clone-file clone . pl_check_clone delete |
|
769
|
{clone SOURCE c.fossil} |
|
770
|
clone-http clone . pl_check_clone delete |
|
771
|
{clone --proxy off http://127.0.0.1:PORT/ c.fossil} |
|
772
|
} { |
|
773
|
if {[string match *PORT* $cmd] && ![loopback_available]} { |
|
774
|
test_skip_part "powerloss-$test needs a loopback interface" |
|
775
|
continue |
|
776
|
} |
|
777
|
foreach journal $journals { |
|
778
|
pl_test $test $journal $template $dir $check $cmd |
|
779
|
} |
|
780
|
} |
|
781
|
unset env(FOSSIL_USER) |
|
782
|
|
|
783
|
test_cleanup |
|
784
|
|