added test case
This commit is contained in:
@@ -450,6 +450,7 @@ static int basicUnitTests(U32 seed, double compressibility)
|
||||
}
|
||||
DISPLAYLEVEL(3, "OK \n");
|
||||
|
||||
/* this test is really too long, and should be made faster */
|
||||
DISPLAYLEVEL(3, "test%3d : overflow protection with large windowLog : ", testNb++);
|
||||
{ ZSTD_CCtx* const cctx = ZSTD_createCCtx();
|
||||
ZSTD_parameters params = ZSTD_getParams(-9, ZSTD_CONTENTSIZE_UNKNOWN, 0);
|
||||
@@ -467,6 +468,40 @@ static int basicUnitTests(U32 seed, double compressibility)
|
||||
}
|
||||
DISPLAYLEVEL(3, "OK \n");
|
||||
|
||||
DISPLAYLEVEL(3, "test%3d : size down context : ", testNb++);
|
||||
{ ZSTD_CCtx* const largeCCtx = ZSTD_createCCtx();
|
||||
assert(largeCCtx != NULL);
|
||||
CHECK_Z( ZSTD_compressBegin(largeCCtx, 19) ); /* streaming implies ZSTD_CONTENTSIZE_UNKNOWN, which maximizes memory usage */
|
||||
CHECK_Z( ZSTD_compressEnd(largeCCtx, compressedBuffer, compressedBufferSize, CNBuffer, 1) );
|
||||
{ size_t const largeCCtxSize = ZSTD_sizeof_CCtx(largeCCtx); /* size of context must be measured after compression */
|
||||
{ ZSTD_CCtx* const smallCCtx = ZSTD_createCCtx();
|
||||
assert(smallCCtx != NULL);
|
||||
CHECK_Z(ZSTD_compressCCtx(smallCCtx, compressedBuffer, compressedBufferSize, CNBuffer, 1, 1));
|
||||
{ size_t const smallCCtxSize = ZSTD_sizeof_CCtx(smallCCtx);
|
||||
DISPLAYLEVEL(5, "(large) %zuKB > 32*%zuKB (small) : ",
|
||||
largeCCtxSize>>10, smallCCtxSize>>10);
|
||||
assert(largeCCtxSize > 32* smallCCtxSize); /* note : "too large" definition is handled within zstd_compress.c .
|
||||
* make this test case extreme, so that it doesn't depend on a possibly fluctuating definition */
|
||||
}
|
||||
ZSTD_freeCCtx(smallCCtx);
|
||||
}
|
||||
{ U32 const maxNbAttempts = 1100; /* nb of usages before triggering size down is handled within zstd_compress.c.
|
||||
* currently defined as 128x, but could be adjusted in the future.
|
||||
* make this test long enough so that it's not too much tied to the current definition within zstd_compress.c */
|
||||
U32 u;
|
||||
for (u=0; u<maxNbAttempts; u++) {
|
||||
size_t const srcSize = (FUZ_rand(&seed) & 4095) + 200;
|
||||
CHECK_Z(ZSTD_compressCCtx(largeCCtx, compressedBuffer, compressedBufferSize, CNBuffer, srcSize, -9));
|
||||
if (ZSTD_sizeof_CCtx(largeCCtx) < largeCCtxSize) break; /* sized down */
|
||||
}
|
||||
DISPLAYLEVEL(5, "size down after %u attempts : ", u);
|
||||
if (u==maxNbAttempts) goto _output_error; /* no sizedown happened */
|
||||
}
|
||||
}
|
||||
ZSTD_freeCCtx(largeCCtx);
|
||||
}
|
||||
DISPLAYLEVEL(3, "OK \n");
|
||||
|
||||
/* Static CCtx tests */
|
||||
#define STATIC_CCTX_LEVEL 3
|
||||
DISPLAYLEVEL(3, "test%3i : create static CCtx for level %u :", testNb++, STATIC_CCTX_LEVEL);
|
||||
|
||||
Reference in New Issue
Block a user