1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-30 22:23:13 +03:00

Test DDSS A Little More Thoroughly

This commit is contained in:
W. Felix Handte
2020-09-10 11:32:16 -04:00
parent efa33861f2
commit 2cc2b40a1b

View File

@ -571,7 +571,7 @@ static int basicUnitTests(U32 const seed, double compressibility)
r = ZSTD_decompress(decodedBuffer, CNBuffSize, compressedBuffer, cSize); r = ZSTD_decompress(decodedBuffer, CNBuffSize, compressedBuffer, cSize);
if (!ZSTD_isError(r)) goto _output_error; if (!ZSTD_isError(r)) goto _output_error;
if (ZSTD_getErrorCode(r) != ZSTD_error_checksum_wrong) goto _output_error; if (ZSTD_getErrorCode(r) != ZSTD_error_checksum_wrong) goto _output_error;
CHECK_Z(ZSTD_DCtx_setParameter(dctx, ZSTD_d_forceIgnoreChecksum, ZSTD_d_ignoreChecksum)); CHECK_Z(ZSTD_DCtx_setParameter(dctx, ZSTD_d_forceIgnoreChecksum, ZSTD_d_ignoreChecksum));
r = ZSTD_decompressDCtx(dctx, decodedBuffer, CNBuffSize, compressedBuffer, cSize-1); r = ZSTD_decompressDCtx(dctx, decodedBuffer, CNBuffSize, compressedBuffer, cSize-1);
if (!ZSTD_isError(r)) goto _output_error; /* wrong checksum size should still throw error */ if (!ZSTD_isError(r)) goto _output_error; /* wrong checksum size should still throw error */
@ -2926,7 +2926,7 @@ static int basicUnitTests(U32 const seed, double compressibility)
{ {
ZSTD_CCtx* const cctx = ZSTD_createCCtx(); ZSTD_CCtx* const cctx = ZSTD_createCCtx();
ZSTD_DCtx* const dctx = ZSTD_createDCtx(); ZSTD_DCtx* const dctx = ZSTD_createDCtx();
size_t dictSize = CNBuffSize > 110 KB ? 110 KB : CNBuffSize; size_t dictSize = CNBuffSize;
void* dict = (void*)malloc(dictSize); void* dict = (void*)malloc(dictSize);
ZSTD_CCtx_params* cctx_params = ZSTD_createCCtxParams(); ZSTD_CCtx_params* cctx_params = ZSTD_createCCtxParams();
ZSTD_dictAttachPref_e const attachPrefs[] = { ZSTD_dictAttachPref_e const attachPrefs[] = {
@ -2934,10 +2934,13 @@ static int basicUnitTests(U32 const seed, double compressibility)
ZSTD_dictForceAttach, ZSTD_dictForceAttach,
ZSTD_dictForceCopy, ZSTD_dictForceCopy,
ZSTD_dictForceLoad, ZSTD_dictForceLoad,
ZSTD_dictForceAttach ZSTD_dictDefaultAttach,
ZSTD_dictForceAttach,
ZSTD_dictForceCopy,
ZSTD_dictForceLoad
}; };
int const enableDedicatedDictSearch[] = {0, 0, 0, 0, 1}; int const enableDedicatedDictSearch[] = {0, 0, 0, 0, 1, 1, 1, 1};
int const cLevel = 6; int cLevel;
int i; int i;
RDG_genBuffer(dict, dictSize, 0.5, 0.5, seed); RDG_genBuffer(dict, dictSize, 0.5, 0.5, seed);
@ -2945,28 +2948,34 @@ static int basicUnitTests(U32 const seed, double compressibility)
CHECK(cctx_params != NULL); CHECK(cctx_params != NULL);
for (i = 0; i < 5; ++i) { for (dictSize = CNBuffSize; dictSize; dictSize = dictSize >> 1) {
ZSTD_dictAttachPref_e const attachPref = attachPrefs[i]; for (cLevel = 4; cLevel < 12; cLevel++) {
int const enableDDS = enableDedicatedDictSearch[i]; for (i = 0; i < 8; ++i) {
ZSTD_CDict* cdict; ZSTD_dictAttachPref_e const attachPref = attachPrefs[i];
int const enableDDS = enableDedicatedDictSearch[i];
ZSTD_CDict* cdict;
DISPLAYLEVEL(5, "\n iter %d ", i); DISPLAYLEVEL(5, "\n dictSize %lu cLevel %d iter %d ", dictSize, cLevel, i);
ZSTD_CCtxParams_init(cctx_params, cLevel); ZSTD_CCtxParams_init(cctx_params, cLevel);
CHECK_Z(ZSTD_CCtxParams_setParameter(cctx_params, ZSTD_c_enableDedicatedDictSearch, enableDDS)); CHECK_Z(ZSTD_CCtxParams_setParameter(cctx_params, ZSTD_c_enableDedicatedDictSearch, enableDDS));
cdict = ZSTD_createCDict_advanced2(dict, dictSize, ZSTD_dlm_byRef, ZSTD_dct_auto, cctx_params, ZSTD_defaultCMem); cdict = ZSTD_createCDict_advanced2(dict, dictSize, ZSTD_dlm_byRef, ZSTD_dct_auto, cctx_params, ZSTD_defaultCMem);
CHECK(cdict != NULL); CHECK(cdict != NULL);
CHECK_Z(ZSTD_CCtx_refCDict(cctx, cdict)); CHECK_Z(ZSTD_CCtx_refCDict(cctx, cdict));
CHECK_Z(ZSTD_CCtx_setParameter(cctx, ZSTD_c_forceAttachDict, attachPref)); CHECK_Z(ZSTD_CCtx_setParameter(cctx, ZSTD_c_forceAttachDict, attachPref));
cSize = ZSTD_compress2(cctx, compressedBuffer, compressedBufferSize, CNBuffer, CNBuffSize); cSize = ZSTD_compress2(cctx, compressedBuffer, compressedBufferSize, CNBuffer, CNBuffSize);
CHECK_Z(cSize); CHECK_Z(cSize);
CHECK_Z(ZSTD_decompress_usingDict(dctx, decodedBuffer, CNBuffSize, compressedBuffer, cSize, dict, dictSize)); CHECK_Z(ZSTD_decompress_usingDict(dctx, decodedBuffer, CNBuffSize, compressedBuffer, cSize, dict, dictSize));
CHECK_Z(ZSTD_CCtx_reset(cctx, ZSTD_reset_session_and_parameters)); DISPLAYLEVEL(5, "compressed to %lu bytes ", cSize);
ZSTD_freeCDict(cdict);
CHECK_Z(ZSTD_CCtx_reset(cctx, ZSTD_reset_session_and_parameters));
ZSTD_freeCDict(cdict);
}
}
} }
ZSTD_freeCCtx(cctx); ZSTD_freeCCtx(cctx);