From: Yann Collet Date: Fri, 8 Apr 2016 13:25:32 +0000 (+0200) Subject: converted fuzzer timer to clock_t X-Git-Tag: v0.6.0^2~17^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea63bb7b5e41db6143905e7c8a0ff2385a2ff677;p=thirdparty%2Fzstd.git converted fuzzer timer to clock_t --- diff --git a/lib/zstd_compress.c b/lib/zstd_compress.c index 2a1bd4e18..a713acce4 100644 --- a/lib/zstd_compress.c +++ b/lib/zstd_compress.c @@ -1655,8 +1655,7 @@ void ZSTD_compressBlock_lazy_generic(ZSTD_CCtx* ctx, /* init */ U32 rep[ZSTD_REP_INIT]; - for (U32 i=0; inextToUpdate3 = ctx->nextToUpdate; ZSTD_resetSeqStore(seqStorePtr); @@ -1818,8 +1817,7 @@ void ZSTD_compressBlock_lazy_extDict_generic(ZSTD_CCtx* ctx, /* init */ U32 rep[ZSTD_REP_INIT]; - for (U32 i=0; inextToUpdate3 = ctx->nextToUpdate; ZSTD_resetSeqStore(seqStorePtr); diff --git a/lib/zstd_opt.h b/lib/zstd_opt.h index 4f6e4c8e9..5f4d4a624 100644 --- a/lib/zstd_opt.h +++ b/lib/zstd_opt.h @@ -224,7 +224,7 @@ U32 ZSTD_insertAndFindFirstIndexHash3 (ZSTD_CCtx* zc, const BYTE* ip) U32 idx = zc->nextToUpdate3; const U32 target = zc->nextToUpdate3 = (U32)(ip - base); const size_t hash3 = ZSTD_hash3Ptr(ip, hashLog3); - + while(idx < target) { hashTable3[ZSTD_hash3Ptr(base+idx, hashLog3)] = idx; idx++; @@ -446,8 +446,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx, /* init */ U32 rep[ZSTD_REP_INIT]; - for (U32 i=0; inextToUpdate3 = ctx->nextToUpdate; ZSTD_resetSeqStore(seqStorePtr); @@ -469,7 +468,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx, opt[0].litlen = (U32)(ip - litstart); /* check repCode */ - for (U32 i=0; i= minMatch); - } + } } match_num = ZSTD_BtGetAllMatches_selectMLS(ctx, ip, iend, maxSearches, mls, matches); /* first search (depth 0) */ ZSTD_LOG_PARSER("%d: match_num=%d last_pos=%d\n", (int)(ip-base), match_num, last_pos); if (!last_pos && !match_num) { ip++; continue; } - for (U32 i=0; i sufficient_len) { @@ -563,7 +561,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx, ZSTD_LOG_PARSER("%d: CURRENT_NoExt price[%d/%d]=%d off=%d mlen=%d litlen=%d rep[0]=%d rep[1]=%d\n", (int)(inr-base), cur, last_pos, opt[cur].price, opt[cur].off, opt[cur].mlen, opt[cur].litlen, opt[cur].rep[0], opt[cur].rep[1]); best_mlen = 0; - for (U32 i=0; i= minMatch); - } + } } match_num = ZSTD_BtGetAllMatches_selectMLS(ctx, inr, iend, maxSearches, mls, matches); @@ -746,8 +744,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx, /* init */ U32 rep[ZSTD_REP_INIT]; - for (U32 i=0; inextToUpdate3 = ctx->nextToUpdate; ZSTD_resetSeqStore(seqStorePtr); @@ -770,7 +767,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx, opt[0].litlen = (U32)(ip - litstart); /* check repCode */ - for (U32 i=0; i= minMatch); - } } + } } } match_num = ZSTD_BtGetAllMatches_selectMLS_extDict(ctx, ip, iend, maxSearches, mls, matches); /* first search (depth 0) */ ZSTD_LOG_PARSER("%d: match_num=%d last_pos=%d\n", (int)(ip-base), match_num, last_pos); if (!last_pos && !match_num) { ip++; continue; } - for (U32 i=0; i sufficient_len) { @@ -872,7 +868,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx, ZSTD_LOG_PARSER("%d: CURRENT_Ext price[%d/%d]=%d off=%d mlen=%d litlen=%d rep[0]=%d rep[1]=%d\n", (int)(inr-base), cur, last_pos, opt[cur].price, opt[cur].off, opt[cur].mlen, opt[cur].litlen, opt[cur].rep[0], opt[cur].rep[1]); best_mlen = 0; - for (U32 i=0; i= minMatch); - } } + } } } match_num = ZSTD_BtGetAllMatches_selectMLS_extDict(ctx, inr, iend, maxSearches, mls, matches); ZSTD_LOG_PARSER("%d: ZSTD_GetAllMatches match_num=%d\n", (int)(inr-base), match_num); diff --git a/programs/fuzzer.c b/programs/fuzzer.c index 29bf4861d..4c78b4579 100644 --- a/programs/fuzzer.c +++ b/programs/fuzzer.c @@ -39,6 +39,7 @@ #include /* fgets, sscanf */ #include /* timeb */ #include /* strcmp */ +#include /* clock_t */ #include "zstd_static.h" #include "datagen.h" /* RDG_genBuffer */ #include "xxhash.h" /* XXH64 */ @@ -69,11 +70,11 @@ static const U32 nbTestsDefault = 30000; static U32 g_displayLevel = 2; #define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ - if ((FUZ_GetMilliSpan(g_displayTime) > g_refreshRate) || (g_displayLevel>=4)) \ - { g_displayTime = FUZ_GetMilliStart(); DISPLAY(__VA_ARGS__); \ + if ((FUZ_clockSpan(g_displayClock) > g_refreshRate) || (g_displayLevel>=4)) \ + { g_displayClock = clock(); DISPLAY(__VA_ARGS__); \ if (g_displayLevel>=4) fflush(stdout); } } -static const U32 g_refreshRate = 150; -static U32 g_displayTime = 0; +static const clock_t g_refreshRate = CLOCKS_PER_SEC * 150 / 1000; +static clock_t g_displayClock = 0; /*-******************************************************* @@ -82,23 +83,9 @@ static U32 g_displayTime = 0; #define MIN(a,b) ((a)<(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b)) -static U32 FUZ_GetMilliStart(void) +static clock_t FUZ_clockSpan(clock_t cStart) { - struct timeb tb; - U32 nCount; - ftime( &tb ); - nCount = (U32) (((tb.time & 0xFFFFF) * 1000) + tb.millitm); - return nCount; -} - - -static U32 FUZ_GetMilliSpan(U32 nTimeStart) -{ - U32 nCurrent = FUZ_GetMilliStart(); - U32 nSpan = nCurrent - nTimeStart; - if (nTimeStart > nCurrent) - nSpan += 0x100000 * 1000; - return nSpan; + return clock() - cStart; /* works even when overflow; max span ~ 30mn */ } @@ -392,7 +379,7 @@ static size_t findDiff(const void* buf1, const void* buf2, size_t max) static const U32 maxSrcLog = 23; static const U32 maxSampleLog = 22; -int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 maxDuration, double compressibility) +static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 const maxDurationS, double compressibility) { BYTE* cNoiseBuffer[5]; BYTE* srcBuffer; @@ -408,7 +395,8 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 maxDuration, doub ZSTD_CCtx* refCtx; ZSTD_CCtx* ctx; ZSTD_DCtx* dctx; - U32 startTime = FUZ_GetMilliStart(); + clock_t startClock = clock(); + clock_t const maxClockSpan = maxDurationS * CLOCKS_PER_SEC; /* allocation */ refCtx = ZSTD_createCCtx(); @@ -438,7 +426,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 maxDuration, doub for (testNb=1; testNb < startTest; testNb++) FUZ_rand(&coreSeed); /* main test loop */ - for ( ; (testNb <= nbTests) || (FUZ_GetMilliSpan(startTime) < maxDuration); testNb++ ) { + for ( ; (testNb <= nbTests) || (FUZ_clockSpan(startClock) < maxClockSpan); testNb++ ) { size_t sampleSize, sampleStart, maxTestSize, totalTestSize; size_t cSize, dSize, errorCode, totalCSize, totalGenSize; U32 sampleSizeLog, buffNb, cLevelMod, nbChunks, n; @@ -526,8 +514,8 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 maxDuration, doub /* too small dst decompression test */ if (sampleSize > 3) { - const size_t missing = (FUZ_rand(&lseed) % (sampleSize-2)) + 1; /* no problem, as cSize > 4 (frameHeaderSizer) */ - const size_t tooSmallSize = sampleSize - missing; + size_t const missing = (FUZ_rand(&lseed) % (sampleSize-2)) + 1; /* no problem, as cSize > 4 (frameHeaderSizer) */ + size_t const tooSmallSize = sampleSize - missing; static const BYTE token = 0xA9; dstBuffer[tooSmallSize] = token; errorCode = ZSTD_decompress(dstBuffer, tooSmallSize, cBuffer, cSize); @@ -568,10 +556,10 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 maxDuration, doub CHECK((!ZSTD_isError(errorCode)) && (errorCode>sampleSize), "ZSTD_decompress on noisy src : result is too large : %u > %u (dst buffer)", (U32)errorCode, (U32)sampleSize); { U32 endCheck; memcpy(&endCheck, dstBuffer+sampleSize, 4); - CHECK(endMark!=endCheck, "ZSTD_decompress on noisy src : dst buffer overflow"); } + CHECK(endMark!=endCheck, "ZSTD_decompress on noisy src : dst buffer overflow"); } } } /* noisy src decompression test */ - /* Streaming compression of scattered segments test */ + /* Streaming compression test, scattered segments and dictionary */ XXH64_reset(xxh64, 0); nbChunks = (FUZ_rand(&lseed) & 127) + 2; sampleSizeLog = FUZ_rand(&lseed) % maxSrcLog; @@ -689,10 +677,9 @@ int main(int argc, const char** argv) int result=0; U32 mainPause = 0; U32 maxDuration = 0; - const char* programName; + const char* programName = argv[0]; /* Check command line */ - programName = argv[0]; for (argNb=1; argNb