fuzzer: tests more compression levels
This commit is contained in:
parent
312d88249f
commit
d2b51c22d3
@ -63,7 +63,6 @@ typedef size_t uintptr_t; /* true on most systems, except OpenVMS-64 (which do
|
||||
#define FUZ_MAX_BLOCK_SIZE (1 << 17)
|
||||
#define FUZ_MAX_DICT_SIZE (1 << 15)
|
||||
#define FUZ_COMPRESSIBILITY_DEFAULT 60
|
||||
#define FUZ_CLEVEL_DEFAULT LZ4HC_CLEVEL_OPT_MIN
|
||||
#define PRIME1 2654435761U
|
||||
#define PRIME2 2246822519U
|
||||
#define PRIME3 3266489917U
|
||||
@ -304,6 +303,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
||||
int const blockStart = FUZ_rand(&randState) % (COMPRESSIBLE_NOISE_LENGTH - blockSize);
|
||||
int const dictSizeRand = FUZ_rand(&randState) % FUZ_MAX_DICT_SIZE;
|
||||
int const dictSize = MIN(dictSizeRand, blockStart);
|
||||
int const compressionLevel = FUZ_rand(&randState) % (LZ4HC_CLEVEL_MAX+1);
|
||||
char* const block = ((char*)CNBuffer) + blockStart;
|
||||
const char* dict = block - dictSize;
|
||||
int compressedSize, HCcompressedSize;
|
||||
@ -350,13 +350,13 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
||||
|
||||
/* Test compression HC */
|
||||
FUZ_DISPLAYTEST;
|
||||
ret = LZ4_compress_HC(block, compressedBuffer, blockSize, (int)compressedBufferSize, FUZ_CLEVEL_DEFAULT);
|
||||
ret = LZ4_compress_HC(block, compressedBuffer, blockSize, (int)compressedBufferSize, compressionLevel);
|
||||
FUZ_CHECKTEST(ret==0, "LZ4_compressHC() failed");
|
||||
HCcompressedSize = ret;
|
||||
|
||||
/* Test compression HC using external state */
|
||||
FUZ_DISPLAYTEST;
|
||||
ret = LZ4_compress_HC_extStateHC(stateLZ4HC, block, compressedBuffer, blockSize, (int)compressedBufferSize, FUZ_CLEVEL_DEFAULT);
|
||||
ret = LZ4_compress_HC_extStateHC(stateLZ4HC, block, compressedBuffer, blockSize, (int)compressedBufferSize, compressionLevel);
|
||||
FUZ_CHECKTEST(ret==0, "LZ4_compressHC_withStateHC() failed");
|
||||
|
||||
/* Test compression using external state */
|
||||
@ -467,12 +467,12 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
||||
|
||||
/* Test HC compression with output size being exactly what's necessary (should work) */
|
||||
FUZ_DISPLAYTEST;
|
||||
ret = LZ4_compress_HC(block, compressedBuffer, blockSize, HCcompressedSize, FUZ_CLEVEL_DEFAULT);
|
||||
ret = LZ4_compress_HC(block, compressedBuffer, blockSize, HCcompressedSize, compressionLevel);
|
||||
FUZ_CHECKTEST(ret==0, "LZ4_compressHC_limitedOutput() failed despite sufficient space");
|
||||
|
||||
/* Test HC compression with output size being exactly what's necessary (should work) */
|
||||
FUZ_DISPLAYTEST;
|
||||
ret = LZ4_compress_HC_extStateHC(stateLZ4HC, block, compressedBuffer, blockSize, HCcompressedSize, FUZ_CLEVEL_DEFAULT);
|
||||
ret = LZ4_compress_HC_extStateHC(stateLZ4HC, block, compressedBuffer, blockSize, HCcompressedSize, compressionLevel);
|
||||
FUZ_CHECKTEST(ret==0, "LZ4_compressHC_limitedOutput_withStateHC() failed despite sufficient space");
|
||||
|
||||
/* Test compression with missing bytes into output buffer => must fail */
|
||||
@ -492,7 +492,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
||||
if (missingBytes >= HCcompressedSize) missingBytes = HCcompressedSize-1;
|
||||
missingBytes += !missingBytes; /* avoid special case missingBytes==0 */
|
||||
compressedBuffer[HCcompressedSize-missingBytes] = 0;
|
||||
ret = LZ4_compress_HC(block, compressedBuffer, blockSize, HCcompressedSize-missingBytes, FUZ_CLEVEL_DEFAULT);
|
||||
ret = LZ4_compress_HC(block, compressedBuffer, blockSize, HCcompressedSize-missingBytes, compressionLevel);
|
||||
FUZ_CHECKTEST(ret, "LZ4_compressHC_limitedOutput should have failed (output buffer too small by %i byte)", missingBytes);
|
||||
FUZ_CHECKTEST(compressedBuffer[HCcompressedSize-missingBytes], "LZ4_compressHC_limitedOutput overran output buffer ! (%i missingBytes)", missingBytes)
|
||||
}
|
||||
@ -593,7 +593,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
||||
FUZ_DISPLAYTEST;
|
||||
dict -= (FUZ_rand(&randState) & 7); /* even bigger separation */
|
||||
if (dict < (char*)CNBuffer) dict = (char*)CNBuffer;
|
||||
LZ4_resetStreamHC (&LZ4dictHC, FUZ_rand(&randState) % (LZ4HC_CLEVEL_MAX+1));
|
||||
LZ4_resetStreamHC (&LZ4dictHC, compressionLevel);
|
||||
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
|
||||
blockContinueCompressedSize = LZ4_compress_HC_continue(&LZ4dictHC, block, compressedBuffer, blockSize, (int)compressedBufferSize);
|
||||
FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compressHC_continue failed");
|
||||
@ -656,7 +656,7 @@ _output_error:
|
||||
#define testCompressedSize (128 KB)
|
||||
#define ringBufferSize (8 KB)
|
||||
|
||||
static void FUZ_unitTests(void)
|
||||
static void FUZ_unitTests(int compressionLevel)
|
||||
{
|
||||
const unsigned testNb = 0;
|
||||
const unsigned seed = 0;
|
||||
@ -751,7 +751,7 @@ static void FUZ_unitTests(void)
|
||||
|
||||
/* simple HC compression test */
|
||||
crcOrig = XXH64(testInput, testCompressedSize, 0);
|
||||
LZ4_resetStreamHC(&sHC, 0);
|
||||
LZ4_resetStreamHC(&sHC, compressionLevel);
|
||||
result = LZ4_compress_HC_continue(&sHC, testInput, testCompressed, testCompressedSize, testCompressedSize-1);
|
||||
FUZ_CHECKTEST(result==0, "LZ4_compressHC_limitedOutput_continue() compression failed");
|
||||
|
||||
@ -762,7 +762,7 @@ static void FUZ_unitTests(void)
|
||||
|
||||
/* simple dictionary HC compression test */
|
||||
crcOrig = XXH64(testInput + 64 KB, testCompressedSize, 0);
|
||||
LZ4_resetStreamHC(&sHC, 0);
|
||||
LZ4_resetStreamHC(&sHC, compressionLevel);
|
||||
LZ4_loadDictHC(&sHC, testInput, 64 KB);
|
||||
result = LZ4_compress_HC_continue(&sHC, testInput + 64 KB, testCompressed, testCompressedSize, testCompressedSize-1);
|
||||
FUZ_CHECKTEST(result==0, "LZ4_compressHC_limitedOutput_continue() dictionary compression failed : result = %i", result);
|
||||
@ -776,7 +776,7 @@ static void FUZ_unitTests(void)
|
||||
{ int result1, result2;
|
||||
int segSize = testCompressedSize / 2;
|
||||
crcOrig = XXH64(testInput + segSize, testCompressedSize, 0);
|
||||
LZ4_resetStreamHC(&sHC, 0);
|
||||
LZ4_resetStreamHC(&sHC, compressionLevel);
|
||||
LZ4_loadDictHC(&sHC, testInput, segSize);
|
||||
result1 = LZ4_compress_HC_continue(&sHC, testInput + segSize, testCompressed, segSize, segSize -1);
|
||||
FUZ_CHECKTEST(result1==0, "LZ4_compressHC_limitedOutput_continue() dictionary compression failed : result = %i", result1);
|
||||
@ -793,7 +793,7 @@ static void FUZ_unitTests(void)
|
||||
|
||||
/* remote dictionary HC compression test */
|
||||
crcOrig = XXH64(testInput + 64 KB, testCompressedSize, 0);
|
||||
LZ4_resetStreamHC(&sHC, 0);
|
||||
LZ4_resetStreamHC(&sHC, compressionLevel);
|
||||
LZ4_loadDictHC(&sHC, testInput, 32 KB);
|
||||
result = LZ4_compress_HC_continue(&sHC, testInput + 64 KB, testCompressed, testCompressedSize, testCompressedSize-1);
|
||||
FUZ_CHECKTEST(result==0, "LZ4_compressHC_limitedOutput_continue() remote dictionary failed : result = %i", result);
|
||||
@ -814,7 +814,7 @@ static void FUZ_unitTests(void)
|
||||
int segSize = (FUZ_rand(&randState) & 8191);
|
||||
int segNb = 1;
|
||||
|
||||
LZ4_resetStreamHC(&sHC, 0);
|
||||
LZ4_resetStreamHC(&sHC, compressionLevel);
|
||||
LZ4_loadDictHC(&sHC, dict, dictSize);
|
||||
|
||||
XXH64_reset(&crcOrigState, 0);
|
||||
@ -860,7 +860,7 @@ static void FUZ_unitTests(void)
|
||||
|
||||
XXH64_reset(&xxhOrig, 0);
|
||||
XXH64_reset(&xxhNew, 0);
|
||||
LZ4_resetStreamHC(&sHC, 0);
|
||||
LZ4_resetStreamHC(&sHC, compressionLevel);
|
||||
LZ4_setStreamDecode(&decodeState, NULL, 0);
|
||||
|
||||
while (iNext + messageSize < testCompressedSize) {
|
||||
@ -902,7 +902,7 @@ static void FUZ_unitTests(void)
|
||||
|
||||
XXH64_reset(&xxhOrig, 0);
|
||||
XXH64_reset(&xxhNew, 0);
|
||||
LZ4_resetStreamHC(&sHC, 0);
|
||||
LZ4_resetStreamHC(&sHC, compressionLevel);
|
||||
LZ4_setStreamDecode(&decodeState, NULL, 0);
|
||||
|
||||
#define BSIZE1 65537
|
||||
@ -957,7 +957,7 @@ static void FUZ_unitTests(void)
|
||||
}
|
||||
}
|
||||
|
||||
printf("All unit tests completed successfully \n");
|
||||
printf("All unit tests completed successfully compressionLevel=%d \n", compressionLevel);
|
||||
return;
|
||||
_output_error:
|
||||
exit(1);
|
||||
@ -1103,7 +1103,7 @@ int main(int argc, const char** argv)
|
||||
|
||||
if (proba!=FUZ_COMPRESSIBILITY_DEFAULT) printf("Compressibility : %i%%\n", proba);
|
||||
|
||||
if ((seedset==0) && (testNb==0)) FUZ_unitTests();
|
||||
if ((seedset==0) && (testNb==0)) { FUZ_unitTests(LZ4HC_CLEVEL_DEFAULT); FUZ_unitTests(LZ4HC_CLEVEL_OPT_MIN); }
|
||||
|
||||
if (nbTests<=0) nbTests=1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user