Skip to content

Commit

Permalink
QATAPP-27109: Fix test mode 9 error (#166)
Browse files Browse the repository at this point in the history
* QATAPP-27109: Fix test mode 9 error

Change-Id: Ibc84faa8757ab6bd3a3ac9a21b9fcbef94b0eaeb
Signed-off-by: Chengfei Zhu <[email protected]>
  • Loading branch information
GarenJian-Intel authored and cfzhu committed Aug 8, 2022
1 parent 6e55617 commit 6cbf82c
Showing 1 changed file with 53 additions and 21 deletions.
74 changes: 53 additions & 21 deletions test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1602,8 +1602,8 @@ void *qzCompressStreamAndDecompress(void *arg)
int rc = -1;
QzSession_T comp_sess = {0}, decomp_sess = {0};
QzStream_T comp_strm = {0};
QzSessionParams_T comp_params = {0};
uint8_t *orig_src, *comp_src, *decomp_src;
QzSessionParams_T comp_params = {0}, decomp_params = {0};
uint8_t *orig_src = NULL, *comp_src = NULL, *decomp_src = NULL;
size_t orig_sz, comp_sz, decomp_sz;
unsigned int slice_sz = 0, done = 0;
unsigned int consumed = 0, produced = 0;
Expand All @@ -1615,41 +1615,64 @@ void *qzCompressStreamAndDecompress(void *arg)

orig_sz = comp_sz = decomp_sz = test_arg->src_sz;
orig_src = malloc(orig_sz);
if (NULL == orig_src) {
QZ_ERROR("Err: fail to malloc memory\n");
goto exit;
}
comp_src = malloc(comp_sz);
if (NULL == comp_src) {
QZ_ERROR("Err: fail to malloc memory\n");
goto exit;
}
decomp_src = calloc(orig_sz, 1);
if (NULL == decomp_src) {
QZ_ERROR("Err: fail to malloc memory\n");
goto exit;
}

if (qzGetDefaults(&comp_params) != QZ_OK) {
QZ_ERROR("Err: get params fail with incorrect compress params.\n");
goto exit;
}
if (qzGetDefaults(&decomp_params) != QZ_OK) {
QZ_ERROR("Err: get params fail with incorrect decompress params.\n");
goto exit;
}
slice_sz = comp_params.hw_buff_sz / 4;

if (NULL == orig_src ||
NULL == comp_src ||
NULL == decomp_src) {
free(orig_src);
free(comp_src);
free(decomp_src);
QZ_ERROR("Malloc Memory for testing %s error\n", __func__);
return NULL;
rc = qzInit(&comp_sess, 0);
if (QZ_INIT_HW_FAIL(rc)) {
QZ_ERROR("Err: fail to init HW with ret: %d.\n", rc);
goto exit;
}

switch (test_arg->test_format) {
case TEST_DEFLATE:
comp_params.data_fmt = QZ_DEFLATE_RAW;
decomp_params.data_fmt = QZ_DEFLATE_RAW;
break;
case TEST_GZIPEXT:
comp_params.data_fmt = QZ_DEFLATE_GZIP_EXT;
decomp_params.data_fmt = QZ_DEFLATE_GZIP_EXT;
break;
default:
QZ_ERROR("Unsupport data format in Stream API\n");
free(orig_src);
free(comp_src);
free(decomp_src);
return NULL;
goto exit;
}
QZ_DEBUG("*** Data Format: %d ***\n", comp_params.data_fmt);

rc = qzSetupSession(&comp_sess, &comp_params);
if (QZ_SETUP_SESSION_FAIL(rc)) {
QZ_ERROR("Err: fail to setup session with ret: %d\n", rc);
goto exit;
}

rc = qzSetupSession(&decomp_sess, &decomp_params);
if (QZ_SETUP_SESSION_FAIL(rc)) {
QZ_ERROR("Err: fail to setup session with ret: %d\n", rc);
goto exit;
}

genRandomData(orig_src, orig_sz);

while (!done) {
Expand Down Expand Up @@ -1715,7 +1738,7 @@ void *qzCompressStreamAndDecompress(void *arg)
last = (comp_sz == (consumed + comp_strm.in_sz)) ? 1 : 0;
org_in_sz = comp_strm.in_sz;

rc = qzDecompressStream(&comp_sess, &comp_strm, last);
rc = qzDecompressStream(&decomp_sess, &comp_strm, last);
if (rc != QZ_OK) {
QZ_ERROR("ERROR: Decompression FAILED with return value: %d\n", rc);
dumpOutputData(comp_sz, comp_src, "decomp_stream__input");
Expand Down Expand Up @@ -1769,7 +1792,7 @@ void *qzCompressStreamAndDecompress(void *arg)
last = 1;
offset += comp_strm.in_sz;

rc = qzDecompressStream(&comp_sess, &comp_strm, last);
rc = qzDecompressStream(&decomp_sess, &comp_strm, last);
if (rc != QZ_OK) {
QZ_ERROR("ERROR: Memcmp with return value: %d\n", rc);
goto exit;
Expand Down Expand Up @@ -1814,7 +1837,7 @@ void *qzCompressStreamAndDecompress(void *arg)
last = 1;
org_in_sz = comp_strm.in_sz;

rc = qzDecompressStream(&comp_sess, &comp_strm, last);
rc = qzDecompressStream(&decomp_sess, &comp_strm, last);
if (rc != QZ_OK) {
QZ_ERROR("ERROR: Decompression FAILED with return value: %d\n", rc);
goto exit;
Expand Down Expand Up @@ -1863,7 +1886,7 @@ void *qzCompressStreamAndDecompress(void *arg)
last = (comp_sz == (consumed + comp_strm.in_sz)) ? 1 : 0;
org_in_sz = comp_strm.in_sz;

rc = qzDecompressStream(&comp_sess, &comp_strm, last);
rc = qzDecompressStream(&decomp_sess, &comp_strm, last);
if (rc != QZ_OK) {
QZ_ERROR("ERROR: Decompression FAILED with return value: %d\n", rc);
goto exit;
Expand Down Expand Up @@ -1899,9 +1922,18 @@ void *qzCompressStreamAndDecompress(void *arg)
QZ_PRINT("Compress Stream and Decompress function test: PASS\n");

exit:
qzFree(orig_src);
qzFree(comp_src);
qzFree(decomp_src);
if (NULL != orig_src) {
free(orig_src);
orig_src = NULL;
}
if (NULL != comp_src) {
free(comp_src);
comp_src = NULL;
}
if (NULL != decomp_src) {
free(decomp_src);
decomp_src = NULL;
}
qzEndStream(&comp_sess, &comp_strm);
(void)qzTeardownSession(&comp_sess);
(void)qzTeardownSession(&decomp_sess);
Expand Down

0 comments on commit 6cbf82c

Please sign in to comment.