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 : compress to stdout"
126 $ZSTD tmp -c > tmpCompressed
127 $ZSTD tmp --stdout > tmpCompressed # long command format
128 $ECHO "test : compress to named file"
130 $ZSTD tmp -o tmpCompressed
131 test -f tmpCompressed # file must be created
132 $ECHO "test : -o must be followed by filename (must fail)"
133 $ZSTD tmp -of tmpCompressed && die "-o must be followed by filename "
134 $ECHO "test : force write, correct order"
135 $ZSTD tmp -fo tmpCompressed
136 $ECHO "test : forgotten argument"
138 $ZSTD tmp2 -fo && die "-o must be followed by filename "
139 $ECHO "test : implied stdout when input is stdin"
140 $ECHO bob | $ZSTD | $ZSTD -d
141 if [ "$isTerminal" = true ]; then
142 $ECHO "test : compressed data to terminal"
143 $ECHO bob | $ZSTD && die "should have refused : compressed data to terminal"
144 $ECHO "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)"
145 $ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal"
147 $ECHO "test : null-length file roundtrip"
148 $ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
149 $ECHO "test : ensure small file doesn't add 3-bytes null block"
151 $ZSTD tmp1 -c | wc -c | grep "14"
152 $ZSTD < tmp1 | wc -c | grep "14"
153 $ECHO "test : decompress file with wrong suffix (must fail)"
154 $ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
155 $ZSTD -df tmp && die "should have refused : wrong extension"
156 $ECHO "test : decompress into stdout"
157 $ZSTD -d tmpCompressed -c > tmpResult # decompression using stdout
158 $ZSTD --decompress tmpCompressed -c > tmpResult
159 $ZSTD --decompress tmpCompressed --stdout > tmpResult
160 $ECHO "test : decompress from stdin into stdout"
161 $ZSTD -dc < tmp.zst > $INTOVOID # combine decompression, stdin & stdout
162 $ZSTD -dc - < tmp.zst > $INTOVOID
163 $ZSTD -d < tmp.zst > $INTOVOID # implicit stdout when stdin is used
164 $ZSTD -d - < tmp.zst > $INTOVOID
165 $ECHO "test : impose memory limitation (must fail)"
166 $ZSTD -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
167 $ZSTD -d -f tmp.zst --memlimit=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
168 $ZSTD -d -f tmp.zst --memory=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
169 $ZSTD -d -f tmp.zst --memlimit-decompress=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
170 $ECHO "test : overwrite protection"
171 $ZSTD -q tmp && die "overwrite check failed!"
172 $ECHO "test : force overwrite"
175 $ECHO "test : overwrite readonly file"
176 rm -f tmpro tmpro.zst
177 $ECHO foo > tmpro.zst
180 $ZSTD -q tmpro && die "should have refused to overwrite read-only file"
182 rm -f tmpro tmpro.zst
185 $ECHO "test : file removal"
187 test ! -f tmp # tmp should no longer be present
188 $ZSTD -f -d --rm tmp.zst
189 test ! -f tmp.zst # tmp.zst should no longer be present
190 $ECHO "test : should quietly not remove non-regular file"
192 $ZSTD tmp -f -o "$DEVDEVICE" 2>tmplog > "$INTOVOID"
193 grep -v "Refusing to remove non-regular file" tmplog
195 $ZSTD tmp -f -o "$INTOVOID" 2>&1 | grep -v "Refusing to remove non-regular file"
196 $ECHO "test : --rm on stdin"
197 $ECHO a | $ZSTD --rm > $INTOVOID # --rm should remain silent
199 $ZSTD -f tmp && die "tmp not present : should have failed"
200 test ! -f tmp.zst # tmp.zst should not be created
201 $ECHO "test : -d -f do not delete destination when source is not present"
202 touch tmp # create destination file
203 $ZSTD -d -f tmp.zst && die "attempt to decompress a non existing file"
204 test -f tmp # destination file should still be present
205 $ECHO "test : -f do not delete destination when source is not present"
206 rm tmp # erase source file
207 touch tmp.zst # create destination file
208 $ZSTD -f tmp && die "attempt to compress a non existing file"
209 test -f tmp.zst # destination file should still be present
213 $ECHO "test : compress multiple files"
216 $ZSTD tmp1 tmp2 -o "$INTOVOID"
217 $ZSTD tmp1 tmp2 -c | $ZSTD -t
218 $ZSTD tmp1 tmp2 -o tmp.zst
222 $ZSTD -t tmp1.zst tmp2.zst
223 $ZSTD -dc tmp1.zst tmp2.zst
224 $ZSTD tmp1.zst tmp2.zst -o "$INTOVOID"
225 $ZSTD -d tmp1.zst tmp2.zst -o tmp
227 $ZSTD tmp1 tmp2 -f -o tmpexists
228 $ZSTD tmp1 tmp2 -o tmpexists && die "should have refused to overwrite"
230 if [ "$?" -eq 139 ]; then
231 die "should not have segfaulted"
236 $ECHO "\n===> Advanced compression parameters "
237 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21, - -o tmp.zst && die "wrong parameters not detected!"
238 $ECHO "Hello world!" | $ZSTD --zstd=windowLo=21 - -o tmp.zst && die "wrong parameters not detected!"
239 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,slog - -o tmp.zst && die "wrong parameters not detected!"
240 test ! -f tmp.zst # tmp.zst should not be created
242 roundTripTest -g512K " --zstd=slen=3,tlen=48,strat=6"
243 roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
244 roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,searchLength=3,targetLength=48,strategy=6"
245 roundTripTest -g512K " --single-thread --long --zstd=ldmHashLog=20,ldmSearchLength=64,ldmBucketSizeLog=1,ldmHashEveryLog=7"
246 roundTripTest -g512K " --single-thread --long --zstd=ldmhlog=20,ldmslen=64,ldmblog=1,ldmhevery=7"
247 roundTripTest -g512K 19
250 $ECHO "\n===> Pass-Through mode "
251 $ECHO "Hello world 1!" | $ZSTD -df
252 $ECHO "Hello world 2!" | $ZSTD -dcf
253 $ECHO "Hello world 3!" > tmp1
257 $ECHO "\n===> frame concatenation "
259 $ECHO "hello " > hello.tmp
260 $ECHO "world!" > world.tmp
261 cat hello.tmp world.tmp > helloworld.tmp
262 $ZSTD -c hello.tmp > hello.zstd
263 $ZSTD -c world.tmp > world.zstd
264 cat hello.zstd world.zstd > helloworld.zstd
265 $ZSTD -dc helloworld.zstd > result.tmp
267 $DIFF helloworld.tmp result.tmp
268 $ECHO "frame concatenation without checksum"
269 $ZSTD -c hello.tmp > hello.zstd --no-check
270 $ZSTD -c world.tmp > world.zstd --no-check
271 cat hello.zstd world.zstd > helloworld.zstd
272 $ZSTD -dc helloworld.zstd > result.tmp
273 $DIFF helloworld.tmp result.tmp
274 $ECHO "testing zstdcat symlink"
276 ./zstdcat helloworld.zstd > result.tmp
277 $DIFF helloworld.tmp result.tmp
280 $ECHO "testing zcat symlink"
282 ./zcat helloworld.zstd > result.tmp
283 $DIFF helloworld.tmp result.tmp
286 $ECHO "frame concatenation tests completed"
289 if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] && [ "$UNAME" != "OpenBSD" ] ; then
290 $ECHO "\n**** flush write error test **** "
292 $ECHO "$ECHO foo | $ZSTD > /dev/full"
293 $ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
294 $ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
295 $ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
298 $ECHO "\n===> symbolic link test "
300 rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
301 $ECHO "hello world" > hello.tmp
302 ln -s hello.tmp world.tmp
303 $ZSTD world.tmp hello.tmp
304 test -f hello.tmp.zst # regular file should have been compressed!
305 test ! -f world.tmp.zst # symbolic link should not have been compressed!
306 $ZSTD world.tmp hello.tmp -f
307 test -f world.tmp.zst # symbolic link should have been compressed with --force
308 rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
313 $ECHO "\n===> test sparse file support "
315 ./datagen -g5M -P100 > tmpSparse
316 $ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
317 $DIFF -s tmpSparse tmpSparseRegen
318 $ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
319 $DIFF -s tmpSparse tmpOutSparse
320 $ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
321 $DIFF -s tmpSparse tmpOutNoSparse
322 ls -ls tmpSparse* # look at file size and block size on disk
323 ./datagen -s1 -g1200007 -P100 | $ZSTD | $ZSTD -dv --sparse -c > tmpSparseOdd # Odd size file (to not finish on an exact nb of blocks)
324 ./datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
325 ls -ls tmpSparseOdd # look at file size and block size on disk
326 $ECHO "\n Sparse Compatibility with Console :"
327 $ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
328 $ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
329 $ECHO "\n Sparse Compatibility with Append :"
330 ./datagen -P100 -g1M > tmpSparse1M
331 cat tmpSparse1M tmpSparse1M > tmpSparse2M
332 $ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
333 $ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
334 $ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
335 ls -ls tmpSparse* # look at file size and block size on disk
336 $DIFF tmpSparse2M tmpSparseRegenerated
340 $ECHO "\n===> multiple files tests "
342 ./datagen -s1 > tmp1 2> $INTOVOID
343 ./datagen -s2 -g100K > tmp2 2> $INTOVOID
344 ./datagen -s3 -g1M > tmp3 2> $INTOVOID
345 $ECHO "compress tmp* : "
349 $ECHO "decompress tmp* : "
352 $ECHO "compress tmp* into stdout > tmpall : "
353 $ZSTD -c tmp1 tmp2 tmp3 > tmpall
354 ls -ls tmp* # check size of tmpall (should be tmp1.zst + tmp2.zst + tmp3.zst)
355 $ECHO "decompress tmpall* into stdout > tmpdec : "
357 $ZSTD -dc tmpall* > tmpdec
358 ls -ls tmp* # check size of tmpdec (should be 2*(tmp1 + tmp2 + tmp3))
359 $ECHO "compress multiple files including a missing one (notHere) : "
360 $ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
363 $ECHO "\n===> dictionary tests "
365 $ECHO "- test with raw dict (content only) "
367 ./datagen -g1M | $MD5SUM > tmp1
368 ./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
370 $ECHO "- Create first dictionary "
371 TESTFILE=../programs/zstdcli.c
372 $ZSTD --train *.c ../programs/*.c -o tmpDict
374 $ECHO "- Dictionary compression roundtrip"
375 $ZSTD -f tmp -D tmpDict
376 $ZSTD -d tmp.zst -D tmpDict -fo result
377 $DIFF $TESTFILE result
378 $ECHO "- Dictionary compression with btlazy2 strategy"
379 $ZSTD -f tmp -D tmpDict --zstd=strategy=6
380 $ZSTD -d tmp.zst -D tmpDict -fo result
381 $DIFF $TESTFILE result
384 $ECHO "- Test dictionary compression with multithreading "
385 ./datagen -g5M | $ZSTD -T2 -D tmpDict | $ZSTD -t -D tmpDict # fails with v1.3.2
387 $ECHO "- Create second (different) dictionary "
388 $ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
389 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
390 $ECHO "- Create dictionary with short dictID"
391 $ZSTD --train *.c ../programs/*.c --dictID=1 -o tmpDict1
392 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
393 $ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
394 $ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
395 $ECHO "- Create dictionary with size limit"
396 $ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict=4K -v
397 $ECHO "- Create dictionary with small size limit"
398 $ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict=1K -v
399 $ECHO "- Create dictionary with wrong parameter order (must fail)"
400 $ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict -v 4K && die "wrong order : --maxdict must be followed by argument "
401 $ECHO "- Compress without dictID"
402 $ZSTD -f tmp -D tmpDict1 --no-dictID
403 $ZSTD -d tmp.zst -D tmpDict -fo result
404 $DIFF $TESTFILE result
405 $ECHO "- Compress with wrong argument order (must fail)"
406 $ZSTD tmp -Df tmpDict1 -c > $INTOVOID && die "-D must be followed by dictionary name "
407 $ECHO "- Compress multiple files with dictionary"
411 cp ../programs/*.c dirTestDict
412 cp ../programs/*.h dirTestDict
413 $MD5SUM dirTestDict/* > tmph1
414 $ZSTD -f --rm dirTestDict/* -D tmpDictC
415 $ZSTD -d --rm dirTestDict/*.zst -D tmpDictC # note : use internal checksum by default
417 Darwin) $ECHO "md5sum -c not supported on OS-X : test skipped" ;; # not compatible with OS-X's md5
418 *) $MD5SUM -c tmph1 ;;
421 $ECHO "- dictionary builder on bogus input"
422 $ECHO "Hello World" > tmp
423 $ZSTD --train-legacy -q tmp && die "Dictionary training should fail : not enough input source"
424 ./datagen -P0 -g10M > tmp
425 $ZSTD --train-legacy -q tmp && die "Dictionary training should fail : source is pure noise"
426 $ECHO "- Test -o before --train"
427 rm -f tmpDict dictionary
428 $ZSTD -o tmpDict --train *.c ../programs/*.c
430 $ZSTD --train *.c ../programs/*.c
435 $ECHO "\n===> fastCover dictionary builder : advanced options "
437 TESTFILE=../programs/zstdcli.c
439 $ECHO "- Create first dictionary"
440 $ZSTD --train-fastcover=k=46,d=8,f=15,split=80 *.c ../programs/*.c -o tmpDict
442 $ZSTD -f tmp -D tmpDict
443 $ZSTD -d tmp.zst -D tmpDict -fo result
444 $DIFF $TESTFILE result
445 $ECHO "- Create second (different) dictionary"
446 $ZSTD --train-fastcover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
447 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
448 $ECHO "- Create dictionary with short dictID"
449 $ZSTD --train-fastcover=k=46,d=8,f=15,split=80 *.c ../programs/*.c --dictID=1 -o tmpDict1
450 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
451 $ECHO "- Create dictionary with size limit"
452 $ZSTD --train-fastcover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
453 $ECHO "- Compare size of dictionary from 90% training samples with 80% training samples"
454 $ZSTD --train-fastcover=split=90 -r *.c ../programs/*.c
455 $ZSTD --train-fastcover=split=80 -r *.c ../programs/*.c
456 $ECHO "- Create dictionary using all samples for both training and testing"
457 $ZSTD --train-fastcover=split=100 -r *.c ../programs/*.c
458 $ECHO "- Create dictionary using f=16"
459 $ZSTD --train-fastcover=f=16 -r *.c ../programs/*.c
460 $ECHO "- Create dictionary using accel=2"
461 $ZSTD --train-fastcover=accel=2 -r *.c ../programs/*.c
462 $ECHO "- Create dictionary using accel=10"
463 $ZSTD --train-fastcover=accel=10 -r *.c ../programs/*.c
464 $ECHO "- Create dictionary with multithreading"
465 $ZSTD --train-fastcover -T4 -r *.c ../programs/*.c
466 $ECHO "- Test -o before --train-fastcover"
467 rm -f tmpDict dictionary
468 $ZSTD -o tmpDict --train-fastcover *.c ../programs/*.c
470 $ZSTD --train-fastcover *.c ../programs/*.c
475 $ECHO "\n===> legacy dictionary builder "
477 TESTFILE=../programs/zstdcli.c
479 $ECHO "- Create first dictionary"
480 $ZSTD --train-legacy=selectivity=8 *.c ../programs/*.c -o tmpDict
482 $ZSTD -f tmp -D tmpDict
483 $ZSTD -d tmp.zst -D tmpDict -fo result
484 $DIFF $TESTFILE result
485 $ECHO "- Create second (different) dictionary"
486 $ZSTD --train-legacy=s=5 *.c ../programs/*.c ../programs/*.h -o tmpDictC
487 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
488 $ECHO "- Create dictionary with short dictID"
489 $ZSTD --train-legacy -s5 *.c ../programs/*.c --dictID=1 -o tmpDict1
490 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
491 $ECHO "- Create dictionary with size limit"
492 $ZSTD --train-legacy -s9 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
493 $ECHO "- Test -o before --train-legacy"
494 rm -f tmpDict dictionary
495 $ZSTD -o tmpDict --train-legacy *.c ../programs/*.c
497 $ZSTD --train-legacy *.c ../programs/*.c
502 $ECHO "\n===> integrity tests "
504 $ECHO "test one file (tmp1.zst) "
508 $ZSTD --test tmp1.zst
509 $ECHO "test multiple files (*.zst) "
511 $ECHO "test bad files (*) "
512 $ZSTD -t * && die "bad files not detected !"
513 $ZSTD -t tmp1 && die "bad file not detected !"
515 $ZSTD -t tmp2.zst && die "bad file not detected !"
517 $ZSTD -t tmp3 && die "bad file not detected !" # detects 0-sized files as bad
518 $ECHO "test --rm and --test combined "
519 $ZSTD -t --rm tmp1.zst
520 test -f tmp1.zst # check file is still present
521 split -b16384 tmp1.zst tmpSplit.
522 $ZSTD -t tmpSplit.* && die "bad file not detected !"
523 ./datagen | $ZSTD -c | $ZSTD -t
527 $ECHO "\n===> golden files tests "
530 $ZSTD -c -r files | $ZSTD -t
533 $ECHO "\n===> benchmark mode tests "
535 $ECHO "bench one file"
538 $ECHO "bench multiple levels"
540 $ECHO "bench negative level"
541 $ZSTD -bi0 --fast tmp1
542 $ECHO "with recursive and quiet modes"
545 $ECHO "\n===> zstd compatibility tests "
549 $ZSTD --format=zstd -f tmp
552 $ECHO "\n===> gzip compatibility tests "
555 $ZSTD --format=gzip -V || GZIPMODE=0
556 if [ $GZIPMODE -eq 1 ]; then
557 $ECHO "gzip support detected"
560 if [ $GZIPEXE -eq 1 ]; then
562 $ZSTD --format=gzip -f tmp
565 $ZSTD -d -f -v tmp.gz
568 $ECHO "gzip binary not detected"
571 $ECHO "gzip mode not supported"
575 $ECHO "\n===> gzip frame tests "
577 if [ $GZIPMODE -eq 1 ]; then
579 $ZSTD -f --format=gzip tmp
581 cat tmp.gz tmp.zst tmp.gz tmp.zst | $ZSTD -d -f -o tmp
582 truncateLastByte tmp.gz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
585 $ECHO "gzip mode not supported"
588 if [ $GZIPMODE -eq 1 ]; then
591 $ZSTD --format=gzip --format=zstd -f tmp
595 $ECHO "\n===> xz compatibility tests "
598 $ZSTD --format=xz -V || LZMAMODE=0
599 if [ $LZMAMODE -eq 1 ]; then
600 $ECHO "xz support detected"
602 xz -Q -V && lzma -Q -V || XZEXE=0
603 if [ $XZEXE -eq 1 ]; then
604 $ECHO "Testing zstd xz and lzma support"
606 $ZSTD --format=lzma -f tmp
607 $ZSTD --format=xz -f tmp
611 lzma -Q -f -k --lzma1 tmp
612 $ZSTD -d -f -v tmp.xz
613 $ZSTD -d -f -v tmp.lzma
615 $ECHO "Creating symlinks"
620 $ECHO "Testing xz and lzma symlinks"
626 $ECHO "Testing unxz and unlzma symlinks"
631 rm xz unxz lzma unlzma
634 $ECHO "xz binary not detected"
637 $ECHO "xz mode not supported"
641 $ECHO "\n===> xz frame tests "
643 if [ $LZMAMODE -eq 1 ]; then
645 $ZSTD -f --format=xz tmp
646 $ZSTD -f --format=lzma tmp
648 cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | $ZSTD -d -f -o tmp
649 truncateLastByte tmp.xz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
650 truncateLastByte tmp.lzma | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
653 $ECHO "xz mode not supported"
656 $ECHO "\n===> lz4 compatibility tests "
659 $ZSTD --format=lz4 -V || LZ4MODE=0
660 if [ $LZ4MODE -eq 1 ]; then
661 $ECHO "lz4 support detected"
664 if [ $LZ4EXE -eq 1 ]; then
666 $ZSTD --format=lz4 -f tmp
669 $ZSTD -d -f -v tmp.lz4
672 $ECHO "lz4 binary not detected"
675 $ECHO "lz4 mode not supported"
679 $ECHO "\n===> lz4 frame tests "
681 if [ $LZ4MODE -eq 1 ]; then
683 $ZSTD -f --format=lz4 tmp
685 cat tmp.lz4 tmp.zst tmp.lz4 tmp.zst | $ZSTD -d -f -o tmp
686 truncateLastByte tmp.lz4 | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
689 $ECHO "lz4 mode not supported"
692 $ECHO "\n===> suffix list test"
694 ! $ZSTD -d tmp.abc 2> tmplg
696 if [ $GZIPMODE -ne 1 ]; then
697 grep ".gz" tmplg > $INTOVOID && die "Unsupported suffix listed"
700 if [ $LZMAMODE -ne 1 ]; then
701 grep ".lzma" tmplg > $INTOVOID && die "Unsupported suffix listed"
702 grep ".xz" tmplg > $INTOVOID && die "Unsupported suffix listed"
705 if [ $LZ4MODE -ne 1 ]; then
706 grep ".lz4" tmplg > $INTOVOID && die "Unsupported suffix listed"
709 $ECHO "\n===> zstd round-trip tests "
712 roundTripTest -g15K # TableID==3
713 roundTripTest -g127K # TableID==2
714 roundTripTest -g255K # TableID==1
715 roundTripTest -g522K # TableID==0
716 roundTripTest -g519K 6 # greedy, hash chain
717 roundTripTest -g517K 16 # btlazy2
718 roundTripTest -g516K 19 # btopt
720 fileRoundTripTest -g500K
722 $ECHO "\n===> zstd long distance matching round-trip tests "
723 roundTripTest -g0 "2 --single-thread --long"
724 roundTripTest -g1000K "1 --single-thread --long"
725 roundTripTest -g517K "6 --single-thread --long"
726 roundTripTest -g516K "16 --single-thread --long"
727 roundTripTest -g518K "19 --single-thread --long"
728 fileRoundTripTest -g5M "3 --single-thread --long"
731 roundTripTest -g96K "5 --single-thread"
734 $ECHO "\n===> zstdmt round-trip tests "
735 roundTripTest -g4M "1 -T0"
736 roundTripTest -g8M "3 -T2"
737 roundTripTest -g8000K "2 --threads=2"
738 fileRoundTripTest -g4M "19 -T2 -B1M"
740 $ECHO "\n===> zstdmt long distance matching round-trip tests "
741 roundTripTest -g8M "3 --long=24 -T2"
743 $ECHO "\n===> ovLog tests "
744 ./datagen -g2MB > tmp
745 refSize=$($ZSTD tmp -6 -c --zstd=wlog=18 | wc -c)
746 ov9Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=9 | wc -c)
747 ov0Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=0 | wc -c)
748 if [ $refSize -eq $ov9Size ]; then
749 echo ov9Size should be different from refSize
752 if [ $refSize -eq $ov0Size ]; then
753 echo ov0Size should be different from refSize
756 if [ $ov9Size -ge $ov0Size ]; then
757 echo ov9Size=$ov9Size should be smaller than ov0Size=$ov0Size
762 $ECHO "\n===> no multithreading, skipping zstdmt tests "
767 $ECHO "\n===> zstd --list/-l single frame tests "
773 $ZSTD -lv *.zst | grep "Decompressed Size:" # check that decompressed size is present in header
775 $ZSTD --list -v *.zst
777 $ECHO "\n===> zstd --list/-l multiple frame tests "
778 cat tmp1.zst tmp2.zst > tmp12.zst
779 cat tmp12.zst tmp3.zst > tmp123.zst
783 $ECHO "\n===> zstd --list/-l error detection tests "
784 $ZSTD -l tmp1 tmp1.zst && die "-l must fail on non-zstd file"
785 $ZSTD --list tmp* && die "-l must fail on non-zstd file"
786 $ZSTD -lv tmp1* && die "-l must fail on non-zstd file"
787 $ZSTD --list -v tmp2 tmp12.zst && die "-l must fail on non-zstd file"
789 $ECHO "\n===> zstd --list/-l errors when presented with stdin / no files"
790 $ZSTD -l && die "-l must fail on empty list of files"
791 $ZSTD -l - && die "-l does not work on stdin"
792 $ZSTD -l < tmp1.zst && die "-l does not work on stdin"
793 $ZSTD -l - < tmp1.zst && die "-l does not work on stdin"
794 $ZSTD -l - tmp1.zst && die "-l does not work on stdin"
795 $ZSTD -l - tmp1.zst < tmp1.zst && die "-l does not work on stdin"
796 $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
798 $ECHO "\n===> zstd --list/-l test with null files "
802 $ZSTD -l tmp5* && die "-l must fail on non-zstd file"
803 $ZSTD -lv tmp5.zst | grep "Decompressed Size: 0.00 KB (0 B)" # check that 0 size is present in header
804 $ZSTD -lv tmp5* && die "-l must fail on non-zstd file"
806 $ECHO "\n===> zstd --list/-l test with no content size field "
807 ./datagen -g513K | $ZSTD > tmp6.zst
809 $ZSTD -lv tmp6.zst | grep "Decompressed Size:" && die "Field :Decompressed Size: should not be available in this compressed file"
811 $ECHO "\n===> zstd --list/-l test with no checksum "
812 $ZSTD -f --no-check tmp1
819 $ECHO "\n===> zstd long distance matching tests "
820 roundTripTest -g0 " --single-thread --long"
821 roundTripTest -g9M "2 --single-thread --long"
822 # Test parameter parsing
823 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --memory=512MB"
824 roundTripTest -g1M -P50 "1 --single-thread --long=29 --zstd=wlog=28" " --memory=256MB"
825 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --long=28 --memory=512MB"
826 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --zstd=wlog=28 --memory=512MB"
829 $ECHO "\n===> adaptive mode "
830 roundTripTest -g270000000 " --adapt"
831 roundTripTest -g27000000 " --adapt=min=1,max=4"
832 $ECHO "===> test: --adapt must fail on incoherent bounds "
834 $ZSTD -f -vv --adapt=min=10,max=9 tmp && die "--adapt must fail on incoherent bounds"
837 if [ "$1" != "--test-large-data" ]; then
838 $ECHO "Skipping large data tests"
843 #############################################################################
845 $ECHO "\n===> large files tests "
847 roundTripTest -g270000000 1
848 roundTripTest -g250000000 2
849 roundTripTest -g230000000 3
851 roundTripTest -g140000000 -P60 4
852 roundTripTest -g130000000 -P62 5
853 roundTripTest -g120000000 -P65 6
855 roundTripTest -g70000000 -P70 7
856 roundTripTest -g60000000 -P71 8
857 roundTripTest -g50000000 -P73 9
859 roundTripTest -g35000000 -P75 10
860 roundTripTest -g30000000 -P76 11
861 roundTripTest -g25000000 -P78 12
863 roundTripTest -g18000013 -P80 13
864 roundTripTest -g18000014 -P80 14
865 roundTripTest -g18000015 -P81 15
866 roundTripTest -g18000016 -P84 16
867 roundTripTest -g18000017 -P88 17
868 roundTripTest -g18000018 -P94 18
869 roundTripTest -g18000019 -P96 19
871 roundTripTest -g5000000000 -P99 1
872 roundTripTest -g1700000000 -P0 "1 --zstd=strategy=6" # ensure btlazy2 can survive an overflow rescale
874 fileRoundTripTest -g4193M -P99 1
877 $ECHO "\n===> zstd long, long distance matching round-trip tests "
878 roundTripTest -g270000000 "1 --single-thread --long"
879 roundTripTest -g130000000 -P60 "5 --single-thread --long"
880 roundTripTest -g35000000 -P70 "8 --single-thread --long"
881 roundTripTest -g18000001 -P80 "18 --single-thread --long"
882 # Test large window logs
883 roundTripTest -g700M -P50 "1 --single-thread --long=29"
884 roundTripTest -g600M -P50 "1 --single-thread --long --zstd=wlog=29,clog=28"
889 $ECHO "\n===> zstdmt long round-trip tests "
890 roundTripTest -g80000000 -P99 "19 -T2" " "
891 roundTripTest -g5000000000 -P99 "1 -T2" " "
892 roundTripTest -g500000000 -P97 "1 -T999" " "
893 fileRoundTripTest -g4103M -P98 " -T0" " "
894 roundTripTest -g400000000 -P97 "1 --long=24 -T2" " "
896 $ECHO "\n**** no multithreading, skipping zstdmt tests **** "
900 $ECHO "\n===> cover dictionary builder : advanced options "
902 TESTFILE=../programs/zstdcli.c
904 $ECHO "- Create first dictionary"
905 $ZSTD --train-cover=k=46,d=8,split=80 *.c ../programs/*.c -o tmpDict
907 $ZSTD -f tmp -D tmpDict
908 $ZSTD -d tmp.zst -D tmpDict -fo result
909 $DIFF $TESTFILE result
910 $ECHO "- Create second (different) dictionary"
911 $ZSTD --train-cover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
912 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
913 $ECHO "- Create dictionary with short dictID"
914 $ZSTD --train-cover=k=46,d=8,split=80 *.c ../programs/*.c --dictID=1 -o tmpDict1
915 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
916 $ECHO "- Create dictionary with size limit"
917 $ZSTD --train-cover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
918 $ECHO "- Compare size of dictionary from 90% training samples with 80% training samples"
919 $ZSTD --train-cover=split=90 -r *.c ../programs/*.c
920 $ZSTD --train-cover=split=80 -r *.c ../programs/*.c
921 $ECHO "- Create dictionary using all samples for both training and testing"
922 $ZSTD --train-cover=split=100 -r *.c ../programs/*.c
923 $ECHO "- Test -o before --train-cover"
924 rm -f tmpDict dictionary
925 $ZSTD -o tmpDict --train-cover *.c ../programs/*.c
927 $ZSTD --train-cover *.c ../programs/*.c
929 rm -f tmp* dictionary