From: Yann Collet Date: Thu, 17 Oct 2024 20:21:55 +0000 (-0700) Subject: fixed RLE detection test X-Git-Tag: v1.5.7^2~71^2~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f83ed087f6310a8cf51267ea431ec4a7b7ffd94f;p=thirdparty%2Fzstd.git fixed RLE detection test --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index eb7b06df9..25a11f070 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -4491,14 +4491,14 @@ static void ZSTD_overflowCorrectIfNeeded(ZSTD_matchState_t* ms, static size_t ZSTD_optimalBlockSize(const void* src, size_t srcSize, size_t blockSizeMax, ZSTD_strategy strat, S64 savings) { - if (srcSize <= 128 KB || blockSizeMax < 128 KB) - return MIN(srcSize, blockSizeMax); - (void)strat; if (strat >= ZSTD_btlazy2) return ZSTD_splitBlock_4k(src, srcSize, blockSizeMax); + if (srcSize <= 128 KB || blockSizeMax < 128 KB) + return MIN(srcSize, blockSizeMax); /* blind split strategy - * heuristic, just tested as being "generally better" - * do not split incompressible data though: just respect the 3 bytes per block overhead limit. + * no cpu cost, but can over-split homegeneous data. + * heuristic, tested as being "generally better". + * do not split incompressible data though: respect the 3 bytes per block overhead limit. */ return savings ? 92 KB : 128 KB; } diff --git a/tests/fuzzer.c b/tests/fuzzer.c index ead3cc8dd..f5a894354 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -3653,16 +3653,19 @@ static int basicUnitTests(U32 const seed, double compressibility) ZSTD_freeDCtx(dctx); } - /* long rle test */ + /* rle detection test: must compress better blocks with a single identical byte repeated */ { size_t sampleSize = 0; - size_t expectedCompressedSize = 39; /* block 1, 2: compressed, block 3: RLE, zstd 1.4.4 */ - DISPLAYLEVEL(3, "test%3i : Long RLE test : ", testNb++); - memset((char*)CNBuffer+sampleSize, 'B', 256 KB - 1); - sampleSize += 256 KB - 1; - memset((char*)CNBuffer+sampleSize, 'A', 96 KB); - sampleSize += 96 KB; + size_t maxCompressedSize = 46; /* block 1, 2: compressed, block 3: RLE, zstd 1.4.4 */ + DISPLAYLEVEL(3, "test%3i : RLE detection test : ", testNb++); + memset((char*)CNBuffer+sampleSize, 'B', 256 KB - 2); + sampleSize += 256 KB - 2; + memset((char*)CNBuffer+sampleSize, 'A', 100 KB); + sampleSize += 100 KB; cSize = ZSTD_compress(compressedBuffer, ZSTD_compressBound(sampleSize), CNBuffer, sampleSize, 1); - if (ZSTD_isError(cSize) || cSize > expectedCompressedSize) goto _output_error; + if (ZSTD_isError(cSize) || cSize > maxCompressedSize) { + DISPLAYLEVEL(4, "error: cSize %u > %u expected ! \n", (unsigned)cSize, (unsigned)maxCompressedSize); + goto _output_error; + } { CHECK_NEWV(regenSize, ZSTD_decompress(decodedBuffer, sampleSize, compressedBuffer, cSize)); if (regenSize!=sampleSize) goto _output_error; } DISPLAYLEVEL(3, "OK \n");