]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Add mem monotonicity test over srcSize
authorSen Huang <senhuang96@fb.com>
Tue, 16 Mar 2021 15:22:13 +0000 (08:22 -0700)
committerSen Huang <senhuang96@fb.com>
Tue, 16 Mar 2021 15:24:26 +0000 (08:24 -0700)
tests/fuzzer.c

index 5f707e027d51229c83fd7fc9675ff622b6fa9b14..4fa57c8ef6ee2a43a2f77d7ff759707f1c3b7c4f 100644 (file)
@@ -3181,6 +3181,31 @@ static int basicUnitTests(U32 const seed, double compressibility)
     }
     DISPLAYLEVEL(3, "OK \n");
 
+    DISPLAYLEVEL(3, "test%3i : check compression mem usage monotonicity over srcSize : ", testNb++);
+    {
+        size_t const kSizeIncrement = 2 KB;
+        int level = -3;
+
+        for (; level <= ZSTD_maxCLevel(); ++level) {
+            size_t dictSize = 0;
+            for (; dictSize <= 256 KB; dictSize += 8 * kSizeIncrement) {
+                size_t srcSize = 2 KB;
+                size_t prevCCtxSize = 0;
+                for (; srcSize < 300 KB; srcSize += kSizeIncrement) {
+                    ZSTD_compressionParameters const cParams = ZSTD_getCParams(level, srcSize, dictSize);
+                    size_t const cctxSize = ZSTD_estimateCCtxSize_usingCParams(cParams);
+                    if (cctxSize < prevCCtxSize || ZSTD_isError(cctxSize)) {
+                        DISPLAYLEVEL(3, "error! level: %d dictSize: %zu srcSize: %zu cctx size: %zu, prevsize: %zu\n",
+                                     level, dictSize, srcSize, cctxSize, prevCCtxSize);
+                        goto _output_error;
+                    }
+                    prevCCtxSize = cctxSize;
+                }
+            }
+        }
+    }
+    DISPLAYLEVEL(3, "OK \n");
+
 #endif
 
 _end: