]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/playTests.sh
import zstd 1.3.8
[FreeBSD/FreeBSD.git] / tests / playTests.sh
1 #!/bin/sh -e
2
3 die() {
4     $ECHO "$@" 1>&2
5     exit 1
6 }
7
8 roundTripTest() {
9     if [ -n "$3" ]; then
10         cLevel="$3"
11         proba="$2"
12     else
13         cLevel="$2"
14         proba=""
15     fi
16     if [ -n "$4" ]; then
17         dLevel="$4"
18     else
19         dLevel="$cLevel"
20     fi
21
22     rm -f tmp1 tmp2
23     $ECHO "roundTripTest: ./datagen $1 $proba | $ZSTD -v$cLevel | $ZSTD -d$dLevel"
24     ./datagen $1 $proba | $MD5SUM > tmp1
25     ./datagen $1 $proba | $ZSTD --ultra -v$cLevel | $ZSTD -d$dLevel  | $MD5SUM > tmp2
26     $DIFF -q tmp1 tmp2
27 }
28
29 fileRoundTripTest() {
30     if [ -n "$3" ]; then
31         local_c="$3"
32         local_p="$2"
33     else
34         local_c="$2"
35         local_p=""
36     fi
37     if [ -n "$4" ]; then
38         local_d="$4"
39     else
40         local_d="$local_c"
41     fi
42
43     rm -f tmp.zstd tmp.md5.1 tmp.md5.2
44     $ECHO "fileRoundTripTest: ./datagen $1 $local_p > tmp && $ZSTD -v$local_c -c tmp | $ZSTD -d$local_d"
45     ./datagen $1 $local_p > tmp
46     < tmp $MD5SUM > tmp.md5.1
47     $ZSTD --ultra -v$local_c -c tmp | $ZSTD -d$local_d | $MD5SUM > tmp.md5.2
48     $DIFF -q tmp.md5.1 tmp.md5.2
49 }
50
51 truncateLastByte() {
52         dd bs=1 count=$(($(wc -c < "$1") - 1)) if="$1" status=none
53 }
54
55 UNAME=$(uname)
56
57 isTerminal=false
58 if [ -t 0 ] && [ -t 1 ]
59 then
60     isTerminal=true
61 fi
62
63 isWindows=false
64 INTOVOID="/dev/null"
65 case "$UNAME" in
66   GNU) DEVDEVICE="/dev/random" ;;
67   *) DEVDEVICE="/dev/zero" ;;
68 esac
69 case "$OS" in
70   Windows*)
71     isWindows=true
72     INTOVOID="NUL"
73     DEVDEVICE="NUL"
74     ;;
75 esac
76
77 case "$UNAME" in
78   Darwin) MD5SUM="md5 -r" ;;
79   FreeBSD) MD5SUM="gmd5sum" ;;
80   OpenBSD) MD5SUM="md5" ;;
81   *) MD5SUM="md5sum" ;;
82 esac
83
84 DIFF="diff"
85 case "$UNAME" in
86   SunOS) DIFF="gdiff" ;;
87 esac
88
89 ECHO="echo -e"
90 case "$UNAME" in
91   Darwin) ECHO="echo" ;;
92 esac
93
94 $ECHO "\nStarting playTests.sh isWindows=$isWindows ZSTD='$ZSTD'"
95
96 [ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
97
98 if [ -n "$(echo hello | $ZSTD -v -T2 2>&1 > $INTOVOID | grep 'multi-threading is disabled')" ]
99 then
100     hasMT=""
101 else
102     hasMT="true"
103 fi
104
105
106
107 $ECHO "\n===>  simple tests "
108
109 ./datagen > tmp
110 $ECHO "test : basic compression "
111 $ZSTD -f tmp                      # trivial compression case, creates tmp.zst
112 $ECHO "test : basic decompression"
113 $ZSTD -df tmp.zst                 # trivial decompression case (overwrites tmp)
114 $ECHO "test : too large compression level => auto-fix"
115 $ZSTD -99 -f tmp  # too large compression level, automatic sized down
116 $ZSTD -5000000000 -f tmp && die "too large numeric value : must fail"
117 $ECHO "test : --fast aka negative compression levels"
118 $ZSTD --fast -f tmp  # == -1
119 $ZSTD --fast=3 -f tmp  # == -3
120 $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"
123 $ECHO "test : too large numeric argument"
124 $ZSTD --fast=9999999999 -f tmp  && die "should have refused numeric value"
125 $ECHO "test : set compression level with environment variable ZSTD_CLEVEL"
126 ZSTD_CLEVEL=12  $ZSTD -f tmp # positive compression level
127 ZSTD_CLEVEL=-12 $ZSTD -f tmp # negative compression level
128 ZSTD_CLEVEL=+12 $ZSTD -f tmp # valid: verbose '+' sign
129 ZSTD_CLEVEL=    $ZSTD -f tmp # empty env var, warn and revert to default setting
130 ZSTD_CLEVEL=-   $ZSTD -f tmp # malformed env var, warn and revert to default setting
131 ZSTD_CLEVEL=a   $ZSTD -f tmp # malformed env var, warn and revert to default setting
132 ZSTD_CLEVEL=+a  $ZSTD -f tmp # malformed env var, warn and revert to default setting
133 ZSTD_CLEVEL=3a7 $ZSTD -f tmp # malformed env var, warn and revert to default setting
134 ZSTD_CLEVEL=50000000000  $ZSTD -f tmp # numeric value too large, warn and revert to default setting
135 $ECHO "test : override ZSTD_CLEVEL with command line option"
136 ZSTD_CLEVEL=12  $ZSTD --fast=3 -f tmp # overridden by command line option
137 $ECHO "test : compress to stdout"
138 $ZSTD tmp -c > tmpCompressed
139 $ZSTD tmp --stdout > tmpCompressed       # long command format
140 $ECHO "test : compress to named file"
141 rm tmpCompressed
142 $ZSTD tmp -o tmpCompressed
143 test -f tmpCompressed   # file must be created
144 $ECHO "test : -o must be followed by filename (must fail)"
145 $ZSTD tmp -of tmpCompressed && die "-o must be followed by filename "
146 $ECHO "test : force write, correct order"
147 $ZSTD tmp -fo tmpCompressed
148 $ECHO "test : forgotten argument"
149 cp tmp tmp2
150 $ZSTD tmp2 -fo && die "-o must be followed by filename "
151 $ECHO "test : implied stdout when input is stdin"
152 $ECHO bob | $ZSTD | $ZSTD -d
153 if [ "$isTerminal" = true ]; then
154 $ECHO "test : compressed data to terminal"
155 $ECHO bob | $ZSTD && die "should have refused : compressed data to terminal"
156 $ECHO "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)"
157 $ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal"
158 fi
159 $ECHO "test : null-length file roundtrip"
160 $ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
161 $ECHO "test : ensure small file doesn't add 3-bytes null block"
162 ./datagen -g1 > tmp1
163 $ZSTD tmp1 -c | wc -c | grep "14"
164 $ZSTD < tmp1  | wc -c | grep "14"
165 $ECHO "test : decompress file with wrong suffix (must fail)"
166 $ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
167 $ZSTD -df tmp && die "should have refused : wrong extension"
168 $ECHO "test : decompress into stdout"
169 $ZSTD -d tmpCompressed -c > tmpResult    # decompression using stdout
170 $ZSTD --decompress tmpCompressed -c > tmpResult
171 $ZSTD --decompress tmpCompressed --stdout > tmpResult
172 $ECHO "test : decompress from stdin into stdout"
173 $ZSTD -dc   < tmp.zst > $INTOVOID   # combine decompression, stdin & stdout
174 $ZSTD -dc - < tmp.zst > $INTOVOID
175 $ZSTD -d    < tmp.zst > $INTOVOID   # implicit stdout when stdin is used
176 $ZSTD -d  - < tmp.zst > $INTOVOID
177 $ECHO "test : impose memory limitation (must fail)"
178 $ZSTD -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
179 $ZSTD -d -f tmp.zst --memlimit=2K -c > $INTOVOID && die "decompression needs more memory than allowed"  # long command
180 $ZSTD -d -f tmp.zst --memory=2K -c > $INTOVOID && die "decompression needs more memory than allowed"  # long command
181 $ZSTD -d -f tmp.zst --memlimit-decompress=2K -c > $INTOVOID && die "decompression needs more memory than allowed"  # long command
182 $ECHO "test : overwrite protection"
183 $ZSTD -q tmp && die "overwrite check failed!"
184 $ECHO "test : force overwrite"
185 $ZSTD -q -f tmp
186 $ZSTD -q --force tmp
187 $ECHO "test : overwrite readonly file"
188 rm -f tmpro tmpro.zst
189 $ECHO foo > tmpro.zst
190 $ECHO foo > tmpro
191 chmod 400 tmpro.zst
192 $ZSTD -q tmpro && die "should have refused to overwrite read-only file"
193 $ZSTD -q -f tmpro
194 $ECHO "test: --no-progress flag"
195 $ZSTD tmpro -c --no-progress | $ZSTD -d -f -o "$INTOVOID" --no-progress
196 $ZSTD tmpro -cv --no-progress | $ZSTD -dv -f -o "$INTOVOID" --no-progress
197 rm -f tmpro tmpro.zst
198 $ECHO "test: overwrite input file (must fail)"
199 $ZSTD tmp -fo tmp && die "zstd compression overwrote the input file"
200 $ZSTD tmp.zst -dfo tmp.zst && die "zstd decompression overwrote the input file"
201 $ECHO "test: detect that input file does not exist"
202 $ZSTD nothere && die "zstd hasn't detected that input file does not exist"
203
204 $ECHO "test : file removal"
205 $ZSTD -f --rm tmp
206 test ! -f tmp  # tmp should no longer be present
207 $ZSTD -f -d --rm tmp.zst
208 test ! -f tmp.zst   # tmp.zst should no longer be present
209 $ECHO "test : should quietly not remove non-regular file"
210 $ECHO hello > tmp
211 $ZSTD tmp -f -o "$DEVDEVICE" 2>tmplog > "$INTOVOID"
212 grep -v "Refusing to remove non-regular file" tmplog
213 rm -f tmplog
214 $ZSTD tmp -f -o "$INTOVOID" 2>&1 | grep -v "Refusing to remove non-regular file"
215 $ECHO "test : --rm on stdin"
216 $ECHO a | $ZSTD --rm > $INTOVOID   # --rm should remain silent
217 rm tmp
218 $ZSTD -f tmp && die "tmp not present : should have failed"
219 test ! -f tmp.zst  # tmp.zst should not be created
220 $ECHO "test : -d -f do not delete destination when source is not present"
221 touch tmp    # create destination file
222 $ZSTD -d -f tmp.zst && die "attempt to decompress a non existing file"
223 test -f tmp  # destination file should still be present
224 $ECHO "test : -f do not delete destination when source is not present"
225 rm tmp         # erase source file
226 touch tmp.zst  # create destination file
227 $ZSTD -f tmp && die "attempt to compress a non existing file"
228 test -f tmp.zst  # destination file should still be present
229 rm tmp*
230
231
232 $ECHO "test : compress multiple files"
233 $ECHO hello > tmp1
234 $ECHO world > tmp2
235 $ZSTD tmp1 tmp2 -o "$INTOVOID" -f
236 $ZSTD tmp1 tmp2 -c | $ZSTD -t
237 $ZSTD tmp1 tmp2 -o tmp.zst
238 test ! -f tmp1.zst
239 test ! -f tmp2.zst
240 $ZSTD tmp1 tmp2
241 $ZSTD -t tmp1.zst tmp2.zst
242 $ZSTD -dc tmp1.zst tmp2.zst
243 $ZSTD tmp1.zst tmp2.zst -o "$INTOVOID" -f
244 $ZSTD -d tmp1.zst tmp2.zst -o tmp
245 touch tmpexists
246 $ZSTD tmp1 tmp2 -f -o tmpexists
247 $ZSTD tmp1 tmp2 -o tmpexists && die "should have refused to overwrite"
248 # Bug: PR #972
249 if [ "$?" -eq 139 ]; then
250   die "should not have segfaulted"
251 fi
252 rm tmp*
253
254
255 $ECHO "\n===>  Advanced compression parameters "
256 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,      - -o tmp.zst && die "wrong parameters not detected!"
257 $ECHO "Hello world!" | $ZSTD --zstd=windowLo=21        - -o tmp.zst && die "wrong parameters not detected!"
258 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,slog  - -o tmp.zst && die "wrong parameters not detected!"
259 $ECHO "Hello world!" | $ZSTD --zstd=strategy=10        - -o tmp.zst && die "parameter out of bound not detected!"  # > btultra2 : does not exist
260 test ! -f tmp.zst  # tmp.zst should not be created
261 roundTripTest -g512K
262 roundTripTest -g512K " --zstd=mml=3,tlen=48,strat=6"
263 roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
264 roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,minMatch=3,targetLength=48,strategy=6"
265 roundTripTest -g512K " --single-thread --long --zstd=ldmHashLog=20,ldmMinMatch=64,ldmBucketSizeLog=1,ldmHashRateLog=7"
266 roundTripTest -g512K " --single-thread --long --zstd=lhlog=20,lmml=64,lblog=1,lhrlog=7"
267 roundTripTest -g64K  "19 --zstd=strat=9"   # btultra2
268
269
270 $ECHO "\n===>  Pass-Through mode "
271 $ECHO "Hello world 1!" | $ZSTD -df
272 $ECHO "Hello world 2!" | $ZSTD -dcf
273 $ECHO "Hello world 3!" > tmp1
274 $ZSTD -dcf tmp1
275
276
277 $ECHO "\n===>  frame concatenation "
278
279 $ECHO "hello " > hello.tmp
280 $ECHO "world!" > world.tmp
281 cat hello.tmp world.tmp > helloworld.tmp
282 $ZSTD -c hello.tmp > hello.zstd
283 $ZSTD -c world.tmp > world.zstd
284 cat hello.zstd world.zstd > helloworld.zstd
285 $ZSTD -dc helloworld.zstd > result.tmp
286 cat result.tmp
287 $DIFF helloworld.tmp result.tmp
288 $ECHO "frame concatenation without checksum"
289 $ZSTD -c hello.tmp > hello.zstd --no-check
290 $ZSTD -c world.tmp > world.zstd --no-check
291 cat hello.zstd world.zstd > helloworld.zstd
292 $ZSTD -dc helloworld.zstd > result.tmp
293 $DIFF helloworld.tmp result.tmp
294 $ECHO "testing zstdcat symlink"
295 ln -sf $ZSTD zstdcat
296 ./zstdcat helloworld.zstd > result.tmp
297 $DIFF helloworld.tmp result.tmp
298 rm zstdcat
299 rm result.tmp
300 $ECHO "testing zcat symlink"
301 ln -sf $ZSTD zcat
302 ./zcat helloworld.zstd > result.tmp
303 $DIFF helloworld.tmp result.tmp
304 rm zcat
305 rm ./*.tmp ./*.zstd
306 $ECHO "frame concatenation tests completed"
307
308
309 if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] && [ "$UNAME" != "OpenBSD" ] ; then
310 $ECHO "\n**** flush write error test **** "
311
312 $ECHO "$ECHO foo | $ZSTD > /dev/full"
313 $ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
314 $ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
315 $ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
316
317
318 $ECHO "\n===>  symbolic link test "
319
320 rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
321 $ECHO "hello world" > hello.tmp
322 ln -s hello.tmp world.tmp
323 $ZSTD world.tmp hello.tmp
324 test -f hello.tmp.zst  # regular file should have been compressed!
325 test ! -f world.tmp.zst  # symbolic link should not have been compressed!
326 $ZSTD world.tmp hello.tmp -f
327 test -f world.tmp.zst  # symbolic link should have been compressed with --force
328 rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
329
330 fi
331
332
333 $ECHO "\n===>  test sparse file support "
334
335 ./datagen -g5M  -P100 > tmpSparse
336 $ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
337 $DIFF -s tmpSparse tmpSparseRegen
338 $ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
339 $DIFF -s tmpSparse tmpOutSparse
340 $ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
341 $DIFF -s tmpSparse tmpOutNoSparse
342 ls -ls tmpSparse*  # look at file size and block size on disk
343 ./datagen -s1 -g1200007 -P100 | $ZSTD | $ZSTD -dv --sparse -c > tmpSparseOdd   # Odd size file (to not finish on an exact nb of blocks)
344 ./datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
345 ls -ls tmpSparseOdd  # look at file size and block size on disk
346 $ECHO "\n Sparse Compatibility with Console :"
347 $ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
348 $ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
349 $ECHO "\n Sparse Compatibility with Append :"
350 ./datagen -P100 -g1M > tmpSparse1M
351 cat tmpSparse1M tmpSparse1M > tmpSparse2M
352 $ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
353 $ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
354 $ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
355 ls -ls tmpSparse*  # look at file size and block size on disk
356 $DIFF tmpSparse2M tmpSparseRegenerated
357 rm tmpSparse*
358
359
360 $ECHO "\n===>  multiple files tests "
361
362 ./datagen -s1        > tmp1 2> $INTOVOID
363 ./datagen -s2 -g100K > tmp2 2> $INTOVOID
364 ./datagen -s3 -g1M   > tmp3 2> $INTOVOID
365 $ECHO "compress tmp* : "
366 $ZSTD -f tmp*
367 ls -ls tmp*
368 rm tmp1 tmp2 tmp3
369 $ECHO "decompress tmp* : "
370 $ZSTD -df *.zst
371 ls -ls tmp*
372 $ECHO "compress tmp* into stdout > tmpall : "
373 $ZSTD -c tmp1 tmp2 tmp3 > tmpall
374 ls -ls tmp*  # check size of tmpall (should be tmp1.zst + tmp2.zst + tmp3.zst)
375 $ECHO "decompress tmpall* into stdout > tmpdec : "
376 cp tmpall tmpall2
377 $ZSTD -dc tmpall* > tmpdec
378 ls -ls tmp* # check size of tmpdec (should be 2*(tmp1 + tmp2 + tmp3))
379 $ECHO "compress multiple files including a missing one (notHere) : "
380 $ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
381
382
383 $ECHO "\n===>  dictionary tests "
384
385 $ECHO "- test with raw dict (content only) "
386 ./datagen > tmpDict
387 ./datagen -g1M | $MD5SUM > tmp1
388 ./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
389 $DIFF -q tmp1 tmp2
390 $ECHO "- Create first dictionary "
391 TESTFILE=../programs/zstdcli.c
392 $ZSTD --train *.c ../programs/*.c -o tmpDict
393 cp $TESTFILE tmp
394 $ECHO "- Dictionary compression roundtrip"
395 $ZSTD -f tmp -D tmpDict
396 $ZSTD -d tmp.zst -D tmpDict -fo result
397 $DIFF $TESTFILE result
398 $ECHO "- Dictionary compression with btlazy2 strategy"
399 $ZSTD -f tmp -D tmpDict --zstd=strategy=6
400 $ZSTD -d tmp.zst -D tmpDict -fo result
401 $DIFF $TESTFILE result
402 if [ -n "$hasMT" ]
403 then
404     $ECHO "- Test dictionary compression with multithreading "
405     ./datagen -g5M | $ZSTD -T2 -D tmpDict | $ZSTD -t -D tmpDict   # fails with v1.3.2
406 fi
407 $ECHO "- Create second (different) dictionary "
408 $ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
409 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
410 $ECHO "- Create dictionary with short dictID"
411 $ZSTD --train *.c ../programs/*.c --dictID=1 -o tmpDict1
412 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
413 $ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
414 $ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
415 $ECHO "- Create dictionary with size limit"
416 $ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict=4K -v
417 $ECHO "- Create dictionary with small size limit"
418 $ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict=1K -v
419 $ECHO "- Create dictionary with wrong parameter order (must fail)"
420 $ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict -v 4K && die "wrong order : --maxdict must be followed by argument "
421 $ECHO "- Compress without dictID"
422 $ZSTD -f tmp -D tmpDict1 --no-dictID
423 $ZSTD -d tmp.zst -D tmpDict -fo result
424 $DIFF $TESTFILE result
425 $ECHO "- Compress with wrong argument order (must fail)"
426 $ZSTD tmp -Df tmpDict1 -c > $INTOVOID && die "-D must be followed by dictionary name "
427 $ECHO "- Compress multiple files with dictionary"
428 rm -rf dirTestDict
429 mkdir dirTestDict
430 cp *.c dirTestDict
431 cp ../programs/*.c dirTestDict
432 cp ../programs/*.h dirTestDict
433 $MD5SUM dirTestDict/* > tmph1
434 $ZSTD -f --rm dirTestDict/* -D tmpDictC
435 $ZSTD -d --rm dirTestDict/*.zst -D tmpDictC  # note : use internal checksum by default
436 case "$UNAME" in
437   Darwin) $ECHO "md5sum -c not supported on OS-X : test skipped" ;;  # not compatible with OS-X's md5
438   *) $MD5SUM -c tmph1 ;;
439 esac
440 rm -rf dirTestDict
441 $ECHO "- dictionary builder on bogus input"
442 $ECHO "Hello World" > tmp
443 $ZSTD --train-legacy -q tmp && die "Dictionary training should fail : not enough input source"
444 ./datagen -P0 -g10M > tmp
445 $ZSTD --train-legacy -q tmp && die "Dictionary training should fail : source is pure noise"
446 $ECHO "- Test -o before --train"
447 rm -f tmpDict dictionary
448 $ZSTD -o tmpDict --train *.c ../programs/*.c
449 test -f tmpDict
450 $ZSTD --train *.c ../programs/*.c
451 test -f dictionary
452 rm tmp* dictionary
453
454
455 $ECHO "\n===>  fastCover dictionary builder : advanced options "
456
457 TESTFILE=../programs/zstdcli.c
458 ./datagen > tmpDict
459 $ECHO "- Create first dictionary"
460 $ZSTD --train-fastcover=k=46,d=8,f=15,split=80 *.c ../programs/*.c -o tmpDict
461 cp $TESTFILE tmp
462 $ZSTD -f tmp -D tmpDict
463 $ZSTD -d tmp.zst -D tmpDict -fo result
464 $DIFF $TESTFILE result
465 $ECHO "- Create second (different) dictionary"
466 $ZSTD --train-fastcover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
467 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
468 $ECHO "- Create dictionary with short dictID"
469 $ZSTD --train-fastcover=k=46,d=8,f=15,split=80 *.c ../programs/*.c --dictID=1 -o tmpDict1
470 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
471 $ECHO "- Create dictionary with size limit"
472 $ZSTD --train-fastcover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
473 $ECHO "- Compare size of dictionary from 90% training samples with 80% training samples"
474 $ZSTD --train-fastcover=split=90 -r *.c ../programs/*.c
475 $ZSTD --train-fastcover=split=80 -r *.c ../programs/*.c
476 $ECHO "- Create dictionary using all samples for both training and testing"
477 $ZSTD --train-fastcover=split=100 -r *.c ../programs/*.c
478 $ECHO "- Create dictionary using f=16"
479 $ZSTD --train-fastcover=f=16 -r *.c ../programs/*.c
480 $ECHO "- Create dictionary using accel=2"
481 $ZSTD --train-fastcover=accel=2 -r *.c ../programs/*.c
482 $ECHO "- Create dictionary using accel=10"
483 $ZSTD --train-fastcover=accel=10 -r *.c ../programs/*.c
484 $ECHO "- Create dictionary with multithreading"
485 $ZSTD --train-fastcover -T4 -r *.c ../programs/*.c
486 $ECHO "- Test -o before --train-fastcover"
487 rm -f tmpDict dictionary
488 $ZSTD -o tmpDict --train-fastcover *.c ../programs/*.c
489 test -f tmpDict
490 $ZSTD --train-fastcover *.c ../programs/*.c
491 test -f dictionary
492 rm tmp* dictionary
493
494
495 $ECHO "\n===>  legacy dictionary builder "
496
497 TESTFILE=../programs/zstdcli.c
498 ./datagen > tmpDict
499 $ECHO "- Create first dictionary"
500 $ZSTD --train-legacy=selectivity=8 *.c ../programs/*.c -o tmpDict
501 cp $TESTFILE tmp
502 $ZSTD -f tmp -D tmpDict
503 $ZSTD -d tmp.zst -D tmpDict -fo result
504 $DIFF $TESTFILE result
505 $ECHO "- Create second (different) dictionary"
506 $ZSTD --train-legacy=s=5 *.c ../programs/*.c ../programs/*.h -o tmpDictC
507 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
508 $ECHO "- Create dictionary with short dictID"
509 $ZSTD --train-legacy -s5 *.c ../programs/*.c --dictID=1 -o tmpDict1
510 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
511 $ECHO "- Create dictionary with size limit"
512 $ZSTD --train-legacy -s9 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
513 $ECHO "- Test -o before --train-legacy"
514 rm -f tmpDict dictionary
515 $ZSTD -o tmpDict --train-legacy *.c ../programs/*.c
516 test -f tmpDict
517 $ZSTD --train-legacy *.c ../programs/*.c
518 test -f dictionary
519 rm tmp* dictionary
520
521
522 $ECHO "\n===>  integrity tests "
523
524 $ECHO "test one file (tmp1.zst) "
525 ./datagen > tmp1
526 $ZSTD tmp1
527 $ZSTD -t tmp1.zst
528 $ZSTD --test tmp1.zst
529 $ECHO "test multiple files (*.zst) "
530 $ZSTD -t *.zst
531 $ECHO "test bad files (*) "
532 $ZSTD -t * && die "bad files not detected !"
533 $ZSTD -t tmp1 && die "bad file not detected !"
534 cp tmp1 tmp2.zst
535 $ZSTD -t tmp2.zst && die "bad file not detected !"
536 ./datagen -g0 > tmp3
537 $ZSTD -t tmp3 && die "bad file not detected !"   # detects 0-sized files as bad
538 $ECHO "test --rm and --test combined "
539 $ZSTD -t --rm tmp1.zst
540 test -f tmp1.zst   # check file is still present
541 split -b16384 tmp1.zst tmpSplit.
542 $ZSTD -t tmpSplit.* && die "bad file not detected !"
543 ./datagen | $ZSTD -c | $ZSTD -t
544
545
546
547 $ECHO "\n===>  golden files tests "
548
549 $ZSTD -t -r files
550 $ZSTD -c -r files | $ZSTD -t
551
552
553 $ECHO "\n===>  benchmark mode tests "
554
555 $ECHO "bench one file"
556 ./datagen > tmp1
557 $ZSTD -bi0 tmp1
558 $ECHO "bench multiple levels"
559 $ZSTD -i0b0e3 tmp1
560 $ECHO "bench negative level"
561 $ZSTD -bi0 --fast tmp1
562 $ECHO "with recursive and quiet modes"
563 $ZSTD -rqi1b1e2 tmp1
564 $ECHO "benchmark decompression only"
565 $ZSTD -f tmp1
566 $ZSTD -b -d -i1 tmp1.zst
567
568 $ECHO "\n===>  zstd compatibility tests "
569
570 ./datagen > tmp
571 rm -f tmp.zst
572 $ZSTD --format=zstd -f tmp
573 test -f tmp.zst
574
575 $ECHO "\n===>  gzip compatibility tests "
576
577 GZIPMODE=1
578 $ZSTD --format=gzip -V || GZIPMODE=0
579 if [ $GZIPMODE -eq 1 ]; then
580     $ECHO "gzip support detected"
581     GZIPEXE=1
582     gzip -V || GZIPEXE=0
583     if [ $GZIPEXE -eq 1 ]; then
584         ./datagen > tmp
585         $ZSTD --format=gzip -f tmp
586         gzip -t -v tmp.gz
587         gzip -f tmp
588         $ZSTD -d -f -v tmp.gz
589         rm tmp*
590     else
591         $ECHO "gzip binary not detected"
592     fi
593 else
594     $ECHO "gzip mode not supported"
595 fi
596
597
598 $ECHO "\n===>  gzip frame tests "
599
600 if [ $GZIPMODE -eq 1 ]; then
601     ./datagen > tmp
602     $ZSTD -f --format=gzip tmp
603     $ZSTD -f tmp
604     cat tmp.gz tmp.zst tmp.gz tmp.zst | $ZSTD -d -f -o tmp
605     truncateLastByte tmp.gz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
606     rm tmp*
607 else
608     $ECHO "gzip mode not supported"
609 fi
610
611 if [ $GZIPMODE -eq 1 ]; then
612     ./datagen > tmp
613     rm -f tmp.zst
614     $ZSTD --format=gzip --format=zstd -f tmp
615     test -f tmp.zst
616 fi
617
618 $ECHO "\n===>  xz compatibility tests "
619
620 LZMAMODE=1
621 $ZSTD --format=xz -V || LZMAMODE=0
622 if [ $LZMAMODE -eq 1 ]; then
623     $ECHO "xz support detected"
624     XZEXE=1
625     xz -Q -V && lzma -Q -V || XZEXE=0
626     if [ $XZEXE -eq 1 ]; then
627         $ECHO "Testing zstd xz and lzma support"
628         ./datagen > tmp
629         $ZSTD --format=lzma -f tmp
630         $ZSTD --format=xz -f tmp
631         xz -Q -t -v tmp.xz
632         xz -Q -t -v tmp.lzma
633         xz -Q -f -k tmp
634         lzma -Q -f -k --lzma1 tmp
635         $ZSTD -d -f -v tmp.xz
636         $ZSTD -d -f -v tmp.lzma
637         rm tmp*
638         $ECHO "Creating symlinks"
639         ln -s $ZSTD ./xz
640         ln -s $ZSTD ./unxz
641         ln -s $ZSTD ./lzma
642         ln -s $ZSTD ./unlzma
643         $ECHO "Testing xz and lzma symlinks"
644         ./datagen > tmp
645         ./xz tmp
646         xz -Q -d tmp.xz
647         ./lzma tmp
648         lzma -Q -d tmp.lzma
649         $ECHO "Testing unxz and unlzma symlinks"
650         xz -Q tmp
651         ./xz -d tmp.xz
652         lzma -Q tmp
653         ./lzma -d tmp.lzma
654         rm xz unxz lzma unlzma
655         rm tmp*
656     else
657         $ECHO "xz binary not detected"
658     fi
659 else
660     $ECHO "xz mode not supported"
661 fi
662
663
664 $ECHO "\n===>  xz frame tests "
665
666 if [ $LZMAMODE -eq 1 ]; then
667     ./datagen > tmp
668     $ZSTD -f --format=xz tmp
669     $ZSTD -f --format=lzma tmp
670     $ZSTD -f tmp
671     cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | $ZSTD -d -f -o tmp
672     truncateLastByte tmp.xz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
673     truncateLastByte tmp.lzma | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
674     rm tmp*
675 else
676     $ECHO "xz mode not supported"
677 fi
678
679 $ECHO "\n===>  lz4 compatibility tests "
680
681 LZ4MODE=1
682 $ZSTD --format=lz4 -V || LZ4MODE=0
683 if [ $LZ4MODE -eq 1 ]; then
684     $ECHO "lz4 support detected"
685     LZ4EXE=1
686     lz4 -V || LZ4EXE=0
687     if [ $LZ4EXE -eq 1 ]; then
688         ./datagen > tmp
689         $ZSTD --format=lz4 -f tmp
690         lz4 -t -v tmp.lz4
691         lz4 -f tmp
692         $ZSTD -d -f -v tmp.lz4
693         rm tmp*
694     else
695         $ECHO "lz4 binary not detected"
696     fi
697 else
698     $ECHO "lz4 mode not supported"
699 fi
700
701
702 $ECHO "\n===>  lz4 frame tests "
703
704 if [ $LZ4MODE -eq 1 ]; then
705     ./datagen > tmp
706     $ZSTD -f --format=lz4 tmp
707     $ZSTD -f tmp
708     cat tmp.lz4 tmp.zst tmp.lz4 tmp.zst | $ZSTD -d -f -o tmp
709     truncateLastByte tmp.lz4 | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
710     rm tmp*
711 else
712     $ECHO "lz4 mode not supported"
713 fi
714
715 $ECHO "\n===> suffix list test"
716
717 ! $ZSTD -d tmp.abc 2> tmplg
718
719 if [ $GZIPMODE -ne 1 ]; then
720     grep ".gz" tmplg > $INTOVOID && die "Unsupported suffix listed"
721 fi
722
723 if [ $LZMAMODE -ne 1 ]; then
724     grep ".lzma" tmplg > $INTOVOID && die "Unsupported suffix listed"
725     grep ".xz" tmplg > $INTOVOID && die "Unsupported suffix listed"
726 fi
727
728 if [ $LZ4MODE -ne 1 ]; then
729     grep ".lz4" tmplg > $INTOVOID && die "Unsupported suffix listed"
730 fi
731
732 $ECHO "\n===>  zstd round-trip tests "
733
734 roundTripTest
735 roundTripTest -g15K       # TableID==3
736 roundTripTest -g127K      # TableID==2
737 roundTripTest -g255K      # TableID==1
738 roundTripTest -g522K      # TableID==0
739 roundTripTest -g519K 6    # greedy, hash chain
740 roundTripTest -g517K 16   # btlazy2
741 roundTripTest -g516K 19   # btopt
742
743 fileRoundTripTest -g500K
744
745 $ECHO "\n===>  zstd long distance matching round-trip tests "
746 roundTripTest -g0 "2 --single-thread --long"
747 roundTripTest -g1000K "1 --single-thread --long"
748 roundTripTest -g517K "6 --single-thread --long"
749 roundTripTest -g516K "16 --single-thread --long"
750 roundTripTest -g518K "19 --single-thread --long"
751 fileRoundTripTest -g5M "3 --single-thread --long"
752
753
754 roundTripTest -g96K "5 --single-thread"
755 if [ -n "$hasMT" ]
756 then
757     $ECHO "\n===>  zstdmt round-trip tests "
758     roundTripTest -g4M "1 -T0"
759     roundTripTest -g8M "3 -T2"
760     roundTripTest -g8000K "2 --threads=2"
761     fileRoundTripTest -g4M "19 -T2 -B1M"
762
763     $ECHO "\n===>  zstdmt long distance matching round-trip tests "
764     roundTripTest -g8M "3 --long=24 -T2"
765
766     $ECHO "\n===>  ovLog tests "
767     ./datagen -g2MB > tmp
768     refSize=$($ZSTD tmp -6 -c --zstd=wlog=18         | wc -c)
769     ov9Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=9 | wc -c)
770     ov1Size=$($ZSTD tmp -6 -c --zstd=wlog=18,ovlog=1 | wc -c)
771     if [ $refSize -eq $ov9Size ]; then
772         echo ov9Size should be different from refSize
773         exit 1
774     fi
775     if [ $refSize -eq $ov1Size ]; then
776         echo ov1Size should be different from refSize
777         exit 1
778     fi
779     if [ $ov9Size -ge $ov1Size ]; then
780         echo ov9Size=$ov9Size should be smaller than ov1Size=$ov1Size
781         exit 1
782     fi
783
784 else
785     $ECHO "\n===>  no multithreading, skipping zstdmt tests "
786 fi
787
788 rm tmp*
789
790 $ECHO "\n===>  zstd --list/-l single frame tests "
791 ./datagen > tmp1
792 ./datagen > tmp2
793 ./datagen > tmp3
794 $ZSTD tmp*
795 $ZSTD -l *.zst
796 $ZSTD -lv *.zst | grep "Decompressed Size:"  # check that decompressed size is present in header
797 $ZSTD --list *.zst
798 $ZSTD --list -v *.zst
799
800 $ECHO "\n===>  zstd --list/-l multiple frame tests "
801 cat tmp1.zst tmp2.zst > tmp12.zst
802 cat tmp12.zst tmp3.zst > tmp123.zst
803 $ZSTD -l *.zst
804 $ZSTD -lv *.zst
805
806 $ECHO "\n===>  zstd --list/-l error detection tests "
807 $ZSTD -l tmp1 tmp1.zst && die "-l must fail on non-zstd file"
808 $ZSTD --list tmp* && die "-l must fail on non-zstd file"
809 $ZSTD -lv tmp1* && die "-l must fail on non-zstd file"
810 $ZSTD --list -v tmp2 tmp12.zst && die "-l must fail on non-zstd file"
811
812 $ECHO "\n===>  zstd --list/-l errors when presented with stdin / no files"
813 $ZSTD -l && die "-l must fail on empty list of files"
814 $ZSTD -l - && die "-l does not work on stdin"
815 $ZSTD -l < tmp1.zst && die "-l does not work on stdin"
816 $ZSTD -l - < tmp1.zst && die "-l does not work on stdin"
817 $ZSTD -l - tmp1.zst && die "-l does not work on stdin"
818 $ZSTD -l - tmp1.zst < tmp1.zst && die "-l does not work on stdin"
819 $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
820
821 $ECHO "\n===>  zstd --list/-l test with null files "
822 ./datagen -g0 > tmp5
823 $ZSTD tmp5
824 $ZSTD -l tmp5.zst
825 $ZSTD -l tmp5* && die "-l must fail on non-zstd file"
826 $ZSTD -lv tmp5.zst | grep "Decompressed Size: 0.00 KB (0 B)"  # check that 0 size is present in header
827 $ZSTD -lv tmp5* && die "-l must fail on non-zstd file"
828
829 $ECHO "\n===>  zstd --list/-l test with no content size field "
830 ./datagen -g513K | $ZSTD > tmp6.zst
831 $ZSTD -l tmp6.zst
832 $ZSTD -lv tmp6.zst | grep "Decompressed Size:"  && die "Field :Decompressed Size: should not be available in this compressed file"
833
834 $ECHO "\n===>   zstd --list/-l test with no checksum "
835 $ZSTD -f --no-check tmp1
836 $ZSTD -l tmp1.zst
837 $ZSTD -lv tmp1.zst
838
839 rm tmp*
840
841
842 $ECHO "\n===>   zstd long distance matching tests "
843 roundTripTest -g0 " --single-thread --long"
844 roundTripTest -g9M "2 --single-thread --long"
845 # Test parameter parsing
846 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --memory=512MB"
847 roundTripTest -g1M -P50 "1 --single-thread --long=29 --zstd=wlog=28" " --memory=256MB"
848 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --long=28 --memory=512MB"
849 roundTripTest -g1M -P50 "1 --single-thread --long=29" " --zstd=wlog=28 --memory=512MB"
850
851
852 $ECHO "\n===>   adaptive mode "
853 roundTripTest -g270000000 " --adapt"
854 roundTripTest -g27000000 " --adapt=min=1,max=4"
855 $ECHO "===>   test: --adapt must fail on incoherent bounds "
856 ./datagen > tmp
857 $ZSTD -f -vv --adapt=min=10,max=9 tmp && die "--adapt must fail on incoherent bounds"
858
859 $ECHO "\n===>   rsyncable mode "
860 roundTripTest -g10M " --rsyncable"
861 roundTripTest -g10M " --rsyncable -B100K"
862 $ECHO "===>   test: --rsyncable must fail with --single-thread"
863 $ZSTD -f -vv --rsyncable --single-thread tmp && die "--rsyncable must fail with --single-thread"
864
865
866 if [ "$1" != "--test-large-data" ]; then
867     $ECHO "Skipping large data tests"
868     exit 0
869 fi
870
871
872 #############################################################################
873
874 $ECHO "\n===>   large files tests "
875
876 roundTripTest -g270000000 1
877 roundTripTest -g250000000 2
878 roundTripTest -g230000000 3
879
880 roundTripTest -g140000000 -P60 4
881 roundTripTest -g130000000 -P62 5
882 roundTripTest -g120000000 -P65 6
883
884 roundTripTest -g70000000 -P70 7
885 roundTripTest -g60000000 -P71 8
886 roundTripTest -g50000000 -P73 9
887
888 roundTripTest -g35000000 -P75 10
889 roundTripTest -g30000000 -P76 11
890 roundTripTest -g25000000 -P78 12
891
892 roundTripTest -g18000013 -P80 13
893 roundTripTest -g18000014 -P80 14
894 roundTripTest -g18000015 -P81 15
895 roundTripTest -g18000016 -P84 16
896 roundTripTest -g18000017 -P88 17
897 roundTripTest -g18000018 -P94 18
898 roundTripTest -g18000019 -P96 19
899
900 roundTripTest -g5000000000 -P99 1
901 roundTripTest -g1700000000 -P0 "1 --zstd=strategy=6"   # ensure btlazy2 can survive an overflow rescale
902
903 fileRoundTripTest -g4193M -P99 1
904
905
906 $ECHO "\n===>   zstd long, long distance matching round-trip tests "
907 roundTripTest -g270000000 "1 --single-thread --long"
908 roundTripTest -g130000000 -P60 "5 --single-thread --long"
909 roundTripTest -g35000000 -P70 "8 --single-thread --long"
910 roundTripTest -g18000001 -P80  "18 --single-thread --long"
911 # Test large window logs
912 roundTripTest -g700M -P50 "1 --single-thread --long=29"
913 roundTripTest -g600M -P50 "1 --single-thread --long --zstd=wlog=29,clog=28"
914
915
916 if [ -n "$hasMT" ]
917 then
918     $ECHO "\n===>   zstdmt long round-trip tests "
919     roundTripTest -g80000000 -P99 "19 -T2" " "
920     roundTripTest -g5000000000 -P99 "1 -T2" " "
921     roundTripTest -g500000000 -P97 "1 -T999" " "
922     fileRoundTripTest -g4103M -P98 " -T0" " "
923     roundTripTest -g400000000 -P97 "1 --long=24 -T2" " "
924 else
925     $ECHO "\n**** no multithreading, skipping zstdmt tests **** "
926 fi
927
928
929 $ECHO "\n===>  cover dictionary builder : advanced options "
930
931 TESTFILE=../programs/zstdcli.c
932 ./datagen > tmpDict
933 $ECHO "- Create first dictionary"
934 $ZSTD --train-cover=k=46,d=8,split=80 *.c ../programs/*.c -o tmpDict
935 cp $TESTFILE tmp
936 $ZSTD -f tmp -D tmpDict
937 $ZSTD -d tmp.zst -D tmpDict -fo result
938 $DIFF $TESTFILE result
939 $ECHO "- Create second (different) dictionary"
940 $ZSTD --train-cover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
941 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
942 $ECHO "- Create dictionary with short dictID"
943 $ZSTD --train-cover=k=46,d=8,split=80 *.c ../programs/*.c --dictID=1 -o tmpDict1
944 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
945 $ECHO "- Create dictionary with size limit"
946 $ZSTD --train-cover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
947 $ECHO "- Compare size of dictionary from 90% training samples with 80% training samples"
948 $ZSTD --train-cover=split=90 -r *.c ../programs/*.c
949 $ZSTD --train-cover=split=80 -r *.c ../programs/*.c
950 $ECHO "- Create dictionary using all samples for both training and testing"
951 $ZSTD --train-cover=split=100 -r *.c ../programs/*.c
952 $ECHO "- Test -o before --train-cover"
953 rm -f tmpDict dictionary
954 $ZSTD -o tmpDict --train-cover *.c ../programs/*.c
955 test -f tmpDict
956 $ZSTD --train-cover *.c ../programs/*.c
957 test -f dictionary
958 rm -f tmp* dictionary
959
960
961 rm -f tmp*