igzip: Make gzip format a run time option.

Change-Id: Ia986d378763146b33c733751652bff788ec3cb9d
Signed-off-by: Roy Oursler <roy.j.oursler@intel.com>
This commit is contained in:
Roy Oursler 2016-09-21 17:43:59 -07:00 committed by Greg Tucker
parent 77e43ef6cf
commit 4ea4f81138
7 changed files with 227 additions and 246 deletions

View File

@ -112,6 +112,7 @@ FIELD _total_out, 4, 4
FIELD _hufftables, 8, 8
FIELD _end_of_stream, 4, 4
FIELD _flush, 4, 4
FIELD _gzip_flag, 4, 4
FIELD _internal_state, _isal_zstate_size, _isal_zstate_align
%assign _isal_zstream_size _FIELD_OFFSET

View File

@ -39,10 +39,6 @@
# include <x86intrin.h>
#endif
#ifndef IGZIP_USE_GZIP_FORMAT
# define DEFLATE 1
#endif
static inline uint32_t bsr(uint32_t val)
{
uint32_t msb;

View File

@ -35,10 +35,6 @@
# include <intrin.h>
#endif
#ifndef IGZIP_USE_GZIP_FORMAT
# define DEFLATE 1
#endif
#define MAX_WRITE_BITS_SIZE 8
#define FORCE_FLUSH 64
#define MIN_OBUF_SIZE 224
@ -60,13 +56,11 @@ extern uint32_t crc32_gzip(uint32_t init_crc, const unsigned char *buf, uint64_t
static int write_stored_block_stateless(struct isal_zstream *stream, uint32_t stored_len,
uint32_t crc32);
#ifndef DEFLATE
static int write_gzip_header_stateless(struct isal_zstream *stream);
#endif
static int write_deflate_header_stateless(struct isal_zstream *stream);
static int write_deflate_header_unaligned_stateless(struct isal_zstream *stream);
static int write_trailer_stateless(struct isal_zstream *stream, uint32_t avail_in,
uint32_t crc32);
static int write_trailer_stateless(struct isal_zstream *stream);
unsigned int detect_repeated_char(uint8_t * buf, uint32_t size);
@ -207,10 +201,7 @@ static void flush_write_buffer(struct isal_zstream *stream)
static void isal_deflate_pass(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
#ifndef DEFLATE
uint8_t *start_in = stream->next_in;
#endif
if (state->state == ZSTATE_NEW_HDR || state->state == ZSTATE_HDR)
write_header(stream);
@ -227,9 +218,9 @@ static void isal_deflate_pass(struct isal_zstream *stream)
if (state->state == ZSTATE_FLUSH_WRITE_BUFFER)
flush_write_buffer(stream);
#ifndef DEFLATE
state->crc = crc32_gzip(state->crc, start_in, stream->next_in - start_in);
#endif
if (stream->gzip_flag)
state->crc = crc32_gzip(state->crc, start_in, stream->next_in - start_in);
if (state->state == ZSTATE_TRL)
write_trailer(stream);
}
@ -312,9 +303,8 @@ static uint32_t write_constant_compressed_stateless(struct isal_zstream *stream,
uint32_t rep_bytes = rep_bits / 8;
uint32_t rep_extra = (repeated_length - 1) % 258;
uint32_t bytes;
#ifndef DEFLATE
uint8_t *start_in = stream->next_in;
#endif
/* Guarantee there is enough space for the header even in the worst case */
if (stream->avail_out < HEADER_LENGTH + MAX_FIXUP_CODE_LENGTH + rep_bytes + 8)
return STATELESS_OVERFLOW;
@ -385,9 +375,9 @@ static uint32_t write_constant_compressed_stateless(struct isal_zstream *stream,
stream->avail_out -= bytes;
stream->total_out += bytes;
#ifndef DEFLATE
state->crc = crc32_gzip(state->crc, start_in, stream->next_in - start_in);
#endif
if (stream->gzip_flag)
state->crc = crc32_gzip(state->crc, start_in, stream->next_in - start_in);
return COMP_OK;
}
@ -409,21 +399,16 @@ int detect_repeated_char_length(uint8_t * in, uint32_t length)
return p_8 - in;
}
static int isal_deflate_int_stateless(struct isal_zstream *stream, uint8_t * next_in,
const uint32_t avail_in)
static int isal_deflate_int_stateless(struct isal_zstream *stream)
{
uint32_t crc32 = 0;
uint32_t repeated_char_length;
struct isal_zstate *state = &stream->internal_state;
state->state = ZSTATE_NEW_HDR;
state->crc = 0;
#ifndef DEFLATE
if (write_gzip_header_stateless(stream))
return STATELESS_OVERFLOW;
#endif
if (stream->gzip_flag)
if (write_gzip_header_stateless(stream))
return STATELESS_OVERFLOW;
if (avail_in >= 8
if (stream->avail_in >= 8
&& (*(uint64_t *) stream->next_in == 0
|| *(uint64_t *) stream->next_in == ~(uint64_t) 0))
repeated_char_length =
@ -439,7 +424,7 @@ static int isal_deflate_int_stateless(struct isal_zstream *stream, uint8_t * nex
return STATELESS_OVERFLOW;
if (state->has_eob_hdr) {
if (write_trailer_stateless(stream, avail_in, crc32) != COMP_OK)
if (write_trailer_stateless(stream) != COMP_OK)
return STATELESS_OVERFLOW;
} else if (stream->avail_out >= 8) {
sync_flush_stateless(stream);
@ -479,10 +464,7 @@ static int write_stored_block_stateless(struct isal_zstream *stream,
uint64_t stored_blk_hdr;
uint32_t copy_size;
uint32_t avail_in;
#ifndef DEFLATE
uint64_t gzip_trl;
#endif
if (stream->avail_out < stored_len)
return STATELESS_OVERFLOW;
@ -491,10 +473,10 @@ static int write_stored_block_stateless(struct isal_zstream *stream,
stream->total_out += stored_len;
avail_in = stream->avail_in;
#ifndef DEFLATE
memcpy(stream->next_out, gzip_hdr, gzip_hdr_bytes);
stream->next_out += gzip_hdr_bytes;
#endif
if (stream->gzip_flag) {
memcpy(stream->next_out, gzip_hdr, gzip_hdr_bytes);
stream->next_out += gzip_hdr_bytes;
}
do {
if (avail_in >= STORED_BLK_MAX_BZ) {
@ -525,15 +507,13 @@ static int write_stored_block_stateless(struct isal_zstream *stream,
stream->total_in += copy_size;
} while (avail_in != 0);
#ifndef DEFLATE
if (stream->internal_state.has_eob_hdr) {
if (stream->gzip_flag && stream->internal_state.has_eob_hdr) {
gzip_trl = stream->avail_in;
gzip_trl <<= 32;
gzip_trl |= crc32 & 0xFFFFFFFF;
memcpy(stream->next_out, &gzip_trl, gzip_trl_bytes);
stream->next_out += gzip_trl_bytes;
}
#endif
stream->avail_in = 0;
return COMP_OK;
@ -562,6 +542,7 @@ void isal_deflate_init(struct isal_zstream *stream)
stream->total_out = 0;
stream->hufftables = (struct isal_hufftables *)&hufftables_default;
stream->flush = 0;
stream->gzip_flag = 0;
state->b_bytes_valid = 0;
state->b_bytes_processed = 0;
@ -593,6 +574,7 @@ void isal_deflate_stateless_init(struct isal_zstream *stream)
stream->hufftables = (struct isal_hufftables *)&hufftables_default;
stream->flush = NO_FLUSH;
stream->end_of_stream = 0;
stream->gzip_flag = 0;
return;
}
@ -624,6 +606,9 @@ int isal_deflate_stateless(struct isal_zstream *stream)
/* Final block has already been written */
stream->internal_state.has_eob_hdr = 0;
init(&stream->internal_state.bitbuf);
stream->internal_state.state = ZSTATE_NEW_HDR;
stream->internal_state.crc = 0;
if (stream->flush == NO_FLUSH)
stream->end_of_stream = 1;
@ -643,10 +628,11 @@ int isal_deflate_stateless(struct isal_zstream *stream)
*/
dyn_min_len = stream->hufftables->deflate_hdr_count + 1;
#ifndef DEFLATE
dyn_min_len += gzip_hdr_bytes + gzip_trl_bytes + 1;
stored_len += gzip_hdr_bytes + gzip_trl_bytes;
#endif
if (stream->gzip_flag) {
dyn_min_len += gzip_hdr_bytes + gzip_trl_bytes + 1;
stored_len += gzip_hdr_bytes + gzip_trl_bytes;
}
min_len = dyn_min_len;
@ -663,7 +649,7 @@ int isal_deflate_stateless(struct isal_zstream *stream)
return STATELESS_OVERFLOW;
if (!select_stored_blk) {
if (isal_deflate_int_stateless(stream, next_in, avail_in) == COMP_OK)
if (isal_deflate_int_stateless(stream) == COMP_OK)
return COMP_OK;
else {
if (stream->flush == FULL_FLUSH) {
@ -686,9 +672,9 @@ int isal_deflate_stateless(struct isal_zstream *stream)
stream->avail_out = avail_out;
stream->total_out = total_out;
#ifndef DEFLATE
crc32 = crc32_gzip(0x0, next_in, avail_in);
#endif
if (stream->gzip_flag)
crc32 = crc32_gzip(0x0, next_in, avail_in);
return write_stored_block_stateless(stream, stored_len, crc32);
}
@ -789,7 +775,6 @@ int isal_deflate(struct isal_zstream *stream)
return ret;
}
#ifndef DEFLATE
static int write_gzip_header_stateless(struct isal_zstream *stream)
{
if (gzip_hdr_bytes >= stream->avail_out)
@ -828,7 +813,6 @@ static void write_gzip_header(struct isal_zstream *stream)
stream->next_out += bytes_to_write;
}
#endif
static int write_deflate_header_stateless(struct isal_zstream *stream)
{
@ -952,10 +936,9 @@ void write_header(struct isal_zstream *stream)
stream->avail_out -= count;
stream->total_out += count;
}
#ifndef DEFLATE
if (!state->has_gzip_hdr)
if (stream->gzip_flag && !state->has_gzip_hdr)
write_gzip_header(stream);
#endif
count = hufftables->deflate_hdr_count - state->count;
@ -1003,6 +986,7 @@ void write_trailer(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
unsigned int bytes;
uint32_t crc = state->crc;
if (stream->avail_out >= 8) {
set_buf(&state->bitbuf, stream->next_out, stream->avail_out);
@ -1031,27 +1015,23 @@ void write_trailer(struct isal_zstream *stream)
stream->next_out = buffer_ptr(&state->bitbuf);
bytes = buffer_used(&state->bitbuf);
#ifndef DEFLATE
uint32_t crc = state->crc;
if (!is_full(&state->bitbuf)) {
*(uint64_t *) stream->next_out =
((uint64_t) stream->total_in << 32) | crc;
stream->next_out += 8;
bytes += 8;
if (stream->gzip_flag) {
if (!is_full(&state->bitbuf)) {
*(uint64_t *) stream->next_out =
((uint64_t) stream->total_in << 32) | crc;
stream->next_out += 8;
bytes += 8;
state->state = ZSTATE_END;
}
} else
state->state = ZSTATE_END;
}
#else
state->state = ZSTATE_END;
#endif
stream->avail_out -= bytes;
stream->total_out += bytes;
}
}
static int write_trailer_stateless(struct isal_zstream *stream, uint32_t avail_in,
uint32_t crc32)
static int write_trailer_stateless(struct isal_zstream *stream)
{
int ret = COMP_OK;
struct isal_zstate *state = &stream->internal_state;
@ -1068,15 +1048,16 @@ static int write_trailer_stateless(struct isal_zstream *stream, uint32_t avail_i
flush(&state->bitbuf);
stream->next_out = buffer_ptr(&state->bitbuf);
bytes = buffer_used(&state->bitbuf);
#ifndef DEFLATE
if (is_full(&state->bitbuf)) {
ret = STATELESS_OVERFLOW;
} else {
*(uint64_t *) stream->next_out = ((uint64_t) avail_in << 32) | crc32;
stream->next_out += 8;
bytes += 8;
if (stream->gzip_flag) {
if (is_full(&state->bitbuf)) {
ret = STATELESS_OVERFLOW;
} else {
*(uint64_t *) stream->next_out =
((uint64_t) stream->total_in << 32) | state->crc;
stream->next_out += 8;
bytes += 8;
}
}
#endif
stream->avail_out -= bytes;
stream->total_out += bytes;
}

View File

@ -44,10 +44,6 @@
#define IBUF_SIZE (1024*1024)
#ifndef IGZIP_USE_GZIP_FORMAT
# define DEFLATE 1
#endif
#define str1 "Short test string"
#define str2 "one two three four five six seven eight nine ten eleven twelve " \
"thirteen fourteen fifteen sixteen"
@ -92,7 +88,6 @@ enum IGZIP_TEST_ERROR_CODES {
const int hdr_bytes = 300;
#ifndef DEFLATE
const uint8_t gzip_hdr[10] = {
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xff
@ -101,15 +96,8 @@ const uint8_t gzip_hdr[10] = {
const uint32_t gzip_hdr_bytes = 10;
const uint32_t gzip_trl_bytes = 8;
const int trl_bytes = 8;
const int gzip_extra_bytes = 18;
#else
const int trl_bytes = 0;
const int gzip_extra_bytes = 0;
#endif
#define HISTORY_SIZE 32*1024
#define MIN_LENGTH 3
#define MIN_DIST 1
@ -267,7 +255,6 @@ void print_uint8_t(uint8_t * array, uint64_t length)
printf("\n");
}
#ifndef DEFLATE
uint32_t check_gzip_header(uint8_t * z_buf)
{
/* These values are defined in RFC 1952 page 4 */
@ -315,10 +302,10 @@ uint32_t check_gzip_trl(struct inflate_state * gstream)
return ret;
}
#endif
/* Inflate the compressed data and check that the decompressed data agrees with the input data */
int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size)
int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size,
uint32_t gzip_flag)
{
/* Test inflate with reference inflate */
@ -326,7 +313,7 @@ int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size)
struct inflate_state gstream;
uint32_t test_size = in_size;
uint8_t *test_buf = NULL;
int mem_result = 0;
int mem_result = 0, gzip_hdr_result = 0, gzip_trl_result = 0;
assert(in_buf != NULL);
@ -339,13 +326,12 @@ int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size)
if (test_buf != NULL)
memset(test_buf, 0xff, test_size);
#ifndef DEFLATE
int gzip_hdr_result, gzip_trl_result;
if (gzip_flag) {
gzip_hdr_result = check_gzip_header(z_buf);
z_buf += gzip_hdr_bytes;
z_size -= gzip_hdr_bytes;
#endif
gzip_hdr_result = check_gzip_header(z_buf);
z_buf += gzip_hdr_bytes;
z_size -= gzip_hdr_bytes;
}
isal_inflate_init(&gstream);
gstream.next_in = z_buf;
@ -370,11 +356,11 @@ int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size)
}
#endif
#ifndef DEFLATE
gzip_trl_result = check_gzip_trl(&gstream);
gstream.avail_in -= gzip_trl_bytes;
gstream.next_in += gzip_trl_bytes;
#endif
if (gzip_flag) {
gzip_trl_result = check_gzip_trl(&gstream);
gstream.avail_in -= gzip_trl_bytes;
gstream.next_in += gzip_trl_bytes;
}
if (test_buf != NULL)
free(test_buf);
@ -411,13 +397,13 @@ int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size)
if (mem_result)
return RESULT_ERROR;
#ifndef DEFLATE
if (gzip_hdr_result)
return INVALID_GZIP_HEADER;
if (gzip_flag) {
if (gzip_hdr_result)
return INVALID_GZIP_HEADER;
if (gzip_trl_result)
return INCORRECT_GZIP_TRAILER;
#endif
if (gzip_trl_result)
return INCORRECT_GZIP_TRAILER;
}
return 0;
}
@ -519,7 +505,7 @@ int isal_deflate_with_checks(struct isal_zstream *stream, uint32_t data_size,
* output buffer are randomly segmented to test state information for the
* compression*/
int compress_multi_pass(uint8_t * data, uint32_t data_size, uint8_t * compressed_buf,
uint32_t * compressed_size, uint32_t flush_type)
uint32_t * compressed_size, uint32_t flush_type, uint32_t gzip_flag)
{
int ret = IGZIP_COMP_OK;
uint8_t *in_buf = NULL, *out_buf = NULL;
@ -546,6 +532,7 @@ int compress_multi_pass(uint8_t * data, uint32_t data_size, uint8_t * compressed
/* These are set here to allow the loop to run correctly */
stream.avail_in = 0;
stream.avail_out = 0;
stream.gzip_flag = gzip_flag;
while (1) {
loop_count++;
@ -651,7 +638,7 @@ int compress_multi_pass(uint8_t * data, uint32_t data_size, uint8_t * compressed
/* Compress the input data into the outbuffer in one call to isal_deflate */
int compress_single_pass(uint8_t * data, uint32_t data_size, uint8_t * compressed_buf,
uint32_t * compressed_size, uint32_t flush_type)
uint32_t * compressed_size, uint32_t flush_type, uint32_t gzip_flag)
{
int ret = IGZIP_COMP_OK;
struct isal_zstream stream;
@ -674,6 +661,7 @@ int compress_single_pass(uint8_t * data, uint32_t data_size, uint8_t * compresse
stream.avail_out = *compressed_size;
stream.next_out = compressed_buf;
stream.end_of_stream = 1;
stream.gzip_flag = gzip_flag;
ret =
isal_deflate_with_checks(&stream, data_size, *compressed_size, data, data_size,
@ -691,7 +679,7 @@ int compress_single_pass(uint8_t * data, uint32_t data_size, uint8_t * compresse
/* Statelessly compress the input buffer into the output buffer */
int compress_stateless(uint8_t * data, uint32_t data_size, uint8_t * compressed_buf,
uint32_t * compressed_size)
uint32_t * compressed_size, uint32_t gzip_flag)
{
int ret = IGZIP_COMP_OK;
struct isal_zstream stream;
@ -707,6 +695,7 @@ int compress_stateless(uint8_t * data, uint32_t data_size, uint8_t * compressed_
stream.avail_out = *compressed_size;
stream.next_out = compressed_buf;
stream.gzip_flag = gzip_flag;
ret = isal_deflate_stateless(&stream);
@ -742,7 +731,7 @@ int compress_stateless(uint8_t * data, uint32_t data_size, uint8_t * compressed_
/*Compress the input buffer into the output buffer, but switch the flush type in
* the middle of the compression to test what happens*/
int compress_swap_flush(uint8_t * data, uint32_t data_size, uint8_t * compressed_buf,
uint32_t * compressed_size, uint32_t flush_type)
uint32_t * compressed_size, uint32_t flush_type, uint32_t gzip_flag)
{
int ret = IGZIP_COMP_OK;
struct isal_zstream stream;
@ -766,6 +755,7 @@ int compress_swap_flush(uint8_t * data, uint32_t data_size, uint8_t * compressed
stream.avail_out = *compressed_size;
stream.next_out = compressed_buf;
stream.end_of_stream = 0;
stream.gzip_flag = gzip_flag;
ret =
isal_deflate_with_checks(&stream, data_size, *compressed_size, data, partial_size,
@ -801,11 +791,16 @@ int compress_swap_flush(uint8_t * data, uint32_t data_size, uint8_t * compressed
int test_compress_stateless(uint8_t * in_buf, uint32_t in_size)
{
int ret = IGZIP_COMP_OK;
uint32_t z_size, overflow;
uint32_t z_size, overflow, gzip_flag;
uint8_t *z_buf = NULL;
gzip_flag = rand() % 2;
/* Test non-overflow case where a type 0 block is not written */
z_size = 2 * in_size + hdr_bytes + trl_bytes;
z_size = 2 * in_size + hdr_bytes;
if (gzip_flag)
z_size += gzip_extra_bytes;
z_buf = malloc(z_size);
@ -813,10 +808,10 @@ int test_compress_stateless(uint8_t * in_buf, uint32_t in_size)
return MALLOC_FAILED;
create_rand_repeat_data(z_buf, z_size);
ret = compress_stateless(in_buf, in_size, z_buf, &z_size);
ret = compress_stateless(in_buf, in_size, z_buf, &z_size, gzip_flag);
if (!ret)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
if (z_buf != NULL) {
free(z_buf);
@ -826,9 +821,9 @@ int test_compress_stateless(uint8_t * in_buf, uint32_t in_size)
print_error(ret);
/*Test non-overflow case where a type 0 block is possible to be written */
z_size =
TYPE0_HDR_SIZE * ((in_size + TYPE0_MAX_SIZE - 1) / TYPE0_MAX_SIZE) + in_size +
gzip_extra_bytes;
z_size = TYPE0_HDR_SIZE * ((in_size + TYPE0_MAX_SIZE - 1) / TYPE0_MAX_SIZE) + in_size;
if (gzip_flag)
z_size += gzip_extra_bytes;
if (z_size == gzip_extra_bytes)
z_size += TYPE0_HDR_SIZE;
@ -843,9 +838,9 @@ int test_compress_stateless(uint8_t * in_buf, uint32_t in_size)
create_rand_repeat_data(z_buf, z_size);
ret = compress_stateless(in_buf, in_size, z_buf, &z_size);
ret = compress_stateless(in_buf, in_size, z_buf, &z_size, gzip_flag);
if (!ret)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
#ifdef VERBOSE
if (ret) {
printf("Compressed array: ");
@ -873,7 +868,7 @@ int test_compress_stateless(uint8_t * in_buf, uint32_t in_size)
return MALLOC_FAILED;
}
overflow = compress_stateless(in_buf, in_size, z_buf, &z_size);
overflow = compress_stateless(in_buf, in_size, z_buf, &z_size, gzip_flag);
if (overflow != COMPRESS_OUT_BUFFER_OVERFLOW) {
#ifdef VERBOSE
@ -906,20 +901,24 @@ int test_compress_stateless(uint8_t * in_buf, uint32_t in_size)
int test_compress(uint8_t * in_buf, uint32_t in_size, uint32_t flush_type)
{
int ret = IGZIP_COMP_OK, fin_ret = IGZIP_COMP_OK;
uint32_t overflow = 0;
uint32_t overflow = 0, gzip_flag;
uint32_t z_size, z_size_max, z_compressed_size;
uint8_t *z_buf = NULL;
/* Test a non overflow case */
if (flush_type == NO_FLUSH)
z_size_max = 2 * in_size + hdr_bytes + trl_bytes + 2;
z_size_max = 2 * in_size + hdr_bytes + 2;
else if (flush_type == SYNC_FLUSH)
z_size_max = 2 * in_size + MAX_LOOPS * (hdr_bytes + trl_bytes + 5);
z_size_max = 2 * in_size + MAX_LOOPS * (hdr_bytes + 5);
else {
printf("Invalid Flush Parameter\n");
return COMPRESS_GENERAL_ERROR;
}
gzip_flag = rand() % 2;
if (gzip_flag)
z_size_max += gzip_extra_bytes;
z_size = z_size_max;
z_buf = malloc(z_size);
@ -929,10 +928,10 @@ int test_compress(uint8_t * in_buf, uint32_t in_size, uint32_t flush_type)
}
create_rand_repeat_data(z_buf, z_size_max);
ret = compress_single_pass(in_buf, in_size, z_buf, &z_size, flush_type);
ret = compress_single_pass(in_buf, in_size, z_buf, &z_size, flush_type, gzip_flag);
if (!ret)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
if (ret) {
#ifdef VERBOSE
@ -952,10 +951,10 @@ int test_compress(uint8_t * in_buf, uint32_t in_size, uint32_t flush_type)
z_size = z_size_max;
create_rand_repeat_data(z_buf, z_size_max);
ret = compress_multi_pass(in_buf, in_size, z_buf, &z_size, flush_type);
ret = compress_multi_pass(in_buf, in_size, z_buf, &z_size, flush_type, gzip_flag);
if (!ret)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
if (ret) {
#ifdef VERBOSE
@ -980,11 +979,12 @@ int test_compress(uint8_t * in_buf, uint32_t in_size, uint32_t flush_type)
z_size = rand() % z_compressed_size;
create_rand_repeat_data(z_buf, z_size_max);
overflow = compress_single_pass(in_buf, in_size, z_buf, &z_size, flush_type);
overflow =
compress_single_pass(in_buf, in_size, z_buf, &z_size, flush_type, gzip_flag);
if (overflow != COMPRESS_OUT_BUFFER_OVERFLOW) {
if (overflow == 0)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
/* Rarely single pass overflow will compresses data
* better than the initial run. This is to stop that
@ -1013,11 +1013,13 @@ int test_compress(uint8_t * in_buf, uint32_t in_size, uint32_t flush_type)
if (flush_type == NO_FLUSH) {
create_rand_repeat_data(z_buf, z_size_max);
overflow = compress_multi_pass(in_buf, in_size, z_buf, &z_size, flush_type);
overflow =
compress_multi_pass(in_buf, in_size, z_buf, &z_size, flush_type,
gzip_flag);
if (overflow != COMPRESS_OUT_BUFFER_OVERFLOW) {
if (overflow == 0)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
/* Rarely multi pass overflow will compresses data
* better than the initial run. This is to stop that
@ -1052,10 +1054,14 @@ int test_compress(uint8_t * in_buf, uint32_t in_size, uint32_t flush_type)
int test_flush(uint8_t * in_buf, uint32_t in_size)
{
int fin_ret = IGZIP_COMP_OK, ret;
uint32_t z_size, flush_type = 0;
uint32_t z_size, flush_type = 0, gzip_flag;
uint8_t *z_buf = NULL;
z_size = 2 * in_size + 2 * (hdr_bytes + trl_bytes) + 8;
z_size = 2 * in_size + 2 * hdr_bytes + 8;
gzip_flag = rand() % 2;
if (gzip_flag)
z_size += gzip_extra_bytes;
z_buf = malloc(z_size);
@ -1068,7 +1074,7 @@ int test_flush(uint8_t * in_buf, uint32_t in_size)
flush_type = rand();
/* Test invalid flush */
ret = compress_single_pass(in_buf, in_size, z_buf, &z_size, flush_type);
ret = compress_single_pass(in_buf, in_size, z_buf, &z_size, flush_type, gzip_flag);
if (ret == COMPRESS_GENERAL_ERROR)
ret = 0;
@ -1083,10 +1089,10 @@ int test_flush(uint8_t * in_buf, uint32_t in_size)
create_rand_repeat_data(z_buf, z_size);
/* Test the valid case of SYNC_FLUSH followed by NO_FLUSH */
ret = compress_swap_flush(in_buf, in_size, z_buf, &z_size, rand() % 2);
ret = compress_swap_flush(in_buf, in_size, z_buf, &z_size, rand() % 2, gzip_flag);
if (!ret)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
if (ret) {
#ifdef VERBOSE

View File

@ -44,10 +44,6 @@
#define IBUF_SIZE (1024*1024)
#ifndef IGZIP_USE_GZIP_FORMAT
# define DEFLATE 1
#endif
#define PAGE_SIZE 4*1024
#define str1 "Short test string"
@ -93,7 +89,6 @@ enum IGZIP_TEST_ERROR_CODES {
const int hdr_bytes = 300;
#ifndef DEFLATE
const uint8_t gzip_hdr[10] = {
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xff
@ -102,14 +97,8 @@ const uint8_t gzip_hdr[10] = {
const uint32_t gzip_hdr_bytes = 10;
const uint32_t gzip_trl_bytes = 8;
const int trl_bytes = 8;
const int gzip_extra_bytes = 18;
#else
const int trl_bytes = 0;
const int gzip_extra_bytes = 0;
#endif
const int gzip_extra_bytes = 18;
int inflate_type = 0;
@ -269,7 +258,6 @@ void print_uint8_t(uint8_t * array, uint64_t length)
printf("\n");
}
#ifndef DEFLATE
uint32_t check_gzip_header(uint8_t * z_buf)
{
/* These values are defined in RFC 1952 page 4 */
@ -316,10 +304,10 @@ uint32_t check_gzip_trl(uint64_t gzip_crc, uint8_t * uncompress_buf, uint32_t un
return ret;
}
#endif
int inflate_stateless_pass(uint8_t * compress_buf, uint64_t compress_len,
uint8_t * uncompress_buf, uint32_t * uncompress_len)
uint8_t * uncompress_buf, uint32_t * uncompress_len,
uint32_t gzip_flag)
{
struct inflate_state state;
int ret = 0;
@ -333,13 +321,13 @@ int inflate_stateless_pass(uint8_t * compress_buf, uint64_t compress_len,
*uncompress_len = state.total_out;
#ifndef DEFLATE
if (!ret)
ret =
check_gzip_trl(*(uint64_t *) state.next_in, uncompress_buf,
*uncompress_len);
state.avail_in -= 8;
#endif
if (gzip_flag) {
if (!ret)
ret =
check_gzip_trl(*(uint64_t *) state.next_in, uncompress_buf,
*uncompress_len);
state.avail_in -= 8;
}
if (ret == 0 && state.avail_in != 0)
ret = INFLATE_LEFTOVER_INPUT;
@ -348,7 +336,7 @@ int inflate_stateless_pass(uint8_t * compress_buf, uint64_t compress_len,
}
int inflate_multi_pass(uint8_t * compress_buf, uint64_t compress_len,
uint8_t * uncompress_buf, uint32_t * uncompress_len)
uint8_t * uncompress_buf, uint32_t * uncompress_len, uint32_t gzip_flag)
{
struct inflate_state *state = NULL;
int ret = 0;
@ -370,9 +358,8 @@ int inflate_multi_pass(uint8_t * compress_buf, uint64_t compress_len,
state->avail_in = 0;
state->avail_out = 0;
#ifndef DEFLATE
compress_len -= 8;
#endif
if (gzip_flag)
compress_len -= 8;
while (1) {
if (state->avail_in == 0) {
@ -460,12 +447,12 @@ int inflate_multi_pass(uint8_t * compress_buf, uint64_t compress_len,
}
}
#ifndef DEFLATE
if (!ret)
ret =
check_gzip_trl(*(uint64_t *) & compress_buf[compress_len],
uncompress_buf, *uncompress_len);
#endif
if (gzip_flag) {
if (!ret)
ret =
check_gzip_trl(*(uint64_t *) & compress_buf[compress_len],
uncompress_buf, *uncompress_len);
}
if (ret == 0 && state->avail_in != 0)
ret = INFLATE_LEFTOVER_INPUT;
@ -484,7 +471,8 @@ int inflate_multi_pass(uint8_t * compress_buf, uint64_t compress_len,
}
/* Inflate the compressed data and check that the decompressed data agrees with the input data */
int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size)
int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size,
uint32_t gzip_flag)
{
/* Test inflate with reference inflate */
@ -492,6 +480,7 @@ int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size)
uint32_t test_size = in_size;
uint8_t *test_buf = NULL;
int mem_result = 0;
int gzip_hdr_result = 0, gzip_trl_result = 0;
if (in_size > 0) {
assert(in_buf != NULL);
@ -503,18 +492,17 @@ int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size)
if (test_buf != NULL)
memset(test_buf, 0xff, test_size);
#ifndef DEFLATE
int gzip_hdr_result = 0, gzip_trl_result = 0;
gzip_hdr_result = check_gzip_header(z_buf);
z_buf += gzip_hdr_bytes;
z_size -= gzip_hdr_bytes;
#endif
if (gzip_flag) {
gzip_hdr_result = check_gzip_header(z_buf);
z_buf += gzip_hdr_bytes;
z_size -= gzip_hdr_bytes;
}
if (inflate_type == 0) {
ret = inflate_stateless_pass(z_buf, z_size, test_buf, &test_size);
ret = inflate_stateless_pass(z_buf, z_size, test_buf, &test_size, gzip_flag);
inflate_type = 1;
} else {
ret = inflate_multi_pass(z_buf, z_size, test_buf, &test_size);
ret = inflate_multi_pass(z_buf, z_size, test_buf, &test_size, gzip_flag);
inflate_type = 0;
}
@ -557,13 +545,10 @@ int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size)
case INFLATE_LEFTOVER_INPUT:
return INFLATE_LEFTOVER_INPUT;
break;
#ifndef DEFLATE
case INCORRECT_GZIP_TRAILER:
gzip_trl_result = INCORRECT_GZIP_TRAILER;
break;
#endif
default:
return INFLATE_GENERAL_ERROR;
break;
@ -575,13 +560,13 @@ int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size)
if (mem_result)
return RESULT_ERROR;
#ifndef DEFLATE
if (gzip_hdr_result)
return INVALID_GZIP_HEADER;
if (gzip_flag) {
if (gzip_hdr_result)
return INVALID_GZIP_HEADER;
if (gzip_trl_result)
return INCORRECT_GZIP_TRAILER;
#endif
if (gzip_trl_result)
return INCORRECT_GZIP_TRAILER;
}
return 0;
}
@ -683,7 +668,7 @@ int isal_deflate_with_checks(struct isal_zstream *stream, uint32_t data_size,
* output buffer are randomly segmented to test state information for the
* compression*/
int compress_multi_pass(uint8_t * data, uint32_t data_size, uint8_t * compressed_buf,
uint32_t * compressed_size, uint32_t flush_type)
uint32_t * compressed_size, uint32_t flush_type, uint32_t gzip_flag)
{
int ret = IGZIP_COMP_OK;
uint8_t *in_buf = NULL, *out_buf = NULL;
@ -713,6 +698,7 @@ int compress_multi_pass(uint8_t * data, uint32_t data_size, uint8_t * compressed
/* These are set here to allow the loop to run correctly */
stream.avail_in = 0;
stream.avail_out = 0;
stream.gzip_flag = gzip_flag;
while (1) {
loop_count++;
@ -818,7 +804,7 @@ int compress_multi_pass(uint8_t * data, uint32_t data_size, uint8_t * compressed
/* Compress the input data into the outbuffer in one call to isal_deflate */
int compress_single_pass(uint8_t * data, uint32_t data_size, uint8_t * compressed_buf,
uint32_t * compressed_size, uint32_t flush_type)
uint32_t * compressed_size, uint32_t flush_type, uint32_t gzip_flag)
{
int ret = IGZIP_COMP_OK;
struct isal_zstream stream;
@ -844,6 +830,7 @@ int compress_single_pass(uint8_t * data, uint32_t data_size, uint8_t * compresse
stream.avail_out = *compressed_size;
stream.next_out = compressed_buf;
stream.end_of_stream = 1;
stream.gzip_flag = gzip_flag;
ret =
isal_deflate_with_checks(&stream, data_size, *compressed_size, data, data_size,
@ -861,7 +848,7 @@ int compress_single_pass(uint8_t * data, uint32_t data_size, uint8_t * compresse
/* Statelessly compress the input buffer into the output buffer */
int compress_stateless(uint8_t * data, uint32_t data_size, uint8_t * compressed_buf,
uint32_t * compressed_size, uint32_t flush_type)
uint32_t * compressed_size, uint32_t flush_type, uint32_t gzip_flag)
{
int ret = IGZIP_COMP_OK;
struct isal_zstream stream;
@ -880,6 +867,7 @@ int compress_stateless(uint8_t * data, uint32_t data_size, uint8_t * compressed_
stream.end_of_stream = 1;
stream.avail_out = *compressed_size;
stream.next_out = compressed_buf;
stream.gzip_flag = gzip_flag;
ret = isal_deflate_stateless(&stream);
@ -982,7 +970,7 @@ int compress_stateless_full_flush(uint8_t * data, uint32_t data_size, uint8_t *
break;
/* Verify that blocks are independent */
ret = inflate_check(out_buf, stream.next_out - out_buf, in_buf, in_size);
ret = inflate_check(out_buf, stream.next_out - out_buf, in_buf, in_size, 0);
if (ret == INFLATE_INVALID_LOOK_BACK_DISTANCE) {
break;
@ -1011,7 +999,7 @@ int compress_stateless_full_flush(uint8_t * data, uint32_t data_size, uint8_t *
* is randomly segmented to test for independence of blocks in full flush
* compression*/
int compress_full_flush(uint8_t * data, uint32_t data_size, uint8_t * compressed_buf,
uint32_t * compressed_size)
uint32_t * compressed_size, uint32_t gzip_flag)
{
int ret = IGZIP_COMP_OK;
uint8_t *in_buf = NULL, *out_buf = compressed_buf;
@ -1040,6 +1028,7 @@ int compress_full_flush(uint8_t * data, uint32_t data_size, uint8_t * compressed
stream.avail_out = *compressed_size;
stream.next_out = compressed_buf;
stream.total_out = 0;
stream.gzip_flag = gzip_flag;
while (1) {
loop_count++;
@ -1085,7 +1074,8 @@ int compress_full_flush(uint8_t * data, uint32_t data_size, uint8_t * compressed
/* Verify that blocks are independent */
if (state->state == ZSTATE_NEW_HDR || state->state == ZSTATE_END) {
ret =
inflate_check(out_buf, stream.next_out - out_buf, in_buf, in_size);
inflate_check(out_buf, stream.next_out - out_buf, in_buf, in_size,
0);
if (ret == INFLATE_INVALID_LOOK_BACK_DISTANCE)
break;
@ -1114,7 +1104,7 @@ int compress_full_flush(uint8_t * data, uint32_t data_size, uint8_t * compressed
/*Compress the input buffer into the output buffer, but switch the flush type in
* the middle of the compression to test what happens*/
int compress_swap_flush(uint8_t * data, uint32_t data_size, uint8_t * compressed_buf,
uint32_t * compressed_size, uint32_t flush_type)
uint32_t * compressed_size, uint32_t flush_type, uint32_t gzip_flag)
{
int ret = IGZIP_COMP_OK;
struct isal_zstream stream;
@ -1141,6 +1131,7 @@ int compress_swap_flush(uint8_t * data, uint32_t data_size, uint8_t * compressed
stream.avail_out = *compressed_size;
stream.next_out = compressed_buf;
stream.end_of_stream = 0;
stream.gzip_flag = gzip_flag;
ret =
isal_deflate_with_checks(&stream, data_size, *compressed_size, data, partial_size,
@ -1173,10 +1164,12 @@ int compress_swap_flush(uint8_t * data, uint32_t data_size, uint8_t * compressed
int test_compress_stateless(uint8_t * in_data, uint32_t in_size, uint32_t flush_type)
{
int ret = IGZIP_COMP_OK;
uint32_t z_size, overflow;
uint32_t z_size, overflow, gzip_flag;
uint8_t *z_buf = NULL;
uint8_t *in_buf = NULL;
gzip_flag = rand() % 2;
if (in_size != 0) {
in_buf = malloc(in_size);
@ -1188,6 +1181,8 @@ int test_compress_stateless(uint8_t * in_data, uint32_t in_size, uint32_t flush_
/* Test non-overflow case where a type 0 block is not written */
z_size = 2 * in_size + hdr_bytes + trl_bytes;
if (gzip_flag)
z_size += gzip_extra_bytes;
z_buf = malloc(z_size);
@ -1198,7 +1193,8 @@ int test_compress_stateless(uint8_t * in_data, uint32_t in_size, uint32_t flush_
/* If flush type is invalid */
if (flush_type != NO_FLUSH && flush_type != FULL_FLUSH) {
ret = compress_stateless(in_buf, in_size, z_buf, &z_size, flush_type);
ret =
compress_stateless(in_buf, in_size, z_buf, &z_size, flush_type, gzip_flag);
if (ret != INVALID_FLUSH_ERROR)
print_error(ret);
@ -1215,10 +1211,10 @@ int test_compress_stateless(uint8_t * in_data, uint32_t in_size, uint32_t flush_
}
/* Else test valid flush type */
ret = compress_stateless(in_buf, in_size, z_buf, &z_size, flush_type);
ret = compress_stateless(in_buf, in_size, z_buf, &z_size, flush_type, gzip_flag);
if (!ret)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
#ifdef VERBOSE
if (ret) {
@ -1239,9 +1235,9 @@ int test_compress_stateless(uint8_t * in_data, uint32_t in_size, uint32_t flush_
return ret;
/*Test non-overflow case where a type 0 block is possible to be written */
z_size =
TYPE0_HDR_SIZE * ((in_size + TYPE0_MAX_SIZE - 1) / TYPE0_MAX_SIZE) + in_size +
gzip_extra_bytes;
z_size = TYPE0_HDR_SIZE * ((in_size + TYPE0_MAX_SIZE - 1) / TYPE0_MAX_SIZE) + in_size;
if (gzip_flag)
z_size += gzip_extra_bytes;
if (z_size == gzip_extra_bytes)
z_size += TYPE0_HDR_SIZE;
@ -1256,9 +1252,9 @@ int test_compress_stateless(uint8_t * in_data, uint32_t in_size, uint32_t flush_
create_rand_repeat_data(z_buf, z_size);
ret = compress_stateless(in_buf, in_size, z_buf, &z_size, flush_type);
ret = compress_stateless(in_buf, in_size, z_buf, &z_size, flush_type, gzip_flag);
if (!ret)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
#ifdef VERBOSE
if (ret) {
printf("Compressed array: ");
@ -1286,14 +1282,16 @@ int test_compress_stateless(uint8_t * in_data, uint32_t in_size, uint32_t flush_
return MALLOC_FAILED;
}
overflow = compress_stateless(in_buf, in_size, z_buf, &z_size, flush_type);
overflow =
compress_stateless(in_buf, in_size, z_buf, &z_size, flush_type, gzip_flag);
if (overflow != COMPRESS_OUT_BUFFER_OVERFLOW) {
#ifdef VERBOSE
printf("overflow error = %d\n", overflow);
print_error(overflow);
if (overflow == 0) {
overflow = inflate_check(z_buf, z_size, in_buf, in_size);
overflow =
inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
printf("inflate ret = %d\n", overflow);
print_error(overflow);
}
@ -1334,7 +1332,7 @@ int test_compress_stateless(uint8_t * in_data, uint32_t in_size, uint32_t flush_
ret = compress_stateless_full_flush(in_buf, in_size, z_buf, &z_size);
if (!ret)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, 0);
else if (ret == COMPRESS_LOOP_COUNT_OVERFLOW)
ret = 0;
@ -1362,7 +1360,7 @@ int test_compress_stateless(uint8_t * in_data, uint32_t in_size, uint32_t flush_
int test_compress(uint8_t * in_buf, uint32_t in_size, uint32_t flush_type)
{
int ret = IGZIP_COMP_OK, fin_ret = IGZIP_COMP_OK;
uint32_t overflow = 0;
uint32_t overflow = 0, gzip_flag;
uint32_t z_size, z_size_max, z_compressed_size;
uint8_t *z_buf = NULL;
@ -1376,6 +1374,10 @@ int test_compress(uint8_t * in_buf, uint32_t in_size, uint32_t flush_type)
return COMPRESS_GENERAL_ERROR;
}
gzip_flag = rand() % 2;
if (gzip_flag)
z_size_max += gzip_extra_bytes;
z_size = z_size_max;
z_buf = malloc(z_size);
@ -1383,12 +1385,12 @@ int test_compress(uint8_t * in_buf, uint32_t in_size, uint32_t flush_type)
print_error(MALLOC_FAILED);
return MALLOC_FAILED;
}
create_rand_repeat_data(z_buf, z_size_max);
create_rand_repeat_data(z_buf, z_size);
ret = compress_single_pass(in_buf, in_size, z_buf, &z_size, flush_type);
ret = compress_single_pass(in_buf, in_size, z_buf, &z_size, flush_type, gzip_flag);
if (!ret)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
if (ret) {
#ifdef VERBOSE
@ -1408,10 +1410,10 @@ int test_compress(uint8_t * in_buf, uint32_t in_size, uint32_t flush_type)
z_size = z_size_max;
create_rand_repeat_data(z_buf, z_size_max);
ret = compress_multi_pass(in_buf, in_size, z_buf, &z_size, flush_type);
ret = compress_multi_pass(in_buf, in_size, z_buf, &z_size, flush_type, gzip_flag);
if (!ret)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
if (ret) {
#ifdef VERBOSE
@ -1436,11 +1438,12 @@ int test_compress(uint8_t * in_buf, uint32_t in_size, uint32_t flush_type)
z_size = rand() % z_compressed_size;
create_rand_repeat_data(z_buf, z_size_max);
overflow = compress_single_pass(in_buf, in_size, z_buf, &z_size, flush_type);
overflow =
compress_single_pass(in_buf, in_size, z_buf, &z_size, flush_type, gzip_flag);
if (overflow != COMPRESS_OUT_BUFFER_OVERFLOW) {
if (overflow == 0)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
/* Rarely single pass overflow will compresses data
* better than the initial run. This is to stop that
@ -1469,11 +1472,13 @@ int test_compress(uint8_t * in_buf, uint32_t in_size, uint32_t flush_type)
if (flush_type == NO_FLUSH) {
create_rand_repeat_data(z_buf, z_size_max);
overflow = compress_multi_pass(in_buf, in_size, z_buf, &z_size, flush_type);
overflow =
compress_multi_pass(in_buf, in_size, z_buf, &z_size, flush_type,
gzip_flag);
if (overflow != COMPRESS_OUT_BUFFER_OVERFLOW) {
if (overflow == 0)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
/* Rarely multi pass overflow will compresses data
* better than the initial run. This is to stop that
@ -1508,11 +1513,13 @@ int test_compress(uint8_t * in_buf, uint32_t in_size, uint32_t flush_type)
int test_flush(uint8_t * in_buf, uint32_t in_size)
{
int fin_ret = IGZIP_COMP_OK, ret;
uint32_t z_size, flush_type = 0;
uint32_t z_size, flush_type = 0, gzip_flag;
uint8_t *z_buf = NULL;
gzip_flag = rand() % 2;
z_size = 2 * in_size + 2 * (hdr_bytes + trl_bytes) + 8;
if (gzip_flag)
z_size += gzip_extra_bytes;
z_buf = malloc(z_size);
if (z_buf == NULL)
@ -1524,7 +1531,7 @@ int test_flush(uint8_t * in_buf, uint32_t in_size)
flush_type = rand();
/* Test invalid flush */
ret = compress_single_pass(in_buf, in_size, z_buf, &z_size, flush_type);
ret = compress_single_pass(in_buf, in_size, z_buf, &z_size, flush_type, gzip_flag);
if (ret == COMPRESS_GENERAL_ERROR)
ret = 0;
@ -1539,10 +1546,10 @@ int test_flush(uint8_t * in_buf, uint32_t in_size)
create_rand_repeat_data(z_buf, z_size);
/* Test swapping flush type */
ret = compress_swap_flush(in_buf, in_size, z_buf, &z_size, rand() % 3);
ret = compress_swap_flush(in_buf, in_size, z_buf, &z_size, rand() % 3, gzip_flag);
if (!ret)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
if (ret) {
#ifdef VERBOSE
@ -1566,11 +1573,15 @@ int test_flush(uint8_t * in_buf, uint32_t in_size)
int test_full_flush(uint8_t * in_buf, uint32_t in_size)
{
int ret = IGZIP_COMP_OK;
uint32_t z_size;
uint32_t z_size, gzip_flag;
uint8_t *z_buf = NULL;
gzip_flag = rand() % 2;
z_size = 2 * in_size + MAX_LOOPS * (hdr_bytes + trl_bytes + 5);
if (gzip_flag)
z_size += gzip_extra_bytes;
z_buf = malloc(z_size);
if (z_buf == NULL) {
print_error(MALLOC_FAILED);
@ -1579,10 +1590,10 @@ int test_full_flush(uint8_t * in_buf, uint32_t in_size)
create_rand_repeat_data(z_buf, z_size);
ret = compress_full_flush(in_buf, in_size, z_buf, &z_size);
ret = compress_full_flush(in_buf, in_size, z_buf, &z_size, gzip_flag);
if (!ret)
ret = inflate_check(z_buf, z_size, in_buf, in_size);
ret = inflate_check(z_buf, z_size, in_buf, in_size, gzip_flag);
if (ret) {
#ifdef VERBOSE
@ -1634,9 +1645,7 @@ int test_compress_file(char *file_name)
ret |= test_compress_stateless(in_buf, in_size, NO_FLUSH);
ret |= test_compress_stateless(in_buf, in_size, SYNC_FLUSH);
#ifndef IGZIP_USE_GZIP_FORMAT
ret |= test_compress_stateless(in_buf, in_size, FULL_FLUSH);
#endif
ret |= test_compress(in_buf, in_size, NO_FLUSH);
ret |= test_compress(in_buf, in_size, SYNC_FLUSH);
ret |= test_compress(in_buf, in_size, FULL_FLUSH);
@ -1819,7 +1828,6 @@ int main(int argc, char *argv[])
printf("%s\n", ret ? "Fail" : "Pass");
#ifndef IGZIP_USE_GZIP_FORMAT
printf("igzip_rand_test stateless FULL_FLUSH: ");
ret = test_compress_stateless((uint8_t *) str1, sizeof(str1), FULL_FLUSH);
@ -1857,7 +1865,6 @@ int main(int argc, char *argv[])
fin_ret |= ret;
printf("%s\n", ret ? "Fail" : "Pass");
#endif
printf("igzip_rand_test stateful NO_FLUSH: ");
@ -1948,7 +1955,6 @@ int main(int argc, char *argv[])
return ret;
}
#ifdef DEFLATE
for (i = 0; i < RANDOMS / 8; i++) {
in_size = rand() % (IBUF_SIZE + 1);
offset = rand() % (IBUF_SIZE + 1 - in_size);
@ -1963,7 +1969,6 @@ int main(int argc, char *argv[])
if (ret)
return ret;
}
#endif
fin_ret |= ret;

View File

@ -32,10 +32,6 @@ default rel
%ifndef __OPTIONS_ASM__
%define __OPTIONS_ASM__
%ifndef IGZIP_USE_GZIP_FORMAT
%define DEFLATE
%endif
; Options:dir
; m - reschedule mem reads
; e b - bitbuff style

View File

@ -62,13 +62,8 @@
* default this optoin is not defined. This define sets IGZIP_HIST_SIZE to be
* 8 if IGZIP_HIST_SIZE > 8K.
*
* - IGZIP_USE_GZIP_FORMAT - Defines whether the compression should add gzip
* header and trailer to compressed data. By default this option is not
* defined
*
* As an example, to compile gzip with an 8K window size and add the gzip
* header and trailer, in a terminal run @verbatim gmake D="-D
* IGZIP_HIST_SIZE=8*1024 -D IGZIP_USE_GZIP_FORMAT" @endverbatim on Linux and
* As an example, to compile gzip with an 8K window size, in a terminal run
* @verbatim gmake D="-D IGZIP_HIST_SIZE=8*1024" @endverbatim on Linux and
* FreeBSD, or with @verbatim nmake -f Makefile.nmake D="-D
* IGZIP_HIST_SIZE=8*1024" @endverbatim on Windows.
*
@ -276,6 +271,7 @@ struct isal_zstream {
struct isal_hufftables *hufftables; //!< Huffman encoding used when compressing
uint32_t end_of_stream; //!< non-zero if this is the last input buffer
uint32_t flush; //!< Flush type can be NO_FLUSH, SYNC_FLUSH or FULL_FLUSH
uint32_t gzip_flag; //!< Indicate if gzip compression is to be performed
struct isal_zstate internal_state; //!< Internal state for this stream
};