+static int
+test_compressdev_deflate_stateful_decomp(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ int ret;
+ uint16_t i;
+ 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_STATEFUL_DECOMPRESSION))
+ return -ENOTSUP;
+
+ struct interim_data_params int_data = {
+ &compress_test_bufs[0],
+ 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_STATEFUL,
+ .buff_type = LB_BOTH,
+ .zlib_dir = ZLIB_COMPRESS,
+ .out_of_space = 0,
+ .big_data = 0,
+ .decompress_output_block_size = 2000,
+ .decompress_steps_max = 4,
+ .overflow = OVERFLOW_DISABLED
+ };
+
+ /* Compress with Zlib, decompress with compressdev */
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto exit;
+ }
+
+ if (capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
+ /* Now test with SGL buffers */
+ test_data.buff_type = SGL_BOTH;
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto exit;
+ }
+ }
+
+ ret = TEST_SUCCESS;
+
+exit:
+ return ret;
+}
+
+static int
+test_compressdev_deflate_stateful_decomp_checksum(void)
+{
+ struct comp_testsuite_params *ts_params = &testsuite_params;
+ int ret;
+ uint16_t i;
+ 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_STATEFUL_DECOMPRESSION))
+ return -ENOTSUP;
+
+ /* Check if driver supports any checksum */
+ if (!(capab->comp_feature_flags &
+ (RTE_COMP_FF_CRC32_CHECKSUM | RTE_COMP_FF_ADLER32_CHECKSUM |
+ RTE_COMP_FF_CRC32_ADLER32_CHECKSUM)))
+ 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");
+ return TEST_FAILED;
+ }
+
+ memcpy(compress_xform, ts_params->def_comp_xform,
+ sizeof(struct rte_comp_xform));
+
+ struct rte_comp_xform *decompress_xform =
+ rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
+ if (decompress_xform == NULL) {
+ RTE_LOG(ERR, USER1, "Decompress xform could not be created\n");
+ rte_free(compress_xform);
+ return TEST_FAILED;
+ }
+
+ memcpy(decompress_xform, ts_params->def_decomp_xform,
+ sizeof(struct rte_comp_xform));
+
+ struct interim_data_params int_data = {
+ &compress_test_bufs[0],
+ 1,
+ &i,
+ &compress_xform,
+ &decompress_xform,
+ 1
+ };
+
+ struct test_data_params test_data = {
+ .compress_state = RTE_COMP_OP_STATELESS,
+ .decompress_state = RTE_COMP_OP_STATEFUL,
+ .buff_type = LB_BOTH,
+ .zlib_dir = ZLIB_COMPRESS,
+ .out_of_space = 0,
+ .big_data = 0,
+ .decompress_output_block_size = 2000,
+ .decompress_steps_max = 4,
+ .overflow = OVERFLOW_DISABLED
+ };
+
+ /* Check if driver supports crc32 checksum and test */
+ if (capab->comp_feature_flags & RTE_COMP_FF_CRC32_CHECKSUM) {
+ compress_xform->compress.chksum = RTE_COMP_CHECKSUM_CRC32;
+ decompress_xform->decompress.chksum = RTE_COMP_CHECKSUM_CRC32;
+ /* Compress with Zlib, decompress with compressdev */
+ test_data.buff_type = LB_BOTH;
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto exit;
+ }
+ if (capab->comp_feature_flags &
+ RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
+ /* Now test with SGL buffers */
+ test_data.buff_type = SGL_BOTH;
+ if (test_deflate_comp_decomp(&int_data,
+ &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto exit;
+ }
+ }
+ }
+
+ /* Check if driver supports adler32 checksum and test */
+ if (capab->comp_feature_flags & RTE_COMP_FF_ADLER32_CHECKSUM) {
+ compress_xform->compress.chksum = RTE_COMP_CHECKSUM_ADLER32;
+ decompress_xform->decompress.chksum = RTE_COMP_CHECKSUM_ADLER32;
+ /* Compress with Zlib, decompress with compressdev */
+ test_data.buff_type = LB_BOTH;
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto exit;
+ }
+ if (capab->comp_feature_flags &
+ RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
+ /* Now test with SGL buffers */
+ test_data.buff_type = SGL_BOTH;
+ if (test_deflate_comp_decomp(&int_data,
+ &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto exit;
+ }
+ }
+ }
+
+ /* Check if driver supports combined crc and adler checksum and test */
+ if (capab->comp_feature_flags & RTE_COMP_FF_CRC32_ADLER32_CHECKSUM) {
+ compress_xform->compress.chksum =
+ RTE_COMP_CHECKSUM_CRC32_ADLER32;
+ decompress_xform->decompress.chksum =
+ RTE_COMP_CHECKSUM_CRC32_ADLER32;
+ /* Zlib doesn't support combined checksum */
+ test_data.zlib_dir = ZLIB_NONE;
+ /* Compress stateless, decompress stateful with compressdev */
+ test_data.buff_type = LB_BOTH;
+ if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto exit;
+ }
+ if (capab->comp_feature_flags &
+ RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
+ /* Now test with SGL buffers */
+ test_data.buff_type = SGL_BOTH;
+ if (test_deflate_comp_decomp(&int_data,
+ &test_data) < 0) {
+ ret = TEST_FAILED;
+ goto exit;
+ }
+ }
+ }
+
+ ret = TEST_SUCCESS;
+
+exit:
+ rte_free(compress_xform);
+ rte_free(decompress_xform);
+ return ret;
+}
+
+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
+ };
+
+ 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;
+}