From dd026ca505fee886ccfd5d1c453ebe42d78f84fc Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 9 May 2020 11:30:45 -0700 Subject: [PATCH] re-inforced tests for initStaticCCtx ensure that `estimateCCtxSize()` works as intended. --- tests/fuzzer.c | 83 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 30 deletions(-) diff --git a/tests/fuzzer.c b/tests/fuzzer.c index c9cf85bdb..1983ae142 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -1066,11 +1066,12 @@ static int basicUnitTests(U32 const seed, double compressibility) /* Static CCtx tests */ #define STATIC_CCTX_LEVEL 3 - DISPLAYLEVEL(3, "test%3i : create static CCtx for level %u :", testNb++, STATIC_CCTX_LEVEL); - { size_t const staticCCtxSize = ZSTD_estimateCStreamSize(STATIC_CCTX_LEVEL); - void* const staticCCtxBuffer = malloc(staticCCtxSize); + DISPLAYLEVEL(3, "test%3i : create static CCtx for level %u : ", testNb++, STATIC_CCTX_LEVEL); + { size_t const staticCStreamSize = ZSTD_estimateCStreamSize(STATIC_CCTX_LEVEL); + void* const staticCCtxBuffer = malloc(staticCStreamSize); size_t const staticDCtxSize = ZSTD_estimateDCtxSize(); void* const staticDCtxBuffer = malloc(staticDCtxSize); + DISPLAYLEVEL(4, "CStream size = %u, ", (U32)staticCStreamSize); if (staticCCtxBuffer==NULL || staticDCtxBuffer==NULL) { free(staticCCtxBuffer); free(staticDCtxBuffer); @@ -1078,17 +1079,25 @@ static int basicUnitTests(U32 const seed, double compressibility) testResult = 1; goto _end; } - { ZSTD_CCtx* staticCCtx = ZSTD_initStaticCCtx(staticCCtxBuffer, staticCCtxSize); - ZSTD_DCtx* staticDCtx = ZSTD_initStaticDCtx(staticDCtxBuffer, staticDCtxSize); + { size_t const staticCCtxSize = ZSTD_estimateCCtxSize(STATIC_CCTX_LEVEL); + ZSTD_CCtx* staticCCtx = ZSTD_initStaticCCtx(staticCCtxBuffer, staticCCtxSize); + ZSTD_DCtx* const staticDCtx = ZSTD_initStaticDCtx(staticDCtxBuffer, staticDCtxSize); if ((staticCCtx==NULL) || (staticDCtx==NULL)) goto _output_error; + DISPLAYLEVEL(4, "CCtx size = %u, ", (U32)staticCCtxSize); DISPLAYLEVEL(3, "OK \n"); + DISPLAYLEVEL(3, "test%3i : compress immediately with static CCtx : ", testNb++); + CHECK_VAR(cSize, ZSTD_compressCCtx(staticCCtx, + compressedBuffer, compressedBufferSize, + CNBuffer, CNBuffSize, STATIC_CCTX_LEVEL) ); + DISPLAYLEVEL(3, "OK (%u bytes : %.2f%%)\n", + (unsigned)cSize, (double)cSize/CNBuffSize*100); + DISPLAYLEVEL(3, "test%3i : init CCtx for level %u : ", testNb++, STATIC_CCTX_LEVEL); - { size_t const r = ZSTD_compressBegin(staticCCtx, STATIC_CCTX_LEVEL); - if (ZSTD_isError(r)) goto _output_error; } + CHECK_Z( ZSTD_compressBegin(staticCCtx, STATIC_CCTX_LEVEL) ); DISPLAYLEVEL(3, "OK \n"); - DISPLAYLEVEL(3, "test%3i : simple compression test with static CCtx : ", testNb++); + DISPLAYLEVEL(3, "test%3i : compression again with static CCtx : ", testNb++); CHECK_VAR(cSize, ZSTD_compressCCtx(staticCCtx, compressedBuffer, compressedBufferSize, CNBuffer, CNBuffSize, STATIC_CCTX_LEVEL) ); @@ -1103,11 +1112,7 @@ static int basicUnitTests(U32 const seed, double compressibility) DISPLAYLEVEL(3, "OK \n"); DISPLAYLEVEL(3, "test%3i : check decompressed result : ", testNb++); - { size_t u; - for (u=0; u