From 32990b5daeb0710b424caaa336911d5a0420bd89 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 23 May 2016 17:48:57 +0200 Subject: [PATCH] Added tests for Sparse mode support Fixed : complex cli arg case involving a mix of `stdin` and `-o` --- programs/playTests.sh | 27 +++++++++++++++++++++++++++ programs/zstdcli.c | 20 ++++++++++++-------- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/programs/playTests.sh b/programs/playTests.sh index 1c5f00a1..ee29bec0 100755 --- a/programs/playTests.sh +++ b/programs/playTests.sh @@ -75,6 +75,33 @@ echo "echo foo | $ZSTD | $ZSTD -d > /dev/full" echo foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!" +echo "\n**** test sparse file support **** " + +./datagen -g5M -P100 > tmpSparse +$ZSTD tmpSparse -c | $ZSTD -dv -o tmpSparseRegen +diff -s tmpSparse tmpSparseRegen +$ZSTD tmpSparse -c | $ZSTD -dv --sparse -c > tmpOutSparse +diff -s tmpSparse tmpOutSparse +$ZSTD tmpSparse -c | $ZSTD -dv --no-sparse -c > tmpOutNoSparse +diff -s tmpSparse tmpOutNoSparse +ls -ls tmpSparse* +./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 +ls -ls tmpSparseOdd +echo "\n Sparse Compatibility with Console :" +echo "Hello World 1 !" | $ZSTD | $ZSTD -d -c +echo "Hello World 2 !" | $ZSTD | $ZSTD -d | cat +echo "\n Sparse Compatibility with Append :" +./datagen -P100 -g1M > tmpSparse1M +cat tmpSparse1M tmpSparse1M > tmpSparse2M +$ZSTD -v -f tmpSparse1M -o tmpSparseCompressed +$ZSTD -d -v -f tmpSparseCompressed -o tmpSparseRegenerated +$ZSTD -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated +ls -ls tmpSparse* +diff tmpSparse2M tmpSparseRegenerated +# rm tmpSparse* + + echo "\n**** dictionary tests **** " ./datagen > tmpDict diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 3fdc558b..d09dbe44 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -176,7 +176,7 @@ static void waitEnter(void) int main(int argCount, const char** argv) { - int i, + int argNb, bench=0, decode=0, forceStdout=0, @@ -203,18 +203,21 @@ int main(int argCount, const char** argv) (void)recursive; (void)cLevelLast; (void)dictCLevel; /* not used when ZSTD_NOBENCH / ZSTD_NODICT set */ (void)decode; (void)cLevel; /* not used when ZSTD_NOCOMPRESS set */ if (filenameTable==NULL) { DISPLAY("not enough memory\n"); exit(1); } + filenameTable[0] = stdinmark; displayOut = stderr; /* Pick out program name from path. Don't rely on stdlib because of conflicting behavior */ - for (i = (int)strlen(programName); i > 0; i--) { if (programName[i] == '/') { i++; break; } } - programName += i; + { size_t pos; + for (pos = (int)strlen(programName); pos > 0; pos--) { if (programName[pos] == '/') { pos++; break; } } + programName += pos; + } /* preset behaviors */ if (!strcmp(programName, ZSTD_UNZSTD)) decode=1; if (!strcmp(programName, ZSTD_CAT)) { decode=1; forceStdout=1; displayLevel=1; outFileName=stdoutmark; } /* command switches */ - for(i=1; i use stdin and stdout */ - if(!filenameIdx) filenameIdx=1, filenameTable[0]=stdinmark, outFileName=stdoutmark; + filenameIdx += !filenameIdx; /*< default input is stdin */ + if (!strcmp(filenameTable[0], stdinmark) && !outFileName ) outFileName = stdoutmark; /*< when input is stdin, default output is stdout */ /* Check if input/output defined as console; trigger an error in this case */ if (!strcmp(filenameTable[0], stdinmark) && IS_CONSOLE(stdin) ) CLEAN_RETURN(badusage(programName)); @@ -443,9 +447,9 @@ int main(int argCount, const char** argv) { /* decompression */ #ifndef ZSTD_NODECOMPRESS if (filenameIdx==1 && outFileName) - operationResult = FIO_decompressFilename(outFileName, filenameTable[0], dictFileName); + operationResult = FIO_decompressFilename(outFileName, filenameTable[0], dictFileName); else - operationResult = FIO_decompressMultipleFilenames(filenameTable, filenameIdx, outFileName ? outFileName : ZSTD_EXTENSION, dictFileName); + operationResult = FIO_decompressMultipleFilenames(filenameTable, filenameIdx, outFileName ? outFileName : ZSTD_EXTENSION, dictFileName); #else DISPLAY("Decompression not supported\n"); #endif