blob: 77853b1a4c01122d479f53aeb5bf2e2c383eb1a3 [file] [log] [blame]
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +03001#!/bin/sh -e
2
3die() {
inikep5d589562016-05-25 10:50:28 +02004 $ECHO "$@" 1>&2
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +03005 exit 1
6}
7
Konstantin Tokarev76be3782015-12-08 18:36:37 +03008roundTripTest() {
9 if [ -n "$3" ]; then
Yann Collet4616fad2017-07-10 17:16:41 -070010 cLevel="$3"
11 proba="$2"
Konstantin Tokarev76be3782015-12-08 18:36:37 +030012 else
Yann Collet4616fad2017-07-10 17:16:41 -070013 cLevel="$2"
14 proba=""
Konstantin Tokarev76be3782015-12-08 18:36:37 +030015 fi
16
17 rm -f tmp1 tmp2
Yann Collet4616fad2017-07-10 17:16:41 -070018 $ECHO "roundTripTest: ./datagen $1 $proba | $ZSTD -v$cLevel | $ZSTD -d"
19 ./datagen $1 $proba | $MD5SUM > tmp1
20 ./datagen $1 $proba | $ZSTD --ultra -v$cLevel | $ZSTD -d | $MD5SUM > tmp2
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +010021 $DIFF -q tmp1 tmp2
Konstantin Tokarev76be3782015-12-08 18:36:37 +030022}
23
Sean Purcelleb70d212017-04-11 17:15:13 -070024fileRoundTripTest() {
25 if [ -n "$3" ]; then
26 local_c="$3"
27 local_p="$2"
28 else
29 local_c="$2"
30 local_p=""
31 fi
32
33 rm -f tmp.zstd tmp.md5.1 tmp.md5.2
Sean Purcellc424ec22017-04-17 11:38:53 -070034 $ECHO "fileRoundTripTest: ./datagen $1 $local_p > tmp && $ZSTD -v$local_c -c tmp | $ZSTD -d"
Sean Purcelleb70d212017-04-11 17:15:13 -070035 ./datagen $1 $local_p > tmp
36 cat tmp | $MD5SUM > tmp.md5.1
37 $ZSTD --ultra -v$local_c -c tmp | $ZSTD -d | $MD5SUM > tmp.md5.2
38 $DIFF -q tmp.md5.1 tmp.md5.2
39}
40
Sean Purcell9a38dfa2017-03-17 12:32:18 -070041isTerminal=false
42if [ -t 0 ] && [ -t 1 ]
43then
44 isTerminal=true
45fi
46
inikep5d589562016-05-25 10:50:28 +020047isWindows=false
Sean Purcellc424ec22017-04-17 11:38:53 -070048ECHO="echo -e"
Yann Collet391a1282016-06-21 17:06:25 +020049INTOVOID="/dev/null"
inikep993a9df2016-05-27 10:07:46 +020050case "$OS" in
Yann Collet673f0d72016-06-06 00:26:38 +020051 Windows*)
inikep5d589562016-05-25 10:50:28 +020052 isWindows=true
Sean Purcell9a38dfa2017-03-17 12:32:18 -070053 INTOVOID="NUL"
inikep993a9df2016-05-27 10:07:46 +020054 ;;
55esac
inikep5d589562016-05-25 10:50:28 +020056
Dimitry Andric12df6da2016-12-12 19:22:47 +010057UNAME=$(uname)
58case "$UNAME" in
59 Darwin) MD5SUM="md5 -r" ;;
60 FreeBSD) MD5SUM="gmd5sum" ;;
Yann Collet94d1a932016-12-06 12:02:56 -080061 *) MD5SUM="md5sum" ;;
62esac
inikep5d589562016-05-25 10:50:28 +020063
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +010064DIFF="diff"
65case "$UNAME" in
66 SunOS) DIFF="gdiff" ;;
67esac
68
Przemyslaw Skibinskie579ab52016-11-14 12:57:05 +010069$ECHO "\nStarting playTests.sh isWindows=$isWindows ZSTD='$ZSTD'"
inikep5d589562016-05-25 10:50:28 +020070
Konstantin Tokarev76be3782015-12-08 18:36:37 +030071[ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
72
Sean Purcellc424ec22017-04-17 11:38:53 -070073if [ -n "$(echo hello | $ZSTD -v -T2 2>&1 > $INTOVOID | grep 'multi-threading is disabled')" ]
74then
75 hasMT=""
76else
77 hasMT="true"
78fi
79
inikep5d589562016-05-25 10:50:28 +020080$ECHO "\n**** simple tests **** "
Yann Colletde95f962016-05-23 19:46:47 +020081
Yann Collet8154c3d2016-02-13 03:12:10 +010082./datagen > tmp
Yann Colletb3060f72016-09-09 16:44:16 +020083$ECHO "test : basic compression "
Yann Collet673f0d72016-06-06 00:26:38 +020084$ZSTD -f tmp # trivial compression case, creates tmp.zst
Yann Colletb3060f72016-09-09 16:44:16 +020085$ECHO "test : basic decompression"
Yann Collet673f0d72016-06-06 00:26:38 +020086$ZSTD -df tmp.zst # trivial decompression case (overwrites tmp)
inikep5d589562016-05-25 10:50:28 +020087$ECHO "test : too large compression level (must fail)"
Yann Colletfab02302016-08-12 19:00:18 +020088$ZSTD -99 -f tmp # too large compression level, automatic sized down
inikep5d589562016-05-25 10:50:28 +020089$ECHO "test : compress to stdout"
Yann Collet0d348d42016-05-29 02:02:24 +020090$ZSTD tmp -c > tmpCompressed
Yann Colletd6931172016-05-10 05:56:09 +020091$ZSTD tmp --stdout > tmpCompressed # long command format
Yann Collet27b5ac62016-09-21 14:20:56 +020092$ECHO "test : compress to named file"
93rm tmpCompressed
94$ZSTD tmp -o tmpCompressed
Yann Collet01a1abf2017-05-05 19:15:24 -070095test -f tmpCompressed # file must be created
Yann Collet27b5ac62016-09-21 14:20:56 +020096$ECHO "test : -o must be followed by filename (must fail)"
Yann Collet714464f2016-09-21 16:05:03 +020097$ZSTD tmp -of tmpCompressed && die "-o must be followed by filename "
Yann Collet27b5ac62016-09-21 14:20:56 +020098$ECHO "test : force write, correct order"
99$ZSTD tmp -fo tmpCompressed
Yann Collet714464f2016-09-21 16:05:03 +0200100$ECHO "test : forgotten argument"
101cp tmp tmp2
102$ZSTD tmp2 -fo && die "-o must be followed by filename "
Yann Colletc8431422016-09-01 15:05:57 -0700103$ECHO "test : implied stdout when input is stdin"
104$ECHO bob | $ZSTD | $ZSTD -d
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700105if [ "$isTerminal" = true ]; then
Sean Purcelld9730712017-03-16 16:25:19 -0700106$ECHO "test : compressed data to terminal"
107$ECHO bob | $ZSTD && die "should have refused : compressed data to terminal"
108$ECHO "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)"
109$ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal"
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700110fi
inikep5d589562016-05-25 10:50:28 +0200111$ECHO "test : null-length file roundtrip"
112$ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
113$ECHO "test : decompress file with wrong suffix (must fail)"
Yann Collet2d08b092016-02-16 14:42:08 +0100114$ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
Yann Collet391a1282016-06-21 17:06:25 +0200115$ZSTD -df tmp && die "should have refused : wrong extension"
116$ECHO "test : decompress into stdout"
Yann Collet0d348d42016-05-29 02:02:24 +0200117$ZSTD -d tmpCompressed -c > tmpResult # decompression using stdout
Yann Collet2d08b092016-02-16 14:42:08 +0100118$ZSTD --decompress tmpCompressed -c > tmpResult
119$ZSTD --decompress tmpCompressed --stdout > tmpResult
Yann Collet391a1282016-06-21 17:06:25 +0200120$ECHO "test : decompress from stdin into stdout"
121$ZSTD -dc < tmp.zst > $INTOVOID # combine decompression, stdin & stdout
122$ZSTD -dc - < tmp.zst > $INTOVOID
123$ZSTD -d < tmp.zst > $INTOVOID # implicit stdout when stdin is used
124$ZSTD -d - < tmp.zst > $INTOVOID
Yann Colletd4cda272016-10-14 13:13:13 -0700125$ECHO "test : impose memory limitation (must fail)"
126$ZSTD -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
Yann Collet11223492016-10-14 14:07:11 -0700127$ZSTD -d -f tmp.zst --memlimit=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
Yann Colletd7b120a2016-10-14 14:22:32 -0700128$ZSTD -d -f tmp.zst --memory=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
129$ZSTD -d -f tmp.zst --memlimit-decompress=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
Yann Collet391a1282016-06-21 17:06:25 +0200130$ECHO "test : overwrite protection"
Yann Collet2d08b092016-02-16 14:42:08 +0100131$ZSTD -q tmp && die "overwrite check failed!"
Yann Collet391a1282016-06-21 17:06:25 +0200132$ECHO "test : force overwrite"
Yann Collet2d08b092016-02-16 14:42:08 +0100133$ZSTD -q -f tmp
134$ZSTD -q --force tmp
Sean Purcell9da11c62017-04-06 12:58:49 -0700135$ECHO "test : overwrite readonly file"
Sean Purcell16521722017-04-06 17:06:30 -0700136rm -f tmpro tmpro.zst
Sean Purcell9da11c62017-04-06 12:58:49 -0700137$ECHO foo > tmpro.zst
138$ECHO foo > tmpro
139chmod 400 tmpro.zst
Sean Purcell16521722017-04-06 17:06:30 -0700140$ZSTD -q tmpro && die "should have refused to overwrite read-only file"
141$ZSTD -q -f tmpro
142rm -f tmpro tmpro.zst
Yann Colletb09b12c2016-06-09 22:59:51 +0200143$ECHO "test : file removal"
144$ZSTD -f --rm tmp
Yann Collet01a1abf2017-05-05 19:15:24 -0700145test ! -f tmp # tmp should no longer be present
Yann Colletb09b12c2016-06-09 22:59:51 +0200146$ZSTD -f -d --rm tmp.zst
Yann Collet01a1abf2017-05-05 19:15:24 -0700147test ! -f tmp.zst # tmp.zst should no longer be present
Yann Collet67d86a72017-02-27 16:09:20 -0800148$ECHO "test : --rm on stdin"
149$ECHO a | $ZSTD --rm > $INTOVOID # --rm should remain silent
Yann Colletb09b12c2016-06-09 22:59:51 +0200150rm tmp
151$ZSTD -f tmp && die "tmp not present : should have failed"
Yann Collet01a1abf2017-05-05 19:15:24 -0700152test ! -f tmp.zst # tmp.zst should not be created
Yann Colletde95f962016-05-23 19:46:47 +0200153
154
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100155$ECHO "\n**** Advanced compression parameters **** "
Przemyslaw Skibinski24a42362016-12-14 18:07:31 +0100156$ECHO "Hello world!" | $ZSTD --zstd=windowLog=21, - -o tmp.zst && die "wrong parameters not detected!"
157$ECHO "Hello world!" | $ZSTD --zstd=windowLo=21 - -o tmp.zst && die "wrong parameters not detected!"
Przemyslaw Skibinskif9a56662016-12-14 18:43:06 +0100158$ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,slog - -o tmp.zst && die "wrong parameters not detected!"
Yann Collet01a1abf2017-05-05 19:15:24 -0700159test ! -f tmp.zst # tmp.zst should not be created
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100160roundTripTest -g512K
Przemyslaw Skibinskiab5ed6f2016-12-14 17:10:38 +0100161roundTripTest -g512K " --zstd=slen=3,tlen=48,strat=6"
162roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100163roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,searchLength=3,targetLength=48,strategy=6"
164roundTripTest -g512K 19
165
166
inikep5d589562016-05-25 10:50:28 +0200167$ECHO "\n**** Pass-Through mode **** "
Yann Collet743b33f2016-12-02 15:18:57 -0800168$ECHO "Hello world 1!" | $ZSTD -df
169$ECHO "Hello world 2!" | $ZSTD -dcf
170$ECHO "Hello world 3!" > tmp1
171$ZSTD -dcf tmp1
Yann Colletde95f962016-05-23 19:46:47 +0200172
Yann Collet8154c3d2016-02-13 03:12:10 +0100173
inikep5d589562016-05-25 10:50:28 +0200174$ECHO "\n**** frame concatenation **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300175
inikep5d589562016-05-25 10:50:28 +0200176$ECHO "hello " > hello.tmp
177$ECHO "world!" > world.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300178cat hello.tmp world.tmp > helloworld.tmp
Yann Colletc8da2c92016-02-12 02:56:27 +0100179$ZSTD -c hello.tmp > hello.zstd
180$ZSTD -c world.tmp > world.zstd
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300181cat hello.zstd world.zstd > helloworld.zstd
Yann Colletc8da2c92016-02-12 02:56:27 +0100182$ZSTD -dc helloworld.zstd > result.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300183cat result.tmp
Yann Colletbd6bc222017-01-22 15:54:14 -0800184$DIFF helloworld.tmp result.tmp
Yann Collet4c5bbf62016-07-28 20:30:25 +0200185$ECHO "frame concatenation without checksum"
186$ZSTD -c hello.tmp > hello.zstd --no-check
187$ZSTD -c world.tmp > world.zstd --no-check
188cat hello.zstd world.zstd > helloworld.zstd
189$ZSTD -dc helloworld.zstd > result.tmp
190cat result.tmp
Yann Colletbd6bc222017-01-22 15:54:14 -0800191$DIFF helloworld.tmp result.tmp
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300192rm ./*.tmp ./*.zstd
inikep5d589562016-05-25 10:50:28 +0200193$ECHO "frame concatenation tests completed"
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300194
Yann Colletf0624362016-02-12 15:56:46 +0100195
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100196if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] ; then
inikep5d589562016-05-25 10:50:28 +0200197$ECHO "\n**** flush write error test **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300198
inikep5d589562016-05-25 10:50:28 +0200199$ECHO "$ECHO foo | $ZSTD > /dev/full"
200$ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
201$ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
202$ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
Sean Purcell680e4e02017-03-23 11:52:09 -0700203
Yann Collet01a1abf2017-05-05 19:15:24 -0700204
Sean Purcell680e4e02017-03-23 11:52:09 -0700205$ECHO "\n**** symbolic link test **** "
206
207rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
208$ECHO "hello world" > hello.tmp
209ln -s hello.tmp world.tmp
210$ZSTD world.tmp hello.tmp
Yann Collet01a1abf2017-05-05 19:15:24 -0700211test -f hello.tmp.zst # regular file should have been compressed!
212test ! -f world.tmp.zst # symbolic link should not have been compressed!
Sean Purcell680e4e02017-03-23 11:52:09 -0700213$ZSTD world.tmp hello.tmp -f
Yann Collet01a1abf2017-05-05 19:15:24 -0700214test -f world.tmp.zst # symbolic link should have been compressed with --force
Sean Purcell680e4e02017-03-23 11:52:09 -0700215rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
216
inikep5d589562016-05-25 10:50:28 +0200217fi
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300218
Yann Collet6a458352015-12-18 02:51:14 +0100219
inikep5d589562016-05-25 10:50:28 +0200220$ECHO "\n**** test sparse file support **** "
Yann Collet32990b52016-05-23 17:48:57 +0200221
222./datagen -g5M -P100 > tmpSparse
223$ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100224$DIFF -s tmpSparse tmpSparseRegen
Yann Collet32990b52016-05-23 17:48:57 +0200225$ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100226$DIFF -s tmpSparse tmpOutSparse
Yann Collet32990b52016-05-23 17:48:57 +0200227$ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100228$DIFF -s tmpSparse tmpOutNoSparse
Yann Collet01a1abf2017-05-05 19:15:24 -0700229ls -ls tmpSparse* # look at file size and block size on disk
Yann Collet32990b52016-05-23 17:48:57 +0200230./datagen -s1 -g1200007 -P100 | $ZSTD | $ZSTD -dv --sparse -c > tmpSparseOdd # Odd size file (to not finish on an exact nb of blocks)
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100231./datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
Yann Collet01a1abf2017-05-05 19:15:24 -0700232ls -ls tmpSparseOdd # look at file size and block size on disk
inikep5d589562016-05-25 10:50:28 +0200233$ECHO "\n Sparse Compatibility with Console :"
234$ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
235$ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
236$ECHO "\n Sparse Compatibility with Append :"
Yann Collet32990b52016-05-23 17:48:57 +0200237./datagen -P100 -g1M > tmpSparse1M
238cat tmpSparse1M tmpSparse1M > tmpSparse2M
239$ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
240$ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
241$ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
Yann Collet01a1abf2017-05-05 19:15:24 -0700242ls -ls tmpSparse* # look at file size and block size on disk
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100243$DIFF tmpSparse2M tmpSparseRegenerated
Yann Collet33341de2016-05-29 23:09:51 +0200244rm tmpSparse*
Yann Collet32990b52016-05-23 17:48:57 +0200245
246
Yann Collet9b998e42016-06-15 23:11:20 +0200247$ECHO "\n**** multiple files tests **** "
248
Yann Collet391a1282016-06-21 17:06:25 +0200249./datagen -s1 > tmp1 2> $INTOVOID
250./datagen -s2 -g100K > tmp2 2> $INTOVOID
251./datagen -s3 -g1M > tmp3 2> $INTOVOID
Yann Collet9b998e42016-06-15 23:11:20 +0200252$ECHO "compress tmp* : "
Yann Collet60ba31c2016-07-28 19:55:09 +0200253$ZSTD -f tmp*
Yann Collet9b998e42016-06-15 23:11:20 +0200254ls -ls tmp*
255rm tmp1 tmp2 tmp3
256$ECHO "decompress tmp* : "
257$ZSTD -df *.zst
258ls -ls tmp*
259$ECHO "compress tmp* into stdout > tmpall : "
260$ZSTD -c tmp1 tmp2 tmp3 > tmpall
Yann Collet01a1abf2017-05-05 19:15:24 -0700261ls -ls tmp* # check size of tmpall (should be tmp1.zst + tmp2.zst + tmp3.zst)
Yann Collet9b998e42016-06-15 23:11:20 +0200262$ECHO "decompress tmpall* into stdout > tmpdec : "
263cp tmpall tmpall2
264$ZSTD -dc tmpall* > tmpdec
Yann Collet01a1abf2017-05-05 19:15:24 -0700265ls -ls tmp* # check size of tmpdec (should be 2*(tmp1 + tmp2 + tmp3))
Yann Collet9b998e42016-06-15 23:11:20 +0200266$ECHO "compress multiple files including a missing one (notHere) : "
267$ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
268
269
inikep5d589562016-05-25 10:50:28 +0200270$ECHO "\n**** dictionary tests **** "
Yann Colletf6f3d752015-12-13 13:35:21 +0100271
Yann Colletbd7fa212017-02-26 14:43:07 -0800272$ECHO "- test with raw dict (content only) "
Yann Colletf6f3d752015-12-13 13:35:21 +0100273./datagen > tmpDict
inikep93fc13e2016-05-30 10:17:55 +0200274./datagen -g1M | $MD5SUM > tmp1
275./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100276$DIFF -q tmp1 tmp2
Yann Colletbd7fa212017-02-26 14:43:07 -0800277$ECHO "- Create first dictionary "
278TESTFILE=../programs/zstdcli.c
inikepb7d34492016-08-18 15:13:41 +0200279$ZSTD --train *.c ../programs/*.c -o tmpDict
280cp $TESTFILE tmp
Yann Collet6381e992016-05-31 02:29:45 +0200281$ZSTD -f tmp -D tmpDict
Yann Collet27b5ac62016-09-21 14:20:56 +0200282$ZSTD -d tmp.zst -D tmpDict -fo result
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100283$DIFF $TESTFILE result
Yann Colletbd7fa212017-02-26 14:43:07 -0800284$ECHO "- Create second (different) dictionary "
inikepb7d34492016-08-18 15:13:41 +0200285$ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
Yann Collet27b5ac62016-09-21 14:20:56 +0200286$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
Yann Collet531a4272016-06-15 19:02:11 +0200287$ECHO "- Create dictionary with short dictID"
Yann Collet4c41d372017-03-24 18:36:56 -0700288$ZSTD --train *.c ../programs/*.c --dictID=1 -o tmpDict1
Yann Collet290aaa72016-05-30 21:18:52 +0200289cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
Yann Collet27b5ac62016-09-21 14:20:56 +0200290$ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
291$ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
292$ECHO "- Create dictionary with size limit"
Yann Collet4c41d372017-03-24 18:36:56 -0700293$ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict=4K -v
Yann Collet27b5ac62016-09-21 14:20:56 +0200294$ECHO "- Create dictionary with wrong parameter order (must fail)"
295$ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict -v 4K && die "wrong order : --maxdict must be followed by argument "
Yann Collet531a4272016-06-15 19:02:11 +0200296$ECHO "- Compress without dictID"
Yann Collet6381e992016-05-31 02:29:45 +0200297$ZSTD -f tmp -D tmpDict1 --no-dictID
Yann Collet27b5ac62016-09-21 14:20:56 +0200298$ZSTD -d tmp.zst -D tmpDict -fo result
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100299$DIFF $TESTFILE result
Yann Collet27b5ac62016-09-21 14:20:56 +0200300$ECHO "- Compress with wrong argument order (must fail)"
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700301$ZSTD tmp -Df tmpDict1 -c > $INTOVOID && die "-D must be followed by dictionary name "
Yann Collet531a4272016-06-15 19:02:11 +0200302$ECHO "- Compress multiple files with dictionary"
Yann Collet531a4272016-06-15 19:02:11 +0200303rm -rf dirTestDict
304mkdir dirTestDict
305cp *.c dirTestDict
inikepb7d34492016-08-18 15:13:41 +0200306cp ../programs/*.c dirTestDict
307cp ../programs/*.h dirTestDict
Yann Collet94376ac2016-08-25 19:09:21 +0200308$MD5SUM dirTestDict/* > tmph1
309$ZSTD -f --rm dirTestDict/* -D tmpDictC
Yann Colletbb93d772016-08-25 22:22:50 +0200310$ZSTD -d --rm dirTestDict/*.zst -D tmpDictC # note : use internal checksum by default
Dimitry Andric12df6da2016-12-12 19:22:47 +0100311case "$UNAME" in
312 Darwin) $ECHO "md5sum -c not supported on OS-X : test skipped" ;; # not compatible with OS-X's md5
Yann Collet94d1a932016-12-06 12:02:56 -0800313 *) $MD5SUM -c tmph1 ;;
314esac
Yann Collet531a4272016-06-15 19:02:11 +0200315rm -rf dirTestDict
Yann Colletf332ece2017-03-23 16:24:02 -0700316$ECHO "- dictionary builder on bogus input"
317$ECHO "Hello World" > tmp
Nick Terrellf376d472017-05-01 23:40:20 -0700318$ZSTD --train-legacy -q tmp && die "Dictionary training should fail : not enough input source"
Yann Colletf332ece2017-03-23 16:24:02 -0700319./datagen -P0 -g10M > tmp
Nick Terrellf376d472017-05-01 23:40:20 -0700320$ZSTD --train-legacy -q tmp && die "Dictionary training should fail : source is pure noise"
Yann Collet6381e992016-05-31 02:29:45 +0200321rm tmp*
Yann Colletb44be742016-03-26 20:52:14 +0100322
Yann Colletf6f3d752015-12-13 13:35:21 +0100323
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500324$ECHO "\n**** cover dictionary tests **** "
325
326TESTFILE=../programs/zstdcli.c
327./datagen > tmpDict
328$ECHO "- Create first dictionary"
Nick Terrellf376d472017-05-01 23:40:20 -0700329$ZSTD --train-cover=k=46,d=8 *.c ../programs/*.c -o tmpDict
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500330cp $TESTFILE tmp
331$ZSTD -f tmp -D tmpDict
332$ZSTD -d tmp.zst -D tmpDict -fo result
333$DIFF $TESTFILE result
334$ECHO "- Create second (different) dictionary"
Nick Terrellf376d472017-05-01 23:40:20 -0700335$ZSTD --train-cover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500336$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
337$ECHO "- Create dictionary with short dictID"
Nick Terrellf376d472017-05-01 23:40:20 -0700338$ZSTD --train-cover=k=46,d=8 *.c ../programs/*.c --dictID=1 -o tmpDict1
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500339cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
340$ECHO "- Create dictionary with size limit"
Nick Terrellf376d472017-05-01 23:40:20 -0700341$ZSTD --train-cover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
342rm tmp*
343
344$ECHO "\n**** legacy dictionary tests **** "
345
346TESTFILE=../programs/zstdcli.c
347./datagen > tmpDict
348$ECHO "- Create first dictionary"
349$ZSTD --train-legacy=selectivity=8 *.c ../programs/*.c -o tmpDict
350cp $TESTFILE tmp
351$ZSTD -f tmp -D tmpDict
352$ZSTD -d tmp.zst -D tmpDict -fo result
353$DIFF $TESTFILE result
354$ECHO "- Create second (different) dictionary"
355$ZSTD --train-legacy=s=5 *.c ../programs/*.c ../programs/*.h -o tmpDictC
356$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
357$ECHO "- Create dictionary with short dictID"
358$ZSTD --train-legacy -s5 *.c ../programs/*.c --dictID=1 -o tmpDict1
359cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
360$ECHO "- Create dictionary with size limit"
361$ZSTD --train-legacy -s9 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500362rm tmp*
363
364
inikep5d589562016-05-25 10:50:28 +0200365$ECHO "\n**** integrity tests **** "
Yann Colletde95f962016-05-23 19:46:47 +0200366
inikep5d589562016-05-25 10:50:28 +0200367$ECHO "test one file (tmp1.zst) "
Yann Collet1a7b8fb2016-06-15 23:33:38 +0200368./datagen > tmp1
369$ZSTD tmp1
Yann Collet459a6b72016-02-15 20:37:23 +0100370$ZSTD -t tmp1.zst
Yann Collet2d08b092016-02-16 14:42:08 +0100371$ZSTD --test tmp1.zst
inikep5d589562016-05-25 10:50:28 +0200372$ECHO "test multiple files (*.zst) "
Yann Collet459a6b72016-02-15 20:37:23 +0100373$ZSTD -t *.zst
Yann Collet24a3d902016-07-26 01:26:56 +0200374$ECHO "test bad files (*) "
Yann Collet459a6b72016-02-15 20:37:23 +0100375$ZSTD -t * && die "bad files not detected !"
Yann Collet24a3d902016-07-26 01:26:56 +0200376$ZSTD -t tmp1 && die "bad file not detected !"
377cp tmp1 tmp2.zst
378$ZSTD -t tmp2.zst && die "bad file not detected !"
Yann Collet7adc2322016-07-26 15:39:31 +0200379./datagen -g0 > tmp3
380$ZSTD -t tmp3 && die "bad file not detected !" # detects 0-sized files as bad
Yann Colletb4024902016-07-26 00:49:47 +0200381$ECHO "test --rm and --test combined "
382$ZSTD -t --rm tmp1.zst
Yann Collet01a1abf2017-05-05 19:15:24 -0700383test -f tmp1.zst # check file is still present
384split -b16384 tmp1.zst tmpSplit.
385$ZSTD -t tmpSplit.* && die "bad file not detected !"
Nick Terrelld0b27482017-07-18 14:45:49 -0700386./datagen | $ZSTD -c | $ZSTD -t
Yann Colletdeb078b2015-12-17 20:30:14 +0100387
Yann Colletde95f962016-05-23 19:46:47 +0200388
Yann Colletb9550d62016-10-28 14:43:24 -0700389$ECHO "\n**** benchmark mode tests **** "
390
391$ECHO "bench one file"
392./datagen > tmp1
Yann Colletc1c040e2017-03-01 16:49:20 -0800393$ZSTD -bi0 tmp1
Yann Colletb9550d62016-10-28 14:43:24 -0700394$ECHO "bench multiple levels"
Yann Colletc1c040e2017-03-01 16:49:20 -0800395$ZSTD -i0b0e3 tmp1
Yann Colletb9550d62016-10-28 14:43:24 -0700396$ECHO "with recursive and quiet modes"
Yann Colletc1c040e2017-03-01 16:49:20 -0800397$ZSTD -rqi1b1e2 tmp1
398
399
400$ECHO "\n**** gzip compatibility tests **** "
401
402GZIPMODE=1
403$ZSTD --format=gzip -V || GZIPMODE=0
404if [ $GZIPMODE -eq 1 ]; then
Yann Collet27526c72017-03-01 17:02:49 -0800405 $ECHO "gzip support detected"
Yann Colletc1c040e2017-03-01 16:49:20 -0800406 GZIPEXE=1
Yann Collet27526c72017-03-01 17:02:49 -0800407 gzip -V || GZIPEXE=0
Yann Colletc1c040e2017-03-01 16:49:20 -0800408 if [ $GZIPEXE -eq 1 ]; then
409 ./datagen > tmp
410 $ZSTD --format=gzip -f tmp
411 gzip -t -v tmp.gz
412 gzip -f tmp
413 $ZSTD -d -f -v tmp.gz
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700414 rm tmp*
Yann Colletc1c040e2017-03-01 16:49:20 -0800415 else
416 $ECHO "gzip binary not detected"
417 fi
418else
419 $ECHO "gzip mode not supported"
420fi
Yann Colletb9550d62016-10-28 14:43:24 -0700421
422
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700423$ECHO "\n**** gzip frame tests **** "
424
425if [ $GZIPMODE -eq 1 ]; then
426 ./datagen > tmp
427 $ZSTD -f --format=gzip tmp
428 $ZSTD -f tmp
429 cat tmp.gz tmp.zst tmp.gz tmp.zst | $ZSTD -d -f -o tmp
Sean Purcell4de86322017-04-24 16:48:25 -0700430 head -c -1 tmp.gz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700431 rm tmp*
432else
433 $ECHO "gzip mode not supported"
434fi
435
436
437$ECHO "\n**** xz compatibility tests **** "
438
439LZMAMODE=1
440$ZSTD --format=xz -V || LZMAMODE=0
441if [ $LZMAMODE -eq 1 ]; then
442 $ECHO "xz support detected"
443 XZEXE=1
444 xz -V && lzma -V || XZEXE=0
445 if [ $XZEXE -eq 1 ]; then
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700446 $ECHO "Testing zstd xz and lzma support"
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700447 ./datagen > tmp
448 $ZSTD --format=lzma -f tmp
449 $ZSTD --format=xz -f tmp
450 xz -t -v tmp.xz
451 xz -t -v tmp.lzma
452 xz -f -k tmp
453 lzma -f -k --lzma1 tmp
454 $ZSTD -d -f -v tmp.xz
455 $ZSTD -d -f -v tmp.lzma
456 rm tmp*
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700457 $ECHO "Creating symlinks"
458 ln -s $ZSTD ./xz
459 ln -s $ZSTD ./unxz
460 ln -s $ZSTD ./lzma
461 ln -s $ZSTD ./unlzma
462 $ECHO "Testing xz and lzma symlinks"
463 ./datagen > tmp
464 ./xz tmp
465 xz -d tmp.xz
466 ./lzma tmp
467 lzma -d tmp.lzma
468 $ECHO "Testing unxz and unlzma symlinks"
469 xz tmp
470 ./xz -d tmp.xz
471 lzma tmp
472 ./lzma -d tmp.lzma
473 rm xz unxz lzma unlzma
474 rm tmp*
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700475 else
476 $ECHO "xz binary not detected"
477 fi
478else
479 $ECHO "xz mode not supported"
480fi
481
482
483$ECHO "\n**** xz frame tests **** "
484
485if [ $LZMAMODE -eq 1 ]; then
486 ./datagen > tmp
487 $ZSTD -f --format=xz tmp
488 $ZSTD -f --format=lzma tmp
489 $ZSTD -f tmp
490 cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | $ZSTD -d -f -o tmp
Sean Purcell4de86322017-04-24 16:48:25 -0700491 head -c -1 tmp.xz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
492 head -c -1 tmp.lzma | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700493 rm tmp*
494else
495 $ECHO "xz mode not supported"
496fi
497
Sean Purcell4de86322017-04-24 16:48:25 -0700498$ECHO "\n**** lz4 compatibility tests **** "
499
500LZ4MODE=1
501$ZSTD --format=lz4 -V || LZ4MODE=0
502if [ $LZ4MODE -eq 1 ]; then
503 $ECHO "lz4 support detected"
504 LZ4EXE=1
505 lz4 -V || LZ4EXE=0
506 if [ $LZ4EXE -eq 1 ]; then
507 ./datagen > tmp
508 $ZSTD --format=lz4 -f tmp
509 lz4 -t -v tmp.lz4
510 lz4 -f tmp
511 $ZSTD -d -f -v tmp.lz4
512 rm tmp*
513 else
514 $ECHO "lz4 binary not detected"
515 fi
516else
517 $ECHO "lz4 mode not supported"
518fi
519
520
521$ECHO "\n**** lz4 frame tests **** "
522
523if [ $LZ4MODE -eq 1 ]; then
524 ./datagen > tmp
525 $ZSTD -f --format=lz4 tmp
526 $ZSTD -f tmp
527 cat tmp.lz4 tmp.zst tmp.lz4 tmp.zst | $ZSTD -d -f -o tmp
528 head -c -1 tmp.lz4 | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
529 rm tmp*
530else
531 $ECHO "lz4 mode not supported"
532fi
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700533
inikep5d589562016-05-25 10:50:28 +0200534$ECHO "\n**** zstd round-trip tests **** "
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300535
536roundTripTest
Yann Collet3b719252016-03-30 19:48:05 +0200537roundTripTest -g15K # TableID==3
538roundTripTest -g127K # TableID==2
539roundTripTest -g255K # TableID==1
Yann Colletc1c040e2017-03-01 16:49:20 -0800540roundTripTest -g522K # TableID==0
541roundTripTest -g519K 6 # greedy, hash chain
542roundTripTest -g517K 16 # btlazy2
543roundTripTest -g516K 19 # btopt
Yann Collet459a6b72016-02-15 20:37:23 +0100544
Sean Purcelleb70d212017-04-11 17:15:13 -0700545fileRoundTripTest -g500K
546
Sean Purcellc424ec22017-04-17 11:38:53 -0700547if [ -n "$hasMT" ]
548then
549 $ECHO "\n**** zstdmt round-trip tests **** "
Sean Purcelld845dab2017-04-17 12:10:58 -0700550 roundTripTest -g4M "1 -T0"
551 roundTripTest -g8M "3 -T2"
Yann Collet230d7ac2017-04-21 11:38:13 -0700552 roundTripTest -g8000K "2 --threads=2"
Sean Purcelld845dab2017-04-17 12:10:58 -0700553 fileRoundTripTest -g4M "19 -T2 -B1M"
Sean Purcellc424ec22017-04-17 11:38:53 -0700554else
555 $ECHO "\n**** no multithreading, skipping zstdmt tests **** "
556fi
557
Yann Collet459a6b72016-02-15 20:37:23 +0100558rm tmp*
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300559
Paul Cruzddd1ab72017-06-15 16:53:03 -0700560$ECHO "\n**** zstd --list/-l single frame tests ****"
561./datagen > tmp1
562./datagen > tmp2
563./datagen > tmp3
564./datagen > tmp4
565$ZSTD tmp*
Paul Cruz6a99de22017-06-20 10:45:06 -0700566$ZSTD -l *.zst
567$ZSTD -lv *.zst
568$ZSTD --list *.zst
569$ZSTD --list -v *.zst
Paul Cruzddd1ab72017-06-15 16:53:03 -0700570
571$ECHO "\n**** zstd --list/-l multiple frame tests ****"
572cat tmp1.zst tmp2.zst > tmp12.zst
573cat tmp3.zst tmp4.zst > tmp34.zst
574cat tmp12.zst tmp34.zst > tmp1234.zst
575cat tmp12.zst tmp4.zst > tmp124.zst
Paul Cruz6a99de22017-06-20 10:45:06 -0700576$ZSTD -l *.zst
577$ZSTD -lv *.zst
578$ZSTD --list *.zst
579$ZSTD --list -v *.zst
Paul Cruzddd1ab72017-06-15 16:53:03 -0700580
Paul Cruzb07d0af2017-06-20 11:54:44 -0700581$ECHO "\n**** zstd --list/-l error detection tests ****"
Paul Cruz58c19b42017-06-20 14:14:53 -0700582! $ZSTD -l tmp1 tmp1.zst
583! $ZSTD --list tmp*
584! $ZSTD -lv tmp1*
585! $ZSTD --list -v tmp2 tmp23.zst
Paul Cruzb07d0af2017-06-20 11:54:44 -0700586
Paul Cruza73c2a42017-06-20 14:33:08 -0700587$ECHO "\n**** zstd --list/-l test with null files ****"
588./datagen -g0 > tmp5
589$ZSTD tmp5
Yann Colletc16748b2017-06-21 12:09:53 -0700590$ZSTD -l tmp5.zst
Paul Cruza73c2a42017-06-20 14:33:08 -0700591! $ZSTD -l tmp5*
Yann Colletc16748b2017-06-21 12:09:53 -0700592$ZSTD -lv tmp5.zst
Paul Cruza73c2a42017-06-20 14:33:08 -0700593! $ZSTD -lv tmp5*
Paul Cruza73c2a42017-06-20 14:33:08 -0700594
Yann Colletc16748b2017-06-21 12:09:53 -0700595$ECHO "\n**** zstd --list/-l test with no content size field ****"
596./datagen -g1MB | $ZSTD > tmp6.zst
Paul Cruzdb3606e2017-06-20 17:43:36 -0700597$ZSTD -l tmp6.zst
598$ZSTD -lv tmp6.zst
Yann Colletc16748b2017-06-21 12:09:53 -0700599
600$ECHO "\n**** zstd --list/-l test with no checksum ****"
601$ZSTD -f --no-check tmp1
602$ZSTD -l tmp1.zst
603$ZSTD -lv tmp1.zst
Paul Cruzdb3606e2017-06-20 17:43:36 -0700604
Paul Cruzddd1ab72017-06-15 16:53:03 -0700605rm tmp*
606
Yann Colletc16748b2017-06-21 12:09:53 -0700607
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300608if [ "$1" != "--test-large-data" ]; then
inikep5d589562016-05-25 10:50:28 +0200609 $ECHO "Skipping large data tests"
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300610 exit 0
611fi
612
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300613roundTripTest -g270000000 1
614roundTripTest -g270000000 2
615roundTripTest -g270000000 3
616
617roundTripTest -g140000000 -P60 4
618roundTripTest -g140000000 -P60 5
619roundTripTest -g140000000 -P60 6
620
621roundTripTest -g70000000 -P70 7
622roundTripTest -g70000000 -P70 8
623roundTripTest -g70000000 -P70 9
624
625roundTripTest -g35000000 -P75 10
626roundTripTest -g35000000 -P75 11
627roundTripTest -g35000000 -P75 12
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300628
Yann Collet4616fad2017-07-10 17:16:41 -0700629roundTripTest -g18000013 -P80 13
630roundTripTest -g18000014 -P80 14
631roundTripTest -g18000015 -P80 15
632roundTripTest -g18000016 -P80 16
633roundTripTest -g18000017 -P80 17
634roundTripTest -g18000018 -P94 18
635roundTripTest -g18000019 -P94 19
Konstantin Tokarev2b465842015-12-08 19:36:42 +0300636
Yann Collet4616fad2017-07-10 17:16:41 -0700637roundTripTest -g68000020 -P99 20
Yann Colletecabfe32016-03-20 16:20:06 +0100638roundTripTest -g6000000000 -P99 1
Yann Collet459a6b72016-02-15 20:37:23 +0100639
Sean Purcelleb70d212017-04-11 17:15:13 -0700640fileRoundTripTest -g4193M -P99 1
641
Sean Purcellc424ec22017-04-17 11:38:53 -0700642if [ -n "$hasMT" ]
643then
644 $ECHO "\n**** zstdmt long round-trip tests **** "
645 roundTripTest -g99000000 -P99 "20 -T2"
646 roundTripTest -g6000000000 -P99 "1 -T2"
Yann Collet3a60efd2017-07-13 10:10:13 -0700647 roundTripTest -g1500000000 -P97 "1 -T999"
648 fileRoundTripTest -g4195M -P98 " -T0"
Sean Purcellc424ec22017-04-17 11:38:53 -0700649else
650 $ECHO "\n**** no multithreading, skipping zstdmt tests **** "
651fi
652
Yann Collet459a6b72016-02-15 20:37:23 +0100653rm tmp*