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