Add test case to roundtrip using ZSTD_getSequences() and ZSTD_compressSequences()
This commit is contained in:
parent
5fd69f8173
commit
2bbdddf24e
@ -3407,7 +3407,6 @@ static size_t ZSTD_writeEpilogue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cctx->stage != ZSTDcs_ending) {
|
if (cctx->stage != ZSTDcs_ending) {
|
||||||
DEBUGLOG(4, "did this\n");
|
|
||||||
/* write one last empty block, make it the "last" block */
|
/* write one last empty block, make it the "last" block */
|
||||||
U32 const cBlockHeader24 = 1 /* last block */ + (((U32)bt_raw)<<1) + 0;
|
U32 const cBlockHeader24 = 1 /* last block */ + (((U32)bt_raw)<<1) + 0;
|
||||||
RETURN_ERROR_IF(dstCapacity<4, dstSize_tooSmall, "no room for epilogue");
|
RETURN_ERROR_IF(dstCapacity<4, dstSize_tooSmall, "no room for epilogue");
|
||||||
@ -4389,7 +4388,7 @@ size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
|||||||
|
|
||||||
/* transparent initialization stage */
|
/* transparent initialization stage */
|
||||||
if (cctx->streamStage == zcss_init) {
|
if (cctx->streamStage == zcss_init) {
|
||||||
ZSTD_CCtx_init_compressStream2(cctx, endOp, input->size);
|
FORWARD_IF_ERROR(ZSTD_CCtx_init_compressStream2(cctx, endOp, input->size), "CompressStream2 initialization failed");
|
||||||
ZSTD_setBufferExpectations(cctx, output, input); /* Set initial buffer expectations now that we've initialized */
|
ZSTD_setBufferExpectations(cctx, output, input); /* Set initial buffer expectations now that we've initialized */
|
||||||
}
|
}
|
||||||
/* end of transparent initialization stage */
|
/* end of transparent initialization stage */
|
||||||
@ -4661,11 +4660,11 @@ static size_t ZSTD_copySequencesToSeqStore(seqStore_t* seqStore, const ZSTD_sequ
|
|||||||
*
|
*
|
||||||
* Returns the cumulative size of all compressed blocks (including their headers), otherwise a ZSTD error
|
* Returns the cumulative size of all compressed blocks (including their headers), otherwise a ZSTD error
|
||||||
*/
|
*/
|
||||||
size_t ZSTD_compressSequences_internal(void* dst, size_t dstCapacity,
|
static size_t ZSTD_compressSequences_internal(void* dst, size_t dstCapacity,
|
||||||
ZSTD_CCtx* cctx,
|
ZSTD_CCtx* cctx,
|
||||||
const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
|
const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
|
||||||
const void* src, size_t srcSize,
|
const void* src, size_t srcSize,
|
||||||
ZSTD_sequenceFormat_e format) {
|
ZSTD_sequenceFormat_e format) {
|
||||||
U32 cSize = 0;
|
U32 cSize = 0;
|
||||||
U32 lastBlock;
|
U32 lastBlock;
|
||||||
U32 blockSize;
|
U32 blockSize;
|
||||||
@ -4675,7 +4674,6 @@ size_t ZSTD_compressSequences_internal(void* dst, size_t dstCapacity,
|
|||||||
seqStore_t blockSeqStore;
|
seqStore_t blockSeqStore;
|
||||||
blockSeqStore.longLengthID = 0;
|
blockSeqStore.longLengthID = 0;
|
||||||
blockSeqStore.longLengthPos = 0;
|
blockSeqStore.longLengthPos = 0;
|
||||||
size_t origDstCapacity = dstCapacity;
|
|
||||||
|
|
||||||
DEBUGLOG(4, "ZSTD_compressSequences_internal srcSize: %zu, inSeqsSize: %zu", srcSize, inSeqsSize);
|
DEBUGLOG(4, "ZSTD_compressSequences_internal srcSize: %zu, inSeqsSize: %zu", srcSize, inSeqsSize);
|
||||||
BYTE const* ip = (BYTE const*)src;
|
BYTE const* ip = (BYTE const*)src;
|
||||||
|
@ -2740,6 +2740,61 @@ static int basicUnitTests(U32 const seed, double compressibility)
|
|||||||
}
|
}
|
||||||
DISPLAYLEVEL(3, "OK \n");
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
|
DISPLAYLEVEL(3, "test%3i : ZSTD_getSequences followed by ZSTD_compressSequences : ", testNb++);
|
||||||
|
{
|
||||||
|
size_t srcSize = 150 KB;
|
||||||
|
BYTE* src = (BYTE*)CNBuffer;
|
||||||
|
BYTE* dst = (BYTE*)compressedBuffer;
|
||||||
|
size_t dstSize = ZSTD_compressBound(srcSize);
|
||||||
|
size_t decompressSize = srcSize;
|
||||||
|
char* decompressBuffer = (char*)malloc(decompressSize);
|
||||||
|
size_t compressedSize;
|
||||||
|
size_t dSize;
|
||||||
|
|
||||||
|
ZSTD_CCtx* cctx = ZSTD_createCCtx();
|
||||||
|
ZSTD_Sequence* seqs = (ZSTD_Sequence*)malloc(srcSize * sizeof(ZSTD_Sequence));
|
||||||
|
size_t seqsSize;
|
||||||
|
|
||||||
|
if (seqs == NULL) goto _output_error;
|
||||||
|
assert(cctx != NULL);
|
||||||
|
|
||||||
|
/* Populate src with random data */
|
||||||
|
RDG_genBuffer(CNBuffer, srcSize, compressibility, 0., seed);
|
||||||
|
|
||||||
|
/* Test with block delimiters roundtrip */
|
||||||
|
seqsSize = ZSTD_getSequences(cctx, seqs, srcSize, src, srcSize, ZSTD_sf_explicitBlockDelimiters);
|
||||||
|
compressedSize = ZSTD_compressSequences(dst, dstSize, seqs, seqsSize, src, srcSize, 3 /* clevel */, ZSTD_sf_explicitBlockDelimiters);
|
||||||
|
if (ZSTD_isError(compressedSize)) {
|
||||||
|
DISPLAY("Error in sequence compression with block delims\n");
|
||||||
|
goto _output_error;
|
||||||
|
}
|
||||||
|
dSize = ZSTD_decompress(decompressBuffer, decompressSize, dst, compressedSize);
|
||||||
|
if (ZSTD_isError(dSize)) {
|
||||||
|
DISPLAY("Error in sequence compression roundtrip with block delims\n");
|
||||||
|
goto _output_error;
|
||||||
|
}
|
||||||
|
assert(!memcmp(decompressBuffer, src, srcSize));
|
||||||
|
|
||||||
|
/* Test with no block delimiters roundtrip */
|
||||||
|
seqsSize = ZSTD_getSequences(cctx, seqs, srcSize, src, srcSize, ZSTD_sf_noBlockDelimiters);
|
||||||
|
compressedSize = ZSTD_compressSequences(dst, dstSize, seqs, seqsSize, src, srcSize, 3 /* clevel */, ZSTD_sf_noBlockDelimiters);
|
||||||
|
if (ZSTD_isError(compressedSize)) {
|
||||||
|
DISPLAY("Error in sequence compression with no block delims\n");
|
||||||
|
goto _output_error;
|
||||||
|
}
|
||||||
|
dSize = ZSTD_decompress(decompressBuffer, decompressSize, dst, compressedSize);
|
||||||
|
if (ZSTD_isError(dSize)) {
|
||||||
|
DISPLAY("Error in sequence compression roundtrip with no block delims\n");
|
||||||
|
goto _output_error;
|
||||||
|
}
|
||||||
|
assert(!memcmp(decompressBuffer, src, srcSize));
|
||||||
|
|
||||||
|
ZSTD_freeCCtx(cctx);
|
||||||
|
free(decompressBuffer);
|
||||||
|
free(seqs);
|
||||||
|
}
|
||||||
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
/* Multiple blocks of zeros test */
|
/* Multiple blocks of zeros test */
|
||||||
#define LONGZEROSLENGTH 1000000 /* 1MB of zeros */
|
#define LONGZEROSLENGTH 1000000 /* 1MB of zeros */
|
||||||
DISPLAYLEVEL(3, "test%3i : compress %u zeroes : ", testNb++, LONGZEROSLENGTH);
|
DISPLAYLEVEL(3, "test%3i : compress %u zeroes : ", testNb++, LONGZEROSLENGTH);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user