1
0
mirror of https://github.com/facebook/zstd.git synced 2025-09-02 15:41:31 +03:00

time-limited fuzzer tests

This commit is contained in:
Yann Collet
2015-12-04 17:25:26 +01:00
parent 417890cec2
commit 553cf6a926

View File

@@ -79,11 +79,13 @@ static const U32 prime2 = 2246822519U;
static U32 g_displayLevel = 2; static U32 g_displayLevel = 2;
#define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ #define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \
if ((FUZ_GetMilliSpan(g_time) > g_refreshRate) || (g_displayLevel>=4)) \ if ((FUZ_GetMilliSpan(g_displayTime) > g_refreshRate) || (g_displayLevel>=4)) \
{ g_time = FUZ_GetMilliStart(); DISPLAY(__VA_ARGS__); \ { g_displayTime = FUZ_GetMilliStart(); DISPLAY(__VA_ARGS__); \
if (g_displayLevel>=4) fflush(stdout); } } if (g_displayLevel>=4) fflush(stdout); } }
static const U32 g_refreshRate = 150; static const U32 g_refreshRate = 150;
static U32 g_time = 0; static U32 g_displayTime = 0;
static U32 g_testTime = 0;
/********************************************************* /*********************************************************
@@ -266,6 +268,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
U32 testNb = 0; U32 testNb = 0;
U32 coreSeed = seed, lseed = 0; U32 coreSeed = seed, lseed = 0;
ZSTD_CCtx* ctx; ZSTD_CCtx* ctx;
U32 startTime = FUZ_GetMilliStart();
/* allocation */ /* allocation */
ctx = ZSTD_createCCtx(); ctx = ZSTD_createCCtx();
@@ -292,7 +295,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
FUZ_rand(&coreSeed); FUZ_rand(&coreSeed);
/* test loop */ /* test loop */
for ( ; testNb <= nbTests; testNb++ ) for ( ; (testNb <= nbTests) || (FUZ_GetMilliSpan(startTime) < g_testTime); testNb++ )
{ {
size_t sampleSize, sampleStart, maxTestSize, totalTestSize; size_t sampleSize, sampleStart, maxTestSize, totalTestSize;
size_t cSize, dSize, dSupSize, errorCode; size_t cSize, dSize, dSupSize, errorCode;
@@ -303,7 +306,9 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
BYTE* sampleBuffer; BYTE* sampleBuffer;
/* init */ /* init */
DISPLAYUPDATE(2, "\r%6u/%6u ", testNb, nbTests); DISPLAYUPDATE(2, "\r%6u", testNb);
if (nbTests >= testNb) DISPLAYUPDATE(2, "\r/%6u", nbTests);
DISPLAYUPDATE(2, " ");
FUZ_rand(&coreSeed); FUZ_rand(&coreSeed);
lseed = coreSeed ^ prime1; lseed = coreSeed ^ prime1;
buffNb = FUZ_rand(&lseed) & 127; buffNb = FUZ_rand(&lseed) & 127;
@@ -466,7 +471,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
cSize += errorCode; cSize += errorCode;
crcOrig = XXH64_digest(&crc64); crcOrig = XXH64_digest(&crc64);
} }
DISPLAY("\rAll fuzzer tests completed \n"); DISPLAY("\r%u fuzzer tests completed \n", testNb);
_cleanup: _cleanup:
ZSTD_freeCCtx(ctx); ZSTD_freeCCtx(ctx);
@@ -550,7 +555,7 @@ int main(int argc, char** argv)
break; break;
case 'i': case 'i':
argument++; argument++; g_testTime=0;
nbTests=0; nbTests=0;
while ((*argument>='0') && (*argument<='9')) while ((*argument>='0') && (*argument<='9'))
{ {
@@ -560,6 +565,20 @@ int main(int argc, char** argv)
} }
break; break;
case 'T':
argument++;
nbTests=0; g_testTime=0;
while ((*argument>='0') && (*argument<='9'))
{
g_testTime *= 10;
g_testTime += *argument - '0';
argument++;
}
if (*argument=='m') g_testTime *=60, argument++;
if (*argument=='n') argument++;
g_testTime *= 1000;
break;
case 's': case 's':
argument++; argument++;
seed=0; seed=0;