mirror of
https://git.tukaani.org/xz.git
synced 2026-10-31 03:14:56 +00:00
Tests: test_index: Add a test for the Index decoder memusage bug
This commit is contained in:
parent
bd3bfe8346
commit
10dfae83fd
@ -1622,6 +1622,53 @@ test_lzma_index_decoder(void)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_lzma_index_decoder_memusage(void)
|
||||
{
|
||||
#ifndef HAVE_DECODERS
|
||||
assert_skip("Decoder support disabled");
|
||||
#else
|
||||
assert_uint(decode_buffer_size, >, 20);
|
||||
|
||||
lzma_stream strm = LZMA_STREAM_INIT;
|
||||
lzma_index *idx = NULL;
|
||||
assert_lzma_ret(lzma_index_decoder(&strm, &idx, MEMLIMIT), LZMA_OK);
|
||||
|
||||
// Nothing decoded yet.
|
||||
assert_uint(lzma_memusage(&strm), <, 1000);
|
||||
|
||||
const size_t step = 5;
|
||||
size_t remaining = decode_buffer_size;
|
||||
strm.next_in = decode_buffer;
|
||||
strm.avail_in = step;
|
||||
remaining -= strm.avail_in;
|
||||
|
||||
uint64_t memused = 0;
|
||||
|
||||
while (true) {
|
||||
lzma_ret ret = lzma_code(&strm, LZMA_RUN);
|
||||
if (ret == LZMA_STREAM_END)
|
||||
break;
|
||||
|
||||
assert_lzma_ret(ret, LZMA_OK);
|
||||
assert_uint_eq(strm.avail_in, 0);
|
||||
strm.avail_in = my_min(remaining, step);
|
||||
remaining -= strm.avail_in;
|
||||
|
||||
if (memused == 0) {
|
||||
memused = lzma_memusage(&strm);
|
||||
assert_uint(memused, >, 100);
|
||||
} else {
|
||||
assert_uint_eq(lzma_memusage(&strm), memused);
|
||||
}
|
||||
}
|
||||
|
||||
lzma_index_end(idx, NULL);
|
||||
lzma_end(&strm);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_lzma_index_buffer_encode(void)
|
||||
{
|
||||
@ -1831,6 +1878,7 @@ main(int argc, char **argv)
|
||||
tuktest_run(test_lzma_index_dup);
|
||||
tuktest_run(test_lzma_index_encoder);
|
||||
tuktest_run(test_lzma_index_decoder);
|
||||
tuktest_run(test_lzma_index_decoder_memusage);
|
||||
tuktest_run(test_lzma_index_buffer_encode);
|
||||
tuktest_run(test_lzma_index_buffer_decode);
|
||||
tuktest_run(test_decode_empty_and_append);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user