+static const struct rte_memzone *
+make_memzone(const char *name, size_t size)
+{
+ unsigned int socket_id = rte_socket_id();
+ char mz_name[RTE_MEMZONE_NAMESIZE];
+ const struct rte_memzone *memzone;
+
+ snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "%s_%u", name, socket_id);
+ memzone = rte_memzone_lookup(mz_name);
+ if (memzone != NULL && memzone->len != size) {
+ rte_memzone_free(memzone);
+ memzone = NULL;
+ }
+ if (memzone == NULL) {
+ memzone = rte_memzone_reserve_aligned(mz_name, size, socket_id,
+ RTE_MEMZONE_IOVA_CONTIG, RTE_CACHE_LINE_SIZE);
+ if (memzone == NULL)
+ RTE_LOG(ERR, USER1, "Can't allocate memory zone %s",
+ mz_name);
+ }
+ return memzone;
+}
+
+static int
+test_compressdev_external_mbufs(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ size_t data_len = 0;
+ uint16_t i;
+ int ret = TEST_FAILED;
+
+ for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
+ data_len = RTE_MAX(data_len, strlen(compress_test_bufs[i]) + 1);
+
+ struct interim_data_params int_data = {
+ NULL,
+ 1,
+ NULL,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = LB_BOTH,
+ .zlib_dir = ZLIB_DECOMPRESS,
+ .out_of_space = 0,
+ .big_data = 0,
+ .use_external_mbufs = 1,
+ .inbuf_data_size = data_len,
+ .inbuf_memzone = make_memzone("inbuf", data_len),
+ .compbuf_memzone = make_memzone("compbuf", data_len *
+ COMPRESS_BUF_SIZE_RATIO),
+ .uncompbuf_memzone = make_memzone("decompbuf", data_len),
+ .overflow = OVERFLOW_DISABLED
+ };
+
+ for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+ /* prepare input data */
+ data_len = strlen(compress_test_bufs[i]) + 1;
+ rte_memcpy(test_data.inbuf_memzone->addr, compress_test_bufs[i],
+ data_len);
+ test_data.inbuf_data_size = data_len;
+ int_data.buf_idx = &i;
+
+ /* Compress with compressdev, decompress with Zlib */
+ test_data.zlib_dir = ZLIB_DECOMPRESS;
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
+ goto exit;
+
+ /* Compress with Zlib, decompress with compressdev */
+ test_data.zlib_dir = ZLIB_COMPRESS;
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
+ goto exit;
+ }
+
+ ret = TEST_SUCCESS;
+
+exit:
+ rte_memzone_free(test_data.inbuf_memzone);
+ rte_memzone_free(test_data.compbuf_memzone);
+ rte_memzone_free(test_data.uncompbuf_memzone);
+ return ret;
+}
+
+static int
+test_compressdev_deflate_stateless_fixed_oos_recoverable(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i;
+ int ret;
+ int comp_result;
+ const struct rte_compressdev_capabilities *capab;
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0)
+ return -ENOTSUP;
+
+ struct rte_comp_xform *compress_xform =
+ rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
+
+ if (compress_xform == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Compress xform could not be created\n");
+ ret = TEST_FAILED;
+ goto exit;
+ }
+
+ memcpy(compress_xform, ts_params->def_comp_xform,
+ sizeof(struct rte_comp_xform));
+ compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
+
+ struct interim_data_params int_data = {
+ NULL,
+ 1,
+ NULL,
+ &compress_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = LB_BOTH,
+ .zlib_dir = ZLIB_DECOMPRESS,
+ .out_of_space = 0,
+ .big_data = 0,
+ .overflow = OVERFLOW_ENABLED,
+ .ratio = RATIO_ENABLED
+ };
+
+ for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+ int_data.test_bufs = &compress_test_bufs[i];
+ int_data.buf_idx = &i;
+
+ /* Compress with compressdev, decompress with Zlib */
+ test_data.zlib_dir = ZLIB_DECOMPRESS;
+ comp_result = test_deflate_comp_decomp(&int_data, &test_data);
+ if (comp_result < 0) {
+ ret = TEST_FAILED;
+ goto exit;
+ } else if (comp_result > 0) {
+ ret = -ENOTSUP;
+ goto exit;
+ }
+
+ /* Compress with Zlib, decompress with compressdev */
+ test_data.zlib_dir = ZLIB_COMPRESS;
+ comp_result = test_deflate_comp_decomp(&int_data, &test_data);
+ if (comp_result < 0) {
+ ret = TEST_FAILED;
+ goto exit;
+ } else if (comp_result > 0) {
+ ret = -ENOTSUP;
+ goto exit;
+ }
+ }
+
+ ret = TEST_SUCCESS;
+
+exit:
+ rte_free(compress_xform);
+ return ret;
+}
+
+static int
+test_compressdev_deflate_im_buffers_LB_1op(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i = 0;
+ int ret = TEST_SUCCESS;
+ int j;
+ const struct rte_compressdev_capabilities *capab;
+ char *test_buffer = NULL;
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
+ return -ENOTSUP;
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
+ return -ENOTSUP;
+
+ test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
+ if (test_buffer == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Can't allocate buffer for 'im buffer' test\n");
+ return TEST_FAILED;
+ }
+
+ struct interim_data_params int_data = {
+ (const char * const *)&test_buffer,
+ 1,
+ &i,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ /* must be LB to SGL,
+ * input LB buffer reaches its maximum,
+ * if ratio 1.3 than another mbuf must be
+ * created and attached
+ */
+ .buff_type = LB_BOTH,
+ .zlib_dir = ZLIB_NONE,
+ .out_of_space = 0,
+ .big_data = 1,
+ .overflow = OVERFLOW_DISABLED,
+ .ratio = RATIO_DISABLED
+ };
+
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DYNAMIC;
+
+ /* fill the buffer with data based on rand. data */
+ srand(IM_BUF_DATA_TEST_SIZE_LB);
+ for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
+ test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
+
+ /* Compress with compressdev, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto end;
+ }
+
+end:
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DEFAULT;
+ rte_free(test_buffer);
+ return ret;
+}
+
+static int
+test_compressdev_deflate_im_buffers_LB_2ops_first(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i = 0;
+ int ret = TEST_SUCCESS;
+ int j;
+ const struct rte_compressdev_capabilities *capab;
+ char *test_buffer = NULL;
+ const char *test_buffers[2];
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
+ return -ENOTSUP;
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
+ return -ENOTSUP;
+
+ test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
+ if (test_buffer == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Can't allocate buffer for 'im buffer' test\n");
+ return TEST_FAILED;
+ }
+
+ test_buffers[0] = test_buffer;
+ test_buffers[1] = compress_test_bufs[0];
+
+ struct interim_data_params int_data = {
+ (const char * const *)test_buffers,
+ 2,
+ &i,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = LB_BOTH,
+ .zlib_dir = ZLIB_NONE,
+ .out_of_space = 0,
+ .big_data = 1,
+ .overflow = OVERFLOW_DISABLED,
+ .ratio = RATIO_DISABLED
+ };
+
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DYNAMIC;
+
+ /* fill the buffer with data based on rand. data */
+ srand(IM_BUF_DATA_TEST_SIZE_LB);
+ for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
+ test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
+
+ /* Compress with compressdev, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto end;
+ }
+
+end:
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DEFAULT;
+ rte_free(test_buffer);
+ return ret;
+}
+
+static int
+test_compressdev_deflate_im_buffers_LB_2ops_second(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i = 0;
+ int ret = TEST_SUCCESS;
+ int j;
+ const struct rte_compressdev_capabilities *capab;
+ char *test_buffer = NULL;
+ const char *test_buffers[2];
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
+ return -ENOTSUP;
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
+ return -ENOTSUP;
+
+ test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
+ if (test_buffer == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Can't allocate buffer for 'im buffer' test\n");
+ return TEST_FAILED;
+ }
+
+ test_buffers[0] = compress_test_bufs[0];
+ test_buffers[1] = test_buffer;
+
+ struct interim_data_params int_data = {
+ (const char * const *)test_buffers,
+ 2,
+ &i,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = LB_BOTH,
+ .zlib_dir = ZLIB_NONE,
+ .out_of_space = 0,
+ .big_data = 1,
+ .overflow = OVERFLOW_DISABLED,
+ .ratio = RATIO_DISABLED
+ };
+
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DYNAMIC;
+
+ /* fill the buffer with data based on rand. data */
+ srand(IM_BUF_DATA_TEST_SIZE_LB);
+ for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
+ test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
+
+ /* Compress with compressdev, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto end;
+ }
+
+end:
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DEFAULT;
+ rte_free(test_buffer);
+ return ret;
+}
+
+static int
+test_compressdev_deflate_im_buffers_LB_3ops(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i = 0;
+ int ret = TEST_SUCCESS;
+ int j;
+ const struct rte_compressdev_capabilities *capab;
+ char *test_buffer = NULL;
+ const char *test_buffers[3];
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
+ return -ENOTSUP;
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
+ return -ENOTSUP;
+
+ test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
+ if (test_buffer == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Can't allocate buffer for 'im buffer' test\n");
+ return TEST_FAILED;
+ }
+
+ test_buffers[0] = compress_test_bufs[0];
+ test_buffers[1] = test_buffer;
+ test_buffers[2] = compress_test_bufs[1];
+
+ struct interim_data_params int_data = {
+ (const char * const *)test_buffers,
+ 3,
+ &i,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = LB_BOTH,
+ .zlib_dir = ZLIB_NONE,
+ .out_of_space = 0,
+ .big_data = 1,
+ .overflow = OVERFLOW_DISABLED,
+ .ratio = RATIO_DISABLED
+ };
+
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DYNAMIC;
+
+ /* fill the buffer with data based on rand. data */
+ srand(IM_BUF_DATA_TEST_SIZE_LB);
+ for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
+ test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
+
+ /* Compress with compressdev, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto end;
+ }
+
+end:
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DEFAULT;
+ rte_free(test_buffer);
+ return ret;
+}
+
+static int
+test_compressdev_deflate_im_buffers_LB_4ops(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i = 0;
+ int ret = TEST_SUCCESS;
+ int j;
+ const struct rte_compressdev_capabilities *capab;
+ char *test_buffer = NULL;
+ const char *test_buffers[4];
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
+ return -ENOTSUP;
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
+ return -ENOTSUP;
+
+ test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
+ if (test_buffer == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Can't allocate buffer for 'im buffer' test\n");
+ return TEST_FAILED;
+ }
+
+ test_buffers[0] = compress_test_bufs[0];
+ test_buffers[1] = test_buffer;
+ test_buffers[2] = compress_test_bufs[1];
+ test_buffers[3] = test_buffer;
+
+ struct interim_data_params int_data = {
+ (const char * const *)test_buffers,
+ 4,
+ &i,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = LB_BOTH,
+ .zlib_dir = ZLIB_NONE,
+ .out_of_space = 0,
+ .big_data = 1,
+ .overflow = OVERFLOW_DISABLED,
+ .ratio = RATIO_DISABLED
+ };
+
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DYNAMIC;
+
+ /* fill the buffer with data based on rand. data */
+ srand(IM_BUF_DATA_TEST_SIZE_LB);
+ for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
+ test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
+
+ /* Compress with compressdev, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto end;
+ }
+
+end:
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DEFAULT;
+ rte_free(test_buffer);
+ return ret;
+}
+
+
+static int
+test_compressdev_deflate_im_buffers_SGL_1op(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i = 0;
+ int ret = TEST_SUCCESS;
+ int j;
+ const struct rte_compressdev_capabilities *capab;
+ char *test_buffer = NULL;
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
+ return -ENOTSUP;
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
+ return -ENOTSUP;
+
+ test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
+ if (test_buffer == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Can't allocate buffer for big-data\n");
+ return TEST_FAILED;
+ }
+
+ struct interim_data_params int_data = {
+ (const char * const *)&test_buffer,
+ 1,
+ &i,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = SGL_BOTH,
+ .zlib_dir = ZLIB_NONE,
+ .out_of_space = 0,
+ .big_data = 1,
+ .overflow = OVERFLOW_DISABLED,
+ .ratio = RATIO_DISABLED
+ };
+
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DYNAMIC;
+
+ /* fill the buffer with data based on rand. data */
+ srand(IM_BUF_DATA_TEST_SIZE_SGL);
+ for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
+ test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
+
+ /* Compress with compressdev, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto end;
+ }
+
+end:
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DEFAULT;
+ rte_free(test_buffer);
+ return ret;
+}
+
+static int
+test_compressdev_deflate_im_buffers_SGL_2ops_first(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i = 0;
+ int ret = TEST_SUCCESS;
+ int j;
+ const struct rte_compressdev_capabilities *capab;
+ char *test_buffer = NULL;
+ const char *test_buffers[2];
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
+ return -ENOTSUP;
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
+ return -ENOTSUP;
+
+ test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
+ if (test_buffer == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Can't allocate buffer for big-data\n");
+ return TEST_FAILED;
+ }
+
+ test_buffers[0] = test_buffer;
+ test_buffers[1] = compress_test_bufs[0];
+
+ struct interim_data_params int_data = {
+ (const char * const *)test_buffers,
+ 2,
+ &i,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = SGL_BOTH,
+ .zlib_dir = ZLIB_NONE,
+ .out_of_space = 0,
+ .big_data = 1,
+ .overflow = OVERFLOW_DISABLED,
+ .ratio = RATIO_DISABLED
+ };
+
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DYNAMIC;
+
+ /* fill the buffer with data based on rand. data */
+ srand(IM_BUF_DATA_TEST_SIZE_SGL);
+ for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
+ test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
+
+ /* Compress with compressdev, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto end;
+ }
+
+end:
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DEFAULT;
+ rte_free(test_buffer);
+ return ret;
+}
+
+static int
+test_compressdev_deflate_im_buffers_SGL_2ops_second(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i = 0;
+ int ret = TEST_SUCCESS;
+ int j;
+ const struct rte_compressdev_capabilities *capab;
+ char *test_buffer = NULL;
+ const char *test_buffers[2];
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
+ return -ENOTSUP;
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
+ return -ENOTSUP;
+
+ test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
+ if (test_buffer == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Can't allocate buffer for big-data\n");
+ return TEST_FAILED;
+ }
+
+ test_buffers[0] = compress_test_bufs[0];
+ test_buffers[1] = test_buffer;
+
+ struct interim_data_params int_data = {
+ (const char * const *)test_buffers,
+ 2,
+ &i,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = SGL_BOTH,
+ .zlib_dir = ZLIB_NONE,
+ .out_of_space = 0,
+ .big_data = 1,
+ .overflow = OVERFLOW_DISABLED,
+ .ratio = RATIO_DISABLED
+ };
+
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DYNAMIC;
+
+ /* fill the buffer with data based on rand. data */
+ srand(IM_BUF_DATA_TEST_SIZE_SGL);
+ for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
+ test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
+
+ /* Compress with compressdev, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto end;
+ }
+
+end:
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DEFAULT;
+ rte_free(test_buffer);
+ return ret;
+}
+
+static int
+test_compressdev_deflate_im_buffers_SGL_3ops(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i = 0;
+ int ret = TEST_SUCCESS;
+ int j;
+ const struct rte_compressdev_capabilities *capab;
+ char *test_buffer = NULL;
+ const char *test_buffers[3];
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
+ return -ENOTSUP;
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
+ return -ENOTSUP;
+
+ test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
+ if (test_buffer == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Can't allocate buffer for big-data\n");
+ return TEST_FAILED;
+ }
+
+ test_buffers[0] = compress_test_bufs[0];
+ test_buffers[1] = test_buffer;
+ test_buffers[2] = compress_test_bufs[1];
+
+ struct interim_data_params int_data = {
+ (const char * const *)test_buffers,
+ 3,
+ &i,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = SGL_BOTH,
+ .zlib_dir = ZLIB_NONE,
+ .out_of_space = 0,
+ .big_data = 1,
+ .overflow = OVERFLOW_DISABLED,
+ .ratio = RATIO_DISABLED
+ };
+
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DYNAMIC;
+
+ /* fill the buffer with data based on rand. data */
+ srand(IM_BUF_DATA_TEST_SIZE_SGL);
+ for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
+ test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
+
+ /* Compress with compressdev, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto end;
+ }
+
+end:
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DEFAULT;
+ rte_free(test_buffer);
+ return ret;
+}
+
+
+static int
+test_compressdev_deflate_im_buffers_SGL_4ops(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i = 0;
+ int ret = TEST_SUCCESS;
+ int j;
+ const struct rte_compressdev_capabilities *capab;
+ char *test_buffer = NULL;
+ const char *test_buffers[4];
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
+ return -ENOTSUP;
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
+ return -ENOTSUP;
+
+ test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
+ if (test_buffer == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Can't allocate buffer for big-data\n");
+ return TEST_FAILED;
+ }
+
+ test_buffers[0] = compress_test_bufs[0];
+ test_buffers[1] = test_buffer;
+ test_buffers[2] = compress_test_bufs[1];
+ test_buffers[3] = test_buffer;
+
+ struct interim_data_params int_data = {
+ (const char * const *)test_buffers,
+ 4,
+ &i,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = SGL_BOTH,
+ .zlib_dir = ZLIB_NONE,
+ .out_of_space = 0,
+ .big_data = 1,
+ .overflow = OVERFLOW_DISABLED,
+ .ratio = RATIO_DISABLED
+ };
+
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DYNAMIC;
+
+ /* fill the buffer with data based on rand. data */
+ srand(IM_BUF_DATA_TEST_SIZE_SGL);
+ for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
+ test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
+
+ /* Compress with compressdev, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto end;
+ }
+
+end:
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DEFAULT;
+ rte_free(test_buffer);
+ return ret;
+}
+
+static int
+test_compressdev_deflate_im_buffers_SGL_over_1op(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i = 0;
+ int ret = TEST_SUCCESS;
+ int j;
+ const struct rte_compressdev_capabilities *capab;
+ char *test_buffer = NULL;
+
+ RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
+ return -ENOTSUP;
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
+ return -ENOTSUP;
+
+ test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_OVER, 0);
+ if (test_buffer == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Can't allocate buffer for big-data\n");
+ return TEST_FAILED;
+ }
+
+ struct interim_data_params int_data = {
+ (const char * const *)&test_buffer,
+ 1,
+ &i,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = SGL_BOTH,
+ .zlib_dir = ZLIB_NONE,
+ .out_of_space = 0,
+ .big_data = 1,
+ .overflow = OVERFLOW_DISABLED,
+ .ratio = RATIO_DISABLED
+ };
+
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DYNAMIC;
+
+ /* fill the buffer with data based on rand. data */
+ srand(IM_BUF_DATA_TEST_SIZE_OVER);
+ for (j = 0; j < IM_BUF_DATA_TEST_SIZE_OVER - 1; ++j)
+ test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
+
+ /* Compress with compressdev, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_SUCCESS;
+ goto end;
+ }
+
+end:
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DEFAULT;
+ rte_free(test_buffer);
+
+ return ret;
+}
+
+
+static int
+test_compressdev_deflate_im_buffers_SGL_over_2ops_first(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i = 0;
+ int ret = TEST_SUCCESS;
+ int j;
+ const struct rte_compressdev_capabilities *capab;
+ char *test_buffer = NULL;
+ const char *test_buffers[2];
+
+ RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
+ return -ENOTSUP;
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
+ return -ENOTSUP;
+
+ test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_OVER, 0);
+ if (test_buffer == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Can't allocate buffer for big-data\n");
+ return TEST_FAILED;
+ }
+
+ test_buffers[0] = test_buffer;
+ test_buffers[1] = compress_test_bufs[0];
+
+ struct interim_data_params int_data = {
+ (const char * const *)test_buffers,
+ 2,
+ &i,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = SGL_BOTH,
+ .zlib_dir = ZLIB_NONE,
+ .out_of_space = 0,
+ .big_data = 1,
+ .overflow = OVERFLOW_DISABLED,
+ .ratio = RATIO_DISABLED
+ };
+
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DYNAMIC;
+
+ /* fill the buffer with data based on rand. data */
+ srand(IM_BUF_DATA_TEST_SIZE_OVER);
+ for (j = 0; j < IM_BUF_DATA_TEST_SIZE_OVER - 1; ++j)
+ test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
+
+ /* Compress with compressdev, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_SUCCESS;
+ goto end;
+ }
+
+end:
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DEFAULT;
+ rte_free(test_buffer);
+ return ret;
+}
+
+static int
+test_compressdev_deflate_im_buffers_SGL_over_2ops_second(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ uint16_t i = 0;
+ int ret = TEST_SUCCESS;
+ int j;
+ const struct rte_compressdev_capabilities *capab;
+ char *test_buffer = NULL;
+ const char *test_buffers[2];
+
+ RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
+
+ capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+ TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
+ return -ENOTSUP;
+
+ if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
+ return -ENOTSUP;
+
+ test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_OVER, 0);
+ if (test_buffer == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Can't allocate buffer for big-data\n");
+ return TEST_FAILED;
+ }
+
+ test_buffers[0] = compress_test_bufs[0];
+ test_buffers[1] = test_buffer;
+
+ struct interim_data_params int_data = {
+ (const char * const *)test_buffers,
+ 2,
+ &i,
+ &ts_params->def_comp_xform,
+ &ts_params->def_decomp_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATELESS,
+ .buff_type = SGL_BOTH,
+ .zlib_dir = ZLIB_NONE,
+ .out_of_space = 0,
+ .big_data = 1,
+ .overflow = OVERFLOW_DISABLED,
+ .ratio = RATIO_DISABLED
+ };
+
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DYNAMIC;
+
+ /* fill the buffer with data based on rand. data */
+ srand(IM_BUF_DATA_TEST_SIZE_OVER);
+ for (j = 0; j < IM_BUF_DATA_TEST_SIZE_OVER - 1; ++j)
+ test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
+
+ /* Compress with compressdev, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_SUCCESS;
+ goto end;
+ }
+
+end:
+ ts_params->def_comp_xform->compress.deflate.huffman =
+ RTE_COMP_HUFFMAN_DEFAULT;
+ rte_free(test_buffer);
+ return ret;
+}
+
+static struct unit_test_suite compressdev_testsuite = {
+ .suite_name = "compressdev unit test suite",
+ .setup = testsuite_setup,
+ .teardown = testsuite_teardown,
+ .unit_test_cases = {
+ TEST_CASE_ST(NULL, NULL,
+ test_compressdev_invalid_configuration),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_stateless_fixed),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_stateless_dynamic),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_stateless_dynamic_big),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_stateless_multi_op),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_stateless_multi_level),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_stateless_multi_xform),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_stateless_sgl),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_stateless_checksum),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_out_of_space_buffer),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_stateful_decomp),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_stateful_decomp_checksum),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_external_mbufs),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_stateless_fixed_oos_recoverable),
+
+ /* Positive test cases for IM buffer handling verification */
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_im_buffers_LB_1op),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_im_buffers_LB_2ops_first),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_im_buffers_LB_2ops_second),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_im_buffers_LB_3ops),
+
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_im_buffers_LB_4ops),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_im_buffers_SGL_1op),
+
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_im_buffers_SGL_2ops_first),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_im_buffers_SGL_2ops_second),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_im_buffers_SGL_3ops),
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_im_buffers_SGL_4ops),
+
+ /* Negative test cases for IM buffer handling verification */
+
+ /* For this test huge mempool is necessary.
+ * It tests one case:
+ * only one op containing big amount of data, so that
+ * number of requested descriptors higher than number
+ * of available descriptors (128)
+ */
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_im_buffers_SGL_over_1op),
+
+ /* For this test huge mempool is necessary.
+ * 2 ops. First op contains big amount of data:
+ * number of requested descriptors higher than number
+ * of available descriptors (128), the second op is
+ * relatively small. In this case both ops are rejected
+ */
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_im_buffers_SGL_over_2ops_first),
+
+ TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+ test_compressdev_deflate_im_buffers_SGL_over_2ops_second),