blob: 99609a5ea01a10c0e8a5cc7050c1b1f667c9d541 [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 Ketelaars06fd1e42018-06-30 15:42:42 +020051truncateLastByte() {
52 dd bs=1 count=$(($(wc -c < "$1") - 1)) if="$1" status=none
53}
54
Björn Ketelaars276988f2018-06-30 13:01:58 +020055UNAME=$(uname)
56
Sean Purcell9a38dfa2017-03-17 12:32:18 -070057isTerminal=false
58if [ -t 0 ] && [ -t 1 ]
59then
60 isTerminal=true
61fi
62
inikep5d589562016-05-25 10:50:28 +020063isWindows=false
Yann Collet391a1282016-06-21 17:06:25 +020064INTOVOID="/dev/null"
Björn Ketelaars276988f2018-06-30 13:01:58 +020065case "$UNAME" in
Dmitry V. Levin7ca12a12018-07-11 12:41:50 +000066 GNU) DEVDEVICE="/dev/random" ;;
67 *) DEVDEVICE="/dev/zero" ;;
Björn Ketelaars276988f2018-06-30 13:01:58 +020068esac
inikep993a9df2016-05-27 10:07:46 +020069case "$OS" in
Yann Collet673f0d72016-06-06 00:26:38 +020070 Windows*)
inikep5d589562016-05-25 10:50:28 +020071 isWindows=true
Sean Purcell9a38dfa2017-03-17 12:32:18 -070072 INTOVOID="NUL"
Nick Terrell82bc8fe2017-12-13 12:04:46 -080073 DEVDEVICE="NUL"
inikep993a9df2016-05-27 10:07:46 +020074 ;;
75esac
inikep5d589562016-05-25 10:50:28 +020076
Dimitry Andric12df6da2016-12-12 19:22:47 +010077case "$UNAME" in
78 Darwin) MD5SUM="md5 -r" ;;
79 FreeBSD) MD5SUM="gmd5sum" ;;
bketdaf3ab02018-04-02 23:12:18 +020080 OpenBSD) MD5SUM="md5" ;;
Yann Collet94d1a932016-12-06 12:02:56 -080081 *) MD5SUM="md5sum" ;;
82esac
inikep5d589562016-05-25 10:50:28 +020083
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +010084DIFF="diff"
85case "$UNAME" in
86 SunOS) DIFF="gdiff" ;;
87esac
88
Yann Collet62568c92017-09-25 14:26:26 -070089ECHO="echo -e"
90case "$UNAME" in
91 Darwin) ECHO="echo" ;;
92esac
93
Przemyslaw Skibinskie579ab52016-11-14 12:57:05 +010094$ECHO "\nStarting playTests.sh isWindows=$isWindows ZSTD='$ZSTD'"
inikep5d589562016-05-25 10:50:28 +020095
Konstantin Tokarev76be3782015-12-08 18:36:37 +030096[ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
97
Sean Purcellc424ec22017-04-17 11:38:53 -070098if [ -n "$(echo hello | $ZSTD -v -T2 2>&1 > $INTOVOID | grep 'multi-threading is disabled')" ]
99then
100 hasMT=""
101else
102 hasMT="true"
103fi
104
Yann Colleta927fae2018-01-06 12:31:26 +0100105
Yann Collet6c51bf42018-09-24 18:16:08 -0700106
Yann Collet241c57a2017-10-16 14:01:42 -0700107$ECHO "\n===> simple tests "
Yann Colletde95f962016-05-23 19:46:47 +0200108
Yann Collet8154c3d2016-02-13 03:12:10 +0100109./datagen > tmp
Yann Colletb3060f72016-09-09 16:44:16 +0200110$ECHO "test : basic compression "
Yann Collet673f0d72016-06-06 00:26:38 +0200111$ZSTD -f tmp # trivial compression case, creates tmp.zst
Yann Colletb3060f72016-09-09 16:44:16 +0200112$ECHO "test : basic decompression"
Yann Collet673f0d72016-06-06 00:26:38 +0200113$ZSTD -df tmp.zst # trivial decompression case (overwrites tmp)
Yann Collet6a9b41b2018-03-11 19:56:48 -0700114$ECHO "test : too large compression level => auto-fix"
Yann Colletfab02302016-08-12 19:00:18 +0200115$ZSTD -99 -f tmp # too large compression level, automatic sized down
Yann Collet63abaf22018-09-25 15:57:28 -0700116$ZSTD -5000000000 -f tmp && die "too large numeric value : must fail"
Yann Collet6a9b41b2018-03-11 19:56:48 -0700117$ECHO "test : --fast aka negative compression levels"
118$ZSTD --fast -f tmp # == -1
119$ZSTD --fast=3 -f tmp # == -3
Yann Collet63abaf22018-09-25 15:57:28 -0700120$ZSTD --fast=200000 -f tmp # too low compression level, automatic fixed
121$ZSTD --fast=5000000000 -f tmp && die "too large numeric value : must fail"
122$ZSTD -c --fast=0 tmp > $INTOVOID && die "--fast must not accept value 0"
Yann Collet9cd5c632018-05-12 14:29:33 -0700123$ECHO "test : too large numeric argument"
124$ZSTD --fast=9999999999 -f tmp && die "should have refused numeric value"
inikep5d589562016-05-25 10:50:28 +0200125$ECHO "test : compress to stdout"
Yann Collet0d348d42016-05-29 02:02:24 +0200126$ZSTD tmp -c > tmpCompressed
Yann Colletd6931172016-05-10 05:56:09 +0200127$ZSTD tmp --stdout > tmpCompressed # long command format
Yann Collet27b5ac62016-09-21 14:20:56 +0200128$ECHO "test : compress to named file"
129rm tmpCompressed
130$ZSTD tmp -o tmpCompressed
Yann Collet01a1abf2017-05-05 19:15:24 -0700131test -f tmpCompressed # file must be created
Yann Collet27b5ac62016-09-21 14:20:56 +0200132$ECHO "test : -o must be followed by filename (must fail)"
Yann Collet714464f2016-09-21 16:05:03 +0200133$ZSTD tmp -of tmpCompressed && die "-o must be followed by filename "
Yann Collet27b5ac62016-09-21 14:20:56 +0200134$ECHO "test : force write, correct order"
135$ZSTD tmp -fo tmpCompressed
Yann Collet714464f2016-09-21 16:05:03 +0200136$ECHO "test : forgotten argument"
137cp tmp tmp2
138$ZSTD tmp2 -fo && die "-o must be followed by filename "
Yann Colletc8431422016-09-01 15:05:57 -0700139$ECHO "test : implied stdout when input is stdin"
140$ECHO bob | $ZSTD | $ZSTD -d
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700141if [ "$isTerminal" = true ]; then
Sean Purcelld9730712017-03-16 16:25:19 -0700142$ECHO "test : compressed data to terminal"
143$ECHO bob | $ZSTD && die "should have refused : compressed data to terminal"
144$ECHO "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)"
145$ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal"
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700146fi
inikep5d589562016-05-25 10:50:28 +0200147$ECHO "test : null-length file roundtrip"
148$ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
Yann Collet281f06e2017-12-14 11:47:02 -0800149$ECHO "test : ensure small file doesn't add 3-bytes null block"
Yann Colleta0e09852017-12-14 13:32:24 -0800150./datagen -g1 > tmp1
151$ZSTD tmp1 -c | wc -c | grep "14"
152$ZSTD < tmp1 | wc -c | grep "14"
inikep5d589562016-05-25 10:50:28 +0200153$ECHO "test : decompress file with wrong suffix (must fail)"
Yann Collet2d08b092016-02-16 14:42:08 +0100154$ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
Yann Collet391a1282016-06-21 17:06:25 +0200155$ZSTD -df tmp && die "should have refused : wrong extension"
156$ECHO "test : decompress into stdout"
Yann Collet0d348d42016-05-29 02:02:24 +0200157$ZSTD -d tmpCompressed -c > tmpResult # decompression using stdout
Yann Collet2d08b092016-02-16 14:42:08 +0100158$ZSTD --decompress tmpCompressed -c > tmpResult
159$ZSTD --decompress tmpCompressed --stdout > tmpResult
Yann Collet391a1282016-06-21 17:06:25 +0200160$ECHO "test : decompress from stdin into stdout"
161$ZSTD -dc < tmp.zst > $INTOVOID # combine decompression, stdin & stdout
162$ZSTD -dc - < tmp.zst > $INTOVOID
163$ZSTD -d < tmp.zst > $INTOVOID # implicit stdout when stdin is used
164$ZSTD -d - < tmp.zst > $INTOVOID
Yann Colletd4cda272016-10-14 13:13:13 -0700165$ECHO "test : impose memory limitation (must fail)"
166$ZSTD -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
Yann Collet11223492016-10-14 14:07:11 -0700167$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 -0700168$ZSTD -d -f tmp.zst --memory=2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
169$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 +0200170$ECHO "test : overwrite protection"
Yann Collet2d08b092016-02-16 14:42:08 +0100171$ZSTD -q tmp && die "overwrite check failed!"
Yann Collet391a1282016-06-21 17:06:25 +0200172$ECHO "test : force overwrite"
Yann Collet2d08b092016-02-16 14:42:08 +0100173$ZSTD -q -f tmp
174$ZSTD -q --force tmp
Sean Purcell9da11c62017-04-06 12:58:49 -0700175$ECHO "test : overwrite readonly file"
Sean Purcell16521722017-04-06 17:06:30 -0700176rm -f tmpro tmpro.zst
Sean Purcell9da11c62017-04-06 12:58:49 -0700177$ECHO foo > tmpro.zst
178$ECHO foo > tmpro
179chmod 400 tmpro.zst
Sean Purcell16521722017-04-06 17:06:30 -0700180$ZSTD -q tmpro && die "should have refused to overwrite read-only file"
181$ZSTD -q -f tmpro
182rm -f tmpro tmpro.zst
Yann Collet9b45db72018-09-27 16:49:08 -0700183
184
Yann Colletb09b12c2016-06-09 22:59:51 +0200185$ECHO "test : file removal"
186$ZSTD -f --rm tmp
Yann Collet01a1abf2017-05-05 19:15:24 -0700187test ! -f tmp # tmp should no longer be present
Yann Colletb09b12c2016-06-09 22:59:51 +0200188$ZSTD -f -d --rm tmp.zst
Yann Collet01a1abf2017-05-05 19:15:24 -0700189test ! -f tmp.zst # tmp.zst should no longer be present
Nick Terrell82bc8fe2017-12-13 12:04:46 -0800190$ECHO "test : should quietly not remove non-regular file"
191$ECHO hello > tmp
192$ZSTD tmp -f -o "$DEVDEVICE" 2>tmplog > "$INTOVOID"
193grep -v "Refusing to remove non-regular file" tmplog
194rm -f tmplog
Nick Terrell263134c2018-05-03 13:03:08 -0700195$ZSTD tmp -f -o "$INTOVOID" 2>&1 | grep -v "Refusing to remove non-regular file"
Yann Collet67d86a72017-02-27 16:09:20 -0800196$ECHO "test : --rm on stdin"
197$ECHO a | $ZSTD --rm > $INTOVOID # --rm should remain silent
Yann Colletb09b12c2016-06-09 22:59:51 +0200198rm tmp
199$ZSTD -f tmp && die "tmp not present : should have failed"
Yann Collet01a1abf2017-05-05 19:15:24 -0700200test ! -f tmp.zst # tmp.zst should not be created
Yann Collet9012b6c2018-10-01 17:16:34 -0700201$ECHO "test : -d -f do not delete destination when source is not present"
Yann Collet9b45db72018-09-27 16:49:08 -0700202touch tmp # create destination file
203$ZSTD -d -f tmp.zst && die "attempt to decompress a non existing file"
Yann Collet9012b6c2018-10-01 17:16:34 -0700204test -f tmp # destination file should still be present
205$ECHO "test : -f do not delete destination when source is not present"
206rm tmp # erase source file
207touch tmp.zst # create destination file
208$ZSTD -f tmp && die "attempt to compress a non existing file"
209test -f tmp.zst # destination file should still be present
Yann Collet9b45db72018-09-27 16:49:08 -0700210rm tmp*
211
Yann Colletde95f962016-05-23 19:46:47 +0200212
Nick Terrell4680e852017-12-12 18:32:50 -0800213$ECHO "test : compress multiple files"
214$ECHO hello > tmp1
215$ECHO world > tmp2
216$ZSTD tmp1 tmp2 -o "$INTOVOID"
217$ZSTD tmp1 tmp2 -c | $ZSTD -t
218$ZSTD tmp1 tmp2 -o tmp.zst
219test ! -f tmp1.zst
220test ! -f tmp2.zst
221$ZSTD tmp1 tmp2
222$ZSTD -t tmp1.zst tmp2.zst
223$ZSTD -dc tmp1.zst tmp2.zst
224$ZSTD tmp1.zst tmp2.zst -o "$INTOVOID"
225$ZSTD -d tmp1.zst tmp2.zst -o tmp
Nick Terrell8adebbd2018-01-03 14:02:44 -0800226touch tmpexists
227$ZSTD tmp1 tmp2 -f -o tmpexists
228$ZSTD tmp1 tmp2 -o tmpexists && die "should have refused to overwrite"
229# Bug: PR #972
230if [ "$?" -eq 139 ]; then
231 die "should not have segfaulted"
232fi
Nick Terrell4680e852017-12-12 18:32:50 -0800233rm tmp*
234
235
Yann Collet241c57a2017-10-16 14:01:42 -0700236$ECHO "\n===> Advanced compression parameters "
Przemyslaw Skibinski24a42362016-12-14 18:07:31 +0100237$ECHO "Hello world!" | $ZSTD --zstd=windowLog=21, - -o tmp.zst && die "wrong parameters not detected!"
238$ECHO "Hello world!" | $ZSTD --zstd=windowLo=21 - -o tmp.zst && die "wrong parameters not detected!"
Przemyslaw Skibinskif9a56662016-12-14 18:43:06 +0100239$ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,slog - -o tmp.zst && die "wrong parameters not detected!"
Yann Collet01a1abf2017-05-05 19:15:24 -0700240test ! -f tmp.zst # tmp.zst should not be created
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100241roundTripTest -g512K
Przemyslaw Skibinskiab5ed6f2016-12-14 17:10:38 +0100242roundTripTest -g512K " --zstd=slen=3,tlen=48,strat=6"
243roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100244roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,searchLength=3,targetLength=48,strategy=6"
Nick Terrellf15a17e2018-02-27 20:09:18 -0800245roundTripTest -g512K " --single-thread --long --zstd=ldmHashLog=20,ldmSearchLength=64,ldmBucketSizeLog=1,ldmHashEveryLog=7"
246roundTripTest -g512K " --single-thread --long --zstd=ldmhlog=20,ldmslen=64,ldmblog=1,ldmhevery=7"
Przemyslaw Skibinski9b4fa0d2016-12-14 16:50:00 +0100247roundTripTest -g512K 19
248
249
Yann Collet241c57a2017-10-16 14:01:42 -0700250$ECHO "\n===> Pass-Through mode "
Yann Collet743b33f2016-12-02 15:18:57 -0800251$ECHO "Hello world 1!" | $ZSTD -df
252$ECHO "Hello world 2!" | $ZSTD -dcf
253$ECHO "Hello world 3!" > tmp1
254$ZSTD -dcf tmp1
Yann Colletde95f962016-05-23 19:46:47 +0200255
Yann Collet8154c3d2016-02-13 03:12:10 +0100256
Yann Collet241c57a2017-10-16 14:01:42 -0700257$ECHO "\n===> frame concatenation "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300258
inikep5d589562016-05-25 10:50:28 +0200259$ECHO "hello " > hello.tmp
260$ECHO "world!" > world.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300261cat hello.tmp world.tmp > helloworld.tmp
Yann Colletc8da2c92016-02-12 02:56:27 +0100262$ZSTD -c hello.tmp > hello.zstd
263$ZSTD -c world.tmp > world.zstd
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300264cat hello.zstd world.zstd > helloworld.zstd
Yann Colletc8da2c92016-02-12 02:56:27 +0100265$ZSTD -dc helloworld.zstd > result.tmp
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300266cat result.tmp
Yann Colletbd6bc222017-01-22 15:54:14 -0800267$DIFF helloworld.tmp result.tmp
Yann Collet4c5bbf62016-07-28 20:30:25 +0200268$ECHO "frame concatenation without checksum"
269$ZSTD -c hello.tmp > hello.zstd --no-check
270$ZSTD -c world.tmp > world.zstd --no-check
271cat hello.zstd world.zstd > helloworld.zstd
272$ZSTD -dc helloworld.zstd > result.tmp
Yann Colletbd6bc222017-01-22 15:54:14 -0800273$DIFF helloworld.tmp result.tmp
Yann Colletcb5eba82018-01-19 11:26:35 -0800274$ECHO "testing zstdcat symlink"
275ln -sf $ZSTD zstdcat
276./zstdcat helloworld.zstd > result.tmp
277$DIFF helloworld.tmp result.tmp
278rm zstdcat
279rm result.tmp
280$ECHO "testing zcat symlink"
281ln -sf $ZSTD zcat
282./zcat helloworld.zstd > result.tmp
283$DIFF helloworld.tmp result.tmp
284rm zcat
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300285rm ./*.tmp ./*.zstd
inikep5d589562016-05-25 10:50:28 +0200286$ECHO "frame concatenation tests completed"
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300287
Yann Colletf0624362016-02-12 15:56:46 +0100288
bketdaf3ab02018-04-02 23:12:18 +0200289if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] && [ "$UNAME" != "OpenBSD" ] ; then
inikep5d589562016-05-25 10:50:28 +0200290$ECHO "\n**** flush write error test **** "
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300291
inikep5d589562016-05-25 10:50:28 +0200292$ECHO "$ECHO foo | $ZSTD > /dev/full"
293$ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
294$ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
295$ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
Sean Purcell680e4e02017-03-23 11:52:09 -0700296
Yann Collet01a1abf2017-05-05 19:15:24 -0700297
Yann Collet241c57a2017-10-16 14:01:42 -0700298$ECHO "\n===> symbolic link test "
Sean Purcell680e4e02017-03-23 11:52:09 -0700299
300rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
301$ECHO "hello world" > hello.tmp
302ln -s hello.tmp world.tmp
303$ZSTD world.tmp hello.tmp
Yann Collet01a1abf2017-05-05 19:15:24 -0700304test -f hello.tmp.zst # regular file should have been compressed!
305test ! -f world.tmp.zst # symbolic link should not have been compressed!
Sean Purcell680e4e02017-03-23 11:52:09 -0700306$ZSTD world.tmp hello.tmp -f
Yann Collet01a1abf2017-05-05 19:15:24 -0700307test -f world.tmp.zst # symbolic link should have been compressed with --force
Sean Purcell680e4e02017-03-23 11:52:09 -0700308rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
309
inikep5d589562016-05-25 10:50:28 +0200310fi
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300311
Yann Collet6a458352015-12-18 02:51:14 +0100312
Yann Collet241c57a2017-10-16 14:01:42 -0700313$ECHO "\n===> test sparse file support "
Yann Collet32990b52016-05-23 17:48:57 +0200314
315./datagen -g5M -P100 > tmpSparse
316$ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100317$DIFF -s tmpSparse tmpSparseRegen
Yann Collet32990b52016-05-23 17:48:57 +0200318$ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100319$DIFF -s tmpSparse tmpOutSparse
Yann Collet32990b52016-05-23 17:48:57 +0200320$ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100321$DIFF -s tmpSparse tmpOutNoSparse
Yann Collet01a1abf2017-05-05 19:15:24 -0700322ls -ls tmpSparse* # look at file size and block size on disk
Yann Collet32990b52016-05-23 17:48:57 +0200323./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 +0100324./datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
Yann Collet01a1abf2017-05-05 19:15:24 -0700325ls -ls tmpSparseOdd # look at file size and block size on disk
inikep5d589562016-05-25 10:50:28 +0200326$ECHO "\n Sparse Compatibility with Console :"
327$ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
328$ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
329$ECHO "\n Sparse Compatibility with Append :"
Yann Collet32990b52016-05-23 17:48:57 +0200330./datagen -P100 -g1M > tmpSparse1M
331cat tmpSparse1M tmpSparse1M > tmpSparse2M
332$ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
333$ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
334$ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
Yann Collet01a1abf2017-05-05 19:15:24 -0700335ls -ls tmpSparse* # look at file size and block size on disk
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100336$DIFF tmpSparse2M tmpSparseRegenerated
Yann Collet33341de2016-05-29 23:09:51 +0200337rm tmpSparse*
Yann Collet32990b52016-05-23 17:48:57 +0200338
339
Yann Collet241c57a2017-10-16 14:01:42 -0700340$ECHO "\n===> multiple files tests "
Yann Collet9b998e42016-06-15 23:11:20 +0200341
Yann Collet391a1282016-06-21 17:06:25 +0200342./datagen -s1 > tmp1 2> $INTOVOID
343./datagen -s2 -g100K > tmp2 2> $INTOVOID
344./datagen -s3 -g1M > tmp3 2> $INTOVOID
Yann Collet9b998e42016-06-15 23:11:20 +0200345$ECHO "compress tmp* : "
Yann Collet60ba31c2016-07-28 19:55:09 +0200346$ZSTD -f tmp*
Yann Collet9b998e42016-06-15 23:11:20 +0200347ls -ls tmp*
348rm tmp1 tmp2 tmp3
349$ECHO "decompress tmp* : "
350$ZSTD -df *.zst
351ls -ls tmp*
352$ECHO "compress tmp* into stdout > tmpall : "
353$ZSTD -c tmp1 tmp2 tmp3 > tmpall
Yann Collet01a1abf2017-05-05 19:15:24 -0700354ls -ls tmp* # check size of tmpall (should be tmp1.zst + tmp2.zst + tmp3.zst)
Yann Collet9b998e42016-06-15 23:11:20 +0200355$ECHO "decompress tmpall* into stdout > tmpdec : "
356cp tmpall tmpall2
357$ZSTD -dc tmpall* > tmpdec
Yann Collet01a1abf2017-05-05 19:15:24 -0700358ls -ls tmp* # check size of tmpdec (should be 2*(tmp1 + tmp2 + tmp3))
Yann Collet9b998e42016-06-15 23:11:20 +0200359$ECHO "compress multiple files including a missing one (notHere) : "
360$ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
361
362
Yann Collet241c57a2017-10-16 14:01:42 -0700363$ECHO "\n===> dictionary tests "
Yann Colletf6f3d752015-12-13 13:35:21 +0100364
Yann Colletbd7fa212017-02-26 14:43:07 -0800365$ECHO "- test with raw dict (content only) "
Yann Colletf6f3d752015-12-13 13:35:21 +0100366./datagen > tmpDict
inikep93fc13e2016-05-30 10:17:55 +0200367./datagen -g1M | $MD5SUM > tmp1
368./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100369$DIFF -q tmp1 tmp2
Yann Colletbd7fa212017-02-26 14:43:07 -0800370$ECHO "- Create first dictionary "
371TESTFILE=../programs/zstdcli.c
inikepb7d34492016-08-18 15:13:41 +0200372$ZSTD --train *.c ../programs/*.c -o tmpDict
373cp $TESTFILE tmp
Yann Colletd228b6b2017-12-29 19:14:18 +0100374$ECHO "- Dictionary compression roundtrip"
Yann Collet6381e992016-05-31 02:29:45 +0200375$ZSTD -f tmp -D tmpDict
Yann Collet27b5ac62016-09-21 14:20:56 +0200376$ZSTD -d tmp.zst -D tmpDict -fo result
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100377$DIFF $TESTFILE result
Yann Colletd228b6b2017-12-29 19:14:18 +0100378$ECHO "- Dictionary compression with btlazy2 strategy"
379$ZSTD -f tmp -D tmpDict --zstd=strategy=6
380$ZSTD -d tmp.zst -D tmpDict -fo result
381$DIFF $TESTFILE result
Yann Collet311878d2017-12-13 11:48:30 -0800382if [ -n "$hasMT" ]
383then
384 $ECHO "- Test dictionary compression with multithreading "
Yann Collet281f06e2017-12-14 11:47:02 -0800385 ./datagen -g5M | $ZSTD -T2 -D tmpDict | $ZSTD -t -D tmpDict # fails with v1.3.2
Yann Collet311878d2017-12-13 11:48:30 -0800386fi
Yann Colletbd7fa212017-02-26 14:43:07 -0800387$ECHO "- Create second (different) dictionary "
inikepb7d34492016-08-18 15:13:41 +0200388$ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
Yann Collet27b5ac62016-09-21 14:20:56 +0200389$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
Yann Collet531a4272016-06-15 19:02:11 +0200390$ECHO "- Create dictionary with short dictID"
Yann Collet4c41d372017-03-24 18:36:56 -0700391$ZSTD --train *.c ../programs/*.c --dictID=1 -o tmpDict1
Yann Collet290aaa72016-05-30 21:18:52 +0200392cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
Yann Collet27b5ac62016-09-21 14:20:56 +0200393$ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
394$ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
395$ECHO "- Create dictionary with size limit"
Yann Collet4c41d372017-03-24 18:36:56 -0700396$ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict=4K -v
Nick Terrell35875562017-08-21 11:16:47 -0700397$ECHO "- Create dictionary with small size limit"
398$ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict=1K -v
Yann Collet27b5ac62016-09-21 14:20:56 +0200399$ECHO "- Create dictionary with wrong parameter order (must fail)"
Nick Terrell35875562017-08-21 11:16:47 -0700400$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 +0200401$ECHO "- Compress without dictID"
Yann Collet6381e992016-05-31 02:29:45 +0200402$ZSTD -f tmp -D tmpDict1 --no-dictID
Yann Collet27b5ac62016-09-21 14:20:56 +0200403$ZSTD -d tmp.zst -D tmpDict -fo result
Przemyslaw Skibinski5f5a9022016-12-22 18:05:07 +0100404$DIFF $TESTFILE result
Yann Collet27b5ac62016-09-21 14:20:56 +0200405$ECHO "- Compress with wrong argument order (must fail)"
Sean Purcell9a38dfa2017-03-17 12:32:18 -0700406$ZSTD tmp -Df tmpDict1 -c > $INTOVOID && die "-D must be followed by dictionary name "
Yann Collet531a4272016-06-15 19:02:11 +0200407$ECHO "- Compress multiple files with dictionary"
Yann Collet531a4272016-06-15 19:02:11 +0200408rm -rf dirTestDict
409mkdir dirTestDict
410cp *.c dirTestDict
inikepb7d34492016-08-18 15:13:41 +0200411cp ../programs/*.c dirTestDict
412cp ../programs/*.h dirTestDict
Yann Collet94376ac2016-08-25 19:09:21 +0200413$MD5SUM dirTestDict/* > tmph1
414$ZSTD -f --rm dirTestDict/* -D tmpDictC
Yann Colletbb93d772016-08-25 22:22:50 +0200415$ZSTD -d --rm dirTestDict/*.zst -D tmpDictC # note : use internal checksum by default
Dimitry Andric12df6da2016-12-12 19:22:47 +0100416case "$UNAME" in
417 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 -0800418 *) $MD5SUM -c tmph1 ;;
419esac
Yann Collet531a4272016-06-15 19:02:11 +0200420rm -rf dirTestDict
Yann Colletf332ece2017-03-23 16:24:02 -0700421$ECHO "- dictionary builder on bogus input"
422$ECHO "Hello World" > tmp
Nick Terrellf376d472017-05-01 23:40:20 -0700423$ZSTD --train-legacy -q tmp && die "Dictionary training should fail : not enough input source"
Yann Colletf332ece2017-03-23 16:24:02 -0700424./datagen -P0 -g10M > tmp
Nick Terrellf376d472017-05-01 23:40:20 -0700425$ZSTD --train-legacy -q tmp && die "Dictionary training should fail : source is pure noise"
Nick Terrell58b82192018-07-09 18:24:07 -0700426$ECHO "- Test -o before --train"
427rm -f tmpDict dictionary
428$ZSTD -o tmpDict --train *.c ../programs/*.c
429test -f tmpDict
430$ZSTD --train *.c ../programs/*.c
431test -f dictionary
432rm tmp* dictionary
Yann Colletb44be742016-03-26 20:52:14 +0100433
Yann Colletf6f3d752015-12-13 13:35:21 +0100434
Jennifer Liu9d6ed9d2018-08-23 12:06:20 -0700435$ECHO "\n===> fastCover dictionary builder : advanced options "
436
437TESTFILE=../programs/zstdcli.c
438./datagen > tmpDict
439$ECHO "- Create first dictionary"
440$ZSTD --train-fastcover=k=46,d=8,f=15,split=80 *.c ../programs/*.c -o tmpDict
441cp $TESTFILE tmp
442$ZSTD -f tmp -D tmpDict
443$ZSTD -d tmp.zst -D tmpDict -fo result
444$DIFF $TESTFILE result
445$ECHO "- Create second (different) dictionary"
446$ZSTD --train-fastcover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
447$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
448$ECHO "- Create dictionary with short dictID"
449$ZSTD --train-fastcover=k=46,d=8,f=15,split=80 *.c ../programs/*.c --dictID=1 -o tmpDict1
450cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
451$ECHO "- Create dictionary with size limit"
452$ZSTD --train-fastcover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
453$ECHO "- Compare size of dictionary from 90% training samples with 80% training samples"
454$ZSTD --train-fastcover=split=90 -r *.c ../programs/*.c
455$ZSTD --train-fastcover=split=80 -r *.c ../programs/*.c
456$ECHO "- Create dictionary using all samples for both training and testing"
457$ZSTD --train-fastcover=split=100 -r *.c ../programs/*.c
458$ECHO "- Create dictionary using f=16"
459$ZSTD --train-fastcover=f=16 -r *.c ../programs/*.c
460$ECHO "- Create dictionary using accel=2"
461$ZSTD --train-fastcover=accel=2 -r *.c ../programs/*.c
462$ECHO "- Create dictionary using accel=10"
463$ZSTD --train-fastcover=accel=10 -r *.c ../programs/*.c
464$ECHO "- Create dictionary with multithreading"
465$ZSTD --train-fastcover -T4 -r *.c ../programs/*.c
466$ECHO "- Test -o before --train-fastcover"
467rm -f tmpDict dictionary
468$ZSTD -o tmpDict --train-fastcover *.c ../programs/*.c
469test -f tmpDict
470$ZSTD --train-fastcover *.c ../programs/*.c
471test -f dictionary
472rm tmp* dictionary
473
474
Yann Collet241c57a2017-10-16 14:01:42 -0700475$ECHO "\n===> legacy dictionary builder "
Nick Terrellf376d472017-05-01 23:40:20 -0700476
477TESTFILE=../programs/zstdcli.c
478./datagen > tmpDict
479$ECHO "- Create first dictionary"
480$ZSTD --train-legacy=selectivity=8 *.c ../programs/*.c -o tmpDict
481cp $TESTFILE tmp
482$ZSTD -f tmp -D tmpDict
483$ZSTD -d tmp.zst -D tmpDict -fo result
484$DIFF $TESTFILE result
485$ECHO "- Create second (different) dictionary"
486$ZSTD --train-legacy=s=5 *.c ../programs/*.c ../programs/*.h -o tmpDictC
487$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
488$ECHO "- Create dictionary with short dictID"
489$ZSTD --train-legacy -s5 *.c ../programs/*.c --dictID=1 -o tmpDict1
490cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
491$ECHO "- Create dictionary with size limit"
492$ZSTD --train-legacy -s9 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
Nick Terrell58b82192018-07-09 18:24:07 -0700493$ECHO "- Test -o before --train-legacy"
494rm -f tmpDict dictionary
495$ZSTD -o tmpDict --train-legacy *.c ../programs/*.c
496test -f tmpDict
497$ZSTD --train-legacy *.c ../programs/*.c
498test -f dictionary
499rm tmp* dictionary
Nick Terrellcbb3ce32017-01-01 01:59:51 -0500500
501
Yann Collet241c57a2017-10-16 14:01:42 -0700502$ECHO "\n===> integrity tests "
Yann Colletde95f962016-05-23 19:46:47 +0200503
inikep5d589562016-05-25 10:50:28 +0200504$ECHO "test one file (tmp1.zst) "
Yann Collet1a7b8fb2016-06-15 23:33:38 +0200505./datagen > tmp1
506$ZSTD tmp1
Yann Collet459a6b72016-02-15 20:37:23 +0100507$ZSTD -t tmp1.zst
Yann Collet2d08b092016-02-16 14:42:08 +0100508$ZSTD --test tmp1.zst
inikep5d589562016-05-25 10:50:28 +0200509$ECHO "test multiple files (*.zst) "
Yann Collet459a6b72016-02-15 20:37:23 +0100510$ZSTD -t *.zst
Yann Collet24a3d902016-07-26 01:26:56 +0200511$ECHO "test bad files (*) "
Yann Collet459a6b72016-02-15 20:37:23 +0100512$ZSTD -t * && die "bad files not detected !"
Yann Collet24a3d902016-07-26 01:26:56 +0200513$ZSTD -t tmp1 && die "bad file not detected !"
514cp tmp1 tmp2.zst
515$ZSTD -t tmp2.zst && die "bad file not detected !"
Yann Collet7adc2322016-07-26 15:39:31 +0200516./datagen -g0 > tmp3
517$ZSTD -t tmp3 && die "bad file not detected !" # detects 0-sized files as bad
Yann Colletb4024902016-07-26 00:49:47 +0200518$ECHO "test --rm and --test combined "
519$ZSTD -t --rm tmp1.zst
Yann Collet01a1abf2017-05-05 19:15:24 -0700520test -f tmp1.zst # check file is still present
521split -b16384 tmp1.zst tmpSplit.
522$ZSTD -t tmpSplit.* && die "bad file not detected !"
Nick Terrelld0b27482017-07-18 14:45:49 -0700523./datagen | $ZSTD -c | $ZSTD -t
Yann Colletdeb078b2015-12-17 20:30:14 +0100524
Yann Colletde95f962016-05-23 19:46:47 +0200525
Nick Terrellabe12b32017-07-28 11:54:28 -0700526
Yann Collet241c57a2017-10-16 14:01:42 -0700527$ECHO "\n===> golden files tests "
Nick Terrellabe12b32017-07-28 11:54:28 -0700528
529$ZSTD -t -r files
530$ZSTD -c -r files | $ZSTD -t
531
532
Yann Collet241c57a2017-10-16 14:01:42 -0700533$ECHO "\n===> benchmark mode tests "
Yann Colletb9550d62016-10-28 14:43:24 -0700534
535$ECHO "bench one file"
536./datagen > tmp1
Yann Colletc1c040e2017-03-01 16:49:20 -0800537$ZSTD -bi0 tmp1
Yann Colletb9550d62016-10-28 14:43:24 -0700538$ECHO "bench multiple levels"
Yann Colletc1c040e2017-03-01 16:49:20 -0800539$ZSTD -i0b0e3 tmp1
Yann Collet6a9b41b2018-03-11 19:56:48 -0700540$ECHO "bench negative level"
541$ZSTD -bi0 --fast tmp1
Yann Colletb9550d62016-10-28 14:43:24 -0700542$ECHO "with recursive and quiet modes"
Yann Colletc1c040e2017-03-01 16:49:20 -0800543$ZSTD -rqi1b1e2 tmp1
Yann Colletf40c6b42018-11-08 12:51:42 -0800544$ECHO "benchmark decompression only"
545$ZSTD -f tmp1
546$ZSTD -b -d -i1 tmp1.zst
Yann Colletc1c040e2017-03-01 16:49:20 -0800547
George Lucfc34512018-06-01 09:52:25 -0700548$ECHO "\n===> zstd compatibility tests "
549
550./datagen > tmp
George Lu41249bf2018-06-01 10:54:51 -0700551rm -f tmp.zst
552$ZSTD --format=zstd -f tmp
553test -f tmp.zst
Yann Colletc1c040e2017-03-01 16:49:20 -0800554
Yann Collet241c57a2017-10-16 14:01:42 -0700555$ECHO "\n===> gzip compatibility tests "
Yann Colletc1c040e2017-03-01 16:49:20 -0800556
557GZIPMODE=1
558$ZSTD --format=gzip -V || GZIPMODE=0
559if [ $GZIPMODE -eq 1 ]; then
Yann Collet27526c72017-03-01 17:02:49 -0800560 $ECHO "gzip support detected"
Yann Colletc1c040e2017-03-01 16:49:20 -0800561 GZIPEXE=1
Yann Collet27526c72017-03-01 17:02:49 -0800562 gzip -V || GZIPEXE=0
Yann Colletc1c040e2017-03-01 16:49:20 -0800563 if [ $GZIPEXE -eq 1 ]; then
564 ./datagen > tmp
565 $ZSTD --format=gzip -f tmp
566 gzip -t -v tmp.gz
567 gzip -f tmp
568 $ZSTD -d -f -v tmp.gz
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700569 rm tmp*
Yann Colletc1c040e2017-03-01 16:49:20 -0800570 else
571 $ECHO "gzip binary not detected"
572 fi
573else
574 $ECHO "gzip mode not supported"
575fi
Yann Colletb9550d62016-10-28 14:43:24 -0700576
577
Yann Collet241c57a2017-10-16 14:01:42 -0700578$ECHO "\n===> gzip frame tests "
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700579
580if [ $GZIPMODE -eq 1 ]; then
581 ./datagen > tmp
582 $ZSTD -f --format=gzip tmp
583 $ZSTD -f tmp
584 cat tmp.gz tmp.zst tmp.gz tmp.zst | $ZSTD -d -f -o tmp
Björn Ketelaars06fd1e42018-06-30 15:42:42 +0200585 truncateLastByte tmp.gz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700586 rm tmp*
587else
588 $ECHO "gzip mode not supported"
589fi
590
George Lu41249bf2018-06-01 10:54:51 -0700591if [ $GZIPMODE -eq 1 ]; then
592 ./datagen > tmp
593 rm -f tmp.zst
Jennifer Liuaef84862018-06-27 14:27:27 -0700594 $ZSTD --format=gzip --format=zstd -f tmp
George Lu41249bf2018-06-01 10:54:51 -0700595 test -f tmp.zst
596fi
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700597
Yann Collet241c57a2017-10-16 14:01:42 -0700598$ECHO "\n===> xz compatibility tests "
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700599
600LZMAMODE=1
601$ZSTD --format=xz -V || LZMAMODE=0
602if [ $LZMAMODE -eq 1 ]; then
603 $ECHO "xz support detected"
604 XZEXE=1
Björn Ketelaars527dbf82018-06-30 13:22:14 +0200605 xz -Q -V && lzma -Q -V || XZEXE=0
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700606 if [ $XZEXE -eq 1 ]; then
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700607 $ECHO "Testing zstd xz and lzma support"
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700608 ./datagen > tmp
609 $ZSTD --format=lzma -f tmp
610 $ZSTD --format=xz -f tmp
Björn Ketelaars527dbf82018-06-30 13:22:14 +0200611 xz -Q -t -v tmp.xz
612 xz -Q -t -v tmp.lzma
613 xz -Q -f -k tmp
614 lzma -Q -f -k --lzma1 tmp
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700615 $ZSTD -d -f -v tmp.xz
616 $ZSTD -d -f -v tmp.lzma
617 rm tmp*
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700618 $ECHO "Creating symlinks"
619 ln -s $ZSTD ./xz
620 ln -s $ZSTD ./unxz
621 ln -s $ZSTD ./lzma
622 ln -s $ZSTD ./unlzma
623 $ECHO "Testing xz and lzma symlinks"
624 ./datagen > tmp
625 ./xz tmp
Björn Ketelaars527dbf82018-06-30 13:22:14 +0200626 xz -Q -d tmp.xz
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700627 ./lzma tmp
Björn Ketelaars527dbf82018-06-30 13:22:14 +0200628 lzma -Q -d tmp.lzma
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700629 $ECHO "Testing unxz and unlzma symlinks"
Björn Ketelaars527dbf82018-06-30 13:22:14 +0200630 xz -Q tmp
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700631 ./xz -d tmp.xz
Björn Ketelaars527dbf82018-06-30 13:22:14 +0200632 lzma -Q tmp
Nick Terrell6aeb50e2017-06-26 11:24:36 -0700633 ./lzma -d tmp.lzma
634 rm xz unxz lzma unlzma
635 rm tmp*
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700636 else
637 $ECHO "xz binary not detected"
638 fi
639else
640 $ECHO "xz mode not supported"
641fi
642
643
Yann Collet241c57a2017-10-16 14:01:42 -0700644$ECHO "\n===> xz frame tests "
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700645
646if [ $LZMAMODE -eq 1 ]; then
647 ./datagen > tmp
648 $ZSTD -f --format=xz tmp
649 $ZSTD -f --format=lzma tmp
650 $ZSTD -f tmp
651 cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | $ZSTD -d -f -o tmp
Björn Ketelaars06fd1e42018-06-30 15:42:42 +0200652 truncateLastByte tmp.xz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
653 truncateLastByte tmp.lzma | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700654 rm tmp*
655else
656 $ECHO "xz mode not supported"
657fi
658
Yann Collet241c57a2017-10-16 14:01:42 -0700659$ECHO "\n===> lz4 compatibility tests "
Sean Purcell4de86322017-04-24 16:48:25 -0700660
661LZ4MODE=1
662$ZSTD --format=lz4 -V || LZ4MODE=0
663if [ $LZ4MODE -eq 1 ]; then
664 $ECHO "lz4 support detected"
665 LZ4EXE=1
666 lz4 -V || LZ4EXE=0
667 if [ $LZ4EXE -eq 1 ]; then
668 ./datagen > tmp
669 $ZSTD --format=lz4 -f tmp
670 lz4 -t -v tmp.lz4
671 lz4 -f tmp
672 $ZSTD -d -f -v tmp.lz4
673 rm tmp*
674 else
675 $ECHO "lz4 binary not detected"
676 fi
677else
678 $ECHO "lz4 mode not supported"
679fi
680
681
Yann Collet241c57a2017-10-16 14:01:42 -0700682$ECHO "\n===> lz4 frame tests "
Sean Purcell4de86322017-04-24 16:48:25 -0700683
684if [ $LZ4MODE -eq 1 ]; then
685 ./datagen > tmp
686 $ZSTD -f --format=lz4 tmp
687 $ZSTD -f tmp
688 cat tmp.lz4 tmp.zst tmp.lz4 tmp.zst | $ZSTD -d -f -o tmp
Björn Ketelaars06fd1e42018-06-30 15:42:42 +0200689 truncateLastByte tmp.lz4 | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
Sean Purcell4de86322017-04-24 16:48:25 -0700690 rm tmp*
691else
692 $ECHO "lz4 mode not supported"
693fi
Nick Terrellaa8bcf32017-03-13 18:11:07 -0700694
George Lu53ea32c2018-06-01 10:43:06 -0700695$ECHO "\n===> suffix list test"
696
George Lu110ec902018-06-01 12:45:02 -0700697! $ZSTD -d tmp.abc 2> tmplg
George Lu53ea32c2018-06-01 10:43:06 -0700698
Jennifer Liuaef84862018-06-27 14:27:27 -0700699if [ $GZIPMODE -ne 1 ]; then
George Lu53ea32c2018-06-01 10:43:06 -0700700 grep ".gz" tmplg > $INTOVOID && die "Unsupported suffix listed"
701fi
702
Jennifer Liuaef84862018-06-27 14:27:27 -0700703if [ $LZMAMODE -ne 1 ]; then
George Lu53ea32c2018-06-01 10:43:06 -0700704 grep ".lzma" tmplg > $INTOVOID && die "Unsupported suffix listed"
705 grep ".xz" tmplg > $INTOVOID && die "Unsupported suffix listed"
706fi
707
708if [ $LZ4MODE -ne 1 ]; then
709 grep ".lz4" tmplg > $INTOVOID && die "Unsupported suffix listed"
710fi
711
Yann Collet241c57a2017-10-16 14:01:42 -0700712$ECHO "\n===> zstd round-trip tests "
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300713
714roundTripTest
Yann Collet3b719252016-03-30 19:48:05 +0200715roundTripTest -g15K # TableID==3
716roundTripTest -g127K # TableID==2
717roundTripTest -g255K # TableID==1
Yann Colletc1c040e2017-03-01 16:49:20 -0800718roundTripTest -g522K # TableID==0
719roundTripTest -g519K 6 # greedy, hash chain
720roundTripTest -g517K 16 # btlazy2
721roundTripTest -g516K 19 # btopt
Yann Collet459a6b72016-02-15 20:37:23 +0100722
Sean Purcelleb70d212017-04-11 17:15:13 -0700723fileRoundTripTest -g500K
724
Yann Collet241c57a2017-10-16 14:01:42 -0700725$ECHO "\n===> zstd long distance matching round-trip tests "
Nick Terrellf15a17e2018-02-27 20:09:18 -0800726roundTripTest -g0 "2 --single-thread --long"
727roundTripTest -g1000K "1 --single-thread --long"
728roundTripTest -g517K "6 --single-thread --long"
729roundTripTest -g516K "16 --single-thread --long"
730roundTripTest -g518K "19 --single-thread --long"
731fileRoundTripTest -g5M "3 --single-thread --long"
Stella Lau6a546ef2017-07-28 15:51:33 -0700732
733
Yann Collet75689832018-02-09 15:53:27 -0800734roundTripTest -g96K "5 --single-thread"
Sean Purcellc424ec22017-04-17 11:38:53 -0700735if [ -n "$hasMT" ]
736then
Yann Collet241c57a2017-10-16 14:01:42 -0700737 $ECHO "\n===> zstdmt round-trip tests "
Sean Purcelld845dab2017-04-17 12:10:58 -0700738 roundTripTest -g4M "1 -T0"
739 roundTripTest -g8M "3 -T2"
Yann Collet230d7ac2017-04-21 11:38:13 -0700740 roundTripTest -g8000K "2 --threads=2"
Sean Purcelld845dab2017-04-17 12:10:58 -0700741 fileRoundTripTest -g4M "19 -T2 -B1M"
Stella Lau6a546ef2017-07-28 15:51:33 -0700742
Yann Collet241c57a2017-10-16 14:01:42 -0700743 $ECHO "\n===> zstdmt long distance matching round-trip tests "
Nick Terrellf15a17e2018-02-27 20:09:18 -0800744 roundTripTest -g8M "3 --long=24 -T2"
Yann Collet96b480a2018-03-29 13:07:28 -0600745
746 $ECHO "\n===> ovLog tests "
747 ./datagen -g2MB > tmp
748 refSize=$($ZSTD tmp -6 -c --zstd=wlog=18 | wc -c)
749 ov9Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=9 | wc -c)
750 ov0Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=0 | wc -c)
751 if [ $refSize -eq $ov9Size ]; then
752 echo ov9Size should be different from refSize
753 exit 1
754 fi
755 if [ $refSize -eq $ov0Size ]; then
756 echo ov0Size should be different from refSize
757 exit 1
758 fi
759 if [ $ov9Size -ge $ov0Size ]; then
760 echo ov9Size=$ov9Size should be smaller than ov0Size=$ov0Size
761 exit 1
762 fi
763
Sean Purcellc424ec22017-04-17 11:38:53 -0700764else
Yann Collet241c57a2017-10-16 14:01:42 -0700765 $ECHO "\n===> no multithreading, skipping zstdmt tests "
Sean Purcellc424ec22017-04-17 11:38:53 -0700766fi
767
Yann Collet459a6b72016-02-15 20:37:23 +0100768rm tmp*
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300769
Yann Collet241c57a2017-10-16 14:01:42 -0700770$ECHO "\n===> zstd --list/-l single frame tests "
Paul Cruzddd1ab72017-06-15 16:53:03 -0700771./datagen > tmp1
772./datagen > tmp2
773./datagen > tmp3
Paul Cruzddd1ab72017-06-15 16:53:03 -0700774$ZSTD tmp*
Paul Cruz6a99de22017-06-20 10:45:06 -0700775$ZSTD -l *.zst
Yann Collet43914f62017-10-13 23:47:01 -0700776$ZSTD -lv *.zst | grep "Decompressed Size:" # check that decompressed size is present in header
Paul Cruz6a99de22017-06-20 10:45:06 -0700777$ZSTD --list *.zst
778$ZSTD --list -v *.zst
Paul Cruzddd1ab72017-06-15 16:53:03 -0700779
Yann Collet241c57a2017-10-16 14:01:42 -0700780$ECHO "\n===> zstd --list/-l multiple frame tests "
Paul Cruzddd1ab72017-06-15 16:53:03 -0700781cat tmp1.zst tmp2.zst > tmp12.zst
Yann Collet60059df2017-09-27 15:16:27 -0700782cat tmp12.zst tmp3.zst > tmp123.zst
Paul Cruz6a99de22017-06-20 10:45:06 -0700783$ZSTD -l *.zst
784$ZSTD -lv *.zst
Paul Cruzddd1ab72017-06-15 16:53:03 -0700785
Yann Collet241c57a2017-10-16 14:01:42 -0700786$ECHO "\n===> zstd --list/-l error detection tests "
Yann Collet63abaf22018-09-25 15:57:28 -0700787$ZSTD -l tmp1 tmp1.zst && die "-l must fail on non-zstd file"
788$ZSTD --list tmp* && die "-l must fail on non-zstd file"
789$ZSTD -lv tmp1* && die "-l must fail on non-zstd file"
790$ZSTD --list -v tmp2 tmp12.zst && die "-l must fail on non-zstd file"
Paul Cruzb07d0af2017-06-20 11:54:44 -0700791
W. Felix Handte8e7bdc12018-06-29 16:31:22 -0400792$ECHO "\n===> zstd --list/-l errors when presented with stdin / no files"
Yann Collet63abaf22018-09-25 15:57:28 -0700793$ZSTD -l && die "-l must fail on empty list of files"
794$ZSTD -l - && die "-l does not work on stdin"
795$ZSTD -l < tmp1.zst && die "-l does not work on stdin"
796$ZSTD -l - < tmp1.zst && die "-l does not work on stdin"
797$ZSTD -l - tmp1.zst && die "-l does not work on stdin"
798$ZSTD -l - tmp1.zst < tmp1.zst && die "-l does not work on stdin"
799$ZSTD -l tmp1.zst < tmp2.zst # this will check tmp1.zst, but not tmp2.zst, which is not an error : zstd simply doesn't read stdin in this case. It must not error just because stdin is not a tty
Topher Lubaway5bac1db2018-06-19 09:56:37 -0700800
Yann Collet241c57a2017-10-16 14:01:42 -0700801$ECHO "\n===> zstd --list/-l test with null files "
Paul Cruza73c2a42017-06-20 14:33:08 -0700802./datagen -g0 > tmp5
803$ZSTD tmp5
Yann Colletc16748b2017-06-21 12:09:53 -0700804$ZSTD -l tmp5.zst
Yann Collet63abaf22018-09-25 15:57:28 -0700805$ZSTD -l tmp5* && die "-l must fail on non-zstd file"
Yann Collet5891f1d2017-10-17 16:23:20 -0700806$ZSTD -lv tmp5.zst | grep "Decompressed Size: 0.00 KB (0 B)" # check that 0 size is present in header
Yann Collet63abaf22018-09-25 15:57:28 -0700807$ZSTD -lv tmp5* && die "-l must fail on non-zstd file"
Paul Cruza73c2a42017-06-20 14:33:08 -0700808
Yann Collet241c57a2017-10-16 14:01:42 -0700809$ECHO "\n===> zstd --list/-l test with no content size field "
Yann Collet43914f62017-10-13 23:47:01 -0700810./datagen -g513K | $ZSTD > tmp6.zst
Paul Cruzdb3606e2017-06-20 17:43:36 -0700811$ZSTD -l tmp6.zst
Yann Collet63abaf22018-09-25 15:57:28 -0700812$ZSTD -lv tmp6.zst | grep "Decompressed Size:" && die "Field :Decompressed Size: should not be available in this compressed file"
Yann Colletc16748b2017-06-21 12:09:53 -0700813
Yann Collet241c57a2017-10-16 14:01:42 -0700814$ECHO "\n===> zstd --list/-l test with no checksum "
Yann Colletc16748b2017-06-21 12:09:53 -0700815$ZSTD -f --no-check tmp1
816$ZSTD -l tmp1.zst
817$ZSTD -lv tmp1.zst
Paul Cruzdb3606e2017-06-20 17:43:36 -0700818
Paul Cruzddd1ab72017-06-15 16:53:03 -0700819rm tmp*
820
Yann Colletc16748b2017-06-21 12:09:53 -0700821
Yann Collet241c57a2017-10-16 14:01:42 -0700822$ECHO "\n===> zstd long distance matching tests "
Nick Terrellf15a17e2018-02-27 20:09:18 -0800823roundTripTest -g0 " --single-thread --long"
824roundTripTest -g9M "2 --single-thread --long"
Yann Collet02502192017-09-27 15:48:06 -0700825# Test parameter parsing
Nick Terrellf15a17e2018-02-27 20:09:18 -0800826roundTripTest -g1M -P50 "1 --single-thread --long=29" " --memory=512MB"
827roundTripTest -g1M -P50 "1 --single-thread --long=29 --zstd=wlog=28" " --memory=256MB"
828roundTripTest -g1M -P50 "1 --single-thread --long=29" " --long=28 --memory=512MB"
829roundTripTest -g1M -P50 "1 --single-thread --long=29" " --zstd=wlog=28 --memory=512MB"
Yann Collet02502192017-09-27 15:48:06 -0700830
831
Yann Collet6c51bf42018-09-24 18:16:08 -0700832$ECHO "\n===> adaptive mode "
833roundTripTest -g270000000 " --adapt"
834roundTripTest -g27000000 " --adapt=min=1,max=4"
Yann Collet9012b6c2018-10-01 17:16:34 -0700835$ECHO "===> test: --adapt must fail on incoherent bounds "
Yann Collet6c51bf42018-09-24 18:16:08 -0700836./datagen > tmp
837$ZSTD -f -vv --adapt=min=10,max=9 tmp && die "--adapt must fail on incoherent bounds"
838
Nick Terrell71fe78c2018-11-14 13:53:14 -0800839$ECHO "\n===> rsyncable mode "
840roundTripTest -g10M " --rsyncable"
841roundTripTest -g10M " --rsyncable -B100K"
842$ECHO "===> test: --rsyncable must fail with --single-thread"
843$ZSTD -f -vv --rsyncable --single-thread tmp && die "--rsyncable must fail with --single-thread"
844
Yann Collet6c51bf42018-09-24 18:16:08 -0700845
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300846if [ "$1" != "--test-large-data" ]; then
inikep5d589562016-05-25 10:50:28 +0200847 $ECHO "Skipping large data tests"
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300848 exit 0
849fi
850
Yann Collet6c51bf42018-09-24 18:16:08 -0700851
Yann Collet9012b6c2018-10-01 17:16:34 -0700852#############################################################################
Yann Collet6c51bf42018-09-24 18:16:08 -0700853
Yann Collet241c57a2017-10-16 14:01:42 -0700854$ECHO "\n===> large files tests "
Yann Collet02502192017-09-27 15:48:06 -0700855
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300856roundTripTest -g270000000 1
Yann Collet60059df2017-09-27 15:16:27 -0700857roundTripTest -g250000000 2
858roundTripTest -g230000000 3
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300859
860roundTripTest -g140000000 -P60 4
Yann Collet60059df2017-09-27 15:16:27 -0700861roundTripTest -g130000000 -P62 5
862roundTripTest -g120000000 -P65 6
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300863
864roundTripTest -g70000000 -P70 7
Yann Collet60059df2017-09-27 15:16:27 -0700865roundTripTest -g60000000 -P71 8
866roundTripTest -g50000000 -P73 9
Konstantin Tokarev76be3782015-12-08 18:36:37 +0300867
868roundTripTest -g35000000 -P75 10
Yann Collet60059df2017-09-27 15:16:27 -0700869roundTripTest -g30000000 -P76 11
870roundTripTest -g25000000 -P78 12
Konstantin Tokarevd66db2f2015-12-08 18:11:10 +0300871
Yann Collet4616fad2017-07-10 17:16:41 -0700872roundTripTest -g18000013 -P80 13
873roundTripTest -g18000014 -P80 14
Yann Collet60059df2017-09-27 15:16:27 -0700874roundTripTest -g18000015 -P81 15
875roundTripTest -g18000016 -P84 16
876roundTripTest -g18000017 -P88 17
Yann Collet4616fad2017-07-10 17:16:41 -0700877roundTripTest -g18000018 -P94 18
Yann Collet60059df2017-09-27 15:16:27 -0700878roundTripTest -g18000019 -P96 19
Konstantin Tokarev2b465842015-12-08 19:36:42 +0300879
Yann Collet60059df2017-09-27 15:16:27 -0700880roundTripTest -g5000000000 -P99 1
Yann Collet4c7f1372017-12-29 17:40:36 +0100881roundTripTest -g1700000000 -P0 "1 --zstd=strategy=6" # ensure btlazy2 can survive an overflow rescale
Yann Collet459a6b72016-02-15 20:37:23 +0100882
Sean Purcelleb70d212017-04-11 17:15:13 -0700883fileRoundTripTest -g4193M -P99 1
884
Yann Collet02502192017-09-27 15:48:06 -0700885
Yann Collet241c57a2017-10-16 14:01:42 -0700886$ECHO "\n===> zstd long, long distance matching round-trip tests "
Nick Terrellf15a17e2018-02-27 20:09:18 -0800887roundTripTest -g270000000 "1 --single-thread --long"
888roundTripTest -g130000000 -P60 "5 --single-thread --long"
889roundTripTest -g35000000 -P70 "8 --single-thread --long"
890roundTripTest -g18000001 -P80 "18 --single-thread --long"
Nick Terrellc233bdb2017-09-22 14:04:39 -0700891# Test large window logs
Nick Terrellf15a17e2018-02-27 20:09:18 -0800892roundTripTest -g700M -P50 "1 --single-thread --long=29"
893roundTripTest -g600M -P50 "1 --single-thread --long --zstd=wlog=29,clog=28"
Stella Lau6a546ef2017-07-28 15:51:33 -0700894
895
Sean Purcellc424ec22017-04-17 11:38:53 -0700896if [ -n "$hasMT" ]
897then
Yann Collet241c57a2017-10-16 14:01:42 -0700898 $ECHO "\n===> zstdmt long round-trip tests "
Yann Collet60059df2017-09-27 15:16:27 -0700899 roundTripTest -g80000000 -P99 "19 -T2" " "
900 roundTripTest -g5000000000 -P99 "1 -T2" " "
901 roundTripTest -g500000000 -P97 "1 -T999" " "
902 fileRoundTripTest -g4103M -P98 " -T0" " "
903 roundTripTest -g400000000 -P97 "1 --long=24 -T2" " "
Sean Purcellc424ec22017-04-17 11:38:53 -0700904else
905 $ECHO "\n**** no multithreading, skipping zstdmt tests **** "
906fi
907
Yann Collet45010da2018-09-19 17:37:22 -0700908
909$ECHO "\n===> cover dictionary builder : advanced options "
910
911TESTFILE=../programs/zstdcli.c
912./datagen > tmpDict
913$ECHO "- Create first dictionary"
914$ZSTD --train-cover=k=46,d=8,split=80 *.c ../programs/*.c -o tmpDict
915cp $TESTFILE tmp
916$ZSTD -f tmp -D tmpDict
917$ZSTD -d tmp.zst -D tmpDict -fo result
918$DIFF $TESTFILE result
919$ECHO "- Create second (different) dictionary"
920$ZSTD --train-cover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
921$ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
922$ECHO "- Create dictionary with short dictID"
923$ZSTD --train-cover=k=46,d=8,split=80 *.c ../programs/*.c --dictID=1 -o tmpDict1
924cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
925$ECHO "- Create dictionary with size limit"
926$ZSTD --train-cover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
927$ECHO "- Compare size of dictionary from 90% training samples with 80% training samples"
928$ZSTD --train-cover=split=90 -r *.c ../programs/*.c
929$ZSTD --train-cover=split=80 -r *.c ../programs/*.c
930$ECHO "- Create dictionary using all samples for both training and testing"
931$ZSTD --train-cover=split=100 -r *.c ../programs/*.c
932$ECHO "- Test -o before --train-cover"
933rm -f tmpDict dictionary
934$ZSTD -o tmpDict --train-cover *.c ../programs/*.c
935test -f tmpDict
936$ZSTD --train-cover *.c ../programs/*.c
937test -f dictionary
Yann Collet15519472018-09-20 13:00:11 -0700938rm -f tmp* dictionary
Yann Collet45010da2018-09-19 17:37:22 -0700939
940
Yann Collet15519472018-09-20 13:00:11 -0700941rm -f tmp*