minor variable isolation

This commit is contained in:
Yann Collet
2016-04-01 15:48:48 +02:00
parent 9bb87e5995
commit 27caf2afca
7 changed files with 614 additions and 130 deletions
+36 -63
View File
@@ -1,6 +1,6 @@
/*
Fuzzer test tool for zstd_buffered
Copyright (C) Yann Collet 2105
Copyright (C) Yann Collet 2015-2016
GPL v2 License
@@ -19,11 +19,10 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
You can contact the author at :
- ZSTD source repository : https://github.com/Cyan4973/zstd
- ZSTD public forum : https://groups.google.com/forum/#!forum/lz4c
- ZSTD homepage : https://www.zstd.net/
*/
/**************************************
/*-************************************
* Compiler specific
**************************************/
#ifdef _MSC_VER /* Visual Studio */
@@ -33,7 +32,7 @@
#endif
/**************************************
/*-************************************
* Includes
**************************************/
#include <stdlib.h> /* free */
@@ -47,8 +46,8 @@
#include "xxhash.h" /* XXH64 */
/**************************************
Constants
/*-************************************
* Constants
**************************************/
#ifndef ZSTD_VERSION
# define ZSTD_VERSION ""
@@ -66,7 +65,7 @@ static const U32 prime2 = 2246822519U;
/**************************************
/*-************************************
* Display Macros
**************************************/
#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
@@ -83,7 +82,7 @@ static U32 g_displayTime = 0;
static U32 g_testTime = 0;
/*********************************************************
/*-*******************************************************
* Fuzzer functions
*********************************************************/
#define MAX(a,b) ((a)>(b)?(a):(b))
@@ -149,8 +148,7 @@ static int basicUnitTests(U32 seed, double compressibility)
CNBuffer = malloc(CNBufferSize);
compressedBuffer = malloc(compressedBufferSize);
decodedBuffer = malloc(decodedBufferSize);
if (!CNBuffer || !compressedBuffer || !decodedBuffer || !zc || !zd)
{
if (!CNBuffer || !compressedBuffer || !decodedBuffer || !zc || !zd) {
DISPLAY("Not enough memory, aborting\n");
goto _output_error;
}
@@ -183,11 +181,9 @@ static int basicUnitTests(U32 seed, double compressibility)
DISPLAYLEVEL(4, "OK \n");
/* check regenerated data is byte exact */
{
size_t i;
{ size_t i;
DISPLAYLEVEL(4, "test%3i : check decompressed result : ", testNb++);
for (i=0; i<CNBufferSize; i++)
{
for (i=0; i<CNBufferSize; i++) {
if (((BYTE*)decodedBuffer)[i] != ((BYTE*)CNBuffer)[i]) goto _output_error;;
}
DISPLAYLEVEL(4, "OK \n");
@@ -213,8 +209,7 @@ static size_t findDiff(const void* buf1, const void* buf2, size_t max)
const BYTE* b1 = (const BYTE*)buf1;
const BYTE* b2 = (const BYTE*)buf2;
size_t i;
for (i=0; i<max; i++)
{
for (i=0; i<max; i++) {
if (b1[i] != b2[i]) break;
}
return i;
@@ -228,7 +223,7 @@ static size_t findDiff(const void* buf1, const void* buf2, size_t max)
static const U32 maxSrcLog = 24;
static const U32 maxSampleLog = 19;
int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibility)
static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibility)
{
BYTE* cNoiseBuffer[5];
BYTE* srcBuffer;
@@ -276,8 +271,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
FUZ_rand(&coreSeed);
/* test loop */
for ( ; (testNb <= nbTests) || (FUZ_GetMilliSpan(startTime) < g_testTime); testNb++ )
{
for ( ; (testNb <= nbTests) || (FUZ_GetMilliSpan(startTime) < g_testTime); testNb++ ) {
size_t sampleSize, sampleStart;
const BYTE* dict;
size_t cSize, dictSize;
@@ -294,20 +288,15 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
lseed = coreSeed ^ prime1;
buffNb = FUZ_rand(&lseed) & 127;
if (buffNb & 7) buffNb=2; /* select buffer */
else
{
else {
buffNb >>= 3;
if (buffNb & 7)
{
if (buffNb & 7) {
const U32 tnb[2] = { 1, 3 };
buffNb = tnb[buffNb >> 3];
}
else
{
} else {
const U32 tnb[2] = { 0, 4 };
buffNb = tnb[buffNb >> 3];
}
}
} }
srcBuffer = cNoiseBuffer[buffNb];
/* Multi - segments compression test */
@@ -327,8 +316,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
totalTestSize = 0;
cSize = 0;
for (n=0; n<nbChunks; n++)
{
for (n=0; n<nbChunks; n++) {
sampleSizeLog = FUZ_rand(&lseed) % maxSampleLog;
sampleSize = (size_t)1 << sampleSizeLog;
sampleSize += FUZ_rand(&lseed) & (sampleSize-1);
@@ -349,8 +337,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
cSize += genSize;
totalTestSize += readSize;
if ((FUZ_rand(&lseed) & 15) == 0)
{
if ((FUZ_rand(&lseed) & 15) == 0) {
/* add a few random flushes operations, to mess around */
sampleSizeLog = FUZ_rand(&lseed) % maxSampleLog;
sampleSize = (size_t)1 << sampleSizeLog;
@@ -374,8 +361,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
ZBUFF_decompressInitDictionary(zd, dict, dictSize);
totalCSize = 0;
totalGenSize = 0;
while (totalCSize < cSize)
{
while (totalCSize < cSize) {
sampleSizeLog = FUZ_rand(&lseed) % maxSampleLog;
sampleSize = (size_t)1 << sampleSizeLog;
sampleSize += FUZ_rand(&lseed) & (sampleSize-1);
@@ -399,8 +385,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
/* noisy/erroneous src decompression test */
/* add some noise */
nbChunks = (FUZ_rand(&lseed) & 7) + 2;
for (n=0; n<nbChunks; n++)
{
for (n=0; n<nbChunks; n++) {
size_t cStart;
sampleSizeLog = FUZ_rand(&lseed) % maxSampleLog;
@@ -417,8 +402,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
ZBUFF_decompressInit(zd);
totalCSize = 0;
totalGenSize = 0;
while ( (totalCSize < cSize) && (totalGenSize < dstBufferSize) )
{
while ( (totalCSize < cSize) && (totalGenSize < dstBufferSize) ) {
sampleSizeLog = FUZ_rand(&lseed) % maxSampleLog;
sampleSize = (size_t)1 << sampleSizeLog;
sampleSize += FUZ_rand(&lseed) & (sampleSize-1);
@@ -431,8 +415,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
if (ZBUFF_isError(errorCode)) break; /* error correctly detected */
totalGenSize += genSize;
totalCSize += readSize;
}
}
} }
DISPLAY("\r%u fuzzer tests completed \n", testNb);
_cleanup:
@@ -454,7 +437,7 @@ _output_error:
}
/*********************************************************
/*-*******************************************************
* Command line
*********************************************************/
int FUZ_usage(char* programName)
@@ -488,19 +471,16 @@ int main(int argc, char** argv)
/* Check command line */
programName = argv[0];
for(argNb=1; argNb<argc; argNb++)
{
for(argNb=1; argNb<argc; argNb++) {
char* argument = argv[argNb];
if(!argument) continue; /* Protection if argument empty */
/* Handle commands. Aggregated commands are allowed */
if (argument[0]=='-')
{
if (argument[0]=='-') {
argument++;
while (*argument!=0)
{
while (*argument!=0) {
switch(*argument)
{
case 'h':
@@ -521,8 +501,7 @@ int main(int argc, char** argv)
case 'i':
argument++;
nbTests=0; g_testTime=0;
while ((*argument>='0') && (*argument<='9'))
{
while ((*argument>='0') && (*argument<='9')) {
nbTests *= 10;
nbTests += *argument - '0';
argument++;
@@ -532,8 +511,7 @@ int main(int argc, char** argv)
case 'T':
argument++;
nbTests=0; g_testTime=0;
while ((*argument>='0') && (*argument<='9'))
{
while ((*argument>='0') && (*argument<='9')) {
g_testTime *= 10;
g_testTime += *argument - '0';
argument++;
@@ -547,8 +525,7 @@ int main(int argc, char** argv)
argument++;
seed=0;
seedset=1;
while ((*argument>='0') && (*argument<='9'))
{
while ((*argument>='0') && (*argument<='9')) {
seed *= 10;
seed += *argument - '0';
argument++;
@@ -558,8 +535,7 @@ int main(int argc, char** argv)
case 't':
argument++;
testNb=0;
while ((*argument>='0') && (*argument<='9'))
{
while ((*argument>='0') && (*argument<='9')) {
testNb *= 10;
testNb += *argument - '0';
argument++;
@@ -569,8 +545,7 @@ int main(int argc, char** argv)
case 'P': /* compressibility % */
argument++;
proba=0;
while ((*argument>='0') && (*argument<='9'))
{
while ((*argument>='0') && (*argument<='9')) {
proba *= 10;
proba += *argument - '0';
argument++;
@@ -582,9 +557,7 @@ int main(int argc, char** argv)
default:
return FUZ_usage(programName);
}
}
}
}
} } }
/* Get Seed */
DISPLAY("Starting zstd_buffered tester (%i-bits, %s)\n", (int)(sizeof(size_t)*8), ZSTD_VERSION);
@@ -598,8 +571,8 @@ int main(int argc, char** argv)
if (testNb==0) result = basicUnitTests(0, ((double)proba) / 100); /* constant seed for predictability */
if (!result)
result = fuzzerTests(seed, nbTests, testNb, ((double)proba) / 100);
if (mainPause)
{
if (mainPause) {
int unused;
DISPLAY("Press Enter \n");
unused = getchar();