Raw
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Jon Seymour
4 #
5 test_description='Tests git rev-list --bisect functionality'
6
7 . ./test-lib.sh
8 . "$TEST_DIRECTORY"/lib-t6000.sh # t6xxx specific functions
9
10 # usage: test_bisection max-diff bisect-option head ^prune...
11 #
12 # e.g. test_bisection 1 --bisect l1 ^l0
13 #
14 test_bisection_diff()
15 {
16 _max_diff=$1
17 _bisect_option=$2
18 shift 2
19 _bisection=$(git rev-list $_bisect_option "$@")
20 _list_size=$(git rev-list "$@" | wc -l)
21 _head=$1
22 shift 1
23 _bisection_size=$(git rev-list $_bisection "$@" | wc -l)
24 [ -n "$_list_size" -a -n "$_bisection_size" ] ||
25 error "test_bisection_diff failed"
26
27 # Test if bisection size is close to half of list size within
28 # tolerance.
29 #
30 _bisect_err=$(($_list_size - $_bisection_size * 2))
31 if test "$_bisect_err" -lt 0
32 then
33 _bisect_err=$((0 - $_bisect_err))
34 fi
35 _bisect_err=$(($_bisect_err / 2)) ; # floor
36
37 test_expect_success "bisection diff $_bisect_option $_head $* <= $_max_diff" '
38 test $_bisect_err -le $_max_diff
39 '
40 }
41
42 date >path0
43 git update-index --add path0
44 save_tag tree git write-tree
45 on_committer_date "00:00" hide_error save_tag root unique_commit root tree
46 on_committer_date "00:01" save_tag l0 unique_commit l0 tree -p root
47 on_committer_date "00:02" save_tag l1 unique_commit l1 tree -p l0
48 on_committer_date "00:03" save_tag l2 unique_commit l2 tree -p l1
49 on_committer_date "00:04" save_tag a0 unique_commit a0 tree -p l2
50 on_committer_date "00:05" save_tag a1 unique_commit a1 tree -p a0
51 on_committer_date "00:06" save_tag b1 unique_commit b1 tree -p a0
52 on_committer_date "00:07" save_tag c1 unique_commit c1 tree -p b1
53 on_committer_date "00:08" save_tag b2 unique_commit b2 tree -p b1
54 on_committer_date "00:09" save_tag b3 unique_commit b2 tree -p b2
55 on_committer_date "00:10" save_tag c2 unique_commit c2 tree -p c1 -p b2
56 on_committer_date "00:11" save_tag c3 unique_commit c3 tree -p c2
57 on_committer_date "00:12" save_tag a2 unique_commit a2 tree -p a1
58 on_committer_date "00:13" save_tag a3 unique_commit a3 tree -p a2
59 on_committer_date "00:14" save_tag b4 unique_commit b4 tree -p b3 -p a3
60 on_committer_date "00:15" save_tag a4 unique_commit a4 tree -p a3 -p b4 -p c3
61 on_committer_date "00:16" save_tag l3 unique_commit l3 tree -p a4
62 on_committer_date "00:17" save_tag l4 unique_commit l4 tree -p l3
63 on_committer_date "00:18" save_tag l5 unique_commit l5 tree -p l4
64 git update-ref HEAD $(tag l5)
65
66
67 # E
68 # / \
69 # e1 |
70 # | |
71 # e2 |
72 # | |
73 # e3 |
74 # | |
75 # e4 |
76 # | |
77 # | f1
78 # | |
79 # | f2
80 # | |
81 # | f3
82 # | |
83 # | f4
84 # | |
85 # e5 |
86 # | |
87 # e6 |
88 # | |
89 # e7 |
90 # | |
91 # e8 |
92 # \ /
93 # F
94
95
96 on_committer_date "00:00" hide_error save_tag F unique_commit F tree
97 on_committer_date "00:01" save_tag e8 unique_commit e8 tree -p F
98 on_committer_date "00:02" save_tag e7 unique_commit e7 tree -p e8
99 on_committer_date "00:03" save_tag e6 unique_commit e6 tree -p e7
100 on_committer_date "00:04" save_tag e5 unique_commit e5 tree -p e6
101 on_committer_date "00:05" save_tag f4 unique_commit f4 tree -p F
102 on_committer_date "00:06" save_tag f3 unique_commit f3 tree -p f4
103 on_committer_date "00:07" save_tag f2 unique_commit f2 tree -p f3
104 on_committer_date "00:08" save_tag f1 unique_commit f1 tree -p f2
105 on_committer_date "00:09" save_tag e4 unique_commit e4 tree -p e5
106 on_committer_date "00:10" save_tag e3 unique_commit e3 tree -p e4
107 on_committer_date "00:11" save_tag e2 unique_commit e2 tree -p e3
108 on_committer_date "00:12" save_tag e1 unique_commit e1 tree -p e2
109 on_committer_date "00:13" save_tag E unique_commit E tree -p e1 -p f1
110
111 on_committer_date "00:00" hide_error save_tag U unique_commit U tree
112 on_committer_date "00:01" save_tag u0 unique_commit u0 tree -p U
113 on_committer_date "00:01" save_tag u1 unique_commit u1 tree -p u0
114 on_committer_date "00:02" save_tag u2 unique_commit u2 tree -p u0
115 on_committer_date "00:03" save_tag u3 unique_commit u3 tree -p u0
116 on_committer_date "00:04" save_tag u4 unique_commit u4 tree -p u0
117 on_committer_date "00:05" save_tag u5 unique_commit u5 tree -p u0
118 on_committer_date "00:06" save_tag V unique_commit V tree -p u1 -p u2 -p u3 -p u4 -p u5
119
120 test_sequence()
121 {
122 _bisect_option=$1
123
124 test_bisection_diff 0 $_bisect_option l0 ^root
125 test_bisection_diff 0 $_bisect_option l1 ^root
126 test_bisection_diff 0 $_bisect_option l2 ^root
127 test_bisection_diff 0 $_bisect_option a0 ^root
128 test_bisection_diff 0 $_bisect_option a1 ^root
129 test_bisection_diff 0 $_bisect_option a2 ^root
130 test_bisection_diff 0 $_bisect_option a3 ^root
131 test_bisection_diff 0 $_bisect_option b1 ^root
132 test_bisection_diff 0 $_bisect_option b2 ^root
133 test_bisection_diff 0 $_bisect_option b3 ^root
134 test_bisection_diff 0 $_bisect_option c1 ^root
135 test_bisection_diff 0 $_bisect_option c2 ^root
136 test_bisection_diff 0 $_bisect_option c3 ^root
137 test_bisection_diff 0 $_bisect_option E ^F
138 test_bisection_diff 0 $_bisect_option e1 ^F
139 test_bisection_diff 0 $_bisect_option e2 ^F
140 test_bisection_diff 0 $_bisect_option e3 ^F
141 test_bisection_diff 0 $_bisect_option e4 ^F
142 test_bisection_diff 0 $_bisect_option e5 ^F
143 test_bisection_diff 0 $_bisect_option e6 ^F
144 test_bisection_diff 0 $_bisect_option e7 ^F
145 test_bisection_diff 0 $_bisect_option f1 ^F
146 test_bisection_diff 0 $_bisect_option f2 ^F
147 test_bisection_diff 0 $_bisect_option f3 ^F
148 test_bisection_diff 0 $_bisect_option f4 ^F
149 test_bisection_diff 0 $_bisect_option E ^F
150
151 test_bisection_diff 1 $_bisect_option V ^U
152 test_bisection_diff 0 $_bisect_option V ^U ^u1 ^u2 ^u3
153 test_bisection_diff 0 $_bisect_option u1 ^U
154 test_bisection_diff 0 $_bisect_option u2 ^U
155 test_bisection_diff 0 $_bisect_option u3 ^U
156 test_bisection_diff 0 $_bisect_option u4 ^U
157 test_bisection_diff 0 $_bisect_option u5 ^U
158
159 #
160 # the following illustrates Linus' binary bug blatt idea.
161 #
162 # assume the bug is actually at l3, but you don't know that - all you know is that l3 is broken
163 # and it wasn't broken before
164 #
165 # keep bisecting the list, advancing the "bad" head and accumulating "good" heads until
166 # the bisection point is the head - this is the bad point.
167 #
168
169 test_output_expect_success "$_bisect_option l5 ^root" 'git rev-list $_bisect_option l5 ^root' <<EOF
170 c3
171 EOF
172
173 test_output_expect_success "$_bisect_option l5 ^root ^c3" 'git rev-list $_bisect_option l5 ^root ^c3' <<EOF
174 b4
175 EOF
176
177 test_output_expect_success "$_bisect_option l5 ^root ^c3 ^b4" 'git rev-list $_bisect_option l5 ^c3 ^b4' <<EOF
178 l3
179 EOF
180
181 test_output_expect_success "$_bisect_option l3 ^root ^c3 ^b4" 'git rev-list $_bisect_option l3 ^root ^c3 ^b4' <<EOF
182 a4
183 EOF
184
185 test_output_expect_success "$_bisect_option l5 ^b3 ^a3 ^b4 ^a4" 'git rev-list $_bisect_option l3 ^b3 ^a3 ^a4' <<EOF
186 l3
187 EOF
188
189 #
190 # if l3 is bad, then l4 is bad too - so advance the bad pointer by making b4 the known bad head
191 #
192
193 test_output_expect_success "$_bisect_option l4 ^a2 ^a3 ^b ^a4" 'git rev-list $_bisect_option l4 ^a2 ^a3 ^a4' <<EOF
194 l3
195 EOF
196
197 test_output_expect_success "$_bisect_option l3 ^a2 ^a3 ^b ^a4" 'git rev-list $_bisect_option l3 ^a2 ^a3 ^a4' <<EOF
198 l3
199 EOF
200
201 # found!
202
203 #
204 # as another example, let's consider a4 to be the bad head, in which case
205 #
206
207 test_output_expect_success "$_bisect_option a4 ^a2 ^a3 ^b4" 'git rev-list $_bisect_option a4 ^a2 ^a3 ^b4' <<EOF
208 c2
209 EOF
210
211 test_output_expect_success "$_bisect_option a4 ^a2 ^a3 ^b4 ^c2" 'git rev-list $_bisect_option a4 ^a2 ^a3 ^b4 ^c2' <<EOF
212 c3
213 EOF
214
215 test_output_expect_success "$_bisect_option a4 ^a2 ^a3 ^b4 ^c2 ^c3" 'git rev-list $_bisect_option a4 ^a2 ^a3 ^b4 ^c2 ^c3' <<EOF
216 a4
217 EOF
218
219 # found!
220
221 #
222 # or consider c3 to be the bad head
223 #
224
225 test_output_expect_success "$_bisect_option a4 ^a2 ^a3 ^b4" 'git rev-list $_bisect_option a4 ^a2 ^a3 ^b4' <<EOF
226 c2
227 EOF
228
229 test_output_expect_success "$_bisect_option c3 ^a2 ^a3 ^b4 ^c2" 'git rev-list $_bisect_option c3 ^a2 ^a3 ^b4 ^c2' <<EOF
230 c3
231 EOF
232
233 # found!
234
235 }
236
237 test_sequence "--bisect"
238
239 #
240 #
241
242 test_expect_success 'set up fake --bisect refs' '
243 git update-ref refs/bisect/bad c3 &&
244 good=$(git rev-parse b1) &&
245 git update-ref refs/bisect/good-$good $good &&
246 good=$(git rev-parse c1) &&
247 git update-ref refs/bisect/good-$good $good
248 '
249
250 test_expect_success 'rev-list --bisect can default to good/bad refs' '
251 # the only thing between c3 and c1 is c2
252 git rev-parse c2 >expect &&
253 git rev-list --bisect >actual &&
254 test_cmp expect actual
255 '
256
257 test_expect_success 'rev-parse --bisect can default to good/bad refs' '
258 git rev-parse c3 ^b1 ^c1 >expect &&
259 git rev-parse --bisect >actual &&
260
261 # output order depends on the refnames, which in turn depends on
262 # the exact sha1s. We just want to make sure we have the same set
263 # of lines in any order.
264 sort <expect >expect.sorted &&
265 sort <actual >actual.sorted &&
266 test_cmp expect.sorted actual.sorted
267 '
268
269 test_output_expect_success '--bisect --first-parent' 'git rev-list --bisect --first-parent E ^F' <<EOF
270 e4
271 EOF
272
273 test_output_expect_success '--first-parent' 'git rev-list --first-parent E ^F' <<EOF
274 E
275 e1
276 e2
277 e3
278 e4
279 e5
280 e6
281 e7
282 e8
283 EOF
284
285 test_output_expect_success '--bisect-vars --first-parent' 'git rev-list --bisect-vars --first-parent E ^F' <<EOF
286 bisect_rev='e5'
287 bisect_nr=4
288 bisect_good=4
289 bisect_bad=3
290 bisect_all=9
291 bisect_steps=2
292 EOF
293
294 test_expect_success '--bisect-all --first-parent' '
295 cat >expect.unsorted <<-EOF &&
296 $(git rev-parse E) (tag: E, dist=0)
297 $(git rev-parse e1) (tag: e1, dist=1)
298 $(git rev-parse e2) (tag: e2, dist=2)
299 $(git rev-parse e3) (tag: e3, dist=3)
300 $(git rev-parse e4) (tag: e4, dist=4)
301 $(git rev-parse e5) (tag: e5, dist=4)
302 $(git rev-parse e6) (tag: e6, dist=3)
303 $(git rev-parse e7) (tag: e7, dist=2)
304 $(git rev-parse e8) (tag: e8, dist=1)
305 EOF
306
307 # expect results to be ordered by distance (descending),
308 # commit hash (ascending)
309 sort -k4,4r -k1,1 expect.unsorted >expect &&
310 git rev-list --bisect-all --first-parent E ^F >actual &&
311 test_cmp expect actual
312 '
313
314 test_expect_success '--bisect without any revisions' '
315 git rev-list --bisect HEAD..HEAD >out &&
316 test_must_be_empty out
317 '
318
319 test_done