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