Skip to content

Commit

Permalink
removed ftime() from fuzzers
Browse files Browse the repository at this point in the history
as it's deprecated.

replaced by C90's clock()
  • Loading branch information
Cyan4973 committed Jul 17, 2020
1 parent 70e4295 commit 3865a70
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 51 deletions.
24 changes: 7 additions & 17 deletions programs/fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ You can contact the author at :
#include <stdlib.h> /* malloc, abs */
#include <stdio.h> /* printf */
#include <string.h> /* memset */
#include <sys/timeb.h> /* timeb */
#include <time.h> /* clock_t */
#include "mem.h"
#include "hist.h"
#define FSE_STATIC_LINKING_ONLY
Expand Down Expand Up @@ -69,22 +69,12 @@ static unsigned displayLevel = 2; // 0 : no display // 1: errors // 2 : + re
/***************************************************
* local functions
***************************************************/
static int FUZ_GetMilliStart(void)
{
struct timeb tb;
int nCount;
ftime ( &tb );
nCount = (int) (tb.millitm + (tb.time & 0xfffff) * 1000);
return nCount;
}

static clock_t FUZ_GetMilliStart(void) { return clock(); }

static int FUZ_GetMilliSpan ( int nTimeStart )
static int FUZ_GetMilliSpan ( clock_t nTimeStart )
{
int nSpan = FUZ_GetMilliStart() - nTimeStart;
if ( nSpan < 0 )
nSpan += 0x100000 * 1000;
return nSpan;
clock_t clockSpan = FUZ_GetMilliStart() - nTimeStart;
return (int)((U64)(clockSpan) * 1000 / CLOCKS_PER_SEC);
}


Expand Down Expand Up @@ -162,7 +152,7 @@ static void FUZ_tests (U32 seed, U32 totalTest, U32 startTestNb)
unsigned testNb, maxSV, tableLog;
const size_t maxTestSizeMask = 0x1FFFF;
U32 rootSeed = seed;
U32 time = FUZ_GetMilliStart();
clock_t time = FUZ_GetMilliStart();

generateNoise (bufferP0, BUFFERSIZE, &rootSeed);
generate (bufferP1 , BUFFERSIZE, 0.01, &rootSeed);
Expand Down Expand Up @@ -491,7 +481,7 @@ int main (int argc, char** argv)
U32 seed, startTestNb=0, pause=0, totalTest = FUZ_NB_TESTS;
int argNb;

seed = FUZ_GetMilliStart() % 10000;
seed = (U32)(FUZ_GetMilliStart() % 10000);
DISPLAYLEVEL (1, "FSE (%2i bits) automated test\n", (int)sizeof(void*)*8);
for (argNb=1; argNb<argc; argNb++)
{
Expand Down
24 changes: 7 additions & 17 deletions programs/fuzzerHuff0.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ You can contact the author at :
#include <stdlib.h> /* malloc, abs */
#include <stdio.h> /* printf */
#include <string.h> /* memset */
#include <sys/timeb.h> /* timeb */
#include <time.h> /* clock */
#include "mem.h"
#define HUF_STATIC_LINKING_ONLY
#include "huf.h"
Expand Down Expand Up @@ -65,22 +65,12 @@ static unsigned displayLevel = 2; /* 0 : no display; 1: errors; 2 : + result +
/*-*************************************************
* local functions
***************************************************/
static int FUZ_GetMilliStart(void)
{
struct timeb tb;
int nCount;
ftime ( &tb );
nCount = (int) (tb.millitm + (tb.time & 0xfffff) * 1000);
return nCount;
}

static clock_t FUZ_GetMilliStart(void) { return clock(); }

static int FUZ_GetMilliSpan ( int nTimeStart )
static int FUZ_GetMilliSpan ( clock_t nTimeStart )
{
int nSpan = FUZ_GetMilliStart() - nTimeStart;
if ( nSpan < 0 )
nSpan += 0x100000 * 1000;
return nSpan;
clock_t clockSpan = FUZ_GetMilliStart() - nTimeStart;
return (int)((U64)(clockSpan) * 1000 / CLOCKS_PER_SEC);
}


Expand Down Expand Up @@ -157,7 +147,7 @@ static void FUZ_tests (U32 seed, U32 totalTest, U32 startTestNb)
unsigned testNb;
size_t const maxTestSizeMask = 0x1FFFF; /* 128 KB - 1 */
U32 rootSeed = seed;
U32 time = FUZ_GetMilliStart();
clock_t time = FUZ_GetMilliStart();

generateNoise (bufferP0, BUFFERSIZE, &rootSeed);
generate (bufferP1 , BUFFERSIZE, 0.01, &rootSeed);
Expand Down Expand Up @@ -321,7 +311,7 @@ int main (int argc, const char** argv)
U32 seed, startTestNb=0, pause=0, totalTest = FUZ_NB_TESTS;
int argNb;

seed = FUZ_GetMilliStart() % 10000;
seed = (U32)(FUZ_GetMilliStart() % 10000);
DISPLAYLEVEL (1, "HUF (%2i bits) automated test\n", (int)sizeof(void*)*8);
for (argNb=1; argNb<argc; argNb++) {
const char* argument = argv[argNb];
Expand Down
24 changes: 7 additions & 17 deletions programs/fuzzerU16.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <stdlib.h> /* malloc, abs */
#include <stdio.h> /* printf */
#include <string.h> /* memset */
#include <sys/timeb.h> /* timeb */
#include <time.h> /* clock */
#include "fse.h" /* FSE_isError */
#include "fseU16.h"
#include "xxhash.h"
Expand Down Expand Up @@ -88,22 +88,12 @@ static unsigned displayLevel = 2; /* 0: no display; 1: errors; 2: + result +
/*-*************************************************
* Local functions
***************************************************/
static int FUZ_GetMilliStart(void)
{
struct timeb tb;
int nCount;
ftime ( &tb );
nCount = (int) (tb.millitm + (tb.time & 0xfffff) * 1000);
return nCount;
}

static clock_t FUZ_GetMilliStart(void) { return clock(); }

static int FUZ_GetMilliSpan ( int nTimeStart )
static int FUZ_GetMilliSpan ( clock_t nTimeStart )
{
int nSpan = FUZ_GetMilliStart() - nTimeStart;
if ( nSpan < 0 )
nSpan += 0x100000 * 1000;
return nSpan;
clock_t clockSpan = FUZ_GetMilliStart() - nTimeStart;
return (int)((U64)(clockSpan) * 1000 / CLOCKS_PER_SEC);
}


Expand Down Expand Up @@ -160,7 +150,7 @@ static void FUZ_tests (const U32 startSeed, U32 totalTest, U32 startTestNb)
void* const bufferDst = malloc (bufferDstSize);
U16* const bufferVerif = (U16*) malloc (bufferDstSize);
const size_t maxTestSizeMask = 0x1FFFF;
U32 time = FUZ_GetMilliStart();
clock_t time = FUZ_GetMilliStart();
U32 seed = startSeed;
unsigned testNb;

Expand Down Expand Up @@ -301,7 +291,7 @@ int main (int argc, const char** argv)
U32 startTestNb=0, pause=0, totalTest = FUZ_NB_TESTS;
int argNb;

U32 seed = FUZ_GetMilliStart() % 10000;
U32 seed = (U32)(FUZ_GetMilliStart() % 10000);
DISPLAYLEVEL(1, "FSE U16 (%2i bits) automated test\n",(int)sizeof(void*)*8);
for (argNb=1; argNb<argc; argNb++) {
const char* argument = argv[argNb];
Expand Down

0 comments on commit 3865a70

Please sign in to comment.