blob: 65c661e17ee350ced9c16f5af2cf985f57d01089 [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
Yann Collet4616fad2017-07-10 17:16:41 -070010 cLevel="$3"
11 proba="$2"
Konstantin Tokarev76be3782015-12-08 18:36:37 +030012 else
Yann Collet4616fad2017-07-10 17:16:41 -070013 cLevel="$2"
14 proba=""
Konstantin Tokarev76be3782015-12-08 18:36:37 +030015 fi
Nick Terrellc233bdb2017-09-22 14:04:39 -070016 if [ -n "$4" ]; then
17 dLevel="$4"
18 else
19 dLevel="$cLevel"
20 fi
Konstantin Tokarev76be3782015-12-08 18:36:37 +030021
22 rm -f tmp1 tmp2
Nick Terrellc233bdb2017-09-22 14:04:39 -070023 $ECHO "roundTripTest: ./datagen $1 $proba | $ZSTD -v$cLevel | $ZSTD -d$dLevel"
Yann Collet4616fad2017-07-10 17:16:41 -070024 ./datagen $1 $proba | $MD5SUM > tmp1
Nick Terrellc233bdb2017-09-22 14:04:39 -070025 ./datagen $1 $proba | $ZSTD --ultra -v$cLevel | $ZSTD -d$dLevel | $MD5SUM > tmp2
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +010026 $DIFF -q tmp1 tmp2
Konstantin Tokarev76be3782015-12-08 18:36:37 +030027}
28
Sean Purcelleb70d212017-04-11 17:15:13 -070029fileRoundTripTest() {
30 if [ -n "$3" ]; then
31 local_c="$3"
32 local_p="$2"
33 else
34 local_c="$2"
35 local_p=""
36 fi
Nick Terrellc233bdb2017-09-22 14:04:39 -070037 if [ -n "$4" ]; then
38 local_d="$4"
39 else
40 local_d="$local_c"
41 fi
Sean Purcelleb70d212017-04-11 17:15:13 -070042
43 rm -f tmp.zstd tmp.md5.1 tmp.md5.2
Nick Terrellc233bdb2017-09-22 14:04:39 -070044 $ECHO "fileRoundTripTest: ./datagen $1 $local_p > tmp && $ZSTD -v$local_c -c tmp | $ZSTD -d$local_d"
Sean Purcelleb70d212017-04-11 17:15:13 -070045 ./datagen $1 $local_p > tmp
Yann Collet42526212017-10-05 20:21:59 -070046 < tmp $MD5SUM > tmp.md5.1
Nick Terrellc233bdb2017-09-22 14:04:39 -070047 $ZSTD --ultra -v$local_c -c tmp | $ZSTD -d$local_d | $MD5SUM > tmp.md5.2
Sean Purcelleb70d212017-04-11 17:15:13 -070048 $DIFF -q tmp.md5.1 tmp.md5.2
49}
50
Björn Ketelaars276988f2018-06-30 13:01:58 +020051UNAME=$(uname)
52
Sean Purcell9a38dfa2017-03-17 12:32:18 -070053isTerminal=false
54if [ -t 0 ] && [ -t 1 ]
55then
56 isTerminal=true
57fi
58
inikep5d589562016-05-25 10:50:28 +020059isWindows=false
Yann Collet391a1282016-06-21 17:06:25 +020060INTOVOID="/dev/null"
Björn Ketelaars276988f2018-06-30 13:01:58 +020061case "$UNAME" in
Dmitry V. Levin7ca12a12018-07-11 12:41:50 +000062 GNU) DEVDEVICE="/dev/random" ;;
63 *) DEVDEVICE="/dev/zero" ;;
Björn Ketelaars276988f2018-06-30 13:01:58 +020064esac
inikep993a9df2016-05-27 10:07:46 +020065case "$OS" in
Yann Collet673f0d72016-06-06 00:26:38 +020066 Windows*)
inikep5d589562016-05-25 10:50:28 +020067 isWindows=true
Sean Purcell9a38dfa2017-03-17 12:32:18 -070068 INTOVOID="NUL"
Nick Terrell82bc8fe2017-12-13 12:04:46 -080069 DEVDEVICE="NUL"
inikep993a9df2016-05-27 10:07:46 +020070 ;;
71esac
inikep5d589562016-05-25 10:50:28 +020072
Dimitry Andric12df6da2016-12-12 19:22:47 +010073case "$UNAME" in
74 Darwin) MD5SUM="md5 -r" ;;
75 FreeBSD) MD5SUM="gmd5sum" ;;
bketdaf3ab02018-04-02 23:12:18 +020076 OpenBSD) MD5SUM="md5" ;;
Yann Collet94d1a932016-12-06 12:02:56 -080077 *) MD5SUM="md5sum" ;;
78esac
inikep5d589562016-05-25 10:50:28 +020079
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +010080DIFF="diff"
81case "$UNAME" in
82 SunOS) DIFF="gdiff" ;;
83esac
84
Yann Collet62568c92017-09-25 14:26:26 -070085ECHO="echo -e"
86case "$UNAME" in
87 Darwin) ECHO="echo" ;;
88esac
89
Przemyslaw Skibinskie579ab52016-11-14 12:57:05 +010090$ECHO "\nStarting playTests.sh isWindows=$isWindows ZSTD='$ZSTD'"
inikep5d589562016-05-25 10:50:28 +020091
Konstantin Tokarev76be3782015-12-08 18:36:37 +030092[ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
93
Sean Purcellc424ec22017-04-17 11:38:53 -070094if [ -n "$(echo hello | $ZSTD -v -T2 2>&1 > $INTOVOID | grep 'multi-threading is disabled')" ]
95then
96 hasMT=""
97else
98 hasMT="true"
99fi
100
Yann Colleta927fae2018-01-06 12:31:26 +0100101
Yann Collet241c57a2017-10-16 14:01:42 -0700102$ECHO "\n===> simple tests "
Yann Colletde95f962016-05-23 19:46:47 +0200103
Yann Collet8154c3d2016-02-13 03:12:10 +0100104./datagen > tmp
Yann Colletb3060f72016-09-09 16:44:16 +0200105$ECHO "test : basic compression "
Yann Collet673f0d72016-06-06 00:26:38 +0200106$ZSTD -f tmp # trivial compression case, creates tmp.zst
Yann Colletb3060f72016-09-09 16:44:16 +0200107$ECHO "test : basic decompression"
Yann Collet673f0d72016-06-06 00:26:38 +0200108$ZSTD -df tmp.zst # trivial decompression case (overwrites tmp)
Yann Collet6a9b41b2018-03-11 19:56:48 -0700109$ECHO "test : too large compression level => auto-fix"
Yann Colletfab02302016-08-12 19:00:18 +0200110$ZSTD -99 -f tmp # too large compression level, automatic sized down
Yann Collet6a9b41b2018-03-11 19:56:48 -0700111$ECHO "test : --fast aka negative compression levels"
112$ZSTD --fast -f tmp # == -1
113$ZSTD --fast=3 -f tmp # == -3
Yann Collet93b82622018-03-21 15:54:44 -0700114$ZSTD --fast=200000 -f tmp # == no compression
Jennifer Liu1ab57a72018-06-27 16:27:45 -0700115! $ZSTD -c --fast=0 tmp > $INTOVOID # should fail
Yann Collet9cd5c632018-05-12 14:29:33 -0700116$ECHO "test : too large numeric argument"
117$ZSTD --fast=9999999999 -f tmp && die "should have refused numeric value"
inikep5d589562016-05-25 10:50:28 +0200118$ECHO "test : compress to stdout"
Yann Collet0d348d42016-05-29 02:02:24 +0200119$ZSTD tmp -c > tmpCompressed
Yann Colletd6931172016-05-10 05:56:09 +0200120$ZSTD tmp --stdout > tmpCompressed # long command format
Yann Collet27b5ac62016-09-21 14:20:56 +0200121$ECHO "test : compress to named file"
122rm tmpCompressed
123$ZSTD tmp -o tmpCompressed
Yann Collet01a1abf2017-05-05 19:15:24 -0700124test -f tmpCompressed # file must be created
Yann Collet27b5ac62016-09-21 14:20:56 +0200125$ECHO "test : -o must be followed by filename (must fail)"
Yann Collet714464f2016-09-21 16:05:03 +0200126$ZSTD tmp -of tmpCompressed && die "-o must be followed by filename "
Yann Collet27b5ac62016-09-21 14:20:56 +0200127$ECHO "test : force write, correct order"
128$ZSTD tmp -fo tmpCompressed
Yann Collet714464f2016-09-21 16:05:03 +0200129$ECHO "test : forgotten argument"
130cp tmp tmp2
131$ZSTD tmp2 -fo && die "-o must be followed by filename "
Yann Colletc8431422016-09-01 15:05:57 -0700132$ECHO "test : implied stdout when input is stdin"
133$ECHO bob | $ZSTD | $ZSTD -d
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700134if [ "$isTerminal" = true ]; then
Sean Purcelld9730712017-03-16 16:25:19 -0700135$ECHO "test : compressed data to terminal"
136$ECHO bob | $ZSTD && die "should have refused : compressed data to terminal"
137$ECHO "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)"
138$ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal"
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700139fi
inikep5d589562016-05-25 10:50:28 +0200140$ECHO "test : null-length file roundtrip"
141$ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
Yann Collet281f06e2017-12-14 11:47:02 -0800142$ECHO "test : ensure small file doesn't add 3-bytes null block"
Yann Colleta0e09852017-12-14 13:32:24 -0800143./datagen -g1 > tmp1
144$ZSTD tmp1 -c | wc -c | grep "14"
145$ZSTD < tmp1 | wc -c | grep "14"
inikep5d589562016-05-25 10:50:28 +0200146$ECHO "test : decompress file with wrong suffix (must fail)"
Yann Collet2d08b092016-02-16 14:42:08 +0100147$ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
Yann Collet391a1282016-06-21 17:06:25 +0200148$ZSTD -df tmp && die "should have refused : wrong extension"
149$ECHO "test : decompress into stdout"
Yann Collet0d348d42016-05-29 02:02:24 +0200150$ZSTD -d tmpCompressed -c > tmpResult # decompression using stdout
Yann Collet2d08b092016-02-16 14:42:08 +0100151$ZSTD --decompress tmpCompressed -c > tmpResult
152$ZSTD --decompress tmpCompressed --stdout > tmpResult
Yann Collet391a1282016-06-21 17:06:25 +0200153$ECHO "test : decompress from stdin into stdout"
154$ZSTD -dc < tmp.zst > $INTOVOID # combine decompression, stdin & stdout
155$ZSTD -dc - < tmp.zst > $INTOVOID
156$ZSTD -d < tmp.zst > $INTOVOID # implicit stdout when stdin is used
157$ZSTD -d - < tmp.zst > $INTOVOID
Yann Colletd4cda272016-10-14 13:13:13 -0700158$ECHO "test : impose memory limitation (must fail)"
159$ZSTD -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
Yann Collet11223492016-10-14 14:07:11 -0700160$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 -0700161$ZSTD -d -f tmp.zst --memory=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
162$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 +0200163$ECHO "test : overwrite protection"
Yann Collet2d08b092016-02-16 14:42:08 +0100164$ZSTD -q tmp && die "overwrite check failed!"
Yann Collet391a1282016-06-21 17:06:25 +0200165$ECHO "test : force overwrite"
Yann Collet2d08b092016-02-16 14:42:08 +0100166$ZSTD -q -f tmp
167$ZSTD -q --force tmp
Sean Purcell9da11c62017-04-06 12:58:49 -0700168$ECHO "test : overwrite readonly file"
Sean Purcell16521722017-04-06 17:06:30 -0700169rm -f tmpro tmpro.zst
Sean Purcell9da11c62017-04-06 12:58:49 -0700170$ECHO foo > tmpro.zst
171$ECHO foo > tmpro
172chmod 400 tmpro.zst
Sean Purcell16521722017-04-06 17:06:30 -0700173$ZSTD -q tmpro && die "should have refused to overwrite read-only file"
174$ZSTD -q -f tmpro
175rm -f tmpro tmpro.zst
Yann Colletb09b12c2016-06-09 22:59:51 +0200176$ECHO "test : file removal"
177$ZSTD -f --rm tmp
Yann Collet01a1abf2017-05-05 19:15:24 -0700178test ! -f tmp # tmp should no longer be present
Yann Colletb09b12c2016-06-09 22:59:51 +0200179$ZSTD -f -d --rm tmp.zst
Yann Collet01a1abf2017-05-05 19:15:24 -0700180test ! -f tmp.zst # tmp.zst should no longer be present
Nick Terrell82bc8fe2017-12-13 12:04:46 -0800181$ECHO "test : should quietly not remove non-regular file"
182$ECHO hello > tmp
183$ZSTD tmp -f -o "$DEVDEVICE" 2>tmplog > "$INTOVOID"
184grep -v "Refusing to remove non-regular file" tmplog
185rm -f tmplog
Nick Terrell263134c2018-05-03 13:03:08 -0700186$ZSTD tmp -f -o "$INTOVOID" 2>&1 | grep -v "Refusing to remove non-regular file"
Yann Collet67d86a72017-02-27 16:09:20 -0800187$ECHO "test : --rm on stdin"
188$ECHO a | $ZSTD --rm > $INTOVOID # --rm should remain silent
Yann Colletb09b12c2016-06-09 22:59:51 +0200189rm tmp
190$ZSTD -f tmp && die "tmp not present : should have failed"
Yann Collet01a1abf2017-05-05 19:15:24 -0700191test ! -f tmp.zst # tmp.zst should not be created
Yann Colletde95f962016-05-23 19:46:47 +0200192
Nick Terrell4680e852017-12-12 18:32:50 -0800193$ECHO "test : compress multiple files"
George Lu0e808d62018-06-04 16:32:37 -0700194rm tmp*
Nick Terrell4680e852017-12-12 18:32:50 -0800195$ECHO hello > tmp1
196$ECHO world > tmp2
197$ZSTD tmp1 tmp2 -o "$INTOVOID"
198$ZSTD tmp1 tmp2 -c | $ZSTD -t
199$ZSTD tmp1 tmp2 -o tmp.zst
200test ! -f tmp1.zst
201test ! -f tmp2.zst
202$ZSTD tmp1 tmp2
203$ZSTD -t tmp1.zst tmp2.zst
204$ZSTD -dc tmp1.zst tmp2.zst
205$ZSTD tmp1.zst tmp2.zst -o "$INTOVOID"
206$ZSTD -d tmp1.zst tmp2.zst -o tmp
Nick Terrell8adebbd2018-01-03 14:02:44 -0800207touch tmpexists
208$ZSTD tmp1 tmp2 -f -o tmpexists
209$ZSTD tmp1 tmp2 -o tmpexists && die "should have refused to overwrite"
210# Bug: PR #972
211if [ "$?" -eq 139 ]; then
212 die "should not have segfaulted"
213fi
Nick Terrell4680e852017-12-12 18:32:50 -0800214rm tmp*
215
216
Yann Collet241c57a2017-10-16 14:01:42 -0700217$ECHO "\n===> Advanced compression parameters "
Przemyslaw Skibinski24a42362016-12-14 18:07:31 +0100218$ECHO "Hello world!" | $ZSTD --zstd=windowLog=21, - -o tmp.zst && die "wrong parameters not detected!"
219$ECHO "Hello world!" | $ZSTD --zstd=windowLo=21 - -o tmp.zst && die "wrong parameters not detected!"
Przemyslaw Skibinskif9a56662016-12-14 18:43:06 +0100220$ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,slog - -o tmp.zst && die "wrong parameters not detected!"
Yann Collet01a1abf2017-05-05 19:15:24 -0700221test ! -f tmp.zst # tmp.zst should not be created
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100222roundTripTest -g512K
Przemyslaw Skibinskiab5ed6f2016-12-14 17:10:38 +0100223roundTripTest -g512K " --zstd=slen=3,tlen=48,strat=6"
224roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100225roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,searchLength=3,targetLength=48,strategy=6"
Nick Terrellf15a17e2018-02-27 20:09:18 -0800226roundTripTest -g512K " --single-thread --long --zstd=ldmHashLog=20,ldmSearchLength=64,ldmBucketSizeLog=1,ldmHashEveryLog=7"
227roundTripTest -g512K " --single-thread --long --zstd=ldmhlog=20,ldmslen=64,ldmblog=1,ldmhevery=7"
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100228roundTripTest -g512K 19
229
230
Yann Collet241c57a2017-10-16 14:01:42 -0700231$ECHO "\n===> Pass-Through mode "
Yann Collet743b33f2016-12-02 15:18:57 -0800232$ECHO "Hello world 1!" | $ZSTD -df
233$ECHO "Hello world 2!" | $ZSTD -dcf
234$ECHO "Hello world 3!" > tmp1
235$ZSTD -dcf tmp1
Yann Colletde95f962016-05-23 19:46:47 +0200236
Yann Collet8154c3d2016-02-13 03:12:10 +0100237
Yann Collet241c57a2017-10-16 14:01:42 -0700238$ECHO "\n===> frame concatenation "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300239
inikep5d589562016-05-25 10:50:28 +0200240$ECHO "hello " > hello.tmp
241$ECHO "world!" > world.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300242cat hello.tmp world.tmp > helloworld.tmp
Yann Colletc8da2c92016-02-12 02:56:27 +0100243$ZSTD -c hello.tmp > hello.zstd
244$ZSTD -c world.tmp > world.zstd
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300245cat hello.zstd world.zstd > helloworld.zstd
Yann Colletc8da2c92016-02-12 02:56:27 +0100246$ZSTD -dc helloworld.zstd > result.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300247cat result.tmp
Yann Colletbd6bc222017-01-22 15:54:14 -0800248$DIFF helloworld.tmp result.tmp
Yann Collet4c5bbf62016-07-28 20:30:25 +0200249$ECHO "frame concatenation without checksum"
250$ZSTD -c hello.tmp > hello.zstd --no-check
251$ZSTD -c world.tmp > world.zstd --no-check
252cat hello.zstd world.zstd > helloworld.zstd
253$ZSTD -dc helloworld.zstd > result.tmp
Yann Colletbd6bc222017-01-22 15:54:14 -0800254$DIFF helloworld.tmp result.tmp
Yann Colletcb5eba82018-01-19 11:26:35 -0800255$ECHO "testing zstdcat symlink"
256ln -sf $ZSTD zstdcat
257./zstdcat helloworld.zstd > result.tmp
258$DIFF helloworld.tmp result.tmp
259rm zstdcat
260rm result.tmp
261$ECHO "testing zcat symlink"
262ln -sf $ZSTD zcat
263./zcat helloworld.zstd > result.tmp
264$DIFF helloworld.tmp result.tmp
265rm zcat
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300266rm ./*.tmp ./*.zstd
inikep5d589562016-05-25 10:50:28 +0200267$ECHO "frame concatenation tests completed"
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300268
Yann Colletf0624362016-02-12 15:56:46 +0100269
bketdaf3ab02018-04-02 23:12:18 +0200270if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] && [ "$UNAME" != "OpenBSD" ] ; then
inikep5d589562016-05-25 10:50:28 +0200271$ECHO "\n**** flush write error test **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300272
inikep5d589562016-05-25 10:50:28 +0200273$ECHO "$ECHO foo | $ZSTD > /dev/full"
274$ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
275$ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
276$ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
Sean Purcell680e4e02017-03-23 11:52:09 -0700277
Yann Collet01a1abf2017-05-05 19:15:24 -0700278
Yann Collet241c57a2017-10-16 14:01:42 -0700279$ECHO "\n===> symbolic link test "
Sean Purcell680e4e02017-03-23 11:52:09 -0700280
281rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
282$ECHO "hello world" > hello.tmp
283ln -s hello.tmp world.tmp
284$ZSTD world.tmp hello.tmp
Yann Collet01a1abf2017-05-05 19:15:24 -0700285test -f hello.tmp.zst # regular file should have been compressed!
286test ! -f world.tmp.zst # symbolic link should not have been compressed!
Sean Purcell680e4e02017-03-23 11:52:09 -0700287$ZSTD world.tmp hello.tmp -f
Yann Collet01a1abf2017-05-05 19:15:24 -0700288test -f world.tmp.zst # symbolic link should have been compressed with --force
Sean Purcell680e4e02017-03-23 11:52:09 -0700289rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
290
inikep5d589562016-05-25 10:50:28 +0200291fi
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300292
Yann Collet6a458352015-12-18 02:51:14 +0100293
Yann Collet241c57a2017-10-16 14:01:42 -0700294$ECHO "\n===> test sparse file support "
Yann Collet32990b52016-05-23 17:48:57 +0200295
296./datagen -g5M -P100 > tmpSparse
297$ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100298$DIFF -s tmpSparse tmpSparseRegen
Yann Collet32990b52016-05-23 17:48:57 +0200299$ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100300$DIFF -s tmpSparse tmpOutSparse
Yann Collet32990b52016-05-23 17:48:57 +0200301$ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100302$DIFF -s tmpSparse tmpOutNoSparse
Yann Collet01a1abf2017-05-05 19:15:24 -0700303ls -ls tmpSparse* # look at file size and block size on disk
Yann Collet32990b52016-05-23 17:48:57 +0200304./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 +0100305./datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
Yann Collet01a1abf2017-05-05 19:15:24 -0700306ls -ls tmpSparseOdd # look at file size and block size on disk
inikep5d589562016-05-25 10:50:28 +0200307$ECHO "\n Sparse Compatibility with Console :"
308$ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
309$ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
310$ECHO "\n Sparse Compatibility with Append :"
Yann Collet32990b52016-05-23 17:48:57 +0200311./datagen -P100 -g1M > tmpSparse1M
312cat tmpSparse1M tmpSparse1M > tmpSparse2M
313$ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
314$ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
315$ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
Yann Collet01a1abf2017-05-05 19:15:24 -0700316ls -ls tmpSparse* # look at file size and block size on disk
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100317$DIFF tmpSparse2M tmpSparseRegenerated
Yann Collet33341de2016-05-29 23:09:51 +0200318rm tmpSparse*
Yann Collet32990b52016-05-23 17:48:57 +0200319
320
Yann Collet241c57a2017-10-16 14:01:42 -0700321$ECHO "\n===> multiple files tests "
Yann Collet9b998e42016-06-15 23:11:20 +0200322
Yann Collet391a1282016-06-21 17:06:25 +0200323./datagen -s1 > tmp1 2> $INTOVOID
324./datagen -s2 -g100K > tmp2 2> $INTOVOID
325./datagen -s3 -g1M > tmp3 2> $INTOVOID
Yann Collet9b998e42016-06-15 23:11:20 +0200326$ECHO "compress tmp* : "
Yann Collet60ba31c2016-07-28 19:55:09 +0200327$ZSTD -f tmp*
Yann Collet9b998e42016-06-15 23:11:20 +0200328ls -ls tmp*
329rm tmp1 tmp2 tmp3
330$ECHO "decompress tmp* : "
331$ZSTD -df *.zst
332ls -ls tmp*
333$ECHO "compress tmp* into stdout > tmpall : "
334$ZSTD -c tmp1 tmp2 tmp3 > tmpall
Yann Collet01a1abf2017-05-05 19:15:24 -0700335ls -ls tmp* # check size of tmpall (should be tmp1.zst + tmp2.zst + tmp3.zst)
Yann Collet9b998e42016-06-15 23:11:20 +0200336$ECHO "decompress tmpall* into stdout > tmpdec : "
337cp tmpall tmpall2
338$ZSTD -dc tmpall* > tmpdec
Yann Collet01a1abf2017-05-05 19:15:24 -0700339ls -ls tmp* # check size of tmpdec (should be 2*(tmp1 + tmp2 + tmp3))
Yann Collet9b998e42016-06-15 23:11:20 +0200340$ECHO "compress multiple files including a missing one (notHere) : "
341$ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
342
343
Yann Collet241c57a2017-10-16 14:01:42 -0700344$ECHO "\n===> dictionary tests "
Yann Colletf6f3d752015-12-13 13:35:21 +0100345
Yann Colletbd7fa212017-02-26 14:43:07 -0800346$ECHO "- test with raw dict (content only) "
Yann Colletf6f3d752015-12-13 13:35:21 +0100347./datagen > tmpDict
inikep93fc13e2016-05-30 10:17:55 +0200348./datagen -g1M | $MD5SUM > tmp1
349./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100350$DIFF -q tmp1 tmp2
Yann Colletbd7fa212017-02-26 14:43:07 -0800351$ECHO "- Create first dictionary "
352TESTFILE=../programs/zstdcli.c
inikepb7d34492016-08-18 15:13:41 +0200353$ZSTD --train *.c ../programs/*.c -o tmpDict
354cp $TESTFILE tmp
Yann Colletd228b6b2017-12-29 19:14:18 +0100355$ECHO "- Dictionary compression roundtrip"
Yann Collet6381e992016-05-31 02:29:45 +0200356$ZSTD -f tmp -D tmpDict
Yann Collet27b5ac62016-09-21 14:20:56 +0200357$ZSTD -d tmp.zst -D tmpDict -fo result
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100358$DIFF $TESTFILE result
Yann Colletd228b6b2017-12-29 19:14:18 +0100359$ECHO "- Dictionary compression with btlazy2 strategy"
360$ZSTD -f tmp -D tmpDict --zstd=strategy=6
361$ZSTD -d tmp.zst -D tmpDict -fo result
362$DIFF $TESTFILE result
Yann Collet311878d2017-12-13 11:48:30 -0800363if [ -n "$hasMT" ]
364then
365 $ECHO "- Test dictionary compression with multithreading "
Yann Collet281f06e2017-12-14 11:47:02 -0800366 ./datagen -g5M | $ZSTD -T2 -D tmpDict | $ZSTD -t -D tmpDict # fails with v1.3.2
Yann Collet311878d2017-12-13 11:48:30 -0800367fi
Yann Colletbd7fa212017-02-26 14:43:07 -0800368$ECHO "- Create second (different) dictionary "
inikepb7d34492016-08-18 15:13:41 +0200369$ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
Yann Collet27b5ac62016-09-21 14:20:56 +0200370$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
Yann Collet531a4272016-06-15 19:02:11 +0200371$ECHO "- Create dictionary with short dictID"
Yann Collet4c41d372017-03-24 18:36:56 -0700372$ZSTD --train *.c ../programs/*.c --dictID=1 -o tmpDict1
Yann Collet290aaa72016-05-30 21:18:52 +0200373cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
Yann Collet27b5ac62016-09-21 14:20:56 +0200374$ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
375$ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
376$ECHO "- Create dictionary with size limit"
Yann Collet4c41d372017-03-24 18:36:56 -0700377$ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict=4K -v
Nick Terrell35875562017-08-21 11:16:47 -0700378$ECHO "- Create dictionary with small size limit"
379$ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict=1K -v
Yann Collet27b5ac62016-09-21 14:20:56 +0200380$ECHO "- Create dictionary with wrong parameter order (must fail)"
Nick Terrell35875562017-08-21 11:16:47 -0700381$ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict -v 4K && die "wrong order : --maxdict must be followed by argument "
Yann Collet531a4272016-06-15 19:02:11 +0200382$ECHO "- Compress without dictID"
Yann Collet6381e992016-05-31 02:29:45 +0200383$ZSTD -f tmp -D tmpDict1 --no-dictID
Yann Collet27b5ac62016-09-21 14:20:56 +0200384$ZSTD -d tmp.zst -D tmpDict -fo result
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100385$DIFF $TESTFILE result
Yann Collet27b5ac62016-09-21 14:20:56 +0200386$ECHO "- Compress with wrong argument order (must fail)"
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700387$ZSTD tmp -Df tmpDict1 -c > $INTOVOID && die "-D must be followed by dictionary name "
Yann Collet531a4272016-06-15 19:02:11 +0200388$ECHO "- Compress multiple files with dictionary"
Yann Collet531a4272016-06-15 19:02:11 +0200389rm -rf dirTestDict
390mkdir dirTestDict
391cp *.c dirTestDict
inikepb7d34492016-08-18 15:13:41 +0200392cp ../programs/*.c dirTestDict
393cp ../programs/*.h dirTestDict
Yann Collet94376ac2016-08-25 19:09:21 +0200394$MD5SUM dirTestDict/* > tmph1
395$ZSTD -f --rm dirTestDict/* -D tmpDictC
Yann Colletbb93d772016-08-25 22:22:50 +0200396$ZSTD -d --rm dirTestDict/*.zst -D tmpDictC # note : use internal checksum by default
Dimitry Andric12df6da2016-12-12 19:22:47 +0100397case "$UNAME" in
398 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 -0800399 *) $MD5SUM -c tmph1 ;;
400esac
Yann Collet531a4272016-06-15 19:02:11 +0200401rm -rf dirTestDict
Yann Colletf332ece2017-03-23 16:24:02 -0700402$ECHO "- dictionary builder on bogus input"
403$ECHO "Hello World" > tmp
Nick Terrellf376d472017-05-01 23:40:20 -0700404$ZSTD --train-legacy -q tmp && die "Dictionary training should fail : not enough input source"
Yann Colletf332ece2017-03-23 16:24:02 -0700405./datagen -P0 -g10M > tmp
Nick Terrellf376d472017-05-01 23:40:20 -0700406$ZSTD --train-legacy -q tmp && die "Dictionary training should fail : source is pure noise"
Yann Collet6381e992016-05-31 02:29:45 +0200407rm tmp*
Yann Colletb44be742016-03-26 20:52:14 +0100408
Yann Colletf6f3d752015-12-13 13:35:21 +0100409
Yann Collet241c57a2017-10-16 14:01:42 -0700410$ECHO "\n===> cover dictionary builder : advanced options "
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500411
412TESTFILE=../programs/zstdcli.c
413./datagen > tmpDict
414$ECHO "- Create first dictionary"
Nick Terrellf376d472017-05-01 23:40:20 -0700415$ZSTD --train-cover=k=46,d=8 *.c ../programs/*.c -o tmpDict
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500416cp $TESTFILE tmp
417$ZSTD -f tmp -D tmpDict
418$ZSTD -d tmp.zst -D tmpDict -fo result
419$DIFF $TESTFILE result
420$ECHO "- Create second (different) dictionary"
Nick Terrellf376d472017-05-01 23:40:20 -0700421$ZSTD --train-cover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500422$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
423$ECHO "- Create dictionary with short dictID"
Nick Terrellf376d472017-05-01 23:40:20 -0700424$ZSTD --train-cover=k=46,d=8 *.c ../programs/*.c --dictID=1 -o tmpDict1
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500425cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
426$ECHO "- Create dictionary with size limit"
Nick Terrellf376d472017-05-01 23:40:20 -0700427$ZSTD --train-cover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
428rm tmp*
429
Yann Collet241c57a2017-10-16 14:01:42 -0700430$ECHO "\n===> legacy dictionary builder "
Nick Terrellf376d472017-05-01 23:40:20 -0700431
432TESTFILE=../programs/zstdcli.c
433./datagen > tmpDict
434$ECHO "- Create first dictionary"
435$ZSTD --train-legacy=selectivity=8 *.c ../programs/*.c -o tmpDict
436cp $TESTFILE tmp
437$ZSTD -f tmp -D tmpDict
438$ZSTD -d tmp.zst -D tmpDict -fo result
439$DIFF $TESTFILE result
440$ECHO "- Create second (different) dictionary"
441$ZSTD --train-legacy=s=5 *.c ../programs/*.c ../programs/*.h -o tmpDictC
442$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
443$ECHO "- Create dictionary with short dictID"
444$ZSTD --train-legacy -s5 *.c ../programs/*.c --dictID=1 -o tmpDict1
445cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
446$ECHO "- Create dictionary with size limit"
447$ZSTD --train-legacy -s9 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500448rm tmp*
449
450
Yann Collet241c57a2017-10-16 14:01:42 -0700451$ECHO "\n===> integrity tests "
Yann Colletde95f962016-05-23 19:46:47 +0200452
inikep5d589562016-05-25 10:50:28 +0200453$ECHO "test one file (tmp1.zst) "
Yann Collet1a7b8fb2016-06-15 23:33:38 +0200454./datagen > tmp1
455$ZSTD tmp1
Yann Collet459a6b72016-02-15 20:37:23 +0100456$ZSTD -t tmp1.zst
Yann Collet2d08b092016-02-16 14:42:08 +0100457$ZSTD --test tmp1.zst
inikep5d589562016-05-25 10:50:28 +0200458$ECHO "test multiple files (*.zst) "
Yann Collet459a6b72016-02-15 20:37:23 +0100459$ZSTD -t *.zst
Yann Collet24a3d902016-07-26 01:26:56 +0200460$ECHO "test bad files (*) "
Yann Collet459a6b72016-02-15 20:37:23 +0100461$ZSTD -t * && die "bad files not detected !"
Yann Collet24a3d902016-07-26 01:26:56 +0200462$ZSTD -t tmp1 && die "bad file not detected !"
463cp tmp1 tmp2.zst
464$ZSTD -t tmp2.zst && die "bad file not detected !"
Yann Collet7adc2322016-07-26 15:39:31 +0200465./datagen -g0 > tmp3
466$ZSTD -t tmp3 && die "bad file not detected !" # detects 0-sized files as bad
Yann Colletb4024902016-07-26 00:49:47 +0200467$ECHO "test --rm and --test combined "
468$ZSTD -t --rm tmp1.zst
Yann Collet01a1abf2017-05-05 19:15:24 -0700469test -f tmp1.zst # check file is still present
470split -b16384 tmp1.zst tmpSplit.
471$ZSTD -t tmpSplit.* && die "bad file not detected !"
Nick Terrelld0b27482017-07-18 14:45:49 -0700472./datagen | $ZSTD -c | $ZSTD -t
Yann Colletdeb078b2015-12-17 20:30:14 +0100473
Yann Colletde95f962016-05-23 19:46:47 +0200474
Nick Terrellabe12b32017-07-28 11:54:28 -0700475
Yann Collet241c57a2017-10-16 14:01:42 -0700476$ECHO "\n===> golden files tests "
Nick Terrellabe12b32017-07-28 11:54:28 -0700477
478$ZSTD -t -r files
479$ZSTD -c -r files | $ZSTD -t
480
481
Yann Collet241c57a2017-10-16 14:01:42 -0700482$ECHO "\n===> benchmark mode tests "
Yann Colletb9550d62016-10-28 14:43:24 -0700483
484$ECHO "bench one file"
485./datagen > tmp1
Yann Colletc1c040e2017-03-01 16:49:20 -0800486$ZSTD -bi0 tmp1
Yann Colletb9550d62016-10-28 14:43:24 -0700487$ECHO "bench multiple levels"
Yann Colletc1c040e2017-03-01 16:49:20 -0800488$ZSTD -i0b0e3 tmp1
Yann Collet6a9b41b2018-03-11 19:56:48 -0700489$ECHO "bench negative level"
490$ZSTD -bi0 --fast tmp1
Yann Colletb9550d62016-10-28 14:43:24 -0700491$ECHO "with recursive and quiet modes"
Yann Colletc1c040e2017-03-01 16:49:20 -0800492$ZSTD -rqi1b1e2 tmp1
493
George Lucfc34512018-06-01 09:52:25 -0700494$ECHO "\n===> zstd compatibility tests "
495
496./datagen > tmp
George Lu41249bf2018-06-01 10:54:51 -0700497rm -f tmp.zst
498$ZSTD --format=zstd -f tmp
499test -f tmp.zst
Yann Colletc1c040e2017-03-01 16:49:20 -0800500
Yann Collet241c57a2017-10-16 14:01:42 -0700501$ECHO "\n===> gzip compatibility tests "
Yann Colletc1c040e2017-03-01 16:49:20 -0800502
503GZIPMODE=1
504$ZSTD --format=gzip -V || GZIPMODE=0
505if [ $GZIPMODE -eq 1 ]; then
Yann Collet27526c72017-03-01 17:02:49 -0800506 $ECHO "gzip support detected"
Yann Colletc1c040e2017-03-01 16:49:20 -0800507 GZIPEXE=1
Yann Collet27526c72017-03-01 17:02:49 -0800508 gzip -V || GZIPEXE=0
Yann Colletc1c040e2017-03-01 16:49:20 -0800509 if [ $GZIPEXE -eq 1 ]; then
510 ./datagen > tmp
511 $ZSTD --format=gzip -f tmp
512 gzip -t -v tmp.gz
513 gzip -f tmp
514 $ZSTD -d -f -v tmp.gz
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700515 rm tmp*
Yann Colletc1c040e2017-03-01 16:49:20 -0800516 else
517 $ECHO "gzip binary not detected"
518 fi
519else
520 $ECHO "gzip mode not supported"
521fi
Yann Colletb9550d62016-10-28 14:43:24 -0700522
523
Yann Collet241c57a2017-10-16 14:01:42 -0700524$ECHO "\n===> gzip frame tests "
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700525
526if [ $GZIPMODE -eq 1 ]; then
527 ./datagen > tmp
528 $ZSTD -f --format=gzip tmp
529 $ZSTD -f tmp
530 cat tmp.gz tmp.zst tmp.gz tmp.zst | $ZSTD -d -f -o tmp
Sean Purcell4de86322017-04-24 16:48:25 -0700531 head -c -1 tmp.gz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700532 rm tmp*
533else
534 $ECHO "gzip mode not supported"
535fi
536
George Lu41249bf2018-06-01 10:54:51 -0700537if [ $GZIPMODE -eq 1 ]; then
538 ./datagen > tmp
539 rm -f tmp.zst
Jennifer Liuaef84862018-06-27 14:27:27 -0700540 $ZSTD --format=gzip --format=zstd -f tmp
George Lu41249bf2018-06-01 10:54:51 -0700541 test -f tmp.zst
542fi
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700543
Yann Collet241c57a2017-10-16 14:01:42 -0700544$ECHO "\n===> xz compatibility tests "
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700545
546LZMAMODE=1
547$ZSTD --format=xz -V || LZMAMODE=0
548if [ $LZMAMODE -eq 1 ]; then
549 $ECHO "xz support detected"
550 XZEXE=1
Björn Ketelaars527dbf82018-06-30 13:22:14 +0200551 xz -Q -V && lzma -Q -V || XZEXE=0
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700552 if [ $XZEXE -eq 1 ]; then
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700553 $ECHO "Testing zstd xz and lzma support"
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700554 ./datagen > tmp
555 $ZSTD --format=lzma -f tmp
556 $ZSTD --format=xz -f tmp
Björn Ketelaars527dbf82018-06-30 13:22:14 +0200557 xz -Q -t -v tmp.xz
558 xz -Q -t -v tmp.lzma
559 xz -Q -f -k tmp
560 lzma -Q -f -k --lzma1 tmp
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700561 $ZSTD -d -f -v tmp.xz
562 $ZSTD -d -f -v tmp.lzma
563 rm tmp*
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700564 $ECHO "Creating symlinks"
565 ln -s $ZSTD ./xz
566 ln -s $ZSTD ./unxz
567 ln -s $ZSTD ./lzma
568 ln -s $ZSTD ./unlzma
569 $ECHO "Testing xz and lzma symlinks"
570 ./datagen > tmp
571 ./xz tmp
Björn Ketelaars527dbf82018-06-30 13:22:14 +0200572 xz -Q -d tmp.xz
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700573 ./lzma tmp
Björn Ketelaars527dbf82018-06-30 13:22:14 +0200574 lzma -Q -d tmp.lzma
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700575 $ECHO "Testing unxz and unlzma symlinks"
Björn Ketelaars527dbf82018-06-30 13:22:14 +0200576 xz -Q tmp
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700577 ./xz -d tmp.xz
Björn Ketelaars527dbf82018-06-30 13:22:14 +0200578 lzma -Q tmp
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700579 ./lzma -d tmp.lzma
580 rm xz unxz lzma unlzma
581 rm tmp*
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700582 else
583 $ECHO "xz binary not detected"
584 fi
585else
586 $ECHO "xz mode not supported"
587fi
588
589
Yann Collet241c57a2017-10-16 14:01:42 -0700590$ECHO "\n===> xz frame tests "
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700591
592if [ $LZMAMODE -eq 1 ]; then
593 ./datagen > tmp
594 $ZSTD -f --format=xz tmp
595 $ZSTD -f --format=lzma tmp
596 $ZSTD -f tmp
597 cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | $ZSTD -d -f -o tmp
Sean Purcell4de86322017-04-24 16:48:25 -0700598 head -c -1 tmp.xz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
599 head -c -1 tmp.lzma | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700600 rm tmp*
601else
602 $ECHO "xz mode not supported"
603fi
604
Yann Collet241c57a2017-10-16 14:01:42 -0700605$ECHO "\n===> lz4 compatibility tests "
Sean Purcell4de86322017-04-24 16:48:25 -0700606
607LZ4MODE=1
608$ZSTD --format=lz4 -V || LZ4MODE=0
609if [ $LZ4MODE -eq 1 ]; then
610 $ECHO "lz4 support detected"
611 LZ4EXE=1
612 lz4 -V || LZ4EXE=0
613 if [ $LZ4EXE -eq 1 ]; then
614 ./datagen > tmp
615 $ZSTD --format=lz4 -f tmp
616 lz4 -t -v tmp.lz4
617 lz4 -f tmp
618 $ZSTD -d -f -v tmp.lz4
619 rm tmp*
620 else
621 $ECHO "lz4 binary not detected"
622 fi
623else
624 $ECHO "lz4 mode not supported"
625fi
626
627
Yann Collet241c57a2017-10-16 14:01:42 -0700628$ECHO "\n===> lz4 frame tests "
Sean Purcell4de86322017-04-24 16:48:25 -0700629
630if [ $LZ4MODE -eq 1 ]; then
631 ./datagen > tmp
632 $ZSTD -f --format=lz4 tmp
633 $ZSTD -f tmp
634 cat tmp.lz4 tmp.zst tmp.lz4 tmp.zst | $ZSTD -d -f -o tmp
635 head -c -1 tmp.lz4 | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
636 rm tmp*
637else
638 $ECHO "lz4 mode not supported"
639fi
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700640
George Lu53ea32c2018-06-01 10:43:06 -0700641$ECHO "\n===> suffix list test"
642
George Lu110ec902018-06-01 12:45:02 -0700643! $ZSTD -d tmp.abc 2> tmplg
George Lu53ea32c2018-06-01 10:43:06 -0700644
Jennifer Liuaef84862018-06-27 14:27:27 -0700645if [ $GZIPMODE -ne 1 ]; then
George Lu53ea32c2018-06-01 10:43:06 -0700646 grep ".gz" tmplg > $INTOVOID && die "Unsupported suffix listed"
647fi
648
Jennifer Liuaef84862018-06-27 14:27:27 -0700649if [ $LZMAMODE -ne 1 ]; then
George Lu53ea32c2018-06-01 10:43:06 -0700650 grep ".lzma" tmplg > $INTOVOID && die "Unsupported suffix listed"
651 grep ".xz" tmplg > $INTOVOID && die "Unsupported suffix listed"
652fi
653
654if [ $LZ4MODE -ne 1 ]; then
655 grep ".lz4" tmplg > $INTOVOID && die "Unsupported suffix listed"
656fi
657
Yann Collet241c57a2017-10-16 14:01:42 -0700658$ECHO "\n===> zstd round-trip tests "
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300659
660roundTripTest
Yann Collet3b719252016-03-30 19:48:05 +0200661roundTripTest -g15K # TableID==3
662roundTripTest -g127K # TableID==2
663roundTripTest -g255K # TableID==1
Yann Colletc1c040e2017-03-01 16:49:20 -0800664roundTripTest -g522K # TableID==0
665roundTripTest -g519K 6 # greedy, hash chain
666roundTripTest -g517K 16 # btlazy2
667roundTripTest -g516K 19 # btopt
Yann Collet459a6b72016-02-15 20:37:23 +0100668
Sean Purcelleb70d212017-04-11 17:15:13 -0700669fileRoundTripTest -g500K
670
Yann Collet241c57a2017-10-16 14:01:42 -0700671$ECHO "\n===> zstd long distance matching round-trip tests "
Nick Terrellf15a17e2018-02-27 20:09:18 -0800672roundTripTest -g0 "2 --single-thread --long"
673roundTripTest -g1000K "1 --single-thread --long"
674roundTripTest -g517K "6 --single-thread --long"
675roundTripTest -g516K "16 --single-thread --long"
676roundTripTest -g518K "19 --single-thread --long"
677fileRoundTripTest -g5M "3 --single-thread --long"
Stella Lau6a546ef2017-07-28 15:51:33 -0700678
679
Yann Collet75689832018-02-09 15:53:27 -0800680roundTripTest -g96K "5 --single-thread"
Sean Purcellc424ec22017-04-17 11:38:53 -0700681if [ -n "$hasMT" ]
682then
Yann Collet241c57a2017-10-16 14:01:42 -0700683 $ECHO "\n===> zstdmt round-trip tests "
Sean Purcelld845dab2017-04-17 12:10:58 -0700684 roundTripTest -g4M "1 -T0"
685 roundTripTest -g8M "3 -T2"
Yann Collet230d7ac2017-04-21 11:38:13 -0700686 roundTripTest -g8000K "2 --threads=2"
Sean Purcelld845dab2017-04-17 12:10:58 -0700687 fileRoundTripTest -g4M "19 -T2 -B1M"
Stella Lau6a546ef2017-07-28 15:51:33 -0700688
Yann Collet241c57a2017-10-16 14:01:42 -0700689 $ECHO "\n===> zstdmt long distance matching round-trip tests "
Nick Terrellf15a17e2018-02-27 20:09:18 -0800690 roundTripTest -g8M "3 --long=24 -T2"
Yann Collet96b480a2018-03-29 13:07:28 -0600691
692 $ECHO "\n===> ovLog tests "
693 ./datagen -g2MB > tmp
694 refSize=$($ZSTD tmp -6 -c --zstd=wlog=18 | wc -c)
695 ov9Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=9 | wc -c)
696 ov0Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=0 | wc -c)
697 if [ $refSize -eq $ov9Size ]; then
698 echo ov9Size should be different from refSize
699 exit 1
700 fi
701 if [ $refSize -eq $ov0Size ]; then
702 echo ov0Size should be different from refSize
703 exit 1
704 fi
705 if [ $ov9Size -ge $ov0Size ]; then
706 echo ov9Size=$ov9Size should be smaller than ov0Size=$ov0Size
707 exit 1
708 fi
709
Sean Purcellc424ec22017-04-17 11:38:53 -0700710else
Yann Collet241c57a2017-10-16 14:01:42 -0700711 $ECHO "\n===> no multithreading, skipping zstdmt tests "
Sean Purcellc424ec22017-04-17 11:38:53 -0700712fi
713
Yann Collet459a6b72016-02-15 20:37:23 +0100714rm tmp*
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300715
Yann Collet241c57a2017-10-16 14:01:42 -0700716$ECHO "\n===> zstd --list/-l single frame tests "
Paul Cruzddd1ab72017-06-15 16:53:03 -0700717./datagen > tmp1
718./datagen > tmp2
719./datagen > tmp3
Paul Cruzddd1ab72017-06-15 16:53:03 -0700720$ZSTD tmp*
Paul Cruz6a99de22017-06-20 10:45:06 -0700721$ZSTD -l *.zst
Yann Collet43914f62017-10-13 23:47:01 -0700722$ZSTD -lv *.zst | grep "Decompressed Size:" # check that decompressed size is present in header
Paul Cruz6a99de22017-06-20 10:45:06 -0700723$ZSTD --list *.zst
724$ZSTD --list -v *.zst
Paul Cruzddd1ab72017-06-15 16:53:03 -0700725
Yann Collet241c57a2017-10-16 14:01:42 -0700726$ECHO "\n===> zstd --list/-l multiple frame tests "
Paul Cruzddd1ab72017-06-15 16:53:03 -0700727cat tmp1.zst tmp2.zst > tmp12.zst
Yann Collet60059df2017-09-27 15:16:27 -0700728cat tmp12.zst tmp3.zst > tmp123.zst
Paul Cruz6a99de22017-06-20 10:45:06 -0700729$ZSTD -l *.zst
730$ZSTD -lv *.zst
Paul Cruzddd1ab72017-06-15 16:53:03 -0700731
Yann Collet241c57a2017-10-16 14:01:42 -0700732$ECHO "\n===> zstd --list/-l error detection tests "
Paul Cruz58c19b42017-06-20 14:14:53 -0700733! $ZSTD -l tmp1 tmp1.zst
734! $ZSTD --list tmp*
735! $ZSTD -lv tmp1*
Yann Collet60059df2017-09-27 15:16:27 -0700736! $ZSTD --list -v tmp2 tmp12.zst
Paul Cruzb07d0af2017-06-20 11:54:44 -0700737
W. Felix Handte8e7bdc12018-06-29 16:31:22 -0400738$ECHO "\n===> zstd --list/-l errors when presented with stdin / no files"
739! $ZSTD -l
740! $ZSTD -l -
741! $ZSTD -l < tmp1.zst
742! $ZSTD -l - < tmp1.zst
743! $ZSTD -l - tmp1.zst
744! $ZSTD -l - tmp1.zst < tmp1.zst
745$ZSTD -l tmp1.zst < tmp1.zst # but doesn't error just because stdin is not a tty
Topher Lubaway5bac1db2018-06-19 09:56:37 -0700746
Yann Collet241c57a2017-10-16 14:01:42 -0700747$ECHO "\n===> zstd --list/-l test with null files "
Paul Cruza73c2a42017-06-20 14:33:08 -0700748./datagen -g0 > tmp5
749$ZSTD tmp5
Yann Colletc16748b2017-06-21 12:09:53 -0700750$ZSTD -l tmp5.zst
Paul Cruza73c2a42017-06-20 14:33:08 -0700751! $ZSTD -l tmp5*
Yann Collet5891f1d2017-10-17 16:23:20 -0700752$ZSTD -lv tmp5.zst | grep "Decompressed Size: 0.00 KB (0 B)" # check that 0 size is present in header
Paul Cruza73c2a42017-06-20 14:33:08 -0700753! $ZSTD -lv tmp5*
Paul Cruza73c2a42017-06-20 14:33:08 -0700754
Yann Collet241c57a2017-10-16 14:01:42 -0700755$ECHO "\n===> zstd --list/-l test with no content size field "
Yann Collet43914f62017-10-13 23:47:01 -0700756./datagen -g513K | $ZSTD > tmp6.zst
Paul Cruzdb3606e2017-06-20 17:43:36 -0700757$ZSTD -l tmp6.zst
Yann Collet43914f62017-10-13 23:47:01 -0700758! $ZSTD -lv tmp6.zst | grep "Decompressed Size:" # must NOT be present in header
Yann Colletc16748b2017-06-21 12:09:53 -0700759
Yann Collet241c57a2017-10-16 14:01:42 -0700760$ECHO "\n===> zstd --list/-l test with no checksum "
Yann Colletc16748b2017-06-21 12:09:53 -0700761$ZSTD -f --no-check tmp1
762$ZSTD -l tmp1.zst
763$ZSTD -lv tmp1.zst
Paul Cruzdb3606e2017-06-20 17:43:36 -0700764
Paul Cruzddd1ab72017-06-15 16:53:03 -0700765rm tmp*
766
Yann Colletc16748b2017-06-21 12:09:53 -0700767
Yann Collet241c57a2017-10-16 14:01:42 -0700768$ECHO "\n===> zstd long distance matching tests "
Nick Terrellf15a17e2018-02-27 20:09:18 -0800769roundTripTest -g0 " --single-thread --long"
770roundTripTest -g9M "2 --single-thread --long"
Yann Collet02502192017-09-27 15:48:06 -0700771# Test parameter parsing
Nick Terrellf15a17e2018-02-27 20:09:18 -0800772roundTripTest -g1M -P50 "1 --single-thread --long=29" " --memory=512MB"
773roundTripTest -g1M -P50 "1 --single-thread --long=29 --zstd=wlog=28" " --memory=256MB"
774roundTripTest -g1M -P50 "1 --single-thread --long=29" " --long=28 --memory=512MB"
775roundTripTest -g1M -P50 "1 --single-thread --long=29" " --zstd=wlog=28 --memory=512MB"
Yann Collet02502192017-09-27 15:48:06 -0700776
777
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300778if [ "$1" != "--test-large-data" ]; then
inikep5d589562016-05-25 10:50:28 +0200779 $ECHO "Skipping large data tests"
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300780 exit 0
781fi
782
Yann Collet241c57a2017-10-16 14:01:42 -0700783$ECHO "\n===> large files tests "
Yann Collet02502192017-09-27 15:48:06 -0700784
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300785roundTripTest -g270000000 1
Yann Collet60059df2017-09-27 15:16:27 -0700786roundTripTest -g250000000 2
787roundTripTest -g230000000 3
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300788
789roundTripTest -g140000000 -P60 4
Yann Collet60059df2017-09-27 15:16:27 -0700790roundTripTest -g130000000 -P62 5
791roundTripTest -g120000000 -P65 6
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300792
793roundTripTest -g70000000 -P70 7
Yann Collet60059df2017-09-27 15:16:27 -0700794roundTripTest -g60000000 -P71 8
795roundTripTest -g50000000 -P73 9
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300796
797roundTripTest -g35000000 -P75 10
Yann Collet60059df2017-09-27 15:16:27 -0700798roundTripTest -g30000000 -P76 11
799roundTripTest -g25000000 -P78 12
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300800
Yann Collet4616fad2017-07-10 17:16:41 -0700801roundTripTest -g18000013 -P80 13
802roundTripTest -g18000014 -P80 14
Yann Collet60059df2017-09-27 15:16:27 -0700803roundTripTest -g18000015 -P81 15
804roundTripTest -g18000016 -P84 16
805roundTripTest -g18000017 -P88 17
Yann Collet4616fad2017-07-10 17:16:41 -0700806roundTripTest -g18000018 -P94 18
Yann Collet60059df2017-09-27 15:16:27 -0700807roundTripTest -g18000019 -P96 19
Konstantin Tokarev2b465842015-12-08 19:36:42 +0300808
Yann Collet60059df2017-09-27 15:16:27 -0700809roundTripTest -g5000000000 -P99 1
Yann Collet4c7f1372017-12-29 17:40:36 +0100810roundTripTest -g1700000000 -P0 "1 --zstd=strategy=6" # ensure btlazy2 can survive an overflow rescale
Yann Collet459a6b72016-02-15 20:37:23 +0100811
Sean Purcelleb70d212017-04-11 17:15:13 -0700812fileRoundTripTest -g4193M -P99 1
813
Yann Collet02502192017-09-27 15:48:06 -0700814
Yann Collet241c57a2017-10-16 14:01:42 -0700815$ECHO "\n===> zstd long, long distance matching round-trip tests "
Nick Terrellf15a17e2018-02-27 20:09:18 -0800816roundTripTest -g270000000 "1 --single-thread --long"
817roundTripTest -g130000000 -P60 "5 --single-thread --long"
818roundTripTest -g35000000 -P70 "8 --single-thread --long"
819roundTripTest -g18000001 -P80 "18 --single-thread --long"
Nick Terrellc233bdb2017-09-22 14:04:39 -0700820# Test large window logs
Nick Terrellf15a17e2018-02-27 20:09:18 -0800821roundTripTest -g700M -P50 "1 --single-thread --long=29"
822roundTripTest -g600M -P50 "1 --single-thread --long --zstd=wlog=29,clog=28"
Stella Lau6a546ef2017-07-28 15:51:33 -0700823
824
Sean Purcellc424ec22017-04-17 11:38:53 -0700825if [ -n "$hasMT" ]
826then
Yann Collet241c57a2017-10-16 14:01:42 -0700827 $ECHO "\n===> zstdmt long round-trip tests "
Yann Collet60059df2017-09-27 15:16:27 -0700828 roundTripTest -g80000000 -P99 "19 -T2" " "
829 roundTripTest -g5000000000 -P99 "1 -T2" " "
830 roundTripTest -g500000000 -P97 "1 -T999" " "
831 fileRoundTripTest -g4103M -P98 " -T0" " "
832 roundTripTest -g400000000 -P97 "1 --long=24 -T2" " "
Sean Purcellc424ec22017-04-17 11:38:53 -0700833else
834 $ECHO "\n**** no multithreading, skipping zstdmt tests **** "
835fi
836
Yann Collet459a6b72016-02-15 20:37:23 +0100837rm tmp*