]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/zstd/tests/playTests.sh
Merge latest version of blacklist sources from NetBSD (@ 20170503)
[FreeBSD/FreeBSD.git] / contrib / zstd / tests / playTests.sh
1 #!/bin/sh -e
2
3 die() {
4     $ECHO "$@" 1>&2
5     exit 1
6 }
7
8 roundTripTest() {
9     if [ -n "$3" ]; then
10         local_c="$3"
11         local_p="$2"
12     else
13         local_c="$2"
14     fi
15
16     rm -f tmp1 tmp2
17     $ECHO "roundTripTest: ./datagen $1 $local_p | $ZSTD -v$local_c | $ZSTD -d"
18     ./datagen $1 $local_p | $MD5SUM > tmp1
19     ./datagen $1 $local_p | $ZSTD --ultra -v$local_c | $ZSTD -d  | $MD5SUM > tmp2
20     $DIFF -q tmp1 tmp2
21 }
22
23 isWindows=false
24 ECHO="echo"
25 INTOVOID="/dev/null"
26 case "$OS" in
27   Windows*)
28     isWindows=true
29     ECHO="echo -e"
30     ;;
31 esac
32
33 UNAME=$(uname)
34 case "$UNAME" in
35   Darwin) MD5SUM="md5 -r" ;;
36   FreeBSD) MD5SUM="gmd5sum" ;;
37   *) MD5SUM="md5sum" ;;
38 esac
39
40 DIFF="diff"
41 case "$UNAME" in
42   SunOS) DIFF="gdiff" ;;
43 esac
44
45
46 $ECHO "\nStarting playTests.sh isWindows=$isWindows ZSTD='$ZSTD'"
47
48 [ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
49
50 $ECHO "\n**** simple tests **** "
51
52 ./datagen > tmp
53 $ECHO "test : basic compression "
54 $ZSTD -f tmp                      # trivial compression case, creates tmp.zst
55 $ECHO "test : basic decompression"
56 $ZSTD -df tmp.zst                 # trivial decompression case (overwrites tmp)
57 $ECHO "test : too large compression level (must fail)"
58 $ZSTD -99 -f tmp  # too large compression level, automatic sized down
59 $ECHO "test : compress to stdout"
60 $ZSTD tmp -c > tmpCompressed
61 $ZSTD tmp --stdout > tmpCompressed       # long command format
62 $ECHO "test : compress to named file"
63 rm tmpCompressed
64 $ZSTD tmp -o tmpCompressed
65 ls tmpCompressed   # must work
66 $ECHO "test : -o must be followed by filename (must fail)"
67 $ZSTD tmp -of tmpCompressed && die "-o must be followed by filename "
68 $ECHO "test : force write, correct order"
69 $ZSTD tmp -fo tmpCompressed
70 $ECHO "test : forgotten argument"
71 cp tmp tmp2
72 $ZSTD tmp2 -fo && die "-o must be followed by filename "
73 $ECHO "test : implied stdout when input is stdin"
74 $ECHO bob | $ZSTD | $ZSTD -d
75 $ECHO "test : null-length file roundtrip"
76 $ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
77 $ECHO "test : decompress file with wrong suffix (must fail)"
78 $ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
79 $ZSTD -df tmp && die "should have refused : wrong extension"
80 $ECHO "test : decompress into stdout"
81 $ZSTD -d tmpCompressed -c > tmpResult    # decompression using stdout
82 $ZSTD --decompress tmpCompressed -c > tmpResult
83 $ZSTD --decompress tmpCompressed --stdout > tmpResult
84 $ECHO "test : decompress from stdin into stdout"
85 $ZSTD -dc   < tmp.zst > $INTOVOID   # combine decompression, stdin & stdout
86 $ZSTD -dc - < tmp.zst > $INTOVOID
87 $ZSTD -d    < tmp.zst > $INTOVOID   # implicit stdout when stdin is used
88 $ZSTD -d  - < tmp.zst > $INTOVOID
89 $ECHO "test : impose memory limitation (must fail)"
90 $ZSTD -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
91 $ZSTD -d -f tmp.zst --memlimit=2K -c > $INTOVOID && die "decompression needs more memory than allowed"  # long command
92 $ZSTD -d -f tmp.zst --memory=2K -c > $INTOVOID && die "decompression needs more memory than allowed"  # long command
93 $ZSTD -d -f tmp.zst --memlimit-decompress=2K -c > $INTOVOID && die "decompression needs more memory than allowed"  # long command
94 $ECHO "test : overwrite protection"
95 $ZSTD -q tmp && die "overwrite check failed!"
96 $ECHO "test : force overwrite"
97 $ZSTD -q -f tmp
98 $ZSTD -q --force tmp
99 $ECHO "test : file removal"
100 $ZSTD -f --rm tmp
101 ls tmp && die "tmp should no longer be present"
102 $ZSTD -f -d --rm tmp.zst
103 ls tmp.zst && die "tmp.zst should no longer be present"
104 $ECHO "test : --rm on stdin"
105 $ECHO a | $ZSTD --rm > $INTOVOID   # --rm should remain silent
106 rm tmp
107 $ZSTD -f tmp && die "tmp not present : should have failed"
108 ls tmp.zst && die "tmp.zst should not be created"
109
110
111 $ECHO "\n**** Advanced compression parameters **** "
112 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,      - -o tmp.zst && die "wrong parameters not detected!"
113 $ECHO "Hello world!" | $ZSTD --zstd=windowLo=21        - -o tmp.zst && die "wrong parameters not detected!"
114 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,slog  - -o tmp.zst && die "wrong parameters not detected!"
115 ls tmp.zst && die "tmp.zst should not be created"
116 roundTripTest -g512K
117 roundTripTest -g512K " --zstd=slen=3,tlen=48,strat=6"
118 roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
119 roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,searchLength=3,targetLength=48,strategy=6"
120 roundTripTest -g512K 19
121
122
123 $ECHO "\n**** Pass-Through mode **** "
124 $ECHO "Hello world 1!" | $ZSTD -df
125 $ECHO "Hello world 2!" | $ZSTD -dcf
126 $ECHO "Hello world 3!" > tmp1
127 $ZSTD -dcf tmp1
128
129
130 $ECHO "\n**** frame concatenation **** "
131
132 $ECHO "hello " > hello.tmp
133 $ECHO "world!" > world.tmp
134 cat hello.tmp world.tmp > helloworld.tmp
135 $ZSTD -c hello.tmp > hello.zstd
136 $ZSTD -c world.tmp > world.zstd
137 cat hello.zstd world.zstd > helloworld.zstd
138 $ZSTD -dc helloworld.zstd > result.tmp
139 cat result.tmp
140 $DIFF helloworld.tmp result.tmp
141 $ECHO "frame concatenation without checksum"
142 $ZSTD -c hello.tmp > hello.zstd --no-check
143 $ZSTD -c world.tmp > world.zstd --no-check
144 cat hello.zstd world.zstd > helloworld.zstd
145 $ZSTD -dc helloworld.zstd > result.tmp
146 cat result.tmp
147 $DIFF helloworld.tmp result.tmp
148 rm ./*.tmp ./*.zstd
149 $ECHO "frame concatenation tests completed"
150
151
152 if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] ; then
153 $ECHO "\n**** flush write error test **** "
154
155 $ECHO "$ECHO foo | $ZSTD > /dev/full"
156 $ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
157 $ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
158 $ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
159 fi
160
161
162 $ECHO "\n**** test sparse file support **** "
163
164 ./datagen -g5M  -P100 > tmpSparse
165 $ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
166 $DIFF -s tmpSparse tmpSparseRegen
167 $ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
168 $DIFF -s tmpSparse tmpOutSparse
169 $ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
170 $DIFF -s tmpSparse tmpOutNoSparse
171 ls -ls tmpSparse*
172 ./datagen -s1 -g1200007 -P100 | $ZSTD | $ZSTD -dv --sparse -c > tmpSparseOdd   # Odd size file (to not finish on an exact nb of blocks)
173 ./datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
174 ls -ls tmpSparseOdd
175 $ECHO "\n Sparse Compatibility with Console :"
176 $ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
177 $ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
178 $ECHO "\n Sparse Compatibility with Append :"
179 ./datagen -P100 -g1M > tmpSparse1M
180 cat tmpSparse1M tmpSparse1M > tmpSparse2M
181 $ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
182 $ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
183 $ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
184 ls -ls tmpSparse*
185 $DIFF tmpSparse2M tmpSparseRegenerated
186 rm tmpSparse*
187
188
189 $ECHO "\n**** multiple files tests **** "
190
191 ./datagen -s1        > tmp1 2> $INTOVOID
192 ./datagen -s2 -g100K > tmp2 2> $INTOVOID
193 ./datagen -s3 -g1M   > tmp3 2> $INTOVOID
194 $ECHO "compress tmp* : "
195 $ZSTD -f tmp*
196 ls -ls tmp*
197 rm tmp1 tmp2 tmp3
198 $ECHO "decompress tmp* : "
199 $ZSTD -df *.zst
200 ls -ls tmp*
201 $ECHO "compress tmp* into stdout > tmpall : "
202 $ZSTD -c tmp1 tmp2 tmp3 > tmpall
203 ls -ls tmp*
204 $ECHO "decompress tmpall* into stdout > tmpdec : "
205 cp tmpall tmpall2
206 $ZSTD -dc tmpall* > tmpdec
207 ls -ls tmp*
208 $ECHO "compress multiple files including a missing one (notHere) : "
209 $ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
210
211
212 $ECHO "\n**** dictionary tests **** "
213
214 $ECHO "- test with raw dict (content only) "
215 ./datagen > tmpDict
216 ./datagen -g1M | $MD5SUM > tmp1
217 ./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
218 $DIFF -q tmp1 tmp2
219 $ECHO "- Create first dictionary "
220 TESTFILE=../programs/zstdcli.c
221 $ZSTD --train *.c ../programs/*.c -o tmpDict
222 cp $TESTFILE tmp
223 $ZSTD -f tmp -D tmpDict
224 $ZSTD -d tmp.zst -D tmpDict -fo result
225 $DIFF $TESTFILE result
226 $ECHO "- Create second (different) dictionary "
227 $ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
228 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
229 $ECHO "- Create dictionary with short dictID"
230 $ZSTD --train *.c ../programs/*.c --dictID 1 -o tmpDict1
231 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
232 $ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
233 $ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
234 $ECHO "- Create dictionary with size limit"
235 $ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict 4K -v
236 $ECHO "- Create dictionary with wrong parameter order (must fail)"
237 $ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict -v 4K && die "wrong order : --maxdict must be followed by argument "
238 $ECHO "- Compress without dictID"
239 $ZSTD -f tmp -D tmpDict1 --no-dictID
240 $ZSTD -d tmp.zst -D tmpDict -fo result
241 $DIFF $TESTFILE result
242 $ECHO "- Compress with wrong argument order (must fail)"
243 $ZSTD tmp -Df tmpDict1 -c > /dev/null && die "-D must be followed by dictionary name "
244 $ECHO "- Compress multiple files with dictionary"
245 rm -rf dirTestDict
246 mkdir dirTestDict
247 cp *.c dirTestDict
248 cp ../programs/*.c dirTestDict
249 cp ../programs/*.h dirTestDict
250 $MD5SUM dirTestDict/* > tmph1
251 $ZSTD -f --rm dirTestDict/* -D tmpDictC
252 $ZSTD -d --rm dirTestDict/*.zst -D tmpDictC  # note : use internal checksum by default
253 case "$UNAME" in
254   Darwin) $ECHO "md5sum -c not supported on OS-X : test skipped" ;;  # not compatible with OS-X's md5
255   *) $MD5SUM -c tmph1 ;;
256 esac
257 rm -rf dirTestDict
258 rm tmp*
259
260
261 $ECHO "\n**** cover dictionary tests **** "
262
263 TESTFILE=../programs/zstdcli.c
264 ./datagen > tmpDict
265 $ECHO "- Create first dictionary"
266 $ZSTD --train --cover=k=46,d=8 *.c ../programs/*.c -o tmpDict
267 cp $TESTFILE tmp
268 $ZSTD -f tmp -D tmpDict
269 $ZSTD -d tmp.zst -D tmpDict -fo result
270 $DIFF $TESTFILE result
271 $ECHO "- Create second (different) dictionary"
272 $ZSTD --train --cover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
273 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
274 $ECHO "- Create dictionary with short dictID"
275 $ZSTD --train --cover=k=46,d=8 *.c ../programs/*.c --dictID 1 -o tmpDict1
276 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
277 $ECHO "- Create dictionary with size limit"
278 $ZSTD --train --optimize-cover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict 4K
279 rm tmp*
280
281
282 $ECHO "\n**** integrity tests **** "
283
284 $ECHO "test one file (tmp1.zst) "
285 ./datagen > tmp1
286 $ZSTD tmp1
287 $ZSTD -t tmp1.zst
288 $ZSTD --test tmp1.zst
289 $ECHO "test multiple files (*.zst) "
290 $ZSTD -t *.zst
291 $ECHO "test bad files (*) "
292 $ZSTD -t * && die "bad files not detected !"
293 $ZSTD -t tmp1 && die "bad file not detected !"
294 cp tmp1 tmp2.zst
295 $ZSTD -t tmp2.zst && die "bad file not detected !"
296 ./datagen -g0 > tmp3
297 $ZSTD -t tmp3 && die "bad file not detected !"   # detects 0-sized files as bad
298 $ECHO "test --rm and --test combined "
299 $ZSTD -t --rm tmp1.zst
300 ls -ls tmp1.zst  # check file is still present
301
302
303 $ECHO "\n**** benchmark mode tests **** "
304
305 $ECHO "bench one file"
306 ./datagen > tmp1
307 $ZSTD -bi0 tmp1
308 $ECHO "bench multiple levels"
309 $ZSTD -i0b0e3 tmp1
310 $ECHO "with recursive and quiet modes"
311 $ZSTD -rqi1b1e2 tmp1
312
313
314 $ECHO "\n**** gzip compatibility tests **** "
315
316 GZIPMODE=1
317 $ZSTD --format=gzip -V || GZIPMODE=0
318 if [ $GZIPMODE -eq 1 ]; then
319     $ECHO "gzip support detected"
320     GZIPEXE=1
321     gzip -V || GZIPEXE=0
322     if [ $GZIPEXE -eq 1 ]; then
323         ./datagen > tmp
324         $ZSTD --format=gzip -f tmp
325         gzip -t -v tmp.gz
326         gzip -f tmp
327         $ZSTD -d -f -v tmp.gz
328         rm tmp*
329     else
330         $ECHO "gzip binary not detected"
331     fi
332 else
333     $ECHO "gzip mode not supported"
334 fi
335
336
337 $ECHO "\n**** gzip frame tests **** "
338
339 if [ $GZIPMODE -eq 1 ]; then
340     ./datagen > tmp
341     $ZSTD -f --format=gzip tmp
342     $ZSTD -f tmp
343     cat tmp.gz tmp.zst tmp.gz tmp.zst | $ZSTD -d -f -o tmp
344     head -c -1 tmp.gz | $ZSTD -t && die "incomplete frame not detected !"
345     rm tmp*
346 else
347     $ECHO "gzip mode not supported"
348 fi
349
350
351 $ECHO "\n**** xz compatibility tests **** "
352
353 LZMAMODE=1
354 $ZSTD --format=xz -V || LZMAMODE=0
355 if [ $LZMAMODE -eq 1 ]; then
356     $ECHO "xz support detected"
357     XZEXE=1
358     xz -V && lzma -V || XZEXE=0
359     if [ $XZEXE -eq 1 ]; then
360         ./datagen > tmp
361         $ZSTD --format=lzma -f tmp
362         $ZSTD --format=xz -f tmp
363         xz -t -v tmp.xz
364         xz -t -v tmp.lzma
365         xz -f -k tmp
366         lzma -f -k --lzma1 tmp
367         $ZSTD -d -f -v tmp.xz
368         $ZSTD -d -f -v tmp.lzma
369         rm tmp*
370     else
371         $ECHO "xz binary not detected"
372     fi
373 else
374     $ECHO "xz mode not supported"
375 fi
376
377
378 $ECHO "\n**** xz frame tests **** "
379
380 if [ $LZMAMODE -eq 1 ]; then
381     ./datagen > tmp
382     $ZSTD -f --format=xz tmp
383     $ZSTD -f --format=lzma tmp
384     $ZSTD -f tmp
385     cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | $ZSTD -d -f -o tmp
386     head -c -1 tmp.xz | $ZSTD -t && die "incomplete frame not detected !"
387     head -c -1 tmp.lzma | $ZSTD -t && die "incomplete frame not detected !"
388     rm tmp*
389 else
390     $ECHO "xz mode not supported"
391 fi
392
393
394 $ECHO "\n**** zstd round-trip tests **** "
395
396 roundTripTest
397 roundTripTest -g15K       # TableID==3
398 roundTripTest -g127K      # TableID==2
399 roundTripTest -g255K      # TableID==1
400 roundTripTest -g522K      # TableID==0
401 roundTripTest -g519K 6    # greedy, hash chain
402 roundTripTest -g517K 16   # btlazy2
403 roundTripTest -g516K 19   # btopt
404
405 rm tmp*
406
407 if [ "$1" != "--test-large-data" ]; then
408     $ECHO "Skipping large data tests"
409     exit 0
410 fi
411
412 roundTripTest -g270000000 1
413 roundTripTest -g270000000 2
414 roundTripTest -g270000000 3
415
416 roundTripTest -g140000000 -P60 4
417 roundTripTest -g140000000 -P60 5
418 roundTripTest -g140000000 -P60 6
419
420 roundTripTest -g70000000 -P70 7
421 roundTripTest -g70000000 -P70 8
422 roundTripTest -g70000000 -P70 9
423
424 roundTripTest -g35000000 -P75 10
425 roundTripTest -g35000000 -P75 11
426 roundTripTest -g35000000 -P75 12
427
428 roundTripTest -g18000000 -P80 13
429 roundTripTest -g18000000 -P80 14
430 roundTripTest -g18000000 -P80 15
431 roundTripTest -g18000000 -P80 16
432 roundTripTest -g18000000 -P80 17
433
434 roundTripTest -g50000000 -P94 18
435 roundTripTest -g50000000 -P94 19
436
437 roundTripTest -g99000000 -P99 20
438 roundTripTest -g6000000000 -P99 1
439
440 rm tmp*