blob: 1bc835f0c65372b30be2ca6c18c0cd8f19a968c8 [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
10 local c="$3"
11 local p="$2"
12 else
13 local c="$2"
14 fi
15
16 rm -f tmp1 tmp2
inikep5d589562016-05-25 10:50:28 +020017 $ECHO "roundTripTest: ./datagen $1 $p | $ZSTD -v$c | $ZSTD -d"
inikep93fc13e2016-05-30 10:17:55 +020018 ./datagen $1 $p | $MD5SUM > tmp1
Yann Collet06dd7412016-07-18 04:06:43 +020019 ./datagen $1 $p | $ZSTD -v$c | $ZSTD -d | $MD5SUM > tmp2
Konstantin Tokarev76be3782015-12-08 18:36:37 +030020 diff -q tmp1 tmp2
21}
22
inikep5d589562016-05-25 10:50:28 +020023isWindows=false
24ECHO="echo"
Yann Collet391a1282016-06-21 17:06:25 +020025INTOVOID="/dev/null"
inikep993a9df2016-05-27 10:07:46 +020026case "$OS" in
Yann Collet673f0d72016-06-06 00:26:38 +020027 Windows*)
inikep5d589562016-05-25 10:50:28 +020028 isWindows=true
29 ECHO="echo -e"
Yann Collet391a1282016-06-21 17:06:25 +020030 INTOVOID="nul"
inikep993a9df2016-05-27 10:07:46 +020031 ;;
32esac
inikep5d589562016-05-25 10:50:28 +020033
inikep93fc13e2016-05-30 10:17:55 +020034MD5SUM="md5sum"
Yann Collet70e3b312016-08-23 01:18:06 +020035if [[ "$OSTYPE" == "darwin"* ]]; then
inikep93fc13e2016-05-30 10:17:55 +020036 MD5SUM="md5 -r"
inikep5d589562016-05-25 10:50:28 +020037fi
38
Przemyslaw Skibinskie579ab52016-11-14 12:57:05 +010039$ECHO "\nStarting playTests.sh isWindows=$isWindows ZSTD='$ZSTD'"
inikep5d589562016-05-25 10:50:28 +020040
Konstantin Tokarev76be3782015-12-08 18:36:37 +030041[ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
42
inikep1dcb2ff2016-05-30 11:33:52 +020043file $ZSTD
Yann Colletc8431422016-09-01 15:05:57 -070044
inikep5d589562016-05-25 10:50:28 +020045$ECHO "\n**** simple tests **** "
Yann Colletde95f962016-05-23 19:46:47 +020046
Yann Collet8154c3d2016-02-13 03:12:10 +010047./datagen > tmp
Yann Colletb3060f72016-09-09 16:44:16 +020048$ECHO "test : basic compression "
Yann Collet673f0d72016-06-06 00:26:38 +020049$ZSTD -f tmp # trivial compression case, creates tmp.zst
Yann Colletb3060f72016-09-09 16:44:16 +020050$ECHO "test : basic decompression"
Yann Collet673f0d72016-06-06 00:26:38 +020051$ZSTD -df tmp.zst # trivial decompression case (overwrites tmp)
inikep5d589562016-05-25 10:50:28 +020052$ECHO "test : too large compression level (must fail)"
Yann Colletfab02302016-08-12 19:00:18 +020053$ZSTD -99 -f tmp # too large compression level, automatic sized down
inikep5d589562016-05-25 10:50:28 +020054$ECHO "test : compress to stdout"
Yann Collet0d348d42016-05-29 02:02:24 +020055$ZSTD tmp -c > tmpCompressed
Yann Colletd6931172016-05-10 05:56:09 +020056$ZSTD tmp --stdout > tmpCompressed # long command format
Yann Collet27b5ac62016-09-21 14:20:56 +020057$ECHO "test : compress to named file"
58rm tmpCompressed
59$ZSTD tmp -o tmpCompressed
60ls tmpCompressed # must work
61$ECHO "test : -o must be followed by filename (must fail)"
Yann Collet714464f2016-09-21 16:05:03 +020062$ZSTD tmp -of tmpCompressed && die "-o must be followed by filename "
Yann Collet27b5ac62016-09-21 14:20:56 +020063$ECHO "test : force write, correct order"
64$ZSTD tmp -fo tmpCompressed
Yann Collet714464f2016-09-21 16:05:03 +020065$ECHO "test : forgotten argument"
66cp tmp tmp2
67$ZSTD tmp2 -fo && die "-o must be followed by filename "
Yann Colletc8431422016-09-01 15:05:57 -070068$ECHO "test : implied stdout when input is stdin"
69$ECHO bob | $ZSTD | $ZSTD -d
inikep5d589562016-05-25 10:50:28 +020070$ECHO "test : null-length file roundtrip"
71$ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
72$ECHO "test : decompress file with wrong suffix (must fail)"
Yann Collet2d08b092016-02-16 14:42:08 +010073$ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
Yann Collet391a1282016-06-21 17:06:25 +020074$ZSTD -df tmp && die "should have refused : wrong extension"
75$ECHO "test : decompress into stdout"
Yann Collet0d348d42016-05-29 02:02:24 +020076$ZSTD -d tmpCompressed -c > tmpResult # decompression using stdout
Yann Collet2d08b092016-02-16 14:42:08 +010077$ZSTD --decompress tmpCompressed -c > tmpResult
78$ZSTD --decompress tmpCompressed --stdout > tmpResult
Yann Collet391a1282016-06-21 17:06:25 +020079$ECHO "test : decompress from stdin into stdout"
80$ZSTD -dc < tmp.zst > $INTOVOID # combine decompression, stdin & stdout
81$ZSTD -dc - < tmp.zst > $INTOVOID
82$ZSTD -d < tmp.zst > $INTOVOID # implicit stdout when stdin is used
83$ZSTD -d - < tmp.zst > $INTOVOID
Yann Colletd4cda272016-10-14 13:13:13 -070084$ECHO "test : impose memory limitation (must fail)"
85$ZSTD -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
Yann Collet11223492016-10-14 14:07:11 -070086$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 -070087$ZSTD -d -f tmp.zst --memory=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
88$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 +020089$ECHO "test : overwrite protection"
Yann Collet2d08b092016-02-16 14:42:08 +010090$ZSTD -q tmp && die "overwrite check failed!"
Yann Collet391a1282016-06-21 17:06:25 +020091$ECHO "test : force overwrite"
Yann Collet2d08b092016-02-16 14:42:08 +010092$ZSTD -q -f tmp
93$ZSTD -q --force tmp
Yann Colletb09b12c2016-06-09 22:59:51 +020094$ECHO "test : file removal"
95$ZSTD -f --rm tmp
96ls tmp && die "tmp should no longer be present"
97$ZSTD -f -d --rm tmp.zst
98ls tmp.zst && die "tmp.zst should no longer be present"
99rm tmp
100$ZSTD -f tmp && die "tmp not present : should have failed"
101ls tmp.zst && die "tmp.zst should not be created"
Yann Colletde95f962016-05-23 19:46:47 +0200102
103
inikep5d589562016-05-25 10:50:28 +0200104$ECHO "\n**** Pass-Through mode **** "
105$ECHO "Hello world !" | $ZSTD -df
106$ECHO "Hello world !" | $ZSTD -dcf
Yann Colletde95f962016-05-23 19:46:47 +0200107
Yann Collet8154c3d2016-02-13 03:12:10 +0100108
inikep5d589562016-05-25 10:50:28 +0200109$ECHO "\n**** frame concatenation **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300110
inikep5d589562016-05-25 10:50:28 +0200111$ECHO "hello " > hello.tmp
112$ECHO "world!" > world.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300113cat hello.tmp world.tmp > helloworld.tmp
Yann Colletc8da2c92016-02-12 02:56:27 +0100114$ZSTD -c hello.tmp > hello.zstd
115$ZSTD -c world.tmp > world.zstd
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300116cat hello.zstd world.zstd > helloworld.zstd
Yann Colletc8da2c92016-02-12 02:56:27 +0100117$ZSTD -dc helloworld.zstd > result.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300118cat result.tmp
119sdiff helloworld.tmp result.tmp
Yann Collet4c5bbf62016-07-28 20:30:25 +0200120$ECHO "frame concatenation without checksum"
121$ZSTD -c hello.tmp > hello.zstd --no-check
122$ZSTD -c world.tmp > world.zstd --no-check
123cat hello.zstd world.zstd > helloworld.zstd
124$ZSTD -dc helloworld.zstd > result.tmp
125cat result.tmp
126sdiff helloworld.tmp result.tmp
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300127rm ./*.tmp ./*.zstd
inikep5d589562016-05-25 10:50:28 +0200128$ECHO "frame concatenation tests completed"
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300129
Yann Colletf0624362016-02-12 15:56:46 +0100130
inikep5d589562016-05-25 10:50:28 +0200131if [ "$isWindows" = false ] ; then
132$ECHO "\n**** flush write error test **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300133
inikep5d589562016-05-25 10:50:28 +0200134$ECHO "$ECHO foo | $ZSTD > /dev/full"
135$ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
136$ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
137$ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
138fi
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300139
Yann Collet6a458352015-12-18 02:51:14 +0100140
inikep5d589562016-05-25 10:50:28 +0200141$ECHO "\n**** test sparse file support **** "
Yann Collet32990b52016-05-23 17:48:57 +0200142
143./datagen -g5M -P100 > tmpSparse
144$ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
145diff -s tmpSparse tmpSparseRegen
146$ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
147diff -s tmpSparse tmpOutSparse
148$ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
149diff -s tmpSparse tmpOutNoSparse
150ls -ls tmpSparse*
151./datagen -s1 -g1200007 -P100 | $ZSTD | $ZSTD -dv --sparse -c > tmpSparseOdd # Odd size file (to not finish on an exact nb of blocks)
152./datagen -s1 -g1200007 -P100 | diff -s - tmpSparseOdd
153ls -ls tmpSparseOdd
inikep5d589562016-05-25 10:50:28 +0200154$ECHO "\n Sparse Compatibility with Console :"
155$ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
156$ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
157$ECHO "\n Sparse Compatibility with Append :"
Yann Collet32990b52016-05-23 17:48:57 +0200158./datagen -P100 -g1M > tmpSparse1M
159cat tmpSparse1M tmpSparse1M > tmpSparse2M
160$ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
161$ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
162$ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
163ls -ls tmpSparse*
164diff tmpSparse2M tmpSparseRegenerated
Yann Collet33341de2016-05-29 23:09:51 +0200165rm tmpSparse*
Yann Collet32990b52016-05-23 17:48:57 +0200166
167
Yann Collet9b998e42016-06-15 23:11:20 +0200168$ECHO "\n**** multiple files tests **** "
169
Yann Collet391a1282016-06-21 17:06:25 +0200170./datagen -s1 > tmp1 2> $INTOVOID
171./datagen -s2 -g100K > tmp2 2> $INTOVOID
172./datagen -s3 -g1M > tmp3 2> $INTOVOID
Yann Collet9b998e42016-06-15 23:11:20 +0200173$ECHO "compress tmp* : "
Yann Collet60ba31c2016-07-28 19:55:09 +0200174$ZSTD -f tmp*
Yann Collet9b998e42016-06-15 23:11:20 +0200175ls -ls tmp*
176rm tmp1 tmp2 tmp3
177$ECHO "decompress tmp* : "
178$ZSTD -df *.zst
179ls -ls tmp*
180$ECHO "compress tmp* into stdout > tmpall : "
181$ZSTD -c tmp1 tmp2 tmp3 > tmpall
182ls -ls tmp*
183$ECHO "decompress tmpall* into stdout > tmpdec : "
184cp tmpall tmpall2
185$ZSTD -dc tmpall* > tmpdec
186ls -ls tmp*
187$ECHO "compress multiple files including a missing one (notHere) : "
188$ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
189
190
inikep5d589562016-05-25 10:50:28 +0200191$ECHO "\n**** dictionary tests **** "
Yann Colletf6f3d752015-12-13 13:35:21 +0100192
inikepb7d34492016-08-18 15:13:41 +0200193TESTFILE=../programs/zstdcli.c
Yann Colletf6f3d752015-12-13 13:35:21 +0100194./datagen > tmpDict
inikep93fc13e2016-05-30 10:17:55 +0200195./datagen -g1M | $MD5SUM > tmp1
196./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
Yann Colletf6f3d752015-12-13 13:35:21 +0100197diff -q tmp1 tmp2
Yann Collet531a4272016-06-15 19:02:11 +0200198$ECHO "- Create first dictionary"
inikepb7d34492016-08-18 15:13:41 +0200199$ZSTD --train *.c ../programs/*.c -o tmpDict
200cp $TESTFILE tmp
Yann Collet6381e992016-05-31 02:29:45 +0200201$ZSTD -f tmp -D tmpDict
Yann Collet27b5ac62016-09-21 14:20:56 +0200202$ZSTD -d tmp.zst -D tmpDict -fo result
inikepb7d34492016-08-18 15:13:41 +0200203diff $TESTFILE result
Yann Collet531a4272016-06-15 19:02:11 +0200204$ECHO "- Create second (different) dictionary"
inikepb7d34492016-08-18 15:13:41 +0200205$ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
Yann Collet27b5ac62016-09-21 14:20:56 +0200206$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
Yann Collet531a4272016-06-15 19:02:11 +0200207$ECHO "- Create dictionary with short dictID"
inikepb7d34492016-08-18 15:13:41 +0200208$ZSTD --train *.c ../programs/*.c --dictID 1 -o tmpDict1
Yann Collet290aaa72016-05-30 21:18:52 +0200209cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
Yann Collet27b5ac62016-09-21 14:20:56 +0200210$ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
211$ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
212$ECHO "- Create dictionary with size limit"
213$ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict 4K -v
214$ECHO "- Create dictionary with wrong parameter order (must fail)"
215$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 +0200216$ECHO "- Compress without dictID"
Yann Collet6381e992016-05-31 02:29:45 +0200217$ZSTD -f tmp -D tmpDict1 --no-dictID
Yann Collet27b5ac62016-09-21 14:20:56 +0200218$ZSTD -d tmp.zst -D tmpDict -fo result
inikepb7d34492016-08-18 15:13:41 +0200219diff $TESTFILE result
Yann Collet27b5ac62016-09-21 14:20:56 +0200220$ECHO "- Compress with wrong argument order (must fail)"
221$ZSTD tmp -Df tmpDict1 -c > /dev/null && die "-D must be followed by dictionary name "
Yann Collet531a4272016-06-15 19:02:11 +0200222$ECHO "- Compress multiple files with dictionary"
Yann Collet531a4272016-06-15 19:02:11 +0200223rm -rf dirTestDict
224mkdir dirTestDict
225cp *.c dirTestDict
inikepb7d34492016-08-18 15:13:41 +0200226cp ../programs/*.c dirTestDict
227cp ../programs/*.h dirTestDict
Yann Collet94376ac2016-08-25 19:09:21 +0200228$MD5SUM dirTestDict/* > tmph1
229$ZSTD -f --rm dirTestDict/* -D tmpDictC
Yann Colletbb93d772016-08-25 22:22:50 +0200230$ZSTD -d --rm dirTestDict/*.zst -D tmpDictC # note : use internal checksum by default
Yann Collet94376ac2016-08-25 19:09:21 +0200231if [[ "$OSTYPE" == "darwin"* ]]; then
Yann Collet3ecbe6a2016-09-14 17:26:59 +0200232 $ECHO "md5sum -c not supported on OS-X : test skipped" # not compatible with OS-X's md5
Yann Collet94376ac2016-08-25 19:09:21 +0200233else
234 $MD5SUM -c tmph1
235fi
Yann Collet531a4272016-06-15 19:02:11 +0200236rm -rf dirTestDict
Yann Collet6381e992016-05-31 02:29:45 +0200237rm tmp*
Yann Colletb44be742016-03-26 20:52:14 +0100238
Yann Colletf6f3d752015-12-13 13:35:21 +0100239
inikep5d589562016-05-25 10:50:28 +0200240$ECHO "\n**** integrity tests **** "
Yann Colletde95f962016-05-23 19:46:47 +0200241
inikep5d589562016-05-25 10:50:28 +0200242$ECHO "test one file (tmp1.zst) "
Yann Collet1a7b8fb2016-06-15 23:33:38 +0200243./datagen > tmp1
244$ZSTD tmp1
Yann Collet459a6b72016-02-15 20:37:23 +0100245$ZSTD -t tmp1.zst
Yann Collet2d08b092016-02-16 14:42:08 +0100246$ZSTD --test tmp1.zst
inikep5d589562016-05-25 10:50:28 +0200247$ECHO "test multiple files (*.zst) "
Yann Collet459a6b72016-02-15 20:37:23 +0100248$ZSTD -t *.zst
Yann Collet24a3d902016-07-26 01:26:56 +0200249$ECHO "test bad files (*) "
Yann Collet459a6b72016-02-15 20:37:23 +0100250$ZSTD -t * && die "bad files not detected !"
Yann Collet24a3d902016-07-26 01:26:56 +0200251$ZSTD -t tmp1 && die "bad file not detected !"
252cp tmp1 tmp2.zst
253$ZSTD -t tmp2.zst && die "bad file not detected !"
Yann Collet7adc2322016-07-26 15:39:31 +0200254./datagen -g0 > tmp3
255$ZSTD -t tmp3 && die "bad file not detected !" # detects 0-sized files as bad
Yann Colletb4024902016-07-26 00:49:47 +0200256$ECHO "test --rm and --test combined "
257$ZSTD -t --rm tmp1.zst
258ls -ls tmp1.zst # check file is still present
Yann Colletdeb078b2015-12-17 20:30:14 +0100259
Yann Colletde95f962016-05-23 19:46:47 +0200260
Yann Colletb9550d62016-10-28 14:43:24 -0700261$ECHO "\n**** benchmark mode tests **** "
262
263$ECHO "bench one file"
264./datagen > tmp1
265$ZSTD -bi1 tmp1
266$ECHO "bench multiple levels"
267$ZSTD -i1b1e3 tmp1
268$ECHO "with recursive and quiet modes"
269$ZSTD -rqi1b1e3 tmp1
270
271
inikep5d589562016-05-25 10:50:28 +0200272$ECHO "\n**** zstd round-trip tests **** "
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300273
274roundTripTest
Yann Collet3b719252016-03-30 19:48:05 +0200275roundTripTest -g15K # TableID==3
276roundTripTest -g127K # TableID==2
277roundTripTest -g255K # TableID==1
278roundTripTest -g513K # TableID==0
Yann Collet459a6b72016-02-15 20:37:23 +0100279roundTripTest -g512K 6 # greedy, hash chain
Yann Collet0d348d42016-05-29 02:02:24 +0200280roundTripTest -g512K 16 # btlazy2
Yann Collet459a6b72016-02-15 20:37:23 +0100281roundTripTest -g512K 19 # btopt
282
283rm tmp*
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300284
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300285if [ "$1" != "--test-large-data" ]; then
inikep5d589562016-05-25 10:50:28 +0200286 $ECHO "Skipping large data tests"
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300287 exit 0
288fi
289
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300290roundTripTest -g270000000 1
291roundTripTest -g270000000 2
292roundTripTest -g270000000 3
293
294roundTripTest -g140000000 -P60 4
295roundTripTest -g140000000 -P60 5
296roundTripTest -g140000000 -P60 6
297
298roundTripTest -g70000000 -P70 7
299roundTripTest -g70000000 -P70 8
300roundTripTest -g70000000 -P70 9
301
302roundTripTest -g35000000 -P75 10
303roundTripTest -g35000000 -P75 11
304roundTripTest -g35000000 -P75 12
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300305
Konstantin Tokarev2b465842015-12-08 19:36:42 +0300306roundTripTest -g18000000 -P80 13
307roundTripTest -g18000000 -P80 14
308roundTripTest -g18000000 -P80 15
309roundTripTest -g18000000 -P80 16
310roundTripTest -g18000000 -P80 17
311
312roundTripTest -g50000000 -P94 18
313roundTripTest -g50000000 -P94 19
314
315roundTripTest -g99000000 -P99 20
Yann Colletecabfe32016-03-20 16:20:06 +0100316roundTripTest -g6000000000 -P99 1
Yann Collet459a6b72016-02-15 20:37:23 +0100317
318rm tmp*