blob: e2dbccbf578d01c079707d27ad425715dec9ec48 [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
Sean Purcell9a38dfa2017-03-17 12:32:18 -070051isTerminal=false
52if [ -t 0 ] && [ -t 1 ]
53then
54 isTerminal=true
55fi
56
inikep5d589562016-05-25 10:50:28 +020057isWindows=false
Yann Collet391a1282016-06-21 17:06:25 +020058INTOVOID="/dev/null"
Nick Terrell2dde9d52018-05-08 11:06:01 -070059DEVDEVICE="/dev/random"
inikep993a9df2016-05-27 10:07:46 +020060case "$OS" in
Yann Collet673f0d72016-06-06 00:26:38 +020061 Windows*)
inikep5d589562016-05-25 10:50:28 +020062 isWindows=true
Sean Purcell9a38dfa2017-03-17 12:32:18 -070063 INTOVOID="NUL"
Nick Terrell82bc8fe2017-12-13 12:04:46 -080064 DEVDEVICE="NUL"
inikep993a9df2016-05-27 10:07:46 +020065 ;;
66esac
inikep5d589562016-05-25 10:50:28 +020067
Dimitry Andric12df6da2016-12-12 19:22:47 +010068UNAME=$(uname)
69case "$UNAME" in
70 Darwin) MD5SUM="md5 -r" ;;
71 FreeBSD) MD5SUM="gmd5sum" ;;
bketdaf3ab02018-04-02 23:12:18 +020072 OpenBSD) MD5SUM="md5" ;;
Yann Collet94d1a932016-12-06 12:02:56 -080073 *) MD5SUM="md5sum" ;;
74esac
inikep5d589562016-05-25 10:50:28 +020075
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +010076DIFF="diff"
77case "$UNAME" in
78 SunOS) DIFF="gdiff" ;;
79esac
80
Yann Collet62568c92017-09-25 14:26:26 -070081ECHO="echo -e"
82case "$UNAME" in
83 Darwin) ECHO="echo" ;;
84esac
85
Przemyslaw Skibinskie579ab52016-11-14 12:57:05 +010086$ECHO "\nStarting playTests.sh isWindows=$isWindows ZSTD='$ZSTD'"
inikep5d589562016-05-25 10:50:28 +020087
Konstantin Tokarev76be3782015-12-08 18:36:37 +030088[ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
89
Sean Purcellc424ec22017-04-17 11:38:53 -070090if [ -n "$(echo hello | $ZSTD -v -T2 2>&1 > $INTOVOID | grep 'multi-threading is disabled')" ]
91then
92 hasMT=""
93else
94 hasMT="true"
95fi
96
Yann Colleta927fae2018-01-06 12:31:26 +010097
Yann Collet241c57a2017-10-16 14:01:42 -070098$ECHO "\n===> simple tests "
Yann Colletde95f962016-05-23 19:46:47 +020099
Yann Collet8154c3d2016-02-13 03:12:10 +0100100./datagen > tmp
Yann Colletb3060f72016-09-09 16:44:16 +0200101$ECHO "test : basic compression "
Yann Collet673f0d72016-06-06 00:26:38 +0200102$ZSTD -f tmp # trivial compression case, creates tmp.zst
Yann Colletb3060f72016-09-09 16:44:16 +0200103$ECHO "test : basic decompression"
Yann Collet673f0d72016-06-06 00:26:38 +0200104$ZSTD -df tmp.zst # trivial decompression case (overwrites tmp)
Yann Collet6a9b41b2018-03-11 19:56:48 -0700105$ECHO "test : too large compression level => auto-fix"
Yann Colletfab02302016-08-12 19:00:18 +0200106$ZSTD -99 -f tmp # too large compression level, automatic sized down
Yann Collet6a9b41b2018-03-11 19:56:48 -0700107$ECHO "test : --fast aka negative compression levels"
108$ZSTD --fast -f tmp # == -1
109$ZSTD --fast=3 -f tmp # == -3
Yann Collet93b82622018-03-21 15:54:44 -0700110$ZSTD --fast=200000 -f tmp # == no compression
Yann Collet9cd5c632018-05-12 14:29:33 -0700111$ECHO "test : too large numeric argument"
112$ZSTD --fast=9999999999 -f tmp && die "should have refused numeric value"
inikep5d589562016-05-25 10:50:28 +0200113$ECHO "test : compress to stdout"
Yann Collet0d348d42016-05-29 02:02:24 +0200114$ZSTD tmp -c > tmpCompressed
Yann Colletd6931172016-05-10 05:56:09 +0200115$ZSTD tmp --stdout > tmpCompressed # long command format
Yann Collet27b5ac62016-09-21 14:20:56 +0200116$ECHO "test : compress to named file"
117rm tmpCompressed
118$ZSTD tmp -o tmpCompressed
Yann Collet01a1abf2017-05-05 19:15:24 -0700119test -f tmpCompressed # file must be created
Yann Collet27b5ac62016-09-21 14:20:56 +0200120$ECHO "test : -o must be followed by filename (must fail)"
Yann Collet714464f2016-09-21 16:05:03 +0200121$ZSTD tmp -of tmpCompressed && die "-o must be followed by filename "
Yann Collet27b5ac62016-09-21 14:20:56 +0200122$ECHO "test : force write, correct order"
123$ZSTD tmp -fo tmpCompressed
Yann Collet714464f2016-09-21 16:05:03 +0200124$ECHO "test : forgotten argument"
125cp tmp tmp2
126$ZSTD tmp2 -fo && die "-o must be followed by filename "
Yann Colletc8431422016-09-01 15:05:57 -0700127$ECHO "test : implied stdout when input is stdin"
128$ECHO bob | $ZSTD | $ZSTD -d
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700129if [ "$isTerminal" = true ]; then
Sean Purcelld9730712017-03-16 16:25:19 -0700130$ECHO "test : compressed data to terminal"
131$ECHO bob | $ZSTD && die "should have refused : compressed data to terminal"
132$ECHO "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)"
133$ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal"
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700134fi
inikep5d589562016-05-25 10:50:28 +0200135$ECHO "test : null-length file roundtrip"
136$ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
Yann Collet281f06e2017-12-14 11:47:02 -0800137$ECHO "test : ensure small file doesn't add 3-bytes null block"
Yann Colleta0e09852017-12-14 13:32:24 -0800138./datagen -g1 > tmp1
139$ZSTD tmp1 -c | wc -c | grep "14"
140$ZSTD < tmp1 | wc -c | grep "14"
inikep5d589562016-05-25 10:50:28 +0200141$ECHO "test : decompress file with wrong suffix (must fail)"
Yann Collet2d08b092016-02-16 14:42:08 +0100142$ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
Yann Collet391a1282016-06-21 17:06:25 +0200143$ZSTD -df tmp && die "should have refused : wrong extension"
144$ECHO "test : decompress into stdout"
Yann Collet0d348d42016-05-29 02:02:24 +0200145$ZSTD -d tmpCompressed -c > tmpResult # decompression using stdout
Yann Collet2d08b092016-02-16 14:42:08 +0100146$ZSTD --decompress tmpCompressed -c > tmpResult
147$ZSTD --decompress tmpCompressed --stdout > tmpResult
Yann Collet391a1282016-06-21 17:06:25 +0200148$ECHO "test : decompress from stdin into stdout"
149$ZSTD -dc < tmp.zst > $INTOVOID # combine decompression, stdin & stdout
150$ZSTD -dc - < tmp.zst > $INTOVOID
151$ZSTD -d < tmp.zst > $INTOVOID # implicit stdout when stdin is used
152$ZSTD -d - < tmp.zst > $INTOVOID
Yann Colletd4cda272016-10-14 13:13:13 -0700153$ECHO "test : impose memory limitation (must fail)"
154$ZSTD -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
Yann Collet11223492016-10-14 14:07:11 -0700155$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 -0700156$ZSTD -d -f tmp.zst --memory=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
157$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 +0200158$ECHO "test : overwrite protection"
Yann Collet2d08b092016-02-16 14:42:08 +0100159$ZSTD -q tmp && die "overwrite check failed!"
Yann Collet391a1282016-06-21 17:06:25 +0200160$ECHO "test : force overwrite"
Yann Collet2d08b092016-02-16 14:42:08 +0100161$ZSTD -q -f tmp
162$ZSTD -q --force tmp
Sean Purcell9da11c62017-04-06 12:58:49 -0700163$ECHO "test : overwrite readonly file"
Sean Purcell16521722017-04-06 17:06:30 -0700164rm -f tmpro tmpro.zst
Sean Purcell9da11c62017-04-06 12:58:49 -0700165$ECHO foo > tmpro.zst
166$ECHO foo > tmpro
167chmod 400 tmpro.zst
Sean Purcell16521722017-04-06 17:06:30 -0700168$ZSTD -q tmpro && die "should have refused to overwrite read-only file"
169$ZSTD -q -f tmpro
170rm -f tmpro tmpro.zst
Yann Colletb09b12c2016-06-09 22:59:51 +0200171$ECHO "test : file removal"
172$ZSTD -f --rm tmp
Yann Collet01a1abf2017-05-05 19:15:24 -0700173test ! -f tmp # tmp should no longer be present
Yann Colletb09b12c2016-06-09 22:59:51 +0200174$ZSTD -f -d --rm tmp.zst
Yann Collet01a1abf2017-05-05 19:15:24 -0700175test ! -f tmp.zst # tmp.zst should no longer be present
Nick Terrell82bc8fe2017-12-13 12:04:46 -0800176$ECHO "test : should quietly not remove non-regular file"
177$ECHO hello > tmp
178$ZSTD tmp -f -o "$DEVDEVICE" 2>tmplog > "$INTOVOID"
179grep -v "Refusing to remove non-regular file" tmplog
180rm -f tmplog
Nick Terrell263134c2018-05-03 13:03:08 -0700181$ZSTD tmp -f -o "$INTOVOID" 2>&1 | grep -v "Refusing to remove non-regular file"
Yann Collet67d86a72017-02-27 16:09:20 -0800182$ECHO "test : --rm on stdin"
183$ECHO a | $ZSTD --rm > $INTOVOID # --rm should remain silent
Yann Colletb09b12c2016-06-09 22:59:51 +0200184rm tmp
185$ZSTD -f tmp && die "tmp not present : should have failed"
Yann Collet01a1abf2017-05-05 19:15:24 -0700186test ! -f tmp.zst # tmp.zst should not be created
Yann Colletde95f962016-05-23 19:46:47 +0200187
Nick Terrell4680e852017-12-12 18:32:50 -0800188$ECHO "test : compress multiple files"
189$ECHO hello > tmp1
190$ECHO world > tmp2
191$ZSTD tmp1 tmp2 -o "$INTOVOID"
192$ZSTD tmp1 tmp2 -c | $ZSTD -t
193$ZSTD tmp1 tmp2 -o tmp.zst
194test ! -f tmp1.zst
195test ! -f tmp2.zst
196$ZSTD tmp1 tmp2
197$ZSTD -t tmp1.zst tmp2.zst
198$ZSTD -dc tmp1.zst tmp2.zst
199$ZSTD tmp1.zst tmp2.zst -o "$INTOVOID"
200$ZSTD -d tmp1.zst tmp2.zst -o tmp
Nick Terrell8adebbd2018-01-03 14:02:44 -0800201touch tmpexists
202$ZSTD tmp1 tmp2 -f -o tmpexists
203$ZSTD tmp1 tmp2 -o tmpexists && die "should have refused to overwrite"
204# Bug: PR #972
205if [ "$?" -eq 139 ]; then
206 die "should not have segfaulted"
207fi
Nick Terrell4680e852017-12-12 18:32:50 -0800208rm tmp*
209
210
Yann Collet241c57a2017-10-16 14:01:42 -0700211$ECHO "\n===> Advanced compression parameters "
Przemyslaw Skibinski24a42362016-12-14 18:07:31 +0100212$ECHO "Hello world!" | $ZSTD --zstd=windowLog=21, - -o tmp.zst && die "wrong parameters not detected!"
213$ECHO "Hello world!" | $ZSTD --zstd=windowLo=21 - -o tmp.zst && die "wrong parameters not detected!"
Przemyslaw Skibinskif9a56662016-12-14 18:43:06 +0100214$ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,slog - -o tmp.zst && die "wrong parameters not detected!"
Yann Collet01a1abf2017-05-05 19:15:24 -0700215test ! -f tmp.zst # tmp.zst should not be created
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100216roundTripTest -g512K
Przemyslaw Skibinskiab5ed6f2016-12-14 17:10:38 +0100217roundTripTest -g512K " --zstd=slen=3,tlen=48,strat=6"
218roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100219roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,searchLength=3,targetLength=48,strategy=6"
Nick Terrellf15a17e2018-02-27 20:09:18 -0800220roundTripTest -g512K " --single-thread --long --zstd=ldmHashLog=20,ldmSearchLength=64,ldmBucketSizeLog=1,ldmHashEveryLog=7"
221roundTripTest -g512K " --single-thread --long --zstd=ldmhlog=20,ldmslen=64,ldmblog=1,ldmhevery=7"
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100222roundTripTest -g512K 19
223
224
Yann Collet241c57a2017-10-16 14:01:42 -0700225$ECHO "\n===> Pass-Through mode "
Yann Collet743b33f2016-12-02 15:18:57 -0800226$ECHO "Hello world 1!" | $ZSTD -df
227$ECHO "Hello world 2!" | $ZSTD -dcf
228$ECHO "Hello world 3!" > tmp1
229$ZSTD -dcf tmp1
Yann Colletde95f962016-05-23 19:46:47 +0200230
Yann Collet8154c3d2016-02-13 03:12:10 +0100231
Yann Collet241c57a2017-10-16 14:01:42 -0700232$ECHO "\n===> frame concatenation "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300233
inikep5d589562016-05-25 10:50:28 +0200234$ECHO "hello " > hello.tmp
235$ECHO "world!" > world.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300236cat hello.tmp world.tmp > helloworld.tmp
Yann Colletc8da2c92016-02-12 02:56:27 +0100237$ZSTD -c hello.tmp > hello.zstd
238$ZSTD -c world.tmp > world.zstd
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300239cat hello.zstd world.zstd > helloworld.zstd
Yann Colletc8da2c92016-02-12 02:56:27 +0100240$ZSTD -dc helloworld.zstd > result.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300241cat result.tmp
Yann Colletbd6bc222017-01-22 15:54:14 -0800242$DIFF helloworld.tmp result.tmp
Yann Collet4c5bbf62016-07-28 20:30:25 +0200243$ECHO "frame concatenation without checksum"
244$ZSTD -c hello.tmp > hello.zstd --no-check
245$ZSTD -c world.tmp > world.zstd --no-check
246cat hello.zstd world.zstd > helloworld.zstd
247$ZSTD -dc helloworld.zstd > result.tmp
Yann Colletbd6bc222017-01-22 15:54:14 -0800248$DIFF helloworld.tmp result.tmp
Yann Colletcb5eba82018-01-19 11:26:35 -0800249$ECHO "testing zstdcat symlink"
250ln -sf $ZSTD zstdcat
251./zstdcat helloworld.zstd > result.tmp
252$DIFF helloworld.tmp result.tmp
253rm zstdcat
254rm result.tmp
255$ECHO "testing zcat symlink"
256ln -sf $ZSTD zcat
257./zcat helloworld.zstd > result.tmp
258$DIFF helloworld.tmp result.tmp
259rm zcat
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300260rm ./*.tmp ./*.zstd
inikep5d589562016-05-25 10:50:28 +0200261$ECHO "frame concatenation tests completed"
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300262
Yann Colletf0624362016-02-12 15:56:46 +0100263
bketdaf3ab02018-04-02 23:12:18 +0200264if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] && [ "$UNAME" != "OpenBSD" ] ; then
inikep5d589562016-05-25 10:50:28 +0200265$ECHO "\n**** flush write error test **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300266
inikep5d589562016-05-25 10:50:28 +0200267$ECHO "$ECHO foo | $ZSTD > /dev/full"
268$ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
269$ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
270$ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
Sean Purcell680e4e02017-03-23 11:52:09 -0700271
Yann Collet01a1abf2017-05-05 19:15:24 -0700272
Yann Collet241c57a2017-10-16 14:01:42 -0700273$ECHO "\n===> symbolic link test "
Sean Purcell680e4e02017-03-23 11:52:09 -0700274
275rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
276$ECHO "hello world" > hello.tmp
277ln -s hello.tmp world.tmp
278$ZSTD world.tmp hello.tmp
Yann Collet01a1abf2017-05-05 19:15:24 -0700279test -f hello.tmp.zst # regular file should have been compressed!
280test ! -f world.tmp.zst # symbolic link should not have been compressed!
Sean Purcell680e4e02017-03-23 11:52:09 -0700281$ZSTD world.tmp hello.tmp -f
Yann Collet01a1abf2017-05-05 19:15:24 -0700282test -f world.tmp.zst # symbolic link should have been compressed with --force
Sean Purcell680e4e02017-03-23 11:52:09 -0700283rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
284
inikep5d589562016-05-25 10:50:28 +0200285fi
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300286
Yann Collet6a458352015-12-18 02:51:14 +0100287
Yann Collet241c57a2017-10-16 14:01:42 -0700288$ECHO "\n===> test sparse file support "
Yann Collet32990b52016-05-23 17:48:57 +0200289
290./datagen -g5M -P100 > tmpSparse
291$ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100292$DIFF -s tmpSparse tmpSparseRegen
Yann Collet32990b52016-05-23 17:48:57 +0200293$ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100294$DIFF -s tmpSparse tmpOutSparse
Yann Collet32990b52016-05-23 17:48:57 +0200295$ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100296$DIFF -s tmpSparse tmpOutNoSparse
Yann Collet01a1abf2017-05-05 19:15:24 -0700297ls -ls tmpSparse* # look at file size and block size on disk
Yann Collet32990b52016-05-23 17:48:57 +0200298./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 +0100299./datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
Yann Collet01a1abf2017-05-05 19:15:24 -0700300ls -ls tmpSparseOdd # look at file size and block size on disk
inikep5d589562016-05-25 10:50:28 +0200301$ECHO "\n Sparse Compatibility with Console :"
302$ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
303$ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
304$ECHO "\n Sparse Compatibility with Append :"
Yann Collet32990b52016-05-23 17:48:57 +0200305./datagen -P100 -g1M > tmpSparse1M
306cat tmpSparse1M tmpSparse1M > tmpSparse2M
307$ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
308$ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
309$ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
Yann Collet01a1abf2017-05-05 19:15:24 -0700310ls -ls tmpSparse* # look at file size and block size on disk
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100311$DIFF tmpSparse2M tmpSparseRegenerated
Yann Collet33341de2016-05-29 23:09:51 +0200312rm tmpSparse*
Yann Collet32990b52016-05-23 17:48:57 +0200313
314
Yann Collet241c57a2017-10-16 14:01:42 -0700315$ECHO "\n===> multiple files tests "
Yann Collet9b998e42016-06-15 23:11:20 +0200316
Yann Collet391a1282016-06-21 17:06:25 +0200317./datagen -s1 > tmp1 2> $INTOVOID
318./datagen -s2 -g100K > tmp2 2> $INTOVOID
319./datagen -s3 -g1M > tmp3 2> $INTOVOID
Yann Collet9b998e42016-06-15 23:11:20 +0200320$ECHO "compress tmp* : "
Yann Collet60ba31c2016-07-28 19:55:09 +0200321$ZSTD -f tmp*
Yann Collet9b998e42016-06-15 23:11:20 +0200322ls -ls tmp*
323rm tmp1 tmp2 tmp3
324$ECHO "decompress tmp* : "
325$ZSTD -df *.zst
326ls -ls tmp*
327$ECHO "compress tmp* into stdout > tmpall : "
328$ZSTD -c tmp1 tmp2 tmp3 > tmpall
Yann Collet01a1abf2017-05-05 19:15:24 -0700329ls -ls tmp* # check size of tmpall (should be tmp1.zst + tmp2.zst + tmp3.zst)
Yann Collet9b998e42016-06-15 23:11:20 +0200330$ECHO "decompress tmpall* into stdout > tmpdec : "
331cp tmpall tmpall2
332$ZSTD -dc tmpall* > tmpdec
Yann Collet01a1abf2017-05-05 19:15:24 -0700333ls -ls tmp* # check size of tmpdec (should be 2*(tmp1 + tmp2 + tmp3))
Yann Collet9b998e42016-06-15 23:11:20 +0200334$ECHO "compress multiple files including a missing one (notHere) : "
335$ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
336
337
Yann Collet241c57a2017-10-16 14:01:42 -0700338$ECHO "\n===> dictionary tests "
Yann Colletf6f3d752015-12-13 13:35:21 +0100339
Yann Colletbd7fa212017-02-26 14:43:07 -0800340$ECHO "- test with raw dict (content only) "
Yann Colletf6f3d752015-12-13 13:35:21 +0100341./datagen > tmpDict
inikep93fc13e2016-05-30 10:17:55 +0200342./datagen -g1M | $MD5SUM > tmp1
343./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100344$DIFF -q tmp1 tmp2
Yann Colletbd7fa212017-02-26 14:43:07 -0800345$ECHO "- Create first dictionary "
346TESTFILE=../programs/zstdcli.c
inikepb7d34492016-08-18 15:13:41 +0200347$ZSTD --train *.c ../programs/*.c -o tmpDict
348cp $TESTFILE tmp
Yann Colletd228b6b2017-12-29 19:14:18 +0100349$ECHO "- Dictionary compression roundtrip"
Yann Collet6381e992016-05-31 02:29:45 +0200350$ZSTD -f tmp -D tmpDict
Yann Collet27b5ac62016-09-21 14:20:56 +0200351$ZSTD -d tmp.zst -D tmpDict -fo result
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100352$DIFF $TESTFILE result
Yann Colletd228b6b2017-12-29 19:14:18 +0100353$ECHO "- Dictionary compression with btlazy2 strategy"
354$ZSTD -f tmp -D tmpDict --zstd=strategy=6
355$ZSTD -d tmp.zst -D tmpDict -fo result
356$DIFF $TESTFILE result
Yann Collet311878d2017-12-13 11:48:30 -0800357if [ -n "$hasMT" ]
358then
359 $ECHO "- Test dictionary compression with multithreading "
Yann Collet281f06e2017-12-14 11:47:02 -0800360 ./datagen -g5M | $ZSTD -T2 -D tmpDict | $ZSTD -t -D tmpDict # fails with v1.3.2
Yann Collet311878d2017-12-13 11:48:30 -0800361fi
Yann Colletbd7fa212017-02-26 14:43:07 -0800362$ECHO "- Create second (different) dictionary "
inikepb7d34492016-08-18 15:13:41 +0200363$ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
Yann Collet27b5ac62016-09-21 14:20:56 +0200364$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
Yann Collet531a4272016-06-15 19:02:11 +0200365$ECHO "- Create dictionary with short dictID"
Yann Collet4c41d372017-03-24 18:36:56 -0700366$ZSTD --train *.c ../programs/*.c --dictID=1 -o tmpDict1
Yann Collet290aaa72016-05-30 21:18:52 +0200367cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
Yann Collet27b5ac62016-09-21 14:20:56 +0200368$ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
369$ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
370$ECHO "- Create dictionary with size limit"
Yann Collet4c41d372017-03-24 18:36:56 -0700371$ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict=4K -v
Nick Terrell35875562017-08-21 11:16:47 -0700372$ECHO "- Create dictionary with small size limit"
373$ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict=1K -v
Yann Collet27b5ac62016-09-21 14:20:56 +0200374$ECHO "- Create dictionary with wrong parameter order (must fail)"
Nick Terrell35875562017-08-21 11:16:47 -0700375$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 +0200376$ECHO "- Compress without dictID"
Yann Collet6381e992016-05-31 02:29:45 +0200377$ZSTD -f tmp -D tmpDict1 --no-dictID
Yann Collet27b5ac62016-09-21 14:20:56 +0200378$ZSTD -d tmp.zst -D tmpDict -fo result
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100379$DIFF $TESTFILE result
Yann Collet27b5ac62016-09-21 14:20:56 +0200380$ECHO "- Compress with wrong argument order (must fail)"
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700381$ZSTD tmp -Df tmpDict1 -c > $INTOVOID && die "-D must be followed by dictionary name "
Yann Collet531a4272016-06-15 19:02:11 +0200382$ECHO "- Compress multiple files with dictionary"
Yann Collet531a4272016-06-15 19:02:11 +0200383rm -rf dirTestDict
384mkdir dirTestDict
385cp *.c dirTestDict
inikepb7d34492016-08-18 15:13:41 +0200386cp ../programs/*.c dirTestDict
387cp ../programs/*.h dirTestDict
Yann Collet94376ac2016-08-25 19:09:21 +0200388$MD5SUM dirTestDict/* > tmph1
389$ZSTD -f --rm dirTestDict/* -D tmpDictC
Yann Colletbb93d772016-08-25 22:22:50 +0200390$ZSTD -d --rm dirTestDict/*.zst -D tmpDictC # note : use internal checksum by default
Dimitry Andric12df6da2016-12-12 19:22:47 +0100391case "$UNAME" in
392 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 -0800393 *) $MD5SUM -c tmph1 ;;
394esac
Yann Collet531a4272016-06-15 19:02:11 +0200395rm -rf dirTestDict
Yann Colletf332ece2017-03-23 16:24:02 -0700396$ECHO "- dictionary builder on bogus input"
397$ECHO "Hello World" > tmp
Nick Terrellf376d472017-05-01 23:40:20 -0700398$ZSTD --train-legacy -q tmp && die "Dictionary training should fail : not enough input source"
Yann Colletf332ece2017-03-23 16:24:02 -0700399./datagen -P0 -g10M > tmp
Nick Terrellf376d472017-05-01 23:40:20 -0700400$ZSTD --train-legacy -q tmp && die "Dictionary training should fail : source is pure noise"
Yann Collet6381e992016-05-31 02:29:45 +0200401rm tmp*
Yann Colletb44be742016-03-26 20:52:14 +0100402
Yann Colletf6f3d752015-12-13 13:35:21 +0100403
Yann Collet241c57a2017-10-16 14:01:42 -0700404$ECHO "\n===> cover dictionary builder : advanced options "
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500405
406TESTFILE=../programs/zstdcli.c
407./datagen > tmpDict
408$ECHO "- Create first dictionary"
Nick Terrellf376d472017-05-01 23:40:20 -0700409$ZSTD --train-cover=k=46,d=8 *.c ../programs/*.c -o tmpDict
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500410cp $TESTFILE tmp
411$ZSTD -f tmp -D tmpDict
412$ZSTD -d tmp.zst -D tmpDict -fo result
413$DIFF $TESTFILE result
414$ECHO "- Create second (different) dictionary"
Nick Terrellf376d472017-05-01 23:40:20 -0700415$ZSTD --train-cover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500416$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
417$ECHO "- Create dictionary with short dictID"
Nick Terrellf376d472017-05-01 23:40:20 -0700418$ZSTD --train-cover=k=46,d=8 *.c ../programs/*.c --dictID=1 -o tmpDict1
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500419cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
420$ECHO "- Create dictionary with size limit"
Nick Terrellf376d472017-05-01 23:40:20 -0700421$ZSTD --train-cover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
422rm tmp*
423
Yann Collet241c57a2017-10-16 14:01:42 -0700424$ECHO "\n===> legacy dictionary builder "
Nick Terrellf376d472017-05-01 23:40:20 -0700425
426TESTFILE=../programs/zstdcli.c
427./datagen > tmpDict
428$ECHO "- Create first dictionary"
429$ZSTD --train-legacy=selectivity=8 *.c ../programs/*.c -o tmpDict
430cp $TESTFILE tmp
431$ZSTD -f tmp -D tmpDict
432$ZSTD -d tmp.zst -D tmpDict -fo result
433$DIFF $TESTFILE result
434$ECHO "- Create second (different) dictionary"
435$ZSTD --train-legacy=s=5 *.c ../programs/*.c ../programs/*.h -o tmpDictC
436$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
437$ECHO "- Create dictionary with short dictID"
438$ZSTD --train-legacy -s5 *.c ../programs/*.c --dictID=1 -o tmpDict1
439cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
440$ECHO "- Create dictionary with size limit"
441$ZSTD --train-legacy -s9 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500442rm tmp*
443
444
Yann Collet241c57a2017-10-16 14:01:42 -0700445$ECHO "\n===> integrity tests "
Yann Colletde95f962016-05-23 19:46:47 +0200446
inikep5d589562016-05-25 10:50:28 +0200447$ECHO "test one file (tmp1.zst) "
Yann Collet1a7b8fb2016-06-15 23:33:38 +0200448./datagen > tmp1
449$ZSTD tmp1
Yann Collet459a6b72016-02-15 20:37:23 +0100450$ZSTD -t tmp1.zst
Yann Collet2d08b092016-02-16 14:42:08 +0100451$ZSTD --test tmp1.zst
inikep5d589562016-05-25 10:50:28 +0200452$ECHO "test multiple files (*.zst) "
Yann Collet459a6b72016-02-15 20:37:23 +0100453$ZSTD -t *.zst
Yann Collet24a3d902016-07-26 01:26:56 +0200454$ECHO "test bad files (*) "
Yann Collet459a6b72016-02-15 20:37:23 +0100455$ZSTD -t * && die "bad files not detected !"
Yann Collet24a3d902016-07-26 01:26:56 +0200456$ZSTD -t tmp1 && die "bad file not detected !"
457cp tmp1 tmp2.zst
458$ZSTD -t tmp2.zst && die "bad file not detected !"
Yann Collet7adc2322016-07-26 15:39:31 +0200459./datagen -g0 > tmp3
460$ZSTD -t tmp3 && die "bad file not detected !" # detects 0-sized files as bad
Yann Colletb4024902016-07-26 00:49:47 +0200461$ECHO "test --rm and --test combined "
462$ZSTD -t --rm tmp1.zst
Yann Collet01a1abf2017-05-05 19:15:24 -0700463test -f tmp1.zst # check file is still present
464split -b16384 tmp1.zst tmpSplit.
465$ZSTD -t tmpSplit.* && die "bad file not detected !"
Nick Terrelld0b27482017-07-18 14:45:49 -0700466./datagen | $ZSTD -c | $ZSTD -t
Yann Colletdeb078b2015-12-17 20:30:14 +0100467
Yann Colletde95f962016-05-23 19:46:47 +0200468
Nick Terrellabe12b32017-07-28 11:54:28 -0700469
Yann Collet241c57a2017-10-16 14:01:42 -0700470$ECHO "\n===> golden files tests "
Nick Terrellabe12b32017-07-28 11:54:28 -0700471
472$ZSTD -t -r files
473$ZSTD -c -r files | $ZSTD -t
474
475
Yann Collet241c57a2017-10-16 14:01:42 -0700476$ECHO "\n===> benchmark mode tests "
Yann Colletb9550d62016-10-28 14:43:24 -0700477
478$ECHO "bench one file"
479./datagen > tmp1
Yann Colletc1c040e2017-03-01 16:49:20 -0800480$ZSTD -bi0 tmp1
Yann Colletb9550d62016-10-28 14:43:24 -0700481$ECHO "bench multiple levels"
Yann Colletc1c040e2017-03-01 16:49:20 -0800482$ZSTD -i0b0e3 tmp1
Yann Collet6a9b41b2018-03-11 19:56:48 -0700483$ECHO "bench negative level"
484$ZSTD -bi0 --fast tmp1
Yann Colletb9550d62016-10-28 14:43:24 -0700485$ECHO "with recursive and quiet modes"
Yann Colletc1c040e2017-03-01 16:49:20 -0800486$ZSTD -rqi1b1e2 tmp1
487
488
Yann Collet241c57a2017-10-16 14:01:42 -0700489$ECHO "\n===> gzip compatibility tests "
Yann Colletc1c040e2017-03-01 16:49:20 -0800490
491GZIPMODE=1
492$ZSTD --format=gzip -V || GZIPMODE=0
493if [ $GZIPMODE -eq 1 ]; then
Yann Collet27526c72017-03-01 17:02:49 -0800494 $ECHO "gzip support detected"
Yann Colletc1c040e2017-03-01 16:49:20 -0800495 GZIPEXE=1
Yann Collet27526c72017-03-01 17:02:49 -0800496 gzip -V || GZIPEXE=0
Yann Colletc1c040e2017-03-01 16:49:20 -0800497 if [ $GZIPEXE -eq 1 ]; then
498 ./datagen > tmp
499 $ZSTD --format=gzip -f tmp
500 gzip -t -v tmp.gz
501 gzip -f tmp
502 $ZSTD -d -f -v tmp.gz
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700503 rm tmp*
Yann Colletc1c040e2017-03-01 16:49:20 -0800504 else
505 $ECHO "gzip binary not detected"
506 fi
507else
508 $ECHO "gzip mode not supported"
509fi
Yann Colletb9550d62016-10-28 14:43:24 -0700510
511
Yann Collet241c57a2017-10-16 14:01:42 -0700512$ECHO "\n===> gzip frame tests "
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700513
514if [ $GZIPMODE -eq 1 ]; then
515 ./datagen > tmp
516 $ZSTD -f --format=gzip tmp
517 $ZSTD -f tmp
518 cat tmp.gz tmp.zst tmp.gz tmp.zst | $ZSTD -d -f -o tmp
Sean Purcell4de86322017-04-24 16:48:25 -0700519 head -c -1 tmp.gz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700520 rm tmp*
521else
522 $ECHO "gzip mode not supported"
523fi
524
525
Yann Collet241c57a2017-10-16 14:01:42 -0700526$ECHO "\n===> xz compatibility tests "
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700527
528LZMAMODE=1
529$ZSTD --format=xz -V || LZMAMODE=0
530if [ $LZMAMODE -eq 1 ]; then
531 $ECHO "xz support detected"
532 XZEXE=1
533 xz -V && lzma -V || XZEXE=0
534 if [ $XZEXE -eq 1 ]; then
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700535 $ECHO "Testing zstd xz and lzma support"
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700536 ./datagen > tmp
537 $ZSTD --format=lzma -f tmp
538 $ZSTD --format=xz -f tmp
539 xz -t -v tmp.xz
540 xz -t -v tmp.lzma
541 xz -f -k tmp
542 lzma -f -k --lzma1 tmp
543 $ZSTD -d -f -v tmp.xz
544 $ZSTD -d -f -v tmp.lzma
545 rm tmp*
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700546 $ECHO "Creating symlinks"
547 ln -s $ZSTD ./xz
548 ln -s $ZSTD ./unxz
549 ln -s $ZSTD ./lzma
550 ln -s $ZSTD ./unlzma
551 $ECHO "Testing xz and lzma symlinks"
552 ./datagen > tmp
553 ./xz tmp
554 xz -d tmp.xz
555 ./lzma tmp
556 lzma -d tmp.lzma
557 $ECHO "Testing unxz and unlzma symlinks"
558 xz tmp
559 ./xz -d tmp.xz
560 lzma tmp
561 ./lzma -d tmp.lzma
562 rm xz unxz lzma unlzma
563 rm tmp*
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700564 else
565 $ECHO "xz binary not detected"
566 fi
567else
568 $ECHO "xz mode not supported"
569fi
570
571
Yann Collet241c57a2017-10-16 14:01:42 -0700572$ECHO "\n===> xz frame tests "
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700573
574if [ $LZMAMODE -eq 1 ]; then
575 ./datagen > tmp
576 $ZSTD -f --format=xz tmp
577 $ZSTD -f --format=lzma tmp
578 $ZSTD -f tmp
579 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 -0700580 head -c -1 tmp.xz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
581 head -c -1 tmp.lzma | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700582 rm tmp*
583else
584 $ECHO "xz mode not supported"
585fi
586
Yann Collet241c57a2017-10-16 14:01:42 -0700587$ECHO "\n===> lz4 compatibility tests "
Sean Purcell4de86322017-04-24 16:48:25 -0700588
589LZ4MODE=1
590$ZSTD --format=lz4 -V || LZ4MODE=0
591if [ $LZ4MODE -eq 1 ]; then
592 $ECHO "lz4 support detected"
593 LZ4EXE=1
594 lz4 -V || LZ4EXE=0
595 if [ $LZ4EXE -eq 1 ]; then
596 ./datagen > tmp
597 $ZSTD --format=lz4 -f tmp
598 lz4 -t -v tmp.lz4
599 lz4 -f tmp
600 $ZSTD -d -f -v tmp.lz4
601 rm tmp*
602 else
603 $ECHO "lz4 binary not detected"
604 fi
605else
606 $ECHO "lz4 mode not supported"
607fi
608
609
Yann Collet241c57a2017-10-16 14:01:42 -0700610$ECHO "\n===> lz4 frame tests "
Sean Purcell4de86322017-04-24 16:48:25 -0700611
612if [ $LZ4MODE -eq 1 ]; then
613 ./datagen > tmp
614 $ZSTD -f --format=lz4 tmp
615 $ZSTD -f tmp
616 cat tmp.lz4 tmp.zst tmp.lz4 tmp.zst | $ZSTD -d -f -o tmp
617 head -c -1 tmp.lz4 | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
618 rm tmp*
619else
620 $ECHO "lz4 mode not supported"
621fi
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700622
George Lu53ea32c2018-06-01 10:43:06 -0700623$ECHO "\n===> suffix list test"
624
625$ZSTD -d tmp.abc 2> tmplg || echo
626
627if [ $GZIPMODE -ne 1 ]; then
628 grep ".gz" tmplg > $INTOVOID && die "Unsupported suffix listed"
629fi
630
631if [ $LZMAMODE -ne 1 ]; then
632 grep ".lzma" tmplg > $INTOVOID && die "Unsupported suffix listed"
633 grep ".xz" tmplg > $INTOVOID && die "Unsupported suffix listed"
634fi
635
636if [ $LZ4MODE -ne 1 ]; then
637 grep ".lz4" tmplg > $INTOVOID && die "Unsupported suffix listed"
638fi
639
Yann Collet241c57a2017-10-16 14:01:42 -0700640$ECHO "\n===> zstd round-trip tests "
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300641
642roundTripTest
Yann Collet3b719252016-03-30 19:48:05 +0200643roundTripTest -g15K # TableID==3
644roundTripTest -g127K # TableID==2
645roundTripTest -g255K # TableID==1
Yann Colletc1c040e2017-03-01 16:49:20 -0800646roundTripTest -g522K # TableID==0
647roundTripTest -g519K 6 # greedy, hash chain
648roundTripTest -g517K 16 # btlazy2
649roundTripTest -g516K 19 # btopt
Yann Collet459a6b72016-02-15 20:37:23 +0100650
Sean Purcelleb70d212017-04-11 17:15:13 -0700651fileRoundTripTest -g500K
652
Yann Collet241c57a2017-10-16 14:01:42 -0700653$ECHO "\n===> zstd long distance matching round-trip tests "
Nick Terrellf15a17e2018-02-27 20:09:18 -0800654roundTripTest -g0 "2 --single-thread --long"
655roundTripTest -g1000K "1 --single-thread --long"
656roundTripTest -g517K "6 --single-thread --long"
657roundTripTest -g516K "16 --single-thread --long"
658roundTripTest -g518K "19 --single-thread --long"
659fileRoundTripTest -g5M "3 --single-thread --long"
Stella Lau6a546ef2017-07-28 15:51:33 -0700660
661
Yann Collet75689832018-02-09 15:53:27 -0800662roundTripTest -g96K "5 --single-thread"
Sean Purcellc424ec22017-04-17 11:38:53 -0700663if [ -n "$hasMT" ]
664then
Yann Collet241c57a2017-10-16 14:01:42 -0700665 $ECHO "\n===> zstdmt round-trip tests "
Sean Purcelld845dab2017-04-17 12:10:58 -0700666 roundTripTest -g4M "1 -T0"
667 roundTripTest -g8M "3 -T2"
Yann Collet230d7ac2017-04-21 11:38:13 -0700668 roundTripTest -g8000K "2 --threads=2"
Sean Purcelld845dab2017-04-17 12:10:58 -0700669 fileRoundTripTest -g4M "19 -T2 -B1M"
Stella Lau6a546ef2017-07-28 15:51:33 -0700670
Yann Collet241c57a2017-10-16 14:01:42 -0700671 $ECHO "\n===> zstdmt long distance matching round-trip tests "
Nick Terrellf15a17e2018-02-27 20:09:18 -0800672 roundTripTest -g8M "3 --long=24 -T2"
Yann Collet96b480a2018-03-29 13:07:28 -0600673
674 $ECHO "\n===> ovLog tests "
675 ./datagen -g2MB > tmp
676 refSize=$($ZSTD tmp -6 -c --zstd=wlog=18 | wc -c)
677 ov9Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=9 | wc -c)
678 ov0Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=0 | wc -c)
679 if [ $refSize -eq $ov9Size ]; then
680 echo ov9Size should be different from refSize
681 exit 1
682 fi
683 if [ $refSize -eq $ov0Size ]; then
684 echo ov0Size should be different from refSize
685 exit 1
686 fi
687 if [ $ov9Size -ge $ov0Size ]; then
688 echo ov9Size=$ov9Size should be smaller than ov0Size=$ov0Size
689 exit 1
690 fi
691
Sean Purcellc424ec22017-04-17 11:38:53 -0700692else
Yann Collet241c57a2017-10-16 14:01:42 -0700693 $ECHO "\n===> no multithreading, skipping zstdmt tests "
Sean Purcellc424ec22017-04-17 11:38:53 -0700694fi
695
Yann Collet459a6b72016-02-15 20:37:23 +0100696rm tmp*
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300697
Yann Collet241c57a2017-10-16 14:01:42 -0700698$ECHO "\n===> zstd --list/-l single frame tests "
Paul Cruzddd1ab72017-06-15 16:53:03 -0700699./datagen > tmp1
700./datagen > tmp2
701./datagen > tmp3
Paul Cruzddd1ab72017-06-15 16:53:03 -0700702$ZSTD tmp*
Paul Cruz6a99de22017-06-20 10:45:06 -0700703$ZSTD -l *.zst
Yann Collet43914f62017-10-13 23:47:01 -0700704$ZSTD -lv *.zst | grep "Decompressed Size:" # check that decompressed size is present in header
Paul Cruz6a99de22017-06-20 10:45:06 -0700705$ZSTD --list *.zst
706$ZSTD --list -v *.zst
Paul Cruzddd1ab72017-06-15 16:53:03 -0700707
Yann Collet241c57a2017-10-16 14:01:42 -0700708$ECHO "\n===> zstd --list/-l multiple frame tests "
Paul Cruzddd1ab72017-06-15 16:53:03 -0700709cat tmp1.zst tmp2.zst > tmp12.zst
Yann Collet60059df2017-09-27 15:16:27 -0700710cat tmp12.zst tmp3.zst > tmp123.zst
Paul Cruz6a99de22017-06-20 10:45:06 -0700711$ZSTD -l *.zst
712$ZSTD -lv *.zst
Paul Cruzddd1ab72017-06-15 16:53:03 -0700713
Yann Collet241c57a2017-10-16 14:01:42 -0700714$ECHO "\n===> zstd --list/-l error detection tests "
Paul Cruz58c19b42017-06-20 14:14:53 -0700715! $ZSTD -l tmp1 tmp1.zst
716! $ZSTD --list tmp*
717! $ZSTD -lv tmp1*
Yann Collet60059df2017-09-27 15:16:27 -0700718! $ZSTD --list -v tmp2 tmp12.zst
Paul Cruzb07d0af2017-06-20 11:54:44 -0700719
Yann Collet241c57a2017-10-16 14:01:42 -0700720$ECHO "\n===> zstd --list/-l test with null files "
Paul Cruza73c2a42017-06-20 14:33:08 -0700721./datagen -g0 > tmp5
722$ZSTD tmp5
Yann Colletc16748b2017-06-21 12:09:53 -0700723$ZSTD -l tmp5.zst
Paul Cruza73c2a42017-06-20 14:33:08 -0700724! $ZSTD -l tmp5*
Yann Collet5891f1d2017-10-17 16:23:20 -0700725$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 -0700726! $ZSTD -lv tmp5*
Paul Cruza73c2a42017-06-20 14:33:08 -0700727
Yann Collet241c57a2017-10-16 14:01:42 -0700728$ECHO "\n===> zstd --list/-l test with no content size field "
Yann Collet43914f62017-10-13 23:47:01 -0700729./datagen -g513K | $ZSTD > tmp6.zst
Paul Cruzdb3606e2017-06-20 17:43:36 -0700730$ZSTD -l tmp6.zst
Yann Collet43914f62017-10-13 23:47:01 -0700731! $ZSTD -lv tmp6.zst | grep "Decompressed Size:" # must NOT be present in header
Yann Colletc16748b2017-06-21 12:09:53 -0700732
Yann Collet241c57a2017-10-16 14:01:42 -0700733$ECHO "\n===> zstd --list/-l test with no checksum "
Yann Colletc16748b2017-06-21 12:09:53 -0700734$ZSTD -f --no-check tmp1
735$ZSTD -l tmp1.zst
736$ZSTD -lv tmp1.zst
Paul Cruzdb3606e2017-06-20 17:43:36 -0700737
Paul Cruzddd1ab72017-06-15 16:53:03 -0700738rm tmp*
739
Yann Colletc16748b2017-06-21 12:09:53 -0700740
Yann Collet241c57a2017-10-16 14:01:42 -0700741$ECHO "\n===> zstd long distance matching tests "
Nick Terrellf15a17e2018-02-27 20:09:18 -0800742roundTripTest -g0 " --single-thread --long"
743roundTripTest -g9M "2 --single-thread --long"
Yann Collet02502192017-09-27 15:48:06 -0700744# Test parameter parsing
Nick Terrellf15a17e2018-02-27 20:09:18 -0800745roundTripTest -g1M -P50 "1 --single-thread --long=29" " --memory=512MB"
746roundTripTest -g1M -P50 "1 --single-thread --long=29 --zstd=wlog=28" " --memory=256MB"
747roundTripTest -g1M -P50 "1 --single-thread --long=29" " --long=28 --memory=512MB"
748roundTripTest -g1M -P50 "1 --single-thread --long=29" " --zstd=wlog=28 --memory=512MB"
Yann Collet02502192017-09-27 15:48:06 -0700749
750
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300751if [ "$1" != "--test-large-data" ]; then
inikep5d589562016-05-25 10:50:28 +0200752 $ECHO "Skipping large data tests"
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300753 exit 0
754fi
755
Yann Collet241c57a2017-10-16 14:01:42 -0700756$ECHO "\n===> large files tests "
Yann Collet02502192017-09-27 15:48:06 -0700757
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300758roundTripTest -g270000000 1
Yann Collet60059df2017-09-27 15:16:27 -0700759roundTripTest -g250000000 2
760roundTripTest -g230000000 3
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300761
762roundTripTest -g140000000 -P60 4
Yann Collet60059df2017-09-27 15:16:27 -0700763roundTripTest -g130000000 -P62 5
764roundTripTest -g120000000 -P65 6
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300765
766roundTripTest -g70000000 -P70 7
Yann Collet60059df2017-09-27 15:16:27 -0700767roundTripTest -g60000000 -P71 8
768roundTripTest -g50000000 -P73 9
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300769
770roundTripTest -g35000000 -P75 10
Yann Collet60059df2017-09-27 15:16:27 -0700771roundTripTest -g30000000 -P76 11
772roundTripTest -g25000000 -P78 12
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300773
Yann Collet4616fad2017-07-10 17:16:41 -0700774roundTripTest -g18000013 -P80 13
775roundTripTest -g18000014 -P80 14
Yann Collet60059df2017-09-27 15:16:27 -0700776roundTripTest -g18000015 -P81 15
777roundTripTest -g18000016 -P84 16
778roundTripTest -g18000017 -P88 17
Yann Collet4616fad2017-07-10 17:16:41 -0700779roundTripTest -g18000018 -P94 18
Yann Collet60059df2017-09-27 15:16:27 -0700780roundTripTest -g18000019 -P96 19
Konstantin Tokarev2b465842015-12-08 19:36:42 +0300781
Yann Collet60059df2017-09-27 15:16:27 -0700782roundTripTest -g5000000000 -P99 1
Yann Collet4c7f1372017-12-29 17:40:36 +0100783roundTripTest -g1700000000 -P0 "1 --zstd=strategy=6" # ensure btlazy2 can survive an overflow rescale
Yann Collet459a6b72016-02-15 20:37:23 +0100784
Sean Purcelleb70d212017-04-11 17:15:13 -0700785fileRoundTripTest -g4193M -P99 1
786
Yann Collet02502192017-09-27 15:48:06 -0700787
Yann Collet241c57a2017-10-16 14:01:42 -0700788$ECHO "\n===> zstd long, long distance matching round-trip tests "
Nick Terrellf15a17e2018-02-27 20:09:18 -0800789roundTripTest -g270000000 "1 --single-thread --long"
790roundTripTest -g130000000 -P60 "5 --single-thread --long"
791roundTripTest -g35000000 -P70 "8 --single-thread --long"
792roundTripTest -g18000001 -P80 "18 --single-thread --long"
Nick Terrellc233bdb2017-09-22 14:04:39 -0700793# Test large window logs
Nick Terrellf15a17e2018-02-27 20:09:18 -0800794roundTripTest -g700M -P50 "1 --single-thread --long=29"
795roundTripTest -g600M -P50 "1 --single-thread --long --zstd=wlog=29,clog=28"
Stella Lau6a546ef2017-07-28 15:51:33 -0700796
797
Sean Purcellc424ec22017-04-17 11:38:53 -0700798if [ -n "$hasMT" ]
799then
Yann Collet241c57a2017-10-16 14:01:42 -0700800 $ECHO "\n===> zstdmt long round-trip tests "
Yann Collet60059df2017-09-27 15:16:27 -0700801 roundTripTest -g80000000 -P99 "19 -T2" " "
802 roundTripTest -g5000000000 -P99 "1 -T2" " "
803 roundTripTest -g500000000 -P97 "1 -T999" " "
804 fileRoundTripTest -g4103M -P98 " -T0" " "
805 roundTripTest -g400000000 -P97 "1 --long=24 -T2" " "
Sean Purcellc424ec22017-04-17 11:38:53 -0700806else
807 $ECHO "\n**** no multithreading, skipping zstdmt tests **** "
808fi
809
Yann Collet459a6b72016-02-15 20:37:23 +0100810rm tmp*