blob: 5ff4c4e0739e3f4558cff56e4facb49ae9b5a81d [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"
inikep993a9df2016-05-27 10:07:46 +020025case "$OS" in
26 Windows*)
inikep5d589562016-05-25 10:50:28 +020027 isWindows=true
28 ECHO="echo -e"
inikep993a9df2016-05-27 10:07:46 +020029 ;;
30esac
inikep5d589562016-05-25 10:50:28 +020031
32$ECHO "\nStarting playTests.sh isWindows=$isWindows"
33
Konstantin Tokarev76be3782015-12-08 18:36:37 +030034[ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
35
inikep5d589562016-05-25 10:50:28 +020036$ECHO "\n**** simple tests **** "
Yann Colletde95f962016-05-23 19:46:47 +020037
Yann Collet8154c3d2016-02-13 03:12:10 +010038./datagen > tmp
Yann Collet7928f6f2016-04-10 20:40:26 +020039$ZSTD -f tmp # trivial compression case, creates tmp.zst
40$ZSTD -df tmp.zst # trivial decompression case (overwrites tmp)
inikep5d589562016-05-25 10:50:28 +020041$ECHO "test : too large compression level (must fail)"
Yann Collet9abc3582016-02-16 16:35:28 +010042$ZSTD -99 tmp && die "too large compression level undetected"
inikep5d589562016-05-25 10:50:28 +020043$ECHO "test : compress to stdout"
Yann Colletd6931172016-05-10 05:56:09 +020044$ZSTD tmp -c > tmpCompressed
45$ZSTD tmp --stdout > tmpCompressed # long command format
inikep5d589562016-05-25 10:50:28 +020046$ECHO "test : null-length file roundtrip"
47$ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
48$ECHO "test : decompress file with wrong suffix (must fail)"
Yann Collet2d08b092016-02-16 14:42:08 +010049$ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
Yann Collet7928f6f2016-04-10 20:40:26 +020050$ZSTD -d tmpCompressed -c > tmpResult # decompression using stdout
Yann Collet2d08b092016-02-16 14:42:08 +010051$ZSTD --decompress tmpCompressed -c > tmpResult
52$ZSTD --decompress tmpCompressed --stdout > tmpResult
inikep5d589562016-05-25 10:50:28 +020053if [ "$isWindows" = false ] ; then
54 $ZSTD -d < tmp.zst > /dev/null # combine decompression, stdin & stdout
55 $ZSTD -d - < tmp.zst > /dev/null
56fi
Yann Collet7928f6f2016-04-10 20:40:26 +020057$ZSTD -dc < tmp.zst > /dev/null
58$ZSTD -dc - < tmp.zst > /dev/null
Yann Collet2d08b092016-02-16 14:42:08 +010059$ZSTD -q tmp && die "overwrite check failed!"
60$ZSTD -q -f tmp
61$ZSTD -q --force tmp
Yann Collet97406c92016-03-14 17:05:40 +010062$ZSTD -df tmp && die "should have refused : wrong extension"
Yann Colletde95f962016-05-23 19:46:47 +020063
64
inikep5d589562016-05-25 10:50:28 +020065$ECHO "\n**** Pass-Through mode **** "
66$ECHO "Hello world !" | $ZSTD -df
67$ECHO "Hello world !" | $ZSTD -dcf
Yann Colletde95f962016-05-23 19:46:47 +020068
Yann Collet8154c3d2016-02-13 03:12:10 +010069
inikep5d589562016-05-25 10:50:28 +020070$ECHO "\n**** frame concatenation **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030071
inikep5d589562016-05-25 10:50:28 +020072$ECHO "hello " > hello.tmp
73$ECHO "world!" > world.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030074cat hello.tmp world.tmp > helloworld.tmp
Yann Colletc8da2c92016-02-12 02:56:27 +010075$ZSTD -c hello.tmp > hello.zstd
76$ZSTD -c world.tmp > world.zstd
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030077cat hello.zstd world.zstd > helloworld.zstd
Yann Colletc8da2c92016-02-12 02:56:27 +010078$ZSTD -dc helloworld.zstd > result.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030079cat result.tmp
80sdiff helloworld.tmp result.tmp
Konstantin Tokarev76be3782015-12-08 18:36:37 +030081rm ./*.tmp ./*.zstd
inikep5d589562016-05-25 10:50:28 +020082$ECHO "frame concatenation tests completed"
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030083
Yann Colletf0624362016-02-12 15:56:46 +010084
inikep5d589562016-05-25 10:50:28 +020085if [ "$isWindows" = false ] ; then
86$ECHO "\n**** flush write error test **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030087
inikep5d589562016-05-25 10:50:28 +020088$ECHO "$ECHO foo | $ZSTD > /dev/full"
89$ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
90$ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
91$ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
92fi
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030093
Yann Collet6a458352015-12-18 02:51:14 +010094
inikep5d589562016-05-25 10:50:28 +020095$ECHO "\n**** test sparse file support **** "
Yann Collet32990b52016-05-23 17:48:57 +020096
97./datagen -g5M -P100 > tmpSparse
98$ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
99diff -s tmpSparse tmpSparseRegen
100$ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
101diff -s tmpSparse tmpOutSparse
102$ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
103diff -s tmpSparse tmpOutNoSparse
104ls -ls tmpSparse*
105./datagen -s1 -g1200007 -P100 | $ZSTD | $ZSTD -dv --sparse -c > tmpSparseOdd # Odd size file (to not finish on an exact nb of blocks)
106./datagen -s1 -g1200007 -P100 | diff -s - tmpSparseOdd
107ls -ls tmpSparseOdd
inikep5d589562016-05-25 10:50:28 +0200108$ECHO "\n Sparse Compatibility with Console :"
109$ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
110$ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
111$ECHO "\n Sparse Compatibility with Append :"
Yann Collet32990b52016-05-23 17:48:57 +0200112./datagen -P100 -g1M > tmpSparse1M
113cat tmpSparse1M tmpSparse1M > tmpSparse2M
114$ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
115$ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
116$ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
117ls -ls tmpSparse*
118diff tmpSparse2M tmpSparseRegenerated
119# rm tmpSparse*
120
121
inikep5d589562016-05-25 10:50:28 +0200122$ECHO "\n**** dictionary tests **** "
Yann Colletf6f3d752015-12-13 13:35:21 +0100123
124./datagen > tmpDict
125./datagen -g1M | md5sum > tmp1
Yann Colletf0624362016-02-12 15:56:46 +0100126./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | md5sum > tmp2
Yann Colletf6f3d752015-12-13 13:35:21 +0100127diff -q tmp1 tmp2
Yann Colletb44be742016-03-26 20:52:14 +0100128$ZSTD --train *.c *.h -o tmpDict
129$ZSTD xxhash.c -D tmpDict -of tmp
130$ZSTD -d tmp -D tmpDict -of result
131diff xxhash.c result
132
Yann Colletf6f3d752015-12-13 13:35:21 +0100133
inikep5d589562016-05-25 10:50:28 +0200134$ECHO "\n**** multiple files tests **** "
Yann Colletdeb078b2015-12-17 20:30:14 +0100135
136./datagen -s1 > tmp1 2> /dev/null
137./datagen -s2 -g100K > tmp2 2> /dev/null
138./datagen -s3 -g1M > tmp3 2> /dev/null
Yann Colletc8da2c92016-02-12 02:56:27 +0100139$ZSTD -f tmp*
inikep5d589562016-05-25 10:50:28 +0200140$ECHO "compress tmp* : "
Yann Colletdeb078b2015-12-17 20:30:14 +0100141ls -ls tmp*
142rm tmp1 tmp2 tmp3
inikep5d589562016-05-25 10:50:28 +0200143$ECHO "decompress tmp* : "
Yann Colletc8da2c92016-02-12 02:56:27 +0100144$ZSTD -df *.zst
Yann Colletdeb078b2015-12-17 20:30:14 +0100145ls -ls tmp*
inikep5d589562016-05-25 10:50:28 +0200146$ECHO "compress tmp* into stdout > tmpall : "
Yann Colletf0624362016-02-12 15:56:46 +0100147$ZSTD -c tmp1 tmp2 tmp3 > tmpall
148ls -ls tmp*
inikep5d589562016-05-25 10:50:28 +0200149$ECHO "decompress tmpall* into stdout > tmpdec : "
Yann Collet1f1f2392016-02-12 18:33:26 +0100150cp tmpall tmpall2
151$ZSTD -dc tmpall* > tmpdec
152ls -ls tmp*
inikep5d589562016-05-25 10:50:28 +0200153$ECHO "compress multiple files including a missing one (notHere) : "
Yann Colletc8da2c92016-02-12 02:56:27 +0100154$ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
Yann Collet459a6b72016-02-15 20:37:23 +0100155
Yann Colletde95f962016-05-23 19:46:47 +0200156
inikep5d589562016-05-25 10:50:28 +0200157$ECHO "\n**** integrity tests **** "
Yann Colletde95f962016-05-23 19:46:47 +0200158
inikep5d589562016-05-25 10:50:28 +0200159$ECHO "test one file (tmp1.zst) "
Yann Collet459a6b72016-02-15 20:37:23 +0100160$ZSTD -t tmp1.zst
Yann Collet2d08b092016-02-16 14:42:08 +0100161$ZSTD --test tmp1.zst
inikep5d589562016-05-25 10:50:28 +0200162$ECHO "test multiple files (*.zst) "
Yann Collet459a6b72016-02-15 20:37:23 +0100163$ZSTD -t *.zst
inikep5d589562016-05-25 10:50:28 +0200164$ECHO "test good and bad files (*) "
Yann Collet459a6b72016-02-15 20:37:23 +0100165$ZSTD -t * && die "bad files not detected !"
Yann Colletdeb078b2015-12-17 20:30:14 +0100166
Yann Colletde95f962016-05-23 19:46:47 +0200167
inikep5d589562016-05-25 10:50:28 +0200168$ECHO "\n**** zstd round-trip tests **** "
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300169
170roundTripTest
Yann Collet3b719252016-03-30 19:48:05 +0200171roundTripTest -g15K # TableID==3
172roundTripTest -g127K # TableID==2
173roundTripTest -g255K # TableID==1
174roundTripTest -g513K # TableID==0
Yann Collet459a6b72016-02-15 20:37:23 +0100175roundTripTest -g512K 6 # greedy, hash chain
176roundTripTest -g512K 16 # btlazy2
177roundTripTest -g512K 19 # btopt
178
179rm tmp*
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300180
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300181if [ "$1" != "--test-large-data" ]; then
inikep5d589562016-05-25 10:50:28 +0200182 $ECHO "Skipping large data tests"
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300183 exit 0
184fi
185
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300186roundTripTest -g270000000 1
187roundTripTest -g270000000 2
188roundTripTest -g270000000 3
189
190roundTripTest -g140000000 -P60 4
191roundTripTest -g140000000 -P60 5
192roundTripTest -g140000000 -P60 6
193
194roundTripTest -g70000000 -P70 7
195roundTripTest -g70000000 -P70 8
196roundTripTest -g70000000 -P70 9
197
198roundTripTest -g35000000 -P75 10
199roundTripTest -g35000000 -P75 11
200roundTripTest -g35000000 -P75 12
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300201
Konstantin Tokarev2b465842015-12-08 19:36:42 +0300202roundTripTest -g18000000 -P80 13
203roundTripTest -g18000000 -P80 14
204roundTripTest -g18000000 -P80 15
205roundTripTest -g18000000 -P80 16
206roundTripTest -g18000000 -P80 17
207
208roundTripTest -g50000000 -P94 18
209roundTripTest -g50000000 -P94 19
210
211roundTripTest -g99000000 -P99 20
Yann Colletecabfe32016-03-20 16:20:06 +0100212roundTripTest -g6000000000 -P99 1
Yann Collet459a6b72016-02-15 20:37:23 +0100213
214rm tmp*
215