blob: 897a901554cf733d0beaf7bf15f370ed78e7b32c [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
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +010010 local_c="$3"
11 local_p="$2"
Konstantin Tokarev76be3782015-12-08 18:36:37 +030012 else
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +010013 local_c="$2"
Konstantin Tokarev76be3782015-12-08 18:36:37 +030014 fi
15
16 rm -f tmp1 tmp2
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +010017 $ECHO "roundTripTest: ./datagen $1 $local_p | $ZSTD -v$local_c | $ZSTD -d"
18 ./datagen $1 $local_p | $MD5SUM > tmp1
19 ./datagen $1 $local_p | $ZSTD --ultra -v$local_c | $ZSTD -d | $MD5SUM > tmp2
20 $DIFF -q tmp1 tmp2
Konstantin Tokarev76be3782015-12-08 18:36:37 +030021}
22
Sean Purcell9a38dfa2017-03-17 12:32:18 -070023isTerminal=false
24if [ -t 0 ] && [ -t 1 ]
25then
26 isTerminal=true
27fi
28
inikep5d589562016-05-25 10:50:28 +020029isWindows=false
30ECHO="echo"
Yann Collet391a1282016-06-21 17:06:25 +020031INTOVOID="/dev/null"
inikep993a9df2016-05-27 10:07:46 +020032case "$OS" in
Yann Collet673f0d72016-06-06 00:26:38 +020033 Windows*)
inikep5d589562016-05-25 10:50:28 +020034 isWindows=true
35 ECHO="echo -e"
Sean Purcell9a38dfa2017-03-17 12:32:18 -070036 INTOVOID="NUL"
inikep993a9df2016-05-27 10:07:46 +020037 ;;
38esac
inikep5d589562016-05-25 10:50:28 +020039
Dimitry Andric12df6da2016-12-12 19:22:47 +010040UNAME=$(uname)
41case "$UNAME" in
42 Darwin) MD5SUM="md5 -r" ;;
43 FreeBSD) MD5SUM="gmd5sum" ;;
Yann Collet94d1a932016-12-06 12:02:56 -080044 *) MD5SUM="md5sum" ;;
45esac
inikep5d589562016-05-25 10:50:28 +020046
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +010047DIFF="diff"
48case "$UNAME" in
49 SunOS) DIFF="gdiff" ;;
50esac
51
52
Przemyslaw Skibinskie579ab52016-11-14 12:57:05 +010053$ECHO "\nStarting playTests.sh isWindows=$isWindows ZSTD='$ZSTD'"
inikep5d589562016-05-25 10:50:28 +020054
Konstantin Tokarev76be3782015-12-08 18:36:37 +030055[ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
56
inikep5d589562016-05-25 10:50:28 +020057$ECHO "\n**** simple tests **** "
Yann Colletde95f962016-05-23 19:46:47 +020058
Yann Collet8154c3d2016-02-13 03:12:10 +010059./datagen > tmp
Yann Colletb3060f72016-09-09 16:44:16 +020060$ECHO "test : basic compression "
Yann Collet673f0d72016-06-06 00:26:38 +020061$ZSTD -f tmp # trivial compression case, creates tmp.zst
Yann Colletb3060f72016-09-09 16:44:16 +020062$ECHO "test : basic decompression"
Yann Collet673f0d72016-06-06 00:26:38 +020063$ZSTD -df tmp.zst # trivial decompression case (overwrites tmp)
inikep5d589562016-05-25 10:50:28 +020064$ECHO "test : too large compression level (must fail)"
Yann Colletfab02302016-08-12 19:00:18 +020065$ZSTD -99 -f tmp # too large compression level, automatic sized down
inikep5d589562016-05-25 10:50:28 +020066$ECHO "test : compress to stdout"
Yann Collet0d348d42016-05-29 02:02:24 +020067$ZSTD tmp -c > tmpCompressed
Yann Colletd6931172016-05-10 05:56:09 +020068$ZSTD tmp --stdout > tmpCompressed # long command format
Yann Collet27b5ac62016-09-21 14:20:56 +020069$ECHO "test : compress to named file"
70rm tmpCompressed
71$ZSTD tmp -o tmpCompressed
72ls tmpCompressed # must work
73$ECHO "test : -o must be followed by filename (must fail)"
Yann Collet714464f2016-09-21 16:05:03 +020074$ZSTD tmp -of tmpCompressed && die "-o must be followed by filename "
Yann Collet27b5ac62016-09-21 14:20:56 +020075$ECHO "test : force write, correct order"
76$ZSTD tmp -fo tmpCompressed
Yann Collet714464f2016-09-21 16:05:03 +020077$ECHO "test : forgotten argument"
78cp tmp tmp2
79$ZSTD tmp2 -fo && die "-o must be followed by filename "
Yann Colletc8431422016-09-01 15:05:57 -070080$ECHO "test : implied stdout when input is stdin"
81$ECHO bob | $ZSTD | $ZSTD -d
Sean Purcell9a38dfa2017-03-17 12:32:18 -070082if [ "$isTerminal" = true ]; then
Sean Purcelld9730712017-03-16 16:25:19 -070083$ECHO "test : compressed data to terminal"
84$ECHO bob | $ZSTD && die "should have refused : compressed data to terminal"
85$ECHO "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)"
86$ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal"
Sean Purcell9a38dfa2017-03-17 12:32:18 -070087fi
inikep5d589562016-05-25 10:50:28 +020088$ECHO "test : null-length file roundtrip"
89$ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
90$ECHO "test : decompress file with wrong suffix (must fail)"
Yann Collet2d08b092016-02-16 14:42:08 +010091$ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
Yann Collet391a1282016-06-21 17:06:25 +020092$ZSTD -df tmp && die "should have refused : wrong extension"
93$ECHO "test : decompress into stdout"
Yann Collet0d348d42016-05-29 02:02:24 +020094$ZSTD -d tmpCompressed -c > tmpResult # decompression using stdout
Yann Collet2d08b092016-02-16 14:42:08 +010095$ZSTD --decompress tmpCompressed -c > tmpResult
96$ZSTD --decompress tmpCompressed --stdout > tmpResult
Yann Collet391a1282016-06-21 17:06:25 +020097$ECHO "test : decompress from stdin into stdout"
98$ZSTD -dc < tmp.zst > $INTOVOID # combine decompression, stdin & stdout
99$ZSTD -dc - < tmp.zst > $INTOVOID
100$ZSTD -d < tmp.zst > $INTOVOID # implicit stdout when stdin is used
101$ZSTD -d - < tmp.zst > $INTOVOID
Yann Colletd4cda272016-10-14 13:13:13 -0700102$ECHO "test : impose memory limitation (must fail)"
103$ZSTD -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
Yann Collet11223492016-10-14 14:07:11 -0700104$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 -0700105$ZSTD -d -f tmp.zst --memory=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
106$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 +0200107$ECHO "test : overwrite protection"
Yann Collet2d08b092016-02-16 14:42:08 +0100108$ZSTD -q tmp && die "overwrite check failed!"
Yann Collet391a1282016-06-21 17:06:25 +0200109$ECHO "test : force overwrite"
Yann Collet2d08b092016-02-16 14:42:08 +0100110$ZSTD -q -f tmp
111$ZSTD -q --force tmp
Yann Colletb09b12c2016-06-09 22:59:51 +0200112$ECHO "test : file removal"
113$ZSTD -f --rm tmp
114ls tmp && die "tmp should no longer be present"
115$ZSTD -f -d --rm tmp.zst
116ls tmp.zst && die "tmp.zst should no longer be present"
Yann Collet67d86a72017-02-27 16:09:20 -0800117$ECHO "test : --rm on stdin"
118$ECHO a | $ZSTD --rm > $INTOVOID # --rm should remain silent
Yann Colletb09b12c2016-06-09 22:59:51 +0200119rm tmp
120$ZSTD -f tmp && die "tmp not present : should have failed"
121ls tmp.zst && die "tmp.zst should not be created"
Yann Colletde95f962016-05-23 19:46:47 +0200122
123
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100124$ECHO "\n**** Advanced compression parameters **** "
Przemyslaw Skibinski24a42362016-12-14 18:07:31 +0100125$ECHO "Hello world!" | $ZSTD --zstd=windowLog=21, - -o tmp.zst && die "wrong parameters not detected!"
126$ECHO "Hello world!" | $ZSTD --zstd=windowLo=21 - -o tmp.zst && die "wrong parameters not detected!"
Przemyslaw Skibinskif9a56662016-12-14 18:43:06 +0100127$ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,slog - -o tmp.zst && die "wrong parameters not detected!"
Przemyslaw Skibinski24a42362016-12-14 18:07:31 +0100128ls tmp.zst && die "tmp.zst should not be created"
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100129roundTripTest -g512K
Przemyslaw Skibinskiab5ed6f2016-12-14 17:10:38 +0100130roundTripTest -g512K " --zstd=slen=3,tlen=48,strat=6"
131roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100132roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,searchLength=3,targetLength=48,strategy=6"
133roundTripTest -g512K 19
134
135
inikep5d589562016-05-25 10:50:28 +0200136$ECHO "\n**** Pass-Through mode **** "
Yann Collet743b33f2016-12-02 15:18:57 -0800137$ECHO "Hello world 1!" | $ZSTD -df
138$ECHO "Hello world 2!" | $ZSTD -dcf
139$ECHO "Hello world 3!" > tmp1
140$ZSTD -dcf tmp1
Yann Colletde95f962016-05-23 19:46:47 +0200141
Yann Collet8154c3d2016-02-13 03:12:10 +0100142
inikep5d589562016-05-25 10:50:28 +0200143$ECHO "\n**** frame concatenation **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300144
inikep5d589562016-05-25 10:50:28 +0200145$ECHO "hello " > hello.tmp
146$ECHO "world!" > world.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300147cat hello.tmp world.tmp > helloworld.tmp
Yann Colletc8da2c92016-02-12 02:56:27 +0100148$ZSTD -c hello.tmp > hello.zstd
149$ZSTD -c world.tmp > world.zstd
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300150cat hello.zstd world.zstd > helloworld.zstd
Yann Colletc8da2c92016-02-12 02:56:27 +0100151$ZSTD -dc helloworld.zstd > result.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300152cat result.tmp
Yann Colletbd6bc222017-01-22 15:54:14 -0800153$DIFF helloworld.tmp result.tmp
Yann Collet4c5bbf62016-07-28 20:30:25 +0200154$ECHO "frame concatenation without checksum"
155$ZSTD -c hello.tmp > hello.zstd --no-check
156$ZSTD -c world.tmp > world.zstd --no-check
157cat hello.zstd world.zstd > helloworld.zstd
158$ZSTD -dc helloworld.zstd > result.tmp
159cat result.tmp
Yann Colletbd6bc222017-01-22 15:54:14 -0800160$DIFF helloworld.tmp result.tmp
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300161rm ./*.tmp ./*.zstd
inikep5d589562016-05-25 10:50:28 +0200162$ECHO "frame concatenation tests completed"
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300163
Yann Colletf0624362016-02-12 15:56:46 +0100164
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100165if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] ; then
inikep5d589562016-05-25 10:50:28 +0200166$ECHO "\n**** flush write error test **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300167
inikep5d589562016-05-25 10:50:28 +0200168$ECHO "$ECHO foo | $ZSTD > /dev/full"
169$ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
170$ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
171$ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
Sean Purcell680e4e02017-03-23 11:52:09 -0700172
173$ECHO "\n**** symbolic link test **** "
174
175rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
176$ECHO "hello world" > hello.tmp
177ln -s hello.tmp world.tmp
178$ZSTD world.tmp hello.tmp
179ls hello.tmp.zst || die "regular file should have been compressed!"
180ls world.tmp.zst && die "symbolic link should not have been compressed!"
181$ZSTD world.tmp hello.tmp -f
182ls world.tmp.zst || die "symbol link should have been compressed with --force"
183rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
184
inikep5d589562016-05-25 10:50:28 +0200185fi
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300186
Yann Collet6a458352015-12-18 02:51:14 +0100187
inikep5d589562016-05-25 10:50:28 +0200188$ECHO "\n**** test sparse file support **** "
Yann Collet32990b52016-05-23 17:48:57 +0200189
190./datagen -g5M -P100 > tmpSparse
191$ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100192$DIFF -s tmpSparse tmpSparseRegen
Yann Collet32990b52016-05-23 17:48:57 +0200193$ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100194$DIFF -s tmpSparse tmpOutSparse
Yann Collet32990b52016-05-23 17:48:57 +0200195$ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100196$DIFF -s tmpSparse tmpOutNoSparse
Yann Collet32990b52016-05-23 17:48:57 +0200197ls -ls tmpSparse*
198./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 +0100199./datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
Yann Collet32990b52016-05-23 17:48:57 +0200200ls -ls tmpSparseOdd
inikep5d589562016-05-25 10:50:28 +0200201$ECHO "\n Sparse Compatibility with Console :"
202$ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
203$ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
204$ECHO "\n Sparse Compatibility with Append :"
Yann Collet32990b52016-05-23 17:48:57 +0200205./datagen -P100 -g1M > tmpSparse1M
206cat tmpSparse1M tmpSparse1M > tmpSparse2M
207$ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
208$ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
209$ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
210ls -ls tmpSparse*
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100211$DIFF tmpSparse2M tmpSparseRegenerated
Yann Collet33341de2016-05-29 23:09:51 +0200212rm tmpSparse*
Yann Collet32990b52016-05-23 17:48:57 +0200213
214
Yann Collet9b998e42016-06-15 23:11:20 +0200215$ECHO "\n**** multiple files tests **** "
216
Yann Collet391a1282016-06-21 17:06:25 +0200217./datagen -s1 > tmp1 2> $INTOVOID
218./datagen -s2 -g100K > tmp2 2> $INTOVOID
219./datagen -s3 -g1M > tmp3 2> $INTOVOID
Yann Collet9b998e42016-06-15 23:11:20 +0200220$ECHO "compress tmp* : "
Yann Collet60ba31c2016-07-28 19:55:09 +0200221$ZSTD -f tmp*
Yann Collet9b998e42016-06-15 23:11:20 +0200222ls -ls tmp*
223rm tmp1 tmp2 tmp3
224$ECHO "decompress tmp* : "
225$ZSTD -df *.zst
226ls -ls tmp*
227$ECHO "compress tmp* into stdout > tmpall : "
228$ZSTD -c tmp1 tmp2 tmp3 > tmpall
229ls -ls tmp*
230$ECHO "decompress tmpall* into stdout > tmpdec : "
231cp tmpall tmpall2
232$ZSTD -dc tmpall* > tmpdec
233ls -ls tmp*
234$ECHO "compress multiple files including a missing one (notHere) : "
235$ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
236
237
inikep5d589562016-05-25 10:50:28 +0200238$ECHO "\n**** dictionary tests **** "
Yann Colletf6f3d752015-12-13 13:35:21 +0100239
Yann Colletbd7fa212017-02-26 14:43:07 -0800240$ECHO "- test with raw dict (content only) "
Yann Colletf6f3d752015-12-13 13:35:21 +0100241./datagen > tmpDict
inikep93fc13e2016-05-30 10:17:55 +0200242./datagen -g1M | $MD5SUM > tmp1
243./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100244$DIFF -q tmp1 tmp2
Yann Colletbd7fa212017-02-26 14:43:07 -0800245$ECHO "- Create first dictionary "
246TESTFILE=../programs/zstdcli.c
inikepb7d34492016-08-18 15:13:41 +0200247$ZSTD --train *.c ../programs/*.c -o tmpDict
248cp $TESTFILE tmp
Yann Collet6381e992016-05-31 02:29:45 +0200249$ZSTD -f tmp -D tmpDict
Yann Collet27b5ac62016-09-21 14:20:56 +0200250$ZSTD -d tmp.zst -D tmpDict -fo result
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100251$DIFF $TESTFILE result
Yann Colletbd7fa212017-02-26 14:43:07 -0800252$ECHO "- Create second (different) dictionary "
inikepb7d34492016-08-18 15:13:41 +0200253$ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
Yann Collet27b5ac62016-09-21 14:20:56 +0200254$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
Yann Collet531a4272016-06-15 19:02:11 +0200255$ECHO "- Create dictionary with short dictID"
inikepb7d34492016-08-18 15:13:41 +0200256$ZSTD --train *.c ../programs/*.c --dictID 1 -o tmpDict1
Yann Collet290aaa72016-05-30 21:18:52 +0200257cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
Yann Collet27b5ac62016-09-21 14:20:56 +0200258$ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
259$ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
260$ECHO "- Create dictionary with size limit"
261$ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict 4K -v
262$ECHO "- Create dictionary with wrong parameter order (must fail)"
263$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 +0200264$ECHO "- Compress without dictID"
Yann Collet6381e992016-05-31 02:29:45 +0200265$ZSTD -f tmp -D tmpDict1 --no-dictID
Yann Collet27b5ac62016-09-21 14:20:56 +0200266$ZSTD -d tmp.zst -D tmpDict -fo result
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100267$DIFF $TESTFILE result
Yann Collet27b5ac62016-09-21 14:20:56 +0200268$ECHO "- Compress with wrong argument order (must fail)"
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700269$ZSTD tmp -Df tmpDict1 -c > $INTOVOID && die "-D must be followed by dictionary name "
Yann Collet531a4272016-06-15 19:02:11 +0200270$ECHO "- Compress multiple files with dictionary"
Yann Collet531a4272016-06-15 19:02:11 +0200271rm -rf dirTestDict
272mkdir dirTestDict
273cp *.c dirTestDict
inikepb7d34492016-08-18 15:13:41 +0200274cp ../programs/*.c dirTestDict
275cp ../programs/*.h dirTestDict
Yann Collet94376ac2016-08-25 19:09:21 +0200276$MD5SUM dirTestDict/* > tmph1
277$ZSTD -f --rm dirTestDict/* -D tmpDictC
Yann Colletbb93d772016-08-25 22:22:50 +0200278$ZSTD -d --rm dirTestDict/*.zst -D tmpDictC # note : use internal checksum by default
Dimitry Andric12df6da2016-12-12 19:22:47 +0100279case "$UNAME" in
280 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 -0800281 *) $MD5SUM -c tmph1 ;;
282esac
Yann Collet531a4272016-06-15 19:02:11 +0200283rm -rf dirTestDict
Yann Colletf332ece2017-03-23 16:24:02 -0700284$ECHO "- dictionary builder on bogus input"
285$ECHO "Hello World" > tmp
286$ZSTD --train -q tmp && die "Dictionary training should fail : not enough input source"
287./datagen -P0 -g10M > tmp
288$ZSTD --train -q tmp && die "Dictionary training should fail : source is pure noise"
Yann Collet6381e992016-05-31 02:29:45 +0200289rm tmp*
Yann Colletb44be742016-03-26 20:52:14 +0100290
Yann Colletf6f3d752015-12-13 13:35:21 +0100291
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500292$ECHO "\n**** cover dictionary tests **** "
293
294TESTFILE=../programs/zstdcli.c
295./datagen > tmpDict
296$ECHO "- Create first dictionary"
297$ZSTD --train --cover=k=46,d=8 *.c ../programs/*.c -o tmpDict
298cp $TESTFILE tmp
299$ZSTD -f tmp -D tmpDict
300$ZSTD -d tmp.zst -D tmpDict -fo result
301$DIFF $TESTFILE result
302$ECHO "- Create second (different) dictionary"
Nick Terrell3a1fefc2017-01-02 12:40:43 -0800303$ZSTD --train --cover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500304$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
305$ECHO "- Create dictionary with short dictID"
306$ZSTD --train --cover=k=46,d=8 *.c ../programs/*.c --dictID 1 -o tmpDict1
307cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
308$ECHO "- Create dictionary with size limit"
Nick Terrell3a1fefc2017-01-02 12:40:43 -0800309$ZSTD --train --optimize-cover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict 4K
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500310rm tmp*
311
312
inikep5d589562016-05-25 10:50:28 +0200313$ECHO "\n**** integrity tests **** "
Yann Colletde95f962016-05-23 19:46:47 +0200314
inikep5d589562016-05-25 10:50:28 +0200315$ECHO "test one file (tmp1.zst) "
Yann Collet1a7b8fb2016-06-15 23:33:38 +0200316./datagen > tmp1
317$ZSTD tmp1
Yann Collet459a6b72016-02-15 20:37:23 +0100318$ZSTD -t tmp1.zst
Yann Collet2d08b092016-02-16 14:42:08 +0100319$ZSTD --test tmp1.zst
inikep5d589562016-05-25 10:50:28 +0200320$ECHO "test multiple files (*.zst) "
Yann Collet459a6b72016-02-15 20:37:23 +0100321$ZSTD -t *.zst
Yann Collet24a3d902016-07-26 01:26:56 +0200322$ECHO "test bad files (*) "
Yann Collet459a6b72016-02-15 20:37:23 +0100323$ZSTD -t * && die "bad files not detected !"
Yann Collet24a3d902016-07-26 01:26:56 +0200324$ZSTD -t tmp1 && die "bad file not detected !"
325cp tmp1 tmp2.zst
326$ZSTD -t tmp2.zst && die "bad file not detected !"
Yann Collet7adc2322016-07-26 15:39:31 +0200327./datagen -g0 > tmp3
328$ZSTD -t tmp3 && die "bad file not detected !" # detects 0-sized files as bad
Yann Colletb4024902016-07-26 00:49:47 +0200329$ECHO "test --rm and --test combined "
330$ZSTD -t --rm tmp1.zst
331ls -ls tmp1.zst # check file is still present
Yann Colletdeb078b2015-12-17 20:30:14 +0100332
Yann Colletde95f962016-05-23 19:46:47 +0200333
Yann Colletb9550d62016-10-28 14:43:24 -0700334$ECHO "\n**** benchmark mode tests **** "
335
336$ECHO "bench one file"
337./datagen > tmp1
Yann Colletc1c040e2017-03-01 16:49:20 -0800338$ZSTD -bi0 tmp1
Yann Colletb9550d62016-10-28 14:43:24 -0700339$ECHO "bench multiple levels"
Yann Colletc1c040e2017-03-01 16:49:20 -0800340$ZSTD -i0b0e3 tmp1
Yann Colletb9550d62016-10-28 14:43:24 -0700341$ECHO "with recursive and quiet modes"
Yann Colletc1c040e2017-03-01 16:49:20 -0800342$ZSTD -rqi1b1e2 tmp1
343
344
345$ECHO "\n**** gzip compatibility tests **** "
346
347GZIPMODE=1
348$ZSTD --format=gzip -V || GZIPMODE=0
349if [ $GZIPMODE -eq 1 ]; then
Yann Collet27526c72017-03-01 17:02:49 -0800350 $ECHO "gzip support detected"
Yann Colletc1c040e2017-03-01 16:49:20 -0800351 GZIPEXE=1
Yann Collet27526c72017-03-01 17:02:49 -0800352 gzip -V || GZIPEXE=0
Yann Colletc1c040e2017-03-01 16:49:20 -0800353 if [ $GZIPEXE -eq 1 ]; then
354 ./datagen > tmp
355 $ZSTD --format=gzip -f tmp
356 gzip -t -v tmp.gz
357 gzip -f tmp
358 $ZSTD -d -f -v tmp.gz
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700359 rm tmp*
Yann Colletc1c040e2017-03-01 16:49:20 -0800360 else
361 $ECHO "gzip binary not detected"
362 fi
363else
364 $ECHO "gzip mode not supported"
365fi
Yann Colletb9550d62016-10-28 14:43:24 -0700366
367
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700368$ECHO "\n**** gzip frame tests **** "
369
370if [ $GZIPMODE -eq 1 ]; then
371 ./datagen > tmp
372 $ZSTD -f --format=gzip tmp
373 $ZSTD -f tmp
374 cat tmp.gz tmp.zst tmp.gz tmp.zst | $ZSTD -d -f -o tmp
375 head -c -1 tmp.gz | $ZSTD -t && die "incomplete frame not detected !"
376 rm tmp*
377else
378 $ECHO "gzip mode not supported"
379fi
380
381
382$ECHO "\n**** xz compatibility tests **** "
383
384LZMAMODE=1
385$ZSTD --format=xz -V || LZMAMODE=0
386if [ $LZMAMODE -eq 1 ]; then
387 $ECHO "xz support detected"
388 XZEXE=1
389 xz -V && lzma -V || XZEXE=0
390 if [ $XZEXE -eq 1 ]; then
391 ./datagen > tmp
392 $ZSTD --format=lzma -f tmp
393 $ZSTD --format=xz -f tmp
394 xz -t -v tmp.xz
395 xz -t -v tmp.lzma
396 xz -f -k tmp
397 lzma -f -k --lzma1 tmp
398 $ZSTD -d -f -v tmp.xz
399 $ZSTD -d -f -v tmp.lzma
400 rm tmp*
401 else
402 $ECHO "xz binary not detected"
403 fi
404else
405 $ECHO "xz mode not supported"
406fi
407
408
409$ECHO "\n**** xz frame tests **** "
410
411if [ $LZMAMODE -eq 1 ]; then
412 ./datagen > tmp
413 $ZSTD -f --format=xz tmp
414 $ZSTD -f --format=lzma tmp
415 $ZSTD -f tmp
416 cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | $ZSTD -d -f -o tmp
417 head -c -1 tmp.xz | $ZSTD -t && die "incomplete frame not detected !"
418 head -c -1 tmp.lzma | $ZSTD -t && die "incomplete frame not detected !"
419 rm tmp*
420else
421 $ECHO "xz mode not supported"
422fi
423
424
inikep5d589562016-05-25 10:50:28 +0200425$ECHO "\n**** zstd round-trip tests **** "
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300426
427roundTripTest
Yann Collet3b719252016-03-30 19:48:05 +0200428roundTripTest -g15K # TableID==3
429roundTripTest -g127K # TableID==2
430roundTripTest -g255K # TableID==1
Yann Colletc1c040e2017-03-01 16:49:20 -0800431roundTripTest -g522K # TableID==0
432roundTripTest -g519K 6 # greedy, hash chain
433roundTripTest -g517K 16 # btlazy2
434roundTripTest -g516K 19 # btopt
Yann Collet459a6b72016-02-15 20:37:23 +0100435
436rm tmp*
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300437
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300438if [ "$1" != "--test-large-data" ]; then
inikep5d589562016-05-25 10:50:28 +0200439 $ECHO "Skipping large data tests"
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300440 exit 0
441fi
442
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300443roundTripTest -g270000000 1
444roundTripTest -g270000000 2
445roundTripTest -g270000000 3
446
447roundTripTest -g140000000 -P60 4
448roundTripTest -g140000000 -P60 5
449roundTripTest -g140000000 -P60 6
450
451roundTripTest -g70000000 -P70 7
452roundTripTest -g70000000 -P70 8
453roundTripTest -g70000000 -P70 9
454
455roundTripTest -g35000000 -P75 10
456roundTripTest -g35000000 -P75 11
457roundTripTest -g35000000 -P75 12
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300458
Konstantin Tokarev2b465842015-12-08 19:36:42 +0300459roundTripTest -g18000000 -P80 13
460roundTripTest -g18000000 -P80 14
461roundTripTest -g18000000 -P80 15
462roundTripTest -g18000000 -P80 16
463roundTripTest -g18000000 -P80 17
464
465roundTripTest -g50000000 -P94 18
466roundTripTest -g50000000 -P94 19
467
468roundTripTest -g99000000 -P99 20
Yann Colletecabfe32016-03-20 16:20:06 +0100469roundTripTest -g6000000000 -P99 1
Yann Collet459a6b72016-02-15 20:37:23 +0100470
471rm tmp*