summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2017-08-15 23:50:04 (GMT)
committerGitHub <noreply@github.com>2017-08-15 23:50:04 (GMT)
commitaf9d72b7f6809ec972787c446d464a8f9be443ba (patch)
treed8b9e795e00d2558945f0f6bc3aed2b239157353 /tests
parent8593ba8831fb4698731c60391aa0ab89b32e9e19 (diff)
parent930a6921103c3ae4e62c99f86fd5329ef957900f (diff)
downloadlz4-af9d72b7f6809ec972787c446d464a8f9be443ba.zip
lz4-af9d72b7f6809ec972787c446d464a8f9be443ba.tar.gz
lz4-af9d72b7f6809ec972787c446d464a8f9be443ba.tar.bz2
Merge pull request #383 from lz4/blockChecksum
Block checksum
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile1
-rw-r--r--tests/frametest.c28
2 files changed, 27 insertions, 2 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 5d2532f..f00778f 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -263,6 +263,7 @@ test-lz4-basic: lz4 datagen unlz4 lz4cat
$(LZ4) -f tmp
cat tmp >> tmp.lz4
$(LZ4) -f tmp.lz4 # uncompress valid frame followed by invalid data
+ $(LZ4) -BX tmp -c -q | $(LZ4) -tv # test block checksum
@$(RM) tmp*
test-lz4-hugefile: lz4 datagen
diff --git a/tests/frametest.c b/tests/frametest.c
index d0665c5..88d0afd 100644
--- a/tests/frametest.c
+++ b/tests/frametest.c
@@ -402,7 +402,7 @@ int basicTests(U32 seed, double compressibility)
CHECK_V(cSize, LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs) );
DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
- DISPLAYLEVEL(3, "without checksum : ");
+ DISPLAYLEVEL(3, "without frame checksum : ");
prefs.frameInfo.contentChecksumFlag = LZ4F_noContentChecksum;
CHECK_V(cSize, LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs) );
DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
@@ -416,7 +416,7 @@ int basicTests(U32 seed, double compressibility)
DISPLAYLEVEL(3, "Compressed %u bytes into a %u bytes frame \n", (U32)testSize, (U32)cSize);
}
- DISPLAYLEVEL(3, "without checksum : ");
+ DISPLAYLEVEL(3, "without frame checksum : ");
prefs.frameInfo.contentChecksumFlag = LZ4F_noContentChecksum;
{ size_t const dstCapacity = LZ4F_compressFrameBound(testSize, &prefs);
DISPLAYLEVEL(4, "dstCapacity = %u ; ", (U32)dstCapacity)
@@ -424,6 +424,29 @@ int basicTests(U32 seed, double compressibility)
DISPLAYLEVEL(3, "Compressed %u bytes into a %u bytes frame \n", (U32)testSize, (U32)cSize);
}
+ DISPLAYLEVEL(3, "LZ4F_compressFrame with block checksum : ");
+ memset(&prefs, 0, sizeof(prefs));
+ prefs.frameInfo.blockChecksumFlag = LZ4F_blockChecksumEnabled;
+ CHECK_V(cSize, LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs) );
+ DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
+
+ DISPLAYLEVEL(3, "Decompress with block checksum : ");
+ { size_t iSize = cSize;
+ size_t decodedSize = COMPRESSIBLE_NOISE_LENGTH;
+ LZ4F_decompressionContext_t dctx;
+ CHECK( LZ4F_createDecompressionContext(&dctx, LZ4F_VERSION) );
+ CHECK( LZ4F_decompress(dctx, decodedBuffer, &decodedSize, compressedBuffer, &iSize, NULL) );
+ if (decodedSize != testSize) goto _output_error;
+ if (iSize != cSize) goto _output_error;
+ { U64 const crcDest = XXH64(decodedBuffer, decodedSize, 1);
+ U64 const crcSrc = XXH64(CNBuffer, testSize, 1);
+ if (crcDest != crcSrc) goto _output_error;
+ }
+ DISPLAYLEVEL(3, "Regenerated %u bytes \n", (U32)decodedSize);
+
+ CHECK( LZ4F_freeDecompressionContext(dctx) );
+ }
+
/* frame content size tests */
{ size_t cErr;
BYTE* const ostart = (BYTE*)compressedBuffer;
@@ -771,6 +794,7 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
memset(&prefs, 0, sizeof(prefs));
prefs.frameInfo.blockMode = (LZ4F_blockMode_t)(FUZ_rand(&randState) & 1);
prefs.frameInfo.blockSizeID = (LZ4F_blockSizeID_t)(4 + (FUZ_rand(&randState) & 3));
+ prefs.frameInfo.blockChecksumFlag = (LZ4F_blockChecksum_t)(FUZ_rand(&randState) & 1);
prefs.frameInfo.contentChecksumFlag = (LZ4F_contentChecksum_t)(FUZ_rand(&randState) & 1);
prefs.frameInfo.contentSize = ((FUZ_rand(&randState) & 0xF) == 1) ? srcSize : 0;
prefs.autoFlush = neverFlush ? 0 : (FUZ_rand(&randState) & 7) == 2;