]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/playTests.sh
import zstd 1.3.3
[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 isTerminal=false
52 if [ -t 0 ] && [ -t 1 ]
53 then
54     isTerminal=true
55 fi
56
57 isWindows=false
58 INTOVOID="/dev/null"
59 DEVDEVICE="/dev/zero"
60 case "$OS" in
61   Windows*)
62     isWindows=true
63     INTOVOID="NUL"
64     DEVDEVICE="NUL"
65     ;;
66 esac
67
68 UNAME=$(uname)
69 case "$UNAME" in
70   Darwin) MD5SUM="md5 -r" ;;
71   FreeBSD) MD5SUM="gmd5sum" ;;
72   *) MD5SUM="md5sum" ;;
73 esac
74
75 DIFF="diff"
76 case "$UNAME" in
77   SunOS) DIFF="gdiff" ;;
78 esac
79
80 ECHO="echo -e"
81 case "$UNAME" in
82   Darwin) ECHO="echo" ;;
83 esac
84
85 $ECHO "\nStarting playTests.sh isWindows=$isWindows ZSTD='$ZSTD'"
86
87 [ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
88
89 if [ -n "$(echo hello | $ZSTD -v -T2 2>&1 > $INTOVOID | grep 'multi-threading is disabled')" ]
90 then
91     hasMT=""
92 else
93     hasMT="true"
94 fi
95
96 $ECHO "\n===>  simple tests "
97
98 ./datagen > tmp
99 $ECHO "test : basic compression "
100 $ZSTD -f tmp                      # trivial compression case, creates tmp.zst
101 $ECHO "test : basic decompression"
102 $ZSTD -df tmp.zst                 # trivial decompression case (overwrites tmp)
103 $ECHO "test : too large compression level (must fail)"
104 $ZSTD -99 -f tmp  # too large compression level, automatic sized down
105 $ECHO "test : compress to stdout"
106 $ZSTD tmp -c > tmpCompressed
107 $ZSTD tmp --stdout > tmpCompressed       # long command format
108 $ECHO "test : compress to named file"
109 rm tmpCompressed
110 $ZSTD tmp -o tmpCompressed
111 test -f tmpCompressed   # file must be created
112 $ECHO "test : -o must be followed by filename (must fail)"
113 $ZSTD tmp -of tmpCompressed && die "-o must be followed by filename "
114 $ECHO "test : force write, correct order"
115 $ZSTD tmp -fo tmpCompressed
116 $ECHO "test : forgotten argument"
117 cp tmp tmp2
118 $ZSTD tmp2 -fo && die "-o must be followed by filename "
119 $ECHO "test : implied stdout when input is stdin"
120 $ECHO bob | $ZSTD | $ZSTD -d
121 if [ "$isTerminal" = true ]; then
122 $ECHO "test : compressed data to terminal"
123 $ECHO bob | $ZSTD && die "should have refused : compressed data to terminal"
124 $ECHO "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)"
125 $ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal"
126 fi
127 $ECHO "test : null-length file roundtrip"
128 $ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
129 $ECHO "test : ensure small file doesn't add 3-bytes null block"
130 ./datagen -g1 > tmp1
131 $ZSTD tmp1 -c | wc -c | grep "14"
132 $ZSTD < tmp1  | wc -c | grep "14"
133 $ECHO "test : decompress file with wrong suffix (must fail)"
134 $ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
135 $ZSTD -df tmp && die "should have refused : wrong extension"
136 $ECHO "test : decompress into stdout"
137 $ZSTD -d tmpCompressed -c > tmpResult    # decompression using stdout
138 $ZSTD --decompress tmpCompressed -c > tmpResult
139 $ZSTD --decompress tmpCompressed --stdout > tmpResult
140 $ECHO "test : decompress from stdin into stdout"
141 $ZSTD -dc   < tmp.zst > $INTOVOID   # combine decompression, stdin & stdout
142 $ZSTD -dc - < tmp.zst > $INTOVOID
143 $ZSTD -d    < tmp.zst > $INTOVOID   # implicit stdout when stdin is used
144 $ZSTD -d  - < tmp.zst > $INTOVOID
145 $ECHO "test : impose memory limitation (must fail)"
146 $ZSTD -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
147 $ZSTD -d -f tmp.zst --memlimit=2K -c > $INTOVOID && die "decompression needs more memory than allowed"  # long command
148 $ZSTD -d -f tmp.zst --memory=2K -c > $INTOVOID && die "decompression needs more memory than allowed"  # long command
149 $ZSTD -d -f tmp.zst --memlimit-decompress=2K -c > $INTOVOID && die "decompression needs more memory than allowed"  # long command
150 $ECHO "test : overwrite protection"
151 $ZSTD -q tmp && die "overwrite check failed!"
152 $ECHO "test : force overwrite"
153 $ZSTD -q -f tmp
154 $ZSTD -q --force tmp
155 $ECHO "test : overwrite readonly file"
156 rm -f tmpro tmpro.zst
157 $ECHO foo > tmpro.zst
158 $ECHO foo > tmpro
159 chmod 400 tmpro.zst
160 $ZSTD -q tmpro && die "should have refused to overwrite read-only file"
161 $ZSTD -q -f tmpro
162 rm -f tmpro tmpro.zst
163 $ECHO "test : file removal"
164 $ZSTD -f --rm tmp
165 test ! -f tmp  # tmp should no longer be present
166 $ZSTD -f -d --rm tmp.zst
167 test ! -f tmp.zst   # tmp.zst should no longer be present
168 $ECHO "test : should quietly not remove non-regular file"
169 $ECHO hello > tmp
170 $ZSTD tmp -f -o "$DEVDEVICE" 2>tmplog > "$INTOVOID"
171 grep -v "Refusing to remove non-regular file" tmplog
172 rm -f tmplog
173 $ZSTD tmp -f -o "$INTONULL" 2>&1 | grep -v "Refusing to remove non-regular file"
174 $ECHO "test : --rm on stdin"
175 $ECHO a | $ZSTD --rm > $INTOVOID   # --rm should remain silent
176 rm tmp
177 $ZSTD -f tmp && die "tmp not present : should have failed"
178 test ! -f tmp.zst  # tmp.zst should not be created
179
180 $ECHO "test : compress multiple files"
181 $ECHO hello > tmp1
182 $ECHO world > tmp2
183 $ZSTD tmp1 tmp2 -o "$INTOVOID"
184 $ZSTD tmp1 tmp2 -c | $ZSTD -t
185 $ZSTD tmp1 tmp2 -o tmp.zst
186 test ! -f tmp1.zst
187 test ! -f tmp2.zst
188 $ZSTD tmp1 tmp2
189 $ZSTD -t tmp1.zst tmp2.zst
190 $ZSTD -dc tmp1.zst tmp2.zst
191 $ZSTD tmp1.zst tmp2.zst -o "$INTOVOID"
192 $ZSTD -d tmp1.zst tmp2.zst -o tmp
193 rm tmp*
194
195
196
197 $ECHO "\n===>  Advanced compression parameters "
198 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,      - -o tmp.zst && die "wrong parameters not detected!"
199 $ECHO "Hello world!" | $ZSTD --zstd=windowLo=21        - -o tmp.zst && die "wrong parameters not detected!"
200 $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,slog  - -o tmp.zst && die "wrong parameters not detected!"
201 test ! -f tmp.zst  # tmp.zst should not be created
202 roundTripTest -g512K
203 roundTripTest -g512K " --zstd=slen=3,tlen=48,strat=6"
204 roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
205 roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,searchLength=3,targetLength=48,strategy=6"
206 roundTripTest -g512K " --long --zstd=ldmHashLog=20,ldmSearchLength=64,ldmBucketSizeLog=1,ldmHashEveryLog=7"
207 roundTripTest -g512K " --long --zstd=ldmhlog=20,ldmslen=64,ldmblog=1,ldmhevery=7"
208 roundTripTest -g512K 19
209
210
211 $ECHO "\n===>  Pass-Through mode "
212 $ECHO "Hello world 1!" | $ZSTD -df
213 $ECHO "Hello world 2!" | $ZSTD -dcf
214 $ECHO "Hello world 3!" > tmp1
215 $ZSTD -dcf tmp1
216
217
218 $ECHO "\n===>  frame concatenation "
219
220 $ECHO "hello " > hello.tmp
221 $ECHO "world!" > world.tmp
222 cat hello.tmp world.tmp > helloworld.tmp
223 $ZSTD -c hello.tmp > hello.zstd
224 $ZSTD -c world.tmp > world.zstd
225 cat hello.zstd world.zstd > helloworld.zstd
226 $ZSTD -dc helloworld.zstd > result.tmp
227 cat result.tmp
228 $DIFF helloworld.tmp result.tmp
229 $ECHO "frame concatenation without checksum"
230 $ZSTD -c hello.tmp > hello.zstd --no-check
231 $ZSTD -c world.tmp > world.zstd --no-check
232 cat hello.zstd world.zstd > helloworld.zstd
233 $ZSTD -dc helloworld.zstd > result.tmp
234 cat result.tmp
235 $DIFF helloworld.tmp result.tmp
236 rm ./*.tmp ./*.zstd
237 $ECHO "frame concatenation tests completed"
238
239
240 if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] ; then
241 $ECHO "\n**** flush write error test **** "
242
243 $ECHO "$ECHO foo | $ZSTD > /dev/full"
244 $ECHO foo | $ZSTD > /dev/full && die "write error not detected!"
245 $ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full"
246 $ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!"
247
248
249 $ECHO "\n===>  symbolic link test "
250
251 rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
252 $ECHO "hello world" > hello.tmp
253 ln -s hello.tmp world.tmp
254 $ZSTD world.tmp hello.tmp
255 test -f hello.tmp.zst  # regular file should have been compressed!
256 test ! -f world.tmp.zst  # symbolic link should not have been compressed!
257 $ZSTD world.tmp hello.tmp -f
258 test -f world.tmp.zst  # symbolic link should have been compressed with --force
259 rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst
260
261 fi
262
263
264 $ECHO "\n===>  test sparse file support "
265
266 ./datagen -g5M  -P100 > tmpSparse
267 $ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen
268 $DIFF -s tmpSparse tmpSparseRegen
269 $ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse
270 $DIFF -s tmpSparse tmpOutSparse
271 $ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse
272 $DIFF -s tmpSparse tmpOutNoSparse
273 ls -ls tmpSparse*  # look at file size and block size on disk
274 ./datagen -s1 -g1200007 -P100 | $ZSTD | $ZSTD -dv --sparse -c > tmpSparseOdd   # Odd size file (to not finish on an exact nb of blocks)
275 ./datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
276 ls -ls tmpSparseOdd  # look at file size and block size on disk
277 $ECHO "\n Sparse Compatibility with Console :"
278 $ECHO "Hello World 1 !" | $ZSTD | $ZSTD -d -c
279 $ECHO "Hello World 2 !" | $ZSTD | $ZSTD -d | cat
280 $ECHO "\n Sparse Compatibility with Append :"
281 ./datagen -P100 -g1M > tmpSparse1M
282 cat tmpSparse1M tmpSparse1M > tmpSparse2M
283 $ZSTD -v -f tmpSparse1M -o tmpSparseCompressed
284 $ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
285 $ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
286 ls -ls tmpSparse*  # look at file size and block size on disk
287 $DIFF tmpSparse2M tmpSparseRegenerated
288 rm tmpSparse*
289
290
291 $ECHO "\n===>  multiple files tests "
292
293 ./datagen -s1        > tmp1 2> $INTOVOID
294 ./datagen -s2 -g100K > tmp2 2> $INTOVOID
295 ./datagen -s3 -g1M   > tmp3 2> $INTOVOID
296 $ECHO "compress tmp* : "
297 $ZSTD -f tmp*
298 ls -ls tmp*
299 rm tmp1 tmp2 tmp3
300 $ECHO "decompress tmp* : "
301 $ZSTD -df *.zst
302 ls -ls tmp*
303 $ECHO "compress tmp* into stdout > tmpall : "
304 $ZSTD -c tmp1 tmp2 tmp3 > tmpall
305 ls -ls tmp*  # check size of tmpall (should be tmp1.zst + tmp2.zst + tmp3.zst)
306 $ECHO "decompress tmpall* into stdout > tmpdec : "
307 cp tmpall tmpall2
308 $ZSTD -dc tmpall* > tmpdec
309 ls -ls tmp* # check size of tmpdec (should be 2*(tmp1 + tmp2 + tmp3))
310 $ECHO "compress multiple files including a missing one (notHere) : "
311 $ZSTD -f tmp1 notHere tmp2 && die "missing file not detected!"
312
313
314 $ECHO "\n===>  dictionary tests "
315
316 $ECHO "- test with raw dict (content only) "
317 ./datagen > tmpDict
318 ./datagen -g1M | $MD5SUM > tmp1
319 ./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dvq | $MD5SUM > tmp2
320 $DIFF -q tmp1 tmp2
321 $ECHO "- Create first dictionary "
322 TESTFILE=../programs/zstdcli.c
323 $ZSTD --train *.c ../programs/*.c -o tmpDict
324 cp $TESTFILE tmp
325 $ZSTD -f tmp -D tmpDict
326 $ZSTD -d tmp.zst -D tmpDict -fo result
327 $DIFF $TESTFILE result
328 if [ -n "$hasMT" ]
329 then
330     $ECHO "- Test dictionary compression with multithreading "
331     ./datagen -g5M | $ZSTD -T2 -D tmpDict | $ZSTD -t -D tmpDict   # fails with v1.3.2
332 fi
333 $ECHO "- Create second (different) dictionary "
334 $ZSTD --train *.c ../programs/*.c ../programs/*.h -o tmpDictC
335 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
336 $ECHO "- Create dictionary with short dictID"
337 $ZSTD --train *.c ../programs/*.c --dictID=1 -o tmpDict1
338 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
339 $ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
340 $ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
341 $ECHO "- Create dictionary with size limit"
342 $ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict=4K -v
343 $ECHO "- Create dictionary with small size limit"
344 $ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict=1K -v
345 $ECHO "- Create dictionary with wrong parameter order (must fail)"
346 $ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict -v 4K && die "wrong order : --maxdict must be followed by argument "
347 $ECHO "- Compress without dictID"
348 $ZSTD -f tmp -D tmpDict1 --no-dictID
349 $ZSTD -d tmp.zst -D tmpDict -fo result
350 $DIFF $TESTFILE result
351 $ECHO "- Compress with wrong argument order (must fail)"
352 $ZSTD tmp -Df tmpDict1 -c > $INTOVOID && die "-D must be followed by dictionary name "
353 $ECHO "- Compress multiple files with dictionary"
354 rm -rf dirTestDict
355 mkdir dirTestDict
356 cp *.c dirTestDict
357 cp ../programs/*.c dirTestDict
358 cp ../programs/*.h dirTestDict
359 $MD5SUM dirTestDict/* > tmph1
360 $ZSTD -f --rm dirTestDict/* -D tmpDictC
361 $ZSTD -d --rm dirTestDict/*.zst -D tmpDictC  # note : use internal checksum by default
362 case "$UNAME" in
363   Darwin) $ECHO "md5sum -c not supported on OS-X : test skipped" ;;  # not compatible with OS-X's md5
364   *) $MD5SUM -c tmph1 ;;
365 esac
366 rm -rf dirTestDict
367 $ECHO "- dictionary builder on bogus input"
368 $ECHO "Hello World" > tmp
369 $ZSTD --train-legacy -q tmp && die "Dictionary training should fail : not enough input source"
370 ./datagen -P0 -g10M > tmp
371 $ZSTD --train-legacy -q tmp && die "Dictionary training should fail : source is pure noise"
372 rm tmp*
373
374
375 $ECHO "\n===>  cover dictionary builder : advanced options "
376
377 TESTFILE=../programs/zstdcli.c
378 ./datagen > tmpDict
379 $ECHO "- Create first dictionary"
380 $ZSTD --train-cover=k=46,d=8 *.c ../programs/*.c -o tmpDict
381 cp $TESTFILE tmp
382 $ZSTD -f tmp -D tmpDict
383 $ZSTD -d tmp.zst -D tmpDict -fo result
384 $DIFF $TESTFILE result
385 $ECHO "- Create second (different) dictionary"
386 $ZSTD --train-cover=k=56,d=8 *.c ../programs/*.c ../programs/*.h -o tmpDictC
387 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
388 $ECHO "- Create dictionary with short dictID"
389 $ZSTD --train-cover=k=46,d=8 *.c ../programs/*.c --dictID=1 -o tmpDict1
390 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
391 $ECHO "- Create dictionary with size limit"
392 $ZSTD --train-cover=steps=8 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
393 rm tmp*
394
395 $ECHO "\n===>  legacy dictionary builder "
396
397 TESTFILE=../programs/zstdcli.c
398 ./datagen > tmpDict
399 $ECHO "- Create first dictionary"
400 $ZSTD --train-legacy=selectivity=8 *.c ../programs/*.c -o tmpDict
401 cp $TESTFILE tmp
402 $ZSTD -f tmp -D tmpDict
403 $ZSTD -d tmp.zst -D tmpDict -fo result
404 $DIFF $TESTFILE result
405 $ECHO "- Create second (different) dictionary"
406 $ZSTD --train-legacy=s=5 *.c ../programs/*.c ../programs/*.h -o tmpDictC
407 $ZSTD -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
408 $ECHO "- Create dictionary with short dictID"
409 $ZSTD --train-legacy -s5 *.c ../programs/*.c --dictID=1 -o tmpDict1
410 cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
411 $ECHO "- Create dictionary with size limit"
412 $ZSTD --train-legacy -s9 *.c ../programs/*.c -o tmpDict2 --maxdict=4K
413 rm tmp*
414
415
416 $ECHO "\n===>  integrity tests "
417
418 $ECHO "test one file (tmp1.zst) "
419 ./datagen > tmp1
420 $ZSTD tmp1
421 $ZSTD -t tmp1.zst
422 $ZSTD --test tmp1.zst
423 $ECHO "test multiple files (*.zst) "
424 $ZSTD -t *.zst
425 $ECHO "test bad files (*) "
426 $ZSTD -t * && die "bad files not detected !"
427 $ZSTD -t tmp1 && die "bad file not detected !"
428 cp tmp1 tmp2.zst
429 $ZSTD -t tmp2.zst && die "bad file not detected !"
430 ./datagen -g0 > tmp3
431 $ZSTD -t tmp3 && die "bad file not detected !"   # detects 0-sized files as bad
432 $ECHO "test --rm and --test combined "
433 $ZSTD -t --rm tmp1.zst
434 test -f tmp1.zst   # check file is still present
435 split -b16384 tmp1.zst tmpSplit.
436 $ZSTD -t tmpSplit.* && die "bad file not detected !"
437 ./datagen | $ZSTD -c | $ZSTD -t
438
439
440
441 $ECHO "\n===>  golden files tests "
442
443 $ZSTD -t -r files
444 $ZSTD -c -r files | $ZSTD -t
445
446
447 $ECHO "\n===>  benchmark mode tests "
448
449 $ECHO "bench one file"
450 ./datagen > tmp1
451 $ZSTD -bi0 tmp1
452 $ECHO "bench multiple levels"
453 $ZSTD -i0b0e3 tmp1
454 $ECHO "with recursive and quiet modes"
455 $ZSTD -rqi1b1e2 tmp1
456
457
458 $ECHO "\n===>  gzip compatibility tests "
459
460 GZIPMODE=1
461 $ZSTD --format=gzip -V || GZIPMODE=0
462 if [ $GZIPMODE -eq 1 ]; then
463     $ECHO "gzip support detected"
464     GZIPEXE=1
465     gzip -V || GZIPEXE=0
466     if [ $GZIPEXE -eq 1 ]; then
467         ./datagen > tmp
468         $ZSTD --format=gzip -f tmp
469         gzip -t -v tmp.gz
470         gzip -f tmp
471         $ZSTD -d -f -v tmp.gz
472         rm tmp*
473     else
474         $ECHO "gzip binary not detected"
475     fi
476 else
477     $ECHO "gzip mode not supported"
478 fi
479
480
481 $ECHO "\n===>  gzip frame tests "
482
483 if [ $GZIPMODE -eq 1 ]; then
484     ./datagen > tmp
485     $ZSTD -f --format=gzip tmp
486     $ZSTD -f tmp
487     cat tmp.gz tmp.zst tmp.gz tmp.zst | $ZSTD -d -f -o tmp
488     head -c -1 tmp.gz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
489     rm tmp*
490 else
491     $ECHO "gzip mode not supported"
492 fi
493
494
495 $ECHO "\n===>  xz compatibility tests "
496
497 LZMAMODE=1
498 $ZSTD --format=xz -V || LZMAMODE=0
499 if [ $LZMAMODE -eq 1 ]; then
500     $ECHO "xz support detected"
501     XZEXE=1
502     xz -V && lzma -V || XZEXE=0
503     if [ $XZEXE -eq 1 ]; then
504         $ECHO "Testing zstd xz and lzma support"
505         ./datagen > tmp
506         $ZSTD --format=lzma -f tmp
507         $ZSTD --format=xz -f tmp
508         xz -t -v tmp.xz
509         xz -t -v tmp.lzma
510         xz -f -k tmp
511         lzma -f -k --lzma1 tmp
512         $ZSTD -d -f -v tmp.xz
513         $ZSTD -d -f -v tmp.lzma
514         rm tmp*
515         $ECHO "Creating symlinks"
516         ln -s $ZSTD ./xz
517         ln -s $ZSTD ./unxz
518         ln -s $ZSTD ./lzma
519         ln -s $ZSTD ./unlzma
520         $ECHO "Testing xz and lzma symlinks"
521         ./datagen > tmp
522         ./xz tmp
523         xz -d tmp.xz
524         ./lzma tmp
525         lzma -d tmp.lzma
526         $ECHO "Testing unxz and unlzma symlinks"
527         xz tmp
528         ./xz -d tmp.xz
529         lzma tmp
530         ./lzma -d tmp.lzma
531         rm xz unxz lzma unlzma
532         rm tmp*
533     else
534         $ECHO "xz binary not detected"
535     fi
536 else
537     $ECHO "xz mode not supported"
538 fi
539
540
541 $ECHO "\n===>  xz frame tests "
542
543 if [ $LZMAMODE -eq 1 ]; then
544     ./datagen > tmp
545     $ZSTD -f --format=xz tmp
546     $ZSTD -f --format=lzma tmp
547     $ZSTD -f tmp
548     cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | $ZSTD -d -f -o tmp
549     head -c -1 tmp.xz | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
550     head -c -1 tmp.lzma | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
551     rm tmp*
552 else
553     $ECHO "xz mode not supported"
554 fi
555
556 $ECHO "\n===>  lz4 compatibility tests "
557
558 LZ4MODE=1
559 $ZSTD --format=lz4 -V || LZ4MODE=0
560 if [ $LZ4MODE -eq 1 ]; then
561     $ECHO "lz4 support detected"
562     LZ4EXE=1
563     lz4 -V || LZ4EXE=0
564     if [ $LZ4EXE -eq 1 ]; then
565         ./datagen > tmp
566         $ZSTD --format=lz4 -f tmp
567         lz4 -t -v tmp.lz4
568         lz4 -f tmp
569         $ZSTD -d -f -v tmp.lz4
570         rm tmp*
571     else
572         $ECHO "lz4 binary not detected"
573     fi
574 else
575     $ECHO "lz4 mode not supported"
576 fi
577
578
579 $ECHO "\n===>  lz4 frame tests "
580
581 if [ $LZ4MODE -eq 1 ]; then
582     ./datagen > tmp
583     $ZSTD -f --format=lz4 tmp
584     $ZSTD -f tmp
585     cat tmp.lz4 tmp.zst tmp.lz4 tmp.zst | $ZSTD -d -f -o tmp
586     head -c -1 tmp.lz4 | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
587     rm tmp*
588 else
589     $ECHO "lz4 mode not supported"
590 fi
591
592 $ECHO "\n===>  zstd round-trip tests "
593
594 roundTripTest
595 roundTripTest -g15K       # TableID==3
596 roundTripTest -g127K      # TableID==2
597 roundTripTest -g255K      # TableID==1
598 roundTripTest -g522K      # TableID==0
599 roundTripTest -g519K 6    # greedy, hash chain
600 roundTripTest -g517K 16   # btlazy2
601 roundTripTest -g516K 19   # btopt
602
603 fileRoundTripTest -g500K
604
605 $ECHO "\n===>  zstd long distance matching round-trip tests "
606 roundTripTest -g0 "2 --long"
607 roundTripTest -g1000K "1 --long"
608 roundTripTest -g517K "6 --long"
609 roundTripTest -g516K "16 --long"
610 roundTripTest -g518K "19 --long"
611 fileRoundTripTest -g5M "3 --long"
612
613
614 if [ -n "$hasMT" ]
615 then
616     $ECHO "\n===>  zstdmt round-trip tests "
617     roundTripTest -g4M "1 -T0"
618     roundTripTest -g8M "3 -T2"
619     roundTripTest -g8000K "2 --threads=2"
620     fileRoundTripTest -g4M "19 -T2 -B1M"
621
622     $ECHO "\n===>  zstdmt long distance matching round-trip tests "
623     roundTripTest -g8M "3 --long -T2"
624 else
625     $ECHO "\n===>  no multithreading, skipping zstdmt tests "
626 fi
627
628 rm tmp*
629
630 $ECHO "\n===>  zstd --list/-l single frame tests "
631 ./datagen > tmp1
632 ./datagen > tmp2
633 ./datagen > tmp3
634 $ZSTD tmp*
635 $ZSTD -l *.zst
636 $ZSTD -lv *.zst | grep "Decompressed Size:"  # check that decompressed size is present in header
637 $ZSTD --list *.zst
638 $ZSTD --list -v *.zst
639
640 $ECHO "\n===>  zstd --list/-l multiple frame tests "
641 cat tmp1.zst tmp2.zst > tmp12.zst
642 cat tmp12.zst tmp3.zst > tmp123.zst
643 $ZSTD -l *.zst
644 $ZSTD -lv *.zst
645
646 $ECHO "\n===>  zstd --list/-l error detection tests "
647 ! $ZSTD -l tmp1 tmp1.zst
648 ! $ZSTD --list tmp*
649 ! $ZSTD -lv tmp1*
650 ! $ZSTD --list -v tmp2 tmp12.zst
651
652 $ECHO "\n===>  zstd --list/-l test with null files "
653 ./datagen -g0 > tmp5
654 $ZSTD tmp5
655 $ZSTD -l tmp5.zst
656 ! $ZSTD -l tmp5*
657 $ZSTD -lv tmp5.zst | grep "Decompressed Size: 0.00 KB (0 B)"  # check that 0 size is present in header
658 ! $ZSTD -lv tmp5*
659
660 $ECHO "\n===>  zstd --list/-l test with no content size field "
661 ./datagen -g513K | $ZSTD > tmp6.zst
662 $ZSTD -l tmp6.zst
663 ! $ZSTD -lv tmp6.zst | grep "Decompressed Size:"  # must NOT be present in header
664
665 $ECHO "\n===>   zstd --list/-l test with no checksum "
666 $ZSTD -f --no-check tmp1
667 $ZSTD -l tmp1.zst
668 $ZSTD -lv tmp1.zst
669
670 rm tmp*
671
672
673 $ECHO "\n===>   zstd long distance matching tests "
674 roundTripTest -g0 " --long"
675 roundTripTest -g9M "2 --long"
676 # Test parameter parsing
677 roundTripTest -g1M -P50 "1 --long=29" " --memory=512MB"
678 roundTripTest -g1M -P50 "1 --long=29 --zstd=wlog=28" " --memory=256MB"
679 roundTripTest -g1M -P50 "1 --long=29" " --long=28 --memory=512MB"
680 roundTripTest -g1M -P50 "1 --long=29" " --zstd=wlog=28 --memory=512MB"
681
682
683 if [ "$1" != "--test-large-data" ]; then
684     $ECHO "Skipping large data tests"
685     exit 0
686 fi
687
688 $ECHO "\n===>   large files tests "
689
690 roundTripTest -g270000000 1
691 roundTripTest -g250000000 2
692 roundTripTest -g230000000 3
693
694 roundTripTest -g140000000 -P60 4
695 roundTripTest -g130000000 -P62 5
696 roundTripTest -g120000000 -P65 6
697
698 roundTripTest -g70000000 -P70 7
699 roundTripTest -g60000000 -P71 8
700 roundTripTest -g50000000 -P73 9
701
702 roundTripTest -g35000000 -P75 10
703 roundTripTest -g30000000 -P76 11
704 roundTripTest -g25000000 -P78 12
705
706 roundTripTest -g18000013 -P80 13
707 roundTripTest -g18000014 -P80 14
708 roundTripTest -g18000015 -P81 15
709 roundTripTest -g18000016 -P84 16
710 roundTripTest -g18000017 -P88 17
711 roundTripTest -g18000018 -P94 18
712 roundTripTest -g18000019 -P96 19
713
714 roundTripTest -g5000000000 -P99 1
715
716 fileRoundTripTest -g4193M -P99 1
717
718
719 $ECHO "\n===>   zstd long, long distance matching round-trip tests "
720 roundTripTest -g270000000 "1 --long"
721 roundTripTest -g130000000 -P60 "5 --long"
722 roundTripTest -g35000000 -P70 "8 --long"
723 roundTripTest -g18000001 -P80  "18 --long"
724 # Test large window logs
725 roundTripTest -g700M -P50 "1 --long=29"
726 roundTripTest -g600M -P50 "1 --long --zstd=wlog=29,clog=28"
727
728
729 if [ -n "$hasMT" ]
730 then
731     $ECHO "\n===>   zstdmt long round-trip tests "
732     roundTripTest -g80000000 -P99 "19 -T2" " "
733     roundTripTest -g5000000000 -P99 "1 -T2" " "
734     roundTripTest -g500000000 -P97 "1 -T999" " "
735     fileRoundTripTest -g4103M -P98 " -T0" " "
736     roundTripTest -g400000000 -P97 "1 --long=24 -T2" " "
737 else
738     $ECHO "\n**** no multithreading, skipping zstdmt tests **** "
739 fi
740
741 rm tmp*