blob: 60d413c99a1ac2b9fa5e8ce69217a21a53e489f2 [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
19 ./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
Yann Collet673f0d72016-06-06 00:26:38 +020026 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
inikep93fc13e2016-05-30 10:17:55 +020032MD5SUM="md5sum"
inikep1dcb2ff2016-05-30 11:33:52 +020033if [ "$TRAVIS_OS_NAME" = "osx" ]; then
inikep93fc13e2016-05-30 10:17:55 +020034 MD5SUM="md5 -r"
inikep5d589562016-05-25 10:50:28 +020035fi
36
inikep1dcb2ff2016-05-30 11:33:52 +020037$ECHO "\nStarting playTests.sh isWindows=$isWindows TRAVIS_OS_NAME=$TRAVIS_OS_NAME"
inikep5d589562016-05-25 10:50:28 +020038
Konstantin Tokarev76be3782015-12-08 18:36:37 +030039[ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
40
inikep1dcb2ff2016-05-30 11:33:52 +020041file $ZSTD
inikep5d589562016-05-25 10:50:28 +020042$ECHO "\n**** simple tests **** "
Yann Colletde95f962016-05-23 19:46:47 +020043
Yann Collet8154c3d2016-02-13 03:12:10 +010044./datagen > tmp
Yann Collet673f0d72016-06-06 00:26:38 +020045$ZSTD -f tmp # trivial compression case, creates tmp.zst
46$ZSTD -df tmp.zst # trivial decompression case (overwrites tmp)
inikep5d589562016-05-25 10:50:28 +020047$ECHO "test : too large compression level (must fail)"
Yann Collet9abc3582016-02-16 16:35:28 +010048$ZSTD -99 tmp && die "too large compression level undetected"
inikep5d589562016-05-25 10:50:28 +020049$ECHO "test : compress to stdout"
Yann Collet0d348d42016-05-29 02:02:24 +020050$ZSTD tmp -c > tmpCompressed
Yann Colletd6931172016-05-10 05:56:09 +020051$ZSTD tmp --stdout > tmpCompressed # long command format
inikep5d589562016-05-25 10:50:28 +020052$ECHO "test : null-length file roundtrip"
53$ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
54$ECHO "test : decompress file with wrong suffix (must fail)"
Yann Collet2d08b092016-02-16 14:42:08 +010055$ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
Yann Collet0d348d42016-05-29 02:02:24 +020056$ZSTD -d tmpCompressed -c > tmpResult # decompression using stdout
Yann Collet2d08b092016-02-16 14:42:08 +010057$ZSTD --decompress tmpCompressed -c > tmpResult
58$ZSTD --decompress tmpCompressed --stdout > tmpResult
inikep5d589562016-05-25 10:50:28 +020059if [ "$isWindows" = false ] ; then
Yann Collet673f0d72016-06-06 00:26:38 +020060 $ZSTD -d < tmp.zst > /dev/null # combine decompression, stdin & stdout
inikep5d589562016-05-25 10:50:28 +020061 $ZSTD -d - < tmp.zst > /dev/null
62fi
Yann Collet7928f6f2016-04-10 20:40:26 +020063$ZSTD -dc < tmp.zst > /dev/null
64$ZSTD -dc - < tmp.zst > /dev/null
Yann Collet2d08b092016-02-16 14:42:08 +010065$ZSTD -q tmp && die "overwrite check failed!"
66$ZSTD -q -f tmp
67$ZSTD -q --force tmp
Yann Collet97406c92016-03-14 17:05:40 +010068$ZSTD -df tmp && die "should have refused : wrong extension"
Yann Colletb09b12c2016-06-09 22:59:51 +020069$ECHO "test : file removal"
70$ZSTD -f --rm tmp
71ls tmp && die "tmp should no longer be present"
72$ZSTD -f -d --rm tmp.zst
73ls tmp.zst && die "tmp.zst should no longer be present"
74rm tmp
75$ZSTD -f tmp && die "tmp not present : should have failed"
76ls tmp.zst && die "tmp.zst should not be created"
Yann Colletde95f962016-05-23 19:46:47 +020077
78
inikep5d589562016-05-25 10:50:28 +020079$ECHO "\n**** Pass-Through mode **** "
80$ECHO "Hello world !" | $ZSTD -df
81$ECHO "Hello world !" | $ZSTD -dcf
Yann Colletde95f962016-05-23 19:46:47 +020082
Yann Collet8154c3d2016-02-13 03:12:10 +010083
inikep5d589562016-05-25 10:50:28 +020084$ECHO "\n**** frame concatenation **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030085
inikep5d589562016-05-25 10:50:28 +020086$ECHO "hello " > hello.tmp
87$ECHO "world!" > world.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030088cat hello.tmp world.tmp > helloworld.tmp
Yann Colletc8da2c92016-02-12 02:56:27 +010089$ZSTD -c hello.tmp > hello.zstd
90$ZSTD -c world.tmp > world.zstd
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030091cat hello.zstd world.zstd > helloworld.zstd
Yann Colletc8da2c92016-02-12 02:56:27 +010092$ZSTD -dc helloworld.zstd > result.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030093cat result.tmp
94sdiff helloworld.tmp result.tmp
Konstantin Tokarev76be3782015-12-08 18:36:37 +030095rm ./*.tmp ./*.zstd
inikep5d589562016-05-25 10:50:28 +020096$ECHO "frame concatenation tests completed"
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +030097
Yann Colletf0624362016-02-12 15:56:46 +010098
inikep5d589562016-05-25 10:50:28 +020099if [ "$isWindows" = false ] ; then
100$ECHO "\n**** flush write error test **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300101
inikep5d589562016-05-25 10:50:28 +0200102$ECHO "$ECHO foo | $ZSTD > /dev/full"
103$ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
104$ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
105$ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
106fi
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300107
Yann Collet6a458352015-12-18 02:51:14 +0100108
inikep5d589562016-05-25 10:50:28 +0200109$ECHO "\n**** test sparse file support **** "
Yann Collet32990b52016-05-23 17:48:57 +0200110
111./datagen -g5M -P100 > tmpSparse
112$ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
113diff -s tmpSparse tmpSparseRegen
114$ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
115diff -s tmpSparse tmpOutSparse
116$ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
117diff -s tmpSparse tmpOutNoSparse
118ls -ls tmpSparse*
119./datagen -s1 -g1200007 -P100 | $ZSTD | $ZSTD -dv --sparse -c > tmpSparseOdd # Odd size file (to not finish on an exact nb of blocks)
120./datagen -s1 -g1200007 -P100 | diff -s - tmpSparseOdd
121ls -ls tmpSparseOdd
inikep5d589562016-05-25 10:50:28 +0200122$ECHO "\n Sparse Compatibility with Console :"
123$ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
124$ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
125$ECHO "\n Sparse Compatibility with Append :"
Yann Collet32990b52016-05-23 17:48:57 +0200126./datagen -P100 -g1M > tmpSparse1M
127cat tmpSparse1M tmpSparse1M > tmpSparse2M
128$ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
129$ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
130$ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
131ls -ls tmpSparse*
132diff tmpSparse2M tmpSparseRegenerated
Yann Collet33341de2016-05-29 23:09:51 +0200133rm tmpSparse*
Yann Collet32990b52016-05-23 17:48:57 +0200134
135
Yann Collet9b998e42016-06-15 23:11:20 +0200136$ECHO "\n**** multiple files tests **** "
137
138./datagen -s1 > tmp1 2> /dev/null
139./datagen -s2 -g100K > tmp2 2> /dev/null
140./datagen -s3 -g1M > tmp3 2> /dev/null
141$ZSTD -f tmp*
142$ECHO "compress tmp* : "
143ls -ls tmp*
144rm tmp1 tmp2 tmp3
145$ECHO "decompress tmp* : "
146$ZSTD -df *.zst
147ls -ls tmp*
148$ECHO "compress tmp* into stdout > tmpall : "
149$ZSTD -c tmp1 tmp2 tmp3 > tmpall
150ls -ls tmp*
151$ECHO "decompress tmpall* into stdout > tmpdec : "
152cp tmpall tmpall2
153$ZSTD -dc tmpall* > tmpdec
154ls -ls tmp*
155$ECHO "compress multiple files including a missing one (notHere) : "
156$ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
157
158
inikep5d589562016-05-25 10:50:28 +0200159$ECHO "\n**** dictionary tests **** "
Yann Colletf6f3d752015-12-13 13:35:21 +0100160
161./datagen > tmpDict
inikep93fc13e2016-05-30 10:17:55 +0200162./datagen -g1M | $MD5SUM > tmp1
163./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
Yann Colletf6f3d752015-12-13 13:35:21 +0100164diff -q tmp1 tmp2
Yann Collet531a4272016-06-15 19:02:11 +0200165$ECHO "- Create first dictionary"
Yann Collet33341de2016-05-29 23:09:51 +0200166$ZSTD --train *.c -o tmpDict
Yann Collet6381e992016-05-31 02:29:45 +0200167cp zstdcli.c tmp
168$ZSTD -f tmp -D tmpDict
169$ZSTD -d tmp.zst -D tmpDict -of result
Yann Colletc46fb922016-05-29 05:01:04 +0200170diff zstdcli.c result
Yann Collet531a4272016-06-15 19:02:11 +0200171$ECHO "- Create second (different) dictionary"
Yann Collet33341de2016-05-29 23:09:51 +0200172$ZSTD --train *.c *.h -o tmpDictC
Yann Collet6381e992016-05-31 02:29:45 +0200173$ZSTD -d tmp.zst -D tmpDictC -of result && die "wrong dictionary not detected!"
Yann Collet531a4272016-06-15 19:02:11 +0200174$ECHO "- Create dictionary with short dictID"
Yann Collet290aaa72016-05-30 21:18:52 +0200175$ZSTD --train *.c --dictID 1 -o tmpDict1
176cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
Yann Collet531a4272016-06-15 19:02:11 +0200177$ECHO "- Compress without dictID"
Yann Collet6381e992016-05-31 02:29:45 +0200178$ZSTD -f tmp -D tmpDict1 --no-dictID
179$ZSTD -d tmp.zst -D tmpDict -of result
180diff zstdcli.c result
Yann Collet531a4272016-06-15 19:02:11 +0200181$ECHO "- Compress multiple files with dictionary"
182cat *.c *.h | $MD5SUM > tmp1
183rm -rf dirTestDict
184mkdir dirTestDict
185cp *.c dirTestDict
186cp *.h dirTestDict
187$ZSTD -f dirTestDict/* -D tmpDictC
188$ZSTD -d dirTestDict/*.zst -D tmpDictC -c | $MD5SUM > tmp2
189diff -q tmp1 tmp2
190rm -rf dirTestDict
Yann Collet6381e992016-05-31 02:29:45 +0200191rm tmp*
Yann Colletb44be742016-03-26 20:52:14 +0100192
Yann Colletf6f3d752015-12-13 13:35:21 +0100193
inikep5d589562016-05-25 10:50:28 +0200194$ECHO "\n**** integrity tests **** "
Yann Colletde95f962016-05-23 19:46:47 +0200195
inikep5d589562016-05-25 10:50:28 +0200196$ECHO "test one file (tmp1.zst) "
Yann Collet459a6b72016-02-15 20:37:23 +0100197$ZSTD -t tmp1.zst
Yann Collet2d08b092016-02-16 14:42:08 +0100198$ZSTD --test tmp1.zst
inikep5d589562016-05-25 10:50:28 +0200199$ECHO "test multiple files (*.zst) "
Yann Collet459a6b72016-02-15 20:37:23 +0100200$ZSTD -t *.zst
inikep5d589562016-05-25 10:50:28 +0200201$ECHO "test good and bad files (*) "
Yann Collet459a6b72016-02-15 20:37:23 +0100202$ZSTD -t * && die "bad files not detected !"
Yann Colletdeb078b2015-12-17 20:30:14 +0100203
Yann Colletde95f962016-05-23 19:46:47 +0200204
inikep5d589562016-05-25 10:50:28 +0200205$ECHO "\n**** zstd round-trip tests **** "
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300206
207roundTripTest
Yann Collet3b719252016-03-30 19:48:05 +0200208roundTripTest -g15K # TableID==3
209roundTripTest -g127K # TableID==2
210roundTripTest -g255K # TableID==1
211roundTripTest -g513K # TableID==0
Yann Collet459a6b72016-02-15 20:37:23 +0100212roundTripTest -g512K 6 # greedy, hash chain
Yann Collet0d348d42016-05-29 02:02:24 +0200213roundTripTest -g512K 16 # btlazy2
Yann Collet459a6b72016-02-15 20:37:23 +0100214roundTripTest -g512K 19 # btopt
215
216rm tmp*
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300217
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300218if [ "$1" != "--test-large-data" ]; then
inikep5d589562016-05-25 10:50:28 +0200219 $ECHO "Skipping large data tests"
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300220 exit 0
221fi
222
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300223roundTripTest -g270000000 1
224roundTripTest -g270000000 2
225roundTripTest -g270000000 3
226
227roundTripTest -g140000000 -P60 4
228roundTripTest -g140000000 -P60 5
229roundTripTest -g140000000 -P60 6
230
231roundTripTest -g70000000 -P70 7
232roundTripTest -g70000000 -P70 8
233roundTripTest -g70000000 -P70 9
234
235roundTripTest -g35000000 -P75 10
236roundTripTest -g35000000 -P75 11
237roundTripTest -g35000000 -P75 12
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300238
Konstantin Tokarev2b465842015-12-08 19:36:42 +0300239roundTripTest -g18000000 -P80 13
240roundTripTest -g18000000 -P80 14
241roundTripTest -g18000000 -P80 15
242roundTripTest -g18000000 -P80 16
243roundTripTest -g18000000 -P80 17
244
245roundTripTest -g50000000 -P94 18
246roundTripTest -g50000000 -P94 19
247
248roundTripTest -g99000000 -P99 20
Yann Colletecabfe32016-03-20 16:20:06 +0100249roundTripTest -g6000000000 -P99 1
Yann Collet459a6b72016-02-15 20:37:23 +0100250
251rm tmp*