]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/playTests.sh
import zstd 1.3.4
[FreeBSD/FreeBSD.git] / 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         cLevel="$3"
11         proba="$2"
12     else
13         cLevel="$2"
14         proba=""
15     fi
16     if [ -n "$4" ]; then
17         dLevel="$4"
18     else
19         dLevel="$cLevel"
20     fi
21
22     rm -f tmp1 tmp2
23     $ECHO "roundTripTest: ./datagen $1 $proba | $ZSTD -v$cLevel | $ZSTD -d$dLevel"
24     ./datagen $1 $proba | $MD5SUM > tmp1
25     ./datagen $1 $proba | $ZSTD --ultra -v$cLevel | $ZSTD -d$dLevel  | $MD5SUM > tmp2
26     $DIFF -q tmp1 tmp2
27 }
28
29 fileRoundTripTest() {
30     if [ -n "$3" ]; then
31         local_c="$3"
32         local_p="$2"
33     else
34         local_c="$2"
35         local_p=""
36     fi
37     if [ -n "$4" ]; then
38         local_d="$4"
39     else
40         local_d="$local_c"
41     fi
42
43     rm -f tmp.zstd tmp.md5.1 tmp.md5.2
44     $ECHO "fileRoundTripTest: ./datagen $1 $local_p > tmp && $ZSTD -v$local_c -c tmp | $ZSTD -d$local_d"
45     ./datagen $1 $local_p > tmp
46     < tmp $MD5SUM > tmp.md5.1
47     $ZSTD --ultra -v$local_c -c tmp | $ZSTD -d$local_d | $MD5SUM > tmp.md5.2
48     $DIFF -q tmp.md5.1 tmp.md5.2
49 }
50
51 isTerminal=false
52 if [ -t 0 ] && [ -t 1 ]
53 then
54     isTerminal=true
55 fi
56
57 isWindows=false
58 INTOVOID="/dev/null"
59 DEVDEVICE="/dev/zero"
60 case "$OS" in
61   Windows*)
62     isWindows=true
63     INTOVOID="NUL"
64     DEVDEVICE="NUL"
65     ;;
66 esac
67
68 UNAME=$(uname)
69 case "$UNAME" in
70   Darwin) MD5SUM="md5 -r" ;;
71   FreeBSD) MD5SUM="gmd5sum" ;;
72   *) MD5SUM="md5sum" ;;
73 esac
74
75 DIFF="diff"
76 case "$UNAME" in
77   SunOS) DIFF="gdiff" ;;
78 esac
79
80 ECHO="echo -e"
81 case "$UNAME" in
82   Darwin) ECHO="echo" ;;
83 esac
84
85 $ECHO "\nStarting playTests.sh isWindows=$isWindows ZSTD='$ZSTD'"
86
87 [ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
88
89 if [ -n "$(echo hello | $ZSTD -v -T2 2>&1 > $INTOVOID | grep 'multi-threading is disabled')" ]
90 then
91     hasMT=""
92 else
93     hasMT="true"
94 fi
95
96
97 $ECHO "\n===>  simple tests "
98
99 ./datagen > tmp
100 $ECHO "test : basic compression "
101 $ZSTD -f tmp                      # trivial compression case, creates tmp.zst
102 $ECHO "test : basic decompression"
103 $ZSTD -df tmp.zst                 # trivial decompression case (overwrites tmp)
104 $ECHO "test : too large compression level => auto-fix"
105 $ZSTD -99 -f tmp  # too large compression level, automatic sized down
106 $ECHO "test : --fast aka negative compression levels"
107 $ZSTD --fast -f tmp  # == -1
108 $ZSTD --fast=3 -f tmp  # == -3
109 $ZSTD --fast=200000 -f tmp  # == no compression
110 $ECHO "test : compress to stdout"
111 $ZSTD tmp -c > tmpCompressed
112 $ZSTD tmp --stdout > tmpCompressed       # long command format
113 $ECHO "test : compress to named file"
114 rm tmpCompressed
115 $ZSTD tmp -o tmpCompressed
116 test -f tmpCompressed   # file must be created
117 $ECHO "test : -o must be followed by filename (must fail)"
118 $ZSTD tmp -of tmpCompressed && die "-o must be followed by filename "
119 $ECHO "test : force write, correct order"
120 $ZSTD tmp -fo tmpCompressed
121 $ECHO "test : forgotten argument"
122 cp tmp tmp2
123 $ZSTD tmp2 -fo && die "-o must be followed by filename "
124 $ECHO "test : implied stdout when input is stdin"
125 $ECHO bob | $ZSTD | $ZSTD -d
126 if [ "$isTerminal" = true ]; then
127 $ECHO "test : compressed data to terminal"
128 $ECHO bob | $ZSTD && die "should have refused : compressed data to terminal"
129 $ECHO "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)"
130 $ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal"
131 fi
132 $ECHO "test : null-length file roundtrip"
133 $ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
134 $ECHO "test : ensure small file doesn't add 3-bytes null block"
135 ./datagen -g1 > tmp1
136 $ZSTD tmp1 -c | wc -c | grep "14"
137 $ZSTD < tmp1  | wc -c | grep "14"
138 $ECHO "test : decompress file with wrong suffix (must fail)"
139 $ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
140 $ZSTD -df tmp && die "should have refused : wrong extension"
141 $ECHO "test : decompress into stdout"
142 $ZSTD -d tmpCompressed -c > tmpResult    # decompression using stdout
143 $ZSTD --decompress tmpCompressed -c > tmpResult
144 $ZSTD --decompress tmpCompressed --stdout > tmpResult
145 $ECHO "test : decompress from stdin into stdout"
146 $ZSTD -dc   < tmp.zst > $INTOVOID   # combine decompression, stdin & stdout
147 $ZSTD -dc - < tmp.zst > $INTOVOID
148 $ZSTD -d    < tmp.zst > $INTOVOID   # implicit stdout when stdin is used
149 $ZSTD -d  - < tmp.zst > $INTOVOID
150 $ECHO "test : impose memory limitation (must fail)"
151 $ZSTD -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
152 $ZSTD -d -f tmp.zst --memlimit=2K -c > $INTOVOID && die "decompression needs more memory than allowed"  # long command
153 $ZSTD -d -f tmp.zst --memory=2K -c > $INTOVOID && die "decompression needs more memory than allowed"  # long command
154 $ZSTD -d -f tmp.zst --memlimit-decompress=2K -c > $INTOVOID && die "decompression needs more memory than allowed"  # long command
155 $ECHO "test : overwrite protection"
156 $ZSTD -q tmp && die "overwrite check failed!"
157 $ECHO "test : force overwrite"
158 $ZSTD -q -f tmp
159 $ZSTD -q --force tmp
160 $ECHO "test : overwrite readonly file"
161 rm -f tmpro tmpro.zst
162 $ECHO foo > tmpro.zst
163 $ECHO foo > tmpro
164 chmod 400 tmpro.zst
165 $ZSTD -q tmpro && die "should have refused to overwrite read-only file"
166 $ZSTD -q -f tmpro
167 rm -f tmpro tmpro.zst
168 $ECHO "test : file removal"
169 $ZSTD -f --rm tmp
170 test ! -f tmp  # tmp should no longer be present
171 $ZSTD -f -d --rm tmp.zst
172 test ! -f tmp.zst   # tmp.zst should no longer be present
173 $ECHO "test : should quietly not remove non-regular file"
174 $ECHO hello > tmp
175 $ZSTD tmp -f -o "$DEVDEVICE" 2>tmplog > "$INTOVOID"
176 grep -v "Refusing to remove non-regular file" tmplog
177 rm -f tmplog
178 $ZSTD tmp -f -o "$INTONULL" 2>&1 | grep -v "Refusing to remove non-regular file"
179 $ECHO "test : --rm on stdin"
180 $ECHO a | $ZSTD --rm > $INTOVOID   # --rm should remain silent
181 rm tmp
182 $ZSTD -f tmp && die "tmp not present : should have failed"
183 test ! -f tmp.zst  # tmp.zst should not be created
184
185 $ECHO "test : compress multiple files"
186 $ECHO hello > tmp1
187 $ECHO world > tmp2
188 $ZSTD tmp1 tmp2 -o "$INTOVOID"
189 $ZSTD tmp1 tmp2 -c | $ZSTD -t
190 $ZSTD tmp1 tmp2 -o tmp.zst
191 test ! -f tmp1.zst
192 test ! -f tmp2.zst
193 $ZSTD tmp1 tmp2
194 $ZSTD -t tmp1.zst tmp2.zst
195 $ZSTD -dc tmp1.zst tmp2.zst
196 $ZSTD tmp1.zst tmp2.zst -o "$INTOVOID"
197 $ZSTD -d tmp1.zst tmp2.zst -o tmp
198 touch tmpexists
199 $ZSTD tmp1 tmp2 -f -o tmpexists
200 $ZSTD tmp1 tmp2 -o tmpexists && die "should have refused to overwrite"
201 # Bug: PR #972
202 if [ "$?" -eq 139 ]; then
203   die "should not have segfaulted"
204 fi
205 rm tmp*
206
207
208 $ECHO "\n===>  Advanced compression parameters "
209 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,      - -o tmp.zst && die "wrong parameters not detected!"
210 $ECHO "Hello world!" | $ZSTD --zstd=windowLo=21        - -o tmp.zst && die "wrong parameters not detected!"
211 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,slog  - -o tmp.zst && die "wrong parameters not detected!"
212 test ! -f tmp.zst  # tmp.zst should not be created
213 roundTripTest -g512K
214 roundTripTest -g512K " --zstd=slen=3,tlen=48,strat=6"
215 roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
216 roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,searchLength=3,targetLength=48,strategy=6"
217 roundTripTest -g512K " --single-thread --long --zstd=ldmHashLog=20,ldmSearchLength=64,ldmBucketSizeLog=1,ldmHashEveryLog=7"
218 roundTripTest -g512K " --single-thread --long --zstd=ldmhlog=20,ldmslen=64,ldmblog=1,ldmhevery=7"
219 roundTripTest -g512K 19
220
221
222 $ECHO "\n===>  Pass-Through mode "
223 $ECHO "Hello world 1!" | $ZSTD -df
224 $ECHO "Hello world 2!" | $ZSTD -dcf
225 $ECHO "Hello world 3!" > tmp1
226 $ZSTD -dcf tmp1
227
228
229 $ECHO "\n===>  frame concatenation "
230
231 $ECHO "hello " > hello.tmp
232 $ECHO "world!" > world.tmp
233 cat hello.tmp world.tmp > helloworld.tmp
234 $ZSTD -c hello.tmp > hello.zstd
235 $ZSTD -c world.tmp > world.zstd
236 cat hello.zstd world.zstd > helloworld.zstd
237 $ZSTD -dc helloworld.zstd > result.tmp
238 cat result.tmp
239 $DIFF helloworld.tmp result.tmp
240 $ECHO "frame concatenation without checksum"
241 $ZSTD -c hello.tmp > hello.zstd --no-check
242 $ZSTD -c world.tmp > world.zstd --no-check
243 cat hello.zstd world.zstd > helloworld.zstd
244 $ZSTD -dc helloworld.zstd > result.tmp
245 $DIFF helloworld.tmp result.tmp
246 $ECHO "testing zstdcat symlink"
247 ln -sf $ZSTD zstdcat
248 ./zstdcat helloworld.zstd > result.tmp
249 $DIFF helloworld.tmp result.tmp
250 rm zstdcat
251 rm result.tmp
252 $ECHO "testing zcat symlink"
253 ln -sf $ZSTD zcat
254 ./zcat helloworld.zstd > result.tmp
255 $DIFF helloworld.tmp result.tmp
256 rm zcat
257 rm ./*.tmp ./*.zstd
258 $ECHO "frame concatenation tests completed"
259
260
261 if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] ; then
262 $ECHO "\n**** flush write error test **** "
263
264 $ECHO "$ECHO foo | $ZSTD > /dev/full"
265 $ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
266 $ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
267 $ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
268
269
270 $ECHO "\n===>  symbolic link test "
271
272 rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
273 $ECHO "hello world" > hello.tmp
274 ln -s hello.tmp world.tmp
275 $ZSTD world.tmp hello.tmp
276 test -f hello.tmp.zst  # regular file should have been compressed!
277 test ! -f world.tmp.zst  # symbolic link should not have been compressed!
278 $ZSTD world.tmp hello.tmp -f
279 test -f world.tmp.zst  # symbolic link should have been compressed with --force
280 rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
281
282 fi
283
284
285 $ECHO "\n===>  test sparse file support "
286
287 ./datagen -g5M  -P100 > tmpSparse
288 $ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
289 $DIFF -s tmpSparse tmpSparseRegen
290 $ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
291 $DIFF -s tmpSparse tmpOutSparse
292 $ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
293 $DIFF -s tmpSparse tmpOutNoSparse
294 ls -ls tmpSparse*  # look at file size and block size on disk
295 ./datagen -s1 -g1200007 -P100 | $ZSTD | $ZSTD -dv --sparse -c > tmpSparseOdd   # Odd size file (to not finish on an exact nb of blocks)
296 ./datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
297 ls -ls tmpSparseOdd  # look at file size and block size on disk
298 $ECHO "\n Sparse Compatibility with Console :"
299 $ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
300 $ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
301 $ECHO "\n Sparse Compatibility with Append :"
302 ./datagen -P100 -g1M > tmpSparse1M
303 cat tmpSparse1M tmpSparse1M > tmpSparse2M
304 $ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
305 $ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
306 $ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
307 ls -ls tmpSparse*  # look at file size and block size on disk
308 $DIFF tmpSparse2M tmpSparseRegenerated
309 rm tmpSparse*
310
311
312 $ECHO "\n===>  multiple files tests "
313
314 ./datagen -s1        > tmp1 2> $INTOVOID
315 ./datagen -s2 -g100K > tmp2 2> $INTOVOID
316 ./datagen -s3 -g1M   > tmp3 2> $INTOVOID
317 $ECHO "compress tmp* : "
318 $ZSTD -f tmp*
319 ls -ls tmp*
320 rm tmp1 tmp2 tmp3
321 $ECHO "decompress tmp* : "
322 $ZSTD -df *.zst
323 ls -ls tmp*
324 $ECHO "compress tmp* into stdout > tmpall : "
325 $ZSTD -c tmp1 tmp2 tmp3 > tmpall
326 ls -ls tmp*  # check size of tmpall (should be tmp1.zst + tmp2.zst + tmp3.zst)
327 $ECHO "decompress tmpall* into stdout > tmpdec : "
328 cp tmpall tmpall2
329 $ZSTD -dc tmpall* > tmpdec
330 ls -ls tmp* # check size of tmpdec (should be 2*(tmp1 + tmp2 + tmp3))
331 $ECHO "compress multiple files including a missing one (notHere) : "
332 $ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
333
334
335 $ECHO "\n===>  dictionary tests "
336
337 $ECHO "- test with raw dict (content only) "
338 ./datagen > tmpDict
339 ./datagen -g1M | $MD5SUM > tmp1
340 ./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
341 $DIFF -q tmp1 tmp2
342 $ECHO "- Create first dictionary "
343 TESTFILE=../programs/zstdcli.c
344 $ZSTD --train *.c ../programs/*.c -o tmpDict
345 cp $TESTFILE tmp
346 $ECHO "- Dictionary compression roundtrip"
347 $ZSTD -f tmp -D tmpDict
348 $ZSTD -d tmp.zst -D tmpDict -fo result
349 $DIFF $TESTFILE result
350 $ECHO "- Dictionary compression with btlazy2 strategy"
351 $ZSTD -f tmp -D tmpDict --zstd=strategy=6
352 $ZSTD -d tmp.zst -D tmpDict -fo result
353 $DIFF $TESTFILE result
354 if [ -n "$hasMT" ]
355 then
356     $ECHO "- Test dictionary compression with multithreading "
357     ./datagen -g5M | $ZSTD -T2 -D tmpDict | $ZSTD -t -D tmpDict   # fails with v1.3.2
358 fi
359 $ECHO "- Create second (different) dictionary "
360 $ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
361 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
362 $ECHO "- Create dictionary with short dictID"
363 $ZSTD --train *.c ../programs/*.c --dictID=1 -o tmpDict1
364 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
365 $ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
366 $ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
367 $ECHO "- Create dictionary with size limit"
368 $ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict=4K -v
369 $ECHO "- Create dictionary with small size limit"
370 $ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict=1K -v
371 $ECHO "- Create dictionary with wrong parameter order (must fail)"
372 $ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict -v 4K && die "wrong order : --maxdict must be followed by argument "
373 $ECHO "- Compress without dictID"
374 $ZSTD -f tmp -D tmpDict1 --no-dictID
375 $ZSTD -d tmp.zst -D tmpDict -fo result
376 $DIFF $TESTFILE result
377 $ECHO "- Compress with wrong argument order (must fail)"
378 $ZSTD tmp -Df tmpDict1 -c > $INTOVOID && die "-D must be followed by dictionary name "
379 $ECHO "- Compress multiple files with dictionary"
380 rm -rf dirTestDict
381 mkdir dirTestDict
382 cp *.c dirTestDict
383 cp ../programs/*.c dirTestDict
384 cp ../programs/*.h dirTestDict
385 $MD5SUM dirTestDict/* > tmph1
386 $ZSTD -f --rm dirTestDict/* -D tmpDictC
387 $ZSTD -d --rm dirTestDict/*.zst -D tmpDictC  # note : use internal checksum by default
388 case "$UNAME" in
389   Darwin) $ECHO "md5sum -c not supported on OS-X : test skipped" ;;  # not compatible with OS-X's md5
390   *) $MD5SUM -c tmph1 ;;
391 esac
392 rm -rf dirTestDict
393 $ECHO "- dictionary builder on bogus input"
394 $ECHO "Hello World" > tmp
395 $ZSTD --train-legacy -q tmp && die "Dictionary training should fail : not enough input source"
396 ./datagen -P0 -g10M > tmp
397 $ZSTD --train-legacy -q tmp && die "Dictionary training should fail : source is pure noise"
398 rm tmp*
399
400
401 $ECHO "\n===>  cover dictionary builder : advanced options "
402
403 TESTFILE=../programs/zstdcli.c
404 ./datagen > tmpDict
405 $ECHO "- Create first dictionary"
406 $ZSTD --train-cover=k=46,d=8 *.c ../programs/*.c -o tmpDict
407 cp $TESTFILE tmp
408 $ZSTD -f tmp -D tmpDict
409 $ZSTD -d tmp.zst -D tmpDict -fo result
410 $DIFF $TESTFILE result
411 $ECHO "- Create second (different) dictionary"
412 $ZSTD --train-cover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
413 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
414 $ECHO "- Create dictionary with short dictID"
415 $ZSTD --train-cover=k=46,d=8 *.c ../programs/*.c --dictID=1 -o tmpDict1
416 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
417 $ECHO "- Create dictionary with size limit"
418 $ZSTD --train-cover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
419 rm tmp*
420
421 $ECHO "\n===>  legacy dictionary builder "
422
423 TESTFILE=../programs/zstdcli.c
424 ./datagen > tmpDict
425 $ECHO "- Create first dictionary"
426 $ZSTD --train-legacy=selectivity=8 *.c ../programs/*.c -o tmpDict
427 cp $TESTFILE tmp
428 $ZSTD -f tmp -D tmpDict
429 $ZSTD -d tmp.zst -D tmpDict -fo result
430 $DIFF $TESTFILE result
431 $ECHO "- Create second (different) dictionary"
432 $ZSTD --train-legacy=s=5 *.c ../programs/*.c ../programs/*.h -o tmpDictC
433 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
434 $ECHO "- Create dictionary with short dictID"
435 $ZSTD --train-legacy -s5 *.c ../programs/*.c --dictID=1 -o tmpDict1
436 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
437 $ECHO "- Create dictionary with size limit"
438 $ZSTD --train-legacy -s9 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
439 rm tmp*
440
441
442 $ECHO "\n===>  integrity tests "
443
444 $ECHO "test one file (tmp1.zst) "
445 ./datagen > tmp1
446 $ZSTD tmp1
447 $ZSTD -t tmp1.zst
448 $ZSTD --test tmp1.zst
449 $ECHO "test multiple files (*.zst) "
450 $ZSTD -t *.zst
451 $ECHO "test bad files (*) "
452 $ZSTD -t * && die "bad files not detected !"
453 $ZSTD -t tmp1 && die "bad file not detected !"
454 cp tmp1 tmp2.zst
455 $ZSTD -t tmp2.zst && die "bad file not detected !"
456 ./datagen -g0 > tmp3
457 $ZSTD -t tmp3 && die "bad file not detected !"   # detects 0-sized files as bad
458 $ECHO "test --rm and --test combined "
459 $ZSTD -t --rm tmp1.zst
460 test -f tmp1.zst   # check file is still present
461 split -b16384 tmp1.zst tmpSplit.
462 $ZSTD -t tmpSplit.* && die "bad file not detected !"
463 ./datagen | $ZSTD -c | $ZSTD -t
464
465
466
467 $ECHO "\n===>  golden files tests "
468
469 $ZSTD -t -r files
470 $ZSTD -c -r files | $ZSTD -t
471
472
473 $ECHO "\n===>  benchmark mode tests "
474
475 $ECHO "bench one file"
476 ./datagen > tmp1
477 $ZSTD -bi0 tmp1
478 $ECHO "bench multiple levels"
479 $ZSTD -i0b0e3 tmp1
480 $ECHO "bench negative level"
481 $ZSTD -bi0 --fast tmp1
482 $ECHO "with recursive and quiet modes"
483 $ZSTD -rqi1b1e2 tmp1
484
485
486 $ECHO "\n===>  gzip compatibility tests "
487
488 GZIPMODE=1
489 $ZSTD --format=gzip -V || GZIPMODE=0
490 if [ $GZIPMODE -eq 1 ]; then
491     $ECHO "gzip support detected"
492     GZIPEXE=1
493     gzip -V || GZIPEXE=0
494     if [ $GZIPEXE -eq 1 ]; then
495         ./datagen > tmp
496         $ZSTD --format=gzip -f tmp
497         gzip -t -v tmp.gz
498         gzip -f tmp
499         $ZSTD -d -f -v tmp.gz
500         rm tmp*
501     else
502         $ECHO "gzip binary not detected"
503     fi
504 else
505     $ECHO "gzip mode not supported"
506 fi
507
508
509 $ECHO "\n===>  gzip frame tests "
510
511 if [ $GZIPMODE -eq 1 ]; then
512     ./datagen > tmp
513     $ZSTD -f --format=gzip tmp
514     $ZSTD -f tmp
515     cat tmp.gz tmp.zst tmp.gz tmp.zst | $ZSTD -d -f -o tmp
516     head -c -1 tmp.gz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
517     rm tmp*
518 else
519     $ECHO "gzip mode not supported"
520 fi
521
522
523 $ECHO "\n===>  xz compatibility tests "
524
525 LZMAMODE=1
526 $ZSTD --format=xz -V || LZMAMODE=0
527 if [ $LZMAMODE -eq 1 ]; then
528     $ECHO "xz support detected"
529     XZEXE=1
530     xz -V && lzma -V || XZEXE=0
531     if [ $XZEXE -eq 1 ]; then
532         $ECHO "Testing zstd xz and lzma support"
533         ./datagen > tmp
534         $ZSTD --format=lzma -f tmp
535         $ZSTD --format=xz -f tmp
536         xz -t -v tmp.xz
537         xz -t -v tmp.lzma
538         xz -f -k tmp
539         lzma -f -k --lzma1 tmp
540         $ZSTD -d -f -v tmp.xz
541         $ZSTD -d -f -v tmp.lzma
542         rm tmp*
543         $ECHO "Creating symlinks"
544         ln -s $ZSTD ./xz
545         ln -s $ZSTD ./unxz
546         ln -s $ZSTD ./lzma
547         ln -s $ZSTD ./unlzma
548         $ECHO "Testing xz and lzma symlinks"
549         ./datagen > tmp
550         ./xz tmp
551         xz -d tmp.xz
552         ./lzma tmp
553         lzma -d tmp.lzma
554         $ECHO "Testing unxz and unlzma symlinks"
555         xz tmp
556         ./xz -d tmp.xz
557         lzma tmp
558         ./lzma -d tmp.lzma
559         rm xz unxz lzma unlzma
560         rm tmp*
561     else
562         $ECHO "xz binary not detected"
563     fi
564 else
565     $ECHO "xz mode not supported"
566 fi
567
568
569 $ECHO "\n===>  xz frame tests "
570
571 if [ $LZMAMODE -eq 1 ]; then
572     ./datagen > tmp
573     $ZSTD -f --format=xz tmp
574     $ZSTD -f --format=lzma tmp
575     $ZSTD -f tmp
576     cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | $ZSTD -d -f -o tmp
577     head -c -1 tmp.xz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
578     head -c -1 tmp.lzma | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
579     rm tmp*
580 else
581     $ECHO "xz mode not supported"
582 fi
583
584 $ECHO "\n===>  lz4 compatibility tests "
585
586 LZ4MODE=1
587 $ZSTD --format=lz4 -V || LZ4MODE=0
588 if [ $LZ4MODE -eq 1 ]; then
589     $ECHO "lz4 support detected"
590     LZ4EXE=1
591     lz4 -V || LZ4EXE=0
592     if [ $LZ4EXE -eq 1 ]; then
593         ./datagen > tmp
594         $ZSTD --format=lz4 -f tmp
595         lz4 -t -v tmp.lz4
596         lz4 -f tmp
597         $ZSTD -d -f -v tmp.lz4
598         rm tmp*
599     else
600         $ECHO "lz4 binary not detected"
601     fi
602 else
603     $ECHO "lz4 mode not supported"
604 fi
605
606
607 $ECHO "\n===>  lz4 frame tests "
608
609 if [ $LZ4MODE -eq 1 ]; then
610     ./datagen > tmp
611     $ZSTD -f --format=lz4 tmp
612     $ZSTD -f tmp
613     cat tmp.lz4 tmp.zst tmp.lz4 tmp.zst | $ZSTD -d -f -o tmp
614     head -c -1 tmp.lz4 | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
615     rm tmp*
616 else
617     $ECHO "lz4 mode not supported"
618 fi
619
620 $ECHO "\n===>  zstd round-trip tests "
621
622 roundTripTest
623 roundTripTest -g15K       # TableID==3
624 roundTripTest -g127K      # TableID==2
625 roundTripTest -g255K      # TableID==1
626 roundTripTest -g522K      # TableID==0
627 roundTripTest -g519K 6    # greedy, hash chain
628 roundTripTest -g517K 16   # btlazy2
629 roundTripTest -g516K 19   # btopt
630
631 fileRoundTripTest -g500K
632
633 $ECHO "\n===>  zstd long distance matching round-trip tests "
634 roundTripTest -g0 "2 --single-thread --long"
635 roundTripTest -g1000K "1 --single-thread --long"
636 roundTripTest -g517K "6 --single-thread --long"
637 roundTripTest -g516K "16 --single-thread --long"
638 roundTripTest -g518K "19 --single-thread --long"
639 fileRoundTripTest -g5M "3 --single-thread --long"
640
641
642 roundTripTest -g96K "5 --single-thread"
643 if [ -n "$hasMT" ]
644 then
645     $ECHO "\n===>  zstdmt round-trip tests "
646     roundTripTest -g4M "1 -T0"
647     roundTripTest -g8M "3 -T2"
648     roundTripTest -g8000K "2 --threads=2"
649     fileRoundTripTest -g4M "19 -T2 -B1M"
650
651     $ECHO "\n===>  zstdmt long distance matching round-trip tests "
652     roundTripTest -g8M "3 --long=24 -T2"
653 else
654     $ECHO "\n===>  no multithreading, skipping zstdmt tests "
655 fi
656
657 rm tmp*
658
659 $ECHO "\n===>  zstd --list/-l single frame tests "
660 ./datagen > tmp1
661 ./datagen > tmp2
662 ./datagen > tmp3
663 $ZSTD tmp*
664 $ZSTD -l *.zst
665 $ZSTD -lv *.zst | grep "Decompressed Size:"  # check that decompressed size is present in header
666 $ZSTD --list *.zst
667 $ZSTD --list -v *.zst
668
669 $ECHO "\n===>  zstd --list/-l multiple frame tests "
670 cat tmp1.zst tmp2.zst > tmp12.zst
671 cat tmp12.zst tmp3.zst > tmp123.zst
672 $ZSTD -l *.zst
673 $ZSTD -lv *.zst
674
675 $ECHO "\n===>  zstd --list/-l error detection tests "
676 ! $ZSTD -l tmp1 tmp1.zst
677 ! $ZSTD --list tmp*
678 ! $ZSTD -lv tmp1*
679 ! $ZSTD --list -v tmp2 tmp12.zst
680
681 $ECHO "\n===>  zstd --list/-l test with null files "
682 ./datagen -g0 > tmp5
683 $ZSTD tmp5
684 $ZSTD -l tmp5.zst
685 ! $ZSTD -l tmp5*
686 $ZSTD -lv tmp5.zst | grep "Decompressed Size: 0.00 KB (0 B)"  # check that 0 size is present in header
687 ! $ZSTD -lv tmp5*
688
689 $ECHO "\n===>  zstd --list/-l test with no content size field "
690 ./datagen -g513K | $ZSTD > tmp6.zst
691 $ZSTD -l tmp6.zst
692 ! $ZSTD -lv tmp6.zst | grep "Decompressed Size:"  # must NOT be present in header
693
694 $ECHO "\n===>   zstd --list/-l test with no checksum "
695 $ZSTD -f --no-check tmp1
696 $ZSTD -l tmp1.zst
697 $ZSTD -lv tmp1.zst
698
699 rm tmp*
700
701
702 $ECHO "\n===>   zstd long distance matching tests "
703 roundTripTest -g0 " --single-thread --long"
704 roundTripTest -g9M "2 --single-thread --long"
705 # Test parameter parsing
706 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --memory=512MB"
707 roundTripTest -g1M -P50 "1 --single-thread --long=29 --zstd=wlog=28" " --memory=256MB"
708 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --long=28 --memory=512MB"
709 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --zstd=wlog=28 --memory=512MB"
710
711
712 if [ "$1" != "--test-large-data" ]; then
713     $ECHO "Skipping large data tests"
714     exit 0
715 fi
716
717 $ECHO "\n===>   large files tests "
718
719 roundTripTest -g270000000 1
720 roundTripTest -g250000000 2
721 roundTripTest -g230000000 3
722
723 roundTripTest -g140000000 -P60 4
724 roundTripTest -g130000000 -P62 5
725 roundTripTest -g120000000 -P65 6
726
727 roundTripTest -g70000000 -P70 7
728 roundTripTest -g60000000 -P71 8
729 roundTripTest -g50000000 -P73 9
730
731 roundTripTest -g35000000 -P75 10
732 roundTripTest -g30000000 -P76 11
733 roundTripTest -g25000000 -P78 12
734
735 roundTripTest -g18000013 -P80 13
736 roundTripTest -g18000014 -P80 14
737 roundTripTest -g18000015 -P81 15
738 roundTripTest -g18000016 -P84 16
739 roundTripTest -g18000017 -P88 17
740 roundTripTest -g18000018 -P94 18
741 roundTripTest -g18000019 -P96 19
742
743 roundTripTest -g5000000000 -P99 1
744 roundTripTest -g1700000000 -P0 "1 --zstd=strategy=6"   # ensure btlazy2 can survive an overflow rescale
745
746 fileRoundTripTest -g4193M -P99 1
747
748
749 $ECHO "\n===>   zstd long, long distance matching round-trip tests "
750 roundTripTest -g270000000 "1 --single-thread --long"
751 roundTripTest -g130000000 -P60 "5 --single-thread --long"
752 roundTripTest -g35000000 -P70 "8 --single-thread --long"
753 roundTripTest -g18000001 -P80  "18 --single-thread --long"
754 # Test large window logs
755 roundTripTest -g700M -P50 "1 --single-thread --long=29"
756 roundTripTest -g600M -P50 "1 --single-thread --long --zstd=wlog=29,clog=28"
757
758
759 if [ -n "$hasMT" ]
760 then
761     $ECHO "\n===>   zstdmt long round-trip tests "
762     roundTripTest -g80000000 -P99 "19 -T2" " "
763     roundTripTest -g5000000000 -P99 "1 -T2" " "
764     roundTripTest -g500000000 -P97 "1 -T999" " "
765     fileRoundTripTest -g4103M -P98 " -T0" " "
766     roundTripTest -g400000000 -P97 "1 --long=24 -T2" " "
767 else
768     $ECHO "\n**** no multithreading, skipping zstdmt tests **** "
769 fi
770
771 rm tmp*