]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0500-progress-display.sh
The second batch
[thirdparty/git.git] / t / t0500-progress-display.sh
CommitLineData
2bb74b53
SG
1#!/bin/sh
2
3test_description='progress display'
4
8266e0c0 5TEST_PASSES_SANITIZE_LEAK=true
2bb74b53
SG
6. ./test-lib.sh
7
8show_cr () {
9 tr '\015' Q | sed -e "s/Q/<CR>\\$LF/g"
10}
11
12test_expect_success 'simple progress display' '
13 cat >expect <<-\EOF &&
14 Working hard: 1<CR>
15 Working hard: 2<CR>
16 Working hard: 5<CR>
17 Working hard: 5, done.
18 EOF
19
20 cat >in <<-\EOF &&
791afae2 21 start 0
2bb74b53
SG
22 update
23 progress 1
24 update
25 progress 2
26 progress 3
27 progress 4
28 update
29 progress 5
791afae2 30 stop
2bb74b53 31 EOF
791afae2 32 test-tool progress <in 2>stderr &&
2bb74b53
SG
33
34 show_cr <stderr >out &&
1108cea7 35 test_cmp expect out
2bb74b53
SG
36'
37
38test_expect_success 'progress display with total' '
39 cat >expect <<-\EOF &&
40 Working hard: 33% (1/3)<CR>
41 Working hard: 66% (2/3)<CR>
42 Working hard: 100% (3/3)<CR>
43 Working hard: 100% (3/3), done.
44 EOF
45
46 cat >in <<-\EOF &&
791afae2 47 start 3
2bb74b53
SG
48 progress 1
49 progress 2
50 progress 3
791afae2 51 stop
2bb74b53 52 EOF
791afae2 53 test-tool progress <in 2>stderr &&
2bb74b53
SG
54
55 show_cr <stderr >out &&
1108cea7 56 test_cmp expect out
2bb74b53
SG
57'
58
59test_expect_success 'progress display breaks long lines #1' '
60 sed -e "s/Z$//" >expect <<\EOF &&
61Working hard.......2.........3.........4.........5.........6: 0% (100/100000)<CR>
62Working hard.......2.........3.........4.........5.........6: 1% (1000/100000)<CR>
63Working hard.......2.........3.........4.........5.........6: Z
64 10% (10000/100000)<CR>
65 100% (100000/100000)<CR>
66 100% (100000/100000), done.
67EOF
68
69 cat >in <<-\EOF &&
791afae2 70 start 100000 Working hard.......2.........3.........4.........5.........6
2bb74b53
SG
71 progress 100
72 progress 1000
73 progress 10000
74 progress 100000
791afae2 75 stop
2bb74b53 76 EOF
791afae2 77 test-tool progress <in 2>stderr &&
2bb74b53
SG
78
79 show_cr <stderr >out &&
1108cea7 80 test_cmp expect out
2bb74b53
SG
81'
82
83test_expect_success 'progress display breaks long lines #2' '
7a40cf15 84 # Note: we do not need that many spaces after the title to cover up
2bb74b53
SG
85 # the last line before breaking the progress line.
86 sed -e "s/Z$//" >expect <<\EOF &&
87Working hard.......2.........3.........4.........5.........6: 0% (1/100000)<CR>
88Working hard.......2.........3.........4.........5.........6: 0% (2/100000)<CR>
89Working hard.......2.........3.........4.........5.........6: Z
90 10% (10000/100000)<CR>
91 100% (100000/100000)<CR>
92 100% (100000/100000), done.
93EOF
94
95 cat >in <<-\EOF &&
791afae2 96 start 100000 Working hard.......2.........3.........4.........5.........6
2bb74b53
SG
97 update
98 progress 1
99 update
100 progress 2
101 progress 10000
102 progress 100000
791afae2 103 stop
2bb74b53 104 EOF
791afae2 105 test-tool progress <in 2>stderr &&
2bb74b53
SG
106
107 show_cr <stderr >out &&
1108cea7 108 test_cmp expect out
2bb74b53
SG
109'
110
111test_expect_success 'progress display breaks long lines #3 - even the first is too long' '
7a40cf15 112 # Note: we do not actually need any spaces at the end of the title
2bb74b53
SG
113 # line, because there is no previous progress line to cover up.
114 sed -e "s/Z$//" >expect <<\EOF &&
115Working hard.......2.........3.........4.........5.........6: Z
116 25% (25000/100000)<CR>
117 50% (50000/100000)<CR>
118 75% (75000/100000)<CR>
119 100% (100000/100000)<CR>
120 100% (100000/100000), done.
121EOF
122
123 cat >in <<-\EOF &&
791afae2 124 start 100000 Working hard.......2.........3.........4.........5.........6
2bb74b53
SG
125 progress 25000
126 progress 50000
127 progress 75000
128 progress 100000
791afae2 129 stop
2bb74b53 130 EOF
791afae2 131 test-tool progress <in 2>stderr &&
2bb74b53
SG
132
133 show_cr <stderr >out &&
1108cea7 134 test_cmp expect out
2bb74b53
SG
135'
136
137test_expect_success 'progress display breaks long lines #4 - title line matches terminal width' '
138 cat >expect <<\EOF &&
139Working hard.......2.........3.........4.........5.........6.........7.........:
140 25% (25000/100000)<CR>
141 50% (50000/100000)<CR>
142 75% (75000/100000)<CR>
143 100% (100000/100000)<CR>
144 100% (100000/100000), done.
145EOF
146
147 cat >in <<-\EOF &&
791afae2 148 start 100000 Working hard.......2.........3.........4.........5.........6.........7.........
2bb74b53
SG
149 progress 25000
150 progress 50000
151 progress 75000
152 progress 100000
791afae2 153 stop
2bb74b53 154 EOF
791afae2 155 test-tool progress <in 2>stderr &&
2bb74b53
SG
156
157 show_cr <stderr >out &&
1108cea7 158 test_cmp expect out
2bb74b53
SG
159'
160
161# Progress counter goes backwards, this should not happen in practice.
162test_expect_success 'progress shortens - crazy caller' '
163 cat >expect <<-\EOF &&
164 Working hard: 10% (100/1000)<CR>
165 Working hard: 20% (200/1000)<CR>
166 Working hard: 0% (1/1000) <CR>
167 Working hard: 100% (1000/1000)<CR>
168 Working hard: 100% (1000/1000), done.
169 EOF
170
171 cat >in <<-\EOF &&
791afae2 172 start 1000
2bb74b53
SG
173 progress 100
174 progress 200
175 progress 1
176 progress 1000
791afae2 177 stop
2bb74b53 178 EOF
791afae2 179 test-tool progress <in 2>stderr &&
2bb74b53
SG
180
181 show_cr <stderr >out &&
1108cea7 182 test_cmp expect out
2bb74b53
SG
183'
184
185test_expect_success 'progress display with throughput' '
186 cat >expect <<-\EOF &&
187 Working hard: 10<CR>
188 Working hard: 20, 200.00 KiB | 100.00 KiB/s<CR>
189 Working hard: 30, 300.00 KiB | 100.00 KiB/s<CR>
190 Working hard: 40, 400.00 KiB | 100.00 KiB/s<CR>
191 Working hard: 40, 400.00 KiB | 100.00 KiB/s, done.
192 EOF
193
194 cat >in <<-\EOF &&
791afae2 195 start 0
2bb74b53
SG
196 throughput 102400 1000
197 update
198 progress 10
199 throughput 204800 2000
200 update
201 progress 20
202 throughput 307200 3000
203 update
204 progress 30
205 throughput 409600 4000
206 update
207 progress 40
791afae2 208 stop
2bb74b53 209 EOF
791afae2 210 test-tool progress <in 2>stderr &&
2bb74b53
SG
211
212 show_cr <stderr >out &&
1108cea7 213 test_cmp expect out
2bb74b53
SG
214'
215
216test_expect_success 'progress display with throughput and total' '
217 cat >expect <<-\EOF &&
218 Working hard: 25% (10/40)<CR>
219 Working hard: 50% (20/40), 200.00 KiB | 100.00 KiB/s<CR>
220 Working hard: 75% (30/40), 300.00 KiB | 100.00 KiB/s<CR>
221 Working hard: 100% (40/40), 400.00 KiB | 100.00 KiB/s<CR>
222 Working hard: 100% (40/40), 400.00 KiB | 100.00 KiB/s, done.
223 EOF
224
225 cat >in <<-\EOF &&
791afae2 226 start 40
2bb74b53
SG
227 throughput 102400 1000
228 progress 10
229 throughput 204800 2000
230 progress 20
231 throughput 307200 3000
232 progress 30
233 throughput 409600 4000
234 progress 40
791afae2 235 stop
2bb74b53 236 EOF
791afae2 237 test-tool progress <in 2>stderr &&
2bb74b53
SG
238
239 show_cr <stderr >out &&
1108cea7 240 test_cmp expect out
2bb74b53
SG
241'
242
243test_expect_success 'cover up after throughput shortens' '
244 cat >expect <<-\EOF &&
245 Working hard: 1<CR>
246 Working hard: 2, 800.00 KiB | 400.00 KiB/s<CR>
247 Working hard: 3, 1.17 MiB | 400.00 KiB/s <CR>
248 Working hard: 4, 1.56 MiB | 400.00 KiB/s<CR>
249 Working hard: 4, 1.56 MiB | 400.00 KiB/s, done.
250 EOF
251
252 cat >in <<-\EOF &&
791afae2 253 start 0
2bb74b53
SG
254 throughput 409600 1000
255 update
256 progress 1
257 throughput 819200 2000
258 update
259 progress 2
260 throughput 1228800 3000
261 update
262 progress 3
263 throughput 1638400 4000
264 update
265 progress 4
791afae2 266 stop
2bb74b53 267 EOF
791afae2 268 test-tool progress <in 2>stderr &&
2bb74b53
SG
269
270 show_cr <stderr >out &&
1108cea7 271 test_cmp expect out
2bb74b53
SG
272'
273
274test_expect_success 'cover up after throughput shortens a lot' '
275 cat >expect <<-\EOF &&
276 Working hard: 1<CR>
277 Working hard: 2, 1000.00 KiB | 1000.00 KiB/s<CR>
278 Working hard: 3, 3.00 MiB | 1.50 MiB/s <CR>
279 Working hard: 3, 3.00 MiB | 1024.00 KiB/s, done.
280 EOF
281
282 cat >in <<-\EOF &&
791afae2 283 start 0
2bb74b53
SG
284 throughput 1 1000
285 update
286 progress 1
287 throughput 1024000 2000
288 update
289 progress 2
290 throughput 3145728 3000
291 update
292 progress 3
791afae2 293 stop
2bb74b53 294 EOF
791afae2 295 test-tool progress <in 2>stderr &&
2bb74b53
SG
296
297 show_cr <stderr >out &&
1108cea7 298 test_cmp expect out
2bb74b53
SG
299'
300
98a13647
ES
301test_expect_success 'progress generates traces' '
302 cat >in <<-\EOF &&
791afae2 303 start 40
98a13647
ES
304 throughput 102400 1000
305 update
306 progress 10
307 throughput 204800 2000
308 update
309 progress 20
310 throughput 307200 3000
311 update
312 progress 30
313 throughput 409600 4000
314 update
315 progress 40
791afae2 316 stop
98a13647
ES
317 EOF
318
791afae2
ÆAB
319 GIT_TRACE2_EVENT="$(pwd)/trace.event" test-tool progress \
320 <in 2>stderr &&
98a13647
ES
321
322 # t0212/parse_events.perl intentionally omits regions and data.
3b144363 323 test_region progress "Working hard" trace.event &&
98a13647
ES
324 grep "\"key\":\"total_objects\",\"value\":\"40\"" trace.event &&
325 grep "\"key\":\"total_bytes\",\"value\":\"409600\"" trace.event
326'
327
bbfb1c24
ÆAB
328test_expect_success 'progress generates traces: stop / start' '
329 cat >in <<-\EOF &&
330 start 0
331 stop
332 EOF
333
334 GIT_TRACE2_EVENT="$PWD/trace-startstop.event" test-tool progress \
335 <in 2>stderr &&
336 test_region progress "Working hard" trace-startstop.event
337'
338
339test_expect_success 'progress generates traces: start without stop' '
340 cat >in <<-\EOF &&
341 start 0
342 EOF
343
344 GIT_TRACE2_EVENT="$PWD/trace-start.event" \
345 LSAN_OPTIONS=detect_leaks=0 \
346 test-tool progress \
347 <in 2>stderr &&
348 grep region_enter.*progress trace-start.event &&
349 ! grep region_leave.*progress trace-start.event
350'
351
352test_expect_success 'progress generates traces: stop without start' '
353 cat >in <<-\EOF &&
354 stop
355 EOF
356
357 GIT_TRACE2_EVENT="$PWD/trace-stop.event" test-tool progress \
358 <in 2>stderr &&
359 ! grep region_enter.*progress trace-stop.event &&
360 ! grep region_leave.*progress trace-stop.event
361'
362
363test_expect_success 'progress generates traces: start with active progress bar (no stops)' '
364 cat >in <<-\EOF &&
365 start 0 One
366 start 0 Two
367 EOF
368
369 GIT_TRACE2_EVENT="$PWD/trace-2start.event" \
370 LSAN_OPTIONS=detect_leaks=0 \
371 test-tool progress \
372 <in 2>stderr &&
373 grep region_enter.*progress.*One trace-2start.event &&
374 grep region_enter.*progress.*Two trace-2start.event &&
375 ! grep region_leave trace-2start.event
376'
377
2bb74b53 378test_done