fixed synthetic benchmark mode

slightly optimized test mode
This commit is contained in:
Yann Collet 2016-11-09 15:04:55 -08:00
parent acc48a3f85
commit 1b95d60c66
4 changed files with 21 additions and 18 deletions

View File

@ -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;

View File

@ -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) */

View File

@ -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;

View File

@ -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