fuzzer : easier random replay

This commit is contained in:
Yann Collet 2014-10-19 16:06:33 +01:00
parent f91d5aae79
commit d618673057

View File

@ -96,12 +96,6 @@ static const U32 g_refreshRate = 250;
static U32 g_time = 0; static U32 g_time = 0;
/*****************************************
Unit Variables
*****************************************/
static char* programName = NULL;
/********************************************************* /*********************************************************
Fuzzer functions Fuzzer functions
*********************************************************/ *********************************************************/
@ -290,7 +284,6 @@ static int FUZ_test(U32 seed, int nbCycles, int startCycle, double compressibili
char* compressedBuffer; char* compressedBuffer;
char* decodedBuffer; char* decodedBuffer;
# define FUZ_max LZ4_COMPRESSBOUND(LEN) # define FUZ_max LZ4_COMPRESSBOUND(LEN)
unsigned int randState=seed;
int ret, cycleNb; int ret, cycleNb;
# define FUZ_CHECKTEST(cond, ...) if (cond) { printf("Test %i : ", testNb); printf(__VA_ARGS__); \ # define FUZ_CHECKTEST(cond, ...) if (cond) { printf("Test %i : ", testNb); printf(__VA_ARGS__); \
printf(" (seed %u, cycle %i) \n", seed, cycleNb); goto _output_error; } printf(" (seed %u, cycle %i) \n", seed, cycleNb); goto _output_error; }
@ -300,6 +293,8 @@ static int FUZ_test(U32 seed, int nbCycles, int startCycle, double compressibili
void* LZ4continue; void* LZ4continue;
LZ4_stream_t LZ4dict; LZ4_stream_t LZ4dict;
U32 crcOrig, crcCheck; U32 crcOrig, crcCheck;
U32 coreRandState = seed;
U32 randState = coreRandState ^ PRIME3;
// init // init
@ -319,16 +314,18 @@ static int FUZ_test(U32 seed, int nbCycles, int startCycle, double compressibili
char* dict; char* dict;
char* block; char* block;
FUZ_displayUpdate(cycleNb); (void)FUZ_rand(&coreRandState);
if (0) // some problems related to dictionary re-use; in this case, enable this loop
{
FUZ_displayUpdate(cycleNb);
randState = coreRandState ^ PRIME3;
blockSize = FUZ_rand(&randState) % FUZ_MAX_BLOCK_SIZE; blockSize = FUZ_rand(&randState) % FUZ_MAX_BLOCK_SIZE;
blockStart = FUZ_rand(&randState) % (COMPRESSIBLE_NOISE_LENGTH - blockSize); blockStart = FUZ_rand(&randState) % (COMPRESSIBLE_NOISE_LENGTH - blockSize);
dictSize = FUZ_rand(&randState) % FUZ_MAX_DICT_SIZE; dictSize = FUZ_rand(&randState) % FUZ_MAX_DICT_SIZE;
if (dictSize > blockStart) dictSize = blockStart; if (dictSize > blockStart) dictSize = blockStart;
block = ((char*)CNBuffer) + blockStart; block = ((char*)CNBuffer) + blockStart;
dict = block - dictSize; dict = block - dictSize;
if (0) // some problems related to dictionary re-use; in this case, enable this loop
{
LZ4_loadDict(&LZ4dict, dict, dictSize); LZ4_loadDict(&LZ4dict, dict, dictSize);
LZ4_compress_continue(&LZ4dict, block, compressedBuffer, blockSize); LZ4_compress_continue(&LZ4dict, block, compressedBuffer, blockSize);
LZ4_loadDict(&LZ4dict, dict, dictSize); LZ4_loadDict(&LZ4dict, dict, dictSize);
@ -348,6 +345,8 @@ static int FUZ_test(U32 seed, int nbCycles, int startCycle, double compressibili
int blockContinueCompressedSize; int blockContinueCompressedSize;
FUZ_displayUpdate(cycleNb); FUZ_displayUpdate(cycleNb);
(void)FUZ_rand(&coreRandState);
randState = coreRandState ^ PRIME3;
// Select block to test // Select block to test
blockSize = FUZ_rand(&randState) % FUZ_MAX_BLOCK_SIZE; blockSize = FUZ_rand(&randState) % FUZ_MAX_BLOCK_SIZE;
@ -717,13 +716,14 @@ static void FUZ_unitTests(void)
//FUZ_CHECKTEST(crcOrig!=crcNew, "LZ4_decompress_safe() dictionary decompression corruption"); //FUZ_CHECKTEST(crcOrig!=crcNew, "LZ4_decompress_safe() dictionary decompression corruption");
} }
printf("All unit tests completed succesfully \n");
return; return;
_output_error: _output_error:
exit(1); exit(1);
} }
static int FUZ_usage(void) static int FUZ_usage(char* programName)
{ {
DISPLAY( "Usage :\n"); DISPLAY( "Usage :\n");
DISPLAY( " %s [args]\n", programName); DISPLAY( " %s [args]\n", programName);
@ -749,9 +749,9 @@ int main(int argc, char** argv)
int testNb = 0; int testNb = 0;
int proba = FUZ_COMPRESSIBILITY_DEFAULT; int proba = FUZ_COMPRESSIBILITY_DEFAULT;
int pause = 0; int pause = 0;
char* programName = argv[0];
// Check command line // Check command line
programName = argv[0];
for(argNb=1; argNb<argc; argNb++) for(argNb=1; argNb<argc; argNb++)
{ {
char* argument = argv[argNb]; char* argument = argv[argNb];
@ -769,7 +769,7 @@ int main(int argc, char** argv)
switch(*argument) switch(*argument)
{ {
case 'h': /* display help */ case 'h': /* display help */
return FUZ_usage(); return FUZ_usage(programName);
case 'v': /* verbose mode */ case 'v': /* verbose mode */
argument++; argument++;