blob: 479ffecae62691a10291b19eb1f1407f19b666ad [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"
Konstantin Tokarev76be3782015-12-08 18:36:37 +030018 ./datagen $1 $p | md5sum > tmp1
Yann Colletef370632016-02-07 03:53:12 +010019 ./datagen $1 $p | $ZSTD -vq$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"
25if [[ "$OS" == "Windows"* ]]; then
26 isWindows=true
27 ECHO="echo -e"
28fi
29
30$ECHO "\nStarting playTests.sh isWindows=$isWindows"
31
Konstantin Tokarev76be3782015-12-08 18:36:37 +030032[ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
33
inikep5d589562016-05-25 10:50:28 +020034$ECHO "\n**** simple tests **** "
Yann Colletde95f962016-05-23 19:46:47 +020035
Yann Collet8154c3d2016-02-13 03:12:10 +010036./datagen > tmp
Yann Collet7928f6f2016-04-10 20:40:26 +020037$ZSTD -f tmp # trivial compression case, creates tmp.zst
38$ZSTD -df tmp.zst # trivial decompression case (overwrites tmp)
inikep5d589562016-05-25 10:50:28 +020039$ECHO "test : too large compression level (must fail)"
Yann Collet9abc3582016-02-16 16:35:28 +010040$ZSTD -99 tmp && die "too large compression level undetected"
inikep5d589562016-05-25 10:50:28 +020041$ECHO "test : compress to stdout"
Yann Collet0d348d42016-05-29 02:02:24 +020042$ZSTD tmp -c > tmpCompressed
Yann Colletd6931172016-05-10 05:56:09 +020043$ZSTD tmp --stdout > tmpCompressed # long command format
inikep5d589562016-05-25 10:50:28 +020044$ECHO "test : null-length file roundtrip"
45$ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
46$ECHO "test : decompress file with wrong suffix (must fail)"
Yann Collet2d08b092016-02-16 14:42:08 +010047$ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
Yann Collet0d348d42016-05-29 02:02:24 +020048$ZSTD -d tmpCompressed -c > tmpResult # decompression using stdout
Yann Collet2d08b092016-02-16 14:42:08 +010049$ZSTD --decompress tmpCompressed -c > tmpResult
50$ZSTD --decompress tmpCompressed --stdout > tmpResult
inikep5d589562016-05-25 10:50:28 +020051if [ "$isWindows" = false ] ; then
52 $ZSTD -d < tmp.zst > /dev/null # combine decompression, stdin & stdout
53 $ZSTD -d - < tmp.zst > /dev/null
54fi
Yann Collet7928f6f2016-04-10 20:40:26 +020055$ZSTD -dc < tmp.zst > /dev/null
56$ZSTD -dc - < tmp.zst > /dev/null
Yann Collet2d08b092016-02-16 14:42:08 +010057$ZSTD -q tmp && die "overwrite check failed!"
58$ZSTD -q -f tmp
59$ZSTD -q --force tmp
Yann Collet97406c92016-03-14 17:05:40 +010060$ZSTD -df tmp && die "should have refused : wrong extension"
Yann Colletde95f962016-05-23 19:46:47 +020061
62
inikep5d589562016-05-25 10:50:28 +020063$ECHO "\n**** Pass-Through mode **** "
64$ECHO "Hello world !" | $ZSTD -df
65$ECHO "Hello world !" | $ZSTD -dcf
Yann Colletde95f962016-05-23 19:46:47 +020066
Yann Collet8154c3d2016-02-13 03:12:10 +010067
inikep5d589562016-05-25 10:50:28 +020068$ECHO "\n**** frame concatenation **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030069
inikep5d589562016-05-25 10:50:28 +020070$ECHO "hello " > hello.tmp
71$ECHO "world!" > world.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030072cat hello.tmp world.tmp > helloworld.tmp
Yann Colletc8da2c92016-02-12 02:56:27 +010073$ZSTD -c hello.tmp > hello.zstd
74$ZSTD -c world.tmp > world.zstd
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030075cat hello.zstd world.zstd > helloworld.zstd
Yann Colletc8da2c92016-02-12 02:56:27 +010076$ZSTD -dc helloworld.zstd > result.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030077cat result.tmp
78sdiff helloworld.tmp result.tmp
Konstantin Tokarev76be3782015-12-08 18:36:37 +030079rm ./*.tmp ./*.zstd
inikep5d589562016-05-25 10:50:28 +020080$ECHO "frame concatenation tests completed"
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030081
Yann Colletf0624362016-02-12 15:56:46 +010082
inikep5d589562016-05-25 10:50:28 +020083if [ "$isWindows" = false ] ; then
84$ECHO "\n**** flush write error test **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030085
inikep5d589562016-05-25 10:50:28 +020086$ECHO "$ECHO foo | $ZSTD > /dev/full"
87$ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
88$ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
89$ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
90fi
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030091
Yann Collet6a458352015-12-18 02:51:14 +010092
inikep5d589562016-05-25 10:50:28 +020093$ECHO "\n**** test sparse file support **** "
Yann Collet32990b52016-05-23 17:48:57 +020094
95./datagen -g5M -P100 > tmpSparse
96$ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
97diff -s tmpSparse tmpSparseRegen
98$ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
99diff -s tmpSparse tmpOutSparse
100$ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
101diff -s tmpSparse tmpOutNoSparse
102ls -ls tmpSparse*
103./datagen -s1 -g1200007 -P100 | $ZSTD | $ZSTD -dv --sparse -c > tmpSparseOdd # Odd size file (to not finish on an exact nb of blocks)
104./datagen -s1 -g1200007 -P100 | diff -s - tmpSparseOdd
105ls -ls tmpSparseOdd
inikep5d589562016-05-25 10:50:28 +0200106$ECHO "\n Sparse Compatibility with Console :"
107$ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
108$ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
109$ECHO "\n Sparse Compatibility with Append :"
Yann Collet32990b52016-05-23 17:48:57 +0200110./datagen -P100 -g1M > tmpSparse1M
111cat tmpSparse1M tmpSparse1M > tmpSparse2M
112$ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
113$ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
114$ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
115ls -ls tmpSparse*
116diff tmpSparse2M tmpSparseRegenerated
117# rm tmpSparse*
118
119
inikep5d589562016-05-25 10:50:28 +0200120$ECHO "\n**** dictionary tests **** "
Yann Colletf6f3d752015-12-13 13:35:21 +0100121
122./datagen > tmpDict
123./datagen -g1M | md5sum > tmp1
Yann Colletf0624362016-02-12 15:56:46 +0100124./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | md5sum > tmp2
Yann Colletf6f3d752015-12-13 13:35:21 +0100125diff -q tmp1 tmp2
Yann Colletb44be742016-03-26 20:52:14 +0100126$ZSTD --train *.c *.h -o tmpDict
Yann Collet0d348d42016-05-29 02:02:24 +0200127$ZSTD zstd_compress.c -D tmpDict -of tmp
Yann Colletb44be742016-03-26 20:52:14 +0100128$ZSTD -d tmp -D tmpDict -of result
Yann Collet0d348d42016-05-29 02:02:24 +0200129diff zstd_compress.c result
Yann Colletb44be742016-03-26 20:52:14 +0100130
Yann Colletf6f3d752015-12-13 13:35:21 +0100131
inikep5d589562016-05-25 10:50:28 +0200132$ECHO "\n**** multiple files tests **** "
Yann Colletdeb078b2015-12-17 20:30:14 +0100133
134./datagen -s1 > tmp1 2> /dev/null
135./datagen -s2 -g100K > tmp2 2> /dev/null
136./datagen -s3 -g1M > tmp3 2> /dev/null
Yann Colletc8da2c92016-02-12 02:56:27 +0100137$ZSTD -f tmp*
inikep5d589562016-05-25 10:50:28 +0200138$ECHO "compress tmp* : "
Yann Colletdeb078b2015-12-17 20:30:14 +0100139ls -ls tmp*
140rm tmp1 tmp2 tmp3
inikep5d589562016-05-25 10:50:28 +0200141$ECHO "decompress tmp* : "
Yann Colletc8da2c92016-02-12 02:56:27 +0100142$ZSTD -df *.zst
Yann Colletdeb078b2015-12-17 20:30:14 +0100143ls -ls tmp*
inikep5d589562016-05-25 10:50:28 +0200144$ECHO "compress tmp* into stdout > tmpall : "
Yann Colletf0624362016-02-12 15:56:46 +0100145$ZSTD -c tmp1 tmp2 tmp3 > tmpall
146ls -ls tmp*
inikep5d589562016-05-25 10:50:28 +0200147$ECHO "decompress tmpall* into stdout > tmpdec : "
Yann Collet1f1f2392016-02-12 18:33:26 +0100148cp tmpall tmpall2
149$ZSTD -dc tmpall* > tmpdec
150ls -ls tmp*
inikep5d589562016-05-25 10:50:28 +0200151$ECHO "compress multiple files including a missing one (notHere) : "
Yann Colletc8da2c92016-02-12 02:56:27 +0100152$ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
Yann Collet459a6b72016-02-15 20:37:23 +0100153
Yann Colletde95f962016-05-23 19:46:47 +0200154
inikep5d589562016-05-25 10:50:28 +0200155$ECHO "\n**** integrity tests **** "
Yann Colletde95f962016-05-23 19:46:47 +0200156
inikep5d589562016-05-25 10:50:28 +0200157$ECHO "test one file (tmp1.zst) "
Yann Collet459a6b72016-02-15 20:37:23 +0100158$ZSTD -t tmp1.zst
Yann Collet2d08b092016-02-16 14:42:08 +0100159$ZSTD --test tmp1.zst
inikep5d589562016-05-25 10:50:28 +0200160$ECHO "test multiple files (*.zst) "
Yann Collet459a6b72016-02-15 20:37:23 +0100161$ZSTD -t *.zst
inikep5d589562016-05-25 10:50:28 +0200162$ECHO "test good and bad files (*) "
Yann Collet459a6b72016-02-15 20:37:23 +0100163$ZSTD -t * && die "bad files not detected !"
Yann Colletdeb078b2015-12-17 20:30:14 +0100164
Yann Colletde95f962016-05-23 19:46:47 +0200165
inikep5d589562016-05-25 10:50:28 +0200166$ECHO "\n**** zstd round-trip tests **** "
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300167
168roundTripTest
Yann Collet3b719252016-03-30 19:48:05 +0200169roundTripTest -g15K # TableID==3
170roundTripTest -g127K # TableID==2
171roundTripTest -g255K # TableID==1
172roundTripTest -g513K # TableID==0
Yann Collet459a6b72016-02-15 20:37:23 +0100173roundTripTest -g512K 6 # greedy, hash chain
Yann Collet0d348d42016-05-29 02:02:24 +0200174roundTripTest -g512K 16 # btlazy2
Yann Collet459a6b72016-02-15 20:37:23 +0100175roundTripTest -g512K 19 # btopt
176
177rm tmp*
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300178
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300179if [ "$1" != "--test-large-data" ]; then
inikep5d589562016-05-25 10:50:28 +0200180 $ECHO "Skipping large data tests"
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300181 exit 0
182fi
183
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300184roundTripTest -g270000000 1
185roundTripTest -g270000000 2
186roundTripTest -g270000000 3
187
188roundTripTest -g140000000 -P60 4
189roundTripTest -g140000000 -P60 5
190roundTripTest -g140000000 -P60 6
191
192roundTripTest -g70000000 -P70 7
193roundTripTest -g70000000 -P70 8
194roundTripTest -g70000000 -P70 9
195
196roundTripTest -g35000000 -P75 10
197roundTripTest -g35000000 -P75 11
198roundTripTest -g35000000 -P75 12
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300199
Konstantin Tokarev2b465842015-12-08 19:36:42 +0300200roundTripTest -g18000000 -P80 13
201roundTripTest -g18000000 -P80 14
202roundTripTest -g18000000 -P80 15
203roundTripTest -g18000000 -P80 16
204roundTripTest -g18000000 -P80 17
205
206roundTripTest -g50000000 -P94 18
207roundTripTest -g50000000 -P94 19
208
209roundTripTest -g99000000 -P99 20
Yann Colletecabfe32016-03-20 16:20:06 +0100210roundTripTest -g6000000000 -P99 1
Yann Collet459a6b72016-02-15 20:37:23 +0100211
212rm tmp*