Add ability to strongly limit fuzzer test size with flag
This commit is contained in:
parent
f5e50519e0
commit
7ebf2de02d
@ -616,7 +616,7 @@ static size_t FUZ_randomLength(U32* seed, U32 maxLog)
|
|||||||
#define CHECK(cond, ...) if (cond) { DISPLAY("Error => "); DISPLAY(__VA_ARGS__); \
|
#define CHECK(cond, ...) if (cond) { DISPLAY("Error => "); DISPLAY(__VA_ARGS__); \
|
||||||
DISPLAY(" (seed %u, test nb %u) \n", seed, testNb); goto _output_error; }
|
DISPLAY(" (seed %u, test nb %u) \n", seed, testNb); goto _output_error; }
|
||||||
|
|
||||||
static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 const maxDurationS, double compressibility)
|
static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 const maxDurationS, double compressibility, int bigTests)
|
||||||
{
|
{
|
||||||
static const U32 maxSrcLog = 23;
|
static const U32 maxSrcLog = 23;
|
||||||
static const U32 maxSampleLog = 22;
|
static const U32 maxSampleLog = 22;
|
||||||
@ -636,6 +636,7 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 const maxD
|
|||||||
U32 coreSeed = seed, lseed = 0;
|
U32 coreSeed = seed, lseed = 0;
|
||||||
clock_t const startClock = clock();
|
clock_t const startClock = clock();
|
||||||
clock_t const maxClockSpan = maxDurationS * CLOCKS_PER_SEC;
|
clock_t const maxClockSpan = maxDurationS * CLOCKS_PER_SEC;
|
||||||
|
int const cLevelLimiter = bigTests ? 3 : 2;
|
||||||
|
|
||||||
/* allocation */
|
/* allocation */
|
||||||
cNoiseBuffer[0] = (BYTE*)malloc (srcBufferSize);
|
cNoiseBuffer[0] = (BYTE*)malloc (srcBufferSize);
|
||||||
@ -701,7 +702,12 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 const maxD
|
|||||||
crcOrig = XXH64(sampleBuffer, sampleSize, 0);
|
crcOrig = XXH64(sampleBuffer, sampleSize, 0);
|
||||||
|
|
||||||
/* compression tests */
|
/* compression tests */
|
||||||
{ unsigned const cLevel = (FUZ_rand(&lseed) % (ZSTD_maxCLevel() - (FUZ_highbit32((U32)sampleSize)/3))) + 1;
|
{
|
||||||
|
unsigned const cLevel =
|
||||||
|
(FUZ_rand(&lseed) %
|
||||||
|
(ZSTD_maxCLevel() -
|
||||||
|
(FUZ_highbit32((U32)sampleSize) / cLevelLimiter))) +
|
||||||
|
1;
|
||||||
cSize = ZSTD_compressCCtx(ctx, cBuffer, cBufferSize, sampleBuffer, sampleSize, cLevel);
|
cSize = ZSTD_compressCCtx(ctx, cBuffer, cBufferSize, sampleBuffer, sampleSize, cLevel);
|
||||||
CHECK(ZSTD_isError(cSize), "ZSTD_compressCCtx failed : %s", ZSTD_getErrorName(cSize));
|
CHECK(ZSTD_isError(cSize), "ZSTD_compressCCtx failed : %s", ZSTD_getErrorName(cSize));
|
||||||
|
|
||||||
@ -801,7 +807,10 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 const maxD
|
|||||||
|
|
||||||
{ U32 const testLog = FUZ_rand(&lseed) % maxSrcLog;
|
{ U32 const testLog = FUZ_rand(&lseed) % maxSrcLog;
|
||||||
U32 const dictLog = FUZ_rand(&lseed) % maxSrcLog;
|
U32 const dictLog = FUZ_rand(&lseed) % maxSrcLog;
|
||||||
int const cLevel = (FUZ_rand(&lseed) % (ZSTD_maxCLevel() - (MAX(testLog, dictLog)/3))) + 1;
|
int const cLevel = (FUZ_rand(&lseed) %
|
||||||
|
(ZSTD_maxCLevel() -
|
||||||
|
(MAX(testLog, dictLog) / cLevelLimiter))) +
|
||||||
|
1;
|
||||||
maxTestSize = FUZ_rLogLength(&lseed, testLog);
|
maxTestSize = FUZ_rLogLength(&lseed, testLog);
|
||||||
if (maxTestSize >= dstBufferSize) maxTestSize = dstBufferSize-1;
|
if (maxTestSize >= dstBufferSize) maxTestSize = dstBufferSize-1;
|
||||||
|
|
||||||
@ -927,6 +936,7 @@ int main(int argc, const char** argv)
|
|||||||
int result=0;
|
int result=0;
|
||||||
U32 mainPause = 0;
|
U32 mainPause = 0;
|
||||||
U32 maxDuration = 0;
|
U32 maxDuration = 0;
|
||||||
|
int bigTests = 1;
|
||||||
const char* programName = argv[0];
|
const char* programName = argv[0];
|
||||||
|
|
||||||
/* Check command line */
|
/* Check command line */
|
||||||
@ -936,6 +946,9 @@ int main(int argc, const char** argv)
|
|||||||
|
|
||||||
/* Handle commands. Aggregated commands are allowed */
|
/* Handle commands. Aggregated commands are allowed */
|
||||||
if (argument[0]=='-') {
|
if (argument[0]=='-') {
|
||||||
|
|
||||||
|
if (!strcmp(argument, "--no-big-tests")) { bigTests=0; continue; }
|
||||||
|
|
||||||
argument++;
|
argument++;
|
||||||
while (*argument!=0) {
|
while (*argument!=0) {
|
||||||
switch(*argument)
|
switch(*argument)
|
||||||
@ -1030,7 +1043,7 @@ int main(int argc, const char** argv)
|
|||||||
if (testNb==0)
|
if (testNb==0)
|
||||||
result = basicUnitTests(0, ((double)proba) / 100); /* constant seed for predictability */
|
result = basicUnitTests(0, ((double)proba) / 100); /* constant seed for predictability */
|
||||||
if (!result)
|
if (!result)
|
||||||
result = fuzzerTests(seed, nbTests, testNb, maxDuration, ((double)proba) / 100);
|
result = fuzzerTests(seed, nbTests, testNb, maxDuration, ((double)proba) / 100, bigTests);
|
||||||
if (mainPause) {
|
if (mainPause) {
|
||||||
int unused;
|
int unused;
|
||||||
DISPLAY("Press Enter \n");
|
DISPLAY("Press Enter \n");
|
||||||
|
@ -552,7 +552,7 @@ static size_t FUZ_randomLength(U32* seed, U32 maxLog)
|
|||||||
#define CHECK(cond, ...) if (cond) { DISPLAY("Error => "); DISPLAY(__VA_ARGS__); \
|
#define CHECK(cond, ...) if (cond) { DISPLAY("Error => "); DISPLAY(__VA_ARGS__); \
|
||||||
DISPLAY(" (seed %u, test nb %u) \n", seed, testNb); goto _output_error; }
|
DISPLAY(" (seed %u, test nb %u) \n", seed, testNb); goto _output_error; }
|
||||||
|
|
||||||
static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibility)
|
static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibility, int bigTests)
|
||||||
{
|
{
|
||||||
static const U32 maxSrcLog = 24;
|
static const U32 maxSrcLog = 24;
|
||||||
static const U32 maxSampleLog = 19;
|
static const U32 maxSampleLog = 19;
|
||||||
@ -574,6 +574,7 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compres
|
|||||||
const BYTE* dict=NULL; /* can keep same dict on 2 consecutive tests */
|
const BYTE* dict=NULL; /* can keep same dict on 2 consecutive tests */
|
||||||
size_t dictSize = 0;
|
size_t dictSize = 0;
|
||||||
U32 oldTestLog = 0;
|
U32 oldTestLog = 0;
|
||||||
|
int const cLevelLimiter = bigTests ? 3 : 2;
|
||||||
|
|
||||||
/* allocations */
|
/* allocations */
|
||||||
cNoiseBuffer[0] = (BYTE*)malloc (srcBufferSize);
|
cNoiseBuffer[0] = (BYTE*)malloc (srcBufferSize);
|
||||||
@ -646,7 +647,10 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compres
|
|||||||
} else {
|
} else {
|
||||||
U32 const testLog = FUZ_rand(&lseed) % maxSrcLog;
|
U32 const testLog = FUZ_rand(&lseed) % maxSrcLog;
|
||||||
U32 const dictLog = FUZ_rand(&lseed) % maxSrcLog;
|
U32 const dictLog = FUZ_rand(&lseed) % maxSrcLog;
|
||||||
U32 const cLevel = (FUZ_rand(&lseed) % (ZSTD_maxCLevel() - (MAX(testLog, dictLog)/3))) + 1;
|
U32 const cLevel = (FUZ_rand(&lseed) %
|
||||||
|
(ZSTD_maxCLevel() -
|
||||||
|
(MAX(testLog, dictLog) / cLevelLimiter))) +
|
||||||
|
1;
|
||||||
maxTestSize = FUZ_rLogLength(&lseed, testLog);
|
maxTestSize = FUZ_rLogLength(&lseed, testLog);
|
||||||
oldTestLog = testLog;
|
oldTestLog = testLog;
|
||||||
/* random dictionary selection */
|
/* random dictionary selection */
|
||||||
@ -785,7 +789,7 @@ _output_error:
|
|||||||
|
|
||||||
|
|
||||||
/* Multi-threading version of fuzzer Tests */
|
/* Multi-threading version of fuzzer Tests */
|
||||||
static int fuzzerTests_MT(U32 seed, U32 nbTests, unsigned startTest, double compressibility)
|
static int fuzzerTests_MT(U32 seed, U32 nbTests, unsigned startTest, double compressibility, int bigTests)
|
||||||
{
|
{
|
||||||
static const U32 maxSrcLog = 24;
|
static const U32 maxSrcLog = 24;
|
||||||
static const U32 maxSampleLog = 19;
|
static const U32 maxSampleLog = 19;
|
||||||
@ -807,6 +811,7 @@ static int fuzzerTests_MT(U32 seed, U32 nbTests, unsigned startTest, double comp
|
|||||||
const BYTE* dict=NULL; /* can keep same dict on 2 consecutive tests */
|
const BYTE* dict=NULL; /* can keep same dict on 2 consecutive tests */
|
||||||
size_t dictSize = 0;
|
size_t dictSize = 0;
|
||||||
U32 oldTestLog = 0;
|
U32 oldTestLog = 0;
|
||||||
|
int const cLevelLimiter = bigTests ? 3 : 2;
|
||||||
|
|
||||||
/* allocations */
|
/* allocations */
|
||||||
cNoiseBuffer[0] = (BYTE*)malloc (srcBufferSize);
|
cNoiseBuffer[0] = (BYTE*)malloc (srcBufferSize);
|
||||||
@ -888,7 +893,10 @@ static int fuzzerTests_MT(U32 seed, U32 nbTests, unsigned startTest, double comp
|
|||||||
} else {
|
} else {
|
||||||
U32 const testLog = FUZ_rand(&lseed) % maxSrcLog;
|
U32 const testLog = FUZ_rand(&lseed) % maxSrcLog;
|
||||||
U32 const dictLog = FUZ_rand(&lseed) % maxSrcLog;
|
U32 const dictLog = FUZ_rand(&lseed) % maxSrcLog;
|
||||||
U32 const cLevel = (FUZ_rand(&lseed) % (ZSTD_maxCLevel() - (MAX(testLog, dictLog)/3))) + 1;
|
U32 const cLevel = (FUZ_rand(&lseed) %
|
||||||
|
(ZSTD_maxCLevel() -
|
||||||
|
(MAX(testLog, dictLog) / cLevelLimiter))) +
|
||||||
|
1;
|
||||||
maxTestSize = FUZ_rLogLength(&lseed, testLog);
|
maxTestSize = FUZ_rLogLength(&lseed, testLog);
|
||||||
oldTestLog = testLog;
|
oldTestLog = testLog;
|
||||||
/* random dictionary selection */
|
/* random dictionary selection */
|
||||||
@ -1063,6 +1071,7 @@ int main(int argc, const char** argv)
|
|||||||
int result=0;
|
int result=0;
|
||||||
int mainPause = 0;
|
int mainPause = 0;
|
||||||
int mtOnly = 0;
|
int mtOnly = 0;
|
||||||
|
int bigTests = 1;
|
||||||
const char* const programName = argv[0];
|
const char* const programName = argv[0];
|
||||||
ZSTD_customMem const customMem = { allocFunction, freeFunction, NULL };
|
ZSTD_customMem const customMem = { allocFunction, freeFunction, NULL };
|
||||||
ZSTD_customMem const customNULL = { NULL, NULL, NULL };
|
ZSTD_customMem const customNULL = { NULL, NULL, NULL };
|
||||||
@ -1076,6 +1085,7 @@ int main(int argc, const char** argv)
|
|||||||
if (argument[0]=='-') {
|
if (argument[0]=='-') {
|
||||||
|
|
||||||
if (!strcmp(argument, "--mt")) { mtOnly=1; continue; }
|
if (!strcmp(argument, "--mt")) { mtOnly=1; continue; }
|
||||||
|
if (!strcmp(argument, "--no-big-tests")) { bigTests=0; continue; }
|
||||||
|
|
||||||
argument++;
|
argument++;
|
||||||
while (*argument!=0) {
|
while (*argument!=0) {
|
||||||
@ -1181,8 +1191,8 @@ int main(int argc, const char** argv)
|
|||||||
result = basicUnitTests(0, ((double)proba) / 100, customMem); /* use custom memory allocation functions */
|
result = basicUnitTests(0, ((double)proba) / 100, customMem); /* use custom memory allocation functions */
|
||||||
} }
|
} }
|
||||||
|
|
||||||
if (!result && !mtOnly) result = fuzzerTests(seed, nbTests, testNb, ((double)proba) / 100);
|
if (!result && !mtOnly) result = fuzzerTests(seed, nbTests, testNb, ((double)proba) / 100, bigTests);
|
||||||
if (!result) result = fuzzerTests_MT(seed, nbTests, testNb, ((double)proba) / 100);
|
if (!result) result = fuzzerTests_MT(seed, nbTests, testNb, ((double)proba) / 100, bigTests);
|
||||||
|
|
||||||
if (mainPause) {
|
if (mainPause) {
|
||||||
int unused;
|
int unused;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user