blob: 6ef5914a9ce5f414f4950e9fcaa6e9e309ab0012 [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"
Sean Purcelleb70d212017-04-11 17:15:13 -070014 local_p=""
Konstantin Tokarev76be3782015-12-08 18:36:37 +030015 fi
16
17 rm -f tmp1 tmp2
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +010018 $ECHO "roundTripTest: ./datagen $1 $local_p | $ZSTD -v$local_c | $ZSTD -d"
19 ./datagen $1 $local_p | $MD5SUM > tmp1
20 ./datagen $1 $local_p | $ZSTD --ultra -v$local_c | $ZSTD -d | $MD5SUM > tmp2
21 $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
34 $ECHO "fileRoundTripTest: ./datagen $1 $local_p > tmp1 && $ZSTD -v$local_c -c | $ZSTD -d | $MD5SUM > tmp.md5.2"
35 ./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
48ECHO="echo"
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
53 ECHO="echo -e"
Sean Purcell9a38dfa2017-03-17 12:32:18 -070054 INTOVOID="NUL"
inikep993a9df2016-05-27 10:07:46 +020055 ;;
56esac
inikep5d589562016-05-25 10:50:28 +020057
Dimitry Andric12df6da2016-12-12 19:22:47 +010058UNAME=$(uname)
59case "$UNAME" in
60 Darwin) MD5SUM="md5 -r" ;;
61 FreeBSD) MD5SUM="gmd5sum" ;;
Yann Collet94d1a932016-12-06 12:02:56 -080062 *) MD5SUM="md5sum" ;;
63esac
inikep5d589562016-05-25 10:50:28 +020064
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +010065DIFF="diff"
66case "$UNAME" in
67 SunOS) DIFF="gdiff" ;;
68esac
69
70
Przemyslaw Skibinskie579ab52016-11-14 12:57:05 +010071$ECHO "\nStarting playTests.sh isWindows=$isWindows ZSTD='$ZSTD'"
inikep5d589562016-05-25 10:50:28 +020072
Konstantin Tokarev76be3782015-12-08 18:36:37 +030073[ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
74
inikep5d589562016-05-25 10:50:28 +020075$ECHO "\n**** simple tests **** "
Yann Colletde95f962016-05-23 19:46:47 +020076
Yann Collet8154c3d2016-02-13 03:12:10 +010077./datagen > tmp
Yann Colletb3060f72016-09-09 16:44:16 +020078$ECHO "test : basic compression "
Yann Collet673f0d72016-06-06 00:26:38 +020079$ZSTD -f tmp # trivial compression case, creates tmp.zst
Yann Colletb3060f72016-09-09 16:44:16 +020080$ECHO "test : basic decompression"
Yann Collet673f0d72016-06-06 00:26:38 +020081$ZSTD -df tmp.zst # trivial decompression case (overwrites tmp)
inikep5d589562016-05-25 10:50:28 +020082$ECHO "test : too large compression level (must fail)"
Yann Colletfab02302016-08-12 19:00:18 +020083$ZSTD -99 -f tmp # too large compression level, automatic sized down
inikep5d589562016-05-25 10:50:28 +020084$ECHO "test : compress to stdout"
Yann Collet0d348d42016-05-29 02:02:24 +020085$ZSTD tmp -c > tmpCompressed
Yann Colletd6931172016-05-10 05:56:09 +020086$ZSTD tmp --stdout > tmpCompressed # long command format
Yann Collet27b5ac62016-09-21 14:20:56 +020087$ECHO "test : compress to named file"
88rm tmpCompressed
89$ZSTD tmp -o tmpCompressed
90ls tmpCompressed # must work
91$ECHO "test : -o must be followed by filename (must fail)"
Yann Collet714464f2016-09-21 16:05:03 +020092$ZSTD tmp -of tmpCompressed && die "-o must be followed by filename "
Yann Collet27b5ac62016-09-21 14:20:56 +020093$ECHO "test : force write, correct order"
94$ZSTD tmp -fo tmpCompressed
Yann Collet714464f2016-09-21 16:05:03 +020095$ECHO "test : forgotten argument"
96cp tmp tmp2
97$ZSTD tmp2 -fo && die "-o must be followed by filename "
Yann Colletc8431422016-09-01 15:05:57 -070098$ECHO "test : implied stdout when input is stdin"
99$ECHO bob | $ZSTD | $ZSTD -d
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700100if [ "$isTerminal" = true ]; then
Sean Purcelld9730712017-03-16 16:25:19 -0700101$ECHO "test : compressed data to terminal"
102$ECHO bob | $ZSTD && die "should have refused : compressed data to terminal"
103$ECHO "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)"
104$ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal"
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700105fi
inikep5d589562016-05-25 10:50:28 +0200106$ECHO "test : null-length file roundtrip"
107$ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
108$ECHO "test : decompress file with wrong suffix (must fail)"
Yann Collet2d08b092016-02-16 14:42:08 +0100109$ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
Yann Collet391a1282016-06-21 17:06:25 +0200110$ZSTD -df tmp && die "should have refused : wrong extension"
111$ECHO "test : decompress into stdout"
Yann Collet0d348d42016-05-29 02:02:24 +0200112$ZSTD -d tmpCompressed -c > tmpResult # decompression using stdout
Yann Collet2d08b092016-02-16 14:42:08 +0100113$ZSTD --decompress tmpCompressed -c > tmpResult
114$ZSTD --decompress tmpCompressed --stdout > tmpResult
Yann Collet391a1282016-06-21 17:06:25 +0200115$ECHO "test : decompress from stdin into stdout"
116$ZSTD -dc < tmp.zst > $INTOVOID # combine decompression, stdin & stdout
117$ZSTD -dc - < tmp.zst > $INTOVOID
118$ZSTD -d < tmp.zst > $INTOVOID # implicit stdout when stdin is used
119$ZSTD -d - < tmp.zst > $INTOVOID
Yann Colletd4cda272016-10-14 13:13:13 -0700120$ECHO "test : impose memory limitation (must fail)"
121$ZSTD -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
Yann Collet11223492016-10-14 14:07:11 -0700122$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 -0700123$ZSTD -d -f tmp.zst --memory=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
124$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 +0200125$ECHO "test : overwrite protection"
Yann Collet2d08b092016-02-16 14:42:08 +0100126$ZSTD -q tmp && die "overwrite check failed!"
Yann Collet391a1282016-06-21 17:06:25 +0200127$ECHO "test : force overwrite"
Yann Collet2d08b092016-02-16 14:42:08 +0100128$ZSTD -q -f tmp
129$ZSTD -q --force tmp
Sean Purcell9da11c62017-04-06 12:58:49 -0700130$ECHO "test : overwrite readonly file"
Sean Purcell16521722017-04-06 17:06:30 -0700131rm -f tmpro tmpro.zst
Sean Purcell9da11c62017-04-06 12:58:49 -0700132$ECHO foo > tmpro.zst
133$ECHO foo > tmpro
134chmod 400 tmpro.zst
Sean Purcell16521722017-04-06 17:06:30 -0700135$ZSTD -q tmpro && die "should have refused to overwrite read-only file"
136$ZSTD -q -f tmpro
137rm -f tmpro tmpro.zst
Yann Colletb09b12c2016-06-09 22:59:51 +0200138$ECHO "test : file removal"
139$ZSTD -f --rm tmp
140ls tmp && die "tmp should no longer be present"
141$ZSTD -f -d --rm tmp.zst
142ls tmp.zst && die "tmp.zst should no longer be present"
Yann Collet67d86a72017-02-27 16:09:20 -0800143$ECHO "test : --rm on stdin"
144$ECHO a | $ZSTD --rm > $INTOVOID # --rm should remain silent
Yann Colletb09b12c2016-06-09 22:59:51 +0200145rm tmp
146$ZSTD -f tmp && die "tmp not present : should have failed"
147ls tmp.zst && die "tmp.zst should not be created"
Yann Colletde95f962016-05-23 19:46:47 +0200148
149
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100150$ECHO "\n**** Advanced compression parameters **** "
Przemyslaw Skibinski24a42362016-12-14 18:07:31 +0100151$ECHO "Hello world!" | $ZSTD --zstd=windowLog=21, - -o tmp.zst && die "wrong parameters not detected!"
152$ECHO "Hello world!" | $ZSTD --zstd=windowLo=21 - -o tmp.zst && die "wrong parameters not detected!"
Przemyslaw Skibinskif9a56662016-12-14 18:43:06 +0100153$ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,slog - -o tmp.zst && die "wrong parameters not detected!"
Przemyslaw Skibinski24a42362016-12-14 18:07:31 +0100154ls tmp.zst && die "tmp.zst should not be created"
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100155roundTripTest -g512K
Przemyslaw Skibinskiab5ed6f2016-12-14 17:10:38 +0100156roundTripTest -g512K " --zstd=slen=3,tlen=48,strat=6"
157roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100158roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,searchLength=3,targetLength=48,strategy=6"
159roundTripTest -g512K 19
160
161
inikep5d589562016-05-25 10:50:28 +0200162$ECHO "\n**** Pass-Through mode **** "
Yann Collet743b33f2016-12-02 15:18:57 -0800163$ECHO "Hello world 1!" | $ZSTD -df
164$ECHO "Hello world 2!" | $ZSTD -dcf
165$ECHO "Hello world 3!" > tmp1
166$ZSTD -dcf tmp1
Yann Colletde95f962016-05-23 19:46:47 +0200167
Yann Collet8154c3d2016-02-13 03:12:10 +0100168
inikep5d589562016-05-25 10:50:28 +0200169$ECHO "\n**** frame concatenation **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300170
inikep5d589562016-05-25 10:50:28 +0200171$ECHO "hello " > hello.tmp
172$ECHO "world!" > world.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300173cat hello.tmp world.tmp > helloworld.tmp
Yann Colletc8da2c92016-02-12 02:56:27 +0100174$ZSTD -c hello.tmp > hello.zstd
175$ZSTD -c world.tmp > world.zstd
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300176cat hello.zstd world.zstd > helloworld.zstd
Yann Colletc8da2c92016-02-12 02:56:27 +0100177$ZSTD -dc helloworld.zstd > result.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300178cat result.tmp
Yann Colletbd6bc222017-01-22 15:54:14 -0800179$DIFF helloworld.tmp result.tmp
Yann Collet4c5bbf62016-07-28 20:30:25 +0200180$ECHO "frame concatenation without checksum"
181$ZSTD -c hello.tmp > hello.zstd --no-check
182$ZSTD -c world.tmp > world.zstd --no-check
183cat hello.zstd world.zstd > helloworld.zstd
184$ZSTD -dc helloworld.zstd > result.tmp
185cat result.tmp
Yann Colletbd6bc222017-01-22 15:54:14 -0800186$DIFF helloworld.tmp result.tmp
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300187rm ./*.tmp ./*.zstd
inikep5d589562016-05-25 10:50:28 +0200188$ECHO "frame concatenation tests completed"
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300189
Yann Colletf0624362016-02-12 15:56:46 +0100190
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100191if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] ; then
inikep5d589562016-05-25 10:50:28 +0200192$ECHO "\n**** flush write error test **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300193
inikep5d589562016-05-25 10:50:28 +0200194$ECHO "$ECHO foo | $ZSTD > /dev/full"
195$ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
196$ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
197$ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
Sean Purcell680e4e02017-03-23 11:52:09 -0700198
199$ECHO "\n**** symbolic link test **** "
200
201rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
202$ECHO "hello world" > hello.tmp
203ln -s hello.tmp world.tmp
204$ZSTD world.tmp hello.tmp
205ls hello.tmp.zst || die "regular file should have been compressed!"
206ls world.tmp.zst && die "symbolic link should not have been compressed!"
207$ZSTD world.tmp hello.tmp -f
208ls world.tmp.zst || die "symbol link should have been compressed with --force"
209rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
210
inikep5d589562016-05-25 10:50:28 +0200211fi
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300212
Yann Collet6a458352015-12-18 02:51:14 +0100213
inikep5d589562016-05-25 10:50:28 +0200214$ECHO "\n**** test sparse file support **** "
Yann Collet32990b52016-05-23 17:48:57 +0200215
216./datagen -g5M -P100 > tmpSparse
217$ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100218$DIFF -s tmpSparse tmpSparseRegen
Yann Collet32990b52016-05-23 17:48:57 +0200219$ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100220$DIFF -s tmpSparse tmpOutSparse
Yann Collet32990b52016-05-23 17:48:57 +0200221$ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100222$DIFF -s tmpSparse tmpOutNoSparse
Yann Collet32990b52016-05-23 17:48:57 +0200223ls -ls tmpSparse*
224./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 +0100225./datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
Yann Collet32990b52016-05-23 17:48:57 +0200226ls -ls tmpSparseOdd
inikep5d589562016-05-25 10:50:28 +0200227$ECHO "\n Sparse Compatibility with Console :"
228$ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
229$ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
230$ECHO "\n Sparse Compatibility with Append :"
Yann Collet32990b52016-05-23 17:48:57 +0200231./datagen -P100 -g1M > tmpSparse1M
232cat tmpSparse1M tmpSparse1M > tmpSparse2M
233$ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
234$ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
235$ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
236ls -ls tmpSparse*
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100237$DIFF tmpSparse2M tmpSparseRegenerated
Yann Collet33341de2016-05-29 23:09:51 +0200238rm tmpSparse*
Yann Collet32990b52016-05-23 17:48:57 +0200239
240
Yann Collet9b998e42016-06-15 23:11:20 +0200241$ECHO "\n**** multiple files tests **** "
242
Yann Collet391a1282016-06-21 17:06:25 +0200243./datagen -s1 > tmp1 2> $INTOVOID
244./datagen -s2 -g100K > tmp2 2> $INTOVOID
245./datagen -s3 -g1M > tmp3 2> $INTOVOID
Yann Collet9b998e42016-06-15 23:11:20 +0200246$ECHO "compress tmp* : "
Yann Collet60ba31c2016-07-28 19:55:09 +0200247$ZSTD -f tmp*
Yann Collet9b998e42016-06-15 23:11:20 +0200248ls -ls tmp*
249rm tmp1 tmp2 tmp3
250$ECHO "decompress tmp* : "
251$ZSTD -df *.zst
252ls -ls tmp*
253$ECHO "compress tmp* into stdout > tmpall : "
254$ZSTD -c tmp1 tmp2 tmp3 > tmpall
255ls -ls tmp*
256$ECHO "decompress tmpall* into stdout > tmpdec : "
257cp tmpall tmpall2
258$ZSTD -dc tmpall* > tmpdec
259ls -ls tmp*
260$ECHO "compress multiple files including a missing one (notHere) : "
261$ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
262
263
inikep5d589562016-05-25 10:50:28 +0200264$ECHO "\n**** dictionary tests **** "
Yann Colletf6f3d752015-12-13 13:35:21 +0100265
Yann Colletbd7fa212017-02-26 14:43:07 -0800266$ECHO "- test with raw dict (content only) "
Yann Colletf6f3d752015-12-13 13:35:21 +0100267./datagen > tmpDict
inikep93fc13e2016-05-30 10:17:55 +0200268./datagen -g1M | $MD5SUM > tmp1
269./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100270$DIFF -q tmp1 tmp2
Yann Colletbd7fa212017-02-26 14:43:07 -0800271$ECHO "- Create first dictionary "
272TESTFILE=../programs/zstdcli.c
inikepb7d34492016-08-18 15:13:41 +0200273$ZSTD --train *.c ../programs/*.c -o tmpDict
274cp $TESTFILE tmp
Yann Collet6381e992016-05-31 02:29:45 +0200275$ZSTD -f tmp -D tmpDict
Yann Collet27b5ac62016-09-21 14:20:56 +0200276$ZSTD -d tmp.zst -D tmpDict -fo result
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100277$DIFF $TESTFILE result
Yann Colletbd7fa212017-02-26 14:43:07 -0800278$ECHO "- Create second (different) dictionary "
inikepb7d34492016-08-18 15:13:41 +0200279$ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
Yann Collet27b5ac62016-09-21 14:20:56 +0200280$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
Yann Collet531a4272016-06-15 19:02:11 +0200281$ECHO "- Create dictionary with short dictID"
Yann Collet4c41d372017-03-24 18:36:56 -0700282$ZSTD --train *.c ../programs/*.c --dictID=1 -o tmpDict1
Yann Collet290aaa72016-05-30 21:18:52 +0200283cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
Yann Collet27b5ac62016-09-21 14:20:56 +0200284$ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
285$ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
286$ECHO "- Create dictionary with size limit"
Yann Collet4c41d372017-03-24 18:36:56 -0700287$ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict=4K -v
Yann Collet27b5ac62016-09-21 14:20:56 +0200288$ECHO "- Create dictionary with wrong parameter order (must fail)"
289$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 +0200290$ECHO "- Compress without dictID"
Yann Collet6381e992016-05-31 02:29:45 +0200291$ZSTD -f tmp -D tmpDict1 --no-dictID
Yann Collet27b5ac62016-09-21 14:20:56 +0200292$ZSTD -d tmp.zst -D tmpDict -fo result
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100293$DIFF $TESTFILE result
Yann Collet27b5ac62016-09-21 14:20:56 +0200294$ECHO "- Compress with wrong argument order (must fail)"
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700295$ZSTD tmp -Df tmpDict1 -c > $INTOVOID && die "-D must be followed by dictionary name "
Yann Collet531a4272016-06-15 19:02:11 +0200296$ECHO "- Compress multiple files with dictionary"
Yann Collet531a4272016-06-15 19:02:11 +0200297rm -rf dirTestDict
298mkdir dirTestDict
299cp *.c dirTestDict
inikepb7d34492016-08-18 15:13:41 +0200300cp ../programs/*.c dirTestDict
301cp ../programs/*.h dirTestDict
Yann Collet94376ac2016-08-25 19:09:21 +0200302$MD5SUM dirTestDict/* > tmph1
303$ZSTD -f --rm dirTestDict/* -D tmpDictC
Yann Colletbb93d772016-08-25 22:22:50 +0200304$ZSTD -d --rm dirTestDict/*.zst -D tmpDictC # note : use internal checksum by default
Dimitry Andric12df6da2016-12-12 19:22:47 +0100305case "$UNAME" in
306 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 -0800307 *) $MD5SUM -c tmph1 ;;
308esac
Yann Collet531a4272016-06-15 19:02:11 +0200309rm -rf dirTestDict
Yann Colletf332ece2017-03-23 16:24:02 -0700310$ECHO "- dictionary builder on bogus input"
311$ECHO "Hello World" > tmp
312$ZSTD --train -q tmp && die "Dictionary training should fail : not enough input source"
313./datagen -P0 -g10M > tmp
314$ZSTD --train -q tmp && die "Dictionary training should fail : source is pure noise"
Yann Collet6381e992016-05-31 02:29:45 +0200315rm tmp*
Yann Colletb44be742016-03-26 20:52:14 +0100316
Yann Colletf6f3d752015-12-13 13:35:21 +0100317
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500318$ECHO "\n**** cover dictionary tests **** "
319
320TESTFILE=../programs/zstdcli.c
321./datagen > tmpDict
322$ECHO "- Create first dictionary"
323$ZSTD --train --cover=k=46,d=8 *.c ../programs/*.c -o tmpDict
324cp $TESTFILE tmp
325$ZSTD -f tmp -D tmpDict
326$ZSTD -d tmp.zst -D tmpDict -fo result
327$DIFF $TESTFILE result
328$ECHO "- Create second (different) dictionary"
Nick Terrell3a1fefc2017-01-02 12:40:43 -0800329$ZSTD --train --cover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500330$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
331$ECHO "- Create dictionary with short dictID"
Yann Collet4c41d372017-03-24 18:36:56 -0700332$ZSTD --train --cover=k=46,d=8 *.c ../programs/*.c --dictID=1 -o tmpDict1
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500333cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
334$ECHO "- Create dictionary with size limit"
Yann Collet4c41d372017-03-24 18:36:56 -0700335$ZSTD --train --optimize-cover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500336rm tmp*
337
338
inikep5d589562016-05-25 10:50:28 +0200339$ECHO "\n**** integrity tests **** "
Yann Colletde95f962016-05-23 19:46:47 +0200340
inikep5d589562016-05-25 10:50:28 +0200341$ECHO "test one file (tmp1.zst) "
Yann Collet1a7b8fb2016-06-15 23:33:38 +0200342./datagen > tmp1
343$ZSTD tmp1
Yann Collet459a6b72016-02-15 20:37:23 +0100344$ZSTD -t tmp1.zst
Yann Collet2d08b092016-02-16 14:42:08 +0100345$ZSTD --test tmp1.zst
inikep5d589562016-05-25 10:50:28 +0200346$ECHO "test multiple files (*.zst) "
Yann Collet459a6b72016-02-15 20:37:23 +0100347$ZSTD -t *.zst
Yann Collet24a3d902016-07-26 01:26:56 +0200348$ECHO "test bad files (*) "
Yann Collet459a6b72016-02-15 20:37:23 +0100349$ZSTD -t * && die "bad files not detected !"
Yann Collet24a3d902016-07-26 01:26:56 +0200350$ZSTD -t tmp1 && die "bad file not detected !"
351cp tmp1 tmp2.zst
352$ZSTD -t tmp2.zst && die "bad file not detected !"
Yann Collet7adc2322016-07-26 15:39:31 +0200353./datagen -g0 > tmp3
354$ZSTD -t tmp3 && die "bad file not detected !" # detects 0-sized files as bad
Yann Colletb4024902016-07-26 00:49:47 +0200355$ECHO "test --rm and --test combined "
356$ZSTD -t --rm tmp1.zst
357ls -ls tmp1.zst # check file is still present
Yann Colletdeb078b2015-12-17 20:30:14 +0100358
Yann Colletde95f962016-05-23 19:46:47 +0200359
Yann Colletb9550d62016-10-28 14:43:24 -0700360$ECHO "\n**** benchmark mode tests **** "
361
362$ECHO "bench one file"
363./datagen > tmp1
Yann Colletc1c040e2017-03-01 16:49:20 -0800364$ZSTD -bi0 tmp1
Yann Colletb9550d62016-10-28 14:43:24 -0700365$ECHO "bench multiple levels"
Yann Colletc1c040e2017-03-01 16:49:20 -0800366$ZSTD -i0b0e3 tmp1
Yann Colletb9550d62016-10-28 14:43:24 -0700367$ECHO "with recursive and quiet modes"
Yann Colletc1c040e2017-03-01 16:49:20 -0800368$ZSTD -rqi1b1e2 tmp1
369
370
371$ECHO "\n**** gzip compatibility tests **** "
372
373GZIPMODE=1
374$ZSTD --format=gzip -V || GZIPMODE=0
375if [ $GZIPMODE -eq 1 ]; then
Yann Collet27526c72017-03-01 17:02:49 -0800376 $ECHO "gzip support detected"
Yann Colletc1c040e2017-03-01 16:49:20 -0800377 GZIPEXE=1
Yann Collet27526c72017-03-01 17:02:49 -0800378 gzip -V || GZIPEXE=0
Yann Colletc1c040e2017-03-01 16:49:20 -0800379 if [ $GZIPEXE -eq 1 ]; then
380 ./datagen > tmp
381 $ZSTD --format=gzip -f tmp
382 gzip -t -v tmp.gz
383 gzip -f tmp
384 $ZSTD -d -f -v tmp.gz
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700385 rm tmp*
Yann Colletc1c040e2017-03-01 16:49:20 -0800386 else
387 $ECHO "gzip binary not detected"
388 fi
389else
390 $ECHO "gzip mode not supported"
391fi
Yann Colletb9550d62016-10-28 14:43:24 -0700392
393
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700394$ECHO "\n**** gzip frame tests **** "
395
396if [ $GZIPMODE -eq 1 ]; then
397 ./datagen > tmp
398 $ZSTD -f --format=gzip tmp
399 $ZSTD -f tmp
400 cat tmp.gz tmp.zst tmp.gz tmp.zst | $ZSTD -d -f -o tmp
401 head -c -1 tmp.gz | $ZSTD -t && die "incomplete frame not detected !"
402 rm tmp*
403else
404 $ECHO "gzip mode not supported"
405fi
406
407
408$ECHO "\n**** xz compatibility tests **** "
409
410LZMAMODE=1
411$ZSTD --format=xz -V || LZMAMODE=0
412if [ $LZMAMODE -eq 1 ]; then
413 $ECHO "xz support detected"
414 XZEXE=1
415 xz -V && lzma -V || XZEXE=0
416 if [ $XZEXE -eq 1 ]; then
417 ./datagen > tmp
418 $ZSTD --format=lzma -f tmp
419 $ZSTD --format=xz -f tmp
420 xz -t -v tmp.xz
421 xz -t -v tmp.lzma
422 xz -f -k tmp
423 lzma -f -k --lzma1 tmp
424 $ZSTD -d -f -v tmp.xz
425 $ZSTD -d -f -v tmp.lzma
426 rm tmp*
427 else
428 $ECHO "xz binary not detected"
429 fi
430else
431 $ECHO "xz mode not supported"
432fi
433
434
435$ECHO "\n**** xz frame tests **** "
436
437if [ $LZMAMODE -eq 1 ]; then
438 ./datagen > tmp
439 $ZSTD -f --format=xz tmp
440 $ZSTD -f --format=lzma tmp
441 $ZSTD -f tmp
442 cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | $ZSTD -d -f -o tmp
443 head -c -1 tmp.xz | $ZSTD -t && die "incomplete frame not detected !"
444 head -c -1 tmp.lzma | $ZSTD -t && die "incomplete frame not detected !"
445 rm tmp*
446else
447 $ECHO "xz mode not supported"
448fi
449
450
inikep5d589562016-05-25 10:50:28 +0200451$ECHO "\n**** zstd round-trip tests **** "
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300452
453roundTripTest
Yann Collet3b719252016-03-30 19:48:05 +0200454roundTripTest -g15K # TableID==3
455roundTripTest -g127K # TableID==2
456roundTripTest -g255K # TableID==1
Yann Colletc1c040e2017-03-01 16:49:20 -0800457roundTripTest -g522K # TableID==0
458roundTripTest -g519K 6 # greedy, hash chain
459roundTripTest -g517K 16 # btlazy2
460roundTripTest -g516K 19 # btopt
Yann Collet459a6b72016-02-15 20:37:23 +0100461
Sean Purcelleb70d212017-04-11 17:15:13 -0700462fileRoundTripTest -g500K
463
Yann Collet459a6b72016-02-15 20:37:23 +0100464rm tmp*
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300465
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300466if [ "$1" != "--test-large-data" ]; then
inikep5d589562016-05-25 10:50:28 +0200467 $ECHO "Skipping large data tests"
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300468 exit 0
469fi
470
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300471roundTripTest -g270000000 1
472roundTripTest -g270000000 2
473roundTripTest -g270000000 3
474
475roundTripTest -g140000000 -P60 4
476roundTripTest -g140000000 -P60 5
477roundTripTest -g140000000 -P60 6
478
479roundTripTest -g70000000 -P70 7
480roundTripTest -g70000000 -P70 8
481roundTripTest -g70000000 -P70 9
482
483roundTripTest -g35000000 -P75 10
484roundTripTest -g35000000 -P75 11
485roundTripTest -g35000000 -P75 12
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300486
Konstantin Tokarev2b465842015-12-08 19:36:42 +0300487roundTripTest -g18000000 -P80 13
488roundTripTest -g18000000 -P80 14
489roundTripTest -g18000000 -P80 15
490roundTripTest -g18000000 -P80 16
491roundTripTest -g18000000 -P80 17
492
493roundTripTest -g50000000 -P94 18
494roundTripTest -g50000000 -P94 19
495
496roundTripTest -g99000000 -P99 20
Yann Colletecabfe32016-03-20 16:20:06 +0100497roundTripTest -g6000000000 -P99 1
Yann Collet459a6b72016-02-15 20:37:23 +0100498
Sean Purcelleb70d212017-04-11 17:15:13 -0700499fileRoundTripTest -g4193M -P99 1
500
Yann Collet459a6b72016-02-15 20:37:23 +0100501rm tmp*