+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)
+ };
+
+ 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;
+}
+