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"
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"
203 $ECHO "test: --[no-]compress-literals"
204 $ZSTD tmp -c --no-compress-literals -1 | $ZSTD -t
205 $ZSTD tmp -c --no-compress-literals --fast=1 | $ZSTD -t
206 $ZSTD tmp -c --no-compress-literals -19 | $ZSTD -t
207 $ZSTD tmp -c --compress-literals -1 | $ZSTD -t
208 $ZSTD tmp -c --compress-literals --fast=1 | $ZSTD -t
209 $ZSTD tmp -c --compress-literals -19 | $ZSTD -t
210 $ZSTD -b --fast=1 -i1e1 tmp --compress-literals
211 $ZSTD -b --fast=1 -i1e1 tmp --no-compress-literals
213 $ECHO "test : file removal"
215 test ! -f tmp # tmp should no longer be present
216 $ZSTD -f -d --rm tmp.zst
217 test ! -f tmp.zst # tmp.zst should no longer be present
218 $ECHO "test : should quietly not remove non-regular file"
220 $ZSTD tmp -f -o "$DEVDEVICE" 2>tmplog > "$INTOVOID"
221 grep -v "Refusing to remove non-regular file" tmplog
223 $ZSTD tmp -f -o "$INTOVOID" 2>&1 | grep -v "Refusing to remove non-regular file"
224 $ECHO "test : --rm on stdin"
225 $ECHO a | $ZSTD --rm > $INTOVOID # --rm should remain silent
227 $ZSTD -f tmp && die "tmp not present : should have failed"
228 test ! -f tmp.zst # tmp.zst should not be created
229 $ECHO "test : -d -f do not delete destination when source is not present"
230 touch tmp # create destination file
231 $ZSTD -d -f tmp.zst && die "attempt to decompress a non existing file"
232 test -f tmp # destination file should still be present
233 $ECHO "test : -f do not delete destination when source is not present"
234 rm tmp # erase source file
235 touch tmp.zst # create destination file
236 $ZSTD -f tmp && die "attempt to compress a non existing file"
237 test -f tmp.zst # destination file should still be present
241 $ECHO "test : compress multiple files"
244 $ZSTD tmp1 tmp2 -o "$INTOVOID" -f
245 $ZSTD tmp1 tmp2 -c | $ZSTD -t
246 $ZSTD tmp1 tmp2 -o tmp.zst
250 $ZSTD -t tmp1.zst tmp2.zst
251 $ZSTD -dc tmp1.zst tmp2.zst
252 $ZSTD tmp1.zst tmp2.zst -o "$INTOVOID" -f
253 $ZSTD -d tmp1.zst tmp2.zst -o tmp
255 $ZSTD tmp1 tmp2 -f -o tmpexists
256 $ZSTD tmp1 tmp2 -o tmpexists && die "should have refused to overwrite"
258 if [ "$?" -eq 139 ]; then
259 die "should not have segfaulted"
264 $ECHO "\n===> Advanced compression parameters "
265 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21, - -o tmp.zst && die "wrong parameters not detected!"
266 $ECHO "Hello world!" | $ZSTD --zstd=windowLo=21 - -o tmp.zst && die "wrong parameters not detected!"
267 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,slog - -o tmp.zst && die "wrong parameters not detected!"
268 $ECHO "Hello world!" | $ZSTD --zstd=strategy=10 - -o tmp.zst && die "parameter out of bound not detected!" # > btultra2 : does not exist
269 test ! -f tmp.zst # tmp.zst should not be created
271 roundTripTest -g512K " --zstd=mml=3,tlen=48,strat=6"
272 roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
273 roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,minMatch=3,targetLength=48,strategy=6"
274 roundTripTest -g512K " --single-thread --long --zstd=ldmHashLog=20,ldmMinMatch=64,ldmBucketSizeLog=1,ldmHashRateLog=7"
275 roundTripTest -g512K " --single-thread --long --zstd=lhlog=20,lmml=64,lblog=1,lhrlog=7"
276 roundTripTest -g64K "19 --zstd=strat=9" # btultra2
279 $ECHO "\n===> Pass-Through mode "
280 $ECHO "Hello world 1!" | $ZSTD -df
281 $ECHO "Hello world 2!" | $ZSTD -dcf
282 $ECHO "Hello world 3!" > tmp1
286 $ECHO "\n===> frame concatenation "
288 $ECHO "hello " > hello.tmp
289 $ECHO "world!" > world.tmp
290 cat hello.tmp world.tmp > helloworld.tmp
291 $ZSTD -c hello.tmp > hello.zstd
292 $ZSTD -c world.tmp > world.zstd
293 cat hello.zstd world.zstd > helloworld.zstd
294 $ZSTD -dc helloworld.zstd > result.tmp
296 $DIFF helloworld.tmp result.tmp
297 $ECHO "frame concatenation without checksum"
298 $ZSTD -c hello.tmp > hello.zstd --no-check
299 $ZSTD -c world.tmp > world.zstd --no-check
300 cat hello.zstd world.zstd > helloworld.zstd
301 $ZSTD -dc helloworld.zstd > result.tmp
302 $DIFF helloworld.tmp result.tmp
303 $ECHO "testing zstdcat symlink"
305 ./zstdcat helloworld.zstd > result.tmp
306 $DIFF helloworld.tmp result.tmp
309 $ECHO "testing zcat symlink"
311 ./zcat helloworld.zstd > result.tmp
312 $DIFF helloworld.tmp result.tmp
315 $ECHO "frame concatenation tests completed"
318 if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] && [ "$UNAME" != "OpenBSD" ] ; then
319 $ECHO "\n**** flush write error test **** "
321 $ECHO "$ECHO foo | $ZSTD > /dev/full"
322 $ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
323 $ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
324 $ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
329 if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] ; then
331 $ECHO "\n===> symbolic link test "
333 rm -f hello.tmp world.tmp world2.tmp hello.tmp.zst world.tmp.zst
334 $ECHO "hello world" > hello.tmp
335 ln -s hello.tmp world.tmp
336 ln -s hello.tmp world2.tmp
337 $ZSTD world.tmp hello.tmp || true
338 test -f hello.tmp.zst # regular file should have been compressed!
339 test ! -f world.tmp.zst # symbolic link should not have been compressed!
340 $ZSTD world.tmp || true
341 test ! -f world.tmp.zst # symbolic link should not have been compressed!
342 $ZSTD world.tmp world2.tmp || true
343 test ! -f world.tmp.zst # symbolic link should not have been compressed!
344 test ! -f world2.tmp.zst # symbolic link should not have been compressed!
345 $ZSTD world.tmp hello.tmp -f
346 test -f world.tmp.zst # symbolic link should have been compressed with --force
347 rm -f hello.tmp world.tmp world2.tmp hello.tmp.zst world.tmp.zst
352 $ECHO "\n===> test sparse file support "
354 ./datagen -g5M -P100 > tmpSparse
355 $ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
356 $DIFF -s tmpSparse tmpSparseRegen
357 $ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
358 $DIFF -s tmpSparse tmpOutSparse
359 $ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
360 $DIFF -s tmpSparse tmpOutNoSparse
361 ls -ls tmpSparse* # look at file size and block size on disk
362 ./datagen -s1 -g1200007 -P100 | $ZSTD | $ZSTD -dv --sparse -c > tmpSparseOdd # Odd size file (to not finish on an exact nb of blocks)
363 ./datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
364 ls -ls tmpSparseOdd # look at file size and block size on disk
365 $ECHO "\n Sparse Compatibility with Console :"
366 $ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
367 $ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
368 $ECHO "\n Sparse Compatibility with Append :"
369 ./datagen -P100 -g1M > tmpSparse1M
370 cat tmpSparse1M tmpSparse1M > tmpSparse2M
371 $ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
372 $ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
373 $ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
374 ls -ls tmpSparse* # look at file size and block size on disk
375 $DIFF tmpSparse2M tmpSparseRegenerated
379 $ECHO "\n===> multiple files tests "
381 ./datagen -s1 > tmp1 2> $INTOVOID
382 ./datagen -s2 -g100K > tmp2 2> $INTOVOID
383 ./datagen -s3 -g1M > tmp3 2> $INTOVOID
384 $ECHO "compress tmp* : "
388 $ECHO "decompress tmp* : "
391 $ECHO "compress tmp* into stdout > tmpall : "
392 $ZSTD -c tmp1 tmp2 tmp3 > tmpall
393 ls -ls tmp* # check size of tmpall (should be tmp1.zst + tmp2.zst + tmp3.zst)
394 $ECHO "decompress tmpall* into stdout > tmpdec : "
396 $ZSTD -dc tmpall* > tmpdec
397 ls -ls tmp* # check size of tmpdec (should be 2*(tmp1 + tmp2 + tmp3))
398 $ECHO "compress multiple files including a missing one (notHere) : "
399 $ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
402 $ECHO "\n===> dictionary tests "
404 $ECHO "- test with raw dict (content only) "
406 ./datagen -g1M | $MD5SUM > tmp1
407 ./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
409 $ECHO "- Create first dictionary "
410 TESTFILE=../programs/zstdcli.c
411 $ZSTD --train *.c ../programs/*.c -o tmpDict
413 $ECHO "- Test dictionary compression with tmpDict as an input file and dictionary"
414 $ZSTD -f tmpDict -D tmpDict && die "compression error not detected!"
415 $ECHO "- Dictionary compression roundtrip"
416 $ZSTD -f tmp -D tmpDict
417 $ZSTD -d tmp.zst -D tmpDict -fo result
418 $DIFF $TESTFILE result
419 $ECHO "- Dictionary compression with btlazy2 strategy"
420 $ZSTD -f tmp -D tmpDict --zstd=strategy=6
421 $ZSTD -d tmp.zst -D tmpDict -fo result
422 $DIFF $TESTFILE result
425 $ECHO "- Test dictionary compression with multithreading "
426 ./datagen -g5M | $ZSTD -T2 -D tmpDict | $ZSTD -t -D tmpDict # fails with v1.3.2
428 $ECHO "- Create second (different) dictionary "
429 $ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
430 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
431 $ECHO "- Create dictionary with short dictID"
432 $ZSTD --train *.c ../programs/*.c --dictID=1 -o tmpDict1
433 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
434 $ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
435 $ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
436 $ECHO "- Create dictionary with size limit"
437 $ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict=4K -v
438 $ECHO "- Create dictionary with small size limit"
439 $ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict=1K -v
440 $ECHO "- Create dictionary with wrong parameter order (must fail)"
441 $ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict -v 4K && die "wrong order : --maxdict must be followed by argument "
442 $ECHO "- Compress without dictID"
443 $ZSTD -f tmp -D tmpDict1 --no-dictID
444 $ZSTD -d tmp.zst -D tmpDict -fo result
445 $DIFF $TESTFILE result
446 $ECHO "- Compress with wrong argument order (must fail)"
447 $ZSTD tmp -Df tmpDict1 -c > $INTOVOID && die "-D must be followed by dictionary name "
448 $ECHO "- Compress multiple files with dictionary"
452 cp ../programs/*.c dirTestDict
453 cp ../programs/*.h dirTestDict
454 $MD5SUM dirTestDict/* > tmph1
455 $ZSTD -f --rm dirTestDict/* -D tmpDictC
456 $ZSTD -d --rm dirTestDict/*.zst -D tmpDictC # note : use internal checksum by default
458 Darwin) $ECHO "md5sum -c not supported on OS-X : test skipped" ;; # not compatible with OS-X's md5
459 *) $MD5SUM -c tmph1 ;;
462 $ECHO "- dictionary builder on bogus input"
463 $ECHO "Hello World" > tmp
464 $ZSTD --train-legacy -q tmp && die "Dictionary training should fail : not enough input source"
465 ./datagen -P0 -g10M > tmp
466 $ZSTD --train-legacy -q tmp && die "Dictionary training should fail : source is pure noise"
467 $ECHO "- Test -o before --train"
468 rm -f tmpDict dictionary
469 $ZSTD -o tmpDict --train *.c ../programs/*.c
471 $ZSTD --train *.c ../programs/*.c
476 $ECHO "\n===> fastCover dictionary builder : advanced options "
478 TESTFILE=../programs/zstdcli.c
480 $ECHO "- Create first dictionary"
481 $ZSTD --train-fastcover=k=46,d=8,f=15,split=80 *.c ../programs/*.c -o tmpDict
483 $ZSTD -f tmp -D tmpDict
484 $ZSTD -d tmp.zst -D tmpDict -fo result
485 $DIFF $TESTFILE result
486 $ECHO "- Create second (different) dictionary"
487 $ZSTD --train-fastcover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
488 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
489 $ECHO "- Create dictionary with short dictID"
490 $ZSTD --train-fastcover=k=46,d=8,f=15,split=80 *.c ../programs/*.c --dictID=1 -o tmpDict1
491 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
492 $ECHO "- Create dictionary with size limit"
493 $ZSTD --train-fastcover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
494 $ECHO "- Compare size of dictionary from 90% training samples with 80% training samples"
495 $ZSTD --train-fastcover=split=90 -r *.c ../programs/*.c
496 $ZSTD --train-fastcover=split=80 -r *.c ../programs/*.c
497 $ECHO "- Create dictionary using all samples for both training and testing"
498 $ZSTD --train-fastcover=split=100 -r *.c ../programs/*.c
499 $ECHO "- Create dictionary using f=16"
500 $ZSTD --train-fastcover=f=16 -r *.c ../programs/*.c
501 $ECHO "- Create dictionary using accel=2"
502 $ZSTD --train-fastcover=accel=2 -r *.c ../programs/*.c
503 $ECHO "- Create dictionary using accel=10"
504 $ZSTD --train-fastcover=accel=10 -r *.c ../programs/*.c
505 $ECHO "- Create dictionary with multithreading"
506 $ZSTD --train-fastcover -T4 -r *.c ../programs/*.c
507 $ECHO "- Test -o before --train-fastcover"
508 rm -f tmpDict dictionary
509 $ZSTD -o tmpDict --train-fastcover *.c ../programs/*.c
511 $ZSTD --train-fastcover *.c ../programs/*.c
516 $ECHO "\n===> legacy dictionary builder "
518 TESTFILE=../programs/zstdcli.c
520 $ECHO "- Create first dictionary"
521 $ZSTD --train-legacy=selectivity=8 *.c ../programs/*.c -o tmpDict
523 $ZSTD -f tmp -D tmpDict
524 $ZSTD -d tmp.zst -D tmpDict -fo result
525 $DIFF $TESTFILE result
526 $ECHO "- Create second (different) dictionary"
527 $ZSTD --train-legacy=s=5 *.c ../programs/*.c ../programs/*.h -o tmpDictC
528 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
529 $ECHO "- Create dictionary with short dictID"
530 $ZSTD --train-legacy -s5 *.c ../programs/*.c --dictID=1 -o tmpDict1
531 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
532 $ECHO "- Create dictionary with size limit"
533 $ZSTD --train-legacy -s9 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
534 $ECHO "- Test -o before --train-legacy"
535 rm -f tmpDict dictionary
536 $ZSTD -o tmpDict --train-legacy *.c ../programs/*.c
538 $ZSTD --train-legacy *.c ../programs/*.c
543 $ECHO "\n===> integrity tests "
545 $ECHO "test one file (tmp1.zst) "
549 $ZSTD --test tmp1.zst
550 $ECHO "test multiple files (*.zst) "
552 $ECHO "test bad files (*) "
553 $ZSTD -t * && die "bad files not detected !"
554 $ZSTD -t tmp1 && die "bad file not detected !"
556 $ZSTD -t tmp2.zst && die "bad file not detected !"
558 $ZSTD -t tmp3 && die "bad file not detected !" # detects 0-sized files as bad
559 $ECHO "test --rm and --test combined "
560 $ZSTD -t --rm tmp1.zst
561 test -f tmp1.zst # check file is still present
562 split -b16384 tmp1.zst tmpSplit.
563 $ZSTD -t tmpSplit.* && die "bad file not detected !"
564 ./datagen | $ZSTD -c | $ZSTD -t
568 $ECHO "\n===> golden files tests "
571 $ZSTD -c -r files | $ZSTD -t
574 $ECHO "\n===> benchmark mode tests "
576 $ECHO "bench one file"
579 $ECHO "bench multiple levels"
581 $ECHO "bench negative level"
582 $ZSTD -bi0 --fast tmp1
583 $ECHO "with recursive and quiet modes"
585 $ECHO "benchmark decompression only"
587 $ZSTD -b -d -i1 tmp1.zst
589 $ECHO "\n===> zstd compatibility tests "
593 $ZSTD --format=zstd -f tmp
596 $ECHO "\n===> gzip compatibility tests "
599 $ZSTD --format=gzip -V || GZIPMODE=0
600 if [ $GZIPMODE -eq 1 ]; then
601 $ECHO "gzip support detected"
604 if [ $GZIPEXE -eq 1 ]; then
606 $ZSTD --format=gzip -f tmp
609 $ZSTD -d -f -v tmp.gz
612 $ECHO "gzip binary not detected"
615 $ECHO "gzip mode not supported"
619 $ECHO "\n===> gzip frame tests "
621 if [ $GZIPMODE -eq 1 ]; then
623 $ZSTD -f --format=gzip tmp
625 cat tmp.gz tmp.zst tmp.gz tmp.zst | $ZSTD -d -f -o tmp
626 truncateLastByte tmp.gz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
629 $ECHO "gzip mode not supported"
632 if [ $GZIPMODE -eq 1 ]; then
635 $ZSTD --format=gzip --format=zstd -f tmp
639 $ECHO "\n===> xz compatibility tests "
642 $ZSTD --format=xz -V || LZMAMODE=0
643 if [ $LZMAMODE -eq 1 ]; then
644 $ECHO "xz support detected"
646 xz -Q -V && lzma -Q -V || XZEXE=0
647 if [ $XZEXE -eq 1 ]; then
648 $ECHO "Testing zstd xz and lzma support"
650 $ZSTD --format=lzma -f tmp
651 $ZSTD --format=xz -f tmp
655 lzma -Q -f -k --lzma1 tmp
656 $ZSTD -d -f -v tmp.xz
657 $ZSTD -d -f -v tmp.lzma
659 $ECHO "Creating symlinks"
664 $ECHO "Testing xz and lzma symlinks"
670 $ECHO "Testing unxz and unlzma symlinks"
675 rm xz unxz lzma unlzma
678 $ECHO "xz binary not detected"
681 $ECHO "xz mode not supported"
685 $ECHO "\n===> xz frame tests "
687 if [ $LZMAMODE -eq 1 ]; then
689 $ZSTD -f --format=xz tmp
690 $ZSTD -f --format=lzma tmp
692 cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | $ZSTD -d -f -o tmp
693 truncateLastByte tmp.xz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
694 truncateLastByte tmp.lzma | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
697 $ECHO "xz mode not supported"
700 $ECHO "\n===> lz4 compatibility tests "
703 $ZSTD --format=lz4 -V || LZ4MODE=0
704 if [ $LZ4MODE -eq 1 ]; then
705 $ECHO "lz4 support detected"
708 if [ $LZ4EXE -eq 1 ]; then
710 $ZSTD --format=lz4 -f tmp
713 $ZSTD -d -f -v tmp.lz4
716 $ECHO "lz4 binary not detected"
719 $ECHO "lz4 mode not supported"
723 $ECHO "\n===> lz4 frame tests "
725 if [ $LZ4MODE -eq 1 ]; then
727 $ZSTD -f --format=lz4 tmp
729 cat tmp.lz4 tmp.zst tmp.lz4 tmp.zst | $ZSTD -d -f -o tmp
730 truncateLastByte tmp.lz4 | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
733 $ECHO "lz4 mode not supported"
736 $ECHO "\n===> suffix list test"
738 ! $ZSTD -d tmp.abc 2> tmplg
740 if [ $GZIPMODE -ne 1 ]; then
741 grep ".gz" tmplg > $INTOVOID && die "Unsupported suffix listed"
744 if [ $LZMAMODE -ne 1 ]; then
745 grep ".lzma" tmplg > $INTOVOID && die "Unsupported suffix listed"
746 grep ".xz" tmplg > $INTOVOID && die "Unsupported suffix listed"
749 if [ $LZ4MODE -ne 1 ]; then
750 grep ".lz4" tmplg > $INTOVOID && die "Unsupported suffix listed"
753 $ECHO "\n===> zstd round-trip tests "
756 roundTripTest -g15K # TableID==3
757 roundTripTest -g127K # TableID==2
758 roundTripTest -g255K # TableID==1
759 roundTripTest -g522K # TableID==0
760 roundTripTest -g519K 6 # greedy, hash chain
761 roundTripTest -g517K 16 # btlazy2
762 roundTripTest -g516K 19 # btopt
764 fileRoundTripTest -g500K
766 $ECHO "\n===> zstd long distance matching round-trip tests "
767 roundTripTest -g0 "2 --single-thread --long"
768 roundTripTest -g1000K "1 --single-thread --long"
769 roundTripTest -g517K "6 --single-thread --long"
770 roundTripTest -g516K "16 --single-thread --long"
771 roundTripTest -g518K "19 --single-thread --long"
772 fileRoundTripTest -g5M "3 --single-thread --long"
775 roundTripTest -g96K "5 --single-thread"
778 $ECHO "\n===> zstdmt round-trip tests "
779 roundTripTest -g4M "1 -T0"
780 roundTripTest -g8M "3 -T2"
781 roundTripTest -g8000K "2 --threads=2"
782 fileRoundTripTest -g4M "19 -T2 -B1M"
784 $ECHO "\n===> zstdmt long distance matching round-trip tests "
785 roundTripTest -g8M "3 --long=24 -T2"
787 $ECHO "\n===> ovLog tests "
788 ./datagen -g2MB > tmp
789 refSize=$($ZSTD tmp -6 -c --zstd=wlog=18 | wc -c)
790 ov9Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=9 | wc -c)
791 ov1Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=1 | wc -c)
792 if [ $refSize -eq $ov9Size ]; then
793 echo ov9Size should be different from refSize
796 if [ $refSize -eq $ov1Size ]; then
797 echo ov1Size should be different from refSize
800 if [ $ov9Size -ge $ov1Size ]; then
801 echo ov9Size=$ov9Size should be smaller than ov1Size=$ov1Size
806 $ECHO "\n===> no multithreading, skipping zstdmt tests "
811 $ECHO "\n===> zstd --list/-l single frame tests "
817 $ZSTD -lv *.zst | grep "Decompressed Size:" # check that decompressed size is present in header
819 $ZSTD --list -v *.zst
821 $ECHO "\n===> zstd --list/-l multiple frame tests "
822 cat tmp1.zst tmp2.zst > tmp12.zst
823 cat tmp12.zst tmp3.zst > tmp123.zst
827 $ECHO "\n===> zstd --list/-l error detection tests "
828 $ZSTD -l tmp1 tmp1.zst && die "-l must fail on non-zstd file"
829 $ZSTD --list tmp* && die "-l must fail on non-zstd file"
830 $ZSTD -lv tmp1* && die "-l must fail on non-zstd file"
831 $ZSTD --list -v tmp2 tmp12.zst && die "-l must fail on non-zstd file"
833 $ECHO "test : detect truncated compressed file "
834 TEST_DATA_FILE=truncatable-input.txt
835 FULL_COMPRESSED_FILE=${TEST_DATA_FILE}.zst
836 TRUNCATED_COMPRESSED_FILE=truncated-input.txt.zst
837 ./datagen -g50000 > $TEST_DATA_FILE
838 $ZSTD -f $TEST_DATA_FILE -o $FULL_COMPRESSED_FILE
839 dd bs=1 count=100 if=$FULL_COMPRESSED_FILE of=$TRUNCATED_COMPRESSED_FILE
840 $ZSTD --list $TRUNCATED_COMPRESSED_FILE && die "-l must fail on truncated file"
843 rm $FULL_COMPRESSED_FILE
844 rm $TRUNCATED_COMPRESSED_FILE
846 $ECHO "\n===> zstd --list/-l errors when presented with stdin / no files"
847 $ZSTD -l && die "-l must fail on empty list of files"
848 $ZSTD -l - && die "-l does not work on stdin"
849 $ZSTD -l < tmp1.zst && die "-l does not work on stdin"
850 $ZSTD -l - < tmp1.zst && die "-l does not work on stdin"
851 $ZSTD -l - tmp1.zst && die "-l does not work on stdin"
852 $ZSTD -l - tmp1.zst < tmp1.zst && die "-l does not work on stdin"
853 $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
855 $ECHO "\n===> zstd --list/-l test with null files "
859 $ZSTD -l tmp5* && die "-l must fail on non-zstd file"
860 $ZSTD -lv tmp5.zst | grep "Decompressed Size: 0.00 KB (0 B)" # check that 0 size is present in header
861 $ZSTD -lv tmp5* && die "-l must fail on non-zstd file"
863 $ECHO "\n===> zstd --list/-l test with no content size field "
864 ./datagen -g513K | $ZSTD > tmp6.zst
866 $ZSTD -lv tmp6.zst | grep "Decompressed Size:" && die "Field :Decompressed Size: should not be available in this compressed file"
868 $ECHO "\n===> zstd --list/-l test with no checksum "
869 $ZSTD -f --no-check tmp1
876 $ECHO "\n===> zstd long distance matching tests "
877 roundTripTest -g0 " --single-thread --long"
878 roundTripTest -g9M "2 --single-thread --long"
879 # Test parameter parsing
880 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --memory=512MB"
881 roundTripTest -g1M -P50 "1 --single-thread --long=29 --zstd=wlog=28" " --memory=256MB"
882 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --long=28 --memory=512MB"
883 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --zstd=wlog=28 --memory=512MB"
886 $ECHO "\n===> adaptive mode "
887 roundTripTest -g270000000 " --adapt"
888 roundTripTest -g27000000 " --adapt=min=1,max=4"
889 $ECHO "===> test: --adapt must fail on incoherent bounds "
891 $ZSTD -f -vv --adapt=min=10,max=9 tmp && die "--adapt must fail on incoherent bounds"
893 $ECHO "\n===> rsyncable mode "
894 roundTripTest -g10M " --rsyncable"
895 roundTripTest -g10M " --rsyncable -B100K"
896 $ECHO "===> test: --rsyncable must fail with --single-thread"
897 $ZSTD -f -vv --rsyncable --single-thread tmp && die "--rsyncable must fail with --single-thread"
900 if [ "$1" != "--test-large-data" ]; then
901 $ECHO "Skipping large data tests"
906 #############################################################################
908 $ECHO "\n===> large files tests "
910 roundTripTest -g270000000 1
911 roundTripTest -g250000000 2
912 roundTripTest -g230000000 3
914 roundTripTest -g140000000 -P60 4
915 roundTripTest -g130000000 -P62 5
916 roundTripTest -g120000000 -P65 6
918 roundTripTest -g70000000 -P70 7
919 roundTripTest -g60000000 -P71 8
920 roundTripTest -g50000000 -P73 9
922 roundTripTest -g35000000 -P75 10
923 roundTripTest -g30000000 -P76 11
924 roundTripTest -g25000000 -P78 12
926 roundTripTest -g18000013 -P80 13
927 roundTripTest -g18000014 -P80 14
928 roundTripTest -g18000015 -P81 15
929 roundTripTest -g18000016 -P84 16
930 roundTripTest -g18000017 -P88 17
931 roundTripTest -g18000018 -P94 18
932 roundTripTest -g18000019 -P96 19
934 roundTripTest -g5000000000 -P99 1
935 roundTripTest -g1700000000 -P0 "1 --zstd=strategy=6" # ensure btlazy2 can survive an overflow rescale
937 fileRoundTripTest -g4193M -P99 1
940 $ECHO "\n===> zstd long, long distance matching round-trip tests "
941 roundTripTest -g270000000 "1 --single-thread --long"
942 roundTripTest -g130000000 -P60 "5 --single-thread --long"
943 roundTripTest -g35000000 -P70 "8 --single-thread --long"
944 roundTripTest -g18000001 -P80 "18 --single-thread --long"
945 # Test large window logs
946 roundTripTest -g700M -P50 "1 --single-thread --long=29"
947 roundTripTest -g600M -P50 "1 --single-thread --long --zstd=wlog=29,clog=28"
952 $ECHO "\n===> zstdmt long round-trip tests "
953 roundTripTest -g80000000 -P99 "19 -T2" " "
954 roundTripTest -g5000000000 -P99 "1 -T2" " "
955 roundTripTest -g500000000 -P97 "1 -T999" " "
956 fileRoundTripTest -g4103M -P98 " -T0" " "
957 roundTripTest -g400000000 -P97 "1 --long=24 -T2" " "
959 $ECHO "\n**** no multithreading, skipping zstdmt tests **** "
963 $ECHO "\n===> cover dictionary builder : advanced options "
965 TESTFILE=../programs/zstdcli.c
967 $ECHO "- Create first dictionary"
968 $ZSTD --train-cover=k=46,d=8,split=80 *.c ../programs/*.c -o tmpDict
970 $ZSTD -f tmp -D tmpDict
971 $ZSTD -d tmp.zst -D tmpDict -fo result
972 $DIFF $TESTFILE result
973 $ECHO "- Create second (different) dictionary"
974 $ZSTD --train-cover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
975 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
976 $ECHO "- Create dictionary with short dictID"
977 $ZSTD --train-cover=k=46,d=8,split=80 *.c ../programs/*.c --dictID=1 -o tmpDict1
978 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
979 $ECHO "- Create dictionary with size limit"
980 $ZSTD --train-cover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
981 $ECHO "- Compare size of dictionary from 90% training samples with 80% training samples"
982 $ZSTD --train-cover=split=90 -r *.c ../programs/*.c
983 $ZSTD --train-cover=split=80 -r *.c ../programs/*.c
984 $ECHO "- Create dictionary using all samples for both training and testing"
985 $ZSTD --train-cover=split=100 -r *.c ../programs/*.c
986 $ECHO "- Test -o before --train-cover"
987 rm -f tmpDict dictionary
988 $ZSTD -o tmpDict --train-cover *.c ../programs/*.c
990 $ZSTD --train-cover *.c ../programs/*.c
992 rm -f tmp* dictionary