summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2019-04-09 23:26:49 (GMT)
committerGitHub <noreply@github.com>2019-04-09 23:26:49 (GMT)
commit9fdc1a01184b5a6f676aba224c7cb4eac5a1e6c4 (patch)
treed70e6cfd23888e2b69b65c2cf16edff0ccc96ea0 /tests
parentf66abc45d9b9671b889acb1e5a2506228f85548c (diff)
parentd8d5f14138109f81d0f5dba60ac179cfe16405c5 (diff)
downloadlz4-9fdc1a01184b5a6f676aba224c7cb4eac5a1e6c4.zip
lz4-9fdc1a01184b5a6f676aba224c7cb4eac5a1e6c4.tar.gz
lz4-9fdc1a01184b5a6f676aba224c7cb4eac5a1e6c4.tar.bz2
Merge pull request #659 from lz4/resetFast
LZ4_resetStream*_fast()
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile14
-rw-r--r--tests/checkFrame.c19
-rw-r--r--tests/frametest.c9
-rw-r--r--tests/fullbench.c21
-rw-r--r--tests/fuzzer.c86
5 files changed, 82 insertions, 67 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 7d49b31..792c22c 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -115,15 +115,15 @@ checkFrame : lz4frame.o lz4.o lz4hc.o xxhash.o checkFrame.c
clean:
@$(MAKE) -C $(LZ4DIR) $@ > $(VOID)
@$(MAKE) -C $(PRGDIR) $@ > $(VOID)
- @$(RM) core *.o *.test tmp* \
+ @$(RM) -rf core *.o *.test tmp* \
fullbench-dll$(EXT) fullbench-lib$(EXT) \
fullbench$(EXT) fullbench32$(EXT) \
fuzzer$(EXT) fuzzer32$(EXT) \
frametest$(EXT) frametest32$(EXT) \
fasttest$(EXT) roundTripTest$(EXT) \
datagen$(EXT) checkTag$(EXT) \
- frameTest$(EXT)
- @rm -fR $(TESTDIR)
+ frameTest$(EXT)
+ @$(RM) -rf $(TESTDIR)
@echo Cleaning completed
.PHONY: versionsTest
@@ -151,12 +151,18 @@ endif
DD:=dd
+.PHONY: list
+list:
+ @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs
+.PHONY: test
test: test-lz4 test-lz4c test-frametest test-fullbench test-fuzzer test-install test-amalgamation
+.PHONY: test32
test32: CFLAGS+=-m32
test32: test
+.PHONY: test-amalgamation
test-amalgamation: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c
cat $(LZ4DIR)/lz4.c > lz4_all.c
cat $(LZ4DIR)/lz4hc.c >> lz4_all.c
@@ -321,7 +327,7 @@ test-lz4-dict: lz4 datagen
test-lz4-hugefile: lz4 datagen
@echo "\n ---- test huge files compression/decompression ----"
./datagen -g6GB | $(LZ4) -vB5D | $(LZ4) -qt
- ./datagen -g6GB | $(LZ4) -v5BD | $(LZ4) -qt
+ ./datagen -g5GB | $(LZ4) -v4BD | $(LZ4) -qt
# test large file size [2-4] GB
@./datagen -g3G -P100 | $(LZ4) -vv | $(LZ4) --decompress --force --sparse - tmphf1
@ls -ls tmphf1
diff --git a/tests/checkFrame.c b/tests/checkFrame.c
index f7e7a50..50c0405 100644
--- a/tests/checkFrame.c
+++ b/tests/checkFrame.c
@@ -1,6 +1,6 @@
/*
checkFrame - verify frame headers
- Copyright (C) Yann Collet 2014-2016
+ Copyright (C) Yann Collet 2014-present
GPL v2 License
@@ -159,8 +159,12 @@ int frameCheck(cRess_t ress, FILE* const srcFile, unsigned bsid, size_t blockSiz
curblocksize = 0;
remaining = readSize - pos;
nextToLoad = LZ4F_getFrameInfo(ress.ctx, &frameInfo, (char*)(ress.srcBuffer)+pos, &remaining);
- if (LZ4F_isError(nextToLoad)) EXM_THROW(22, "Error getting frame info: %s", LZ4F_getErrorName(nextToLoad)); /* XXX */
- if (frameInfo.blockSizeID != bsid) EXM_THROW(23, "Block size ID %u != expected %u", frameInfo.blockSizeID, bsid);
+ if (LZ4F_isError(nextToLoad))
+ EXM_THROW(22, "Error getting frame info: %s",
+ LZ4F_getErrorName(nextToLoad));
+ if (frameInfo.blockSizeID != bsid)
+ EXM_THROW(23, "Block size ID %u != expected %u",
+ frameInfo.blockSizeID, bsid);
pos += remaining;
/* nextToLoad should be block header size */
remaining = nextToLoad;
@@ -189,7 +193,8 @@ int frameCheck(cRess_t ress, FILE* const srcFile, unsigned bsid, size_t blockSiz
/* detect small block due to end of frame; the final 4-byte frame checksum could be left in the buffer */
if ((curblocksize != 0) && (nextToLoad > 4)) {
if (curblocksize != blockSize)
- EXM_THROW(25, "Block size %zu != expected %zu, pos %zu\n", curblocksize, blockSize, pos);
+ EXM_THROW(25, "Block size %u != expected %u, pos %u\n",
+ (unsigned)curblocksize, (unsigned)blockSize, (unsigned)pos);
}
curblocksize = 0;
}
@@ -220,7 +225,7 @@ int FUZ_usage(const char* programName)
int main(int argc, const char** argv)
{
int argNb;
- int bsid=0;
+ unsigned bsid=0;
size_t blockSize=0;
const char* const programName = argv[0];
@@ -262,7 +267,7 @@ int main(int argc, const char** argv)
bsid=0;
while ((*argument>='0') && (*argument<='9')) {
bsid *= 10;
- bsid += *argument - '0';
+ bsid += (unsigned)(*argument - '0');
argument++;
}
break;
@@ -272,7 +277,7 @@ int main(int argc, const char** argv)
blockSize=0;
while ((*argument>='0') && (*argument<='9')) {
blockSize *= 10;
- blockSize += *argument - '0';
+ blockSize += (size_t)(*argument - '0');
argument++;
}
break;
diff --git a/tests/frametest.c b/tests/frametest.c
index 14906a0..fa005db 100644
--- a/tests/frametest.c
+++ b/tests/frametest.c
@@ -270,7 +270,7 @@ int basicTests(U32 seed, double compressibility)
if (decResult != 0) goto _output_error; /* should finish now */
op += oSize;
if (op>oend) { DISPLAY("decompression write overflow \n"); goto _output_error; }
- { U64 const crcDest = XXH64(decodedBuffer, op-ostart, 1);
+ { U64 const crcDest = XXH64(decodedBuffer, (size_t)(op-ostart), 1);
if (crcDest != crcOrig) goto _output_error;
} }
@@ -309,7 +309,6 @@ int basicTests(U32 seed, double compressibility)
iSize = 15 - iSize;
CHECK( LZ4F_getFrameInfo(dCtx, &fi, ip, &iSize) );
DISPLAYLEVEL(3, " correctly decoded \n");
- ip += iSize;
}
DISPLAYLEVEL(3, "Decode a buggy input : ");
@@ -337,7 +336,7 @@ int basicTests(U32 seed, double compressibility)
const BYTE* ip = (const BYTE*) compressedBuffer;
const BYTE* const iend = ip + cSize;
while (ip < iend) {
- size_t oSize = oend-op;
+ size_t oSize = (size_t)(oend-op);
size_t iSize = 1;
CHECK( LZ4F_decompress(dCtx, op, &oSize, ip, &iSize, NULL) );
op += oSize;
@@ -380,8 +379,8 @@ int basicTests(U32 seed, double compressibility)
while (ip < iend) {
unsigned const nbBits = FUZ_rand(&randState) % maxBits;
size_t iSize = (FUZ_rand(&randState) & ((1<<nbBits)-1)) + 1;
- size_t oSize = oend-op;
- if (iSize > (size_t)(iend-ip)) iSize = iend-ip;
+ size_t oSize = (size_t)(oend-op);
+ if (iSize > (size_t)(iend-ip)) iSize = (size_t)(iend-ip);
CHECK( LZ4F_decompress(dCtx, op, &oSize, ip, &iSize, NULL) );
op += oSize;
ip += iSize;
diff --git a/tests/fullbench.c b/tests/fullbench.c
index e08947d..456c916 100644
--- a/tests/fullbench.c
+++ b/tests/fullbench.c
@@ -161,12 +161,14 @@ static size_t BMK_findMaxMem(U64 requiredMem)
static LZ4_stream_t LZ4_stream;
static void local_LZ4_resetDictT(void)
{
- LZ4_resetStream(&LZ4_stream);
+ void* const r = LZ4_initStream(&LZ4_stream, sizeof(LZ4_stream));
+ assert(r != NULL);
}
static void local_LZ4_createStream(void)
{
- LZ4_resetStream(&LZ4_stream);
+ void* const r = LZ4_initStream(&LZ4_stream, sizeof(LZ4_stream));
+ assert(r != NULL);
}
static int local_LZ4_saveDict(const char* in, char* out, int inSize)
@@ -243,7 +245,7 @@ static int local_LZ4_compress_forceDict(const char* in, char* out, int inSize)
LZ4_streamHC_t LZ4_streamHC;
static void local_LZ4_resetStreamHC(void)
{
- LZ4_resetStreamHC(&LZ4_streamHC, 0);
+ LZ4_initStreamHC(&LZ4_streamHC, sizeof(LZ4_streamHC));
}
static int local_LZ4_saveDictHC(const char* in, char* out, int inSize)
@@ -327,16 +329,19 @@ static int local_LZ4_decompress_safe_partial(const char* in, char* out, int inSi
/* frame functions */
static int local_LZ4F_compressFrame(const char* in, char* out, int inSize)
{
- return (int)LZ4F_compressFrame(out, LZ4F_compressFrameBound(inSize, NULL), in, inSize, NULL);
+ assert(inSize >= 0);
+ return (int)LZ4F_compressFrame(out, LZ4F_compressFrameBound((size_t)inSize, NULL), in, (size_t)inSize, NULL);
}
static LZ4F_decompressionContext_t g_dCtx;
static int local_LZ4F_decompress(const char* in, char* out, int inSize, int outSize)
{
- size_t srcSize = inSize;
- size_t dstSize = outSize;
+ size_t srcSize = (size_t)inSize;
+ size_t dstSize = (size_t)outSize;
size_t result;
+ assert(inSize >= 0);
+ assert(outSize >= 0);
result = LZ4F_decompress(g_dCtx, out, &dstSize, in, &srcSize, NULL);
if (result!=0) { DISPLAY("Error decompressing frame : unfinished frame\n"); exit(8); }
if (srcSize != (size_t)inSize) { DISPLAY("Error decompressing frame : read size incorrect\n"); exit(9); }
@@ -439,7 +444,7 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
char* out = compressed_buff;
nbChunks = (int) (((int)benchedSize + (g_chunkSize-1))/ g_chunkSize);
for (i=0; i<nbChunks; i++) {
- chunkP[i].id = i;
+ chunkP[i].id = (U32)i;
chunkP[i].origBuffer = in; in += g_chunkSize;
if ((int)remaining > g_chunkSize) { chunkP[i].origSize = g_chunkSize; remaining -= g_chunkSize; } else { chunkP[i].origSize = (int)remaining; remaining = 0; }
chunkP[i].compressedBuffer = out; out += maxCompressedChunkSize;
@@ -611,7 +616,7 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
PROGRESS("%2i-%-34.34s :%10i -> %7.1f MB/s\r", loopNb, dName, (int)benchedSize, (double)benchedSize / bestTime / 1000000);
/* CRC Checking */
- crcDecoded = XXH32(orig_buff, (int)benchedSize, 0);
+ crcDecoded = XXH32(orig_buff, benchedSize, 0);
if (checkResult && (crcOriginal!=crcDecoded)) {
DISPLAY("\n!!! WARNING !!! %14s : Invalid Checksum : %x != %x\n",
inFileName, (unsigned)crcOriginal, (unsigned)crcDecoded);
diff --git a/tests/fuzzer.c b/tests/fuzzer.c
index 69c763b..27d8d9c 100644
--- a/tests/fuzzer.c
+++ b/tests/fuzzer.c
@@ -37,6 +37,8 @@
* Dependencies
**************************************/
#if defined(__unix__) && !defined(_AIX) /* must be included before platform.h for MAP_ANONYMOUS */
+# undef _GNU_SOURCE /* in case it's already defined */
+# define _GNU_SOURCE /* MAP_ANONYMOUS even in -std=c99 mode */
# include <sys/mman.h> /* mmap */
#endif
#include "platform.h" /* _CRT_SECURE_NO_WARNINGS */
@@ -47,9 +49,6 @@
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */
#include <assert.h>
#include <limits.h> /* INT_MAX */
-#if defined(__unix__) && defined(_AIX)
-# include <sys/mman.h> /* mmap */
-#endif
#define LZ4_DISABLE_DEPRECATE_WARNINGS /* LZ4_decompress_fast */
#define LZ4_STATIC_LINKING_ONLY
@@ -309,13 +308,13 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
unsigned long long hcbytes = 0;
unsigned long long ccbytes = 0;
void* const CNBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH);
- size_t const compressedBufferSize = LZ4_compressBound(FUZ_MAX_BLOCK_SIZE);
+ size_t const compressedBufferSize = (size_t)LZ4_compressBound(FUZ_MAX_BLOCK_SIZE);
char* const compressedBuffer = (char*)malloc(compressedBufferSize);
char* const decodedBuffer = (char*)malloc(FUZ_MAX_DICT_SIZE + FUZ_MAX_BLOCK_SIZE);
size_t const labSize = 96 KB;
void* const lowAddrBuffer = FUZ_createLowAddr(labSize);
- void* const stateLZ4 = malloc(LZ4_sizeofState());
- void* const stateLZ4HC = malloc(LZ4_sizeofStateHC());
+ void* const stateLZ4 = malloc((size_t)LZ4_sizeofState());
+ void* const stateLZ4HC = malloc((size_t)LZ4_sizeofStateHC());
LZ4_stream_t LZ4dict;
LZ4_streamHC_t LZ4dictHC;
U32 coreRandState = seed;
@@ -346,7 +345,8 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
DISPLAY("Not enough memory to start fuzzer tests");
goto _output_error;
}
- memset(&LZ4dict, 0, sizeof(LZ4dict));
+ if ( LZ4_initStream(&LZ4dict, sizeof(LZ4dict)) == NULL) abort();
+ if ( LZ4_initStreamHC(&LZ4dictHC, sizeof(LZ4dictHC)) == NULL) abort();
{ U32 randState = coreRandState ^ PRIME3;
FUZ_fillCompressibleNoiseBuffer(CNBuffer, COMPRESSIBLE_NOISE_LENGTH, compressibility, &randState);
}
@@ -370,7 +370,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
const char* dict = block - dictSize;
int compressedSize, HCcompressedSize;
int blockContinueCompressedSize;
- U32 const crcOrig = XXH32(block, blockSize, 0);
+ U32 const crcOrig = XXH32(block, (size_t)blockSize, 0);
int ret;
FUZ_displayUpdate(cycleNb);
@@ -395,7 +395,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
DISPLAYLEVEL(5, "destSize : %7i/%7i; content%7i/%7i ", ret, targetSize, srcSize, blockSize);
if (targetSize>0) {
/* check correctness */
- U32 const crcBase = XXH32(block, srcSize, 0);
+ U32 const crcBase = XXH32(block, (size_t)srcSize, 0);
char const canary = FUZ_rand(&randState) & 255;
FUZ_CHECKTEST((ret==0), "LZ4_compress_destSize() compression failed");
FUZ_DISPLAYTEST();
@@ -430,7 +430,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
FUZ_CHECKTEST(srcSize > blockSize, "LZ4_compress_HC_destSize() fed more than src buffer !");
if (targetSize>0) {
/* check correctness */
- U32 const crcBase = XXH32(block, srcSize, 0);
+ U32 const crcBase = XXH32(block, (size_t)srcSize, 0);
char const canary = FUZ_rand(&randState) & 255;
FUZ_CHECKTEST((ret==0), "LZ4_compress_HC_destSize() compression failed");
FUZ_DISPLAYTEST();
@@ -547,7 +547,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
FUZ_CHECKTEST(ret<0, "LZ4_decompress_safe failed despite amply sufficient space");
FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe did not regenerate original data");
FUZ_CHECKTEST(decodedBuffer[blockSize+1], "LZ4_decompress_safe overrun specified output buffer size");
- { U32 const crcCheck = XXH32(decodedBuffer, blockSize, 0);
+ { U32 const crcCheck = XXH32(decodedBuffer, (size_t)blockSize, 0);
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe corrupted decoded data");
}
@@ -582,7 +582,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
/* Test partial decoding => must work */
FUZ_DISPLAYTEST("test LZ4_decompress_safe_partial");
{ size_t const missingBytes = FUZ_rand(&randState) % blockSize;
- int const targetSize = (int)(blockSize - missingBytes);
+ int const targetSize = (int)((size_t)blockSize - missingBytes);
char const sentinel = decodedBuffer[targetSize] = block[targetSize] ^ 0x5A;
int const decResult = LZ4_decompress_safe_partial(compressedBuffer, decodedBuffer, compressedSize, targetSize, blockSize);
FUZ_CHECKTEST(decResult<0, "LZ4_decompress_safe_partial failed despite valid input data (error:%i)", decResult);
@@ -642,7 +642,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
/* Compress using dictionary */
FUZ_DISPLAYTEST("test LZ4_compress_fast_continue() with dictionary of size %i", dictSize);
{ LZ4_stream_t LZ4_stream;
- LZ4_resetStream(&LZ4_stream);
+ LZ4_initStream(&LZ4_stream, sizeof(LZ4_stream));
LZ4_compress_fast_continue (&LZ4_stream, dict, compressedBuffer, dictSize, (int)compressedBufferSize, 1); /* Just to fill hash tables */
blockContinueCompressedSize = LZ4_compress_fast_continue (&LZ4_stream, block, compressedBuffer, blockSize, (int)compressedBufferSize, 1);
FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_fast_continue failed");
@@ -653,7 +653,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
memcpy(decodedBuffer, dict, dictSize);
ret = LZ4_decompress_fast_usingDict(compressedBuffer, decodedBuffer+dictSize, blockSize, decodedBuffer, dictSize);
FUZ_CHECKTEST(ret!=blockContinueCompressedSize, "LZ4_decompress_fast_usingDict did not read all compressed block input");
- { U32 const crcCheck = XXH32(decodedBuffer+dictSize, blockSize, 0);
+ { U32 const crcCheck = XXH32(decodedBuffer+dictSize, (size_t)blockSize, 0);
if (crcCheck!=crcOrig) FUZ_findDiff(block, decodedBuffer);
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_fast_usingDict corrupted decoded data (dict %i)", dictSize);
}
@@ -661,7 +661,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
FUZ_DISPLAYTEST("test LZ4_decompress_safe_usingDict()");
ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer+dictSize, blockContinueCompressedSize, blockSize, decodedBuffer, dictSize);
FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
- { U32 const crcCheck = XXH32(decodedBuffer+dictSize, blockSize, 0);
+ { U32 const crcCheck = XXH32(decodedBuffer+dictSize, (size_t)blockSize, 0);
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data");
}
@@ -743,7 +743,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
FUZ_DISPLAYTEST("LZ4_compress_fast_continue() after LZ4_attach_dictionary()");
LZ4_loadDict(&LZ4dict, dict, dictSize);
- LZ4_resetStream(&LZ4_stream);
+ LZ4_initStream(&LZ4_stream, sizeof(LZ4_stream));
LZ4_attach_dictionary(&LZ4_stream, &LZ4dict);
blockContinueCompressedSize = LZ4_compress_fast_continue(&LZ4_stream, block, compressedBuffer, blockSize, (int)compressedBufferSize, 1);
FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_fast_continue using extDictCtx failed");
@@ -801,7 +801,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize, dict, dictSize);
FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
FUZ_CHECKTEST(decodedBuffer[blockSize], "LZ4_decompress_safe_usingDict overrun specified output buffer size");
- { U32 const crcCheck = XXH32(decodedBuffer, blockSize, 0);
+ { U32 const crcCheck = XXH32(decodedBuffer, (size_t)blockSize, 0);
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data");
}
@@ -830,23 +830,22 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
FUZ_DISPLAYTEST("LZ4_compress_HC_continue with an external dictionary");
dict -= (FUZ_rand(&randState) & 7); /* even bigger separation */
if (dict < (char*)CNBuffer) dict = (char*)CNBuffer;
- LZ4_resetStreamHC (&LZ4dictHC, compressionLevel);
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
- LZ4_setCompressionLevel(&LZ4dictHC, compressionLevel-1);
+ LZ4_setCompressionLevel (&LZ4dictHC, compressionLevel);
blockContinueCompressedSize = LZ4_compress_HC_continue(&LZ4dictHC, block, compressedBuffer, blockSize, (int)compressedBufferSize);
FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_HC_continue failed");
FUZ_CHECKTEST(LZ4dictHC.internal_donotuse.dirty, "Context should be clean");
- FUZ_DISPLAYTEST();
+ FUZ_DISPLAYTEST("LZ4_compress_HC_continue with same external dictionary, but output buffer 1 byte too short");
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
ret = LZ4_compress_HC_continue(&LZ4dictHC, block, compressedBuffer, blockSize, blockContinueCompressedSize-1);
- FUZ_CHECKTEST(ret>0, "LZ4_compress_HC_continue using ExtDict should fail : one missing byte for output buffer (%i != %i)", ret, blockContinueCompressedSize);
+ FUZ_CHECKTEST(ret>0, "LZ4_compress_HC_continue using ExtDict should fail : one missing byte for output buffer (expected %i, but result=%i)", blockContinueCompressedSize, ret);
FUZ_CHECKTEST(!LZ4dictHC.internal_donotuse.dirty, "Context should be dirty");
- FUZ_DISPLAYTEST();
+ FUZ_DISPLAYTEST("LZ4_compress_HC_continue with same external dictionary, and output buffer exactly the right size");
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
ret = LZ4_compress_HC_continue(&LZ4dictHC, block, compressedBuffer, blockSize, blockContinueCompressedSize);
- FUZ_CHECKTEST(ret!=blockContinueCompressedSize, "LZ4_compress_HC_continue size is different (%i != %i)", ret, blockContinueCompressedSize);
+ FUZ_CHECKTEST(ret!=blockContinueCompressedSize, "LZ4_compress_HC_continue size is different : ret(%i) != expected(%i)", ret, blockContinueCompressedSize);
FUZ_CHECKTEST(ret<=0, "LZ4_compress_HC_continue should work : enough size available within output buffer");
FUZ_CHECKTEST(LZ4dictHC.internal_donotuse.dirty, "Context should be clean");
@@ -855,7 +854,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize, dict, dictSize);
FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
FUZ_CHECKTEST(decodedBuffer[blockSize], "LZ4_decompress_safe_usingDict overrun specified output buffer size");
- { U32 const crcCheck = XXH32(decodedBuffer, blockSize, 0);
+ { U32 const crcCheck = XXH32(decodedBuffer, (size_t)blockSize, 0);
if (crcCheck!=crcOrig) FUZ_findDiff(block, decodedBuffer);
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data");
}
@@ -864,11 +863,11 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
FUZ_DISPLAYTEST();
{
LZ4_streamHC_t LZ4_streamHC;
+ LZ4_initStreamHC(&LZ4_streamHC, sizeof(LZ4_streamHC));
- LZ4_resetStreamHC (&LZ4dictHC, compressionLevel);
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
- LZ4_resetStreamHC (&LZ4_streamHC, compressionLevel);
LZ4_attach_HC_dictionary(&LZ4_streamHC, &LZ4dictHC);
+ LZ4_setCompressionLevel (&LZ4_streamHC, compressionLevel);
blockContinueCompressedSize = LZ4_compress_HC_continue(&LZ4_streamHC, block, compressedBuffer, blockSize, (int)compressedBufferSize);
FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_HC_continue with ExtDictCtx failed");
FUZ_CHECKTEST(LZ4_streamHC.internal_donotuse.dirty, "Context should be clean");
@@ -895,25 +894,25 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
FUZ_CHECKTEST(ret!=blockContinueCompressedSize, "LZ4_compress_HC_continue using ExtDictCtx and fast reset size is different (%i != %i)", ret, blockContinueCompressedSize);
FUZ_CHECKTEST(ret<=0, "LZ4_compress_HC_continue using ExtDictCtx and fast reset should work : enough size available within output buffer");
FUZ_CHECKTEST(LZ4_streamHC.internal_donotuse.dirty, "Context should be clean");
+ }
- FUZ_DISPLAYTEST();
- decodedBuffer[blockSize] = 0;
- ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize, dict, dictSize);
- FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
- FUZ_CHECKTEST(decodedBuffer[blockSize], "LZ4_decompress_safe_usingDict overrun specified output buffer size");
- { U32 const crcCheck = XXH32(decodedBuffer, blockSize, 0);
- if (crcCheck!=crcOrig) FUZ_findDiff(block, decodedBuffer);
- FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data");
- }
+ FUZ_DISPLAYTEST();
+ decodedBuffer[blockSize] = 0;
+ ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize, dict, dictSize);
+ FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
+ FUZ_CHECKTEST(decodedBuffer[blockSize], "LZ4_decompress_safe_usingDict overrun specified output buffer size");
+ { U32 const crcCheck = XXH32(decodedBuffer, (size_t)blockSize, 0);
+ if (crcCheck!=crcOrig) FUZ_findDiff(block, decodedBuffer);
+ FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data");
}
/* Compress HC continue destSize */
FUZ_DISPLAYTEST();
- { int const availableSpace = (FUZ_rand(&randState) % blockSize) + 5;
+ { int const availableSpace = (int)(FUZ_rand(&randState) % blockSize) + 5;
int consumedSize = blockSize;
FUZ_DISPLAYTEST();
- LZ4_resetStreamHC (&LZ4dictHC, compressionLevel);
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
+ LZ4_setCompressionLevel(&LZ4dictHC, compressionLevel);
blockContinueCompressedSize = LZ4_compress_HC_continue_destSize(&LZ4dictHC, block, compressedBuffer, &consumedSize, availableSpace);
DISPLAYLEVEL(5, " LZ4_compress_HC_continue_destSize : compressed %6i/%6i into %6i/%6i at cLevel=%i\n", consumedSize, blockSize, blockContinueCompressedSize, availableSpace, compressionLevel);
FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_HC_continue_destSize failed");
@@ -925,8 +924,8 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, consumedSize, dict, dictSize);
FUZ_CHECKTEST(ret!=consumedSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
FUZ_CHECKTEST(decodedBuffer[consumedSize], "LZ4_decompress_safe_usingDict overrun specified output buffer size")
- { U32 const crcSrc = XXH32(block, consumedSize, 0);
- U32 const crcDst = XXH32(decodedBuffer, consumedSize, 0);
+ { U32 const crcSrc = XXH32(block, (size_t)consumedSize, 0);
+ U32 const crcDst = XXH32(decodedBuffer, (size_t)consumedSize, 0);
if (crcSrc!=crcDst) FUZ_findDiff(block, decodedBuffer);
FUZ_CHECKTEST(crcSrc!=crcDst, "LZ4_decompress_safe_usingDict corrupted decoded data");
}
@@ -1001,7 +1000,7 @@ static void FUZ_unitTests(int compressionLevel)
/* simple compression test */
crcOrig = XXH64(testInput, testCompressedSize, 0);
- LZ4_resetStream(&streamingState);
+ LZ4_initStream(&streamingState, sizeof(streamingState));
result = LZ4_compress_fast_continue(&streamingState, testInput, testCompressed, testCompressedSize, testCompressedSize-1, 1);
FUZ_CHECKTEST(result==0, "LZ4_compress_fast_continue() compression failed!");
FUZ_CHECKTEST(streamingState.internal_donotuse.dirty, "context should be clean")
@@ -1068,6 +1067,7 @@ static void FUZ_unitTests(int compressionLevel)
{ LZ4_streamHC_t sHC; /* statically allocated */
U64 crcOrig;
int result;
+ LZ4_initStreamHC(&sHC, sizeof(sHC));
/* Allocation test */
DISPLAYLEVEL(3, " Basic HC allocation : ");
@@ -1080,7 +1080,7 @@ static void FUZ_unitTests(int compressionLevel)
/* simple HC compression test */
DISPLAYLEVEL(3, " Simple HC round-trip : ");
{ U64 const crc64 = XXH64(testInput, testCompressedSize, 0);
- LZ4_resetStreamHC(&sHC, compressionLevel);
+ LZ4_setCompressionLevel(&sHC, compressionLevel);
result = LZ4_compress_HC_continue(&sHC, testInput, testCompressed, testCompressedSize, testCompressedSize-1);
FUZ_CHECKTEST(result==0, "LZ4_compressHC_limitedOutput_continue() compression failed");
FUZ_CHECKTEST(sHC.internal_donotuse.dirty, "Context should be clean");
@@ -1105,7 +1105,7 @@ static void FUZ_unitTests(int compressionLevel)
memset(block, 0, blockSize);
((char*)dstBlock)[targetSize] = sentinel;
- LZ4_resetStreamHC(&sHC, 3);
+ LZ4_resetStreamHC_fast(&sHC, 3);
assert(blockSize < INT_MAX);
srcSize = (int)blockSize;
assert(targetSize < INT_MAX);
@@ -1114,7 +1114,7 @@ static void FUZ_unitTests(int compressionLevel)
FUZ_CHECKTEST(result!=4116, "LZ4_compress_HC_destSize() : compression must fill dstBuffer completely, but no more !");
FUZ_CHECKTEST(((char*)dstBlock)[targetSize] != sentinel, "LZ4_compress_HC_destSize()")
- LZ4_resetStreamHC(&sHC, 3); /* make sure the context is clean after the test */
+ LZ4_resetStreamHC_fast(&sHC, 3); /* make sure the context is clean after the test */
free(block);
free(dstBlock);
}