mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-26 15:42:34 +01:00
Add coverage markers in Zstd + LZMA compression backends.
See: https://bugs.torproject.org/22286
This commit is contained in:
parent
77511aed6c
commit
fcf836d239
2 changed files with 28 additions and 2 deletions
|
@ -46,6 +46,7 @@ memory_level(compression_level_t level)
|
||||||
static const char *
|
static const char *
|
||||||
lzma_error_str(lzma_ret error)
|
lzma_error_str(lzma_ret error)
|
||||||
{
|
{
|
||||||
|
// LCOV_EXCL_START
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case LZMA_OK:
|
case LZMA_OK:
|
||||||
return "Operation completed successfully";
|
return "Operation completed successfully";
|
||||||
|
@ -74,6 +75,7 @@ lzma_error_str(lzma_ret error)
|
||||||
default:
|
default:
|
||||||
return "Unknown LZMA error";
|
return "Unknown LZMA error";
|
||||||
}
|
}
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
#endif // HAVE_LZMA.
|
#endif // HAVE_LZMA.
|
||||||
|
|
||||||
|
@ -144,9 +146,11 @@ tor_lzma_state_size_precalc(int compress, compression_level_t level)
|
||||||
memory_usage = lzma_easy_decoder_memusage(memory_level(level));
|
memory_usage = lzma_easy_decoder_memusage(memory_level(level));
|
||||||
|
|
||||||
if (memory_usage == UINT64_MAX) {
|
if (memory_usage == UINT64_MAX) {
|
||||||
|
// LCOV_EXCL_START
|
||||||
log_warn(LD_GENERAL, "Unsupported compression level passed to LZMA %s",
|
log_warn(LD_GENERAL, "Unsupported compression level passed to LZMA %s",
|
||||||
compress ? "encoder" : "decoder");
|
compress ? "encoder" : "decoder");
|
||||||
goto err;
|
goto err;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memory_usage + sizeof(tor_lzma_compress_state_t) > SIZE_MAX)
|
if (memory_usage + sizeof(tor_lzma_compress_state_t) > SIZE_MAX)
|
||||||
|
@ -157,7 +161,7 @@ tor_lzma_state_size_precalc(int compress, compression_level_t level)
|
||||||
return (size_t)memory_usage;
|
return (size_t)memory_usage;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
return 0;
|
return 0; // LCOV_EXCL_LINE
|
||||||
}
|
}
|
||||||
#endif // HAVE_LZMA.
|
#endif // HAVE_LZMA.
|
||||||
|
|
||||||
|
@ -189,17 +193,21 @@ tor_lzma_compress_new(int compress,
|
||||||
retval = lzma_alone_encoder(&result->stream, &stream_options);
|
retval = lzma_alone_encoder(&result->stream, &stream_options);
|
||||||
|
|
||||||
if (retval != LZMA_OK) {
|
if (retval != LZMA_OK) {
|
||||||
|
// LCOV_EXCL_START
|
||||||
log_warn(LD_GENERAL, "Error from LZMA encoder: %s (%u).",
|
log_warn(LD_GENERAL, "Error from LZMA encoder: %s (%u).",
|
||||||
lzma_error_str(retval), retval);
|
lzma_error_str(retval), retval);
|
||||||
goto err;
|
goto err;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
retval = lzma_alone_decoder(&result->stream, MEMORY_LIMIT);
|
retval = lzma_alone_decoder(&result->stream, MEMORY_LIMIT);
|
||||||
|
|
||||||
if (retval != LZMA_OK) {
|
if (retval != LZMA_OK) {
|
||||||
|
// LCOV_EXCL_START
|
||||||
log_warn(LD_GENERAL, "Error from LZMA decoder: %s (%u).",
|
log_warn(LD_GENERAL, "Error from LZMA decoder: %s (%u).",
|
||||||
lzma_error_str(retval), retval);
|
lzma_error_str(retval), retval);
|
||||||
goto err;
|
goto err;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +215,7 @@ tor_lzma_compress_new(int compress,
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
tor_free(result);
|
tor_free(result); // LCOV_EXCL_LINE
|
||||||
return NULL;
|
return NULL;
|
||||||
#else // HAVE_LZMA.
|
#else // HAVE_LZMA.
|
||||||
(void)compress;
|
(void)compress;
|
||||||
|
@ -295,10 +303,12 @@ tor_lzma_compress_process(tor_lzma_compress_state_t *state,
|
||||||
case LZMA_DATA_ERROR:
|
case LZMA_DATA_ERROR:
|
||||||
case LZMA_PROG_ERROR:
|
case LZMA_PROG_ERROR:
|
||||||
default:
|
default:
|
||||||
|
// LCOV_EXCL_START
|
||||||
log_warn(LD_GENERAL, "LZMA %s didn't finish: %s.",
|
log_warn(LD_GENERAL, "LZMA %s didn't finish: %s.",
|
||||||
state->compress ? "compression" : "decompression",
|
state->compress ? "compression" : "decompression",
|
||||||
lzma_error_str(retval));
|
lzma_error_str(retval));
|
||||||
return TOR_COMPRESS_ERROR;
|
return TOR_COMPRESS_ERROR;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
#else // HAVE_LZMA.
|
#else // HAVE_LZMA.
|
||||||
(void)state;
|
(void)state;
|
||||||
|
|
|
@ -194,31 +194,39 @@ tor_zstd_compress_new(int compress,
|
||||||
result->u.compress_stream = ZSTD_createCStream();
|
result->u.compress_stream = ZSTD_createCStream();
|
||||||
|
|
||||||
if (result->u.compress_stream == NULL) {
|
if (result->u.compress_stream == NULL) {
|
||||||
|
// LCOV_EXCL_START
|
||||||
log_warn(LD_GENERAL, "Error while creating Zstandard stream");
|
log_warn(LD_GENERAL, "Error while creating Zstandard stream");
|
||||||
goto err;
|
goto err;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = ZSTD_initCStream(result->u.compress_stream, preset);
|
retval = ZSTD_initCStream(result->u.compress_stream, preset);
|
||||||
|
|
||||||
if (ZSTD_isError(retval)) {
|
if (ZSTD_isError(retval)) {
|
||||||
|
// LCOV_EXCL_START
|
||||||
log_warn(LD_GENERAL, "Zstandard stream initialization error: %s",
|
log_warn(LD_GENERAL, "Zstandard stream initialization error: %s",
|
||||||
ZSTD_getErrorName(retval));
|
ZSTD_getErrorName(retval));
|
||||||
goto err;
|
goto err;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result->u.decompress_stream = ZSTD_createDStream();
|
result->u.decompress_stream = ZSTD_createDStream();
|
||||||
|
|
||||||
if (result->u.decompress_stream == NULL) {
|
if (result->u.decompress_stream == NULL) {
|
||||||
|
// LCOV_EXCL_START
|
||||||
log_warn(LD_GENERAL, "Error while creating Zstandard stream");
|
log_warn(LD_GENERAL, "Error while creating Zstandard stream");
|
||||||
goto err;
|
goto err;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = ZSTD_initDStream(result->u.decompress_stream);
|
retval = ZSTD_initDStream(result->u.decompress_stream);
|
||||||
|
|
||||||
if (ZSTD_isError(retval)) {
|
if (ZSTD_isError(retval)) {
|
||||||
|
// LCOV_EXCL_START
|
||||||
log_warn(LD_GENERAL, "Zstandard stream initialization error: %s",
|
log_warn(LD_GENERAL, "Zstandard stream initialization error: %s",
|
||||||
ZSTD_getErrorName(retval));
|
ZSTD_getErrorName(retval));
|
||||||
goto err;
|
goto err;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,6 +234,7 @@ tor_zstd_compress_new(int compress,
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
// LCOV_EXCL_START
|
||||||
if (compress) {
|
if (compress) {
|
||||||
ZSTD_freeCStream(result->u.compress_stream);
|
ZSTD_freeCStream(result->u.compress_stream);
|
||||||
} else {
|
} else {
|
||||||
|
@ -234,6 +243,7 @@ tor_zstd_compress_new(int compress,
|
||||||
|
|
||||||
tor_free(result);
|
tor_free(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
#else // HAVE_ZSTD.
|
#else // HAVE_ZSTD.
|
||||||
(void)compress;
|
(void)compress;
|
||||||
(void)method;
|
(void)method;
|
||||||
|
@ -294,10 +304,12 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ZSTD_isError(retval)) {
|
if (ZSTD_isError(retval)) {
|
||||||
|
// LCOV_EXCL_START
|
||||||
log_warn(LD_GENERAL, "Zstandard %s didn't finish: %s.",
|
log_warn(LD_GENERAL, "Zstandard %s didn't finish: %s.",
|
||||||
state->compress ? "compression" : "decompression",
|
state->compress ? "compression" : "decompression",
|
||||||
ZSTD_getErrorName(retval));
|
ZSTD_getErrorName(retval));
|
||||||
return TOR_COMPRESS_ERROR;
|
return TOR_COMPRESS_ERROR;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state->compress && !finish) {
|
if (state->compress && !finish) {
|
||||||
|
@ -307,9 +319,11 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state,
|
||||||
*out_len = output.size - output.pos;
|
*out_len = output.size - output.pos;
|
||||||
|
|
||||||
if (ZSTD_isError(retval)) {
|
if (ZSTD_isError(retval)) {
|
||||||
|
// LCOV_EXCL_START
|
||||||
log_warn(LD_GENERAL, "Zstandard compression unable to flush: %s.",
|
log_warn(LD_GENERAL, "Zstandard compression unable to flush: %s.",
|
||||||
ZSTD_getErrorName(retval));
|
ZSTD_getErrorName(retval));
|
||||||
return TOR_COMPRESS_ERROR;
|
return TOR_COMPRESS_ERROR;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval > 0)
|
if (retval > 0)
|
||||||
|
@ -326,10 +340,12 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state,
|
||||||
*out_len = output.size - output.pos;
|
*out_len = output.size - output.pos;
|
||||||
|
|
||||||
if (ZSTD_isError(retval)) {
|
if (ZSTD_isError(retval)) {
|
||||||
|
// LCOV_EXCL_START
|
||||||
log_warn(LD_GENERAL, "Zstandard compression unable to write "
|
log_warn(LD_GENERAL, "Zstandard compression unable to write "
|
||||||
"epilogue: %s.",
|
"epilogue: %s.",
|
||||||
ZSTD_getErrorName(retval));
|
ZSTD_getErrorName(retval));
|
||||||
return TOR_COMPRESS_ERROR;
|
return TOR_COMPRESS_ERROR;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
|
|
||||||
// endStream returns the number of bytes that is needed to write the
|
// endStream returns the number of bytes that is needed to write the
|
||||||
|
|
Loading…
Add table
Reference in a new issue