2019-05-02 19:35:37 +00:00
#!/bin/sh
set -e
2015-12-08 15:11:10 +00:00
die( ) {
2019-05-02 19:35:37 +00:00
println " $@ " 1>& 2
2015-12-08 15:11:10 +00:00
exit 1
}
2020-03-26 22:04:15 +00:00
datagen( ) {
2020-06-02 16:12:13 +00:00
" $DATAGEN_BIN " " $@ "
2020-03-26 22:04:15 +00:00
}
zstd( ) {
if [ -z " $EXEC_PREFIX " ] ; then
2020-06-02 16:12:13 +00:00
" $ZSTD_BIN " " $@ "
2020-03-26 22:04:15 +00:00
else
2020-06-02 16:12:13 +00:00
" $EXEC_PREFIX " " $ZSTD_BIN " " $@ "
2020-03-26 22:04:15 +00:00
fi
}
sudoZstd( ) {
if [ -z " $EXEC_PREFIX " ] ; then
2020-06-02 16:12:13 +00:00
sudo " $ZSTD_BIN " " $@ "
2020-03-26 22:04:15 +00:00
else
2020-06-02 16:12:13 +00:00
sudo " $EXEC_PREFIX " " $ZSTD_BIN " " $@ "
2020-03-26 22:04:15 +00:00
fi
}
2015-12-08 15:36:37 +00:00
roundTripTest( ) {
if [ -n " $3 " ] ; then
2017-07-11 00:16:41 +00:00
cLevel = " $3 "
proba = " $2 "
2015-12-08 15:36:37 +00:00
else
2017-07-11 00:16:41 +00:00
cLevel = " $2 "
proba = ""
2015-12-08 15:36:37 +00:00
fi
2017-09-22 21:04:39 +00:00
if [ -n " $4 " ] ; then
dLevel = " $4 "
else
dLevel = " $cLevel "
fi
2015-12-08 15:36:37 +00:00
rm -f tmp1 tmp2
2020-03-26 22:04:15 +00:00
println " roundTripTest: datagen $1 $proba | zstd -v $cLevel | zstd -d $dLevel "
datagen $1 $proba | $MD5SUM > tmp1
datagen $1 $proba | zstd --ultra -v$cLevel | zstd -d$dLevel | $MD5SUM > tmp2
2016-12-22 17:05:07 +00:00
$DIFF -q tmp1 tmp2
2015-12-08 15:36:37 +00:00
}
2017-04-12 00:15:13 +00:00
fileRoundTripTest( ) {
if [ -n " $3 " ] ; then
local_c = " $3 "
local_p = " $2 "
else
local_c = " $2 "
local_p = ""
fi
2017-09-22 21:04:39 +00:00
if [ -n " $4 " ] ; then
local_d = " $4 "
else
local_d = " $local_c "
fi
2017-04-12 00:15:13 +00:00
2020-03-26 22:04:15 +00:00
rm -f tmp.zst tmp.md5.1 tmp.md5.2
println " fileRoundTripTest: datagen $1 $local_p > tmp && zstd -v $local_c -c tmp | zstd -d $local_d "
datagen $1 $local_p > tmp
2017-10-06 03:21:59 +00:00
< tmp $MD5SUM > tmp.md5.1
2020-03-26 22:04:15 +00:00
zstd --ultra -v$local_c -c tmp | zstd -d$local_d | $MD5SUM > tmp.md5.2
2017-04-12 00:15:13 +00:00
$DIFF -q tmp.md5.1 tmp.md5.2
}
2018-06-30 13:42:42 +00:00
truncateLastByte( ) {
2019-05-02 19:35:37 +00:00
dd bs = 1 count = $(( $( wc -c < " $1 " ) - 1 )) if = " $1 "
}
println( ) {
printf '%b\n' " ${ * } "
2018-06-30 13:42:42 +00:00
}
2020-06-02 16:12:50 +00:00
if [ -z " ${ size } " ] ; then
size =
else
size = ${ size }
fi
2019-05-02 19:35:37 +00:00
SCRIPT_DIR = $( cd " $( dirname " $0 " ) " && pwd )
PRGDIR = " $SCRIPT_DIR /../programs "
TESTDIR = " $SCRIPT_DIR /../tests "
2018-06-30 11:01:58 +00:00
UNAME = $( uname)
2020-03-02 21:04:37 +00:00
ZSTDGREP = " $PRGDIR /zstdgrep "
2018-06-30 11:01:58 +00:00
2019-10-17 22:07:47 +00:00
detectedTerminal = false
2017-03-17 19:32:18 +00:00
if [ -t 0 ] && [ -t 1 ]
then
2019-10-17 22:07:47 +00:00
detectedTerminal = true
2017-03-17 19:32:18 +00:00
fi
2019-10-17 22:07:47 +00:00
isTerminal = ${ isTerminal :- $detectedTerminal }
2017-03-17 19:32:18 +00:00
2016-05-25 08:50:28 +00:00
isWindows = false
2016-06-21 15:06:25 +00:00
INTOVOID = "/dev/null"
2018-06-30 11:01:58 +00:00
case " $UNAME " in
2018-07-11 12:41:50 +00:00
GNU) DEVDEVICE = "/dev/random" ; ;
*) DEVDEVICE = "/dev/zero" ; ;
2018-06-30 11:01:58 +00:00
esac
2016-05-27 08:07:46 +00:00
case " $OS " in
2016-06-05 22:26:38 +00:00
Windows*)
2016-05-25 08:50:28 +00:00
isWindows = true
2017-03-17 19:32:18 +00:00
INTOVOID = "NUL"
2017-12-13 20:04:46 +00:00
DEVDEVICE = "NUL"
2016-05-27 08:07:46 +00:00
; ;
esac
2016-05-25 08:50:28 +00:00
2016-12-12 18:22:47 +00:00
case " $UNAME " in
Darwin) MD5SUM = "md5 -r" ; ;
FreeBSD) MD5SUM = "gmd5sum" ; ;
2018-04-02 21:12:18 +00:00
OpenBSD) MD5SUM = "md5" ; ;
2016-12-06 20:02:56 +00:00
*) MD5SUM = "md5sum" ; ;
esac
2016-05-25 08:50:28 +00:00
2019-11-06 11:16:02 +00:00
MTIME = "stat -c %Y"
case " $UNAME " in
Darwin | FreeBSD | OpenBSD) MTIME = "stat -f %m" ; ;
esac
2016-12-22 17:05:07 +00:00
DIFF = "diff"
case " $UNAME " in
SunOS) DIFF = "gdiff" ; ;
esac
2015-12-08 15:36:37 +00:00
2020-06-03 17:49:21 +00:00
# check if ZSTD_BIN is defined. if not, use the default value
2020-06-03 18:36:38 +00:00
if [ -z " ${ ZSTD_BIN } " ] ; then
2020-06-03 17:49:21 +00:00
println "\nZSTD_BIN is not set. Using the default value..."
ZSTD_BIN = " $PRGDIR /zstd "
fi
# check if DATAGEN_BIN is defined. if not, use the default value
2020-06-03 18:36:38 +00:00
if [ -z " ${ DATAGEN_BIN } " ] ; then
2020-06-03 17:49:21 +00:00
println "\nDATAGEN_BIN is not set. Using the default value..."
DATAGEN_BIN = " $TESTDIR /datagen "
fi
ZSTD_BIN = " $EXE_PREFIX $ZSTD_BIN "
# assertions
[ -n " $ZSTD_BIN " ] || die " zstd not found at $ZSTD_BIN ! \n Please define ZSTD_BIN pointing to the zstd binary. You might also consider rebuilding zstd follwing the instructions in README.md "
[ -n " $DATAGEN_BIN " ] || die " datagen not found at $DATAGEN_BIN ! \n Please define DATAGEN_BIN pointing to the datagen binary. You might also consider rebuilding zstd tests following the instructions in README.md. "
println " \nStarting playTests.sh isWindows= $isWindows EXE_PREFIX=' $EXE_PREFIX ' ZSTD_BIN=' $ZSTD_BIN ' DATAGEN_BIN=' $DATAGEN_BIN ' "
2016-02-12 14:56:46 +00:00
2020-03-26 22:04:15 +00:00
if echo hello | zstd -v -T2 2>& 1 > $INTOVOID | grep -q 'multi-threading is disabled'
2017-04-17 18:38:53 +00:00
then
hasMT = ""
else
hasMT = "true"
fi
2018-01-06 11:31:26 +00:00
2019-11-26 22:18:09 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> simple tests "
2016-05-23 17:46:47 +00:00
2020-03-26 22:04:15 +00:00
datagen > tmp
2019-05-02 19:35:37 +00:00
println "test : basic compression "
2020-03-26 22:04:15 +00:00
zstd -f tmp # trivial compression case, creates tmp.zst
2019-05-02 19:35:37 +00:00
println "test : basic decompression"
2020-03-26 22:04:15 +00:00
zstd -df tmp.zst # trivial decompression case (overwrites tmp)
2019-05-02 19:35:37 +00:00
println "test : too large compression level => auto-fix"
2020-03-26 22:04:15 +00:00
zstd -99 -f tmp # too large compression level, automatic sized down
zstd -5000000000 -f tmp && die "too large numeric value : must fail"
2019-05-02 19:35:37 +00:00
println "test : --fast aka negative compression levels"
2020-03-26 22:04:15 +00:00
zstd --fast -f tmp # == -1
zstd --fast= 3 -f tmp # == -3
zstd --fast= 200000 -f tmp # too low compression level, automatic fixed
zstd --fast= 5000000000 -f tmp && die "too large numeric value : must fail"
zstd -c --fast= 0 tmp > $INTOVOID && die "--fast must not accept value 0"
2019-05-02 19:35:37 +00:00
println "test : too large numeric argument"
2020-03-26 22:04:15 +00:00
zstd --fast= 9999999999 -f tmp && die "should have refused numeric value"
2019-05-02 19:35:37 +00:00
println "test : set compression level with environment variable ZSTD_CLEVEL"
2020-03-26 22:04:15 +00:00
ZSTD_CLEVEL = 12 zstd -f tmp # positive compression level
ZSTD_CLEVEL = -12 zstd -f tmp # negative compression level
ZSTD_CLEVEL = +12 zstd -f tmp # valid: verbose '+' sign
ZSTD_CLEVEL = '' zstd -f tmp # empty env var, warn and revert to default setting
ZSTD_CLEVEL = - zstd -f tmp # malformed env var, warn and revert to default setting
ZSTD_CLEVEL = a zstd -f tmp # malformed env var, warn and revert to default setting
ZSTD_CLEVEL = +a zstd -f tmp # malformed env var, warn and revert to default setting
ZSTD_CLEVEL = 3a7 zstd -f tmp # malformed env var, warn and revert to default setting
ZSTD_CLEVEL = 50000000000 zstd -f tmp # numeric value too large, warn and revert to default setting
2019-05-02 19:35:37 +00:00
println "test : override ZSTD_CLEVEL with command line option"
2020-03-26 22:04:15 +00:00
ZSTD_CLEVEL = 12 zstd --fast= 3 -f tmp # overridden by command line option
2019-05-02 19:35:37 +00:00
println "test : compress to stdout"
2020-03-26 22:04:15 +00:00
zstd tmp -c > tmpCompressed
zstd tmp --stdout > tmpCompressed # long command format
2019-05-02 19:35:37 +00:00
println "test : compress to named file"
2016-09-21 12:20:56 +00:00
rm tmpCompressed
2020-03-26 22:04:15 +00:00
zstd tmp -o tmpCompressed
2017-05-06 02:15:24 +00:00
test -f tmpCompressed # file must be created
2019-05-02 19:35:37 +00:00
println "test : force write, correct order"
2020-03-26 22:04:15 +00:00
zstd tmp -fo tmpCompressed
2019-05-02 19:35:37 +00:00
println "test : forgotten argument"
2016-09-21 14:05:03 +00:00
cp tmp tmp2
2020-03-26 22:04:15 +00:00
zstd tmp2 -fo && die "-o must be followed by filename "
2019-05-02 19:35:37 +00:00
println "test : implied stdout when input is stdin"
2020-03-26 22:04:15 +00:00
println bob | zstd | zstd -d
2017-03-17 19:32:18 +00:00
if [ " $isTerminal " = true ] ; then
2019-05-02 19:35:37 +00:00
println "test : compressed data to terminal"
2020-03-26 22:04:15 +00:00
println bob | zstd && die "should have refused : compressed data to terminal"
2019-05-02 19:35:37 +00:00
println "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)"
2020-03-26 22:04:15 +00:00
zstd -d > $INTOVOID && die "should have refused : compressed data from terminal"
2017-03-17 19:32:18 +00:00
fi
2019-05-02 19:35:37 +00:00
println "test : null-length file roundtrip"
2020-03-26 22:04:15 +00:00
println -n '' | zstd - --stdout | zstd -d --stdout
2019-05-02 19:35:37 +00:00
println "test : ensure small file doesn't add 3-bytes null block"
2020-03-26 22:04:15 +00:00
datagen -g1 > tmp1
zstd tmp1 -c | wc -c | grep "14"
zstd < tmp1 | wc -c | grep "14"
2019-05-02 19:35:37 +00:00
println "test : decompress file with wrong suffix (must fail)"
2020-03-26 22:04:15 +00:00
zstd -d tmpCompressed && die "wrong suffix error not detected!"
zstd -df tmp && die "should have refused : wrong extension"
2019-05-02 19:35:37 +00:00
println "test : decompress into stdout"
2020-03-26 22:04:15 +00:00
zstd -d tmpCompressed -c > tmpResult # decompression using stdout
zstd --decompress tmpCompressed -c > tmpResult
zstd --decompress tmpCompressed --stdout > tmpResult
2019-05-02 19:35:37 +00:00
println "test : decompress from stdin into stdout"
2020-03-26 22:04:15 +00:00
zstd -dc < tmp.zst > $INTOVOID # combine decompression, stdin & stdout
zstd -dc - < tmp.zst > $INTOVOID
zstd -d < tmp.zst > $INTOVOID # implicit stdout when stdin is used
zstd -d - < tmp.zst > $INTOVOID
2019-05-02 19:35:37 +00:00
println "test : impose memory limitation (must fail)"
2020-03-26 22:04:15 +00:00
zstd -d -f tmp.zst -M2K -c > $INTOVOID && die "decompression needs more memory than allowed"
zstd -d -f tmp.zst --memlimit= 2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
zstd -d -f tmp.zst --memory= 2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
zstd -d -f tmp.zst --memlimit-decompress= 2K -c > $INTOVOID && die "decompression needs more memory than allowed" # long command
2019-05-02 19:35:37 +00:00
println "test : overwrite protection"
2020-03-26 22:04:15 +00:00
zstd -q tmp && die "overwrite check failed!"
2019-05-02 19:35:37 +00:00
println "test : force overwrite"
2020-03-26 22:04:15 +00:00
zstd -q -f tmp
zstd -q --force tmp
2019-05-02 19:35:37 +00:00
println "test : overwrite readonly file"
2017-04-07 00:06:30 +00:00
rm -f tmpro tmpro.zst
2019-05-02 19:35:37 +00:00
println foo > tmpro.zst
println foo > tmpro
2017-04-06 19:58:49 +00:00
chmod 400 tmpro.zst
2020-03-26 22:04:15 +00:00
zstd -q tmpro && die "should have refused to overwrite read-only file"
zstd -q -f tmpro
2019-05-02 19:35:37 +00:00
println "test: --no-progress flag"
2020-03-26 22:04:15 +00:00
zstd tmpro -c --no-progress | zstd -d -f -o " $INTOVOID " --no-progress
zstd tmpro -cv --no-progress | zstd -dv -f -o " $INTOVOID " --no-progress
2017-04-07 00:06:30 +00:00
rm -f tmpro tmpro.zst
2019-05-02 19:35:37 +00:00
println "test: overwrite input file (must fail)"
2020-03-26 22:04:15 +00:00
zstd tmp -fo tmp && die "zstd compression overwrote the input file"
zstd tmp.zst -dfo tmp.zst && die "zstd decompression overwrote the input file"
2019-05-02 19:35:37 +00:00
println "test: detect that input file does not exist"
2020-03-26 22:04:15 +00:00
zstd nothere && die "zstd hasn't detected that input file does not exist"
2019-05-02 19:35:37 +00:00
println "test: --[no-]compress-literals"
2020-03-26 22:04:15 +00:00
zstd tmp -c --no-compress-literals -1 | zstd -t
zstd tmp -c --no-compress-literals --fast= 1 | zstd -t
zstd tmp -c --no-compress-literals -19 | zstd -t
zstd tmp -c --compress-literals -1 | zstd -t
zstd tmp -c --compress-literals --fast= 1 | zstd -t
zstd tmp -c --compress-literals -19 | zstd -t
zstd -b --fast= 1 -i0e1 tmp --compress-literals
zstd -b --fast= 1 -i0e1 tmp --no-compress-literals
2020-08-22 20:05:40 +00:00
println "test: --no-check for decompression"
2020-08-24 21:28:00 +00:00
zstd -f tmp -o tmp_corrupt.zst --check
zstd -f tmp -o tmp.zst --no-check
printf '\xDE\xAD\xBE\xEF' | dd of = tmp_corrupt.zst bs = 1 seek = $(( $( wc -c < "tmp_corrupt.zst" ) - 4 )) count = 4 conv = notrunc # corrupt checksum in tmp
zstd -d -f tmp_corrupt.zst --no-check
zstd -d -f tmp_corrupt.zst --check --no-check # final flag overrides
2020-08-22 20:05:40 +00:00
zstd -d -f tmp.zst --no-check
2018-09-27 23:49:08 +00:00
2020-03-02 21:04:37 +00:00
println "\n===> zstdgrep tests"
2020-03-26 22:04:15 +00:00
ln -sf " $ZSTD_BIN " zstdcat
2020-03-02 21:04:37 +00:00
rm -f tmp_grep
echo "1234" > tmp_grep
2020-03-26 22:04:15 +00:00
zstd -f tmp_grep
2020-03-02 21:04:37 +00:00
lines = $( ZCAT = ./zstdcat $ZSTDGREP 2>& 1 "1234" tmp_grep tmp_grep.zst | wc -l)
test 2 -eq $lines
ZCAT = ./zstdcat $ZSTDGREP 2>& 1 "1234" tmp_grep_bad.zst && die "Should have failed"
ZCAT = ./zstdcat $ZSTDGREP 2>& 1 "1234" tmp_grep_bad.zst | grep "No such file or directory" || true
rm -f tmp_grep*
2019-11-25 18:35:36 +00:00
println "\n===> --exclude-compressed flag"
2019-10-29 16:54:54 +00:00
rm -rf precompressedFilterTestDir
2019-10-29 05:24:01 +00:00
mkdir -p precompressedFilterTestDir
2020-03-26 22:04:15 +00:00
datagen $size > precompressedFilterTestDir/input.5
datagen $size > precompressedFilterTestDir/input.6
zstd --exclude-compressed --long --rm -r precompressedFilterTestDir
datagen $size > precompressedFilterTestDir/input.7
datagen $size > precompressedFilterTestDir/input.8
zstd --exclude-compressed --long --rm -r precompressedFilterTestDir
2019-10-29 20:36:09 +00:00
test ! -f precompressedFilterTestDir/input.5.zst.zst
test ! -f precompressedFilterTestDir/input.6.zst.zst
2019-11-06 11:16:02 +00:00
file1timestamp = ` $MTIME precompressedFilterTestDir/input.5.zst`
file2timestamp = ` $MTIME precompressedFilterTestDir/input.7.zst`
2020-05-18 18:54:06 +00:00
if [ $file2timestamp -ge $file1timestamp ] ; then
2019-10-29 19:27:54 +00:00
println "Test is successful. input.5.zst is precompressed and therefore not compressed/modified again."
2019-10-25 22:49:11 +00:00
else
println "Test is not successful"
fi
2019-12-02 22:28:18 +00:00
# File Extension check.
2020-03-26 22:04:15 +00:00
datagen $size > precompressedFilterTestDir/input.zstbar
zstd --exclude-compressed --long --rm -r precompressedFilterTestDir
# zstd should compress input.zstbar
2019-10-29 20:36:09 +00:00
test -f precompressedFilterTestDir/input.zstbar.zst
2019-12-02 22:28:18 +00:00
# Check without the --exclude-compressed flag
2020-03-26 22:04:15 +00:00
zstd --long --rm -r precompressedFilterTestDir
2019-12-02 22:28:18 +00:00
# Files should get compressed again without the --exclude-compressed flag.
2019-10-29 20:36:09 +00:00
test -f precompressedFilterTestDir/input.5.zst.zst
test -f precompressedFilterTestDir/input.6.zst.zst
2019-10-25 22:49:11 +00:00
println "Test completed"
2019-12-02 22:28:18 +00:00
println "\n===> recursive mode test "
# combination of -r with empty list of input file
2020-03-26 22:04:15 +00:00
zstd -c -r < tmp > tmp.zst
2019-12-02 22:28:18 +00:00
2019-11-25 18:35:36 +00:00
println "\n===> file removal"
2020-03-26 22:04:15 +00:00
zstd -f --rm tmp
2017-05-06 02:15:24 +00:00
test ! -f tmp # tmp should no longer be present
2020-03-26 22:04:15 +00:00
zstd -f -d --rm tmp.zst
2017-05-06 02:15:24 +00:00
test ! -f tmp.zst # tmp.zst should no longer be present
2019-05-02 19:35:37 +00:00
println "test : should quietly not remove non-regular file"
println hello > tmp
2020-03-26 22:04:15 +00:00
zstd tmp -f -o " $DEVDEVICE " 2>tmplog > " $INTOVOID "
2017-12-13 20:04:46 +00:00
grep -v "Refusing to remove non-regular file" tmplog
rm -f tmplog
2020-03-26 22:04:15 +00:00
zstd tmp -f -o " $INTOVOID " 2>& 1 | grep -v "Refusing to remove non-regular file"
2019-05-02 19:35:37 +00:00
println "test : --rm on stdin"
2020-03-26 22:04:15 +00:00
println a | zstd --rm > $INTOVOID # --rm should remain silent
2016-06-09 20:59:51 +00:00
rm tmp
2020-03-26 22:04:15 +00:00
zstd -f tmp && die "tmp not present : should have failed"
2017-05-06 02:15:24 +00:00
test ! -f tmp.zst # tmp.zst should not be created
2019-05-02 19:35:37 +00:00
println "test : -d -f do not delete destination when source is not present"
2018-09-27 23:49:08 +00:00
touch tmp # create destination file
2020-03-26 22:04:15 +00:00
zstd -d -f tmp.zst && die "attempt to decompress a non existing file"
2018-10-02 00:16:34 +00:00
test -f tmp # destination file should still be present
2019-05-02 19:35:37 +00:00
println "test : -f do not delete destination when source is not present"
2018-10-02 00:16:34 +00:00
rm tmp # erase source file
touch tmp.zst # create destination file
2020-03-26 22:04:15 +00:00
zstd -f tmp && die "attempt to compress a non existing file"
2018-10-02 00:16:34 +00:00
test -f tmp.zst # destination file should still be present
2019-10-18 21:28:34 +00:00
rm -rf tmp* # may also erase tmp* directory from previous failed run
2018-09-27 23:49:08 +00:00
2019-10-28 22:15:26 +00:00
2019-11-25 18:35:36 +00:00
println "\n===> decompression only tests "
# the following test verifies that the decoder is compatible with RLE as first block
# older versions of zstd cli are not able to decode such corner case.
# As a consequence, the zstd cli do not generate them, to maintain compatibility with older versions.
dd bs = 1048576 count = 1 if = /dev/zero of = tmp
2020-03-26 22:04:15 +00:00
zstd -d -o tmp1 " $TESTDIR /golden-decompression/rle-first-block.zst "
2019-09-09 18:54:43 +00:00
$DIFF -s tmp1 tmp
rm tmp*
2016-05-23 17:46:47 +00:00
2019-10-28 22:15:26 +00:00
2019-11-26 19:20:26 +00:00
println "\n===> compress multiple files"
2019-05-02 19:35:37 +00:00
println hello > tmp1
println world > tmp2
2020-08-25 00:19:55 +00:00
zstd tmp1 tmp2 -o " $INTOVOID " -f
zstd tmp1 tmp2 -c | zstd -t
zstd tmp1 tmp2 -o tmp.zst
2017-12-13 02:32:50 +00:00
test ! -f tmp1.zst
test ! -f tmp2.zst
2020-03-26 22:04:15 +00:00
zstd tmp1 tmp2
zstd -t tmp1.zst tmp2.zst
zstd -dc tmp1.zst tmp2.zst
2020-08-25 00:19:55 +00:00
zstd tmp1.zst tmp2.zst -o " $INTOVOID " -f
zstd -d tmp1.zst tmp2.zst -o tmp
2018-01-03 22:02:44 +00:00
touch tmpexists
2020-08-25 00:19:55 +00:00
zstd tmp1 tmp2 -f -o tmpexists
2020-08-26 15:40:05 +00:00
zstd tmp1 tmp2 -q -o tmpexists && die "should have refused to overwrite"
2020-08-24 23:10:03 +00:00
println gooder > tmp_rm1
println boi > tmp_rm2
2020-08-25 00:19:55 +00:00
println worldly > tmp_rm3
echo 'y' | zstd tmp_rm1 tmp_rm2 -o tmp_rm3.zst --rm # tests the warning prompt for --rm with multiple inputs into once source
test ! -f tmp_rm1
test ! -f tmp_rm2
cp tmp_rm3.zst tmp_rm4.zst
echo 'Y' | zstd -d tmp_rm3.zst tmp_rm4.zst -o tmp_rm_out --rm
test ! -f tmp_rm3.zst
test ! -f tmp_rm4.zst
echo 'yes' | zstd tmp_rm_out tmp_rm3 -c --rm
test ! -f tmp_rm_out
test ! -f tmp_rm3
println gooder > tmpexists1
zstd tmpexists1 tmpexists -c --rm -f
2020-08-24 23:10:03 +00:00
2018-01-03 22:02:44 +00:00
# Bug: PR #972
if [ " $? " -eq 139 ] ; then
die "should not have segfaulted"
fi
2019-10-28 22:15:26 +00:00
println "\n===> multiple files and shell completion "
2020-03-26 22:04:15 +00:00
datagen -s1 > tmp1 2> $INTOVOID
datagen -s2 -g100K > tmp2 2> $INTOVOID
datagen -s3 -g1M > tmp3 2> $INTOVOID
2019-10-28 22:15:26 +00:00
println "compress tmp* : "
2020-03-26 22:04:15 +00:00
zstd -f tmp*
2019-10-28 22:15:26 +00:00
test -f tmp1.zst
test -f tmp2.zst
test -f tmp3.zst
rm tmp1 tmp2 tmp3
println "decompress tmp* : "
2020-03-26 22:04:15 +00:00
zstd -df ./*.zst
2019-10-28 22:15:26 +00:00
test -f tmp1
test -f tmp2
test -f tmp3
println "compress tmp* into stdout > tmpall : "
2020-08-25 00:19:55 +00:00
zstd -c tmp1 tmp2 tmp3 > tmpall
2019-10-28 22:15:26 +00:00
test -f tmpall # should check size of tmpall (should be tmp1.zst + tmp2.zst + tmp3.zst)
println "decompress tmpall* into stdout > tmpdec : "
cp tmpall tmpall2
2020-03-26 22:04:15 +00:00
zstd -dc tmpall* > tmpdec
2019-10-28 22:15:26 +00:00
test -f tmpdec # should check size of tmpdec (should be 2*(tmp1 + tmp2 + tmp3))
println "compress multiple files including a missing one (notHere) : "
2020-03-26 22:04:15 +00:00
zstd -f tmp1 notHere tmp2 && die "missing file not detected!"
2017-12-13 02:32:50 +00:00
rm tmp*
2019-10-28 22:15:26 +00:00
2019-11-26 22:18:09 +00:00
if [ " $isWindows " = false ] ; then
println "\n===> zstd fifo named pipe test "
echo "Hello World!" > tmp_original
mkfifo tmp_named_pipe
# note : fifo test doesn't work in combination with `dd` or `cat`
echo "Hello World!" > tmp_named_pipe &
2020-03-26 22:04:15 +00:00
zstd tmp_named_pipe -o tmp_compressed
zstd -d -o tmp_decompressed tmp_compressed
2019-11-26 22:18:09 +00:00
$DIFF -s tmp_original tmp_decompressed
rm -rf tmp*
fi
if [ -n " $DEVNULLRIGHTS " ] ; then
2019-11-25 18:35:36 +00:00
# these tests requires sudo rights, which is uncommon.
# they are only triggered if DEVNULLRIGHTS macro is defined.
println "\n===> checking /dev/null permissions are unaltered "
2020-03-26 22:04:15 +00:00
datagen > tmp
sudoZstd tmp -o $INTOVOID # sudo rights could modify /dev/null permissions
sudoZstd tmp -c > $INTOVOID
zstd tmp -f -o tmp.zst
sudoZstd -d tmp.zst -c > $INTOVOID
sudoZstd -d tmp.zst -o $INTOVOID
2019-11-25 18:35:36 +00:00
ls -las $INTOVOID | grep "rw-rw-rw-"
fi
2019-11-26 19:20:26 +00:00
2019-11-25 18:35:36 +00:00
println "\n===> compress multiple files into an output directory, --output-dir-flat"
2019-10-02 15:08:20 +00:00
println henlo > tmp1
mkdir tmpInputTestDir
mkdir tmpInputTestDir/we
mkdir tmpInputTestDir/we/must
mkdir tmpInputTestDir/we/must/go
mkdir tmpInputTestDir/we/must/go/deeper
println cool > tmpInputTestDir/we/must/go/deeper/tmp2
mkdir tmpOutDir
2020-03-26 22:04:15 +00:00
zstd tmp1 tmpInputTestDir/we/must/go/deeper/tmp2 --output-dir-flat tmpOutDir
2019-10-02 15:08:20 +00:00
test -f tmpOutDir/tmp1.zst
test -f tmpOutDir/tmp2.zst
println "test : decompress multiple files into an output directory, --output-dir-flat"
mkdir tmpOutDirDecomp
2020-03-26 22:04:15 +00:00
zstd tmpOutDir -r -d --output-dir-flat tmpOutDirDecomp
2019-10-02 15:08:20 +00:00
test -f tmpOutDirDecomp/tmp2
test -f tmpOutDirDecomp/tmp1
2019-10-21 21:33:50 +00:00
rm -f tmpOutDirDecomp/*
2020-03-26 22:04:15 +00:00
zstd tmpOutDir -r -d --output-dir-flat= tmpOutDirDecomp
2019-10-21 21:33:50 +00:00
test -f tmpOutDirDecomp/tmp2
test -f tmpOutDirDecomp/tmp1
2019-10-02 15:08:20 +00:00
rm -rf tmp*
2017-12-13 02:32:50 +00:00
2020-06-20 02:35:51 +00:00
if [ " $isWindows " = false ] ; then
println "\n===> compress multiple files into an output directory and mirror input folder, --output-dir-mirror"
println "test --output-dir-mirror" > tmp1
mkdir -p tmpInputTestDir/we/must/go/deeper
println cool > tmpInputTestDir/we/must/go/deeper/tmp2
zstd tmp1 -r tmpInputTestDir --output-dir-mirror tmpOutDir
test -f tmpOutDir/tmp1.zst
test -f tmpOutDir/tmpInputTestDir/we/must/go/deeper/tmp2.zst
println "test: compress input dir will be ignored if it has '..'"
zstd -r tmpInputTestDir/we/must/../must --output-dir-mirror non-exist && die "input cannot contain '..'"
test ! -d non-exist
println "test : decompress multiple files into an output directory, --output-dir-mirror"
zstd tmpOutDir -r -d --output-dir-mirror tmpOutDirDecomp
test -f tmpOutDirDecomp/tmpOutDir/tmp1
test -f tmpOutDirDecomp/tmpOutDir/tmpInputTestDir/we/must/go/deeper/tmp2
println "test: decompress input dir will be ignored if it has '..'"
zstd -r tmpOutDir/tmpInputTestDir/we/must/../must --output-dir-mirror non-exist && die "input cannot contain '..'"
test ! -d non-exist
rm -rf tmp*
fi
2019-10-25 23:36:59 +00:00
2019-10-28 20:54:36 +00:00
println "test : compress multiple files reading them from a file, --filelist=FILE"
2019-10-25 23:36:59 +00:00
println "Hello world!, file1" > tmp1
println "Hello world!, file2" > tmp2
println tmp1 > tmp_fileList
println tmp2 >> tmp_fileList
2020-03-26 22:04:15 +00:00
zstd -f --filelist= tmp_fileList
2019-10-25 23:36:59 +00:00
test -f tmp2.zst
test -f tmp1.zst
2019-10-28 22:15:26 +00:00
2020-07-17 20:31:15 +00:00
println "test : alternate syntax: --filelist FILE"
zstd -f --filelist tmp_fileList
test -f tmp2.zst
test -f tmp1.zst
2019-10-28 22:15:26 +00:00
println "test : reading file list from a symlink, --filelist=FILE"
2019-10-25 23:36:59 +00:00
rm -f *.zst
2019-10-28 22:15:26 +00:00
ln -s tmp_fileList tmp_symLink
2020-03-26 22:04:15 +00:00
zstd -f --filelist= tmp_symLink
2019-10-28 22:15:26 +00:00
test -f tmp2.zst
test -f tmp1.zst
2019-10-25 14:54:52 +00:00
2019-10-28 20:54:36 +00:00
println "test : compress multiple files reading them from multiple files, --filelist=FILE"
2019-10-28 22:15:26 +00:00
rm -f *.zst
2019-10-25 23:36:59 +00:00
println "Hello world!, file3" > tmp3
println "Hello world!, file4" > tmp4
println tmp3 > tmp_fileList2
println tmp4 >> tmp_fileList2
2020-03-26 22:04:15 +00:00
zstd -f --filelist= tmp_fileList --filelist= tmp_fileList2
2019-10-25 23:36:59 +00:00
test -f tmp1.zst
test -f tmp2.zst
test -f tmp3.zst
test -f tmp4.zst
2019-10-25 14:54:52 +00:00
2019-10-28 20:54:36 +00:00
println "test : decompress multiple files reading them from a file, --filelist=FILE"
2019-10-25 23:36:59 +00:00
rm -f tmp1 tmp2
println tmp1.zst > tmpZst
println tmp2.zst >> tmpZst
2020-03-26 22:04:15 +00:00
zstd -d -f --filelist= tmpZst
2019-10-25 23:36:59 +00:00
test -f tmp1
test -f tmp2
2019-10-25 14:54:52 +00:00
2019-10-28 20:54:36 +00:00
println "test : decompress multiple files reading them from multiple files, --filelist=FILE"
2019-10-25 23:36:59 +00:00
rm -f tmp1 tmp2 tmp3 tmp4
println tmp3.zst > tmpZst2
println tmp4.zst >> tmpZst2
2020-03-26 22:04:15 +00:00
zstd -d -f --filelist= tmpZst --filelist= tmpZst2
2019-10-25 23:36:59 +00:00
test -f tmp1
test -f tmp2
test -f tmp3
test -f tmp4
2019-10-25 14:54:52 +00:00
2019-10-28 20:54:36 +00:00
println "test : survive a list of files which is text garbage (--filelist=FILE)"
2020-03-26 22:04:15 +00:00
datagen > tmp_badList
zstd -f --filelist= tmp_badList && die "should have failed : list is text garbage"
2019-10-26 00:01:26 +00:00
2019-10-28 20:54:36 +00:00
println "test : survive a list of files which is binary garbage (--filelist=FILE)"
2020-03-26 22:04:15 +00:00
datagen -P0 -g1M > tmp_badList
zstd -qq -f --filelist= tmp_badList && die "should have failed : list is binary garbage" # let's avoid printing binary garbage on console
2019-10-26 00:01:26 +00:00
2019-10-28 23:05:42 +00:00
println "test : try to overflow internal list of files (--filelist=FILE)"
touch tmp1 tmp2 tmp3 tmp4 tmp5 tmp6
ls tmp* > tmpList
2020-03-26 22:04:15 +00:00
zstd -f tmp1 --filelist= tmpList --filelist= tmpList tmp2 tmp3 # can trigger an overflow of internal file list
2019-10-25 14:54:52 +00:00
rm -rf tmp*
2020-03-09 19:44:38 +00:00
println "\n===> --[no-]content-size tests"
2020-03-26 22:04:15 +00:00
datagen > tmp_contentsize
zstd -f tmp_contentsize
zstd -lv tmp_contentsize.zst | grep "Decompressed Size:"
zstd -f --no-content-size tmp_contentsize
zstd -lv tmp_contentsize.zst | grep "Decompressed Size:" && die
zstd -f --content-size tmp_contentsize
zstd -lv tmp_contentsize.zst | grep "Decompressed Size:"
zstd -f --content-size --no-content-size tmp_contentsize
zstd -lv tmp_contentsize.zst | grep "Decompressed Size:" && die
2020-03-09 19:44:38 +00:00
rm -rf tmp*
2020-01-30 22:12:03 +00:00
println "test : show-default-cparams regular"
2020-03-26 22:04:15 +00:00
datagen > tmp
zstd --show-default-cparams -f tmp
2020-01-30 22:12:03 +00:00
rm -rf tmp*
println "test : show-default-cparams recursive"
mkdir tmp_files
2020-03-26 22:04:15 +00:00
datagen -g15000 > tmp_files/tmp1
datagen -g129000 > tmp_files/tmp2
datagen -g257000 > tmp_files/tmp3
zstd --show-default-cparams -f -r tmp_files
2020-01-30 22:12:03 +00:00
rm -rf tmp*
2019-10-25 14:54:52 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> Advanced compression parameters "
2020-03-26 22:04:15 +00:00
println "Hello world!" | zstd --zstd= windowLog = 21, - -o tmp.zst && die "wrong parameters not detected!"
println "Hello world!" | zstd --zstd= windowLo = 21 - -o tmp.zst && die "wrong parameters not detected!"
println "Hello world!" | zstd --zstd= windowLog = 21,slog - -o tmp.zst && die "wrong parameters not detected!"
println "Hello world!" | zstd --zstd= strategy = 10 - -o tmp.zst && die "parameter out of bound not detected!" # > btultra2 : does not exist
2017-05-06 02:15:24 +00:00
test ! -f tmp.zst # tmp.zst should not be created
2016-12-14 15:50:00 +00:00
roundTripTest -g512K
2018-11-20 22:56:07 +00:00
roundTripTest -g512K " --zstd=mml=3,tlen=48,strat=6"
2016-12-14 16:10:38 +00:00
roundTripTest -g512K " --zstd=strat=6,wlog=23,clog=23,hlog=22,slog=6"
2018-11-20 22:56:07 +00:00
roundTripTest -g512K " --zstd=windowLog=23,chainLog=23,hashLog=22,searchLog=6,minMatch=3,targetLength=48,strategy=6"
2018-11-21 22:36:57 +00:00
roundTripTest -g512K " --single-thread --long --zstd=ldmHashLog=20,ldmMinMatch=64,ldmBucketSizeLog=1,ldmHashRateLog=7"
roundTripTest -g512K " --single-thread --long --zstd=lhlog=20,lmml=64,lblog=1,lhrlog=7"
2018-12-07 22:19:50 +00:00
roundTripTest -g64K "19 --zstd=strat=9" # btultra2
2016-12-14 15:50:00 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> Pass-Through mode "
2020-03-26 22:04:15 +00:00
println "Hello world 1!" | zstd -df
println "Hello world 2!" | zstd -dcf
2019-05-02 19:35:37 +00:00
println "Hello world 3!" > tmp1
2020-03-26 22:04:15 +00:00
zstd -dcf tmp1
2016-05-23 17:46:47 +00:00
2016-02-13 02:12:10 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> frame concatenation "
println "hello " > hello.tmp
println "world!" > world.tmp
2015-12-08 15:11:10 +00:00
cat hello.tmp world.tmp > helloworld.tmp
2020-03-26 22:04:15 +00:00
zstd -c hello.tmp > hello.zst
zstd -c world.tmp > world.zst
cat hello.zst world.zst > helloworld.zst
zstd -dc helloworld.zst > result.tmp
2015-12-08 15:11:10 +00:00
cat result.tmp
2017-01-22 23:54:14 +00:00
$DIFF helloworld.tmp result.tmp
2019-05-02 19:35:37 +00:00
println "frame concatenation without checksum"
2020-03-26 22:04:15 +00:00
zstd -c hello.tmp > hello.zst --no-check
zstd -c world.tmp > world.zst --no-check
cat hello.zst world.zst > helloworld.zstd
zstd -dc helloworld.zst > result.tmp
2017-01-22 23:54:14 +00:00
$DIFF helloworld.tmp result.tmp
2019-05-02 19:35:37 +00:00
println "testing zstdcat symlink"
2020-03-26 22:04:15 +00:00
ln -sf " $ZSTD_BIN " zstdcat
$EXE_PREFIX ./zstdcat helloworld.zst > result.tmp
2018-01-19 19:26:35 +00:00
$DIFF helloworld.tmp result.tmp
2020-03-26 22:04:15 +00:00
ln -s helloworld.zst helloworld.link.zst
$EXE_PREFIX ./zstdcat helloworld.link.zst > result.tmp
2019-04-29 22:47:47 +00:00
$DIFF helloworld.tmp result.tmp
2018-01-19 19:26:35 +00:00
rm zstdcat
rm result.tmp
2019-05-02 19:35:37 +00:00
println "testing zcat symlink"
2020-03-26 22:04:15 +00:00
ln -sf " $ZSTD_BIN " zcat
$EXE_PREFIX ./zcat helloworld.zst > result.tmp
2018-01-19 19:26:35 +00:00
$DIFF helloworld.tmp result.tmp
2020-03-26 22:04:15 +00:00
$EXE_PREFIX ./zcat helloworld.link.zst > result.tmp
2019-04-29 22:47:47 +00:00
$DIFF helloworld.tmp result.tmp
2018-01-19 19:26:35 +00:00
rm zcat
2015-12-08 15:36:37 +00:00
rm ./*.tmp ./*.zstd
2019-05-02 19:35:37 +00:00
println "frame concatenation tests completed"
2015-12-08 15:11:10 +00:00
2016-02-12 14:56:46 +00:00
2018-04-02 21:12:18 +00:00
if [ " $isWindows " = false ] && [ " $UNAME " != 'SunOS' ] && [ " $UNAME " != "OpenBSD" ] ; then
2019-05-02 19:35:37 +00:00
println "\n**** flush write error test **** "
2015-12-08 15:11:10 +00:00
2020-03-26 22:04:15 +00:00
println "println foo | zstd > /dev/full"
println foo | zstd > /dev/full && die "write error not detected!"
println "println foo | zstd | zstd -d > /dev/full"
println foo | zstd | zstd -d > /dev/full && die "write error not detected!"
2017-03-23 18:52:09 +00:00
2019-02-12 00:14:58 +00:00
fi
if [ " $isWindows " = false ] && [ " $UNAME " != 'SunOS' ] ; then
2017-05-06 02:15:24 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> symbolic link test "
2017-03-23 18:52:09 +00:00
2019-02-12 00:14:58 +00:00
rm -f hello.tmp world.tmp world2.tmp hello.tmp.zst world.tmp.zst
2019-05-02 19:35:37 +00:00
println "hello world" > hello.tmp
2017-03-23 18:52:09 +00:00
ln -s hello.tmp world.tmp
2019-02-12 00:14:58 +00:00
ln -s hello.tmp world2.tmp
2020-03-26 22:04:15 +00:00
zstd world.tmp hello.tmp || true
2017-05-06 02:15:24 +00:00
test -f hello.tmp.zst # regular file should have been compressed!
test ! -f world.tmp.zst # symbolic link should not have been compressed!
2020-03-26 22:04:15 +00:00
zstd world.tmp || true
2019-02-12 00:14:58 +00:00
test ! -f world.tmp.zst # symbolic link should not have been compressed!
2020-03-26 22:04:15 +00:00
zstd world.tmp world2.tmp || true
2019-02-12 00:14:58 +00:00
test ! -f world.tmp.zst # symbolic link should not have been compressed!
test ! -f world2.tmp.zst # symbolic link should not have been compressed!
2020-03-26 22:04:15 +00:00
zstd world.tmp hello.tmp -f
2017-05-06 02:15:24 +00:00
test -f world.tmp.zst # symbolic link should have been compressed with --force
2019-02-12 00:14:58 +00:00
rm -f hello.tmp world.tmp world2.tmp hello.tmp.zst world.tmp.zst
2017-03-23 18:52:09 +00:00
2016-05-25 08:50:28 +00:00
fi
2015-12-08 15:11:10 +00:00
2015-12-18 01:51:14 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> test sparse file support "
2016-05-23 15:48:57 +00:00
2020-03-26 22:04:15 +00:00
datagen -g5M -P100 > tmpSparse
zstd tmpSparse -c | zstd -dv -o tmpSparseRegen
2016-12-22 17:05:07 +00:00
$DIFF -s tmpSparse tmpSparseRegen
2020-03-26 22:04:15 +00:00
zstd tmpSparse -c | zstd -dv --sparse -c > tmpOutSparse
2016-12-22 17:05:07 +00:00
$DIFF -s tmpSparse tmpOutSparse
2020-03-26 22:04:15 +00:00
zstd tmpSparse -c | zstd -dv --no-sparse -c > tmpOutNoSparse
2016-12-22 17:05:07 +00:00
$DIFF -s tmpSparse tmpOutNoSparse
2017-05-06 02:15:24 +00:00
ls -ls tmpSparse* # look at file size and block size on disk
2020-03-26 22:04:15 +00:00
datagen -s1 -g1200007 -P100 | zstd | zstd -dv --sparse -c > tmpSparseOdd # Odd size file (to not finish on an exact nb of blocks)
datagen -s1 -g1200007 -P100 | $DIFF -s - tmpSparseOdd
2017-05-06 02:15:24 +00:00
ls -ls tmpSparseOdd # look at file size and block size on disk
2019-05-02 19:35:37 +00:00
println "\n Sparse Compatibility with Console :"
2020-03-26 22:04:15 +00:00
println "Hello World 1 !" | zstd | zstd -d -c
println "Hello World 2 !" | zstd | zstd -d | cat
2019-05-02 19:35:37 +00:00
println "\n Sparse Compatibility with Append :"
2020-03-26 22:04:15 +00:00
datagen -P100 -g1M > tmpSparse1M
2016-05-23 15:48:57 +00:00
cat tmpSparse1M tmpSparse1M > tmpSparse2M
2020-03-26 22:04:15 +00:00
zstd -v -f tmpSparse1M -o tmpSparseCompressed
zstd -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
zstd -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
2017-05-06 02:15:24 +00:00
ls -ls tmpSparse* # look at file size and block size on disk
2016-12-22 17:05:07 +00:00
$DIFF tmpSparse2M tmpSparseRegenerated
2016-05-29 21:09:51 +00:00
rm tmpSparse*
2016-05-23 15:48:57 +00:00
2019-08-21 17:27:54 +00:00
println "\n===> stream-size mode"
2020-03-26 22:04:15 +00:00
datagen -g11000 > tmp
2019-08-21 17:27:54 +00:00
println "test : basic file compression vs sized streaming compression"
2020-03-26 22:04:15 +00:00
file_size = $( zstd -14 -f tmp -o tmp.zst && wc -c < tmp.zst)
stream_size = $( cat tmp | zstd -14 --stream-size= 11000 | wc -c)
2019-08-21 17:27:54 +00:00
if [ " $stream_size " -gt " $file_size " ] ; then
die "hinted compression larger than expected"
fi
println "test : sized streaming compression and decompression"
2020-07-17 20:31:15 +00:00
cat tmp | zstd -14 -f tmp -o tmp.zst --stream-size= 11000
2020-03-26 22:04:15 +00:00
zstd -df tmp.zst -o tmp_decompress
2019-08-21 17:27:54 +00:00
cmp tmp tmp_decompress || die "difference between original and decompressed file"
println "test : incorrect stream size"
2020-03-26 22:04:15 +00:00
cat tmp | zstd -14 -f -o tmp.zst --stream-size= 11001 && die "should fail with incorrect stream size"
2019-08-21 17:27:54 +00:00
2019-11-26 20:24:19 +00:00
println "\n===> zstd zero weight dict test "
rm -f tmp*
cp " $TESTDIR /dict-files/zero-weight-dict " tmp_input
2020-03-26 22:04:15 +00:00
zstd -D " $TESTDIR /dict-files/zero-weight-dict " tmp_input
zstd -D " $TESTDIR /dict-files/zero-weight-dict " -d tmp_input.zst -o tmp_decomp
2019-11-26 20:24:19 +00:00
$DIFF tmp_decomp tmp_input
rm -rf tmp*
println "\n===> zstd (valid) zero weight dict test "
rm -f tmp*
# 0 has a non-zero weight in the dictionary
echo "0000000000000000000000000" > tmp_input
2020-03-26 22:04:15 +00:00
zstd -D " $TESTDIR /dict-files/zero-weight-dict " tmp_input
zstd -D " $TESTDIR /dict-files/zero-weight-dict " -d tmp_input.zst -o tmp_decomp
2019-11-26 20:24:19 +00:00
$DIFF tmp_decomp tmp_input
rm -rf tmp*
2019-08-21 17:27:54 +00:00
2019-08-19 15:52:08 +00:00
println "\n===> size-hint mode"
2020-03-26 22:04:15 +00:00
datagen -g11000 > tmp
datagen -g11000 > tmp2
datagen > tmpDict
2019-08-19 23:48:35 +00:00
println "test : basic file compression vs hinted streaming compression"
2020-03-26 22:04:15 +00:00
file_size = $( zstd -14 -f tmp -o tmp.zst && wc -c < tmp.zst)
stream_size = $( cat tmp | zstd -14 --size-hint= 11000 | wc -c)
2019-08-19 23:48:35 +00:00
if [ " $stream_size " -ge " $file_size " ] ; then
die "hinted compression larger than expected"
2019-08-19 15:52:08 +00:00
fi
println "test : hinted streaming compression and decompression"
2020-03-26 22:04:15 +00:00
cat tmp | zstd -14 -f -o tmp.zst --size-hint= 11000
zstd -df tmp.zst -o tmp_decompress
2019-08-19 15:52:08 +00:00
cmp tmp tmp_decompress || die "difference between original and decompressed file"
2019-08-19 23:48:35 +00:00
println "test : hinted streaming compression with dictionary"
2020-03-26 22:04:15 +00:00
cat tmp | zstd -14 -f -D tmpDict --size-hint= 11000 | zstd -t -D tmpDict
2019-08-19 23:48:35 +00:00
println "test : multiple file compression with hints and dictionary"
2020-03-26 22:04:15 +00:00
zstd -14 -f -D tmpDict --size-hint= 11000 tmp tmp2
zstd -14 -f -o tmp1_.zst -D tmpDict --size-hint= 11000 tmp
zstd -14 -f -o tmp2_.zst -D tmpDict --size-hint= 11000 tmp2
2019-08-19 23:48:35 +00:00
cmp tmp.zst tmp1_.zst || die "first file's output differs"
cmp tmp2.zst tmp2_.zst || die "second file's output differs"
2019-08-19 15:52:08 +00:00
println "test : incorrect hinted stream sizes"
2020-03-26 22:04:15 +00:00
cat tmp | zstd -14 -f --size-hint= 11050 | zstd -t # slightly too high
cat tmp | zstd -14 -f --size-hint= 10950 | zstd -t # slightly too low
cat tmp | zstd -14 -f --size-hint= 22000 | zstd -t # considerably too high
cat tmp | zstd -14 -f --size-hint= 5500 | zstd -t # considerably too low
2019-08-19 15:52:08 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> dictionary tests "
2015-12-13 12:35:21 +00:00
2019-05-02 19:35:37 +00:00
println "- test with raw dict (content only) "
2020-03-26 22:04:15 +00:00
datagen > tmpDict
datagen -g1M | $MD5SUM > tmp1
datagen -g1M | zstd -D tmpDict | zstd -D tmpDict -dvq | $MD5SUM > tmp2
2016-12-22 17:05:07 +00:00
$DIFF -q tmp1 tmp2
2019-05-02 19:35:37 +00:00
println "- Create first dictionary "
TESTFILE = " $PRGDIR " /zstdcli.c
2020-03-26 22:04:15 +00:00
zstd --train " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpDict
2019-05-02 19:35:37 +00:00
cp " $TESTFILE " tmp
println "- Test dictionary compression with tmpDict as an input file and dictionary"
2020-03-26 22:04:15 +00:00
zstd -f tmpDict -D tmpDict && die "compression error not detected!"
2019-05-02 19:35:37 +00:00
println "- Dictionary compression roundtrip"
2020-03-26 22:04:15 +00:00
zstd -f tmp -D tmpDict
zstd -d tmp.zst -D tmpDict -fo result
2019-05-02 19:35:37 +00:00
$DIFF " $TESTFILE " result
println "- Dictionary compression with btlazy2 strategy"
2020-03-26 22:04:15 +00:00
zstd -f tmp -D tmpDict --zstd= strategy = 6
zstd -d tmp.zst -D tmpDict -fo result
2019-05-02 19:35:37 +00:00
$DIFF " $TESTFILE " result
2017-12-13 19:48:30 +00:00
if [ -n " $hasMT " ]
then
2019-05-02 19:35:37 +00:00
println "- Test dictionary compression with multithreading "
2020-03-26 22:04:15 +00:00
datagen -g5M | zstd -T2 -D tmpDict | zstd -t -D tmpDict # fails with v1.3.2
2017-12-13 19:48:30 +00:00
fi
2019-05-02 19:35:37 +00:00
println "- Create second (different) dictionary "
2020-03-26 22:04:15 +00:00
zstd --train " $TESTDIR " /*.c " $PRGDIR " /*.c " $PRGDIR " /*.h -o tmpDictC
zstd -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
2019-05-02 19:35:37 +00:00
println "- Create dictionary with short dictID"
2020-03-26 22:04:15 +00:00
zstd --train " $TESTDIR " /*.c " $PRGDIR " /*.c --dictID= 1 -o tmpDict1
2016-05-30 19:18:52 +00:00
cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
2019-05-02 19:35:37 +00:00
println "- Create dictionary with wrong dictID parameter order (must fail)"
2020-03-26 22:04:15 +00:00
zstd --train " $TESTDIR " /*.c " $PRGDIR " /*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
2019-05-02 19:35:37 +00:00
println "- Create dictionary with size limit"
2020-03-26 22:04:15 +00:00
zstd --train " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpDict2 --maxdict= 4K -v
2019-05-02 19:35:37 +00:00
println "- Create dictionary with small size limit"
2020-03-26 22:04:15 +00:00
zstd --train " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpDict3 --maxdict= 1K -v
2019-05-02 19:35:37 +00:00
println "- Create dictionary with wrong parameter order (must fail)"
2020-03-26 22:04:15 +00:00
zstd --train " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpDict3 --maxdict -v 4K && die "wrong order : --maxdict must be followed by argument "
2019-05-02 19:35:37 +00:00
println "- Compress without dictID"
2020-03-26 22:04:15 +00:00
zstd -f tmp -D tmpDict1 --no-dictID
zstd -d tmp.zst -D tmpDict -fo result
2019-05-02 19:35:37 +00:00
$DIFF " $TESTFILE " result
println "- Compress multiple files with dictionary"
2016-06-15 17:02:11 +00:00
rm -rf dirTestDict
mkdir dirTestDict
2019-05-02 19:35:37 +00:00
cp " $TESTDIR " /*.c dirTestDict
cp " $PRGDIR " /*.c dirTestDict
cp " $PRGDIR " /*.h dirTestDict
2016-08-25 17:09:21 +00:00
$MD5SUM dirTestDict/* > tmph1
2020-03-26 22:04:15 +00:00
zstd -f --rm dirTestDict/* -D tmpDictC
zstd -d --rm dirTestDict/*.zst -D tmpDictC # note : use internal checksum by default
2016-12-12 18:22:47 +00:00
case " $UNAME " in
2019-05-02 19:35:37 +00:00
Darwin) println "md5sum -c not supported on OS-X : test skipped" ; ; # not compatible with OS-X's md5
2016-12-06 20:02:56 +00:00
*) $MD5SUM -c tmph1 ; ;
esac
2016-06-15 17:02:11 +00:00
rm -rf dirTestDict
2019-05-02 19:35:37 +00:00
println "- dictionary builder on bogus input"
println "Hello World" > tmp
2020-03-26 22:04:15 +00:00
zstd --train-legacy -q tmp && die "Dictionary training should fail : not enough input source"
datagen -P0 -g10M > tmp
zstd --train-legacy -q tmp && die "Dictionary training should fail : source is pure noise"
2019-05-02 19:35:37 +00:00
println "- Test -o before --train"
2018-07-10 01:24:07 +00:00
rm -f tmpDict dictionary
2020-03-26 22:04:15 +00:00
zstd -o tmpDict --train " $TESTDIR " /*.c " $PRGDIR " /*.c
2018-07-10 01:24:07 +00:00
test -f tmpDict
2020-03-26 22:04:15 +00:00
zstd --train " $TESTDIR " /*.c " $PRGDIR " /*.c
2018-07-10 01:24:07 +00:00
test -f dictionary
2019-08-27 01:32:08 +00:00
println "- Test dictionary training fails"
echo "000000000000000000000000000000000" > tmpz
2020-03-26 22:04:15 +00:00
zstd --train tmpz tmpz tmpz tmpz tmpz tmpz tmpz tmpz tmpz && die "Dictionary training should fail : source is all zeros"
2019-08-27 01:32:08 +00:00
if [ -n " $hasMT " ]
then
2020-03-26 22:04:15 +00:00
zstd --train -T0 tmpz tmpz tmpz tmpz tmpz tmpz tmpz tmpz tmpz && die "Dictionary training should fail : source is all zeros"
2019-08-27 01:32:08 +00:00
println "- Create dictionary with multithreading enabled"
2020-03-26 22:04:15 +00:00
zstd --train -T0 " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpDict
2019-08-27 01:32:08 +00:00
fi
2018-07-10 01:24:07 +00:00
rm tmp* dictionary
2016-03-26 19:52:14 +00:00
2015-12-13 12:35:21 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> fastCover dictionary builder : advanced options "
TESTFILE = " $PRGDIR " /zstdcli.c
2020-03-26 22:04:15 +00:00
datagen > tmpDict
2019-05-02 19:35:37 +00:00
println "- Create first dictionary"
2020-03-26 22:04:15 +00:00
zstd --train-fastcover= k = 46,d= 8,f= 15,split= 80 " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpDict
2019-05-02 19:35:37 +00:00
cp " $TESTFILE " tmp
2020-03-26 22:04:15 +00:00
zstd -f tmp -D tmpDict
zstd -d tmp.zst -D tmpDict -fo result
2019-05-02 19:35:37 +00:00
$DIFF " $TESTFILE " result
println "- Create second (different) dictionary"
2020-03-26 22:04:15 +00:00
zstd --train-fastcover= k = 56,d= 8 " $TESTDIR " /*.c " $PRGDIR " /*.c " $PRGDIR " /*.h -o tmpDictC
zstd -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
zstd --train-fastcover= k = 56,d= 8 && die "Create dictionary without input file"
2019-05-02 19:35:37 +00:00
println "- Create dictionary with short dictID"
2020-03-26 22:04:15 +00:00
zstd --train-fastcover= k = 46,d= 8,f= 15,split= 80 " $TESTDIR " /*.c " $PRGDIR " /*.c --dictID= 1 -o tmpDict1
2018-08-23 19:06:20 +00:00
cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
2019-06-27 23:26:57 +00:00
println "- Create dictionaries with shrink-dict flag enabled"
2020-03-26 22:04:15 +00:00
zstd --train-fastcover= steps = 1,shrink " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpShrinkDict
zstd --train-fastcover= steps = 1,shrink= 1 " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpShrinkDict1
zstd --train-fastcover= steps = 1,shrink= 5 " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpShrinkDict2
2019-05-02 19:35:37 +00:00
println "- Create dictionary with size limit"
2020-03-26 22:04:15 +00:00
zstd --train-fastcover= steps = 1 " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpDict2 --maxdict= 4K
2019-05-02 19:35:37 +00:00
println "- Create dictionary using all samples for both training and testing"
2020-03-26 22:04:15 +00:00
zstd --train-fastcover= k = 56,d= 8,split= 100 -r " $TESTDIR " /*.c " $PRGDIR " /*.c
2019-05-02 19:35:37 +00:00
println "- Create dictionary using f=16"
2020-03-26 22:04:15 +00:00
zstd --train-fastcover= k = 56,d= 8,f= 16 -r " $TESTDIR " /*.c " $PRGDIR " /*.c
zstd --train-fastcover= k = 56,d= 8,accel= 15 -r " $TESTDIR " /*.c " $PRGDIR " /*.c && die "Created dictionary using accel=15"
2019-05-02 19:35:37 +00:00
println "- Create dictionary using accel=2"
2020-03-26 22:04:15 +00:00
zstd --train-fastcover= k = 56,d= 8,accel= 2 -r " $TESTDIR " /*.c " $PRGDIR " /*.c
2019-05-02 19:35:37 +00:00
println "- Create dictionary using accel=10"
2020-03-26 22:04:15 +00:00
zstd --train-fastcover= k = 56,d= 8,accel= 10 -r " $TESTDIR " /*.c " $PRGDIR " /*.c
2019-05-02 19:35:37 +00:00
println "- Create dictionary with multithreading"
2020-03-26 22:04:15 +00:00
zstd --train-fastcover -T4 -r " $TESTDIR " /*.c " $PRGDIR " /*.c
2019-05-02 19:35:37 +00:00
println "- Test -o before --train-fastcover"
2018-08-23 19:06:20 +00:00
rm -f tmpDict dictionary
2020-03-26 22:04:15 +00:00
zstd -o tmpDict --train-fastcover= k = 56,d= 8 " $TESTDIR " /*.c " $PRGDIR " /*.c
2018-08-23 19:06:20 +00:00
test -f tmpDict
2020-03-26 22:04:15 +00:00
zstd --train-fastcover= k = 56,d= 8 " $TESTDIR " /*.c " $PRGDIR " /*.c
2018-08-23 19:06:20 +00:00
test -f dictionary
rm tmp* dictionary
2019-05-02 19:35:37 +00:00
println "\n===> legacy dictionary builder "
2017-05-02 06:40:20 +00:00
2019-05-02 19:35:37 +00:00
TESTFILE = " $PRGDIR " /zstdcli.c
2020-03-26 22:04:15 +00:00
datagen > tmpDict
2019-05-02 19:35:37 +00:00
println "- Create first dictionary"
2020-03-26 22:04:15 +00:00
zstd --train-legacy= selectivity = 8 " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpDict
2019-05-02 19:35:37 +00:00
cp " $TESTFILE " tmp
2020-03-26 22:04:15 +00:00
zstd -f tmp -D tmpDict
zstd -d tmp.zst -D tmpDict -fo result
2019-05-02 19:35:37 +00:00
$DIFF " $TESTFILE " result
2020-03-26 22:04:15 +00:00
zstd --train-legacy= s = 8 && die "Create dictionary without input files (should error)"
2019-05-02 19:35:37 +00:00
println "- Create second (different) dictionary"
2020-03-26 22:04:15 +00:00
zstd --train-legacy= s = 5 " $TESTDIR " /*.c " $PRGDIR " /*.c " $PRGDIR " /*.h -o tmpDictC
zstd -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
2019-05-02 19:35:37 +00:00
println "- Create dictionary with short dictID"
2020-03-26 22:04:15 +00:00
zstd --train-legacy -s5 " $TESTDIR " /*.c " $PRGDIR " /*.c --dictID= 1 -o tmpDict1
2017-05-02 06:40:20 +00:00
cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
2019-05-02 19:35:37 +00:00
println "- Create dictionary with size limit"
2020-03-26 22:04:15 +00:00
zstd --train-legacy -s9 " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpDict2 --maxdict= 4K
2019-05-02 19:35:37 +00:00
println "- Test -o before --train-legacy"
2018-07-10 01:24:07 +00:00
rm -f tmpDict dictionary
2020-03-26 22:04:15 +00:00
zstd -o tmpDict --train-legacy " $TESTDIR " /*.c " $PRGDIR " /*.c
2018-07-10 01:24:07 +00:00
test -f tmpDict
2020-03-26 22:04:15 +00:00
zstd --train-legacy " $TESTDIR " /*.c " $PRGDIR " /*.c
2018-07-10 01:24:07 +00:00
test -f dictionary
rm tmp* dictionary
2017-01-01 06:59:51 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> integrity tests "
2016-05-23 17:46:47 +00:00
2019-05-02 19:35:37 +00:00
println "test one file (tmp1.zst) "
2020-03-26 22:04:15 +00:00
datagen > tmp1
zstd tmp1
zstd -t tmp1.zst
zstd --test tmp1.zst
2019-05-02 19:35:37 +00:00
println "test multiple files (*.zst) "
2020-03-26 22:04:15 +00:00
zstd -t ./*.zst
2019-05-02 19:35:37 +00:00
println "test bad files (*) "
2020-03-26 22:04:15 +00:00
zstd -t ./* && die "bad files not detected !"
zstd -t tmp1 && die "bad file not detected !"
2016-07-25 23:26:56 +00:00
cp tmp1 tmp2.zst
2020-03-26 22:04:15 +00:00
zstd -t tmp2.zst && die "bad file not detected !"
datagen -g0 > tmp3
zstd -t tmp3 && die "bad file not detected !" # detects 0-sized files as bad
2019-05-02 19:35:37 +00:00
println "test --rm and --test combined "
2020-03-26 22:04:15 +00:00
zstd -t --rm tmp1.zst
2017-05-06 02:15:24 +00:00
test -f tmp1.zst # check file is still present
split -b16384 tmp1.zst tmpSplit.
2020-03-26 22:04:15 +00:00
zstd -t tmpSplit.* && die "bad file not detected !"
datagen | zstd -c | zstd -t
2015-12-17 19:30:14 +00:00
2016-05-23 17:46:47 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> golden files tests "
2017-07-28 18:54:28 +00:00
2020-06-13 00:48:39 +00:00
zstd -t -r " $TESTDIR /golden-decompression "
2020-08-25 00:19:55 +00:00
zstd -c -r " $TESTDIR /golden-compression " | zstd -t
2020-06-13 00:48:39 +00:00
zstd -D " $TESTDIR /golden-dictionaries/http-dict-missing-symbols " " $TESTDIR /golden-compression/http " -c | zstd -D " $TESTDIR /golden-dictionaries/http-dict-missing-symbols " -t
2017-07-28 18:54:28 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> benchmark mode tests "
2016-10-28 21:43:24 +00:00
2019-05-02 19:35:37 +00:00
println "bench one file"
2020-03-26 22:04:15 +00:00
datagen > tmp1
zstd -bi0 tmp1
2019-05-02 19:35:37 +00:00
println "bench multiple levels"
2020-03-26 22:04:15 +00:00
zstd -i0b0e3 tmp1
2019-05-02 19:35:37 +00:00
println "bench negative level"
2020-03-26 22:04:15 +00:00
zstd -bi0 --fast tmp1
2019-05-02 19:35:37 +00:00
println "with recursive and quiet modes"
2020-03-26 22:04:15 +00:00
zstd -rqi0b1e2 tmp1
2019-05-02 19:35:37 +00:00
println "benchmark decompression only"
2020-03-26 22:04:15 +00:00
zstd -f tmp1
zstd -b -d -i0 tmp1.zst
2017-03-02 00:49:20 +00:00
2019-10-28 22:15:26 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> zstd compatibility tests "
2018-06-01 16:52:25 +00:00
2020-03-26 22:04:15 +00:00
datagen > tmp
2018-06-01 17:54:51 +00:00
rm -f tmp.zst
2020-03-26 22:04:15 +00:00
zstd --format= zstd -f tmp
2018-06-01 17:54:51 +00:00
test -f tmp.zst
2017-03-02 00:49:20 +00:00
2019-10-28 22:15:26 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> gzip compatibility tests "
2017-03-02 00:49:20 +00:00
GZIPMODE = 1
2020-03-26 22:04:15 +00:00
zstd --format= gzip -V || GZIPMODE = 0
2017-03-02 00:49:20 +00:00
if [ $GZIPMODE -eq 1 ] ; then
2019-05-02 19:35:37 +00:00
println "gzip support detected"
2017-03-02 00:49:20 +00:00
GZIPEXE = 1
2017-03-02 01:02:49 +00:00
gzip -V || GZIPEXE = 0
2017-03-02 00:49:20 +00:00
if [ $GZIPEXE -eq 1 ] ; then
2020-03-26 22:04:15 +00:00
datagen > tmp
zstd --format= gzip -f tmp
2017-03-02 00:49:20 +00:00
gzip -t -v tmp.gz
gzip -f tmp
2020-03-26 22:04:15 +00:00
zstd -d -f -v tmp.gz
2017-03-14 01:11:07 +00:00
rm tmp*
2017-03-02 00:49:20 +00:00
else
2019-05-02 19:35:37 +00:00
println "gzip binary not detected"
2017-03-02 00:49:20 +00:00
fi
else
2019-05-02 19:35:37 +00:00
println "gzip mode not supported"
2017-03-02 00:49:20 +00:00
fi
2016-10-28 21:43:24 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> gzip frame tests "
2017-03-14 01:11:07 +00:00
if [ $GZIPMODE -eq 1 ] ; then
2020-03-26 22:04:15 +00:00
datagen > tmp
zstd -f --format= gzip tmp
zstd -f tmp
cat tmp.gz tmp.zst tmp.gz tmp.zst | zstd -d -f -o tmp
truncateLastByte tmp.gz | zstd -t > $INTOVOID && die "incomplete frame not detected !"
2017-03-14 01:11:07 +00:00
rm tmp*
else
2019-05-02 19:35:37 +00:00
println "gzip mode not supported"
2017-03-14 01:11:07 +00:00
fi
2018-06-01 17:54:51 +00:00
if [ $GZIPMODE -eq 1 ] ; then
2020-03-26 22:04:15 +00:00
datagen > tmp
2018-06-01 17:54:51 +00:00
rm -f tmp.zst
2020-03-26 22:04:15 +00:00
zstd --format= gzip --format= zstd -f tmp
2018-06-01 17:54:51 +00:00
test -f tmp.zst
fi
2017-03-14 01:11:07 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> xz compatibility tests "
2017-03-14 01:11:07 +00:00
LZMAMODE = 1
2020-03-26 22:04:15 +00:00
zstd --format= xz -V || LZMAMODE = 0
2017-03-14 01:11:07 +00:00
if [ $LZMAMODE -eq 1 ] ; then
2019-05-02 19:35:37 +00:00
println "xz support detected"
2017-03-14 01:11:07 +00:00
XZEXE = 1
2018-06-30 11:22:14 +00:00
xz -Q -V && lzma -Q -V || XZEXE = 0
2017-03-14 01:11:07 +00:00
if [ $XZEXE -eq 1 ] ; then
2019-05-02 19:35:37 +00:00
println "Testing zstd xz and lzma support"
2020-03-26 22:04:15 +00:00
datagen > tmp
zstd --format= lzma -f tmp
zstd --format= xz -f tmp
2018-06-30 11:22:14 +00:00
xz -Q -t -v tmp.xz
xz -Q -t -v tmp.lzma
xz -Q -f -k tmp
lzma -Q -f -k --lzma1 tmp
2020-03-26 22:04:15 +00:00
zstd -d -f -v tmp.xz
zstd -d -f -v tmp.lzma
2017-03-14 01:11:07 +00:00
rm tmp*
2019-05-02 19:35:37 +00:00
println "Creating symlinks"
2020-03-26 22:04:15 +00:00
ln -s " $ZSTD_BIN " ./xz
ln -s " $ZSTD_BIN " ./unxz
ln -s " $ZSTD_BIN " ./lzma
ln -s " $ZSTD_BIN " ./unlzma
2019-05-02 19:35:37 +00:00
println "Testing xz and lzma symlinks"
2020-03-26 22:04:15 +00:00
datagen > tmp
2017-06-26 18:24:36 +00:00
./xz tmp
2018-06-30 11:22:14 +00:00
xz -Q -d tmp.xz
2017-06-26 18:24:36 +00:00
./lzma tmp
2018-06-30 11:22:14 +00:00
lzma -Q -d tmp.lzma
2019-05-02 19:35:37 +00:00
println "Testing unxz and unlzma symlinks"
2018-06-30 11:22:14 +00:00
xz -Q tmp
2017-06-26 18:24:36 +00:00
./xz -d tmp.xz
2018-06-30 11:22:14 +00:00
lzma -Q tmp
2017-06-26 18:24:36 +00:00
./lzma -d tmp.lzma
rm xz unxz lzma unlzma
rm tmp*
2017-03-14 01:11:07 +00:00
else
2019-05-02 19:35:37 +00:00
println "xz binary not detected"
2017-03-14 01:11:07 +00:00
fi
else
2019-05-02 19:35:37 +00:00
println "xz mode not supported"
2017-03-14 01:11:07 +00:00
fi
2019-05-02 19:35:37 +00:00
println "\n===> xz frame tests "
2017-03-14 01:11:07 +00:00
if [ $LZMAMODE -eq 1 ] ; then
2020-03-26 22:04:15 +00:00
datagen > tmp
zstd -f --format= xz tmp
zstd -f --format= lzma tmp
zstd -f tmp
cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | zstd -d -f -o tmp
truncateLastByte tmp.xz | zstd -t > $INTOVOID && die "incomplete frame not detected !"
truncateLastByte tmp.lzma | zstd -t > $INTOVOID && die "incomplete frame not detected !"
2017-03-14 01:11:07 +00:00
rm tmp*
else
2019-05-02 19:35:37 +00:00
println "xz mode not supported"
2017-03-14 01:11:07 +00:00
fi
2019-05-02 19:35:37 +00:00
println "\n===> lz4 compatibility tests "
2017-04-24 23:48:25 +00:00
LZ4MODE = 1
2020-03-26 22:04:15 +00:00
zstd --format= lz4 -V || LZ4MODE = 0
2017-04-24 23:48:25 +00:00
if [ $LZ4MODE -eq 1 ] ; then
2019-05-02 19:35:37 +00:00
println "lz4 support detected"
2017-04-24 23:48:25 +00:00
LZ4EXE = 1
lz4 -V || LZ4EXE = 0
if [ $LZ4EXE -eq 1 ] ; then
2020-03-26 22:04:15 +00:00
datagen > tmp
zstd --format= lz4 -f tmp
2017-04-24 23:48:25 +00:00
lz4 -t -v tmp.lz4
lz4 -f tmp
2020-03-26 22:04:15 +00:00
zstd -d -f -v tmp.lz4
2017-04-24 23:48:25 +00:00
rm tmp*
else
2019-05-02 19:35:37 +00:00
println "lz4 binary not detected"
2017-04-24 23:48:25 +00:00
fi
else
2019-05-02 19:35:37 +00:00
println "lz4 mode not supported"
2017-04-24 23:48:25 +00:00
fi
if [ $LZ4MODE -eq 1 ] ; then
2019-10-28 22:03:32 +00:00
println "\n===> lz4 frame tests "
2020-03-26 22:04:15 +00:00
datagen > tmp
zstd -f --format= lz4 tmp
zstd -f tmp
cat tmp.lz4 tmp.zst tmp.lz4 tmp.zst | zstd -d -f -o tmp
truncateLastByte tmp.lz4 | zstd -t > $INTOVOID && die "incomplete frame not detected !"
2017-04-24 23:48:25 +00:00
rm tmp*
else
2019-10-28 22:03:32 +00:00
println "\nlz4 mode not supported"
2017-04-24 23:48:25 +00:00
fi
2017-03-14 01:11:07 +00:00
2019-10-28 22:03:32 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> suffix list test"
2018-06-01 17:43:06 +00:00
2020-03-26 22:04:15 +00:00
! zstd -d tmp.abc 2> tmplg
2018-06-01 17:43:06 +00:00
2018-06-27 21:27:27 +00:00
if [ $GZIPMODE -ne 1 ] ; then
2018-06-01 17:43:06 +00:00
grep ".gz" tmplg > $INTOVOID && die "Unsupported suffix listed"
fi
2018-06-27 21:27:27 +00:00
if [ $LZMAMODE -ne 1 ] ; then
2018-06-01 17:43:06 +00:00
grep ".lzma" tmplg > $INTOVOID && die "Unsupported suffix listed"
grep ".xz" tmplg > $INTOVOID && die "Unsupported suffix listed"
fi
if [ $LZ4MODE -ne 1 ] ; then
grep ".lz4" tmplg > $INTOVOID && die "Unsupported suffix listed"
fi
2019-10-28 22:03:32 +00:00
2019-10-25 00:19:10 +00:00
println "\n===> tar extension tests "
rm -f tmp tmp.tar tmp.tzst tmp.tgz tmp.txz tmp.tlz4
2020-03-26 22:04:15 +00:00
datagen > tmp
2019-10-25 00:19:10 +00:00
tar cf tmp.tar tmp
2020-03-26 22:04:15 +00:00
zstd tmp.tar -o tmp.tzst
2019-10-25 00:19:10 +00:00
rm tmp.tar
2020-03-26 22:04:15 +00:00
zstd -d tmp.tzst
2019-10-25 00:19:10 +00:00
[ -e tmp.tar ] || die ".tzst failed to decompress to .tar!"
rm -f tmp.tar tmp.tzst
if [ $GZIPMODE -eq 1 ] ; then
tar czf tmp.tgz tmp
2020-03-26 22:04:15 +00:00
zstd -d tmp.tgz
2019-10-25 00:19:10 +00:00
[ -e tmp.tar ] || die ".tgz failed to decompress to .tar!"
rm -f tmp.tar tmp.tgz
fi
if [ $LZMAMODE -eq 1 ] ; then
2020-03-26 22:04:15 +00:00
tar c tmp | zstd --format= xz > tmp.txz
zstd -d tmp.txz
2019-10-25 00:19:10 +00:00
[ -e tmp.tar ] || die ".txz failed to decompress to .tar!"
rm -f tmp.tar tmp.txz
fi
if [ $LZ4MODE -eq 1 ] ; then
2020-03-26 22:04:15 +00:00
tar c tmp | zstd --format= lz4 > tmp.tlz4
zstd -d tmp.tlz4
2019-10-25 00:19:10 +00:00
[ -e tmp.tar ] || die ".tlz4 failed to decompress to .tar!"
rm -f tmp.tar tmp.tlz4
fi
touch tmp.t tmp.tz tmp.tzs
2020-03-26 22:04:15 +00:00
! zstd -d tmp.t
! zstd -d tmp.tz
! zstd -d tmp.tzs
2019-10-25 00:19:10 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> zstd round-trip tests "
2015-12-08 15:36:37 +00:00
roundTripTest
2016-03-30 17:48:05 +00:00
roundTripTest -g15K # TableID==3
roundTripTest -g127K # TableID==2
roundTripTest -g255K # TableID==1
2017-03-02 00:49:20 +00:00
roundTripTest -g522K # TableID==0
roundTripTest -g519K 6 # greedy, hash chain
roundTripTest -g517K 16 # btlazy2
roundTripTest -g516K 19 # btopt
2016-02-15 19:37:23 +00:00
2017-04-12 00:15:13 +00:00
fileRoundTripTest -g500K
2019-05-02 19:35:37 +00:00
println "\n===> zstd long distance matching round-trip tests "
2018-02-28 04:09:18 +00:00
roundTripTest -g0 "2 --single-thread --long"
roundTripTest -g1000K "1 --single-thread --long"
roundTripTest -g517K "6 --single-thread --long"
roundTripTest -g516K "16 --single-thread --long"
roundTripTest -g518K "19 --single-thread --long"
fileRoundTripTest -g5M "3 --single-thread --long"
2017-07-28 22:51:33 +00:00
2018-02-09 23:53:27 +00:00
roundTripTest -g96K "5 --single-thread"
2017-04-17 18:38:53 +00:00
if [ -n " $hasMT " ]
then
2019-05-02 19:35:37 +00:00
println "\n===> zstdmt round-trip tests "
2017-04-17 19:10:58 +00:00
roundTripTest -g4M "1 -T0"
roundTripTest -g8M "3 -T2"
2017-04-21 18:38:13 +00:00
roundTripTest -g8000K "2 --threads=2"
2017-04-17 19:10:58 +00:00
fileRoundTripTest -g4M "19 -T2 -B1M"
2017-07-28 22:51:33 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> zstdmt long distance matching round-trip tests "
2018-02-28 04:09:18 +00:00
roundTripTest -g8M "3 --long=24 -T2"
2018-03-29 19:07:28 +00:00
2020-09-08 14:34:50 +00:00
println "\n===> zstdmt environment variable tests "
echo "multifoo" >> mt_tmp
2020-09-09 16:35:40 +00:00
ZSTD_NBTHREADS = -3 zstd -f mt_tmp # negative value, warn and revert to default setting
ZSTD_NBTHREADS = '' zstd -f mt_tmp # empty env var, warn and revert to default setting
ZSTD_NBTHREADS = - zstd -f mt_tmp # malformed env var, warn and revert to default setting
ZSTD_NBTHREADS = a zstd -f mt_tmp # malformed env var, warn and revert to default setting
ZSTD_NBTHREADS = +a zstd -f mt_tmp # malformed env var, warn and revert to default setting
ZSTD_NBTHREADS = 3a7 zstd -f mt_tmp # malformed env var, warn and revert to default setting
ZSTD_NBTHREADS = 50000000000 zstd -f mt_tmp # numeric value too large, warn and revert to default setting=
ZSTD_NBTHREADS = 2 zstd -f mt_tmp # correct usage
ZSTD_NBTHREADS = 1 zstd -f mt_tmp # correct usage: single thread
2020-09-08 14:34:50 +00:00
rm mt_tmp*
2019-05-02 19:35:37 +00:00
println "\n===> ovLog tests "
2020-03-26 22:04:15 +00:00
datagen -g2MB > tmp
refSize = $( zstd tmp -6 -c --zstd= wlog = 18 | wc -c)
ov9Size = $( zstd tmp -6 -c --zstd= wlog = 18,ovlog= 9 | wc -c)
ov1Size = $( zstd tmp -6 -c --zstd= wlog = 18,ovlog= 1 | wc -c)
2019-05-02 19:35:37 +00:00
if [ " $refSize " -eq " $ov9Size " ] ; then
2018-03-29 19:07:28 +00:00
echo ov9Size should be different from refSize
exit 1
fi
2019-05-02 19:35:37 +00:00
if [ " $refSize " -eq " $ov1Size " ] ; then
2018-12-13 05:09:14 +00:00
echo ov1Size should be different from refSize
2018-03-29 19:07:28 +00:00
exit 1
fi
2019-05-02 19:35:37 +00:00
if [ " $ov9Size " -ge " $ov1Size " ] ; then
echo ov9Size = " $ov9Size " should be smaller than ov1Size = " $ov1Size "
2018-03-29 19:07:28 +00:00
exit 1
fi
2017-04-17 18:38:53 +00:00
else
2019-05-02 19:35:37 +00:00
println "\n===> no multithreading, skipping zstdmt tests "
2017-04-17 18:38:53 +00:00
fi
2016-02-15 19:37:23 +00:00
rm tmp*
2015-12-08 15:36:37 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> zstd --list/-l single frame tests "
2020-03-26 22:04:15 +00:00
datagen > tmp1
datagen > tmp2
datagen > tmp3
zstd tmp*
zstd -l ./*.zst
zstd -lv ./*.zst | grep "Decompressed Size:" # check that decompressed size is present in header
zstd --list ./*.zst
zstd --list -v ./*.zst
2017-06-15 23:53:03 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> zstd --list/-l multiple frame tests "
2017-06-15 23:53:03 +00:00
cat tmp1.zst tmp2.zst > tmp12.zst
2017-09-27 22:16:27 +00:00
cat tmp12.zst tmp3.zst > tmp123.zst
2020-03-26 22:04:15 +00:00
zstd -l ./*.zst
zstd -lv ./*.zst
2017-06-15 23:53:03 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> zstd --list/-l error detection tests "
2020-03-26 22:04:15 +00:00
zstd -l tmp1 tmp1.zst && die "-l must fail on non-zstd file"
zstd --list tmp* && die "-l must fail on non-zstd file"
zstd -lv tmp1* && die "-l must fail on non-zstd file"
zstd --list -v tmp2 tmp12.zst && die "-l must fail on non-zstd file"
2017-06-20 18:54:44 +00:00
2019-05-02 19:35:37 +00:00
println "test : detect truncated compressed file "
2019-01-15 01:58:46 +00:00
TEST_DATA_FILE = truncatable-input.txt
FULL_COMPRESSED_FILE = ${ TEST_DATA_FILE } .zst
TRUNCATED_COMPRESSED_FILE = truncated-input.txt.zst
2020-03-26 22:04:15 +00:00
datagen -g50000 > $TEST_DATA_FILE
zstd -f $TEST_DATA_FILE -o $FULL_COMPRESSED_FILE
2019-04-15 23:21:46 +00:00
dd bs = 1 count = 100 if = $FULL_COMPRESSED_FILE of = $TRUNCATED_COMPRESSED_FILE
2020-03-26 22:04:15 +00:00
zstd --list $TRUNCATED_COMPRESSED_FILE && die "-l must fail on truncated file"
2019-01-15 01:58:46 +00:00
rm $TEST_DATA_FILE
rm $FULL_COMPRESSED_FILE
rm $TRUNCATED_COMPRESSED_FILE
2019-05-02 19:35:37 +00:00
println "\n===> zstd --list/-l errors when presented with stdin / no files"
2020-03-26 22:04:15 +00:00
zstd -l && die "-l must fail on empty list of files"
zstd -l - && die "-l does not work on stdin"
zstd -l < tmp1.zst && die "-l does not work on stdin"
zstd -l - < tmp1.zst && die "-l does not work on stdin"
zstd -l - tmp1.zst && die "-l does not work on stdin"
zstd -l - tmp1.zst < tmp1.zst && die "-l does not work on stdin"
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
2018-06-19 16:56:37 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> zstd --list/-l test with null files "
2020-03-26 22:04:15 +00:00
datagen -g0 > tmp5
zstd tmp5
zstd -l tmp5.zst
zstd -l tmp5* && die "-l must fail on non-zstd file"
zstd -lv tmp5.zst | grep "Decompressed Size: 0.00 KB (0 B)" # check that 0 size is present in header
zstd -lv tmp5* && die "-l must fail on non-zstd file"
2017-06-20 21:33:08 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> zstd --list/-l test with no content size field "
2020-03-26 22:04:15 +00:00
datagen -g513K | zstd > tmp6.zst
zstd -l tmp6.zst
zstd -lv tmp6.zst | grep "Decompressed Size:" && die "Field :Decompressed Size: should not be available in this compressed file"
2017-06-21 19:09:53 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> zstd --list/-l test with no checksum "
2020-03-26 22:04:15 +00:00
zstd -f --no-check tmp1
zstd -l tmp1.zst
zstd -lv tmp1.zst
2017-06-21 00:43:36 +00:00
2017-06-15 23:53:03 +00:00
rm tmp*
2017-06-21 19:09:53 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> zstd long distance matching tests "
2018-02-28 04:09:18 +00:00
roundTripTest -g0 " --single-thread --long"
roundTripTest -g9M "2 --single-thread --long"
2017-09-27 22:48:06 +00:00
# Test parameter parsing
2018-02-28 04:09:18 +00:00
roundTripTest -g1M -P50 "1 --single-thread --long=29" " --memory=512MB"
roundTripTest -g1M -P50 "1 --single-thread --long=29 --zstd=wlog=28" " --memory=256MB"
roundTripTest -g1M -P50 "1 --single-thread --long=29" " --long=28 --memory=512MB"
roundTripTest -g1M -P50 "1 --single-thread --long=29" " --zstd=wlog=28 --memory=512MB"
2017-09-27 22:48:06 +00:00
2019-12-03 00:08:08 +00:00
if [ " $1 " != "--test-large-data" ] ; then
println "Skipping large data tests"
exit 0
fi
#############################################################################
2019-05-26 10:18:39 +00:00
if [ -n " $hasMT " ]
then
println "\n===> adaptive mode "
roundTripTest -g270000000 " --adapt"
roundTripTest -g27000000 " --adapt=min=1,max=4"
println "===> test: --adapt must fail on incoherent bounds "
2020-03-26 22:04:15 +00:00
datagen > tmp
zstd -f -vv --adapt= min = 10,max= 9 tmp && die "--adapt must fail on incoherent bounds"
2018-09-25 01:16:08 +00:00
2019-05-26 10:18:39 +00:00
println "\n===> rsyncable mode "
roundTripTest -g10M " --rsyncable"
roundTripTest -g10M " --rsyncable -B100K"
println "===> test: --rsyncable must fail with --single-thread"
2020-03-26 22:04:15 +00:00
zstd -f -vv --rsyncable --single-thread tmp && die "--rsyncable must fail with --single-thread"
2019-05-26 10:18:39 +00:00
fi
2018-11-14 21:53:14 +00:00
2020-07-17 20:31:15 +00:00
println "\n===> patch-from=origin tests"
2020-03-26 22:04:15 +00:00
datagen -g1000 -P50 > tmp_dict
datagen -g1000 -P10 > tmp_patch
2020-04-17 20:58:53 +00:00
zstd --patch-from= tmp_dict tmp_patch -o tmp_patch_diff
zstd -d --patch-from= tmp_dict tmp_patch_diff -o tmp_patch_recon
2020-01-10 22:25:24 +00:00
$DIFF -s tmp_patch_recon tmp_patch
2020-07-17 20:31:15 +00:00
println "\n===> alternate syntax: patch-from origin"
zstd -f --patch-from tmp_dict tmp_patch -o tmp_patch_diff
zstd -df --patch-from tmp_dict tmp_patch_diff -o tmp_patch_recon
$DIFF -s tmp_patch_recon tmp_patch
2020-01-10 22:25:24 +00:00
rm -rf tmp_*
2018-09-25 01:16:08 +00:00
2020-04-17 20:58:53 +00:00
println "\n===> patch-from recursive tests"
mkdir tmp_dir
2020-04-22 02:04:55 +00:00
datagen > tmp_dir/tmp1
2020-04-17 20:58:53 +00:00
datagen > tmp_dir/tmp2
datagen > tmp_dict
zstd --patch-from= tmp_dict -r tmp_dir && die
2020-04-22 02:04:55 +00:00
rm -rf tmp*
println "\n===> patch-from long mode trigger larger file test"
datagen -g5000000 > tmp_dict
datagen -g5000000 > tmp_patch
2020-06-05 08:19:30 +00:00
zstd -15 --patch-from= tmp_dict tmp_patch 2>& 1 | grep "long mode automatically triggered"
2020-04-22 02:04:55 +00:00
rm -rf tmp*
2020-04-17 20:58:53 +00:00
2020-06-18 16:36:36 +00:00
println "\n===> patch-from --stream-size test"
datagen -g1000 -P50 > tmp_dict
datagen -g1000 -P10 > tmp_patch
cat tmp_patch | zstd -f --patch-from= tmp_dict -c -o tmp_patch_diff && die
cat tmp_patch | zstd -f --patch-from= tmp_dict --stream-size= 1000 -c -o tmp_patch_diff
rm -rf tmp*
2019-05-02 19:35:37 +00:00
println "\n===> large files tests "
2017-09-27 22:48:06 +00:00
2015-12-08 15:36:37 +00:00
roundTripTest -g270000000 1
2017-09-27 22:16:27 +00:00
roundTripTest -g250000000 2
roundTripTest -g230000000 3
2015-12-08 15:36:37 +00:00
roundTripTest -g140000000 -P60 4
2017-09-27 22:16:27 +00:00
roundTripTest -g130000000 -P62 5
roundTripTest -g120000000 -P65 6
2015-12-08 15:36:37 +00:00
roundTripTest -g70000000 -P70 7
2017-09-27 22:16:27 +00:00
roundTripTest -g60000000 -P71 8
roundTripTest -g50000000 -P73 9
2015-12-08 15:36:37 +00:00
roundTripTest -g35000000 -P75 10
2017-09-27 22:16:27 +00:00
roundTripTest -g30000000 -P76 11
roundTripTest -g25000000 -P78 12
2015-12-08 15:11:10 +00:00
2017-07-11 00:16:41 +00:00
roundTripTest -g18000013 -P80 13
roundTripTest -g18000014 -P80 14
2017-09-27 22:16:27 +00:00
roundTripTest -g18000015 -P81 15
roundTripTest -g18000016 -P84 16
roundTripTest -g18000017 -P88 17
2017-07-11 00:16:41 +00:00
roundTripTest -g18000018 -P94 18
2017-09-27 22:16:27 +00:00
roundTripTest -g18000019 -P96 19
2015-12-08 16:36:42 +00:00
2020-01-17 22:20:44 +00:00
roundTripTest -g5000000000 -P99 "1 --zstd=wlog=25"
roundTripTest -g3700000000 -P0 "1 --zstd=strategy=6,wlog=25" # ensure btlazy2 can survive an overflow rescale
2016-02-15 19:37:23 +00:00
2017-04-12 00:15:13 +00:00
fileRoundTripTest -g4193M -P99 1
2017-09-27 22:48:06 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> zstd long, long distance matching round-trip tests "
2018-02-28 04:09:18 +00:00
roundTripTest -g270000000 "1 --single-thread --long"
roundTripTest -g130000000 -P60 "5 --single-thread --long"
roundTripTest -g35000000 -P70 "8 --single-thread --long"
roundTripTest -g18000001 -P80 "18 --single-thread --long"
2017-09-22 21:04:39 +00:00
# Test large window logs
2018-02-28 04:09:18 +00:00
roundTripTest -g700M -P50 "1 --single-thread --long=29"
roundTripTest -g600M -P50 "1 --single-thread --long --zstd=wlog=29,clog=28"
2017-07-28 22:51:33 +00:00
2017-04-17 18:38:53 +00:00
if [ -n " $hasMT " ]
then
2019-05-02 19:35:37 +00:00
println "\n===> zstdmt long round-trip tests "
2017-09-27 22:16:27 +00:00
roundTripTest -g80000000 -P99 "19 -T2" " "
roundTripTest -g5000000000 -P99 "1 -T2" " "
roundTripTest -g500000000 -P97 "1 -T999" " "
fileRoundTripTest -g4103M -P98 " -T0" " "
roundTripTest -g400000000 -P97 "1 --long=24 -T2" " "
2019-07-12 22:45:18 +00:00
# Exposes the bug in https://github.com/facebook/zstd/pull/1678
# This test fails on 4 different travis builds at the time of writing
# because it needs to allocate 8 GB of memory.
# roundTripTest -g10G -P99 "1 -T1 --long=31 --zstd=clog=27 --fast=1000"
2017-04-17 18:38:53 +00:00
else
2019-05-02 19:35:37 +00:00
println "\n**** no multithreading, skipping zstdmt tests **** "
2017-04-17 18:38:53 +00:00
fi
2018-09-20 00:37:22 +00:00
2019-05-02 19:35:37 +00:00
println "\n===> cover dictionary builder : advanced options "
2018-09-20 00:37:22 +00:00
2019-05-02 19:35:37 +00:00
TESTFILE = " $PRGDIR " /zstdcli.c
2020-03-26 22:04:15 +00:00
datagen > tmpDict
2019-05-02 19:35:37 +00:00
println "- Create first dictionary"
2020-03-26 22:04:15 +00:00
zstd --train-cover= k = 46,d= 8,split= 80 " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpDict
2019-05-02 19:35:37 +00:00
cp " $TESTFILE " tmp
2020-03-26 22:04:15 +00:00
zstd -f tmp -D tmpDict
zstd -d tmp.zst -D tmpDict -fo result
2019-05-02 19:35:37 +00:00
$DIFF " $TESTFILE " result
2020-03-26 22:04:15 +00:00
zstd --train-cover= k = 56,d= 8 && die "Create dictionary without input file (should error)"
2019-05-02 19:35:37 +00:00
println "- Create second (different) dictionary"
2020-03-26 22:04:15 +00:00
zstd --train-cover= k = 56,d= 8 " $TESTDIR " /*.c " $PRGDIR " /*.c " $PRGDIR " /*.h -o tmpDictC
zstd -d tmp.zst -D tmpDictC -fo result && die "wrong dictionary not detected!"
2019-06-27 23:26:57 +00:00
println "- Create dictionary using shrink-dict flag"
2020-03-26 22:04:15 +00:00
zstd --train-cover= steps = 256,shrink " $TESTDIR " /*.c " $PRGDIR " /*.c --dictID= 1 -o tmpShrinkDict
zstd --train-cover= steps = 256,shrink= 1 " $TESTDIR " /*.c " $PRGDIR " /*.c --dictID= 1 -o tmpShrinkDict1
zstd --train-cover= steps = 256,shrink= 5 " $TESTDIR " /*.c " $PRGDIR " /*.c --dictID= 1 -o tmpShrinkDict2
2019-05-02 19:35:37 +00:00
println "- Create dictionary with short dictID"
2020-03-26 22:04:15 +00:00
zstd --train-cover= k = 46,d= 8,split= 80 " $TESTDIR " /*.c " $PRGDIR " /*.c --dictID= 1 -o tmpDict1
2018-09-20 00:37:22 +00:00
cmp tmpDict tmpDict1 && die "dictionaries should have different ID !"
2019-05-02 19:35:37 +00:00
println "- Create dictionary with size limit"
2020-03-26 22:04:15 +00:00
zstd --train-cover= steps = 8 " $TESTDIR " /*.c " $PRGDIR " /*.c -o tmpDict2 --maxdict= 4K
2019-05-02 19:35:37 +00:00
println "- Compare size of dictionary from 90% training samples with 80% training samples"
2020-03-26 22:04:15 +00:00
zstd --train-cover= split = 90 -r " $TESTDIR " /*.c " $PRGDIR " /*.c
zstd --train-cover= split = 80 -r " $TESTDIR " /*.c " $PRGDIR " /*.c
2019-05-02 19:35:37 +00:00
println "- Create dictionary using all samples for both training and testing"
2020-03-26 22:04:15 +00:00
zstd --train-cover= split = 100 -r " $TESTDIR " /*.c " $PRGDIR " /*.c
2019-05-02 19:35:37 +00:00
println "- Test -o before --train-cover"
2018-09-20 00:37:22 +00:00
rm -f tmpDict dictionary
2020-03-26 22:04:15 +00:00
zstd -o tmpDict --train-cover " $TESTDIR " /*.c " $PRGDIR " /*.c
2018-09-20 00:37:22 +00:00
test -f tmpDict
2020-03-26 22:04:15 +00:00
zstd --train-cover " $TESTDIR " /*.c " $PRGDIR " /*.c
2018-09-20 00:37:22 +00:00
test -f dictionary
2018-09-20 20:00:11 +00:00
rm -f tmp* dictionary
2018-09-20 00:37:22 +00:00
2018-09-20 20:00:11 +00:00
rm -f tmp*