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
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
52 dd bs=1 count=$(($(wc -c < "$1") - 1)) if="$1" status=none
58 if [ -t 0 ] && [ -t 1 ]
66 GNU) DEVDEVICE="/dev/random" ;;
67 *) DEVDEVICE="/dev/zero" ;;
78 Darwin) MD5SUM="md5 -r" ;;
79 FreeBSD) MD5SUM="gmd5sum" ;;
80 OpenBSD) MD5SUM="md5" ;;
86 SunOS) DIFF="gdiff" ;;
91 Darwin) ECHO="echo" ;;
94 $ECHO "\nStarting playTests.sh isWindows=$isWindows ZSTD='$ZSTD'"
96 [ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
98 if [ -n "$(echo hello | $ZSTD -v -T2 2>&1 > $INTOVOID | grep 'multi-threading is disabled')" ]
107 $ECHO "\n===> simple tests "
110 $ECHO "test : basic compression "
111 $ZSTD -f tmp # trivial compression case, creates tmp.zst
112 $ECHO "test : basic decompression"
113 $ZSTD -df tmp.zst # trivial decompression case (overwrites tmp)
114 $ECHO "test : too large compression level => auto-fix"
115 $ZSTD -99 -f tmp # too large compression level, automatic sized down
116 $ZSTD -5000000000 -f tmp && die "too large numeric value : must fail"
117 $ECHO "test : --fast aka negative compression levels"
118 $ZSTD --fast -f tmp # == -1
119 $ZSTD --fast=3 -f tmp # == -3
120 $ZSTD --fast=200000 -f tmp # too low compression level, automatic fixed
121 $ZSTD --fast=5000000000 -f tmp && die "too large numeric value : must fail"
122 $ZSTD -c --fast=0 tmp > $INTOVOID && die "--fast must not accept value 0"
123 $ECHO "test : too large numeric argument"
124 $ZSTD --fast=9999999999 -f tmp && die "should have refused numeric value"
125 $ECHO "test : set compression level with environment variable ZSTD_CLEVEL"
126 ZSTD_CLEVEL=12 $ZSTD -f tmp # positive compression level
127 ZSTD_CLEVEL=-12 $ZSTD -f tmp # negative compression level
128 ZSTD_CLEVEL=+12 $ZSTD -f tmp # valid: verbose '+' sign
129 ZSTD_CLEVEL= $ZSTD -f tmp # empty env var, warn and revert to default setting
130 ZSTD_CLEVEL=- $ZSTD -f tmp # malformed env var, warn and revert to default setting
131 ZSTD_CLEVEL=a $ZSTD -f tmp # malformed env var, warn and revert to default setting
132 ZSTD_CLEVEL=+a $ZSTD -f tmp # malformed env var, warn and revert to default setting
133 ZSTD_CLEVEL=3a7 $ZSTD -f tmp # malformed env var, warn and revert to default setting
134 ZSTD_CLEVEL=50000000000 $ZSTD -f tmp # numeric value too large, warn and revert to default setting
135 $ECHO "test : override ZSTD_CLEVEL with command line option"
136 ZSTD_CLEVEL=12 $ZSTD --fast=3 -f tmp # overridden by command line option
137 $ECHO "test : compress to stdout"
138 $ZSTD tmp -c > tmpCompressed
139 $ZSTD tmp --stdout > tmpCompressed # long command format
140 $ECHO "test : compress to named file"
142 $ZSTD tmp -o tmpCompressed
143 test -f tmpCompressed # file must be created
144 $ECHO "test : -o must be followed by filename (must fail)"
145 $ZSTD tmp -of tmpCompressed && die "-o must be followed by filename "
146 $ECHO "test : force write, correct order"
147 $ZSTD tmp -fo tmpCompressed
148 $ECHO "test : forgotten argument"
150 $ZSTD tmp2 -fo && die "-o must be followed by filename "
151 $ECHO "test : implied stdout when input is stdin"
152 $ECHO bob | $ZSTD | $ZSTD -d
153 if [ "$isTerminal" = true ]; then
154 $ECHO "test : compressed data to terminal"
155 $ECHO bob | $ZSTD && die "should have refused : compressed data to terminal"
156 $ECHO "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)"
157 $ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal"
159 $ECHO "test : null-length file roundtrip"
160 $ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
161 $ECHO "test : ensure small file doesn't add 3-bytes null block"
163 $ZSTD tmp1 -c | wc -c | grep "14"
164 $ZSTD < tmp1 | wc -c | grep "14"
165 $ECHO "test : decompress file with wrong suffix (must fail)"
166 $ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
167 $ZSTD -df tmp && die "should have refused : wrong extension"
168 $ECHO "test : decompress into stdout"
169 $ZSTD -d tmpCompressed -c > tmpResult # decompression using stdout
170 $ZSTD --decompress tmpCompressed -c > tmpResult
171 $ZSTD --decompress tmpCompressed --stdout > tmpResult
172 $ECHO "test : decompress from stdin into stdout"
173 $ZSTD -dc < tmp.zst > $INTOVOID # combine decompression, stdin & stdout
174 $ZSTD -dc - < tmp.zst > $INTOVOID
175 $ZSTD -d < tmp.zst > $INTOVOID # implicit stdout when stdin is used
176 $ZSTD -d - < tmp.zst > $INTOVOID
177 $ECHO "test : impose memory limitation (must fail)"
178 $ZSTD -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
179 $ZSTD -d -f tmp.zst --memlimit=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
180 $ZSTD -d -f tmp.zst --memory=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
181 $ZSTD -d -f tmp.zst --memlimit-decompress=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
182 $ECHO "test : overwrite protection"
183 $ZSTD -q tmp && die "overwrite check failed!"
184 $ECHO "test : force overwrite"
187 $ECHO "test : overwrite readonly file"
188 rm -f tmpro tmpro.zst
189 $ECHO foo > tmpro.zst
192 $ZSTD -q tmpro && die "should have refused to overwrite read-only file"
194 $ECHO "test: --no-progress flag"
195 $ZSTD tmpro -c --no-progress | $ZSTD -d -f -o "$INTOVOID" --no-progress
196 $ZSTD tmpro -cv --no-progress | $ZSTD -dv -f -o "$INTOVOID" --no-progress
197 rm -f tmpro tmpro.zst
198 $ECHO "test: overwrite input file (must fail)"
199 $ZSTD tmp -fo tmp && die "zstd compression overwrote the input file"
200 $ZSTD tmp.zst -dfo tmp.zst && die "zstd decompression overwrote the input file"
201 $ECHO "test: detect that input file does not exist"
202 $ZSTD nothere && die "zstd hasn't detected that input file does not exist"
204 $ECHO "test : file removal"
206 test ! -f tmp # tmp should no longer be present
207 $ZSTD -f -d --rm tmp.zst
208 test ! -f tmp.zst # tmp.zst should no longer be present
209 $ECHO "test : should quietly not remove non-regular file"
211 $ZSTD tmp -f -o "$DEVDEVICE" 2>tmplog > "$INTOVOID"
212 grep -v "Refusing to remove non-regular file" tmplog
214 $ZSTD tmp -f -o "$INTOVOID" 2>&1 | grep -v "Refusing to remove non-regular file"
215 $ECHO "test : --rm on stdin"
216 $ECHO a | $ZSTD --rm > $INTOVOID # --rm should remain silent
218 $ZSTD -f tmp && die "tmp not present : should have failed"
219 test ! -f tmp.zst # tmp.zst should not be created
220 $ECHO "test : -d -f do not delete destination when source is not present"
221 touch tmp # create destination file
222 $ZSTD -d -f tmp.zst && die "attempt to decompress a non existing file"
223 test -f tmp # destination file should still be present
224 $ECHO "test : -f do not delete destination when source is not present"
225 rm tmp # erase source file
226 touch tmp.zst # create destination file
227 $ZSTD -f tmp && die "attempt to compress a non existing file"
228 test -f tmp.zst # destination file should still be present
232 $ECHO "test : compress multiple files"
235 $ZSTD tmp1 tmp2 -o "$INTOVOID" -f
236 $ZSTD tmp1 tmp2 -c | $ZSTD -t
237 $ZSTD tmp1 tmp2 -o tmp.zst
241 $ZSTD -t tmp1.zst tmp2.zst
242 $ZSTD -dc tmp1.zst tmp2.zst
243 $ZSTD tmp1.zst tmp2.zst -o "$INTOVOID" -f
244 $ZSTD -d tmp1.zst tmp2.zst -o tmp
246 $ZSTD tmp1 tmp2 -f -o tmpexists
247 $ZSTD tmp1 tmp2 -o tmpexists && die "should have refused to overwrite"
249 if [ "$?" -eq 139 ]; then
250 die "should not have segfaulted"
255 $ECHO "\n===> Advanced compression parameters "
256 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21, - -o tmp.zst && die "wrong parameters not detected!"
257 $ECHO "Hello world!" | $ZSTD --zstd=windowLo=21 - -o tmp.zst && die "wrong parameters not detected!"
258 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,slog - -o tmp.zst && die "wrong parameters not detected!"
259 $ECHO "Hello world!" | $ZSTD --zstd=strategy=10 - -o tmp.zst && die "parameter out of bound not detected!" # > btultra2 : does not exist
260 test ! -f tmp.zst # tmp.zst should not be created
262 roundTripTest -g512K " --zstd=mml=3,tlen=48,strat=6"
263 roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
264 roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,minMatch=3,targetLength=48,strategy=6"
265 roundTripTest -g512K " --single-thread --long --zstd=ldmHashLog=20,ldmMinMatch=64,ldmBucketSizeLog=1,ldmHashRateLog=7"
266 roundTripTest -g512K " --single-thread --long --zstd=lhlog=20,lmml=64,lblog=1,lhrlog=7"
267 roundTripTest -g64K "19 --zstd=strat=9" # btultra2
270 $ECHO "\n===> Pass-Through mode "
271 $ECHO "Hello world 1!" | $ZSTD -df
272 $ECHO "Hello world 2!" | $ZSTD -dcf
273 $ECHO "Hello world 3!" > tmp1
277 $ECHO "\n===> frame concatenation "
279 $ECHO "hello " > hello.tmp
280 $ECHO "world!" > world.tmp
281 cat hello.tmp world.tmp > helloworld.tmp
282 $ZSTD -c hello.tmp > hello.zstd
283 $ZSTD -c world.tmp > world.zstd
284 cat hello.zstd world.zstd > helloworld.zstd
285 $ZSTD -dc helloworld.zstd > result.tmp
287 $DIFF helloworld.tmp result.tmp
288 $ECHO "frame concatenation without checksum"
289 $ZSTD -c hello.tmp > hello.zstd --no-check
290 $ZSTD -c world.tmp > world.zstd --no-check
291 cat hello.zstd world.zstd > helloworld.zstd
292 $ZSTD -dc helloworld.zstd > result.tmp
293 $DIFF helloworld.tmp result.tmp
294 $ECHO "testing zstdcat symlink"
296 ./zstdcat helloworld.zstd > result.tmp
297 $DIFF helloworld.tmp result.tmp
300 $ECHO "testing zcat symlink"
302 ./zcat helloworld.zstd > result.tmp
303 $DIFF helloworld.tmp result.tmp
306 $ECHO "frame concatenation tests completed"
309 if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] && [ "$UNAME" != "OpenBSD" ] ; then
310 $ECHO "\n**** flush write error test **** "
312 $ECHO "$ECHO foo | $ZSTD > /dev/full"
313 $ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
314 $ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
315 $ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
318 $ECHO "\n===> symbolic link test "
320 rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
321 $ECHO "hello world" > hello.tmp
322 ln -s hello.tmp world.tmp
323 $ZSTD world.tmp hello.tmp
324 test -f hello.tmp.zst # regular file should have been compressed!
325 test ! -f world.tmp.zst # symbolic link should not have been compressed!
326 $ZSTD world.tmp hello.tmp -f
327 test -f world.tmp.zst # symbolic link should have been compressed with --force
328 rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
333 $ECHO "\n===> test sparse file support "
335 ./datagen -g5M -P100 > tmpSparse
336 $ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
337 $DIFF -s tmpSparse tmpSparseRegen
338 $ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
339 $DIFF -s tmpSparse tmpOutSparse
340 $ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
341 $DIFF -s tmpSparse tmpOutNoSparse
342 ls -ls tmpSparse* # look at file size and block size on disk
343 ./datagen -s1 -g1200007 -P100 | $ZSTD | $ZSTD -dv --sparse -c > tmpSparseOdd # Odd size file (to not finish on an exact nb of blocks)
344 ./datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
345 ls -ls tmpSparseOdd # look at file size and block size on disk
346 $ECHO "\n Sparse Compatibility with Console :"
347 $ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
348 $ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
349 $ECHO "\n Sparse Compatibility with Append :"
350 ./datagen -P100 -g1M > tmpSparse1M
351 cat tmpSparse1M tmpSparse1M > tmpSparse2M
352 $ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
353 $ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
354 $ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
355 ls -ls tmpSparse* # look at file size and block size on disk
356 $DIFF tmpSparse2M tmpSparseRegenerated
360 $ECHO "\n===> multiple files tests "
362 ./datagen -s1 > tmp1 2> $INTOVOID
363 ./datagen -s2 -g100K > tmp2 2> $INTOVOID
364 ./datagen -s3 -g1M > tmp3 2> $INTOVOID
365 $ECHO "compress tmp* : "
369 $ECHO "decompress tmp* : "
372 $ECHO "compress tmp* into stdout > tmpall : "
373 $ZSTD -c tmp1 tmp2 tmp3 > tmpall
374 ls -ls tmp* # check size of tmpall (should be tmp1.zst + tmp2.zst + tmp3.zst)
375 $ECHO "decompress tmpall* into stdout > tmpdec : "
377 $ZSTD -dc tmpall* > tmpdec
378 ls -ls tmp* # check size of tmpdec (should be 2*(tmp1 + tmp2 + tmp3))
379 $ECHO "compress multiple files including a missing one (notHere) : "
380 $ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
383 $ECHO "\n===> dictionary tests "
385 $ECHO "- test with raw dict (content only) "
387 ./datagen -g1M | $MD5SUM > tmp1
388 ./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
390 $ECHO "- Create first dictionary "
391 TESTFILE=../programs/zstdcli.c
392 $ZSTD --train *.c ../programs/*.c -o tmpDict
394 $ECHO "- Dictionary compression roundtrip"
395 $ZSTD -f tmp -D tmpDict
396 $ZSTD -d tmp.zst -D tmpDict -fo result
397 $DIFF $TESTFILE result
398 $ECHO "- Dictionary compression with btlazy2 strategy"
399 $ZSTD -f tmp -D tmpDict --zstd=strategy=6
400 $ZSTD -d tmp.zst -D tmpDict -fo result
401 $DIFF $TESTFILE result
404 $ECHO "- Test dictionary compression with multithreading "
405 ./datagen -g5M | $ZSTD -T2 -D tmpDict | $ZSTD -t -D tmpDict # fails with v1.3.2
407 $ECHO "- Create second (different) dictionary "
408 $ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
409 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
410 $ECHO "- Create dictionary with short dictID"
411 $ZSTD --train *.c ../programs/*.c --dictID=1 -o tmpDict1
412 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
413 $ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
414 $ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
415 $ECHO "- Create dictionary with size limit"
416 $ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict=4K -v
417 $ECHO "- Create dictionary with small size limit"
418 $ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict=1K -v
419 $ECHO "- Create dictionary with wrong parameter order (must fail)"
420 $ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict -v 4K && die "wrong order : --maxdict must be followed by argument "
421 $ECHO "- Compress without dictID"
422 $ZSTD -f tmp -D tmpDict1 --no-dictID
423 $ZSTD -d tmp.zst -D tmpDict -fo result
424 $DIFF $TESTFILE result
425 $ECHO "- Compress with wrong argument order (must fail)"
426 $ZSTD tmp -Df tmpDict1 -c > $INTOVOID && die "-D must be followed by dictionary name "
427 $ECHO "- Compress multiple files with dictionary"
431 cp ../programs/*.c dirTestDict
432 cp ../programs/*.h dirTestDict
433 $MD5SUM dirTestDict/* > tmph1
434 $ZSTD -f --rm dirTestDict/* -D tmpDictC
435 $ZSTD -d --rm dirTestDict/*.zst -D tmpDictC # note : use internal checksum by default
437 Darwin) $ECHO "md5sum -c not supported on OS-X : test skipped" ;; # not compatible with OS-X's md5
438 *) $MD5SUM -c tmph1 ;;
441 $ECHO "- dictionary builder on bogus input"
442 $ECHO "Hello World" > tmp
443 $ZSTD --train-legacy -q tmp && die "Dictionary training should fail : not enough input source"
444 ./datagen -P0 -g10M > tmp
445 $ZSTD --train-legacy -q tmp && die "Dictionary training should fail : source is pure noise"
446 $ECHO "- Test -o before --train"
447 rm -f tmpDict dictionary
448 $ZSTD -o tmpDict --train *.c ../programs/*.c
450 $ZSTD --train *.c ../programs/*.c
455 $ECHO "\n===> fastCover dictionary builder : advanced options "
457 TESTFILE=../programs/zstdcli.c
459 $ECHO "- Create first dictionary"
460 $ZSTD --train-fastcover=k=46,d=8,f=15,split=80 *.c ../programs/*.c -o tmpDict
462 $ZSTD -f tmp -D tmpDict
463 $ZSTD -d tmp.zst -D tmpDict -fo result
464 $DIFF $TESTFILE result
465 $ECHO "- Create second (different) dictionary"
466 $ZSTD --train-fastcover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
467 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
468 $ECHO "- Create dictionary with short dictID"
469 $ZSTD --train-fastcover=k=46,d=8,f=15,split=80 *.c ../programs/*.c --dictID=1 -o tmpDict1
470 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
471 $ECHO "- Create dictionary with size limit"
472 $ZSTD --train-fastcover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
473 $ECHO "- Compare size of dictionary from 90% training samples with 80% training samples"
474 $ZSTD --train-fastcover=split=90 -r *.c ../programs/*.c
475 $ZSTD --train-fastcover=split=80 -r *.c ../programs/*.c
476 $ECHO "- Create dictionary using all samples for both training and testing"
477 $ZSTD --train-fastcover=split=100 -r *.c ../programs/*.c
478 $ECHO "- Create dictionary using f=16"
479 $ZSTD --train-fastcover=f=16 -r *.c ../programs/*.c
480 $ECHO "- Create dictionary using accel=2"
481 $ZSTD --train-fastcover=accel=2 -r *.c ../programs/*.c
482 $ECHO "- Create dictionary using accel=10"
483 $ZSTD --train-fastcover=accel=10 -r *.c ../programs/*.c
484 $ECHO "- Create dictionary with multithreading"
485 $ZSTD --train-fastcover -T4 -r *.c ../programs/*.c
486 $ECHO "- Test -o before --train-fastcover"
487 rm -f tmpDict dictionary
488 $ZSTD -o tmpDict --train-fastcover *.c ../programs/*.c
490 $ZSTD --train-fastcover *.c ../programs/*.c
495 $ECHO "\n===> legacy dictionary builder "
497 TESTFILE=../programs/zstdcli.c
499 $ECHO "- Create first dictionary"
500 $ZSTD --train-legacy=selectivity=8 *.c ../programs/*.c -o tmpDict
502 $ZSTD -f tmp -D tmpDict
503 $ZSTD -d tmp.zst -D tmpDict -fo result
504 $DIFF $TESTFILE result
505 $ECHO "- Create second (different) dictionary"
506 $ZSTD --train-legacy=s=5 *.c ../programs/*.c ../programs/*.h -o tmpDictC
507 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
508 $ECHO "- Create dictionary with short dictID"
509 $ZSTD --train-legacy -s5 *.c ../programs/*.c --dictID=1 -o tmpDict1
510 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
511 $ECHO "- Create dictionary with size limit"
512 $ZSTD --train-legacy -s9 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
513 $ECHO "- Test -o before --train-legacy"
514 rm -f tmpDict dictionary
515 $ZSTD -o tmpDict --train-legacy *.c ../programs/*.c
517 $ZSTD --train-legacy *.c ../programs/*.c
522 $ECHO "\n===> integrity tests "
524 $ECHO "test one file (tmp1.zst) "
528 $ZSTD --test tmp1.zst
529 $ECHO "test multiple files (*.zst) "
531 $ECHO "test bad files (*) "
532 $ZSTD -t * && die "bad files not detected !"
533 $ZSTD -t tmp1 && die "bad file not detected !"
535 $ZSTD -t tmp2.zst && die "bad file not detected !"
537 $ZSTD -t tmp3 && die "bad file not detected !" # detects 0-sized files as bad
538 $ECHO "test --rm and --test combined "
539 $ZSTD -t --rm tmp1.zst
540 test -f tmp1.zst # check file is still present
541 split -b16384 tmp1.zst tmpSplit.
542 $ZSTD -t tmpSplit.* && die "bad file not detected !"
543 ./datagen | $ZSTD -c | $ZSTD -t
547 $ECHO "\n===> golden files tests "
550 $ZSTD -c -r files | $ZSTD -t
553 $ECHO "\n===> benchmark mode tests "
555 $ECHO "bench one file"
558 $ECHO "bench multiple levels"
560 $ECHO "bench negative level"
561 $ZSTD -bi0 --fast tmp1
562 $ECHO "with recursive and quiet modes"
564 $ECHO "benchmark decompression only"
566 $ZSTD -b -d -i1 tmp1.zst
568 $ECHO "\n===> zstd compatibility tests "
572 $ZSTD --format=zstd -f tmp
575 $ECHO "\n===> gzip compatibility tests "
578 $ZSTD --format=gzip -V || GZIPMODE=0
579 if [ $GZIPMODE -eq 1 ]; then
580 $ECHO "gzip support detected"
583 if [ $GZIPEXE -eq 1 ]; then
585 $ZSTD --format=gzip -f tmp
588 $ZSTD -d -f -v tmp.gz
591 $ECHO "gzip binary not detected"
594 $ECHO "gzip mode not supported"
598 $ECHO "\n===> gzip frame tests "
600 if [ $GZIPMODE -eq 1 ]; then
602 $ZSTD -f --format=gzip tmp
604 cat tmp.gz tmp.zst tmp.gz tmp.zst | $ZSTD -d -f -o tmp
605 truncateLastByte tmp.gz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
608 $ECHO "gzip mode not supported"
611 if [ $GZIPMODE -eq 1 ]; then
614 $ZSTD --format=gzip --format=zstd -f tmp
618 $ECHO "\n===> xz compatibility tests "
621 $ZSTD --format=xz -V || LZMAMODE=0
622 if [ $LZMAMODE -eq 1 ]; then
623 $ECHO "xz support detected"
625 xz -Q -V && lzma -Q -V || XZEXE=0
626 if [ $XZEXE -eq 1 ]; then
627 $ECHO "Testing zstd xz and lzma support"
629 $ZSTD --format=lzma -f tmp
630 $ZSTD --format=xz -f tmp
634 lzma -Q -f -k --lzma1 tmp
635 $ZSTD -d -f -v tmp.xz
636 $ZSTD -d -f -v tmp.lzma
638 $ECHO "Creating symlinks"
643 $ECHO "Testing xz and lzma symlinks"
649 $ECHO "Testing unxz and unlzma symlinks"
654 rm xz unxz lzma unlzma
657 $ECHO "xz binary not detected"
660 $ECHO "xz mode not supported"
664 $ECHO "\n===> xz frame tests "
666 if [ $LZMAMODE -eq 1 ]; then
668 $ZSTD -f --format=xz tmp
669 $ZSTD -f --format=lzma tmp
671 cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | $ZSTD -d -f -o tmp
672 truncateLastByte tmp.xz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
673 truncateLastByte tmp.lzma | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
676 $ECHO "xz mode not supported"
679 $ECHO "\n===> lz4 compatibility tests "
682 $ZSTD --format=lz4 -V || LZ4MODE=0
683 if [ $LZ4MODE -eq 1 ]; then
684 $ECHO "lz4 support detected"
687 if [ $LZ4EXE -eq 1 ]; then
689 $ZSTD --format=lz4 -f tmp
692 $ZSTD -d -f -v tmp.lz4
695 $ECHO "lz4 binary not detected"
698 $ECHO "lz4 mode not supported"
702 $ECHO "\n===> lz4 frame tests "
704 if [ $LZ4MODE -eq 1 ]; then
706 $ZSTD -f --format=lz4 tmp
708 cat tmp.lz4 tmp.zst tmp.lz4 tmp.zst | $ZSTD -d -f -o tmp
709 truncateLastByte tmp.lz4 | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
712 $ECHO "lz4 mode not supported"
715 $ECHO "\n===> suffix list test"
717 ! $ZSTD -d tmp.abc 2> tmplg
719 if [ $GZIPMODE -ne 1 ]; then
720 grep ".gz" tmplg > $INTOVOID && die "Unsupported suffix listed"
723 if [ $LZMAMODE -ne 1 ]; then
724 grep ".lzma" tmplg > $INTOVOID && die "Unsupported suffix listed"
725 grep ".xz" tmplg > $INTOVOID && die "Unsupported suffix listed"
728 if [ $LZ4MODE -ne 1 ]; then
729 grep ".lz4" tmplg > $INTOVOID && die "Unsupported suffix listed"
732 $ECHO "\n===> zstd round-trip tests "
735 roundTripTest -g15K # TableID==3
736 roundTripTest -g127K # TableID==2
737 roundTripTest -g255K # TableID==1
738 roundTripTest -g522K # TableID==0
739 roundTripTest -g519K 6 # greedy, hash chain
740 roundTripTest -g517K 16 # btlazy2
741 roundTripTest -g516K 19 # btopt
743 fileRoundTripTest -g500K
745 $ECHO "\n===> zstd long distance matching round-trip tests "
746 roundTripTest -g0 "2 --single-thread --long"
747 roundTripTest -g1000K "1 --single-thread --long"
748 roundTripTest -g517K "6 --single-thread --long"
749 roundTripTest -g516K "16 --single-thread --long"
750 roundTripTest -g518K "19 --single-thread --long"
751 fileRoundTripTest -g5M "3 --single-thread --long"
754 roundTripTest -g96K "5 --single-thread"
757 $ECHO "\n===> zstdmt round-trip tests "
758 roundTripTest -g4M "1 -T0"
759 roundTripTest -g8M "3 -T2"
760 roundTripTest -g8000K "2 --threads=2"
761 fileRoundTripTest -g4M "19 -T2 -B1M"
763 $ECHO "\n===> zstdmt long distance matching round-trip tests "
764 roundTripTest -g8M "3 --long=24 -T2"
766 $ECHO "\n===> ovLog tests "
767 ./datagen -g2MB > tmp
768 refSize=$($ZSTD tmp -6 -c --zstd=wlog=18 | wc -c)
769 ov9Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=9 | wc -c)
770 ov1Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=1 | wc -c)
771 if [ $refSize -eq $ov9Size ]; then
772 echo ov9Size should be different from refSize
775 if [ $refSize -eq $ov1Size ]; then
776 echo ov1Size should be different from refSize
779 if [ $ov9Size -ge $ov1Size ]; then
780 echo ov9Size=$ov9Size should be smaller than ov1Size=$ov1Size
785 $ECHO "\n===> no multithreading, skipping zstdmt tests "
790 $ECHO "\n===> zstd --list/-l single frame tests "
796 $ZSTD -lv *.zst | grep "Decompressed Size:" # check that decompressed size is present in header
798 $ZSTD --list -v *.zst
800 $ECHO "\n===> zstd --list/-l multiple frame tests "
801 cat tmp1.zst tmp2.zst > tmp12.zst
802 cat tmp12.zst tmp3.zst > tmp123.zst
806 $ECHO "\n===> zstd --list/-l error detection tests "
807 $ZSTD -l tmp1 tmp1.zst && die "-l must fail on non-zstd file"
808 $ZSTD --list tmp* && die "-l must fail on non-zstd file"
809 $ZSTD -lv tmp1* && die "-l must fail on non-zstd file"
810 $ZSTD --list -v tmp2 tmp12.zst && die "-l must fail on non-zstd file"
812 $ECHO "\n===> zstd --list/-l errors when presented with stdin / no files"
813 $ZSTD -l && die "-l must fail on empty list of files"
814 $ZSTD -l - && die "-l does not work on stdin"
815 $ZSTD -l < tmp1.zst && die "-l does not work on stdin"
816 $ZSTD -l - < tmp1.zst && die "-l does not work on stdin"
817 $ZSTD -l - tmp1.zst && die "-l does not work on stdin"
818 $ZSTD -l - tmp1.zst < tmp1.zst && die "-l does not work on stdin"
819 $ZSTD -l tmp1.zst < tmp2.zst # this will check tmp1.zst, but not tmp2.zst, which is not an error : zstd simply doesn't read stdin in this case. It must not error just because stdin is not a tty
821 $ECHO "\n===> zstd --list/-l test with null files "
825 $ZSTD -l tmp5* && die "-l must fail on non-zstd file"
826 $ZSTD -lv tmp5.zst | grep "Decompressed Size: 0.00 KB (0 B)" # check that 0 size is present in header
827 $ZSTD -lv tmp5* && die "-l must fail on non-zstd file"
829 $ECHO "\n===> zstd --list/-l test with no content size field "
830 ./datagen -g513K | $ZSTD > tmp6.zst
832 $ZSTD -lv tmp6.zst | grep "Decompressed Size:" && die "Field :Decompressed Size: should not be available in this compressed file"
834 $ECHO "\n===> zstd --list/-l test with no checksum "
835 $ZSTD -f --no-check tmp1
842 $ECHO "\n===> zstd long distance matching tests "
843 roundTripTest -g0 " --single-thread --long"
844 roundTripTest -g9M "2 --single-thread --long"
845 # Test parameter parsing
846 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --memory=512MB"
847 roundTripTest -g1M -P50 "1 --single-thread --long=29 --zstd=wlog=28" " --memory=256MB"
848 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --long=28 --memory=512MB"
849 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --zstd=wlog=28 --memory=512MB"
852 $ECHO "\n===> adaptive mode "
853 roundTripTest -g270000000 " --adapt"
854 roundTripTest -g27000000 " --adapt=min=1,max=4"
855 $ECHO "===> test: --adapt must fail on incoherent bounds "
857 $ZSTD -f -vv --adapt=min=10,max=9 tmp && die "--adapt must fail on incoherent bounds"
859 $ECHO "\n===> rsyncable mode "
860 roundTripTest -g10M " --rsyncable"
861 roundTripTest -g10M " --rsyncable -B100K"
862 $ECHO "===> test: --rsyncable must fail with --single-thread"
863 $ZSTD -f -vv --rsyncable --single-thread tmp && die "--rsyncable must fail with --single-thread"
866 if [ "$1" != "--test-large-data" ]; then
867 $ECHO "Skipping large data tests"
872 #############################################################################
874 $ECHO "\n===> large files tests "
876 roundTripTest -g270000000 1
877 roundTripTest -g250000000 2
878 roundTripTest -g230000000 3
880 roundTripTest -g140000000 -P60 4
881 roundTripTest -g130000000 -P62 5
882 roundTripTest -g120000000 -P65 6
884 roundTripTest -g70000000 -P70 7
885 roundTripTest -g60000000 -P71 8
886 roundTripTest -g50000000 -P73 9
888 roundTripTest -g35000000 -P75 10
889 roundTripTest -g30000000 -P76 11
890 roundTripTest -g25000000 -P78 12
892 roundTripTest -g18000013 -P80 13
893 roundTripTest -g18000014 -P80 14
894 roundTripTest -g18000015 -P81 15
895 roundTripTest -g18000016 -P84 16
896 roundTripTest -g18000017 -P88 17
897 roundTripTest -g18000018 -P94 18
898 roundTripTest -g18000019 -P96 19
900 roundTripTest -g5000000000 -P99 1
901 roundTripTest -g1700000000 -P0 "1 --zstd=strategy=6" # ensure btlazy2 can survive an overflow rescale
903 fileRoundTripTest -g4193M -P99 1
906 $ECHO "\n===> zstd long, long distance matching round-trip tests "
907 roundTripTest -g270000000 "1 --single-thread --long"
908 roundTripTest -g130000000 -P60 "5 --single-thread --long"
909 roundTripTest -g35000000 -P70 "8 --single-thread --long"
910 roundTripTest -g18000001 -P80 "18 --single-thread --long"
911 # Test large window logs
912 roundTripTest -g700M -P50 "1 --single-thread --long=29"
913 roundTripTest -g600M -P50 "1 --single-thread --long --zstd=wlog=29,clog=28"
918 $ECHO "\n===> zstdmt long round-trip tests "
919 roundTripTest -g80000000 -P99 "19 -T2" " "
920 roundTripTest -g5000000000 -P99 "1 -T2" " "
921 roundTripTest -g500000000 -P97 "1 -T999" " "
922 fileRoundTripTest -g4103M -P98 " -T0" " "
923 roundTripTest -g400000000 -P97 "1 --long=24 -T2" " "
925 $ECHO "\n**** no multithreading, skipping zstdmt tests **** "
929 $ECHO "\n===> cover dictionary builder : advanced options "
931 TESTFILE=../programs/zstdcli.c
933 $ECHO "- Create first dictionary"
934 $ZSTD --train-cover=k=46,d=8,split=80 *.c ../programs/*.c -o tmpDict
936 $ZSTD -f tmp -D tmpDict
937 $ZSTD -d tmp.zst -D tmpDict -fo result
938 $DIFF $TESTFILE result
939 $ECHO "- Create second (different) dictionary"
940 $ZSTD --train-cover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
941 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
942 $ECHO "- Create dictionary with short dictID"
943 $ZSTD --train-cover=k=46,d=8,split=80 *.c ../programs/*.c --dictID=1 -o tmpDict1
944 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
945 $ECHO "- Create dictionary with size limit"
946 $ZSTD --train-cover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
947 $ECHO "- Compare size of dictionary from 90% training samples with 80% training samples"
948 $ZSTD --train-cover=split=90 -r *.c ../programs/*.c
949 $ZSTD --train-cover=split=80 -r *.c ../programs/*.c
950 $ECHO "- Create dictionary using all samples for both training and testing"
951 $ZSTD --train-cover=split=100 -r *.c ../programs/*.c
952 $ECHO "- Test -o before --train-cover"
953 rm -f tmpDict dictionary
954 $ZSTD -o tmpDict --train-cover *.c ../programs/*.c
956 $ZSTD --train-cover *.c ../programs/*.c
958 rm -f tmp* dictionary