From 1b95d60c66bfc80b77066f929263cf3aac412434 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 9 Nov 2016 15:04:55 -0800 Subject: fixed synthetic benchmark mode slightly optimized test mode --- programs/bench.c | 5 ++--- programs/lz4cli.c | 25 +++++++++++++------------ programs/lz4io.c | 4 ++-- tests/Makefile | 5 ++++- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/programs/bench.c b/programs/bench.c index 33f5fcf..e8d89ec 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -43,7 +43,7 @@ static int LZ4_compress_local(const char* src, char* dst, int srcSize, int dstSi #include "lz4hc.h" #define COMPRESSOR1 LZ4_compress_HC #define DEFAULTCOMPRESSOR COMPRESSOR0 -#define LZ4_isError(errcode) (errcode==0) +#define LZ4_isError(errcode) (errcode==0) /* ************************************* @@ -129,8 +129,7 @@ void BMK_SetBlockSize(size_t blockSize) /* ******************************************************** * Bench functions **********************************************************/ -typedef struct -{ +typedef struct { const char* srcPtr; size_t srcSize; char* cPtr; diff --git a/programs/lz4cli.c b/programs/lz4cli.c index fdfa8f2..e3951f8 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -284,9 +284,9 @@ int main(int argc, const char** argv) multiple_inputs=0, operationResult=0; operationMode_e mode = om_auto; - const char* input_filename=0; - const char* output_filename=0; - char* dynNameSpace=0; + const char* input_filename = NULL; + const char* output_filename= NULL; + char* dynNameSpace = NULL; const char** inFileNames = NULL; unsigned ifnIdx=0; const char nullOutput[] = NULL_OUTPUT; @@ -428,7 +428,7 @@ int main(int argc, const char** argv) /* Benchmark */ case 'b': mode = om_bench; multiple_inputs=1; if (inFileNames == NULL) - inFileNames = (const char**) malloc(argc * sizeof(char*)); + inFileNames = (const char**) calloc(argc, sizeof(char*)); break; #ifdef UTIL_HAS_CREATEFILELIST @@ -438,7 +438,7 @@ int main(int argc, const char** argv) /* Treat non-option args as input files. See https://code.google.com/p/lz4/issues/detail?id=151 */ case 'm': multiple_inputs=1; if (inFileNames == NULL) - inFileNames = (const char**) malloc(argc * sizeof(char*)); + inFileNames = (const char**) calloc(argc, sizeof(char*)); break; /* Modify Nb Seconds (benchmark only) */ @@ -502,13 +502,6 @@ int main(int argc, const char** argv) } #endif } - if(!input_filename) { input_filename=stdinmark; } - - /* Check if input is defined as console; trigger an error in this case */ - if (!strcmp(input_filename, stdinmark) && IS_CONSOLE(stdin) ) { - DISPLAYLEVEL(1, "refusing to read from a console\n"); - exit(1); - } /* benchmark and test modes */ if (mode == om_bench) { @@ -524,6 +517,14 @@ int main(int argc, const char** argv) } /* compress or decompress */ + if (!input_filename) { input_filename=stdinmark; } + /* Check if input is defined as console; trigger an error in this case */ + if (!strcmp(input_filename, stdinmark) + && IS_CONSOLE(stdin) ) { + DISPLAYLEVEL(1, "refusing to read from a console\n"); + exit(1); + } + /* No output filename ==> try to select one automatically (when possible) */ while (!output_filename) { if (!IS_CONSOLE(stdout)) { output_filename=stdoutmark; break; } /* Default to stdout whenever possible (i.e. not a console) */ diff --git a/programs/lz4io.c b/programs/lz4io.c index 73957e1..c0eb667 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -805,7 +805,7 @@ static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE /* Write Block */ if (decodedBytes) { - storedSkips = LZ4IO_fwriteSparse(dstFile, ress.dstBuffer, decodedBytes, storedSkips); + if (!g_testMode) storedSkips = LZ4IO_fwriteSparse(dstFile, ress.dstBuffer, decodedBytes, storedSkips); filesize += decodedBytes; DISPLAYUPDATE(2, "\rDecompressed : %u MB ", (unsigned)(filesize>>20)); } @@ -816,7 +816,7 @@ static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE /* can be out because readSize == 0, which could be an fread() error */ if (ferror(srcFile)) EXM_THROW(67, "Read error"); - LZ4IO_fwriteSparseEnd(dstFile, storedSkips); + if (!g_testMode) LZ4IO_fwriteSparseEnd(dstFile, storedSkips); if (nextToLoad!=0) EXM_THROW(68, "Unfinished stream"); return filesize; diff --git a/tests/Makefile b/tests/Makefile index e6779d9..56c299b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -230,9 +230,12 @@ test-lz4-hugefile: lz4 datagen @$(RM) tmp* test-lz4-testmode: lz4 datagen - @echo "\n ---- test and pass-through ----" + @echo "\n ---- bench mode ----" + $(PRGDIR)/lz4 -bi1 + @echo "\n ---- test mode ----" ./datagen | $(PRGDIR)/lz4 -t && false || true ./datagen | $(PRGDIR)/lz4 -tf && false || true + @echo "\n ---- pass-through mode ----" ./datagen | $(PRGDIR)/lz4 -d > $(VOID) && false || true ./datagen | $(PRGDIR)/lz4 -df > $(VOID) @echo "Hello World !" > tmp1 -- cgit v0.12