@@ -3181,6 +3181,48 @@ static int basicUnitTests(U32 const seed, double compressibility)
3181
3181
}
3182
3182
DISPLAYLEVEL (3 , "OK \n" );
3183
3183
3184
+ DISPLAYLEVEL (3 , "test%3i : check compression mem usage monotonicity over levels for estimateCCtxSize() : " , testNb ++ );
3185
+ {
3186
+ int level = 1 ;
3187
+ size_t prevSize = 0 ;
3188
+ for (; level < ZSTD_maxCLevel (); ++ level ) {
3189
+ size_t const currSize = ZSTD_estimateCCtxSize (level );
3190
+ if (prevSize > currSize ) {
3191
+ DISPLAYLEVEL (3 , "Error! previous cctx size: %zu at level: %d is larger than current cctx size: %zu at level: %d" ,
3192
+ prevSize , level - 1 , currSize , level );
3193
+ goto _output_error ;
3194
+ }
3195
+ prevSize = currSize ;
3196
+ }
3197
+ }
3198
+ DISPLAYLEVEL (3 , "OK \n" );
3199
+
3200
+ DISPLAYLEVEL (3 , "test%3i : check estimateCCtxSize() always larger or equal to ZSTD_estimateCCtxSize_usingCParams() : " , testNb ++ );
3201
+ {
3202
+ size_t const kSizeIncrement = 2 KB ;
3203
+ int level = -3 ;
3204
+
3205
+ for (; level <= ZSTD_maxCLevel (); ++ level ) {
3206
+ size_t dictSize = 0 ;
3207
+ for (; dictSize <= 256 KB ; dictSize += 8 * kSizeIncrement ) {
3208
+ size_t srcSize = 2 KB ;
3209
+ for (; srcSize < 300 KB ; srcSize += kSizeIncrement ) {
3210
+ ZSTD_compressionParameters const cParams = ZSTD_getCParams (level , srcSize , dictSize );
3211
+ size_t const cctxSizeUsingCParams = ZSTD_estimateCCtxSize_usingCParams (cParams );
3212
+ size_t const cctxSizeUsingLevel = ZSTD_estimateCCtxSize (level );
3213
+ if (cctxSizeUsingLevel < cctxSizeUsingCParams
3214
+ || ZSTD_isError (cctxSizeUsingCParams )
3215
+ || ZSTD_isError (cctxSizeUsingLevel )) {
3216
+ DISPLAYLEVEL (3 , "error! l: %d dict: %zu srcSize: %zu cctx size cpar: %zu, cctx size level: %zu\n" ,
3217
+ level , dictSize , srcSize , cctxSizeUsingCParams , cctxSizeUsingLevel );
3218
+ goto _output_error ;
3219
+ }
3220
+ }
3221
+ }
3222
+ }
3223
+ }
3224
+ DISPLAYLEVEL (3 , "OK \n" );
3225
+
3184
3226
#endif
3185
3227
3186
3228
_end :
0 commit comments