DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/5] Initial compressdev unit tests
@ 2018-02-28 14:00 Pablo de Lara
  2018-02-28 14:00 ` [dpdk-dev] [PATCH 1/5] compressdev: add const for xform in session init Pablo de Lara
                   ` (7 more replies)
  0 siblings, 8 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-02-28 14:00 UTC (permalink / raw)
  To: fiona.trahe, Shally.Verma, ahmed.mansour, lee.daly, tomaszx.jozwiak
  Cc: dev, Pablo de Lara

Added initial tests for Compressdev library.
The tests are performed compressing a test buffer
(or multiple test buffers) with compressdev or Zlib,
and decompressing it/them with the other library
(if compression is done with compressdev, decompression
is done with Zlib, and viceversa).

Tests added so far are based on the deflate algorithm,
including:
- Fixed huffman on single buffer
- Dynamic huffman on single buffer
- Multi compression level test on single buffer
- Multi buffer
- Multi session using a the same buffer

Due to a dependency on Zlib, the test is not enabled
by default. Once the library is installed, the configuration
option CONFIG_RTE_COMPRESSDEV_TEST must be set to Y.

The test requires a compressdev PMD to be initialized,
when running the test app. For example:

./build/app/test --vdev="compress_X"

RTE>>compressdev_autotest

This patch depends on the Compressdev API patch:
http://dpdk.org/dev/patchwork/patch/34900/
("compressdev: implement API")

Pablo de Lara (5):
  compressdev: add const for xform in session init
  test/compress: add initial unit tests
  test/compress: add multi op test
  test/compress: add multi level test
  test/compress: add multi session test

 config/common_base                           |   5 +
 lib/librte_compressdev/rte_compressdev.c     |   2 +-
 lib/librte_compressdev/rte_compressdev.h     |   2 +-
 lib/librte_compressdev/rte_compressdev_pmd.h |   2 +-
 test/test/Makefile                           |   9 +
 test/test/test_compressdev.c                 | 972 +++++++++++++++++++++++++++
 test/test/test_compressdev_test_buffer.h     | 295 ++++++++
 7 files changed, 1284 insertions(+), 3 deletions(-)
 create mode 100644 test/test/test_compressdev.c
 create mode 100644 test/test/test_compressdev_test_buffer.h

-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH 1/5] compressdev: add const for xform in session init
  2018-02-28 14:00 [dpdk-dev] [PATCH 0/5] Initial compressdev unit tests Pablo de Lara
@ 2018-02-28 14:00 ` Pablo de Lara
  2018-02-28 14:00 ` [dpdk-dev] [PATCH 2/5] test/compress: add initial unit tests Pablo de Lara
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-02-28 14:00 UTC (permalink / raw)
  To: fiona.trahe, Shally.Verma, ahmed.mansour, lee.daly, tomaszx.jozwiak
  Cc: dev, Pablo de Lara

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 lib/librte_compressdev/rte_compressdev.c     | 2 +-
 lib/librte_compressdev/rte_compressdev.h     | 2 +-
 lib/librte_compressdev/rte_compressdev_pmd.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/librte_compressdev/rte_compressdev.c b/lib/librte_compressdev/rte_compressdev.c
index 8fc66740c..486ad9a51 100644
--- a/lib/librte_compressdev/rte_compressdev.c
+++ b/lib/librte_compressdev/rte_compressdev.c
@@ -650,7 +650,7 @@ rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info)
 int __rte_experimental
 rte_compressdev_session_init(uint8_t dev_id,
 		struct rte_comp_session *sess,
-		struct rte_comp_xform *xforms,
+		const struct rte_comp_xform *xforms,
 		struct rte_mempool *mp)
 {
 	struct rte_compressdev *dev;
diff --git a/lib/librte_compressdev/rte_compressdev.h b/lib/librte_compressdev/rte_compressdev.h
index 72390b4f2..d37e221c9 100644
--- a/lib/librte_compressdev/rte_compressdev.h
+++ b/lib/librte_compressdev/rte_compressdev.h
@@ -647,7 +647,7 @@ rte_compressdev_session_terminate(struct rte_comp_session *sess);
 int __rte_experimental
 rte_compressdev_session_init(uint8_t dev_id,
 			struct rte_comp_session *sess,
-			struct rte_comp_xform *xforms,
+			const struct rte_comp_xform *xforms,
 			struct rte_mempool *mempool);
 
 /**
diff --git a/lib/librte_compressdev/rte_compressdev_pmd.h b/lib/librte_compressdev/rte_compressdev_pmd.h
index 0e30cb484..1d1688a53 100644
--- a/lib/librte_compressdev/rte_compressdev_pmd.h
+++ b/lib/librte_compressdev/rte_compressdev_pmd.h
@@ -257,7 +257,7 @@ typedef unsigned int (*compressdev_get_session_private_size_t)(
  *  - Returns -ENOMEM if the private session could not be allocated.
  */
 typedef int (*compressdev_configure_session_t)(struct rte_compressdev *dev,
-		struct rte_comp_xform *xform,
+		const struct rte_comp_xform *xform,
 		struct rte_comp_session *session,
 		struct rte_mempool *mp);
 
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH 2/5] test/compress: add initial unit tests
  2018-02-28 14:00 [dpdk-dev] [PATCH 0/5] Initial compressdev unit tests Pablo de Lara
  2018-02-28 14:00 ` [dpdk-dev] [PATCH 1/5] compressdev: add const for xform in session init Pablo de Lara
@ 2018-02-28 14:00 ` Pablo de Lara
  2018-02-28 14:00 ` [dpdk-dev] [PATCH 3/5] test/compress: add multi op test Pablo de Lara
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-02-28 14:00 UTC (permalink / raw)
  To: fiona.trahe, Shally.Verma, ahmed.mansour, lee.daly, tomaszx.jozwiak
  Cc: dev, Pablo de Lara

This commit introduces the initial tests for compressdev,
performing basic compression and decompression operations
of sample test buffers, using the Zlib library in one direction
and compressdev in another direction, to make sure that
the library is compatible with Zlib.

Due to the use of Zlib API, the test is disabled by default,
to avoid adding a new dependency on DPDK.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 config/common_base                       |   5 +
 test/test/Makefile                       |   9 +
 test/test/test_compressdev.c             | 701 +++++++++++++++++++++++++++++++
 test/test/test_compressdev_test_buffer.h | 295 +++++++++++++
 4 files changed, 1010 insertions(+)
 create mode 100644 test/test/test_compressdev.c
 create mode 100644 test/test/test_compressdev_test_buffer.h

diff --git a/config/common_base b/config/common_base
index e0e576896..5066f7ed0 100644
--- a/config/common_base
+++ b/config/common_base
@@ -540,6 +540,11 @@ CONFIG_RTE_LIBRTE_PMD_MRVL_CRYPTO_DEBUG=n
 CONFIG_RTE_LIBRTE_COMPRESSDEV=y
 CONFIG_RTE_COMPRESS_MAX_DEVS=64
 
+#
+# Compile compressdev unit test
+#
+CONFIG_RTE_COMPRESSDEV_TEST=n
+
 #
 # Compile generic security library
 #
diff --git a/test/test/Makefile b/test/test/Makefile
index a88cc38bf..0faa03bad 100644
--- a/test/test/Makefile
+++ b/test/test/Makefile
@@ -181,6 +181,10 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_RING) += test_pmd_ring_perf.c
 SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_blockcipher.c
 SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c
 
+ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y)
+SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c
+endif
+
 ifeq ($(CONFIG_RTE_LIBRTE_EVENTDEV),y)
 SRCS-y += test_eventdev.c
 SRCS-y += test_event_ring.c
@@ -201,6 +205,11 @@ CFLAGS += $(WERROR_FLAGS)
 CFLAGS += -D_GNU_SOURCE
 
 LDLIBS += -lm
+ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y)
+ifeq ($(CONFIG_RTE_LIBRTE_COMPRESSDEV),y)
+LDLIBS += -lz
+endif
+endif
 
 # Disable VTA for memcpy test
 ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
new file mode 100644
index 000000000..e92b8142b
--- /dev/null
+++ b/test/test/test_compressdev.c
@@ -0,0 +1,701 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+#include <string.h>
+#include <zlib.h>
+#include <math.h>
+
+#include <rte_cycles.h>
+#include <rte_malloc.h>
+#include <rte_mempool.h>
+#include <rte_mbuf.h>
+#include <rte_compressdev.h>
+
+#include "test_compressdev_test_buffer.h"
+#include "test.h"
+
+#define DEFAULT_WINDOW_SIZE 32768
+#define DEFAULT_MEM_LEVEL 8
+
+/*
+ * 30% extra size for compressed data compared to original data,
+ * in case data size cannot be reduced and it is actually bigger
+ * due to the compress block headers
+ */
+#define COMPRESS_BUF_SIZE_RATIO 1.3
+#define NUM_MBUFS 16
+#define NUM_OPS 16
+#define NUM_SESSIONS 1
+#define NUM_MAX_INFLIGHT_OPS 128
+#define CACHE_SIZE 0
+
+#define DIV_CEIL(a, b)  ((a % b) ? ((a / b) + 1) : (a / b))
+
+const char *
+huffman_type_strings[] = {
+	[RTE_COMP_DEFAULT]	= "PMD default",
+	[RTE_COMP_FIXED]	= "Fixed",
+	[RTE_COMP_DYNAMIC]	= "Dynamic"
+};
+
+enum zlib_direction {
+	ZLIB_NONE,
+	ZLIB_COMPRESS,
+	ZLIB_DECOMPRESS,
+	ZLIB_ALL
+};
+
+struct comp_testsuite_params {
+	struct rte_mempool *mbuf_pool;
+	struct rte_mempool *sess_pool;
+	struct rte_mempool *op_pool;
+	struct rte_comp_xform def_comp_xform;
+	struct rte_comp_xform def_decomp_xform;
+};
+
+static struct comp_testsuite_params testsuite_params = { 0 };
+
+static void
+testsuite_teardown(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+
+	rte_mempool_free(ts_params->mbuf_pool);
+	rte_mempool_free(ts_params->sess_pool);
+	rte_mempool_free(ts_params->op_pool);
+}
+
+static int
+testsuite_setup(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	unsigned int i;
+
+	if (rte_compressdev_count() == 0) {
+		RTE_LOG(ERR, USER1, "Need at least one compress device\n");
+		return -EINVAL;
+	}
+
+	uint32_t max_buf_size = 0;
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
+		max_buf_size = RTE_MAX(max_buf_size,
+				strlen(compress_test_bufs[i]) + 1);
+
+	max_buf_size *= COMPRESS_BUF_SIZE_RATIO;
+	/*
+	 * Buffers to be used in compression and decompression.
+	 * Since decompressed data might be larger than
+	 * compressed data (due to block header),
+	 * buffers should be big enough for both cases.
+	 */
+	ts_params->mbuf_pool = rte_pktmbuf_pool_create("mbuf_pool",
+			NUM_MBUFS,
+			CACHE_SIZE, 0,
+			max_buf_size + RTE_PKTMBUF_HEADROOM,
+			rte_socket_id());
+	if (ts_params->mbuf_pool == NULL) {
+		RTE_LOG(ERR, USER1, "Large mbuf pool could not be created\n");
+		goto exit;
+	}
+
+	/*
+	 * Create session mempool, with two objects per session,
+	 * one for the session header and another one for the
+	 * private session data for the compress device.
+	 */
+	uint32_t session_size = rte_compressdev_get_private_session_size(0);
+	ts_params->sess_pool = rte_mempool_create("session_pool",
+						NUM_SESSIONS * 2,
+						session_size,
+						0, 0, NULL, NULL, NULL,
+						NULL, rte_socket_id(), 0);
+	if (ts_params->sess_pool == NULL) {
+		RTE_LOG(ERR, USER1, "Session pool could not be created\n");
+		goto exit;
+	}
+	ts_params->op_pool = rte_comp_op_pool_create("op_pool", NUM_OPS,
+						0, 0, rte_socket_id());
+	if (ts_params->op_pool == NULL) {
+		RTE_LOG(ERR, USER1, "Operation pool could not be created\n");
+		goto exit;
+	}
+
+	/* Initializes default values for compress/decompress xforms */
+	ts_params->def_comp_xform.next = NULL;
+	ts_params->def_comp_xform.type = RTE_COMP_COMPRESS;
+	ts_params->def_comp_xform.compress.algo = RTE_COMP_DEFLATE,
+	ts_params->def_comp_xform.compress.deflate.huffman = RTE_COMP_DEFAULT;
+	ts_params->def_comp_xform.compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
+	ts_params->def_comp_xform.compress.chksum = RTE_COMP_NONE;
+	ts_params->def_comp_xform.compress.window_size = DEFAULT_WINDOW_SIZE;
+
+	ts_params->def_decomp_xform.next = NULL;
+	ts_params->def_decomp_xform.type = RTE_COMP_DECOMPRESS;
+	ts_params->def_decomp_xform.decompress.algo = RTE_COMP_DEFLATE,
+	ts_params->def_decomp_xform.decompress.chksum = RTE_COMP_NONE;
+	ts_params->def_decomp_xform.decompress.window_size = DEFAULT_WINDOW_SIZE;
+
+	return TEST_SUCCESS;
+
+exit:
+	testsuite_teardown();
+
+	return TEST_FAILED;
+}
+
+static int
+generic_ut_setup(void)
+{
+	/* Configure compressdev (one device, one queue pair) */
+	struct rte_compressdev_config config = {
+		.socket_id = rte_socket_id(),
+		.nb_queue_pairs = 1,
+	};
+
+	if (rte_compressdev_configure(0, &config) < 0) {
+		RTE_LOG(ERR, USER1, "Device configuration failed\n");
+		return -1;
+	}
+
+	if (rte_compressdev_queue_pair_setup(0, 0, NUM_MAX_INFLIGHT_OPS,
+			rte_socket_id()) < 0) {
+		RTE_LOG(ERR, USER1, "Queue pair setup failed\n");
+		return -1;
+	}
+
+	if (rte_compressdev_start(0) < 0) {
+		RTE_LOG(ERR, USER1, "Device could not be started\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+static void
+generic_ut_teardown(void)
+{
+	rte_compressdev_stop(0);
+}
+
+static int
+compare_buffers(const char *buffer1, uint32_t buffer1_len,
+		const char *buffer2, uint32_t buffer2_len)
+{
+	if (buffer1_len != buffer2_len) {
+		RTE_LOG(ERR, USER1, "Buffer lengths are different\n");
+		return -1;
+	}
+
+	if (memcmp(buffer1, buffer2, buffer1_len) != 0) {
+		RTE_LOG(ERR, USER1, "Buffers are different\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+/*
+ * Maps compressdev and Zlib flush flags
+ */
+static int
+map_zlib_flush_flag(enum rte_comp_flush_flag flag)
+{
+	switch (flag) {
+	case RTE_COMP_FLUSH_NONE:
+		return Z_NO_FLUSH;
+	case RTE_COMP_FLUSH_SYNC:
+		return Z_SYNC_FLUSH;
+	case RTE_COMP_FLUSH_FULL:
+		return Z_FULL_FLUSH;
+	case RTE_COMP_FLUSH_FINAL:
+		return Z_FINISH;
+	/*
+	 * There should be only the values above,
+	 * so this should never happen
+	 */
+	default:
+		return -1;
+	}
+}
+
+static int
+compress_zlib(struct rte_comp_op *op,
+		const struct rte_comp_compress_xform *xform, int mem_level)
+{
+	z_stream stream;
+	int zlib_flush;
+	int strategy, window_bits, comp_level;
+	int ret = -1;
+
+	/* initialize zlib stream */
+	stream.zalloc = Z_NULL;
+	stream.zfree = Z_NULL;
+	stream.opaque = Z_NULL;
+
+	if (xform->deflate.huffman == RTE_COMP_FIXED)
+		strategy = Z_FIXED;
+	else
+		strategy = Z_DEFAULT_STRATEGY;
+
+	/*
+	 * Window bits is the base two logarithm of the window size (in bytes).
+	 * When doing raw DEFLATE, this number will be negative.
+	 */
+	window_bits = -log2(xform->window_size);
+
+	comp_level = xform->level;
+
+	if (comp_level != RTE_COMP_LEVEL_NONE)
+		ret = deflateInit2(&stream, comp_level, Z_DEFLATED,
+			window_bits, mem_level, strategy);
+	else
+		ret = deflateInit(&stream, Z_NO_COMPRESSION);
+
+	if (ret != Z_OK) {
+		printf("Zlib deflate could not be initialized\n");
+		goto exit;
+	}
+
+	/* Assuming stateless operation */
+	stream.avail_in = op->src.length;
+	stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
+	stream.avail_out = op->m_dst->data_len;
+	stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
+
+	/* Stateless operation, all buffer will be compressed in one go */
+	zlib_flush = map_zlib_flush_flag(op->flush_flag);
+	ret = deflate(&stream, zlib_flush);
+
+	if (stream.avail_in != 0) {
+		RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
+		goto exit;
+	}
+
+	//TODO: This is only if flush final is used
+	if (ret != Z_STREAM_END)
+		goto exit;
+
+	op->consumed = op->src.length - stream.avail_in;
+	op->produced = op->m_dst->data_len - stream.avail_out;
+	op->status = RTE_COMP_OP_STATUS_SUCCESS;
+
+	deflateReset(&stream);
+
+	ret = 0;
+exit:
+	deflateEnd(&stream);
+
+	return ret;
+}
+
+static int
+decompress_zlib(struct rte_comp_op *op,
+		const struct rte_comp_decompress_xform *xform)
+{
+	z_stream stream;
+	int window_bits;
+	int zlib_flush;
+	int ret = TEST_FAILED;
+
+	/* initialize zlib stream */
+	stream.zalloc = Z_NULL;
+	stream.zfree = Z_NULL;
+	stream.opaque = Z_NULL;
+
+	/*
+	 * Window bits is the base two logarithm of the window size (in bytes).
+	 * When doing raw DEFLATE, this number will be negative.
+	 */
+	window_bits = -log2(xform->window_size);
+
+	ret = inflateInit2(&stream, window_bits);
+
+	if (ret != Z_OK) {
+		printf("Zlib deflate could not be initialized\n");
+		goto exit;
+	}
+
+	/* Assuming stateless operation */
+	stream.avail_in = op->src.length;
+	stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
+	stream.avail_out = op->m_dst->data_len;
+	stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
+
+	/* Stateless operation, all buffer will be compressed in one go */
+	zlib_flush = map_zlib_flush_flag(op->flush_flag);
+	ret = inflate(&stream, zlib_flush);
+
+	if (stream.avail_in != 0) {
+		RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
+		goto exit;
+	}
+
+	//TODO: This is only if flush final is used
+	if (ret != Z_STREAM_END)
+		goto exit;
+
+	op->consumed = op->src.length - stream.avail_in;
+	op->produced = op->m_dst->data_len - stream.avail_out;
+	op->status = RTE_COMP_OP_STATUS_SUCCESS;
+
+	inflateReset(&stream);
+
+	ret = 0;
+exit:
+	inflateEnd(&stream);
+
+	return ret;
+}
+
+/*
+ * Compresses and decompresses buffer with compressdev API and Zlib API
+ */
+static int
+test_deflate_comp_decomp(const char *test_buffer,
+		const struct rte_comp_xform *compress_xform,
+		const struct rte_comp_xform *decompress_xform,
+		enum rte_comp_op_type state,
+		enum zlib_direction zlib_dir)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	int ret;
+	struct rte_mbuf *comp_buf = NULL;
+	struct rte_mbuf *uncomp_buf = NULL;
+	struct rte_comp_op *op = NULL;
+	struct rte_comp_op *op_processed = NULL;
+	struct rte_comp_session *sess = NULL;
+	char *data_ptr;
+
+	/* Prepare the source mbuf with the data */
+	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+	if (uncomp_buf == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Source mbuf could not be allocated "
+			"from the mempool\n");
+		goto err;
+	}
+
+	data_ptr = rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
+	snprintf(data_ptr, strlen(test_buffer) + 1, "%s", test_buffer);
+
+	/* Prepare the destination mbuf */
+	comp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+	if (comp_buf == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Destination mbuf could not be allocated "
+			"from the mempool\n");
+		goto err;
+	}
+
+	rte_pktmbuf_append(comp_buf,
+			strlen(test_buffer) * COMPRESS_BUF_SIZE_RATIO);
+
+	/* Build the compression operations */
+	op = rte_comp_op_alloc(ts_params->op_pool);
+	if (op == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Compress operation could not be allocated "
+			"from the mempool\n");
+		goto err;
+	}
+
+	op->m_src = uncomp_buf;
+	op->m_dst = comp_buf;
+	op->src.offset = 0;
+	op->src.length = rte_pktmbuf_pkt_len(uncomp_buf);
+	op->dst.offset = 0;
+	if (state == RTE_COMP_OP_STATELESS) {
+		//TODO: FULL or FINAL?
+		op->flush_flag = RTE_COMP_FLUSH_FINAL;
+	} else {
+		RTE_LOG(ERR, USER1,
+			"Stateful operations are not supported "
+			"in these tests yet\n");
+		goto err;
+	}
+	op->input_chksum = 0;
+
+	/* Compress data (either with Zlib API or compressdev API */
+	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
+		ret = compress_zlib(op,
+				&compress_xform->compress,
+				DEFAULT_MEM_LEVEL);
+		if (ret < 0)
+			goto err;
+
+		op_processed = op;
+	} else {
+		uint16_t nb_deqd = 0;
+		/* Create compress session */
+		sess = rte_compressdev_session_create(ts_params->sess_pool);
+		ret = rte_compressdev_session_init(0, sess, compress_xform,
+			ts_params->sess_pool);
+		if (ret < 0) {
+			RTE_LOG(ERR, USER1,
+				"Compression session could not be created\n");
+			goto err;
+		}
+
+		/* Attach session to operation */
+		op->session = sess;
+
+		/* Enqueue and dequeue all operations */
+		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
+		if (ret == 0) {
+			RTE_LOG(ERR, USER1,
+				"The operation could not be enqueued\n");
+			goto err;
+		}
+		do {
+			nb_deqd = rte_compressdev_dequeue_burst(0, 0,
+						&op_processed, 1);
+		} while (nb_deqd < 1);
+
+		/* Free compress session */
+		rte_compressdev_session_clear(0, sess);
+		rte_compressdev_session_terminate(sess);
+		sess = NULL;
+	}
+
+	enum rte_comp_huffman huffman_type =
+		compress_xform->compress.deflate.huffman;
+	RTE_LOG(DEBUG, USER1, "Buffer compressed from %u to %u bytes "
+			"(level = %u, huffman = %s)\n",
+			op_processed->consumed, op_processed->produced,
+			compress_xform->compress.level,
+			huffman_type_strings[huffman_type]);
+
+	/*
+	 * Check operation status and free source mbuf (destination mbuf and
+	 * compress operation information is needed for the decompression stage)
+	 */
+	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
+		RTE_LOG(ERR, USER1,
+			"Some operations were not successful\n");
+		goto err;
+	}
+	rte_pktmbuf_free(uncomp_buf);
+	uncomp_buf = NULL;
+
+	/* Allocate buffer for decompressed data */
+	comp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+	if (comp_buf == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Destination mbuf could not be allocated "
+			"from the mempool\n");
+		goto err;
+	}
+
+	rte_pktmbuf_append(comp_buf, strlen(test_buffer) + 1);
+
+	/* Build the decompression operations */
+	op = rte_comp_op_alloc(ts_params->op_pool);
+	if (op == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Decompress operation could not be allocated "
+			"from the mempool\n");
+		goto err;
+	}
+
+	/* Source buffer is the compressed data from the previous operation */
+	op->m_src = op_processed->m_dst;
+	op->m_dst = uncomp_buf;
+	op->src.offset = 0;
+	/*
+	 * Set the length of the compressed data to the
+	 * number of bytes that were produced in the previous stage
+	 */
+	op->src.length = op_processed->produced;
+	op->dst.offset = 0;
+	if (state == RTE_COMP_OP_STATELESS) {
+		//TODO: FULL or FINAL?
+		op->flush_flag = RTE_COMP_FLUSH_FINAL;
+	} else {
+		RTE_LOG(ERR, USER1,
+			"Stateful operations are not supported "
+			"in these tests yet\n");
+		goto err;
+	}
+	op->input_chksum = 0;
+
+	/*
+	 * Free the previous compress operation,
+	 * as it is not needed anymore
+	 */
+	rte_comp_op_free(op_processed);
+	op_processed = NULL;
+
+	/* Decompress data (either with Zlib API or compressdev API */
+	if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
+		ret = decompress_zlib(op, &decompress_xform->decompress);
+		if (ret < 0)
+			goto err;
+
+		op_processed = op;
+	} else {
+		uint16_t nb_deqd = 0;
+		/* Create compress session */
+		sess = rte_compressdev_session_create(ts_params->sess_pool);
+		ret = rte_compressdev_session_init(0, sess, decompress_xform,
+			ts_params->sess_pool);
+		if (ret < 0) {
+			RTE_LOG(ERR, USER1,
+				"Decompression session could not be created\n");
+			goto err;
+		}
+
+		/* Attach session to operation */
+		op->session = sess;
+
+		/* Enqueue and dequeue all operations */
+		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
+		if (ret == 0) {
+			RTE_LOG(ERR, USER1,
+				"The operation could not be enqueued\n");
+			goto err;
+		}
+		do {
+			nb_deqd = rte_compressdev_dequeue_burst(0, 0,
+						&op_processed, 1);
+		} while (nb_deqd < 1);
+
+		/* Free compress session */
+		rte_compressdev_session_clear(0, sess);
+		rte_compressdev_session_terminate(sess);
+		sess = NULL;
+	}
+
+	RTE_LOG(DEBUG, USER1, "Buffer decompressed from %u to %u bytes\n",
+			op_processed->consumed, op_processed->produced);
+	/*
+	 * Check operation status and free source mbuf (destination mbuf and
+	 * compress operation information is still needed)
+	 */
+	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
+		RTE_LOG(ERR, USER1,
+			"Some operations were not successful\n");
+		goto err;
+	}
+	rte_pktmbuf_free(comp_buf);
+	comp_buf = NULL;
+
+	/*
+	 * Compare the original stream with the decompressed stream
+	 * (in size and the data)
+	 */
+	if (compare_buffers(test_buffer, strlen(test_buffer) + 1,
+			rte_pktmbuf_mtod(op_processed->m_dst, const char *),
+			op_processed->produced) < 0)
+		goto err;
+
+	/* Free rest of resources */
+	rte_pktmbuf_free(uncomp_buf);
+	uncomp_buf = NULL;
+
+	rte_comp_op_free(op_processed);
+	op_processed = NULL;
+
+	return 0;
+
+err:
+	rte_pktmbuf_free(uncomp_buf);
+	rte_pktmbuf_free(comp_buf);
+	rte_comp_op_free(op);
+	rte_comp_op_free(op_processed);
+
+	rte_compressdev_session_clear(0, sess);
+	rte_compressdev_session_terminate(sess);
+
+	return -1;
+}
+
+static int
+test_compressdev_deflate_stateless_fixed(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	const char *test_buffer;
+	uint16_t i;
+	struct rte_comp_xform compress_xform;
+
+	memcpy(&compress_xform, &ts_params->def_comp_xform,
+			sizeof(struct rte_comp_xform));
+	compress_xform.compress.deflate.huffman = RTE_COMP_FIXED;
+
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+		test_buffer = compress_test_bufs[i];
+
+		/* Compress with compressdev, decompress with Zlib */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_DECOMPRESS) < 0)
+			return TEST_FAILED;
+
+		/* Compress with Zlib, decompress with compressdev */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_COMPRESS) < 0)
+			return TEST_FAILED;
+	}
+
+	return TEST_SUCCESS;
+}
+
+static int
+test_compressdev_deflate_stateless_dynamic(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	const char *test_buffer;
+	uint16_t i;
+	struct rte_comp_xform compress_xform;
+
+	memcpy(&compress_xform, &ts_params->def_comp_xform,
+			sizeof(struct rte_comp_xform));
+	compress_xform.compress.deflate.huffman = RTE_COMP_DYNAMIC;
+
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+		test_buffer = compress_test_bufs[i];
+
+		/* Compress with compressdev, decompress with Zlib */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_DECOMPRESS) < 0)
+			return TEST_FAILED;
+
+		/* Compress with Zlib, decompress with compressdev */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_COMPRESS) < 0)
+			return TEST_FAILED;
+	}
+
+	return TEST_SUCCESS;
+}
+
+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(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_CASES_END() /**< NULL terminate unit test array */
+	}
+};
+
+static int
+test_compressdev(void)
+{
+	return unit_test_suite_runner(&compressdev_testsuite);
+}
+
+REGISTER_TEST_COMMAND(compressdev_autotest, test_compressdev);
diff --git a/test/test/test_compressdev_test_buffer.h b/test/test/test_compressdev_test_buffer.h
new file mode 100644
index 000000000..c0492f89a
--- /dev/null
+++ b/test/test/test_compressdev_test_buffer.h
@@ -0,0 +1,295 @@
+#ifndef TEST_COMPRESSDEV_TEST_BUFFERS_H_
+#define TEST_COMPRESSDEV_TEST_BUFFERS_H_
+
+/*
+ * These test buffers are snippets obtained
+ * from the Canterbury and Calgary Corpus
+ * collection.
+ */
+
+/* Snippet of Alice's Adventures in Wonderland */
+static const char test_buf_alice[] =
+	"  Alice was beginning to get very tired of sitting by her sister\n"
+	"on the bank, and of having nothing to do:  once or twice she had\n"
+	"peeped into the book her sister was reading, but it had no\n"
+	"pictures or conversations in it, `and what is the use of a book,'\n"
+	"thought Alice `without pictures or conversation?'\n\n"
+	"  So she was considering in her own mind (as well as she could,\n"
+	"for the hot day made her feel very sleepy and stupid), whether\n"
+	"the pleasure of making a daisy-chain would be worth the trouble\n"
+	"of getting up and picking the daisies, when suddenly a White\n"
+	"Rabbit with pink eyes ran close by her.\n\n"
+	"  There was nothing so VERY remarkable in that; nor did Alice\n"
+	"think it so VERY much out of the way to hear the Rabbit say to\n"
+	"itself, `Oh dear!  Oh dear!  I shall be late!'  (when she thought\n"
+	"it over afterwards, it occurred to her that she ought to have\n"
+	"wondered at this, but at the time it all seemed quite natural);\n"
+	"but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT-\n"
+	"POCKET, and looked at it, and then hurried on, Alice started to\n"
+	"her feet, for it flashed across her mind that she had never\n"
+	"before seen a rabbit with either a waistcoat-pocket, or a watch to\n"
+	"take out of it, and burning with curiosity, she ran across the\n"
+	"field after it, and fortunately was just in time to see it pop\n"
+	"down a large rabbit-hole under the hedge.\n\n"
+	"  In another moment down went Alice after it, never once\n"
+	"considering how in the world she was to get out again.\n\n"
+	"  The rabbit-hole went straight on like a tunnel for some way,\n"
+	"and then dipped suddenly down, so suddenly that Alice had not a\n"
+	"moment to think about stopping herself before she found herself\n"
+	"falling down a very deep well.\n\n"
+	"  Either the well was very deep, or she fell very slowly, for she\n"
+	"had plenty of time as she went down to look about her and to\n"
+	"wonder what was going to happen next.  First, she tried to look\n"
+	"down and make out what she was coming to, but it was too dark to\n"
+	"see anything; then she looked at the sides of the well, and\n"
+	"noticed that they were filled with cupboards and book-shelves;\n"
+	"here and there she saw maps and pictures hung upon pegs.  She\n"
+	"took down a jar from one of the shelves as she passed; it was\n"
+	"labelled `ORANGE MARMALADE', but to her great disappointment it\n"
+	"was empty:  she did not like to drop the jar for fear of killing\n"
+	"somebody, so managed to put it into one of the cupboards as she\n"
+	"fell past it.\n\n"
+	"  `Well!' thought Alice to herself, `after such a fall as this, I\n"
+	"shall think nothing of tumbling down stairs!  How brave they'll\n"
+	"all think me at home!  Why, I wouldn't say anything about it,\n"
+	"even if I fell off the top of the house!' (Which was very likely\n"
+	"true.)\n\n"
+	"  Down, down, down.  Would the fall NEVER come to an end!  `I\n"
+	"wonder how many miles I've fallen by this time?' she said aloud.\n"
+	"`I must be getting somewhere near the centre of the earth.  Let\n"
+	"me see:  that would be four thousand miles down, I think--' (for,\n"
+	"you see, Alice had learnt several things of this sort in her\n"
+	"lessons in the schoolroom, and though this was not a VERY good\n"
+	"opportunity for showing off her knowledge, as there was no one to\n"
+	"listen to her, still it was good practice to say it over) `--yes,\n"
+	"that's about the right distance--but then I wonder what Latitude\n"
+	"or Longitude I've got to?'  (Alice had no idea what Latitude was,\n"
+	"or Longitude either, but thought they were nice grand words to\n"
+	"say.)\n\n"
+	"  Presently she began again.  `I wonder if I shall fall right\n"
+	"THROUGH the earth!  How funny it'll seem to come out among the\n"
+	"people that walk with their heads downward!  The Antipathies, I\n"
+	"think--' (she was rather glad there WAS no one listening, this\n"
+	"time, as it didn't sound at all the right word) `--but I shall\n"
+	"have to ask them what the name of the country is, you know.\n"
+	"Please, Ma'am, is this New Zealand or Australia?' (and she tried\n"
+	"to curtsey as she spoke--fancy CURTSEYING as you're falling\n"
+	"through the air!  Do you think you could manage it?)  `And what\n"
+	"an ignorant little girl she'll think me for asking!  No, it'll\n"
+	"never do to ask:  perhaps I shall see it written up somewhere.'\n"
+	"  Down, down, down.  There was nothing else to do, so Alice soon\n"
+	"began talking again.  `Dinah'll miss me very much to-night, I\n"
+	"should think!'  (Dinah was the cat.)  `I hope they'll remember\n"
+	"her saucer of milk at tea-time.  Dinah my dear!  I wish you were\n"
+	"down here with me!  There are no mice in the air, I'm afraid, but\n"
+	"you might catch a bat, and that's very like a mouse, you know.\n"
+	"But do cats eat bats, I wonder?'  And here Alice began to get\n"
+	"rather sleepy, and went on saying to herself, in a dreamy sort of\n"
+	"way, `Do cats eat bats?  Do cats eat bats?' and sometimes, `Do\n"
+	"bats eat cats?' for, you see, as she couldn't answer either\n"
+	"question, it didn't much matter which way she put it.  She felt\n"
+	"that she was dozing off, and had just begun to dream that she\n"
+	"was walking hand in hand with Dinah, and saying to her very\n"
+	"earnestly, `Now, Dinah, tell me the truth:  did you ever eat a\n"
+	"bat?' when suddenly, thump! thump! down she came upon a heap of\n"
+	"sticks and dry leaves, and the fall was over.\n\n";
+
+/* Snippet of Shakespeare play */
+static const char test_buf_shakespeare[] =
+	"CHARLES	wrestler to Frederick.\n"
+	"\n"
+	"\n"
+	"OLIVER		|\n"
+	"		|\n"
+	"JAQUES (JAQUES DE BOYS:)  	|  sons of Sir Rowland de Boys.\n"
+	"		|\n"
+	"ORLANDO		|\n"
+	"\n"
+	"\n"
+	"ADAM	|\n"
+	"	|  servants to Oliver.\n"
+	"DENNIS	|\n"
+	"\n"
+	"\n"
+	"TOUCHSTONE	a clown.\n"
+	"\n"
+	"SIR OLIVER MARTEXT	a vicar.\n"
+	"\n"
+	"\n"
+	"CORIN	|\n"
+	"	|  shepherds.\n"
+	"SILVIUS	|\n"
+	"\n"
+	"\n"
+	"WILLIAM	a country fellow in love with Audrey.\n"
+	"\n"
+	"	A person representing HYMEN. (HYMEN:)\n"
+	"\n"
+	"ROSALIND	daughter to the banished duke.\n"
+	"\n"
+	"CELIA	daughter to Frederick.\n"
+	"\n"
+	"PHEBE	a shepherdess.\n"
+	"\n"
+	"AUDREY	a country wench.\n"
+	"\n"
+	"	Lords, pages, and attendants, &c.\n"
+	"	(Forester:)\n"
+	"	(A Lord:)\n"
+	"	(First Lord:)\n"
+	"	(Second Lord:)\n"
+	"	(First Page:)\n"
+	"	(Second Page:)\n"
+	"\n"
+	"\n"
+	"SCENE	Oliver's house; Duke Frederick's court; and the\n"
+	"	Forest of Arden.\n"
+	"\n"
+	"\n"
+	"\n"
+	"\n"
+	"	AS YOU LIKE IT\n"
+	"\n"
+	"\n"
+	"ACT I\n"
+	"\n"
+	"\n"
+	"\n"
+	"SCENE I	Orchard of Oliver's house.\n"
+	"\n"
+	"\n"
+	"	[Enter ORLANDO and ADAM]\n"
+	"\n"
+	"ORLANDO	As I remember, Adam, it was upon this fashion\n"
+	"	bequeathed me by will but poor a thousand crowns,\n"
+	"	and, as thou sayest, charged my brother, on his\n"
+	"	blessing, to breed me well: and there begins my\n"
+	"	sadness. My brother Jaques he keeps at school, and\n"
+	"	report speaks goldenly of his profit: for my part,\n"
+	"	he keeps me rustically at home, or, to speak more\n"
+	"	properly, stays me here at home unkept; for call you\n"
+	"	that keeping for a gentleman of my birth, that\n"
+	"	differs not from the stalling of an ox? His horses\n"
+	"	are bred better; for, besides that they are fair\n"
+	"	with their feeding, they are taught their manage,\n"
+	"	and to that end riders dearly hired: but I, his\n"
+	"	brother, gain nothing under him but growth; for the\n"
+	"	which his animals on his dunghills are as much\n"
+	"	bound to him as I. Besides this nothing that he so\n"
+	"	plentifully gives me, the something that nature gave\n"
+	"	me his countenance seems to take from me: he lets\n"
+	"	me feed with his hinds, bars me the place of a\n"
+	"	brother, and, as much as in him lies, mines my\n"
+	"	gentility with my education. This is it, Adam, that\n"
+	"	grieves me; and the spirit of my father, which I\n"
+	"	think is within me, begins to mutiny against this\n"
+	"	servitude: I will no longer endure it, though yet I\n"
+	"	know no wise remedy how to avoid it.\n"
+	"\n"
+	"ADAM	Yonder comes my master, your brother.\n"
+	"\n"
+	"ORLANDO	Go apart, Adam, and thou shalt hear how he will\n";
+
+/* Snippet of source code in Pascal */
+static const char test_buf_pascal[] =
+	"	Ptr    = 1..DMem;\n"
+	"	Loc    = 1..IMem;\n"
+	"	Loc0   = 0..IMem;\n"
+	"	EdgeT  = (hout,lin,hin,lout); {Warning this order is important in}\n"
+	"				      {predicates such as gtS,geS}\n"
+	"	CardT  = (finite,infinite);\n"
+	"	ExpT   = Minexp..Maxexp;\n"
+	"	ManT   = Mininf..Maxinf; \n"
+	"	Pflag  = (PNull,PSoln,PTrace,PPrint);\n"
+	"	Sreal  = record\n"
+	"		    edge:EdgeT;\n"
+	"		    cardinality:CardT;\n"
+	"		    exp:ExpT; {exponent}\n"
+	"		    mantissa:ManT;\n"
+	"		 end;\n"
+	"	Int    = record\n"
+	"		    hi:Sreal;\n"
+	"		    lo:Sreal;\n"
+	"	 end;\n"
+	"	Instr  = record\n"
+	"		    Code:OpType;\n"
+	"		    Pars: array[0..Par] of 0..DMem;\n"
+	"		 end;\n"
+	"	DataMem= record\n"
+	"		    D        :array [Ptr] of Int;\n"
+	"		    S        :array [Loc] of State;\n"
+	"		    LastHalve:Loc;\n"
+	"		    RHalve   :array [Loc] of real;\n"
+	"		 end;\n"
+	"	DataFlags=record\n"
+	"		    PF	     :array [Ptr] of Pflag;\n"
+	"		 end;\n"
+	"var\n"
+	"	Debug  : (none,activity,post,trace,dump);\n"
+	"	Cut    : (once,all);\n"
+	"	GlobalEnd,Verifiable:boolean;\n"
+	"	HalveThreshold:real;\n"
+	"	I      : array [Loc] of Instr; {Memory holding instructions}\n"
+	"	End    : Loc; {last instruction in I}\n"
+	"	ParN   : array [OpType] of -1..Par; {number of parameters for each \n"
+	"			opcode. -1 means no result}\n"
+	"        ParIntersect : array [OpType] of boolean ;\n"
+	"	DInit  : DataMem; {initial memory which is cleared and \n"
+	"				used in first call}\n"
+	"	DF     : DataFlags; {hold flags for variables, e.g. print/trace}\n"
+	"	MaxDMem:0..DMem;\n"
+	"	Shift  : array[0..Digits] of 1..maxint;{array of constant multipliers}\n"
+	"						{used for alignment etc.}\n"
+	"	Dummy  :Positive;\n"
+	"	{constant intervals and Sreals}\n"
+	"	PlusInfS,MinusInfS,PlusSmallS,MinusSmallS,ZeroS,\n"
+	"	PlusFiniteS,MinusFiniteS:Sreal;\n"
+	"	Zero,All,AllFinite:Int;\n"
+	"\n"
+	"procedure deblank;\n"
+	"var Ch:char;\n"
+	"begin\n"
+	"   while (not eof) and (input^ in [' ','	']) do read(Ch);\n"
+	"end;\n"
+	"\n"
+	"procedure InitialOptions;\n"
+	"\n"
+	"#include '/user/profs/cleary/bin/options.i';\n"
+	"\n"
+	"   procedure Option;\n"
+	"   begin\n"
+	"      case Opt of\n"
+	"      'a','A':Debug:=activity;\n"
+	"      'd','D':Debug:=dump;\n"
+	"      'h','H':HalveThreshold:=StringNum/100;\n"
+	"      'n','N':Debug:=none;\n"
+	"      'p','P':Debug:=post;\n"
+	"      't','T':Debug:=trace;\n"
+	"      'v','V':Verifiable:=true;\n"
+	"      end;\n"
+	"   end;\n"
+	"\n"
+	"begin\n"
+	"   Debug:=trace;\n"
+	"   Verifiable:=false;\n"
+	"   HalveThreshold:=67/100;\n"
+	"   Options;\n"
+	"   writeln(Debug);\n"
+	"   writeln('Verifiable:',Verifiable);\n"
+	"   writeln('Halve threshold',HalveThreshold);\n"
+	"end;{InitialOptions}\n"
+	"\n"
+	"procedure NormalizeUp(E,M:integer;var S:Sreal;var Closed:boolean);\n"
+	"begin\n"
+	"with S do\n"
+	"begin\n"
+	"   if M=0 then S:=ZeroS else\n"
+	"   if M>0 then\n";
+
+static const char * const compress_test_bufs[] = {
+	test_buf_alice,
+	test_buf_shakespeare,
+	test_buf_pascal
+};
+
+#endif /* TEST_COMPRESSDEV_TEST_BUFFERS_H_ */
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH 3/5] test/compress: add multi op test
  2018-02-28 14:00 [dpdk-dev] [PATCH 0/5] Initial compressdev unit tests Pablo de Lara
  2018-02-28 14:00 ` [dpdk-dev] [PATCH 1/5] compressdev: add const for xform in session init Pablo de Lara
  2018-02-28 14:00 ` [dpdk-dev] [PATCH 2/5] test/compress: add initial unit tests Pablo de Lara
@ 2018-02-28 14:00 ` Pablo de Lara
  2018-02-28 14:00 ` [dpdk-dev] [PATCH 4/5] test/compress: add multi level test Pablo de Lara
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-02-28 14:00 UTC (permalink / raw)
  To: fiona.trahe, Shally.Verma, ahmed.mansour, lee.daly, tomaszx.jozwiak
  Cc: dev, Pablo de Lara

Add test that checks if multiple operations with
different buffers can be handled on a single enqueue call.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 test/test/test_compressdev.c | 366 ++++++++++++++++++++++++++++---------------
 1 file changed, 240 insertions(+), 126 deletions(-)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index e92b8142b..ad7585f13 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -45,6 +45,10 @@ enum zlib_direction {
 	ZLIB_ALL
 };
 
+struct priv_op_data {
+	uint16_t orig_idx;
+};
+
 struct comp_testsuite_params {
 	struct rte_mempool *mbuf_pool;
 	struct rte_mempool *sess_pool;
@@ -114,7 +118,8 @@ testsuite_setup(void)
 		goto exit;
 	}
 	ts_params->op_pool = rte_comp_op_pool_create("op_pool", NUM_OPS,
-						0, 0, rte_socket_id());
+				0, sizeof(struct priv_op_data),
+				rte_socket_id());
 	if (ts_params->op_pool == NULL) {
 		RTE_LOG(ERR, USER1, "Operation pool could not be created\n");
 		goto exit;
@@ -351,7 +356,9 @@ decompress_zlib(struct rte_comp_op *op,
  * Compresses and decompresses buffer with compressdev API and Zlib API
  */
 static int
-test_deflate_comp_decomp(const char *test_buffer,
+test_deflate_comp_decomp(const char * const test_bufs[],
+		unsigned int num_bufs,
+		uint16_t buf_idx[],
 		const struct rte_comp_xform *compress_xform,
 		const struct rte_comp_xform *decompress_xform,
 		enum rte_comp_op_type state,
@@ -359,73 +366,97 @@ test_deflate_comp_decomp(const char *test_buffer,
 {
 	struct comp_testsuite_params *ts_params = &testsuite_params;
 	int ret;
-	struct rte_mbuf *comp_buf = NULL;
-	struct rte_mbuf *uncomp_buf = NULL;
-	struct rte_comp_op *op = NULL;
-	struct rte_comp_op *op_processed = NULL;
+	struct rte_mbuf *uncomp_bufs[num_bufs];
+	struct rte_mbuf *comp_bufs[num_bufs];
+	struct rte_comp_op *ops[num_bufs];
+	struct rte_comp_op *ops_processed[num_bufs];
 	struct rte_comp_session *sess = NULL;
+	uint16_t num_enqd, num_deqd;
+	struct priv_op_data *priv_data;
 	char *data_ptr;
+	unsigned int i;
+
+	/* Initialize all arrays to NULL */
+	memset(uncomp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
+	memset(comp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
+	memset(ops, 0, sizeof(struct rte_comp_op *) * num_bufs);
+	memset(ops_processed, 0, sizeof(struct rte_comp_op *) * num_bufs);
 
-	/* Prepare the source mbuf with the data */
-	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
-	if (uncomp_buf == NULL) {
+	/* Prepare the source mbufs with the data */
+	ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, uncomp_bufs, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Source mbuf could not be allocated "
+			"Source mbufs could not be allocated "
 			"from the mempool\n");
 		goto err;
 	}
 
-	data_ptr = rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
-	snprintf(data_ptr, strlen(test_buffer) + 1, "%s", test_buffer);
+	for (i = 0; i < num_bufs; i++) {
+		data_ptr = rte_pktmbuf_append(uncomp_bufs[i], strlen(test_bufs[i]) + 1);
+		snprintf(data_ptr, strlen(test_bufs[i]) + 1, "%s", test_bufs[i]);
+	}
 
-	/* Prepare the destination mbuf */
-	comp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
-	if (comp_buf == NULL) {
+	/* Prepare the destination mbufs */
+	ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, comp_bufs, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Destination mbuf could not be allocated "
+			"Destination mbufs could not be allocated "
 			"from the mempool\n");
 		goto err;
 	}
 
-	rte_pktmbuf_append(comp_buf,
-			strlen(test_buffer) * COMPRESS_BUF_SIZE_RATIO);
+	for (i = 0; i < num_bufs; i++)
+		rte_pktmbuf_append(comp_bufs[i],
+			strlen(test_bufs[i]) * COMPRESS_BUF_SIZE_RATIO);
 
 	/* Build the compression operations */
-	op = rte_comp_op_alloc(ts_params->op_pool);
-	if (op == NULL) {
+	ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Compress operation could not be allocated "
+			"Compress operations could not be allocated "
 			"from the mempool\n");
 		goto err;
 	}
 
-	op->m_src = uncomp_buf;
-	op->m_dst = comp_buf;
-	op->src.offset = 0;
-	op->src.length = rte_pktmbuf_pkt_len(uncomp_buf);
-	op->dst.offset = 0;
-	if (state == RTE_COMP_OP_STATELESS) {
-		//TODO: FULL or FINAL?
-		op->flush_flag = RTE_COMP_FLUSH_FINAL;
-	} else {
-		RTE_LOG(ERR, USER1,
-			"Stateful operations are not supported "
-			"in these tests yet\n");
-		goto err;
+	for (i = 0; i < num_bufs; i++) {
+		ops[i]->m_src = uncomp_bufs[i];
+		ops[i]->m_dst = comp_bufs[i];
+		ops[i]->src.offset = 0;
+		ops[i]->src.length = rte_pktmbuf_pkt_len(uncomp_bufs[i]);
+		ops[i]->dst.offset = 0;
+		if (state == RTE_COMP_OP_STATELESS) {
+			//TODO: FULL or FINAL?
+			ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
+		} else {
+			RTE_LOG(ERR, USER1,
+				"Stateful operations are not supported "
+				"in these tests yet\n");
+			goto err;
+		}
+		ops[i]->input_chksum = 0;
+		/*
+		 * Store original operation index in private data,
+		 * since ordering does not have to be maintained,
+		 * when dequeueing from compressdev, so a comparison
+		 * at the end of the test can be done.
+		 */
+		priv_data = (struct priv_op_data *) (ops[i] + 1);
+		priv_data->orig_idx = i;
 	}
-	op->input_chksum = 0;
 
 	/* Compress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
-		ret = compress_zlib(op,
-				&compress_xform->compress,
-				DEFAULT_MEM_LEVEL);
-		if (ret < 0)
-			goto err;
-
-		op_processed = op;
+		for (i = 0; i < num_bufs; i++) {
+			ret = compress_zlib(ops[i],
+					&compress_xform->compress,
+					DEFAULT_MEM_LEVEL);
+			if (ret < 0)
+				goto err;
+
+			ops_processed[i] = ops[i];
+		}
 	} else {
-		uint16_t nb_deqd = 0;
+		num_deqd = 0;
 		/* Create compress session */
 		sess = rte_compressdev_session_create(ts_params->sess_pool);
 		ret = rte_compressdev_session_init(0, sess, compress_xform,
@@ -437,19 +468,21 @@ test_deflate_comp_decomp(const char *test_buffer,
 		}
 
 		/* Attach session to operation */
-		op->session = sess;
+		for (i = 0; i < num_bufs; i++)
+			ops[i]->session = sess;
 
 		/* Enqueue and dequeue all operations */
-		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
-		if (ret == 0) {
+		num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
+		if (num_enqd < num_bufs) {
 			RTE_LOG(ERR, USER1,
-				"The operation could not be enqueued\n");
+				"The operations could not be enqueued\n");
 			goto err;
 		}
+
 		do {
-			nb_deqd = rte_compressdev_dequeue_burst(0, 0,
-						&op_processed, 1);
-		} while (nb_deqd < 1);
+			num_deqd += rte_compressdev_dequeue_burst(0, 0,
+					&ops_processed[num_deqd], num_bufs);
+		} while (num_deqd < num_enqd);
 
 		/* Free compress session */
 		rte_compressdev_session_clear(0, sess);
@@ -459,81 +492,104 @@ test_deflate_comp_decomp(const char *test_buffer,
 
 	enum rte_comp_huffman huffman_type =
 		compress_xform->compress.deflate.huffman;
-	RTE_LOG(DEBUG, USER1, "Buffer compressed from %u to %u bytes "
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *) (ops_processed[i] + 1);
+		RTE_LOG(DEBUG, USER1, "Buffer %u compressed from %u to %u bytes "
 			"(level = %u, huffman = %s)\n",
-			op_processed->consumed, op_processed->produced,
+			buf_idx[priv_data->orig_idx],
+			ops_processed[i]->consumed, ops_processed[i]->produced,
 			compress_xform->compress.level,
 			huffman_type_strings[huffman_type]);
+	}
 
 	/*
-	 * Check operation status and free source mbuf (destination mbuf and
+	 * Check operation status and free source mbufs (destination mbuf and
 	 * compress operation information is needed for the decompression stage)
 	 */
-	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
-		RTE_LOG(ERR, USER1,
-			"Some operations were not successful\n");
-		goto err;
+	for (i = 0; i < num_bufs; i++) {
+		if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
+			RTE_LOG(ERR, USER1,
+				"Some operations were not successful\n");
+			goto err;
+		}
+		priv_data = (struct priv_op_data *) (ops_processed[i] + 1);
+		rte_pktmbuf_free(uncomp_bufs[priv_data->orig_idx]);
+		uncomp_bufs[priv_data->orig_idx] = NULL;
 	}
-	rte_pktmbuf_free(uncomp_buf);
-	uncomp_buf = NULL;
 
-	/* Allocate buffer for decompressed data */
-	comp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
-	if (comp_buf == NULL) {
+	/* Allocate buffers for decompressed data */
+	ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, uncomp_bufs, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Destination mbuf could not be allocated "
+			"Destination mbufs could not be allocated "
 			"from the mempool\n");
 		goto err;
 	}
 
-	rte_pktmbuf_append(comp_buf, strlen(test_buffer) + 1);
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *) (ops_processed[i] + 1);
+		rte_pktmbuf_append(uncomp_bufs[i],
+				strlen(test_bufs[priv_data->orig_idx]) + 1);
+	}
 
 	/* Build the decompression operations */
-	op = rte_comp_op_alloc(ts_params->op_pool);
-	if (op == NULL) {
+	ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Decompress operation could not be allocated "
+			"Decompress operations could not be allocated "
 			"from the mempool\n");
 		goto err;
 	}
 
-	/* Source buffer is the compressed data from the previous operation */
-	op->m_src = op_processed->m_dst;
-	op->m_dst = uncomp_buf;
-	op->src.offset = 0;
-	/*
-	 * Set the length of the compressed data to the
-	 * number of bytes that were produced in the previous stage
-	 */
-	op->src.length = op_processed->produced;
-	op->dst.offset = 0;
-	if (state == RTE_COMP_OP_STATELESS) {
-		//TODO: FULL or FINAL?
-		op->flush_flag = RTE_COMP_FLUSH_FINAL;
-	} else {
-		RTE_LOG(ERR, USER1,
-			"Stateful operations are not supported "
-			"in these tests yet\n");
-		goto err;
+	/* Source buffer is the compressed data from the previous operations */
+	for (i = 0; i < num_bufs; i++) {
+		ops[i]->m_src = ops_processed[i]->m_dst;
+		ops[i]->m_dst = uncomp_bufs[i];
+		ops[i]->src.offset = 0;
+		/*
+		 * Set the length of the compressed data to the
+		 * number of bytes that were produced in the previous stage
+		 */
+		ops[i]->src.length = ops_processed[i]->produced;
+		ops[i]->dst.offset = 0;
+		if (state == RTE_COMP_OP_STATELESS) {
+			//TODO: FULL or FINAL?
+			ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
+		} else {
+			RTE_LOG(ERR, USER1,
+				"Stateful operations are not supported "
+				"in these tests yet\n");
+			goto err;
+		}
+		ops[i]->input_chksum = 0;
+		/*
+		 * Copy private data from previous operations,
+		 * to keep the pointer to the original buffer
+		 */
+		memcpy(ops[i] + 1, ops_processed[i] + 1, sizeof(struct priv_op_data));
 	}
-	op->input_chksum = 0;
 
 	/*
-	 * Free the previous compress operation,
+	 * Free the previous compress operations,
 	 * as it is not needed anymore
 	 */
-	rte_comp_op_free(op_processed);
-	op_processed = NULL;
+	for (i = 0; i < num_bufs; i++) {
+		rte_comp_op_free(ops_processed[i]);
+		ops_processed[i] = NULL;
+	}
 
 	/* Decompress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
-		ret = decompress_zlib(op, &decompress_xform->decompress);
-		if (ret < 0)
-			goto err;
+		for (i = 0; i < num_bufs; i++) {
+			ret = decompress_zlib(ops[i],
+					&decompress_xform->decompress);
+			if (ret < 0)
+				goto err;
 
-		op_processed = op;
+			ops_processed[i] = ops[i];
+		}
 	} else {
-		uint16_t nb_deqd = 0;
+		num_deqd = 0;
 		/* Create compress session */
 		sess = rte_compressdev_session_create(ts_params->sess_pool);
 		ret = rte_compressdev_session_init(0, sess, decompress_xform,
@@ -545,19 +601,21 @@ test_deflate_comp_decomp(const char *test_buffer,
 		}
 
 		/* Attach session to operation */
-		op->session = sess;
+		for (i = 0; i < num_bufs; i++)
+			ops[i]->session = sess;
 
 		/* Enqueue and dequeue all operations */
-		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
-		if (ret == 0) {
+		num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
+		if (num_enqd < num_bufs) {
 			RTE_LOG(ERR, USER1,
-				"The operation could not be enqueued\n");
+				"The operations could not be enqueued\n");
 			goto err;
 		}
+
 		do {
-			nb_deqd = rte_compressdev_dequeue_burst(0, 0,
-						&op_processed, 1);
-		} while (nb_deqd < 1);
+			num_deqd += rte_compressdev_dequeue_burst(0, 0,
+					&ops_processed[num_deqd], num_bufs);
+		} while (num_deqd < num_enqd);
 
 		/* Free compress session */
 		rte_compressdev_session_clear(0, sess);
@@ -565,44 +623,62 @@ test_deflate_comp_decomp(const char *test_buffer,
 		sess = NULL;
 	}
 
-	RTE_LOG(DEBUG, USER1, "Buffer decompressed from %u to %u bytes\n",
-			op_processed->consumed, op_processed->produced);
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *) (ops_processed[i] + 1);
+		RTE_LOG(DEBUG, USER1, "Buffer %u decompressed from %u to %u bytes\n",
+			buf_idx[priv_data->orig_idx],
+			ops_processed[i]->consumed, ops_processed[i]->produced);
+	}
+
 	/*
 	 * Check operation status and free source mbuf (destination mbuf and
 	 * compress operation information is still needed)
 	 */
-	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
-		RTE_LOG(ERR, USER1,
-			"Some operations were not successful\n");
-		goto err;
+	for (i = 0; i < num_bufs; i++) {
+		if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
+			RTE_LOG(ERR, USER1,
+				"Some operations were not successful\n");
+			goto err;
+		}
+		priv_data = (struct priv_op_data *) (ops_processed[i] + 1);
+		rte_pktmbuf_free(comp_bufs[priv_data->orig_idx]);
+		comp_bufs[priv_data->orig_idx] = NULL;
 	}
-	rte_pktmbuf_free(comp_buf);
-	comp_buf = NULL;
 
 	/*
 	 * Compare the original stream with the decompressed stream
 	 * (in size and the data)
 	 */
-	if (compare_buffers(test_buffer, strlen(test_buffer) + 1,
-			rte_pktmbuf_mtod(op_processed->m_dst, const char *),
-			op_processed->produced) < 0)
-		goto err;
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *) (ops_processed[i] + 1);
+		const char *buf1 = test_bufs[priv_data->orig_idx];
+		const char *buf2 = rte_pktmbuf_mtod(ops_processed[i]->m_dst,
+				const char *);
+
+		if (compare_buffers(buf1, strlen(buf1) + 1,
+				buf2, ops_processed[i]->produced) < 0)
+			goto err;
+	}
 
 	/* Free rest of resources */
-	rte_pktmbuf_free(uncomp_buf);
-	uncomp_buf = NULL;
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *) (ops_processed[i] + 1);
+		rte_pktmbuf_free(uncomp_bufs[priv_data->orig_idx]);
+		uncomp_bufs[priv_data->orig_idx] = NULL;
 
-	rte_comp_op_free(op_processed);
-	op_processed = NULL;
+		rte_comp_op_free(ops_processed[i]);
+		ops_processed[i] = NULL;
+	}
 
 	return 0;
 
 err:
-	rte_pktmbuf_free(uncomp_buf);
-	rte_pktmbuf_free(comp_buf);
-	rte_comp_op_free(op);
-	rte_comp_op_free(op_processed);
-
+	for (i = 0; i < num_bufs; i++) {
+		rte_pktmbuf_free(uncomp_bufs[i]);
+		rte_pktmbuf_free(comp_bufs[i]);
+		rte_comp_op_free(ops[i]);
+		rte_comp_op_free(ops_processed[i]);
+	}
 	rte_compressdev_session_clear(0, sess);
 	rte_compressdev_session_terminate(sess);
 
@@ -625,7 +701,8 @@ test_compressdev_deflate_stateless_fixed(void)
 		test_buffer = compress_test_bufs[i];
 
 		/* Compress with compressdev, decompress with Zlib */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -633,7 +710,8 @@ test_compressdev_deflate_stateless_fixed(void)
 			return TEST_FAILED;
 
 		/* Compress with Zlib, decompress with compressdev */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -660,7 +738,8 @@ test_compressdev_deflate_stateless_dynamic(void)
 		test_buffer = compress_test_bufs[i];
 
 		/* Compress with compressdev, decompress with Zlib */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -668,7 +747,8 @@ test_compressdev_deflate_stateless_dynamic(void)
 			return TEST_FAILED;
 
 		/* Compress with Zlib, decompress with compressdev */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -679,6 +759,38 @@ test_compressdev_deflate_stateless_dynamic(void)
 	return TEST_SUCCESS;
 }
 
+static int
+test_compressdev_deflate_stateless_multi_op(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	uint16_t num_bufs = RTE_DIM(compress_test_bufs);
+	uint16_t buf_idx[num_bufs];
+	uint16_t i;
+
+	for (i = 0; i < num_bufs; i++)
+		buf_idx[i] = i;
+
+	/* Compress with compressdev, decompress with Zlib */
+	if (test_deflate_comp_decomp(compress_test_bufs, num_bufs,
+			buf_idx,
+			&ts_params->def_comp_xform,
+			&ts_params->def_decomp_xform,
+			RTE_COMP_OP_STATELESS,
+			ZLIB_DECOMPRESS) < 0)
+		return TEST_FAILED;
+
+	/* Compress with Zlib, decompress with compressdev */
+	if (test_deflate_comp_decomp(compress_test_bufs, num_bufs,
+			buf_idx,
+			&ts_params->def_comp_xform,
+			&ts_params->def_decomp_xform,
+			RTE_COMP_OP_STATELESS,
+			ZLIB_COMPRESS) < 0)
+		return TEST_FAILED;
+
+	return TEST_SUCCESS;
+}
+
 static struct unit_test_suite compressdev_testsuite  = {
 	.suite_name = "compressdev unit test suite",
 	.setup = testsuite_setup,
@@ -688,6 +800,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 			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_multi_op),
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH 4/5] test/compress: add multi level test
  2018-02-28 14:00 [dpdk-dev] [PATCH 0/5] Initial compressdev unit tests Pablo de Lara
                   ` (2 preceding siblings ...)
  2018-02-28 14:00 ` [dpdk-dev] [PATCH 3/5] test/compress: add multi op test Pablo de Lara
@ 2018-02-28 14:00 ` Pablo de Lara
  2018-02-28 14:00 ` [dpdk-dev] [PATCH 5/5] test/compress: add multi session test Pablo de Lara
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-02-28 14:00 UTC (permalink / raw)
  To: fiona.trahe, Shally.Verma, ahmed.mansour, lee.daly, tomaszx.jozwiak
  Cc: dev, Pablo de Lara

Add test that checks if all compression levels
are supported and compress a buffer correctly.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 test/test/test_compressdev.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index ad7585f13..8f19413cd 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -791,6 +791,37 @@ test_compressdev_deflate_stateless_multi_op(void)
 	return TEST_SUCCESS;
 }
 
+
+static int
+test_compressdev_deflate_stateless_multi_level(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	const char *test_buffer;
+	unsigned int level;
+	uint16_t i;
+	struct rte_comp_xform compress_xform;
+
+	memcpy(&compress_xform, &ts_params->def_comp_xform,
+			sizeof(struct rte_comp_xform));
+
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+		test_buffer = compress_test_bufs[i];
+		for (level = RTE_COMP_LEVEL_MIN; level <= RTE_COMP_LEVEL_MAX;
+				level++) {
+			compress_xform.compress.level = level;
+			/* Compress with compressdev, decompress with Zlib */
+			if (test_deflate_comp_decomp(&test_buffer, 1,
+					&i,
+					&compress_xform,
+					&ts_params->def_decomp_xform,
+					RTE_COMP_OP_STATELESS,
+					ZLIB_DECOMPRESS) < 0)
+				return TEST_FAILED;
+		}
+	}
+
+	return TEST_SUCCESS;
+}
 static struct unit_test_suite compressdev_testsuite  = {
 	.suite_name = "compressdev unit test suite",
 	.setup = testsuite_setup,
@@ -802,6 +833,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 			test_compressdev_deflate_stateless_dynamic),
 		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_CASES_END() /**< NULL terminate unit test array */
 	}
 };
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH 5/5] test/compress: add multi session test
  2018-02-28 14:00 [dpdk-dev] [PATCH 0/5] Initial compressdev unit tests Pablo de Lara
                   ` (3 preceding siblings ...)
  2018-02-28 14:00 ` [dpdk-dev] [PATCH 4/5] test/compress: add multi level test Pablo de Lara
@ 2018-02-28 14:00 ` Pablo de Lara
  2018-04-08 14:00 ` [dpdk-dev] [PATCH v2 0/5] Initial compressdev unit tests Pablo de Lara
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-02-28 14:00 UTC (permalink / raw)
  To: fiona.trahe, Shally.Verma, ahmed.mansour, lee.daly, tomaszx.jozwiak
  Cc: dev, Pablo de Lara

Add test that checks if multiple sessions can be
handled on a single enqueue call.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 test/test/test_compressdev.c | 280 +++++++++++++++++++++++++++++++------------
 1 file changed, 202 insertions(+), 78 deletions(-)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index 8f19413cd..5a7635d06 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -25,7 +25,7 @@
 #define COMPRESS_BUF_SIZE_RATIO 1.3
 #define NUM_MBUFS 16
 #define NUM_OPS 16
-#define NUM_SESSIONS 1
+#define NUM_MAX_SESSIONS 16
 #define NUM_MAX_INFLIGHT_OPS 128
 #define CACHE_SIZE 0
 
@@ -53,8 +53,8 @@ struct comp_testsuite_params {
 	struct rte_mempool *mbuf_pool;
 	struct rte_mempool *sess_pool;
 	struct rte_mempool *op_pool;
-	struct rte_comp_xform def_comp_xform;
-	struct rte_comp_xform def_decomp_xform;
+	struct rte_comp_xform *def_comp_xform;
+	struct rte_comp_xform *def_decomp_xform;
 };
 
 static struct comp_testsuite_params testsuite_params = { 0 };
@@ -67,6 +67,8 @@ testsuite_teardown(void)
 	rte_mempool_free(ts_params->mbuf_pool);
 	rte_mempool_free(ts_params->sess_pool);
 	rte_mempool_free(ts_params->op_pool);
+	rte_free(ts_params->def_comp_xform);
+	rte_free(ts_params->def_decomp_xform);
 }
 
 static int
@@ -109,7 +111,7 @@ testsuite_setup(void)
 	 */
 	uint32_t session_size = rte_compressdev_get_private_session_size(0);
 	ts_params->sess_pool = rte_mempool_create("session_pool",
-						NUM_SESSIONS * 2,
+						NUM_MAX_SESSIONS * 2,
 						session_size,
 						0, 0, NULL, NULL, NULL,
 						NULL, rte_socket_id(), 0);
@@ -125,20 +127,25 @@ testsuite_setup(void)
 		goto exit;
 	}
 
+	ts_params->def_comp_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
+	ts_params->def_decomp_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
+
 	/* Initializes default values for compress/decompress xforms */
-	ts_params->def_comp_xform.next = NULL;
-	ts_params->def_comp_xform.type = RTE_COMP_COMPRESS;
-	ts_params->def_comp_xform.compress.algo = RTE_COMP_DEFLATE,
-	ts_params->def_comp_xform.compress.deflate.huffman = RTE_COMP_DEFAULT;
-	ts_params->def_comp_xform.compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
-	ts_params->def_comp_xform.compress.chksum = RTE_COMP_NONE;
-	ts_params->def_comp_xform.compress.window_size = DEFAULT_WINDOW_SIZE;
-
-	ts_params->def_decomp_xform.next = NULL;
-	ts_params->def_decomp_xform.type = RTE_COMP_DECOMPRESS;
-	ts_params->def_decomp_xform.decompress.algo = RTE_COMP_DEFLATE,
-	ts_params->def_decomp_xform.decompress.chksum = RTE_COMP_NONE;
-	ts_params->def_decomp_xform.decompress.window_size = DEFAULT_WINDOW_SIZE;
+	ts_params->def_comp_xform->next = NULL;
+	ts_params->def_comp_xform->type = RTE_COMP_COMPRESS;
+	ts_params->def_comp_xform->compress.algo = RTE_COMP_DEFLATE,
+	ts_params->def_comp_xform->compress.deflate.huffman = RTE_COMP_DEFAULT;
+	ts_params->def_comp_xform->compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
+	ts_params->def_comp_xform->compress.chksum = RTE_COMP_NONE;
+	ts_params->def_comp_xform->compress.window_size = DEFAULT_WINDOW_SIZE;
+
+	ts_params->def_decomp_xform->next = NULL;
+	ts_params->def_decomp_xform->type = RTE_COMP_DECOMPRESS;
+	ts_params->def_decomp_xform->decompress.algo = RTE_COMP_DEFLATE,
+	ts_params->def_decomp_xform->decompress.chksum = RTE_COMP_NONE;
+	ts_params->def_decomp_xform->decompress.window_size = DEFAULT_WINDOW_SIZE;
 
 	return TEST_SUCCESS;
 
@@ -359,8 +366,9 @@ static int
 test_deflate_comp_decomp(const char * const test_bufs[],
 		unsigned int num_bufs,
 		uint16_t buf_idx[],
-		const struct rte_comp_xform *compress_xform,
-		const struct rte_comp_xform *decompress_xform,
+		struct rte_comp_xform *compress_xforms[],
+		struct rte_comp_xform *decompress_xforms[],
+		unsigned int num_xforms,
 		enum rte_comp_op_type state,
 		enum zlib_direction zlib_dir)
 {
@@ -370,7 +378,7 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 	struct rte_mbuf *comp_bufs[num_bufs];
 	struct rte_comp_op *ops[num_bufs];
 	struct rte_comp_op *ops_processed[num_bufs];
-	struct rte_comp_session *sess = NULL;
+	struct rte_comp_session *sess[num_xforms];
 	uint16_t num_enqd, num_deqd;
 	struct priv_op_data *priv_data;
 	char *data_ptr;
@@ -381,6 +389,7 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 	memset(comp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
 	memset(ops, 0, sizeof(struct rte_comp_op *) * num_bufs);
 	memset(ops_processed, 0, sizeof(struct rte_comp_op *) * num_bufs);
+	memset(sess, 0, sizeof(struct rte_comp_session *) * num_xforms);
 
 	/* Prepare the source mbufs with the data */
 	ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, uncomp_bufs, num_bufs);
@@ -447,8 +456,9 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 	/* Compress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
 		for (i = 0; i < num_bufs; i++) {
-			ret = compress_zlib(ops[i],
-					&compress_xform->compress,
+			const struct rte_comp_compress_xform *compress_xform =
+				&compress_xforms[i % num_xforms]->compress;
+			ret = compress_zlib(ops[i], compress_xform,
 					DEFAULT_MEM_LEVEL);
 			if (ret < 0)
 				goto err;
@@ -457,19 +467,21 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 		}
 	} else {
 		num_deqd = 0;
-		/* Create compress session */
-		sess = rte_compressdev_session_create(ts_params->sess_pool);
-		ret = rte_compressdev_session_init(0, sess, compress_xform,
-			ts_params->sess_pool);
-		if (ret < 0) {
-			RTE_LOG(ERR, USER1,
-				"Compression session could not be created\n");
-			goto err;
+		/* Create compress sessions */
+		for (i = 0; i < num_xforms; i++) {
+			sess[i] = rte_compressdev_session_create(ts_params->sess_pool);
+			ret = rte_compressdev_session_init(0, sess[i], compress_xforms[i],
+				ts_params->sess_pool);
+			if (ret < 0) {
+				RTE_LOG(ERR, USER1,
+					"Compression session could not be created\n");
+				goto err;
+			}
 		}
 
 		/* Attach session to operation */
 		for (i = 0; i < num_bufs; i++)
-			ops[i]->session = sess;
+			ops[i]->session = sess[i % num_xforms];
 
 		/* Enqueue and dequeue all operations */
 		num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
@@ -485,20 +497,25 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 		} while (num_deqd < num_enqd);
 
 		/* Free compress session */
-		rte_compressdev_session_clear(0, sess);
-		rte_compressdev_session_terminate(sess);
-		sess = NULL;
+		for (i = 0; i < num_xforms; i++) {
+			rte_compressdev_session_clear(0, sess[i]);
+			rte_compressdev_session_terminate(sess[i]);
+			sess[i] = NULL;
+		}
 	}
 
-	enum rte_comp_huffman huffman_type =
-		compress_xform->compress.deflate.huffman;
 	for (i = 0; i < num_bufs; i++) {
 		priv_data = (struct priv_op_data *) (ops_processed[i] + 1);
+		uint16_t xform_idx = priv_data->orig_idx % num_xforms;
+		const struct rte_comp_compress_xform *compress_xform =
+				&compress_xforms[xform_idx]->compress;
+		enum rte_comp_huffman huffman_type =
+			compress_xform->deflate.huffman;
 		RTE_LOG(DEBUG, USER1, "Buffer %u compressed from %u to %u bytes "
-			"(level = %u, huffman = %s)\n",
+			"(level = %d, huffman = %s)\n",
 			buf_idx[priv_data->orig_idx],
 			ops_processed[i]->consumed, ops_processed[i]->produced,
-			compress_xform->compress.level,
+			compress_xform->level,
 			huffman_type_strings[huffman_type]);
 	}
 
@@ -581,8 +598,12 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 	/* Decompress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
 		for (i = 0; i < num_bufs; i++) {
-			ret = decompress_zlib(ops[i],
-					&decompress_xform->decompress);
+			priv_data = (struct priv_op_data *) (ops[i] + 1);
+			uint16_t xform_idx = priv_data->orig_idx % num_xforms;
+			const struct rte_comp_decompress_xform *decompress_xform =
+				&decompress_xforms[xform_idx]->decompress;
+
+			ret = decompress_zlib(ops[i], decompress_xform);
 			if (ret < 0)
 				goto err;
 
@@ -590,19 +611,24 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 		}
 	} else {
 		num_deqd = 0;
-		/* Create compress session */
-		sess = rte_compressdev_session_create(ts_params->sess_pool);
-		ret = rte_compressdev_session_init(0, sess, decompress_xform,
-			ts_params->sess_pool);
-		if (ret < 0) {
-			RTE_LOG(ERR, USER1,
-				"Decompression session could not be created\n");
-			goto err;
+		/* Create decompress session */
+		for (i = 0; i < num_xforms; i++) {
+			sess[i] = rte_compressdev_session_create(ts_params->sess_pool);
+			ret = rte_compressdev_session_init(0, sess[i],
+				decompress_xforms[i], ts_params->sess_pool);
+			if (ret < 0) {
+				RTE_LOG(ERR, USER1,
+					"Decompression session could not be created\n");
+				goto err;
+			}
 		}
 
 		/* Attach session to operation */
-		for (i = 0; i < num_bufs; i++)
-			ops[i]->session = sess;
+		for (i = 0; i < num_bufs; i++) {
+			priv_data = (struct priv_op_data *) (ops[i] + 1);
+			uint16_t sess_idx = priv_data->orig_idx % num_xforms;
+			ops[i]->session = sess[sess_idx];
+		}
 
 		/* Enqueue and dequeue all operations */
 		num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
@@ -618,9 +644,11 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 		} while (num_deqd < num_enqd);
 
 		/* Free compress session */
-		rte_compressdev_session_clear(0, sess);
-		rte_compressdev_session_terminate(sess);
-		sess = NULL;
+		for (i = 0; i < num_xforms; i++) {
+			rte_compressdev_session_clear(0, sess[i]);
+			rte_compressdev_session_terminate(sess[i]);
+			sess[i] = NULL;
+		}
 	}
 
 	for (i = 0; i < num_bufs; i++) {
@@ -679,8 +707,10 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 		rte_comp_op_free(ops[i]);
 		rte_comp_op_free(ops_processed[i]);
 	}
-	rte_compressdev_session_clear(0, sess);
-	rte_compressdev_session_terminate(sess);
+	for (i = 0; i < num_xforms; i++) {
+		rte_compressdev_session_clear(0, sess[i]);
+		rte_compressdev_session_terminate(sess[i]);
+	}
 
 	return -1;
 }
@@ -691,11 +721,13 @@ test_compressdev_deflate_stateless_fixed(void)
 	struct comp_testsuite_params *ts_params = &testsuite_params;
 	const char *test_buffer;
 	uint16_t i;
-	struct rte_comp_xform compress_xform;
+	int ret;
+	struct rte_comp_xform *compress_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
 
-	memcpy(&compress_xform, &ts_params->def_comp_xform,
+	memcpy(compress_xform, ts_params->def_comp_xform,
 			sizeof(struct rte_comp_xform));
-	compress_xform.compress.deflate.huffman = RTE_COMP_FIXED;
+	compress_xform->compress.deflate.huffman = RTE_COMP_FIXED;
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
 		test_buffer = compress_test_bufs[i];
@@ -705,21 +737,31 @@ test_compressdev_deflate_stateless_fixed(void)
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_DECOMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_DECOMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 
 		/* Compress with Zlib, decompress with compressdev */
 		if (test_deflate_comp_decomp(&test_buffer, 1,
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_COMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_COMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 	}
 
-	return TEST_SUCCESS;
+	ret = TEST_SUCCESS;
+
+exit:
+	rte_free(compress_xform);
+	return ret;
 }
 
 static int
@@ -728,11 +770,13 @@ test_compressdev_deflate_stateless_dynamic(void)
 	struct comp_testsuite_params *ts_params = &testsuite_params;
 	const char *test_buffer;
 	uint16_t i;
-	struct rte_comp_xform compress_xform;
+	int ret;
+	struct rte_comp_xform *compress_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
 
-	memcpy(&compress_xform, &ts_params->def_comp_xform,
+	memcpy(compress_xform, ts_params->def_comp_xform,
 			sizeof(struct rte_comp_xform));
-	compress_xform.compress.deflate.huffman = RTE_COMP_DYNAMIC;
+	compress_xform->compress.deflate.huffman = RTE_COMP_DYNAMIC;
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
 		test_buffer = compress_test_bufs[i];
@@ -742,21 +786,31 @@ test_compressdev_deflate_stateless_dynamic(void)
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_DECOMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_DECOMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 
 		/* Compress with Zlib, decompress with compressdev */
 		if (test_deflate_comp_decomp(&test_buffer, 1,
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_COMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_COMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 	}
 
-	return TEST_SUCCESS;
+	ret = TEST_SUCCESS;
+
+exit:
+	rte_free(compress_xform);
+	return ret;
 }
 
 static int
@@ -775,6 +829,7 @@ test_compressdev_deflate_stateless_multi_op(void)
 			buf_idx,
 			&ts_params->def_comp_xform,
 			&ts_params->def_decomp_xform,
+			1,
 			RTE_COMP_OP_STATELESS,
 			ZLIB_DECOMPRESS) < 0)
 		return TEST_FAILED;
@@ -784,6 +839,7 @@ test_compressdev_deflate_stateless_multi_op(void)
 			buf_idx,
 			&ts_params->def_comp_xform,
 			&ts_params->def_decomp_xform,
+			1,
 			RTE_COMP_OP_STATELESS,
 			ZLIB_COMPRESS) < 0)
 		return TEST_FAILED;
@@ -791,7 +847,6 @@ test_compressdev_deflate_stateless_multi_op(void)
 	return TEST_SUCCESS;
 }
 
-
 static int
 test_compressdev_deflate_stateless_multi_level(void)
 {
@@ -799,29 +854,96 @@ test_compressdev_deflate_stateless_multi_level(void)
 	const char *test_buffer;
 	unsigned int level;
 	uint16_t i;
-	struct rte_comp_xform compress_xform;
+	int ret;
+	struct rte_comp_xform *compress_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
 
-	memcpy(&compress_xform, &ts_params->def_comp_xform,
+	memcpy(compress_xform, ts_params->def_comp_xform,
 			sizeof(struct rte_comp_xform));
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
 		test_buffer = compress_test_bufs[i];
 		for (level = RTE_COMP_LEVEL_MIN; level <= RTE_COMP_LEVEL_MAX;
 				level++) {
-			compress_xform.compress.level = level;
+			compress_xform->compress.level = level;
 			/* Compress with compressdev, decompress with Zlib */
 			if (test_deflate_comp_decomp(&test_buffer, 1,
 					&i,
 					&compress_xform,
 					&ts_params->def_decomp_xform,
+					1,
 					RTE_COMP_OP_STATELESS,
-					ZLIB_DECOMPRESS) < 0)
-				return TEST_FAILED;
+					ZLIB_DECOMPRESS) < 0) {
+				ret = TEST_FAILED;
+				goto exit;
+			}
 		}
 	}
 
-	return TEST_SUCCESS;
+	ret = TEST_SUCCESS;
+
+exit:
+	rte_free(compress_xform);
+	return ret;
+}
+
+#define NUM_SESSIONS 3
+static int
+test_compressdev_deflate_stateless_multi_session(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	uint16_t num_bufs = NUM_SESSIONS;
+	struct rte_comp_xform *compress_xforms[NUM_SESSIONS] = {NULL};
+	struct rte_comp_xform *decompress_xforms[NUM_SESSIONS] = {NULL};
+	const char *test_buffers[NUM_SESSIONS];
+	uint16_t i;
+	unsigned int level = RTE_COMP_LEVEL_MIN;
+	uint16_t buf_idx[num_bufs];
+
+	int ret;
+
+	/* Create multiple xforms with various levels */
+	for (i = 0; i < NUM_SESSIONS; i++) {
+		compress_xforms[i] = rte_malloc(NULL,
+				sizeof(struct rte_comp_xform), 0);
+		memcpy(compress_xforms[i], ts_params->def_comp_xform,
+				sizeof(struct rte_comp_xform));
+		compress_xforms[i]->compress.level = level;
+		level++;
+
+		decompress_xforms[i] = rte_malloc(NULL,
+				sizeof(struct rte_comp_xform), 0);
+		memcpy(decompress_xforms[i], ts_params->def_decomp_xform,
+				sizeof(struct rte_comp_xform));
+	}
+
+	for (i = 0; i < NUM_SESSIONS; i++) {
+		buf_idx[i] = 0;
+		/* Use the same buffer in all sessions */
+		test_buffers[i] = compress_test_bufs[0];
+	}
+	/* Compress with compressdev, decompress with Zlib */
+	if (test_deflate_comp_decomp(test_buffers, num_bufs,
+			buf_idx,
+			compress_xforms,
+			decompress_xforms,
+			NUM_SESSIONS,
+			RTE_COMP_OP_STATELESS,
+			ZLIB_DECOMPRESS) < 0) {
+		ret = TEST_FAILED;
+		goto exit;
+	}
+
+	ret = TEST_SUCCESS;
+exit:
+	for (i = 0; i < NUM_SESSIONS; i++) {
+		rte_free(compress_xforms[i]);
+		rte_free(decompress_xforms[i]);
+	}
+
+	return ret;
 }
+
 static struct unit_test_suite compressdev_testsuite  = {
 	.suite_name = "compressdev unit test suite",
 	.setup = testsuite_setup,
@@ -835,6 +957,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 			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_session),
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v2 0/5] Initial compressdev unit tests
  2018-02-28 14:00 [dpdk-dev] [PATCH 0/5] Initial compressdev unit tests Pablo de Lara
                   ` (4 preceding siblings ...)
  2018-02-28 14:00 ` [dpdk-dev] [PATCH 5/5] test/compress: add multi session test Pablo de Lara
@ 2018-04-08 14:00 ` Pablo de Lara
  2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 1/5] test/compress: add initial " Pablo de Lara
                     ` (4 more replies)
  2018-04-27 14:14 ` [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests Pablo de Lara
  2018-05-04 10:22 ` [dpdk-dev] [PATCH v4 " Pablo de Lara
  7 siblings, 5 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-04-08 14:00 UTC (permalink / raw)
  To: dev; +Cc: fiona.trahe, shally.verma, ahmed.mansour, Ashish.Gupta, Pablo de Lara

Added initial tests for Compressdev library.
The tests are performed compressing a test buffer (or multiple test buffers)
with compressdev or Zlib, and decompressing it/them with the other library
(if compression is done with compressdev, decompression is done with Zlib, and viceversa).

Tests added so far are based on the deflate algorithm,
including:
- Fixed huffman on single buffer
- Dynamic huffman on single buffer
- Multi compression level test on single buffer
- Multi buffer
- Multi xform using the same buffer

Due to a dependency on Zlib, the test is not enabled by default.
Once the library is installed, the configuration option CONFIG_RTE_COMPRESSDEV_TEST must be set to Y.
However, if building with Meson, the test will be built automatically,
if Zlib is installed.

The test requires a compressdev PMD to be initialized, when running the test app. For example:

./build/app/test --vdev="compress_X"

RTE>>compressdev_autotest

This patchset depends on the Compressdev API patchset:
http://dpdk.org/ml/archives/dev/2018-April/096028.html
("[PATCH v4 00/13] Implement compression API")

Changes in v2:
- Add meson build
- Add invalid configuration tests
- Use new Compressdev API:
  * Substitute session with priv xform
  * Check if priv xform is shareable and create one per operation if not


Pablo de Lara (5):
  test/compress: add initial unit tests
  test/compress: add multi op test
  test/compress: add multi level test
  test/compress: add multi xform test
  test/compress: add invalid configuration tests

 config/common_base                       |    5 +
 test/test/Makefile                       |    9 +
 test/test/meson.build                    |    8 +
 test/test/test_compressdev.c             | 1094 ++++++++++++++++++++++++++++++
 test/test/test_compressdev_test_buffer.h |  295 ++++++++
 5 files changed, 1411 insertions(+)
 create mode 100644 test/test/test_compressdev.c
 create mode 100644 test/test/test_compressdev_test_buffer.h

-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v2 1/5] test/compress: add initial unit tests
  2018-04-08 14:00 ` [dpdk-dev] [PATCH v2 0/5] Initial compressdev unit tests Pablo de Lara
@ 2018-04-08 14:00   ` Pablo de Lara
  2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 2/5] test/compress: add multi op test Pablo de Lara
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-04-08 14:00 UTC (permalink / raw)
  To: dev
  Cc: fiona.trahe, shally.verma, ahmed.mansour, Ashish.Gupta,
	Pablo de Lara, Ashish Gupta, Shally Verma

This commit introduces the initial tests for compressdev,
performing basic compression and decompression operations
of sample test buffers, using the Zlib library in one direction
and compressdev in another direction, to make sure that
the library is compatible with Zlib.

Due to the use of Zlib API, the test is disabled by default,
to avoid adding a new dependency on DPDK.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Signed-off-by: Ashish Gupta <ashish.gupta@caviumnetworks.com>
Signed-off-by: Shally Verma <shally.verma@caviumnetworks.com>
---
 config/common_base                       |   5 +
 test/test/Makefile                       |   9 +
 test/test/meson.build                    |   8 +
 test/test/test_compressdev.c             | 727 +++++++++++++++++++++++++++++++
 test/test/test_compressdev_test_buffer.h | 295 +++++++++++++
 5 files changed, 1044 insertions(+)
 create mode 100644 test/test/test_compressdev.c
 create mode 100644 test/test/test_compressdev_test_buffer.h

diff --git a/config/common_base b/config/common_base
index f40354487..004b5e5d1 100644
--- a/config/common_base
+++ b/config/common_base
@@ -549,6 +549,11 @@ CONFIG_RTE_LIBRTE_SECURITY=y
 CONFIG_RTE_LIBRTE_COMPRESSDEV=y
 CONFIG_RTE_COMPRESS_MAX_DEVS=64
 
+#
+# Compile compressdev unit test
+#
+CONFIG_RTE_COMPRESSDEV_TEST=n
+
 #
 # Compile generic event device library
 #
diff --git a/test/test/Makefile b/test/test/Makefile
index a88cc38bf..0faa03bad 100644
--- a/test/test/Makefile
+++ b/test/test/Makefile
@@ -181,6 +181,10 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_RING) += test_pmd_ring_perf.c
 SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_blockcipher.c
 SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c
 
+ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y)
+SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c
+endif
+
 ifeq ($(CONFIG_RTE_LIBRTE_EVENTDEV),y)
 SRCS-y += test_eventdev.c
 SRCS-y += test_event_ring.c
@@ -201,6 +205,11 @@ CFLAGS += $(WERROR_FLAGS)
 CFLAGS += -D_GNU_SOURCE
 
 LDLIBS += -lm
+ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y)
+ifeq ($(CONFIG_RTE_LIBRTE_COMPRESSDEV),y)
+LDLIBS += -lz
+endif
+endif
 
 # Disable VTA for memcpy test
 ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
diff --git a/test/test/meson.build b/test/test/meson.build
index eb3d87a4d..69d3fa699 100644
--- a/test/test/meson.build
+++ b/test/test/meson.build
@@ -235,6 +235,14 @@ if dpdk_conf.has('RTE_LIBRTE_KNI')
 endif
 
 test_dep_objs = []
+compress_test_dep = dependency('zlib', required: false)
+if compress_test_dep.found()
+	test_dep_objs += compress_test_dep
+	test_sources += 'test_compressdev.c'
+	test_deps += 'compressdev'
+	test_names += 'compressdev_autotest'
+endif
+
 foreach d:test_deps
 	def_lib = get_option('default_library')
 	test_dep_objs += get_variable(def_lib + '_rte_' + d)
diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
new file mode 100644
index 000000000..02fc6c3fa
--- /dev/null
+++ b/test/test/test_compressdev.c
@@ -0,0 +1,727 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+#include <string.h>
+#include <zlib.h>
+#include <math.h>
+
+#include <rte_cycles.h>
+#include <rte_malloc.h>
+#include <rte_mempool.h>
+#include <rte_mbuf.h>
+#include <rte_compressdev.h>
+
+#include "test_compressdev_test_buffer.h"
+#include "test.h"
+
+#define DEFAULT_WINDOW_SIZE 15
+#define DEFAULT_MEM_LEVEL 8
+#define MAX_DEQD_RETRIES 10
+#define DEQUEUE_WAIT_TIME 10000
+
+/*
+ * 30% extra size for compressed data compared to original data,
+ * in case data size cannot be reduced and it is actually bigger
+ * due to the compress block headers
+ */
+#define COMPRESS_BUF_SIZE_RATIO 1.3
+#define NUM_MBUFS 16
+#define NUM_OPS 16
+#define NUM_MAX_XFORMS 1
+#define NUM_MAX_INFLIGHT_OPS 128
+#define CACHE_SIZE 0
+
+#define DIV_CEIL(a, b)  ((a % b) ? ((a / b) + 1) : (a / b))
+
+const char *
+huffman_type_strings[] = {
+	[RTE_COMP_HUFFMAN_DEFAULT]	= "PMD default",
+	[RTE_COMP_HUFFMAN_FIXED]	= "Fixed",
+	[RTE_COMP_HUFFMAN_DYNAMIC]	= "Dynamic"
+};
+
+enum zlib_direction {
+	ZLIB_NONE,
+	ZLIB_COMPRESS,
+	ZLIB_DECOMPRESS,
+	ZLIB_ALL
+};
+
+struct comp_testsuite_params {
+	struct rte_mempool *mbuf_pool;
+	struct rte_mempool *op_pool;
+	struct rte_comp_xform def_comp_xform;
+	struct rte_comp_xform def_decomp_xform;
+};
+
+static struct comp_testsuite_params testsuite_params = { 0 };
+
+static void
+testsuite_teardown(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+
+	rte_mempool_free(ts_params->mbuf_pool);
+	rte_mempool_free(ts_params->op_pool);
+}
+
+static int
+testsuite_setup(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	unsigned int i;
+
+	if (rte_compressdev_count() == 0) {
+		RTE_LOG(ERR, USER1, "Need at least one compress device\n");
+		return -EINVAL;
+	}
+
+	uint32_t max_buf_size = 0;
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
+		max_buf_size = RTE_MAX(max_buf_size,
+				strlen(compress_test_bufs[i]) + 1);
+
+	max_buf_size *= COMPRESS_BUF_SIZE_RATIO;
+	/*
+	 * Buffers to be used in compression and decompression.
+	 * Since decompressed data might be larger than
+	 * compressed data (due to block header),
+	 * buffers should be big enough for both cases.
+	 */
+	ts_params->mbuf_pool = rte_pktmbuf_pool_create("mbuf_pool",
+			NUM_MBUFS,
+			CACHE_SIZE, 0,
+			max_buf_size + RTE_PKTMBUF_HEADROOM,
+			rte_socket_id());
+	if (ts_params->mbuf_pool == NULL) {
+		RTE_LOG(ERR, USER1, "Large mbuf pool could not be created\n");
+		goto exit;
+	}
+
+	ts_params->op_pool = rte_comp_op_pool_create("op_pool", NUM_OPS,
+						0, 0, rte_socket_id());
+	if (ts_params->op_pool == NULL) {
+		RTE_LOG(ERR, USER1, "Operation pool could not be created\n");
+		goto exit;
+	}
+
+	/* Initializes default values for compress/decompress xforms */
+	ts_params->def_comp_xform.next = NULL;
+	ts_params->def_comp_xform.type = RTE_COMP_COMPRESS;
+	ts_params->def_comp_xform.compress.algo = RTE_COMP_ALGO_DEFLATE,
+	ts_params->def_comp_xform.compress.deflate.huffman =
+						RTE_COMP_HUFFMAN_DEFAULT;
+	ts_params->def_comp_xform.compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
+	ts_params->def_comp_xform.compress.chksum = RTE_COMP_CHECKSUM_NONE;
+	ts_params->def_comp_xform.compress.window_size = DEFAULT_WINDOW_SIZE;
+
+	ts_params->def_decomp_xform.next = NULL;
+	ts_params->def_decomp_xform.type = RTE_COMP_DECOMPRESS;
+	ts_params->def_decomp_xform.decompress.algo = RTE_COMP_ALGO_DEFLATE,
+	ts_params->def_decomp_xform.decompress.chksum = RTE_COMP_CHECKSUM_NONE;
+	ts_params->def_decomp_xform.decompress.window_size = DEFAULT_WINDOW_SIZE;
+
+	return TEST_SUCCESS;
+
+exit:
+	testsuite_teardown();
+
+	return TEST_FAILED;
+}
+
+static int
+generic_ut_setup(void)
+{
+	/* Configure compressdev (one device, one queue pair) */
+	struct rte_compressdev_config config = {
+		.socket_id = rte_socket_id(),
+		.nb_queue_pairs = 1,
+		.max_nb_priv_xforms = NUM_MAX_XFORMS,
+		.max_nb_streams = 0
+	};
+
+	if (rte_compressdev_configure(0, &config) < 0) {
+		RTE_LOG(ERR, USER1, "Device configuration failed\n");
+		return -1;
+	}
+
+	if (rte_compressdev_queue_pair_setup(0, 0, NUM_MAX_INFLIGHT_OPS,
+			rte_socket_id()) < 0) {
+		RTE_LOG(ERR, USER1, "Queue pair setup failed\n");
+		return -1;
+	}
+
+	if (rte_compressdev_start(0) < 0) {
+		RTE_LOG(ERR, USER1, "Device could not be started\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+static void
+generic_ut_teardown(void)
+{
+	rte_compressdev_stop(0);
+}
+
+static int
+compare_buffers(const char *buffer1, uint32_t buffer1_len,
+		const char *buffer2, uint32_t buffer2_len)
+{
+	if (buffer1_len != buffer2_len) {
+		RTE_LOG(ERR, USER1, "Buffer lengths are different\n");
+		return -1;
+	}
+
+	if (memcmp(buffer1, buffer2, buffer1_len) != 0) {
+		RTE_LOG(ERR, USER1, "Buffers are different\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+/*
+ * Maps compressdev and Zlib flush flags
+ */
+static int
+map_zlib_flush_flag(enum rte_comp_flush_flag flag)
+{
+	switch (flag) {
+	case RTE_COMP_FLUSH_NONE:
+		return Z_NO_FLUSH;
+	case RTE_COMP_FLUSH_SYNC:
+		return Z_SYNC_FLUSH;
+	case RTE_COMP_FLUSH_FULL:
+		return Z_FULL_FLUSH;
+	case RTE_COMP_FLUSH_FINAL:
+		return Z_FINISH;
+	/*
+	 * There should be only the values above,
+	 * so this should never happen
+	 */
+	default:
+		return -1;
+	}
+}
+
+static int
+compress_zlib(struct rte_comp_op *op,
+		const struct rte_comp_xform *xform, int mem_level)
+{
+	z_stream stream;
+	int zlib_flush;
+	int strategy, window_bits, comp_level;
+	int ret = -1;
+
+	/* initialize zlib stream */
+	stream.zalloc = Z_NULL;
+	stream.zfree = Z_NULL;
+	stream.opaque = Z_NULL;
+
+	if (xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_FIXED)
+		strategy = Z_FIXED;
+	else
+		strategy = Z_DEFAULT_STRATEGY;
+
+	/*
+	 * Window bits is the base two logarithm of the window size (in bytes).
+	 * When doing raw DEFLATE, this number will be negative.
+	 */
+	window_bits = -(xform->compress.window_size);
+
+	comp_level = xform->compress.level;
+
+	if (comp_level != RTE_COMP_LEVEL_NONE)
+		ret = deflateInit2(&stream, comp_level, Z_DEFLATED,
+			window_bits, mem_level, strategy);
+	else
+		ret = deflateInit(&stream, Z_NO_COMPRESSION);
+
+	if (ret != Z_OK) {
+		printf("Zlib deflate could not be initialized\n");
+		goto exit;
+	}
+
+	/* Assuming stateless operation */
+	stream.avail_in = op->src.length;
+	stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
+	stream.avail_out = op->m_dst->data_len;
+	stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
+
+	/* Stateless operation, all buffer will be compressed in one go */
+	zlib_flush = map_zlib_flush_flag(op->flush_flag);
+	ret = deflate(&stream, zlib_flush);
+
+	if (stream.avail_in != 0) {
+		RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
+		goto exit;
+	}
+
+	//TODO: This is only if flush final is used
+	if (ret != Z_STREAM_END)
+		goto exit;
+
+	op->consumed = op->src.length - stream.avail_in;
+	op->produced = op->m_dst->data_len - stream.avail_out;
+	op->status = RTE_COMP_OP_STATUS_SUCCESS;
+
+	deflateReset(&stream);
+
+	ret = 0;
+exit:
+	deflateEnd(&stream);
+
+	return ret;
+}
+
+static int
+decompress_zlib(struct rte_comp_op *op,
+		const struct rte_comp_xform *xform)
+{
+	z_stream stream;
+	int window_bits;
+	int zlib_flush;
+	int ret = TEST_FAILED;
+
+	/* initialize zlib stream */
+	stream.zalloc = Z_NULL;
+	stream.zfree = Z_NULL;
+	stream.opaque = Z_NULL;
+
+	/*
+	 * Window bits is the base two logarithm of the window size (in bytes).
+	 * When doing raw DEFLATE, this number will be negative.
+	 */
+	window_bits = -(xform->decompress.window_size);
+
+	ret = inflateInit2(&stream, window_bits);
+
+	if (ret != Z_OK) {
+		printf("Zlib deflate could not be initialized\n");
+		goto exit;
+	}
+
+	/* Assuming stateless operation */
+	stream.avail_in = op->src.length;
+	stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
+	stream.avail_out = op->m_dst->data_len;
+	stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
+
+	/* Stateless operation, all buffer will be compressed in one go */
+	zlib_flush = map_zlib_flush_flag(op->flush_flag);
+	ret = inflate(&stream, zlib_flush);
+
+	if (stream.avail_in != 0) {
+		RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
+		goto exit;
+	}
+
+	//TODO: This is only if flush final is used
+	if (ret != Z_STREAM_END)
+		goto exit;
+
+	op->consumed = op->src.length - stream.avail_in;
+	op->produced = op->m_dst->data_len - stream.avail_out;
+	op->status = RTE_COMP_OP_STATUS_SUCCESS;
+
+	inflateReset(&stream);
+
+	ret = 0;
+exit:
+	inflateEnd(&stream);
+
+	return ret;
+}
+
+/*
+ * Compresses and decompresses buffer with compressdev API and Zlib API
+ */
+static int
+test_deflate_comp_decomp(const char *test_buffer,
+		struct rte_comp_xform *compress_xform,
+		struct rte_comp_xform *decompress_xform,
+		enum rte_comp_op_type state,
+		enum zlib_direction zlib_dir)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	int ret_status = -1;
+	int ret;
+	struct rte_mbuf *comp_buf = NULL;
+	struct rte_mbuf *uncomp_buf = NULL;
+	struct rte_comp_op *op = NULL;
+	struct rte_comp_op *op_processed = NULL;
+	void *priv_xform = NULL;
+	uint16_t num_deqd;
+	unsigned int deqd_retries = 0;
+	char *data_ptr;
+
+	/* Prepare the source mbuf with the data */
+	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+	if (uncomp_buf == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Source mbuf could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	data_ptr = rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
+	snprintf(data_ptr, strlen(test_buffer) + 1, "%s", test_buffer);
+
+	/* Prepare the destination mbuf */
+	comp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+	if (comp_buf == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Destination mbuf could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	rte_pktmbuf_append(comp_buf,
+			strlen(test_buffer) * COMPRESS_BUF_SIZE_RATIO);
+
+	/* Build the compression operations */
+	op = rte_comp_op_alloc(ts_params->op_pool);
+	if (op == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Compress operation could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	op->m_src = uncomp_buf;
+	op->m_dst = comp_buf;
+	op->src.offset = 0;
+	op->src.length = rte_pktmbuf_pkt_len(uncomp_buf);
+	op->dst.offset = 0;
+	if (state == RTE_COMP_OP_STATELESS) {
+		//TODO: FULL or FINAL?
+		op->flush_flag = RTE_COMP_FLUSH_FINAL;
+	} else {
+		RTE_LOG(ERR, USER1,
+			"Stateful operations are not supported "
+			"in these tests yet\n");
+		goto exit;
+	}
+	op->input_chksum = 0;
+
+	/* Compress data (either with Zlib API or compressdev API */
+	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
+		ret = compress_zlib(op,
+			(const struct rte_comp_xform *)&compress_xform,
+			DEFAULT_MEM_LEVEL);
+		if (ret < 0)
+			goto exit;
+
+		op_processed = op;
+	} else {
+		/* Create compress xform private data */
+		ret = rte_compressdev_private_xform_create(0,
+			(const struct rte_comp_xform *)compress_xform,
+			&priv_xform);
+		if (ret < 0) {
+			RTE_LOG(ERR, USER1,
+				"Compression private xform "
+				"could not be created\n");
+			goto exit;
+		}
+
+		/* Attach xform private data to operation */
+		op->private_xform = priv_xform;
+
+		/* Enqueue and dequeue all operations */
+		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
+		if (ret == 0) {
+			RTE_LOG(ERR, USER1,
+				"The operation could not be enqueued\n");
+			goto exit;
+		}
+		do {
+			/*
+			 * If retrying a dequeue call, wait for 10 ms to allow
+			 * enough time to the driver to process the operations
+			 */
+			if (deqd_retries != 0) {
+				/*
+				 * Avoid infinite loop if not all the
+				 * operations get out of the device
+				 */
+				if (deqd_retries == MAX_DEQD_RETRIES) {
+					RTE_LOG(ERR, USER1,
+						"Not all operations could be "
+						"dequeued\n");
+					goto exit;
+				}
+				usleep(DEQUEUE_WAIT_TIME);
+			}
+			num_deqd = rte_compressdev_dequeue_burst(0, 0,
+					&op_processed, 1);
+
+			deqd_retries++;
+		} while (num_deqd < 1);
+
+		deqd_retries = 0;
+
+		/* Free compress private xform */
+		rte_compressdev_private_xform_free(0, priv_xform);
+		priv_xform = NULL;
+	}
+
+	enum rte_comp_huffman huffman_type =
+		compress_xform->compress.deflate.huffman;
+	RTE_LOG(DEBUG, USER1, "Buffer compressed from %u to %u bytes "
+			"(level = %u, huffman = %s)\n",
+			op_processed->consumed, op_processed->produced,
+			compress_xform->compress.level,
+			huffman_type_strings[huffman_type]);
+	RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
+			(float)op_processed->produced /
+			op_processed->consumed * 100);
+	op = NULL;
+
+	/*
+	 * Check operation status and free source mbuf (destination mbuf and
+	 * compress operation information is needed for the decompression stage)
+	 */
+	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
+		RTE_LOG(ERR, USER1,
+			"Some operations were not successful\n");
+		goto exit;
+	}
+	rte_pktmbuf_free(uncomp_buf);
+	uncomp_buf = NULL;
+
+	/* Allocate buffer for decompressed data */
+	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+	if (uncomp_buf == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Destination mbuf could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
+
+	/* Build the decompression operations */
+	op = rte_comp_op_alloc(ts_params->op_pool);
+	if (op == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Decompress operation could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	/* Source buffer is the compressed data from the previous operation */
+	op->m_src = op_processed->m_dst;
+	op->m_dst = uncomp_buf;
+	op->src.offset = 0;
+	/*
+	 * Set the length of the compressed data to the
+	 * number of bytes that were produced in the previous stage
+	 */
+	op->src.length = op_processed->produced;
+	op->dst.offset = 0;
+	if (state == RTE_COMP_OP_STATELESS) {
+		//TODO: FULL or FINAL?
+		op->flush_flag = RTE_COMP_FLUSH_FINAL;
+	} else {
+		RTE_LOG(ERR, USER1,
+			"Stateful operations are not supported "
+			"in these tests yet\n");
+		goto exit;
+	}
+	op->input_chksum = 0;
+
+	/*
+	 * Free the previous compress operation,
+	 * as it is not needed anymore
+	 */
+	rte_comp_op_free(op_processed);
+	op_processed = NULL;
+
+	/* Decompress data (either with Zlib API or compressdev API */
+	if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
+		ret = decompress_zlib(op,
+			(const struct rte_comp_xform *)&decompress_xform);
+		if (ret < 0)
+			goto exit;
+
+		op_processed = op;
+	} else {
+		num_deqd = 0;
+		/* Create decompress xform private data */
+		ret = rte_compressdev_private_xform_create(0,
+			(const struct rte_comp_xform *)decompress_xform,
+			&priv_xform);
+		if (ret < 0) {
+			RTE_LOG(ERR, USER1,
+				"Decompression private xform "
+				"could not be created\n");
+			goto exit;
+		}
+
+		/* Attach xform private data to operation */
+		op->private_xform = priv_xform;
+
+		/* Enqueue and dequeue all operations */
+		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
+		if (ret == 0) {
+			RTE_LOG(ERR, USER1,
+				"The operation could not be enqueued\n");
+			goto exit;
+		}
+		do {
+			/*
+			 * If retrying a dequeue call, wait for 10 ms to allow
+			 * enough time to the driver to process the operations
+			 */
+			if (deqd_retries != 0) {
+				/*
+				 * Avoid infinite loop if not all the
+				 * operations get out of the device
+				 */
+				if (deqd_retries == MAX_DEQD_RETRIES) {
+					RTE_LOG(ERR, USER1,
+						"Not all operations could be "
+						"dequeued\n");
+					goto exit;
+				}
+				usleep(DEQUEUE_WAIT_TIME);
+			}
+			num_deqd = rte_compressdev_dequeue_burst(0, 0,
+					&op_processed, 1);
+
+			deqd_retries++;
+		} while (num_deqd < 1);
+	}
+
+	RTE_LOG(DEBUG, USER1, "Buffer decompressed from %u to %u bytes\n",
+			op_processed->consumed, op_processed->produced);
+	op = NULL;
+	/*
+	 * Check operation status and free source mbuf (destination mbuf and
+	 * compress operation information is still needed)
+	 */
+	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
+		RTE_LOG(ERR, USER1,
+			"Some operations were not successful\n");
+		goto exit;
+	}
+	rte_pktmbuf_free(comp_buf);
+	comp_buf = NULL;
+
+	/*
+	 * Compare the original stream with the decompressed stream
+	 * (in size and the data)
+	 */
+	if (compare_buffers(test_buffer, strlen(test_buffer) + 1,
+			rte_pktmbuf_mtod(op_processed->m_dst, const char *),
+			op_processed->produced) < 0)
+		goto exit;
+
+	ret_status = 0;
+
+exit:
+	/* Free resources */
+	rte_pktmbuf_free(uncomp_buf);
+	rte_pktmbuf_free(comp_buf);
+	rte_comp_op_free(op);
+	rte_comp_op_free(op_processed);
+
+	if (priv_xform != NULL)
+		rte_compressdev_private_xform_free(0, priv_xform);
+
+	return ret_status;
+}
+
+static int
+test_compressdev_deflate_stateless_fixed(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	const char *test_buffer;
+	uint16_t i;
+	struct rte_comp_xform compress_xform;
+
+	memcpy(&compress_xform, &ts_params->def_comp_xform,
+			sizeof(struct rte_comp_xform));
+	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
+
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+		test_buffer = compress_test_bufs[i];
+
+		/* Compress with compressdev, decompress with Zlib */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_DECOMPRESS) < 0)
+			return TEST_FAILED;
+
+		/* Compress with Zlib, decompress with compressdev */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_COMPRESS) < 0)
+			return TEST_FAILED;
+	}
+
+	return TEST_SUCCESS;
+}
+
+static int
+test_compressdev_deflate_stateless_dynamic(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	const char *test_buffer;
+	uint16_t i;
+	struct rte_comp_xform compress_xform;
+
+	memcpy(&compress_xform, &ts_params->def_comp_xform,
+			sizeof(struct rte_comp_xform));
+	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
+
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+		test_buffer = compress_test_bufs[i];
+
+		/* Compress with compressdev, decompress with Zlib */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_DECOMPRESS) < 0)
+			return TEST_FAILED;
+
+		/* Compress with Zlib, decompress with compressdev */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_COMPRESS) < 0)
+			return TEST_FAILED;
+	}
+
+	return TEST_SUCCESS;
+}
+
+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(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_CASES_END() /**< NULL terminate unit test array */
+	}
+};
+
+static int
+test_compressdev(void)
+{
+	return unit_test_suite_runner(&compressdev_testsuite);
+}
+
+REGISTER_TEST_COMMAND(compressdev_autotest, test_compressdev);
diff --git a/test/test/test_compressdev_test_buffer.h b/test/test/test_compressdev_test_buffer.h
new file mode 100644
index 000000000..c0492f89a
--- /dev/null
+++ b/test/test/test_compressdev_test_buffer.h
@@ -0,0 +1,295 @@
+#ifndef TEST_COMPRESSDEV_TEST_BUFFERS_H_
+#define TEST_COMPRESSDEV_TEST_BUFFERS_H_
+
+/*
+ * These test buffers are snippets obtained
+ * from the Canterbury and Calgary Corpus
+ * collection.
+ */
+
+/* Snippet of Alice's Adventures in Wonderland */
+static const char test_buf_alice[] =
+	"  Alice was beginning to get very tired of sitting by her sister\n"
+	"on the bank, and of having nothing to do:  once or twice she had\n"
+	"peeped into the book her sister was reading, but it had no\n"
+	"pictures or conversations in it, `and what is the use of a book,'\n"
+	"thought Alice `without pictures or conversation?'\n\n"
+	"  So she was considering in her own mind (as well as she could,\n"
+	"for the hot day made her feel very sleepy and stupid), whether\n"
+	"the pleasure of making a daisy-chain would be worth the trouble\n"
+	"of getting up and picking the daisies, when suddenly a White\n"
+	"Rabbit with pink eyes ran close by her.\n\n"
+	"  There was nothing so VERY remarkable in that; nor did Alice\n"
+	"think it so VERY much out of the way to hear the Rabbit say to\n"
+	"itself, `Oh dear!  Oh dear!  I shall be late!'  (when she thought\n"
+	"it over afterwards, it occurred to her that she ought to have\n"
+	"wondered at this, but at the time it all seemed quite natural);\n"
+	"but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT-\n"
+	"POCKET, and looked at it, and then hurried on, Alice started to\n"
+	"her feet, for it flashed across her mind that she had never\n"
+	"before seen a rabbit with either a waistcoat-pocket, or a watch to\n"
+	"take out of it, and burning with curiosity, she ran across the\n"
+	"field after it, and fortunately was just in time to see it pop\n"
+	"down a large rabbit-hole under the hedge.\n\n"
+	"  In another moment down went Alice after it, never once\n"
+	"considering how in the world she was to get out again.\n\n"
+	"  The rabbit-hole went straight on like a tunnel for some way,\n"
+	"and then dipped suddenly down, so suddenly that Alice had not a\n"
+	"moment to think about stopping herself before she found herself\n"
+	"falling down a very deep well.\n\n"
+	"  Either the well was very deep, or she fell very slowly, for she\n"
+	"had plenty of time as she went down to look about her and to\n"
+	"wonder what was going to happen next.  First, she tried to look\n"
+	"down and make out what she was coming to, but it was too dark to\n"
+	"see anything; then she looked at the sides of the well, and\n"
+	"noticed that they were filled with cupboards and book-shelves;\n"
+	"here and there she saw maps and pictures hung upon pegs.  She\n"
+	"took down a jar from one of the shelves as she passed; it was\n"
+	"labelled `ORANGE MARMALADE', but to her great disappointment it\n"
+	"was empty:  she did not like to drop the jar for fear of killing\n"
+	"somebody, so managed to put it into one of the cupboards as she\n"
+	"fell past it.\n\n"
+	"  `Well!' thought Alice to herself, `after such a fall as this, I\n"
+	"shall think nothing of tumbling down stairs!  How brave they'll\n"
+	"all think me at home!  Why, I wouldn't say anything about it,\n"
+	"even if I fell off the top of the house!' (Which was very likely\n"
+	"true.)\n\n"
+	"  Down, down, down.  Would the fall NEVER come to an end!  `I\n"
+	"wonder how many miles I've fallen by this time?' she said aloud.\n"
+	"`I must be getting somewhere near the centre of the earth.  Let\n"
+	"me see:  that would be four thousand miles down, I think--' (for,\n"
+	"you see, Alice had learnt several things of this sort in her\n"
+	"lessons in the schoolroom, and though this was not a VERY good\n"
+	"opportunity for showing off her knowledge, as there was no one to\n"
+	"listen to her, still it was good practice to say it over) `--yes,\n"
+	"that's about the right distance--but then I wonder what Latitude\n"
+	"or Longitude I've got to?'  (Alice had no idea what Latitude was,\n"
+	"or Longitude either, but thought they were nice grand words to\n"
+	"say.)\n\n"
+	"  Presently she began again.  `I wonder if I shall fall right\n"
+	"THROUGH the earth!  How funny it'll seem to come out among the\n"
+	"people that walk with their heads downward!  The Antipathies, I\n"
+	"think--' (she was rather glad there WAS no one listening, this\n"
+	"time, as it didn't sound at all the right word) `--but I shall\n"
+	"have to ask them what the name of the country is, you know.\n"
+	"Please, Ma'am, is this New Zealand or Australia?' (and she tried\n"
+	"to curtsey as she spoke--fancy CURTSEYING as you're falling\n"
+	"through the air!  Do you think you could manage it?)  `And what\n"
+	"an ignorant little girl she'll think me for asking!  No, it'll\n"
+	"never do to ask:  perhaps I shall see it written up somewhere.'\n"
+	"  Down, down, down.  There was nothing else to do, so Alice soon\n"
+	"began talking again.  `Dinah'll miss me very much to-night, I\n"
+	"should think!'  (Dinah was the cat.)  `I hope they'll remember\n"
+	"her saucer of milk at tea-time.  Dinah my dear!  I wish you were\n"
+	"down here with me!  There are no mice in the air, I'm afraid, but\n"
+	"you might catch a bat, and that's very like a mouse, you know.\n"
+	"But do cats eat bats, I wonder?'  And here Alice began to get\n"
+	"rather sleepy, and went on saying to herself, in a dreamy sort of\n"
+	"way, `Do cats eat bats?  Do cats eat bats?' and sometimes, `Do\n"
+	"bats eat cats?' for, you see, as she couldn't answer either\n"
+	"question, it didn't much matter which way she put it.  She felt\n"
+	"that she was dozing off, and had just begun to dream that she\n"
+	"was walking hand in hand with Dinah, and saying to her very\n"
+	"earnestly, `Now, Dinah, tell me the truth:  did you ever eat a\n"
+	"bat?' when suddenly, thump! thump! down she came upon a heap of\n"
+	"sticks and dry leaves, and the fall was over.\n\n";
+
+/* Snippet of Shakespeare play */
+static const char test_buf_shakespeare[] =
+	"CHARLES	wrestler to Frederick.\n"
+	"\n"
+	"\n"
+	"OLIVER		|\n"
+	"		|\n"
+	"JAQUES (JAQUES DE BOYS:)  	|  sons of Sir Rowland de Boys.\n"
+	"		|\n"
+	"ORLANDO		|\n"
+	"\n"
+	"\n"
+	"ADAM	|\n"
+	"	|  servants to Oliver.\n"
+	"DENNIS	|\n"
+	"\n"
+	"\n"
+	"TOUCHSTONE	a clown.\n"
+	"\n"
+	"SIR OLIVER MARTEXT	a vicar.\n"
+	"\n"
+	"\n"
+	"CORIN	|\n"
+	"	|  shepherds.\n"
+	"SILVIUS	|\n"
+	"\n"
+	"\n"
+	"WILLIAM	a country fellow in love with Audrey.\n"
+	"\n"
+	"	A person representing HYMEN. (HYMEN:)\n"
+	"\n"
+	"ROSALIND	daughter to the banished duke.\n"
+	"\n"
+	"CELIA	daughter to Frederick.\n"
+	"\n"
+	"PHEBE	a shepherdess.\n"
+	"\n"
+	"AUDREY	a country wench.\n"
+	"\n"
+	"	Lords, pages, and attendants, &c.\n"
+	"	(Forester:)\n"
+	"	(A Lord:)\n"
+	"	(First Lord:)\n"
+	"	(Second Lord:)\n"
+	"	(First Page:)\n"
+	"	(Second Page:)\n"
+	"\n"
+	"\n"
+	"SCENE	Oliver's house; Duke Frederick's court; and the\n"
+	"	Forest of Arden.\n"
+	"\n"
+	"\n"
+	"\n"
+	"\n"
+	"	AS YOU LIKE IT\n"
+	"\n"
+	"\n"
+	"ACT I\n"
+	"\n"
+	"\n"
+	"\n"
+	"SCENE I	Orchard of Oliver's house.\n"
+	"\n"
+	"\n"
+	"	[Enter ORLANDO and ADAM]\n"
+	"\n"
+	"ORLANDO	As I remember, Adam, it was upon this fashion\n"
+	"	bequeathed me by will but poor a thousand crowns,\n"
+	"	and, as thou sayest, charged my brother, on his\n"
+	"	blessing, to breed me well: and there begins my\n"
+	"	sadness. My brother Jaques he keeps at school, and\n"
+	"	report speaks goldenly of his profit: for my part,\n"
+	"	he keeps me rustically at home, or, to speak more\n"
+	"	properly, stays me here at home unkept; for call you\n"
+	"	that keeping for a gentleman of my birth, that\n"
+	"	differs not from the stalling of an ox? His horses\n"
+	"	are bred better; for, besides that they are fair\n"
+	"	with their feeding, they are taught their manage,\n"
+	"	and to that end riders dearly hired: but I, his\n"
+	"	brother, gain nothing under him but growth; for the\n"
+	"	which his animals on his dunghills are as much\n"
+	"	bound to him as I. Besides this nothing that he so\n"
+	"	plentifully gives me, the something that nature gave\n"
+	"	me his countenance seems to take from me: he lets\n"
+	"	me feed with his hinds, bars me the place of a\n"
+	"	brother, and, as much as in him lies, mines my\n"
+	"	gentility with my education. This is it, Adam, that\n"
+	"	grieves me; and the spirit of my father, which I\n"
+	"	think is within me, begins to mutiny against this\n"
+	"	servitude: I will no longer endure it, though yet I\n"
+	"	know no wise remedy how to avoid it.\n"
+	"\n"
+	"ADAM	Yonder comes my master, your brother.\n"
+	"\n"
+	"ORLANDO	Go apart, Adam, and thou shalt hear how he will\n";
+
+/* Snippet of source code in Pascal */
+static const char test_buf_pascal[] =
+	"	Ptr    = 1..DMem;\n"
+	"	Loc    = 1..IMem;\n"
+	"	Loc0   = 0..IMem;\n"
+	"	EdgeT  = (hout,lin,hin,lout); {Warning this order is important in}\n"
+	"				      {predicates such as gtS,geS}\n"
+	"	CardT  = (finite,infinite);\n"
+	"	ExpT   = Minexp..Maxexp;\n"
+	"	ManT   = Mininf..Maxinf; \n"
+	"	Pflag  = (PNull,PSoln,PTrace,PPrint);\n"
+	"	Sreal  = record\n"
+	"		    edge:EdgeT;\n"
+	"		    cardinality:CardT;\n"
+	"		    exp:ExpT; {exponent}\n"
+	"		    mantissa:ManT;\n"
+	"		 end;\n"
+	"	Int    = record\n"
+	"		    hi:Sreal;\n"
+	"		    lo:Sreal;\n"
+	"	 end;\n"
+	"	Instr  = record\n"
+	"		    Code:OpType;\n"
+	"		    Pars: array[0..Par] of 0..DMem;\n"
+	"		 end;\n"
+	"	DataMem= record\n"
+	"		    D        :array [Ptr] of Int;\n"
+	"		    S        :array [Loc] of State;\n"
+	"		    LastHalve:Loc;\n"
+	"		    RHalve   :array [Loc] of real;\n"
+	"		 end;\n"
+	"	DataFlags=record\n"
+	"		    PF	     :array [Ptr] of Pflag;\n"
+	"		 end;\n"
+	"var\n"
+	"	Debug  : (none,activity,post,trace,dump);\n"
+	"	Cut    : (once,all);\n"
+	"	GlobalEnd,Verifiable:boolean;\n"
+	"	HalveThreshold:real;\n"
+	"	I      : array [Loc] of Instr; {Memory holding instructions}\n"
+	"	End    : Loc; {last instruction in I}\n"
+	"	ParN   : array [OpType] of -1..Par; {number of parameters for each \n"
+	"			opcode. -1 means no result}\n"
+	"        ParIntersect : array [OpType] of boolean ;\n"
+	"	DInit  : DataMem; {initial memory which is cleared and \n"
+	"				used in first call}\n"
+	"	DF     : DataFlags; {hold flags for variables, e.g. print/trace}\n"
+	"	MaxDMem:0..DMem;\n"
+	"	Shift  : array[0..Digits] of 1..maxint;{array of constant multipliers}\n"
+	"						{used for alignment etc.}\n"
+	"	Dummy  :Positive;\n"
+	"	{constant intervals and Sreals}\n"
+	"	PlusInfS,MinusInfS,PlusSmallS,MinusSmallS,ZeroS,\n"
+	"	PlusFiniteS,MinusFiniteS:Sreal;\n"
+	"	Zero,All,AllFinite:Int;\n"
+	"\n"
+	"procedure deblank;\n"
+	"var Ch:char;\n"
+	"begin\n"
+	"   while (not eof) and (input^ in [' ','	']) do read(Ch);\n"
+	"end;\n"
+	"\n"
+	"procedure InitialOptions;\n"
+	"\n"
+	"#include '/user/profs/cleary/bin/options.i';\n"
+	"\n"
+	"   procedure Option;\n"
+	"   begin\n"
+	"      case Opt of\n"
+	"      'a','A':Debug:=activity;\n"
+	"      'd','D':Debug:=dump;\n"
+	"      'h','H':HalveThreshold:=StringNum/100;\n"
+	"      'n','N':Debug:=none;\n"
+	"      'p','P':Debug:=post;\n"
+	"      't','T':Debug:=trace;\n"
+	"      'v','V':Verifiable:=true;\n"
+	"      end;\n"
+	"   end;\n"
+	"\n"
+	"begin\n"
+	"   Debug:=trace;\n"
+	"   Verifiable:=false;\n"
+	"   HalveThreshold:=67/100;\n"
+	"   Options;\n"
+	"   writeln(Debug);\n"
+	"   writeln('Verifiable:',Verifiable);\n"
+	"   writeln('Halve threshold',HalveThreshold);\n"
+	"end;{InitialOptions}\n"
+	"\n"
+	"procedure NormalizeUp(E,M:integer;var S:Sreal;var Closed:boolean);\n"
+	"begin\n"
+	"with S do\n"
+	"begin\n"
+	"   if M=0 then S:=ZeroS else\n"
+	"   if M>0 then\n";
+
+static const char * const compress_test_bufs[] = {
+	test_buf_alice,
+	test_buf_shakespeare,
+	test_buf_pascal
+};
+
+#endif /* TEST_COMPRESSDEV_TEST_BUFFERS_H_ */
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v2 2/5] test/compress: add multi op test
  2018-04-08 14:00 ` [dpdk-dev] [PATCH v2 0/5] Initial compressdev unit tests Pablo de Lara
  2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 1/5] test/compress: add initial " Pablo de Lara
@ 2018-04-08 14:00   ` Pablo de Lara
  2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 3/5] test/compress: add multi level test Pablo de Lara
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-04-08 14:00 UTC (permalink / raw)
  To: dev; +Cc: fiona.trahe, shally.verma, ahmed.mansour, Ashish.Gupta, Pablo de Lara

Add test that checks if multiple operations with
different buffers can be handled on a single enqueue call.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 test/test/test_compressdev.c | 476 +++++++++++++++++++++++++++++--------------
 1 file changed, 319 insertions(+), 157 deletions(-)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index 02fc6c3fa..a264c4da4 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -47,6 +47,10 @@ enum zlib_direction {
 	ZLIB_ALL
 };
 
+struct priv_op_data {
+	uint16_t orig_idx;
+};
+
 struct comp_testsuite_params {
 	struct rte_mempool *mbuf_pool;
 	struct rte_mempool *op_pool;
@@ -99,7 +103,8 @@ testsuite_setup(void)
 	}
 
 	ts_params->op_pool = rte_comp_op_pool_create("op_pool", NUM_OPS,
-						0, 0, rte_socket_id());
+				0, sizeof(struct priv_op_data),
+				rte_socket_id());
 	if (ts_params->op_pool == NULL) {
 		RTE_LOG(ERR, USER1, "Operation pool could not be created\n");
 		goto exit;
@@ -339,7 +344,9 @@ decompress_zlib(struct rte_comp_op *op,
  * Compresses and decompresses buffer with compressdev API and Zlib API
  */
 static int
-test_deflate_comp_decomp(const char *test_buffer,
+test_deflate_comp_decomp(const char * const test_bufs[],
+		unsigned int num_bufs,
+		uint16_t buf_idx[],
 		struct rte_comp_xform *compress_xform,
 		struct rte_comp_xform *decompress_xform,
 		enum rte_comp_op_type state,
@@ -348,95 +355,146 @@ test_deflate_comp_decomp(const char *test_buffer,
 	struct comp_testsuite_params *ts_params = &testsuite_params;
 	int ret_status = -1;
 	int ret;
-	struct rte_mbuf *comp_buf = NULL;
-	struct rte_mbuf *uncomp_buf = NULL;
-	struct rte_comp_op *op = NULL;
-	struct rte_comp_op *op_processed = NULL;
-	void *priv_xform = NULL;
-	uint16_t num_deqd;
+	struct rte_mbuf *uncomp_bufs[num_bufs];
+	struct rte_mbuf *comp_bufs[num_bufs];
+	struct rte_comp_op *ops[num_bufs];
+	struct rte_comp_op *ops_processed[num_bufs];
+	void *priv_xforms[num_bufs];
+	uint16_t num_enqd, num_deqd, num_total_deqd;
+	uint16_t num_priv_xforms = 0;
 	unsigned int deqd_retries = 0;
+	struct priv_op_data *priv_data;
 	char *data_ptr;
-
-	/* Prepare the source mbuf with the data */
-	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
-	if (uncomp_buf == NULL) {
+	unsigned int i;
+	const struct rte_compressdev_capabilities *capa =
+		rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+
+	/* Initialize all arrays to NULL */
+	memset(uncomp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
+	memset(comp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
+	memset(ops, 0, sizeof(struct rte_comp_op *) * num_bufs);
+	memset(ops_processed, 0, sizeof(struct rte_comp_op *) * num_bufs);
+	memset(priv_xforms, 0, sizeof(void *) * num_bufs);
+
+	/* Prepare the source mbufs with the data */
+	ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, uncomp_bufs, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Source mbuf could not be allocated "
+			"Source mbufs could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	data_ptr = rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
-	snprintf(data_ptr, strlen(test_buffer) + 1, "%s", test_buffer);
+	for (i = 0; i < num_bufs; i++) {
+		data_ptr = rte_pktmbuf_append(uncomp_bufs[i],
+					strlen(test_bufs[i]) + 1);
+		snprintf(data_ptr, strlen(test_bufs[i]) + 1, "%s",
+					test_bufs[i]);
+	}
 
-	/* Prepare the destination mbuf */
-	comp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
-	if (comp_buf == NULL) {
+	/* Prepare the destination mbufs */
+	ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, comp_bufs, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Destination mbuf could not be allocated "
+			"Destination mbufs could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	rte_pktmbuf_append(comp_buf,
-			strlen(test_buffer) * COMPRESS_BUF_SIZE_RATIO);
+	for (i = 0; i < num_bufs; i++)
+		rte_pktmbuf_append(comp_bufs[i],
+			strlen(test_bufs[i]) * COMPRESS_BUF_SIZE_RATIO);
 
 	/* Build the compression operations */
-	op = rte_comp_op_alloc(ts_params->op_pool);
-	if (op == NULL) {
+	ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Compress operation could not be allocated "
+			"Compress operations could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	op->m_src = uncomp_buf;
-	op->m_dst = comp_buf;
-	op->src.offset = 0;
-	op->src.length = rte_pktmbuf_pkt_len(uncomp_buf);
-	op->dst.offset = 0;
-	if (state == RTE_COMP_OP_STATELESS) {
-		//TODO: FULL or FINAL?
-		op->flush_flag = RTE_COMP_FLUSH_FINAL;
-	} else {
-		RTE_LOG(ERR, USER1,
-			"Stateful operations are not supported "
-			"in these tests yet\n");
-		goto exit;
+	for (i = 0; i < num_bufs; i++) {
+		ops[i]->m_src = uncomp_bufs[i];
+		ops[i]->m_dst = comp_bufs[i];
+		ops[i]->src.offset = 0;
+		ops[i]->src.length = rte_pktmbuf_pkt_len(uncomp_bufs[i]);
+		ops[i]->dst.offset = 0;
+		if (state == RTE_COMP_OP_STATELESS) {
+			//TODO: FULL or FINAL?
+			ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
+		} else {
+			RTE_LOG(ERR, USER1,
+				"Stateful operations are not supported "
+				"in these tests yet\n");
+			goto exit;
+		}
+		ops[i]->input_chksum = 0;
+		/*
+		 * Store original operation index in private data,
+		 * since ordering does not have to be maintained,
+		 * when dequeueing from compressdev, so a comparison
+		 * at the end of the test can be done.
+		 */
+		priv_data = (struct priv_op_data *) (ops[i] + 1);
+		priv_data->orig_idx = i;
 	}
-	op->input_chksum = 0;
 
 	/* Compress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
-		ret = compress_zlib(op,
-			(const struct rte_comp_xform *)&compress_xform,
-			DEFAULT_MEM_LEVEL);
-		if (ret < 0)
-			goto exit;
-
-		op_processed = op;
-	} else {
-		/* Create compress xform private data */
-		ret = rte_compressdev_private_xform_create(0,
-			(const struct rte_comp_xform *)compress_xform,
-			&priv_xform);
-		if (ret < 0) {
-			RTE_LOG(ERR, USER1,
-				"Compression private xform "
-				"could not be created\n");
-			goto exit;
+		for (i = 0; i < num_bufs; i++) {
+			ret = compress_zlib(ops[i],
+				(const struct rte_comp_xform *)compress_xform,
+					DEFAULT_MEM_LEVEL);
+			if (ret < 0)
+				goto exit;
+
+			ops_processed[i] = ops[i];
 		}
+	} else {
+		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
+			/* Create single compress private xform data */
+			ret = rte_compressdev_private_xform_create(0,
+				(const struct rte_comp_xform *)compress_xform,
+				&priv_xforms[0]);
+			if (ret < 0) {
+				RTE_LOG(ERR, USER1,
+					"Compression private xform "
+					"could not be created\n");
+				goto exit;
+			}
+			num_priv_xforms++;
+			/* Attach shareable private xform data to ops */
+			for (i = 0; i < num_bufs; i++)
+				ops[i]->private_xform = priv_xforms[0];
+		} else {
+			/* Create compress private xform data per op */
+			for (i = 0; i < num_bufs; i++) {
+				ret = rte_compressdev_private_xform_create(0,
+					compress_xform, &priv_xforms[i]);
+				if (ret < 0) {
+					RTE_LOG(ERR, USER1,
+						"Compression private xform "
+						"could not be created\n");
+					goto exit;
+				}
+				num_priv_xforms++;
+			}
 
-		/* Attach xform private data to operation */
-		op->private_xform = priv_xform;
+			/* Attach non shareable private xform data to ops */
+			for (i = 0; i < num_bufs; i++)
+				ops[i]->private_xform = priv_xforms[i];
+		}
 
 		/* Enqueue and dequeue all operations */
-		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
-		if (ret == 0) {
+		num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
+		if (num_enqd < num_bufs) {
 			RTE_LOG(ERR, USER1,
-				"The operation could not be enqueued\n");
+				"The operations could not be enqueued\n");
 			goto exit;
 		}
+
+		num_total_deqd = 0;
 		do {
 			/*
 			 * If retrying a dequeue call, wait for 10 ms to allow
@@ -456,121 +514,168 @@ test_deflate_comp_decomp(const char *test_buffer,
 				usleep(DEQUEUE_WAIT_TIME);
 			}
 			num_deqd = rte_compressdev_dequeue_burst(0, 0,
-					&op_processed, 1);
-
+					&ops_processed[num_total_deqd], num_bufs);
+			num_total_deqd += num_deqd;
 			deqd_retries++;
-		} while (num_deqd < 1);
+		} while (num_total_deqd < num_enqd);
 
 		deqd_retries = 0;
 
-		/* Free compress private xform */
-		rte_compressdev_private_xform_free(0, priv_xform);
-		priv_xform = NULL;
+		/* Free compress private xforms */
+		for (i = 0; i < num_priv_xforms; i++) {
+			rte_compressdev_private_xform_free(0, priv_xforms[i]);
+			priv_xforms[i] = NULL;
+		}
+		num_priv_xforms = 0;
 	}
 
 	enum rte_comp_huffman huffman_type =
 		compress_xform->compress.deflate.huffman;
-	RTE_LOG(DEBUG, USER1, "Buffer compressed from %u to %u bytes "
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		RTE_LOG(DEBUG, USER1, "Buffer %u compressed from %u to %u bytes "
 			"(level = %u, huffman = %s)\n",
-			op_processed->consumed, op_processed->produced,
+			buf_idx[priv_data->orig_idx],
+			ops_processed[i]->consumed, ops_processed[i]->produced,
 			compress_xform->compress.level,
 			huffman_type_strings[huffman_type]);
-	RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
-			(float)op_processed->produced /
-			op_processed->consumed * 100);
-	op = NULL;
+		RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
+			(float)ops_processed[i]->produced /
+			ops_processed[i]->consumed * 100);
+		ops[i] = NULL;
+	}
 
 	/*
-	 * Check operation status and free source mbuf (destination mbuf and
+	 * Check operation status and free source mbufs (destination mbuf and
 	 * compress operation information is needed for the decompression stage)
 	 */
-	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
-		RTE_LOG(ERR, USER1,
-			"Some operations were not successful\n");
-		goto exit;
+	for (i = 0; i < num_bufs; i++) {
+		if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
+			RTE_LOG(ERR, USER1,
+				"Some operations were not successful\n");
+			goto exit;
+		}
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		rte_pktmbuf_free(uncomp_bufs[priv_data->orig_idx]);
+		uncomp_bufs[priv_data->orig_idx] = NULL;
 	}
-	rte_pktmbuf_free(uncomp_buf);
-	uncomp_buf = NULL;
 
-	/* Allocate buffer for decompressed data */
-	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
-	if (uncomp_buf == NULL) {
+	/* Allocate buffers for decompressed data */
+	ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, uncomp_bufs, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Destination mbuf could not be allocated "
+			"Destination mbufs could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		rte_pktmbuf_append(uncomp_bufs[i],
+				strlen(test_bufs[priv_data->orig_idx]) + 1);
+	}
 
 	/* Build the decompression operations */
-	op = rte_comp_op_alloc(ts_params->op_pool);
-	if (op == NULL) {
+	ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Decompress operation could not be allocated "
+			"Decompress operations could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	/* Source buffer is the compressed data from the previous operation */
-	op->m_src = op_processed->m_dst;
-	op->m_dst = uncomp_buf;
-	op->src.offset = 0;
-	/*
-	 * Set the length of the compressed data to the
-	 * number of bytes that were produced in the previous stage
-	 */
-	op->src.length = op_processed->produced;
-	op->dst.offset = 0;
-	if (state == RTE_COMP_OP_STATELESS) {
-		//TODO: FULL or FINAL?
-		op->flush_flag = RTE_COMP_FLUSH_FINAL;
-	} else {
-		RTE_LOG(ERR, USER1,
-			"Stateful operations are not supported "
-			"in these tests yet\n");
-		goto exit;
+	/* Source buffer is the compressed data from the previous operations */
+	for (i = 0; i < num_bufs; i++) {
+		ops[i]->m_src = ops_processed[i]->m_dst;
+		ops[i]->m_dst = uncomp_bufs[i];
+		ops[i]->src.offset = 0;
+		/*
+		 * Set the length of the compressed data to the
+		 * number of bytes that were produced in the previous stage
+		 */
+		ops[i]->src.length = ops_processed[i]->produced;
+		ops[i]->dst.offset = 0;
+		if (state == RTE_COMP_OP_STATELESS) {
+			//TODO: FULL or FINAL?
+			ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
+		} else {
+			RTE_LOG(ERR, USER1,
+				"Stateful operations are not supported "
+				"in these tests yet\n");
+			goto exit;
+		}
+		ops[i]->input_chksum = 0;
+		/*
+		 * Copy private data from previous operations,
+		 * to keep the pointer to the original buffer
+		 */
+		memcpy(ops[i] + 1, ops_processed[i] + 1,
+				sizeof(struct priv_op_data));
 	}
-	op->input_chksum = 0;
 
 	/*
-	 * Free the previous compress operation,
+	 * Free the previous compress operations,
 	 * as it is not needed anymore
 	 */
-	rte_comp_op_free(op_processed);
-	op_processed = NULL;
+	for (i = 0; i < num_bufs; i++) {
+		rte_comp_op_free(ops_processed[i]);
+		ops_processed[i] = NULL;
+	}
 
 	/* Decompress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
-		ret = decompress_zlib(op,
-			(const struct rte_comp_xform *)&decompress_xform);
-		if (ret < 0)
-			goto exit;
+		for (i = 0; i < num_bufs; i++) {
+			ret = decompress_zlib(ops[i],
+				(const struct rte_comp_xform *)decompress_xform);
+			if (ret < 0)
+				goto exit;
 
-		op_processed = op;
-	} else {
-		num_deqd = 0;
-		/* Create decompress xform private data */
-		ret = rte_compressdev_private_xform_create(0,
-			(const struct rte_comp_xform *)decompress_xform,
-			&priv_xform);
-		if (ret < 0) {
-			RTE_LOG(ERR, USER1,
-				"Decompression private xform "
-				"could not be created\n");
-			goto exit;
+			ops_processed[i] = ops[i];
 		}
+	} else {
+		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
+			/* Create single decompress private xform data */
+			ret = rte_compressdev_private_xform_create(0,
+				(const struct rte_comp_xform *)decompress_xform,
+				&priv_xforms[0]);
+			if (ret < 0) {
+				RTE_LOG(ERR, USER1,
+					"Decompression private xform "
+					"could not be created\n");
+				goto exit;
+			}
+			num_priv_xforms++;
+			/* Attach shareable private xform data to ops */
+			for (i = 0; i < num_bufs; i++)
+				ops[i]->private_xform = priv_xforms[0];
+		} else {
+			/* Create decompress private xform data per op */
+			for (i = 0; i < num_bufs; i++) {
+				ret = rte_compressdev_private_xform_create(0,
+					decompress_xform, &priv_xforms[i]);
+				if (ret < 0) {
+					RTE_LOG(ERR, USER1,
+						"Deompression private xform "
+						"could not be created\n");
+					goto exit;
+				}
+				num_priv_xforms++;
+			}
 
-		/* Attach xform private data to operation */
-		op->private_xform = priv_xform;
+			/* Attach non shareable private xform data to ops */
+			for (i = 0; i < num_bufs; i++)
+				ops[i]->private_xform = priv_xforms[i];
+		}
 
 		/* Enqueue and dequeue all operations */
-		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
-		if (ret == 0) {
+		num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
+		if (num_enqd < num_bufs) {
 			RTE_LOG(ERR, USER1,
-				"The operation could not be enqueued\n");
+				"The operations could not be enqueued\n");
 			goto exit;
 		}
+
+		num_total_deqd = 0;
 		do {
 			/*
 			 * If retrying a dequeue call, wait for 10 ms to allow
@@ -590,47 +695,66 @@ test_deflate_comp_decomp(const char *test_buffer,
 				usleep(DEQUEUE_WAIT_TIME);
 			}
 			num_deqd = rte_compressdev_dequeue_burst(0, 0,
-					&op_processed, 1);
-
+					&ops_processed[num_total_deqd], num_bufs);
+			num_total_deqd += num_deqd;
 			deqd_retries++;
-		} while (num_deqd < 1);
+		} while (num_total_deqd < num_enqd);
+
+		deqd_retries = 0;
+	}
+
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		RTE_LOG(DEBUG, USER1, "Buffer %u decompressed from %u to %u bytes\n",
+			buf_idx[priv_data->orig_idx],
+			ops_processed[i]->consumed, ops_processed[i]->produced);
+		ops[i] = NULL;
 	}
 
-	RTE_LOG(DEBUG, USER1, "Buffer decompressed from %u to %u bytes\n",
-			op_processed->consumed, op_processed->produced);
-	op = NULL;
 	/*
 	 * Check operation status and free source mbuf (destination mbuf and
 	 * compress operation information is still needed)
 	 */
-	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
-		RTE_LOG(ERR, USER1,
-			"Some operations were not successful\n");
-		goto exit;
+	for (i = 0; i < num_bufs; i++) {
+		if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
+			RTE_LOG(ERR, USER1,
+				"Some operations were not successful\n");
+			goto exit;
+		}
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		rte_pktmbuf_free(comp_bufs[priv_data->orig_idx]);
+		comp_bufs[priv_data->orig_idx] = NULL;
 	}
-	rte_pktmbuf_free(comp_buf);
-	comp_buf = NULL;
 
 	/*
 	 * Compare the original stream with the decompressed stream
 	 * (in size and the data)
 	 */
-	if (compare_buffers(test_buffer, strlen(test_buffer) + 1,
-			rte_pktmbuf_mtod(op_processed->m_dst, const char *),
-			op_processed->produced) < 0)
-		goto exit;
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		const char *buf1 = test_bufs[priv_data->orig_idx];
+		const char *buf2 = rte_pktmbuf_mtod(ops_processed[i]->m_dst,
+				const char *);
+
+		if (compare_buffers(buf1, strlen(buf1) + 1,
+				buf2, ops_processed[i]->produced) < 0)
+			goto exit;
+	}
 
 	ret_status = 0;
 
 exit:
 	/* Free resources */
-	rte_pktmbuf_free(uncomp_buf);
-	rte_pktmbuf_free(comp_buf);
-	rte_comp_op_free(op);
-	rte_comp_op_free(op_processed);
-
-	if (priv_xform != NULL)
-		rte_compressdev_private_xform_free(0, priv_xform);
+	for (i = 0; i < num_bufs; i++) {
+		rte_pktmbuf_free(uncomp_bufs[i]);
+		rte_pktmbuf_free(comp_bufs[i]);
+		rte_comp_op_free(ops[i]);
+		rte_comp_op_free(ops_processed[i]);
+	}
+	for (i = 0; i < num_priv_xforms; i++) {
+		if (priv_xforms[i] != NULL)
+			rte_compressdev_private_xform_free(0, priv_xforms[i]);
+	}
 
 	return ret_status;
 }
@@ -651,7 +775,8 @@ test_compressdev_deflate_stateless_fixed(void)
 		test_buffer = compress_test_bufs[i];
 
 		/* Compress with compressdev, decompress with Zlib */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -659,7 +784,8 @@ test_compressdev_deflate_stateless_fixed(void)
 			return TEST_FAILED;
 
 		/* Compress with Zlib, decompress with compressdev */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -686,7 +812,8 @@ test_compressdev_deflate_stateless_dynamic(void)
 		test_buffer = compress_test_bufs[i];
 
 		/* Compress with compressdev, decompress with Zlib */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -694,7 +821,8 @@ test_compressdev_deflate_stateless_dynamic(void)
 			return TEST_FAILED;
 
 		/* Compress with Zlib, decompress with compressdev */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -705,6 +833,38 @@ test_compressdev_deflate_stateless_dynamic(void)
 	return TEST_SUCCESS;
 }
 
+static int
+test_compressdev_deflate_stateless_multi_op(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	uint16_t num_bufs = RTE_DIM(compress_test_bufs);
+	uint16_t buf_idx[num_bufs];
+	uint16_t i;
+
+	for (i = 0; i < num_bufs; i++)
+		buf_idx[i] = i;
+
+	/* Compress with compressdev, decompress with Zlib */
+	if (test_deflate_comp_decomp(compress_test_bufs, num_bufs,
+			buf_idx,
+			&ts_params->def_comp_xform,
+			&ts_params->def_decomp_xform,
+			RTE_COMP_OP_STATELESS,
+			ZLIB_DECOMPRESS) < 0)
+		return TEST_FAILED;
+
+	/* Compress with Zlib, decompress with compressdev */
+	if (test_deflate_comp_decomp(compress_test_bufs, num_bufs,
+			buf_idx,
+			&ts_params->def_comp_xform,
+			&ts_params->def_decomp_xform,
+			RTE_COMP_OP_STATELESS,
+			ZLIB_COMPRESS) < 0)
+		return TEST_FAILED;
+
+	return TEST_SUCCESS;
+}
+
 static struct unit_test_suite compressdev_testsuite  = {
 	.suite_name = "compressdev unit test suite",
 	.setup = testsuite_setup,
@@ -714,6 +874,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 			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_multi_op),
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v2 3/5] test/compress: add multi level test
  2018-04-08 14:00 ` [dpdk-dev] [PATCH v2 0/5] Initial compressdev unit tests Pablo de Lara
  2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 1/5] test/compress: add initial " Pablo de Lara
  2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 2/5] test/compress: add multi op test Pablo de Lara
@ 2018-04-08 14:00   ` Pablo de Lara
  2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 4/5] test/compress: add multi xform test Pablo de Lara
  2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 5/5] test/compress: add invalid configuration tests Pablo de Lara
  4 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-04-08 14:00 UTC (permalink / raw)
  To: dev; +Cc: fiona.trahe, shally.verma, ahmed.mansour, Ashish.Gupta, Pablo de Lara

Add test that checks if all compression levels
are supported and compress a buffer correctly.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 test/test/test_compressdev.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index a264c4da4..10f205ac9 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -865,6 +865,37 @@ test_compressdev_deflate_stateless_multi_op(void)
 	return TEST_SUCCESS;
 }
 
+
+static int
+test_compressdev_deflate_stateless_multi_level(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	const char *test_buffer;
+	unsigned int level;
+	uint16_t i;
+	struct rte_comp_xform compress_xform;
+
+	memcpy(&compress_xform, &ts_params->def_comp_xform,
+			sizeof(struct rte_comp_xform));
+
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+		test_buffer = compress_test_bufs[i];
+		for (level = RTE_COMP_LEVEL_MIN; level <= RTE_COMP_LEVEL_MAX;
+				level++) {
+			compress_xform.compress.level = level;
+			/* Compress with compressdev, decompress with Zlib */
+			if (test_deflate_comp_decomp(&test_buffer, 1,
+					&i,
+					&compress_xform,
+					&ts_params->def_decomp_xform,
+					RTE_COMP_OP_STATELESS,
+					ZLIB_DECOMPRESS) < 0)
+				return TEST_FAILED;
+		}
+	}
+
+	return TEST_SUCCESS;
+}
 static struct unit_test_suite compressdev_testsuite  = {
 	.suite_name = "compressdev unit test suite",
 	.setup = testsuite_setup,
@@ -876,6 +907,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 			test_compressdev_deflate_stateless_dynamic),
 		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_CASES_END() /**< NULL terminate unit test array */
 	}
 };
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v2 4/5] test/compress: add multi xform test
  2018-04-08 14:00 ` [dpdk-dev] [PATCH v2 0/5] Initial compressdev unit tests Pablo de Lara
                     ` (2 preceding siblings ...)
  2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 3/5] test/compress: add multi level test Pablo de Lara
@ 2018-04-08 14:00   ` Pablo de Lara
  2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 5/5] test/compress: add invalid configuration tests Pablo de Lara
  4 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-04-08 14:00 UTC (permalink / raw)
  To: dev; +Cc: fiona.trahe, shally.verma, ahmed.mansour, Ashish.Gupta, Pablo de Lara

Add test that checks if multiple xforms can be
handled on a single enqueue call.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 test/test/test_compressdev.c | 261 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 193 insertions(+), 68 deletions(-)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index 10f205ac9..0cffd85ba 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -27,7 +27,7 @@
 #define COMPRESS_BUF_SIZE_RATIO 1.3
 #define NUM_MBUFS 16
 #define NUM_OPS 16
-#define NUM_MAX_XFORMS 1
+#define NUM_MAX_XFORMS 16
 #define NUM_MAX_INFLIGHT_OPS 128
 #define CACHE_SIZE 0
 
@@ -54,8 +54,8 @@ struct priv_op_data {
 struct comp_testsuite_params {
 	struct rte_mempool *mbuf_pool;
 	struct rte_mempool *op_pool;
-	struct rte_comp_xform def_comp_xform;
-	struct rte_comp_xform def_decomp_xform;
+	struct rte_comp_xform *def_comp_xform;
+	struct rte_comp_xform *def_decomp_xform;
 };
 
 static struct comp_testsuite_params testsuite_params = { 0 };
@@ -67,6 +67,8 @@ testsuite_teardown(void)
 
 	rte_mempool_free(ts_params->mbuf_pool);
 	rte_mempool_free(ts_params->op_pool);
+	rte_free(ts_params->def_comp_xform);
+	rte_free(ts_params->def_decomp_xform);
 }
 
 static int
@@ -110,21 +112,26 @@ testsuite_setup(void)
 		goto exit;
 	}
 
+	ts_params->def_comp_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
+	ts_params->def_decomp_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
+
 	/* Initializes default values for compress/decompress xforms */
-	ts_params->def_comp_xform.next = NULL;
-	ts_params->def_comp_xform.type = RTE_COMP_COMPRESS;
-	ts_params->def_comp_xform.compress.algo = RTE_COMP_ALGO_DEFLATE,
-	ts_params->def_comp_xform.compress.deflate.huffman =
+	ts_params->def_comp_xform->next = NULL;
+	ts_params->def_comp_xform->type = RTE_COMP_COMPRESS;
+	ts_params->def_comp_xform->compress.algo = RTE_COMP_ALGO_DEFLATE,
+	ts_params->def_comp_xform->compress.deflate.huffman =
 						RTE_COMP_HUFFMAN_DEFAULT;
-	ts_params->def_comp_xform.compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
-	ts_params->def_comp_xform.compress.chksum = RTE_COMP_CHECKSUM_NONE;
-	ts_params->def_comp_xform.compress.window_size = DEFAULT_WINDOW_SIZE;
+	ts_params->def_comp_xform->compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
+	ts_params->def_comp_xform->compress.chksum = RTE_COMP_CHECKSUM_NONE;
+	ts_params->def_comp_xform->compress.window_size = DEFAULT_WINDOW_SIZE;
 
-	ts_params->def_decomp_xform.next = NULL;
-	ts_params->def_decomp_xform.type = RTE_COMP_DECOMPRESS;
-	ts_params->def_decomp_xform.decompress.algo = RTE_COMP_ALGO_DEFLATE,
-	ts_params->def_decomp_xform.decompress.chksum = RTE_COMP_CHECKSUM_NONE;
-	ts_params->def_decomp_xform.decompress.window_size = DEFAULT_WINDOW_SIZE;
+	ts_params->def_decomp_xform->next = NULL;
+	ts_params->def_decomp_xform->type = RTE_COMP_DECOMPRESS;
+	ts_params->def_decomp_xform->decompress.algo = RTE_COMP_ALGO_DEFLATE,
+	ts_params->def_decomp_xform->decompress.chksum = RTE_COMP_CHECKSUM_NONE;
+	ts_params->def_decomp_xform->decompress.window_size = DEFAULT_WINDOW_SIZE;
 
 	return TEST_SUCCESS;
 
@@ -347,8 +354,9 @@ static int
 test_deflate_comp_decomp(const char * const test_bufs[],
 		unsigned int num_bufs,
 		uint16_t buf_idx[],
-		struct rte_comp_xform *compress_xform,
-		struct rte_comp_xform *decompress_xform,
+		struct rte_comp_xform *compress_xforms[],
+		struct rte_comp_xform *decompress_xforms[],
+		unsigned int num_xforms,
 		enum rte_comp_op_type state,
 		enum zlib_direction zlib_dir)
 {
@@ -443,8 +451,9 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 	/* Compress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
 		for (i = 0; i < num_bufs; i++) {
-			ret = compress_zlib(ops[i],
-				(const struct rte_comp_xform *)compress_xform,
+			const struct rte_comp_xform *compress_xform =
+				compress_xforms[i % num_xforms];
+			ret = compress_zlib(ops[i], compress_xform,
 					DEFAULT_MEM_LEVEL);
 			if (ret < 0)
 				goto exit;
@@ -452,11 +461,11 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 			ops_processed[i] = ops[i];
 		}
 	} else {
-		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
-			/* Create single compress private xform data */
+		/* Create compress private xform data */
+		for (i = 0; i < num_xforms; i++) {
 			ret = rte_compressdev_private_xform_create(0,
-				(const struct rte_comp_xform *)compress_xform,
-				&priv_xforms[0]);
+				(const struct rte_comp_xform *)compress_xforms[i],
+				&priv_xforms[i]);
 			if (ret < 0) {
 				RTE_LOG(ERR, USER1,
 					"Compression private xform "
@@ -464,14 +473,18 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 				goto exit;
 			}
 			num_priv_xforms++;
+		}
+
+		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
 			/* Attach shareable private xform data to ops */
 			for (i = 0; i < num_bufs; i++)
-				ops[i]->private_xform = priv_xforms[0];
+				ops[i]->private_xform = priv_xforms[i % num_xforms];
 		} else {
-			/* Create compress private xform data per op */
-			for (i = 0; i < num_bufs; i++) {
+			/* Create rest of the private xforms for the other ops */
+			for (i = num_xforms; i < num_bufs; i++) {
 				ret = rte_compressdev_private_xform_create(0,
-					compress_xform, &priv_xforms[i]);
+					compress_xforms[i % num_xforms],
+					&priv_xforms[i]);
 				if (ret < 0) {
 					RTE_LOG(ERR, USER1,
 						"Compression private xform "
@@ -529,15 +542,18 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 		num_priv_xforms = 0;
 	}
 
-	enum rte_comp_huffman huffman_type =
-		compress_xform->compress.deflate.huffman;
 	for (i = 0; i < num_bufs; i++) {
 		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		uint16_t xform_idx = priv_data->orig_idx % num_xforms;
+		const struct rte_comp_compress_xform *compress_xform =
+				&compress_xforms[xform_idx]->compress;
+		enum rte_comp_huffman huffman_type =
+			compress_xform->deflate.huffman;
 		RTE_LOG(DEBUG, USER1, "Buffer %u compressed from %u to %u bytes "
-			"(level = %u, huffman = %s)\n",
+			"(level = %d, huffman = %s)\n",
 			buf_idx[priv_data->orig_idx],
 			ops_processed[i]->consumed, ops_processed[i]->produced,
-			compress_xform->compress.level,
+			compress_xform->level,
 			huffman_type_strings[huffman_type]);
 		RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
 			(float)ops_processed[i]->produced /
@@ -625,19 +641,23 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 	/* Decompress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
 		for (i = 0; i < num_bufs; i++) {
-			ret = decompress_zlib(ops[i],
-				(const struct rte_comp_xform *)decompress_xform);
+			priv_data = (struct priv_op_data *)(ops[i] + 1);
+			uint16_t xform_idx = priv_data->orig_idx % num_xforms;
+			const struct rte_comp_xform *decompress_xform =
+				decompress_xforms[xform_idx];
+
+			ret = decompress_zlib(ops[i], decompress_xform);
 			if (ret < 0)
 				goto exit;
 
 			ops_processed[i] = ops[i];
 		}
 	} else {
-		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
-			/* Create single decompress private xform data */
+		/* Create decompress private xform data */
+		for (i = 0; i < num_xforms; i++) {
 			ret = rte_compressdev_private_xform_create(0,
-				(const struct rte_comp_xform *)decompress_xform,
-				&priv_xforms[0]);
+				(const struct rte_comp_xform *)decompress_xforms[i],
+				&priv_xforms[i]);
 			if (ret < 0) {
 				RTE_LOG(ERR, USER1,
 					"Decompression private xform "
@@ -645,17 +665,25 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 				goto exit;
 			}
 			num_priv_xforms++;
+		}
+
+		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
 			/* Attach shareable private xform data to ops */
-			for (i = 0; i < num_bufs; i++)
-				ops[i]->private_xform = priv_xforms[0];
-		} else {
-			/* Create decompress private xform data per op */
 			for (i = 0; i < num_bufs; i++) {
+				priv_data = (struct priv_op_data *)(ops[i] + 1);
+				uint16_t xform_idx = priv_data->orig_idx %
+								num_xforms;
+				ops[i]->private_xform = priv_xforms[xform_idx];
+			}
+		} else {
+			/* Create rest of the private xforms for the other ops */
+			for (i = num_xforms; i < num_bufs; i++) {
 				ret = rte_compressdev_private_xform_create(0,
-					decompress_xform, &priv_xforms[i]);
+					decompress_xforms[i % num_xforms],
+					&priv_xforms[i]);
 				if (ret < 0) {
 					RTE_LOG(ERR, USER1,
-						"Deompression private xform "
+						"Decompression private xform "
 						"could not be created\n");
 					goto exit;
 				}
@@ -663,8 +691,11 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 			}
 
 			/* Attach non shareable private xform data to ops */
-			for (i = 0; i < num_bufs; i++)
-				ops[i]->private_xform = priv_xforms[i];
+			for (i = 0; i < num_bufs; i++) {
+				priv_data = (struct priv_op_data *) (ops[i] + 1);
+				uint16_t xform_idx = priv_data->orig_idx;
+				ops[i]->private_xform = priv_xforms[xform_idx];
+			}
 		}
 
 		/* Enqueue and dequeue all operations */
@@ -765,11 +796,13 @@ test_compressdev_deflate_stateless_fixed(void)
 	struct comp_testsuite_params *ts_params = &testsuite_params;
 	const char *test_buffer;
 	uint16_t i;
-	struct rte_comp_xform compress_xform;
+	int ret;
+	struct rte_comp_xform *compress_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
 
-	memcpy(&compress_xform, &ts_params->def_comp_xform,
+	memcpy(compress_xform, ts_params->def_comp_xform,
 			sizeof(struct rte_comp_xform));
-	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
+	compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
 		test_buffer = compress_test_bufs[i];
@@ -779,21 +812,31 @@ test_compressdev_deflate_stateless_fixed(void)
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_DECOMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_DECOMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 
 		/* Compress with Zlib, decompress with compressdev */
 		if (test_deflate_comp_decomp(&test_buffer, 1,
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_COMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_COMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 	}
 
-	return TEST_SUCCESS;
+	ret = TEST_SUCCESS;
+
+exit:
+	rte_free(compress_xform);
+	return ret;
 }
 
 static int
@@ -802,11 +845,13 @@ test_compressdev_deflate_stateless_dynamic(void)
 	struct comp_testsuite_params *ts_params = &testsuite_params;
 	const char *test_buffer;
 	uint16_t i;
-	struct rte_comp_xform compress_xform;
+	int ret;
+	struct rte_comp_xform *compress_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
 
-	memcpy(&compress_xform, &ts_params->def_comp_xform,
+	memcpy(compress_xform, ts_params->def_comp_xform,
 			sizeof(struct rte_comp_xform));
-	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
+	compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
 		test_buffer = compress_test_bufs[i];
@@ -816,21 +861,31 @@ test_compressdev_deflate_stateless_dynamic(void)
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_DECOMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_DECOMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 
 		/* Compress with Zlib, decompress with compressdev */
 		if (test_deflate_comp_decomp(&test_buffer, 1,
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_COMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_COMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 	}
 
-	return TEST_SUCCESS;
+	ret = TEST_SUCCESS;
+
+exit:
+	rte_free(compress_xform);
+	return ret;
 }
 
 static int
@@ -849,6 +904,7 @@ test_compressdev_deflate_stateless_multi_op(void)
 			buf_idx,
 			&ts_params->def_comp_xform,
 			&ts_params->def_decomp_xform,
+			1,
 			RTE_COMP_OP_STATELESS,
 			ZLIB_DECOMPRESS) < 0)
 		return TEST_FAILED;
@@ -858,6 +914,7 @@ test_compressdev_deflate_stateless_multi_op(void)
 			buf_idx,
 			&ts_params->def_comp_xform,
 			&ts_params->def_decomp_xform,
+			1,
 			RTE_COMP_OP_STATELESS,
 			ZLIB_COMPRESS) < 0)
 		return TEST_FAILED;
@@ -865,7 +922,6 @@ test_compressdev_deflate_stateless_multi_op(void)
 	return TEST_SUCCESS;
 }
 
-
 static int
 test_compressdev_deflate_stateless_multi_level(void)
 {
@@ -873,29 +929,96 @@ test_compressdev_deflate_stateless_multi_level(void)
 	const char *test_buffer;
 	unsigned int level;
 	uint16_t i;
-	struct rte_comp_xform compress_xform;
+	int ret;
+	struct rte_comp_xform *compress_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
 
-	memcpy(&compress_xform, &ts_params->def_comp_xform,
+	memcpy(compress_xform, ts_params->def_comp_xform,
 			sizeof(struct rte_comp_xform));
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
 		test_buffer = compress_test_bufs[i];
 		for (level = RTE_COMP_LEVEL_MIN; level <= RTE_COMP_LEVEL_MAX;
 				level++) {
-			compress_xform.compress.level = level;
+			compress_xform->compress.level = level;
 			/* Compress with compressdev, decompress with Zlib */
 			if (test_deflate_comp_decomp(&test_buffer, 1,
 					&i,
 					&compress_xform,
 					&ts_params->def_decomp_xform,
+					1,
 					RTE_COMP_OP_STATELESS,
-					ZLIB_DECOMPRESS) < 0)
-				return TEST_FAILED;
+					ZLIB_DECOMPRESS) < 0) {
+				ret = TEST_FAILED;
+				goto exit;
+			}
 		}
 	}
 
-	return TEST_SUCCESS;
+	ret = TEST_SUCCESS;
+
+exit:
+	rte_free(compress_xform);
+	return ret;
 }
+
+#define NUM_XFORMS 3
+static int
+test_compressdev_deflate_stateless_multi_xform(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	uint16_t num_bufs = NUM_XFORMS;
+	struct rte_comp_xform *compress_xforms[NUM_XFORMS] = {NULL};
+	struct rte_comp_xform *decompress_xforms[NUM_XFORMS] = {NULL};
+	const char *test_buffers[NUM_XFORMS];
+	uint16_t i;
+	unsigned int level = RTE_COMP_LEVEL_MIN;
+	uint16_t buf_idx[num_bufs];
+
+	int ret;
+
+	/* Create multiple xforms with various levels */
+	for (i = 0; i < NUM_XFORMS; i++) {
+		compress_xforms[i] = rte_malloc(NULL,
+				sizeof(struct rte_comp_xform), 0);
+		memcpy(compress_xforms[i], ts_params->def_comp_xform,
+				sizeof(struct rte_comp_xform));
+		compress_xforms[i]->compress.level = level;
+		level++;
+
+		decompress_xforms[i] = rte_malloc(NULL,
+				sizeof(struct rte_comp_xform), 0);
+		memcpy(decompress_xforms[i], ts_params->def_decomp_xform,
+				sizeof(struct rte_comp_xform));
+	}
+
+	for (i = 0; i < NUM_XFORMS; i++) {
+		buf_idx[i] = 0;
+		/* Use the same buffer in all sessions */
+		test_buffers[i] = compress_test_bufs[0];
+	}
+	/* Compress with compressdev, decompress with Zlib */
+	if (test_deflate_comp_decomp(test_buffers, num_bufs,
+			buf_idx,
+			compress_xforms,
+			decompress_xforms,
+			NUM_XFORMS,
+			RTE_COMP_OP_STATELESS,
+			ZLIB_DECOMPRESS) < 0) {
+		ret = TEST_FAILED;
+		goto exit;
+	}
+
+	ret = TEST_SUCCESS;
+exit:
+	for (i = 0; i < NUM_XFORMS; i++) {
+		rte_free(compress_xforms[i]);
+		rte_free(decompress_xforms[i]);
+	}
+
+	return ret;
+}
+
 static struct unit_test_suite compressdev_testsuite  = {
 	.suite_name = "compressdev unit test suite",
 	.setup = testsuite_setup,
@@ -909,6 +1032,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 			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_CASES_END() /**< NULL terminate unit test array */
 	}
 };
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v2 5/5] test/compress: add invalid configuration tests
  2018-04-08 14:00 ` [dpdk-dev] [PATCH v2 0/5] Initial compressdev unit tests Pablo de Lara
                     ` (3 preceding siblings ...)
  2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 4/5] test/compress: add multi xform test Pablo de Lara
@ 2018-04-08 14:00   ` Pablo de Lara
  4 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-04-08 14:00 UTC (permalink / raw)
  To: dev; +Cc: fiona.trahe, shally.verma, ahmed.mansour, Ashish.Gupta, Pablo de Lara

Add tests that check if device configuration
is not successful when providing invalid parameters.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 test/test/test_compressdev.c | 49 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index 0cffd85ba..1dbd8779d 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -177,6 +177,51 @@ generic_ut_teardown(void)
 	rte_compressdev_stop(0);
 }
 
+static int
+test_compressdev_invalid_configuration(void)
+{
+	struct rte_compressdev_config invalid_config;
+	struct rte_compressdev_config valid_config = {
+		.socket_id = rte_socket_id(),
+		.nb_queue_pairs = 1,
+		.max_nb_priv_xforms = NUM_MAX_XFORMS,
+		.max_nb_streams = 0
+	};
+	struct rte_compressdev_info dev_info;
+
+	/* Invalid configuration with 0 queue pairs */
+	memcpy(&invalid_config, &valid_config,
+			sizeof(struct rte_compressdev_config));
+	invalid_config.nb_queue_pairs = 0;
+
+	TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
+			"Device configuration was successful "
+			"with no queue pairs (invalid)\n");
+
+	/*
+	 * Invalid configuration with too many queue pairs
+	 * (if there is an actual maximum number of queue pairs)
+	 */
+	rte_compressdev_info_get(0, &dev_info);
+	if (dev_info.max_nb_queue_pairs != 0) {
+		memcpy(&invalid_config, &valid_config,
+			sizeof(struct rte_compressdev_config));
+		invalid_config.nb_queue_pairs = dev_info.max_nb_queue_pairs + 1;
+
+		TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
+				"Device configuration was successful "
+				"with too many queue pairs (invalid)\n");
+	}
+
+	/* Invalid queue pair setup, with no number of queue pairs set */
+	TEST_ASSERT_FAIL(rte_compressdev_queue_pair_setup(0, 0,
+				NUM_MAX_INFLIGHT_OPS, rte_socket_id()),
+			"Queue pair setup was successful "
+			"with no queue pairs set (invalid)\n");
+
+	return TEST_SUCCESS;
+}
+
 static int
 compare_buffers(const char *buffer1, uint32_t buffer1_len,
 		const char *buffer2, uint32_t buffer2_len)
@@ -692,7 +737,7 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 
 			/* Attach non shareable private xform data to ops */
 			for (i = 0; i < num_bufs; i++) {
-				priv_data = (struct priv_op_data *) (ops[i] + 1);
+				priv_data = (struct priv_op_data *)(ops[i] + 1);
 				uint16_t xform_idx = priv_data->orig_idx;
 				ops[i]->private_xform = priv_xforms[xform_idx];
 			}
@@ -1024,6 +1069,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 	.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,
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests
  2018-02-28 14:00 [dpdk-dev] [PATCH 0/5] Initial compressdev unit tests Pablo de Lara
                   ` (5 preceding siblings ...)
  2018-04-08 14:00 ` [dpdk-dev] [PATCH v2 0/5] Initial compressdev unit tests Pablo de Lara
@ 2018-04-27 14:14 ` Pablo de Lara
  2018-04-27 14:14   ` [dpdk-dev] [PATCH v3 1/5] test/compress: add initial " Pablo de Lara
                     ` (5 more replies)
  2018-05-04 10:22 ` [dpdk-dev] [PATCH v4 " Pablo de Lara
  7 siblings, 6 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-04-27 14:14 UTC (permalink / raw)
  To: dev; +Cc: fiona.trahe, shally.verma, ahmed.mansour, Ashish.Gupta, Pablo de Lara

Added initial tests for Compressdev library.
The tests are performed compressing a test buffer (or multiple test buffers)
with compressdev or Zlib, and decompressing it/them with the other library
(if compression is done with compressdev, decompression is done with Zlib,
and viceversa).

Tests added so far are based on the deflate algorithm,
including:
- Fixed huffman on single buffer
- Dynamic huffman on single buffer
- Multi compression level test on single buffer
- Multi buffer
- Multi xform using the same buffer

Due to a dependency on Zlib, the test is not enabled by default.
Once the library is installed, the configuration option
CONFIG_RTE_COMPRESSDEV_TEST must be set to Y.
However, if building with Meson, the test will be built automatically,
if Zlib is installed.

The test requires a compressdev PMD to be initialized,
when running the test app. For example:

./build/app/test --vdev="compress_X"

RTE>>compressdev_autotest

This patchset depends on the Compressdev API patchset:
http://dpdk.org/ml/archives/dev/2018-April/099580.html
("[PATCH v6 00/14] Implement compression API")

Changes in v3:
- Remove next pointer in xform setting
- Remove unneeded DIV_CEIL macro
- Add rte_compressdev_close() call after finishing test cases

Changes in v2:
- Add meson build
- Add invalid configuration tests
- Use new Compressdev API:
  * Substitute session with priv xform
  * Check if priv xform is shareable and create one per operation if not

Pablo de Lara (5):
  test/compress: add initial unit tests
  test/compress: add multi op test
  test/compress: add multi level test
  test/compress: add multi xform test
  test/compress: add invalid configuration tests

 config/common_base                       |    5 +
 test/test/Makefile                       |    9 +
 test/test/meson.build                    |    8 +
 test/test/test_compressdev.c             | 1092 ++++++++++++++++++++++++++++++
 test/test/test_compressdev_test_buffer.h |  295 ++++++++
 5 files changed, 1409 insertions(+)
 create mode 100644 test/test/test_compressdev.c
 create mode 100644 test/test/test_compressdev_test_buffer.h

-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v3 1/5] test/compress: add initial unit tests
  2018-04-27 14:14 ` [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests Pablo de Lara
@ 2018-04-27 14:14   ` Pablo de Lara
  2018-05-02 13:44     ` Daly, Lee
  2018-04-27 14:14   ` [dpdk-dev] [PATCH v3 2/5] test/compress: add multi op test Pablo de Lara
                     ` (4 subsequent siblings)
  5 siblings, 1 reply; 32+ messages in thread
From: Pablo de Lara @ 2018-04-27 14:14 UTC (permalink / raw)
  To: dev
  Cc: fiona.trahe, shally.verma, ahmed.mansour, Ashish.Gupta,
	Pablo de Lara, Ashish Gupta, Shally Verma

This commit introduces the initial tests for compressdev,
performing basic compression and decompression operations
of sample test buffers, using the Zlib library in one direction
and compressdev in another direction, to make sure that
the library is compatible with Zlib.

Due to the use of Zlib API, the test is disabled by default,
to avoid adding a new dependency on DPDK.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Signed-off-by: Ashish Gupta <ashish.gupta@caviumnetworks.com>
Signed-off-by: Shally Verma <shally.verma@caviumnetworks.com>
---
 config/common_base                       |   5 +
 test/test/Makefile                       |   9 +
 test/test/meson.build                    |   8 +
 test/test/test_compressdev.c             | 725 +++++++++++++++++++++++++++++++
 test/test/test_compressdev_test_buffer.h | 295 +++++++++++++
 5 files changed, 1042 insertions(+)
 create mode 100644 test/test/test_compressdev.c
 create mode 100644 test/test/test_compressdev_test_buffer.h

diff --git a/config/common_base b/config/common_base
index 23cf00011..fdec213cc 100644
--- a/config/common_base
+++ b/config/common_base
@@ -574,6 +574,11 @@ CONFIG_RTE_LIBRTE_SECURITY=y
 CONFIG_RTE_LIBRTE_COMPRESSDEV=y
 CONFIG_RTE_COMPRESS_MAX_DEVS=64
 
+#
+# Compile compressdev unit test
+#
+CONFIG_RTE_COMPRESSDEV_TEST=n
+
 #
 # Compile generic event device library
 #
diff --git a/test/test/Makefile b/test/test/Makefile
index 2630ab484..77d6369d6 100644
--- a/test/test/Makefile
+++ b/test/test/Makefile
@@ -180,6 +180,10 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_RING) += test_pmd_ring_perf.c
 SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_blockcipher.c
 SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c
 
+ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y)
+SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c
+endif
+
 ifeq ($(CONFIG_RTE_LIBRTE_EVENTDEV),y)
 SRCS-y += test_eventdev.c
 SRCS-y += test_event_ring.c
@@ -201,6 +205,11 @@ CFLAGS += $(WERROR_FLAGS)
 CFLAGS += -D_GNU_SOURCE
 
 LDLIBS += -lm
+ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y)
+ifeq ($(CONFIG_RTE_LIBRTE_COMPRESSDEV),y)
+LDLIBS += -lz
+endif
+endif
 
 # Disable VTA for memcpy test
 ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
diff --git a/test/test/meson.build b/test/test/meson.build
index ad0a65080..d71cd3c83 100644
--- a/test/test/meson.build
+++ b/test/test/meson.build
@@ -234,6 +234,14 @@ if dpdk_conf.has('RTE_LIBRTE_KNI')
 endif
 
 test_dep_objs = []
+compress_test_dep = dependency('zlib', required: false)
+if compress_test_dep.found()
+	test_dep_objs += compress_test_dep
+	test_sources += 'test_compressdev.c'
+	test_deps += 'compressdev'
+	test_names += 'compressdev_autotest'
+endif
+
 foreach d:test_deps
 	def_lib = get_option('default_library')
 	test_dep_objs += get_variable(def_lib + '_rte_' + d)
diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
new file mode 100644
index 000000000..a1c4f1027
--- /dev/null
+++ b/test/test/test_compressdev.c
@@ -0,0 +1,725 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+#include <string.h>
+#include <zlib.h>
+#include <math.h>
+
+#include <rte_cycles.h>
+#include <rte_malloc.h>
+#include <rte_mempool.h>
+#include <rte_mbuf.h>
+#include <rte_compressdev.h>
+
+#include "test_compressdev_test_buffer.h"
+#include "test.h"
+
+#define DEFAULT_WINDOW_SIZE 15
+#define DEFAULT_MEM_LEVEL 8
+#define MAX_DEQD_RETRIES 10
+#define DEQUEUE_WAIT_TIME 10000
+
+/*
+ * 30% extra size for compressed data compared to original data,
+ * in case data size cannot be reduced and it is actually bigger
+ * due to the compress block headers
+ */
+#define COMPRESS_BUF_SIZE_RATIO 1.3
+#define NUM_MBUFS 16
+#define NUM_OPS 16
+#define NUM_MAX_XFORMS 1
+#define NUM_MAX_INFLIGHT_OPS 128
+#define CACHE_SIZE 0
+
+const char *
+huffman_type_strings[] = {
+	[RTE_COMP_HUFFMAN_DEFAULT]	= "PMD default",
+	[RTE_COMP_HUFFMAN_FIXED]	= "Fixed",
+	[RTE_COMP_HUFFMAN_DYNAMIC]	= "Dynamic"
+};
+
+enum zlib_direction {
+	ZLIB_NONE,
+	ZLIB_COMPRESS,
+	ZLIB_DECOMPRESS,
+	ZLIB_ALL
+};
+
+struct comp_testsuite_params {
+	struct rte_mempool *mbuf_pool;
+	struct rte_mempool *op_pool;
+	struct rte_comp_xform def_comp_xform;
+	struct rte_comp_xform def_decomp_xform;
+};
+
+static struct comp_testsuite_params testsuite_params = { 0 };
+
+static void
+testsuite_teardown(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+
+	rte_mempool_free(ts_params->mbuf_pool);
+	rte_mempool_free(ts_params->op_pool);
+}
+
+static int
+testsuite_setup(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	unsigned int i;
+
+	if (rte_compressdev_count() == 0) {
+		RTE_LOG(ERR, USER1, "Need at least one compress device\n");
+		return -EINVAL;
+	}
+
+	uint32_t max_buf_size = 0;
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
+		max_buf_size = RTE_MAX(max_buf_size,
+				strlen(compress_test_bufs[i]) + 1);
+
+	max_buf_size *= COMPRESS_BUF_SIZE_RATIO;
+	/*
+	 * Buffers to be used in compression and decompression.
+	 * Since decompressed data might be larger than
+	 * compressed data (due to block header),
+	 * buffers should be big enough for both cases.
+	 */
+	ts_params->mbuf_pool = rte_pktmbuf_pool_create("mbuf_pool",
+			NUM_MBUFS,
+			CACHE_SIZE, 0,
+			max_buf_size + RTE_PKTMBUF_HEADROOM,
+			rte_socket_id());
+	if (ts_params->mbuf_pool == NULL) {
+		RTE_LOG(ERR, USER1, "Large mbuf pool could not be created\n");
+		goto exit;
+	}
+
+	ts_params->op_pool = rte_comp_op_pool_create("op_pool", NUM_OPS,
+						0, 0, rte_socket_id());
+	if (ts_params->op_pool == NULL) {
+		RTE_LOG(ERR, USER1, "Operation pool could not be created\n");
+		goto exit;
+	}
+
+	/* Initializes default values for compress/decompress xforms */
+	ts_params->def_comp_xform.type = RTE_COMP_COMPRESS;
+	ts_params->def_comp_xform.compress.algo = RTE_COMP_ALGO_DEFLATE,
+	ts_params->def_comp_xform.compress.deflate.huffman =
+						RTE_COMP_HUFFMAN_DEFAULT;
+	ts_params->def_comp_xform.compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
+	ts_params->def_comp_xform.compress.chksum = RTE_COMP_CHECKSUM_NONE;
+	ts_params->def_comp_xform.compress.window_size = DEFAULT_WINDOW_SIZE;
+
+	ts_params->def_decomp_xform.type = RTE_COMP_DECOMPRESS;
+	ts_params->def_decomp_xform.decompress.algo = RTE_COMP_ALGO_DEFLATE,
+	ts_params->def_decomp_xform.decompress.chksum = RTE_COMP_CHECKSUM_NONE;
+	ts_params->def_decomp_xform.decompress.window_size = DEFAULT_WINDOW_SIZE;
+
+	return TEST_SUCCESS;
+
+exit:
+	testsuite_teardown();
+
+	return TEST_FAILED;
+}
+
+static int
+generic_ut_setup(void)
+{
+	/* Configure compressdev (one device, one queue pair) */
+	struct rte_compressdev_config config = {
+		.socket_id = rte_socket_id(),
+		.nb_queue_pairs = 1,
+		.max_nb_priv_xforms = NUM_MAX_XFORMS,
+		.max_nb_streams = 0
+	};
+
+	if (rte_compressdev_configure(0, &config) < 0) {
+		RTE_LOG(ERR, USER1, "Device configuration failed\n");
+		return -1;
+	}
+
+	if (rte_compressdev_queue_pair_setup(0, 0, NUM_MAX_INFLIGHT_OPS,
+			rte_socket_id()) < 0) {
+		RTE_LOG(ERR, USER1, "Queue pair setup failed\n");
+		return -1;
+	}
+
+	if (rte_compressdev_start(0) < 0) {
+		RTE_LOG(ERR, USER1, "Device could not be started\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+static void
+generic_ut_teardown(void)
+{
+	rte_compressdev_stop(0);
+	if (rte_compressdev_close(0) < 0)
+		RTE_LOG(ERR, USER1, "Device could not be closed\n");
+}
+
+static int
+compare_buffers(const char *buffer1, uint32_t buffer1_len,
+		const char *buffer2, uint32_t buffer2_len)
+{
+	if (buffer1_len != buffer2_len) {
+		RTE_LOG(ERR, USER1, "Buffer lengths are different\n");
+		return -1;
+	}
+
+	if (memcmp(buffer1, buffer2, buffer1_len) != 0) {
+		RTE_LOG(ERR, USER1, "Buffers are different\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+/*
+ * Maps compressdev and Zlib flush flags
+ */
+static int
+map_zlib_flush_flag(enum rte_comp_flush_flag flag)
+{
+	switch (flag) {
+	case RTE_COMP_FLUSH_NONE:
+		return Z_NO_FLUSH;
+	case RTE_COMP_FLUSH_SYNC:
+		return Z_SYNC_FLUSH;
+	case RTE_COMP_FLUSH_FULL:
+		return Z_FULL_FLUSH;
+	case RTE_COMP_FLUSH_FINAL:
+		return Z_FINISH;
+	/*
+	 * There should be only the values above,
+	 * so this should never happen
+	 */
+	default:
+		return -1;
+	}
+}
+
+static int
+compress_zlib(struct rte_comp_op *op,
+		const struct rte_comp_xform *xform, int mem_level)
+{
+	z_stream stream;
+	int zlib_flush;
+	int strategy, window_bits, comp_level;
+	int ret = -1;
+
+	/* initialize zlib stream */
+	stream.zalloc = Z_NULL;
+	stream.zfree = Z_NULL;
+	stream.opaque = Z_NULL;
+
+	if (xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_FIXED)
+		strategy = Z_FIXED;
+	else
+		strategy = Z_DEFAULT_STRATEGY;
+
+	/*
+	 * Window bits is the base two logarithm of the window size (in bytes).
+	 * When doing raw DEFLATE, this number will be negative.
+	 */
+	window_bits = -(xform->compress.window_size);
+
+	comp_level = xform->compress.level;
+
+	if (comp_level != RTE_COMP_LEVEL_NONE)
+		ret = deflateInit2(&stream, comp_level, Z_DEFLATED,
+			window_bits, mem_level, strategy);
+	else
+		ret = deflateInit(&stream, Z_NO_COMPRESSION);
+
+	if (ret != Z_OK) {
+		printf("Zlib deflate could not be initialized\n");
+		goto exit;
+	}
+
+	/* Assuming stateless operation */
+	stream.avail_in = op->src.length;
+	stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
+	stream.avail_out = op->m_dst->data_len;
+	stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
+
+	/* Stateless operation, all buffer will be compressed in one go */
+	zlib_flush = map_zlib_flush_flag(op->flush_flag);
+	ret = deflate(&stream, zlib_flush);
+
+	if (stream.avail_in != 0) {
+		RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
+		goto exit;
+	}
+
+	//TODO: This is only if flush final is used
+	if (ret != Z_STREAM_END)
+		goto exit;
+
+	op->consumed = op->src.length - stream.avail_in;
+	op->produced = op->m_dst->data_len - stream.avail_out;
+	op->status = RTE_COMP_OP_STATUS_SUCCESS;
+
+	deflateReset(&stream);
+
+	ret = 0;
+exit:
+	deflateEnd(&stream);
+
+	return ret;
+}
+
+static int
+decompress_zlib(struct rte_comp_op *op,
+		const struct rte_comp_xform *xform)
+{
+	z_stream stream;
+	int window_bits;
+	int zlib_flush;
+	int ret = TEST_FAILED;
+
+	/* initialize zlib stream */
+	stream.zalloc = Z_NULL;
+	stream.zfree = Z_NULL;
+	stream.opaque = Z_NULL;
+
+	/*
+	 * Window bits is the base two logarithm of the window size (in bytes).
+	 * When doing raw DEFLATE, this number will be negative.
+	 */
+	window_bits = -(xform->decompress.window_size);
+
+	ret = inflateInit2(&stream, window_bits);
+
+	if (ret != Z_OK) {
+		printf("Zlib deflate could not be initialized\n");
+		goto exit;
+	}
+
+	/* Assuming stateless operation */
+	stream.avail_in = op->src.length;
+	stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
+	stream.avail_out = op->m_dst->data_len;
+	stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
+
+	/* Stateless operation, all buffer will be compressed in one go */
+	zlib_flush = map_zlib_flush_flag(op->flush_flag);
+	ret = inflate(&stream, zlib_flush);
+
+	if (stream.avail_in != 0) {
+		RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
+		goto exit;
+	}
+
+	//TODO: This is only if flush final is used
+	if (ret != Z_STREAM_END)
+		goto exit;
+
+	op->consumed = op->src.length - stream.avail_in;
+	op->produced = op->m_dst->data_len - stream.avail_out;
+	op->status = RTE_COMP_OP_STATUS_SUCCESS;
+
+	inflateReset(&stream);
+
+	ret = 0;
+exit:
+	inflateEnd(&stream);
+
+	return ret;
+}
+
+/*
+ * Compresses and decompresses buffer with compressdev API and Zlib API
+ */
+static int
+test_deflate_comp_decomp(const char *test_buffer,
+		struct rte_comp_xform *compress_xform,
+		struct rte_comp_xform *decompress_xform,
+		enum rte_comp_op_type state,
+		enum zlib_direction zlib_dir)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	int ret_status = -1;
+	int ret;
+	struct rte_mbuf *comp_buf = NULL;
+	struct rte_mbuf *uncomp_buf = NULL;
+	struct rte_comp_op *op = NULL;
+	struct rte_comp_op *op_processed = NULL;
+	void *priv_xform = NULL;
+	uint16_t num_deqd;
+	unsigned int deqd_retries = 0;
+	char *data_ptr;
+
+	/* Prepare the source mbuf with the data */
+	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+	if (uncomp_buf == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Source mbuf could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	data_ptr = rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
+	snprintf(data_ptr, strlen(test_buffer) + 1, "%s", test_buffer);
+
+	/* Prepare the destination mbuf */
+	comp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+	if (comp_buf == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Destination mbuf could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	rte_pktmbuf_append(comp_buf,
+			strlen(test_buffer) * COMPRESS_BUF_SIZE_RATIO);
+
+	/* Build the compression operations */
+	op = rte_comp_op_alloc(ts_params->op_pool);
+	if (op == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Compress operation could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	op->m_src = uncomp_buf;
+	op->m_dst = comp_buf;
+	op->src.offset = 0;
+	op->src.length = rte_pktmbuf_pkt_len(uncomp_buf);
+	op->dst.offset = 0;
+	if (state == RTE_COMP_OP_STATELESS) {
+		//TODO: FULL or FINAL?
+		op->flush_flag = RTE_COMP_FLUSH_FINAL;
+	} else {
+		RTE_LOG(ERR, USER1,
+			"Stateful operations are not supported "
+			"in these tests yet\n");
+		goto exit;
+	}
+	op->input_chksum = 0;
+
+	/* Compress data (either with Zlib API or compressdev API */
+	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
+		ret = compress_zlib(op,
+			(const struct rte_comp_xform *)&compress_xform,
+			DEFAULT_MEM_LEVEL);
+		if (ret < 0)
+			goto exit;
+
+		op_processed = op;
+	} else {
+		/* Create compress xform private data */
+		ret = rte_compressdev_private_xform_create(0,
+			(const struct rte_comp_xform *)compress_xform,
+			&priv_xform);
+		if (ret < 0) {
+			RTE_LOG(ERR, USER1,
+				"Compression private xform "
+				"could not be created\n");
+			goto exit;
+		}
+
+		/* Attach xform private data to operation */
+		op->private_xform = priv_xform;
+
+		/* Enqueue and dequeue all operations */
+		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
+		if (ret == 0) {
+			RTE_LOG(ERR, USER1,
+				"The operation could not be enqueued\n");
+			goto exit;
+		}
+		do {
+			/*
+			 * If retrying a dequeue call, wait for 10 ms to allow
+			 * enough time to the driver to process the operations
+			 */
+			if (deqd_retries != 0) {
+				/*
+				 * Avoid infinite loop if not all the
+				 * operations get out of the device
+				 */
+				if (deqd_retries == MAX_DEQD_RETRIES) {
+					RTE_LOG(ERR, USER1,
+						"Not all operations could be "
+						"dequeued\n");
+					goto exit;
+				}
+				usleep(DEQUEUE_WAIT_TIME);
+			}
+			num_deqd = rte_compressdev_dequeue_burst(0, 0,
+					&op_processed, 1);
+
+			deqd_retries++;
+		} while (num_deqd < 1);
+
+		deqd_retries = 0;
+
+		/* Free compress private xform */
+		rte_compressdev_private_xform_free(0, priv_xform);
+		priv_xform = NULL;
+	}
+
+	enum rte_comp_huffman huffman_type =
+		compress_xform->compress.deflate.huffman;
+	RTE_LOG(DEBUG, USER1, "Buffer compressed from %u to %u bytes "
+			"(level = %u, huffman = %s)\n",
+			op_processed->consumed, op_processed->produced,
+			compress_xform->compress.level,
+			huffman_type_strings[huffman_type]);
+	RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
+			(float)op_processed->produced /
+			op_processed->consumed * 100);
+	op = NULL;
+
+	/*
+	 * Check operation status and free source mbuf (destination mbuf and
+	 * compress operation information is needed for the decompression stage)
+	 */
+	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
+		RTE_LOG(ERR, USER1,
+			"Some operations were not successful\n");
+		goto exit;
+	}
+	rte_pktmbuf_free(uncomp_buf);
+	uncomp_buf = NULL;
+
+	/* Allocate buffer for decompressed data */
+	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+	if (uncomp_buf == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Destination mbuf could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
+
+	/* Build the decompression operations */
+	op = rte_comp_op_alloc(ts_params->op_pool);
+	if (op == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Decompress operation could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	/* Source buffer is the compressed data from the previous operation */
+	op->m_src = op_processed->m_dst;
+	op->m_dst = uncomp_buf;
+	op->src.offset = 0;
+	/*
+	 * Set the length of the compressed data to the
+	 * number of bytes that were produced in the previous stage
+	 */
+	op->src.length = op_processed->produced;
+	op->dst.offset = 0;
+	if (state == RTE_COMP_OP_STATELESS) {
+		//TODO: FULL or FINAL?
+		op->flush_flag = RTE_COMP_FLUSH_FINAL;
+	} else {
+		RTE_LOG(ERR, USER1,
+			"Stateful operations are not supported "
+			"in these tests yet\n");
+		goto exit;
+	}
+	op->input_chksum = 0;
+
+	/*
+	 * Free the previous compress operation,
+	 * as it is not needed anymore
+	 */
+	rte_comp_op_free(op_processed);
+	op_processed = NULL;
+
+	/* Decompress data (either with Zlib API or compressdev API */
+	if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
+		ret = decompress_zlib(op,
+			(const struct rte_comp_xform *)&decompress_xform);
+		if (ret < 0)
+			goto exit;
+
+		op_processed = op;
+	} else {
+		num_deqd = 0;
+		/* Create decompress xform private data */
+		ret = rte_compressdev_private_xform_create(0,
+			(const struct rte_comp_xform *)decompress_xform,
+			&priv_xform);
+		if (ret < 0) {
+			RTE_LOG(ERR, USER1,
+				"Decompression private xform "
+				"could not be created\n");
+			goto exit;
+		}
+
+		/* Attach xform private data to operation */
+		op->private_xform = priv_xform;
+
+		/* Enqueue and dequeue all operations */
+		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
+		if (ret == 0) {
+			RTE_LOG(ERR, USER1,
+				"The operation could not be enqueued\n");
+			goto exit;
+		}
+		do {
+			/*
+			 * If retrying a dequeue call, wait for 10 ms to allow
+			 * enough time to the driver to process the operations
+			 */
+			if (deqd_retries != 0) {
+				/*
+				 * Avoid infinite loop if not all the
+				 * operations get out of the device
+				 */
+				if (deqd_retries == MAX_DEQD_RETRIES) {
+					RTE_LOG(ERR, USER1,
+						"Not all operations could be "
+						"dequeued\n");
+					goto exit;
+				}
+				usleep(DEQUEUE_WAIT_TIME);
+			}
+			num_deqd = rte_compressdev_dequeue_burst(0, 0,
+					&op_processed, 1);
+
+			deqd_retries++;
+		} while (num_deqd < 1);
+	}
+
+	RTE_LOG(DEBUG, USER1, "Buffer decompressed from %u to %u bytes\n",
+			op_processed->consumed, op_processed->produced);
+	op = NULL;
+	/*
+	 * Check operation status and free source mbuf (destination mbuf and
+	 * compress operation information is still needed)
+	 */
+	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
+		RTE_LOG(ERR, USER1,
+			"Some operations were not successful\n");
+		goto exit;
+	}
+	rte_pktmbuf_free(comp_buf);
+	comp_buf = NULL;
+
+	/*
+	 * Compare the original stream with the decompressed stream
+	 * (in size and the data)
+	 */
+	if (compare_buffers(test_buffer, strlen(test_buffer) + 1,
+			rte_pktmbuf_mtod(op_processed->m_dst, const char *),
+			op_processed->produced) < 0)
+		goto exit;
+
+	ret_status = 0;
+
+exit:
+	/* Free resources */
+	rte_pktmbuf_free(uncomp_buf);
+	rte_pktmbuf_free(comp_buf);
+	rte_comp_op_free(op);
+	rte_comp_op_free(op_processed);
+
+	if (priv_xform != NULL)
+		rte_compressdev_private_xform_free(0, priv_xform);
+
+	return ret_status;
+}
+
+static int
+test_compressdev_deflate_stateless_fixed(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	const char *test_buffer;
+	uint16_t i;
+	struct rte_comp_xform compress_xform;
+
+	memcpy(&compress_xform, &ts_params->def_comp_xform,
+			sizeof(struct rte_comp_xform));
+	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
+
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+		test_buffer = compress_test_bufs[i];
+
+		/* Compress with compressdev, decompress with Zlib */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_DECOMPRESS) < 0)
+			return TEST_FAILED;
+
+		/* Compress with Zlib, decompress with compressdev */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_COMPRESS) < 0)
+			return TEST_FAILED;
+	}
+
+	return TEST_SUCCESS;
+}
+
+static int
+test_compressdev_deflate_stateless_dynamic(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	const char *test_buffer;
+	uint16_t i;
+	struct rte_comp_xform compress_xform;
+
+	memcpy(&compress_xform, &ts_params->def_comp_xform,
+			sizeof(struct rte_comp_xform));
+	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
+
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+		test_buffer = compress_test_bufs[i];
+
+		/* Compress with compressdev, decompress with Zlib */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_DECOMPRESS) < 0)
+			return TEST_FAILED;
+
+		/* Compress with Zlib, decompress with compressdev */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_COMPRESS) < 0)
+			return TEST_FAILED;
+	}
+
+	return TEST_SUCCESS;
+}
+
+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(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_CASES_END() /**< NULL terminate unit test array */
+	}
+};
+
+static int
+test_compressdev(void)
+{
+	return unit_test_suite_runner(&compressdev_testsuite);
+}
+
+REGISTER_TEST_COMMAND(compressdev_autotest, test_compressdev);
diff --git a/test/test/test_compressdev_test_buffer.h b/test/test/test_compressdev_test_buffer.h
new file mode 100644
index 000000000..c0492f89a
--- /dev/null
+++ b/test/test/test_compressdev_test_buffer.h
@@ -0,0 +1,295 @@
+#ifndef TEST_COMPRESSDEV_TEST_BUFFERS_H_
+#define TEST_COMPRESSDEV_TEST_BUFFERS_H_
+
+/*
+ * These test buffers are snippets obtained
+ * from the Canterbury and Calgary Corpus
+ * collection.
+ */
+
+/* Snippet of Alice's Adventures in Wonderland */
+static const char test_buf_alice[] =
+	"  Alice was beginning to get very tired of sitting by her sister\n"
+	"on the bank, and of having nothing to do:  once or twice she had\n"
+	"peeped into the book her sister was reading, but it had no\n"
+	"pictures or conversations in it, `and what is the use of a book,'\n"
+	"thought Alice `without pictures or conversation?'\n\n"
+	"  So she was considering in her own mind (as well as she could,\n"
+	"for the hot day made her feel very sleepy and stupid), whether\n"
+	"the pleasure of making a daisy-chain would be worth the trouble\n"
+	"of getting up and picking the daisies, when suddenly a White\n"
+	"Rabbit with pink eyes ran close by her.\n\n"
+	"  There was nothing so VERY remarkable in that; nor did Alice\n"
+	"think it so VERY much out of the way to hear the Rabbit say to\n"
+	"itself, `Oh dear!  Oh dear!  I shall be late!'  (when she thought\n"
+	"it over afterwards, it occurred to her that she ought to have\n"
+	"wondered at this, but at the time it all seemed quite natural);\n"
+	"but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT-\n"
+	"POCKET, and looked at it, and then hurried on, Alice started to\n"
+	"her feet, for it flashed across her mind that she had never\n"
+	"before seen a rabbit with either a waistcoat-pocket, or a watch to\n"
+	"take out of it, and burning with curiosity, she ran across the\n"
+	"field after it, and fortunately was just in time to see it pop\n"
+	"down a large rabbit-hole under the hedge.\n\n"
+	"  In another moment down went Alice after it, never once\n"
+	"considering how in the world she was to get out again.\n\n"
+	"  The rabbit-hole went straight on like a tunnel for some way,\n"
+	"and then dipped suddenly down, so suddenly that Alice had not a\n"
+	"moment to think about stopping herself before she found herself\n"
+	"falling down a very deep well.\n\n"
+	"  Either the well was very deep, or she fell very slowly, for she\n"
+	"had plenty of time as she went down to look about her and to\n"
+	"wonder what was going to happen next.  First, she tried to look\n"
+	"down and make out what she was coming to, but it was too dark to\n"
+	"see anything; then she looked at the sides of the well, and\n"
+	"noticed that they were filled with cupboards and book-shelves;\n"
+	"here and there she saw maps and pictures hung upon pegs.  She\n"
+	"took down a jar from one of the shelves as she passed; it was\n"
+	"labelled `ORANGE MARMALADE', but to her great disappointment it\n"
+	"was empty:  she did not like to drop the jar for fear of killing\n"
+	"somebody, so managed to put it into one of the cupboards as she\n"
+	"fell past it.\n\n"
+	"  `Well!' thought Alice to herself, `after such a fall as this, I\n"
+	"shall think nothing of tumbling down stairs!  How brave they'll\n"
+	"all think me at home!  Why, I wouldn't say anything about it,\n"
+	"even if I fell off the top of the house!' (Which was very likely\n"
+	"true.)\n\n"
+	"  Down, down, down.  Would the fall NEVER come to an end!  `I\n"
+	"wonder how many miles I've fallen by this time?' she said aloud.\n"
+	"`I must be getting somewhere near the centre of the earth.  Let\n"
+	"me see:  that would be four thousand miles down, I think--' (for,\n"
+	"you see, Alice had learnt several things of this sort in her\n"
+	"lessons in the schoolroom, and though this was not a VERY good\n"
+	"opportunity for showing off her knowledge, as there was no one to\n"
+	"listen to her, still it was good practice to say it over) `--yes,\n"
+	"that's about the right distance--but then I wonder what Latitude\n"
+	"or Longitude I've got to?'  (Alice had no idea what Latitude was,\n"
+	"or Longitude either, but thought they were nice grand words to\n"
+	"say.)\n\n"
+	"  Presently she began again.  `I wonder if I shall fall right\n"
+	"THROUGH the earth!  How funny it'll seem to come out among the\n"
+	"people that walk with their heads downward!  The Antipathies, I\n"
+	"think--' (she was rather glad there WAS no one listening, this\n"
+	"time, as it didn't sound at all the right word) `--but I shall\n"
+	"have to ask them what the name of the country is, you know.\n"
+	"Please, Ma'am, is this New Zealand or Australia?' (and she tried\n"
+	"to curtsey as she spoke--fancy CURTSEYING as you're falling\n"
+	"through the air!  Do you think you could manage it?)  `And what\n"
+	"an ignorant little girl she'll think me for asking!  No, it'll\n"
+	"never do to ask:  perhaps I shall see it written up somewhere.'\n"
+	"  Down, down, down.  There was nothing else to do, so Alice soon\n"
+	"began talking again.  `Dinah'll miss me very much to-night, I\n"
+	"should think!'  (Dinah was the cat.)  `I hope they'll remember\n"
+	"her saucer of milk at tea-time.  Dinah my dear!  I wish you were\n"
+	"down here with me!  There are no mice in the air, I'm afraid, but\n"
+	"you might catch a bat, and that's very like a mouse, you know.\n"
+	"But do cats eat bats, I wonder?'  And here Alice began to get\n"
+	"rather sleepy, and went on saying to herself, in a dreamy sort of\n"
+	"way, `Do cats eat bats?  Do cats eat bats?' and sometimes, `Do\n"
+	"bats eat cats?' for, you see, as she couldn't answer either\n"
+	"question, it didn't much matter which way she put it.  She felt\n"
+	"that she was dozing off, and had just begun to dream that she\n"
+	"was walking hand in hand with Dinah, and saying to her very\n"
+	"earnestly, `Now, Dinah, tell me the truth:  did you ever eat a\n"
+	"bat?' when suddenly, thump! thump! down she came upon a heap of\n"
+	"sticks and dry leaves, and the fall was over.\n\n";
+
+/* Snippet of Shakespeare play */
+static const char test_buf_shakespeare[] =
+	"CHARLES	wrestler to Frederick.\n"
+	"\n"
+	"\n"
+	"OLIVER		|\n"
+	"		|\n"
+	"JAQUES (JAQUES DE BOYS:)  	|  sons of Sir Rowland de Boys.\n"
+	"		|\n"
+	"ORLANDO		|\n"
+	"\n"
+	"\n"
+	"ADAM	|\n"
+	"	|  servants to Oliver.\n"
+	"DENNIS	|\n"
+	"\n"
+	"\n"
+	"TOUCHSTONE	a clown.\n"
+	"\n"
+	"SIR OLIVER MARTEXT	a vicar.\n"
+	"\n"
+	"\n"
+	"CORIN	|\n"
+	"	|  shepherds.\n"
+	"SILVIUS	|\n"
+	"\n"
+	"\n"
+	"WILLIAM	a country fellow in love with Audrey.\n"
+	"\n"
+	"	A person representing HYMEN. (HYMEN:)\n"
+	"\n"
+	"ROSALIND	daughter to the banished duke.\n"
+	"\n"
+	"CELIA	daughter to Frederick.\n"
+	"\n"
+	"PHEBE	a shepherdess.\n"
+	"\n"
+	"AUDREY	a country wench.\n"
+	"\n"
+	"	Lords, pages, and attendants, &c.\n"
+	"	(Forester:)\n"
+	"	(A Lord:)\n"
+	"	(First Lord:)\n"
+	"	(Second Lord:)\n"
+	"	(First Page:)\n"
+	"	(Second Page:)\n"
+	"\n"
+	"\n"
+	"SCENE	Oliver's house; Duke Frederick's court; and the\n"
+	"	Forest of Arden.\n"
+	"\n"
+	"\n"
+	"\n"
+	"\n"
+	"	AS YOU LIKE IT\n"
+	"\n"
+	"\n"
+	"ACT I\n"
+	"\n"
+	"\n"
+	"\n"
+	"SCENE I	Orchard of Oliver's house.\n"
+	"\n"
+	"\n"
+	"	[Enter ORLANDO and ADAM]\n"
+	"\n"
+	"ORLANDO	As I remember, Adam, it was upon this fashion\n"
+	"	bequeathed me by will but poor a thousand crowns,\n"
+	"	and, as thou sayest, charged my brother, on his\n"
+	"	blessing, to breed me well: and there begins my\n"
+	"	sadness. My brother Jaques he keeps at school, and\n"
+	"	report speaks goldenly of his profit: for my part,\n"
+	"	he keeps me rustically at home, or, to speak more\n"
+	"	properly, stays me here at home unkept; for call you\n"
+	"	that keeping for a gentleman of my birth, that\n"
+	"	differs not from the stalling of an ox? His horses\n"
+	"	are bred better; for, besides that they are fair\n"
+	"	with their feeding, they are taught their manage,\n"
+	"	and to that end riders dearly hired: but I, his\n"
+	"	brother, gain nothing under him but growth; for the\n"
+	"	which his animals on his dunghills are as much\n"
+	"	bound to him as I. Besides this nothing that he so\n"
+	"	plentifully gives me, the something that nature gave\n"
+	"	me his countenance seems to take from me: he lets\n"
+	"	me feed with his hinds, bars me the place of a\n"
+	"	brother, and, as much as in him lies, mines my\n"
+	"	gentility with my education. This is it, Adam, that\n"
+	"	grieves me; and the spirit of my father, which I\n"
+	"	think is within me, begins to mutiny against this\n"
+	"	servitude: I will no longer endure it, though yet I\n"
+	"	know no wise remedy how to avoid it.\n"
+	"\n"
+	"ADAM	Yonder comes my master, your brother.\n"
+	"\n"
+	"ORLANDO	Go apart, Adam, and thou shalt hear how he will\n";
+
+/* Snippet of source code in Pascal */
+static const char test_buf_pascal[] =
+	"	Ptr    = 1..DMem;\n"
+	"	Loc    = 1..IMem;\n"
+	"	Loc0   = 0..IMem;\n"
+	"	EdgeT  = (hout,lin,hin,lout); {Warning this order is important in}\n"
+	"				      {predicates such as gtS,geS}\n"
+	"	CardT  = (finite,infinite);\n"
+	"	ExpT   = Minexp..Maxexp;\n"
+	"	ManT   = Mininf..Maxinf; \n"
+	"	Pflag  = (PNull,PSoln,PTrace,PPrint);\n"
+	"	Sreal  = record\n"
+	"		    edge:EdgeT;\n"
+	"		    cardinality:CardT;\n"
+	"		    exp:ExpT; {exponent}\n"
+	"		    mantissa:ManT;\n"
+	"		 end;\n"
+	"	Int    = record\n"
+	"		    hi:Sreal;\n"
+	"		    lo:Sreal;\n"
+	"	 end;\n"
+	"	Instr  = record\n"
+	"		    Code:OpType;\n"
+	"		    Pars: array[0..Par] of 0..DMem;\n"
+	"		 end;\n"
+	"	DataMem= record\n"
+	"		    D        :array [Ptr] of Int;\n"
+	"		    S        :array [Loc] of State;\n"
+	"		    LastHalve:Loc;\n"
+	"		    RHalve   :array [Loc] of real;\n"
+	"		 end;\n"
+	"	DataFlags=record\n"
+	"		    PF	     :array [Ptr] of Pflag;\n"
+	"		 end;\n"
+	"var\n"
+	"	Debug  : (none,activity,post,trace,dump);\n"
+	"	Cut    : (once,all);\n"
+	"	GlobalEnd,Verifiable:boolean;\n"
+	"	HalveThreshold:real;\n"
+	"	I      : array [Loc] of Instr; {Memory holding instructions}\n"
+	"	End    : Loc; {last instruction in I}\n"
+	"	ParN   : array [OpType] of -1..Par; {number of parameters for each \n"
+	"			opcode. -1 means no result}\n"
+	"        ParIntersect : array [OpType] of boolean ;\n"
+	"	DInit  : DataMem; {initial memory which is cleared and \n"
+	"				used in first call}\n"
+	"	DF     : DataFlags; {hold flags for variables, e.g. print/trace}\n"
+	"	MaxDMem:0..DMem;\n"
+	"	Shift  : array[0..Digits] of 1..maxint;{array of constant multipliers}\n"
+	"						{used for alignment etc.}\n"
+	"	Dummy  :Positive;\n"
+	"	{constant intervals and Sreals}\n"
+	"	PlusInfS,MinusInfS,PlusSmallS,MinusSmallS,ZeroS,\n"
+	"	PlusFiniteS,MinusFiniteS:Sreal;\n"
+	"	Zero,All,AllFinite:Int;\n"
+	"\n"
+	"procedure deblank;\n"
+	"var Ch:char;\n"
+	"begin\n"
+	"   while (not eof) and (input^ in [' ','	']) do read(Ch);\n"
+	"end;\n"
+	"\n"
+	"procedure InitialOptions;\n"
+	"\n"
+	"#include '/user/profs/cleary/bin/options.i';\n"
+	"\n"
+	"   procedure Option;\n"
+	"   begin\n"
+	"      case Opt of\n"
+	"      'a','A':Debug:=activity;\n"
+	"      'd','D':Debug:=dump;\n"
+	"      'h','H':HalveThreshold:=StringNum/100;\n"
+	"      'n','N':Debug:=none;\n"
+	"      'p','P':Debug:=post;\n"
+	"      't','T':Debug:=trace;\n"
+	"      'v','V':Verifiable:=true;\n"
+	"      end;\n"
+	"   end;\n"
+	"\n"
+	"begin\n"
+	"   Debug:=trace;\n"
+	"   Verifiable:=false;\n"
+	"   HalveThreshold:=67/100;\n"
+	"   Options;\n"
+	"   writeln(Debug);\n"
+	"   writeln('Verifiable:',Verifiable);\n"
+	"   writeln('Halve threshold',HalveThreshold);\n"
+	"end;{InitialOptions}\n"
+	"\n"
+	"procedure NormalizeUp(E,M:integer;var S:Sreal;var Closed:boolean);\n"
+	"begin\n"
+	"with S do\n"
+	"begin\n"
+	"   if M=0 then S:=ZeroS else\n"
+	"   if M>0 then\n";
+
+static const char * const compress_test_bufs[] = {
+	test_buf_alice,
+	test_buf_shakespeare,
+	test_buf_pascal
+};
+
+#endif /* TEST_COMPRESSDEV_TEST_BUFFERS_H_ */
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v3 2/5] test/compress: add multi op test
  2018-04-27 14:14 ` [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests Pablo de Lara
  2018-04-27 14:14   ` [dpdk-dev] [PATCH v3 1/5] test/compress: add initial " Pablo de Lara
@ 2018-04-27 14:14   ` Pablo de Lara
  2018-04-27 14:15   ` [dpdk-dev] [PATCH v3 3/5] test/compress: add multi level test Pablo de Lara
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-04-27 14:14 UTC (permalink / raw)
  To: dev; +Cc: fiona.trahe, shally.verma, ahmed.mansour, Ashish.Gupta, Pablo de Lara

Add test that checks if multiple operations with
different buffers can be handled on a single enqueue call.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 test/test/test_compressdev.c | 476 +++++++++++++++++++++++++++++--------------
 1 file changed, 319 insertions(+), 157 deletions(-)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index a1c4f1027..8e67faec2 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -45,6 +45,10 @@ enum zlib_direction {
 	ZLIB_ALL
 };
 
+struct priv_op_data {
+	uint16_t orig_idx;
+};
+
 struct comp_testsuite_params {
 	struct rte_mempool *mbuf_pool;
 	struct rte_mempool *op_pool;
@@ -97,7 +101,8 @@ testsuite_setup(void)
 	}
 
 	ts_params->op_pool = rte_comp_op_pool_create("op_pool", NUM_OPS,
-						0, 0, rte_socket_id());
+				0, sizeof(struct priv_op_data),
+				rte_socket_id());
 	if (ts_params->op_pool == NULL) {
 		RTE_LOG(ERR, USER1, "Operation pool could not be created\n");
 		goto exit;
@@ -337,7 +342,9 @@ decompress_zlib(struct rte_comp_op *op,
  * Compresses and decompresses buffer with compressdev API and Zlib API
  */
 static int
-test_deflate_comp_decomp(const char *test_buffer,
+test_deflate_comp_decomp(const char * const test_bufs[],
+		unsigned int num_bufs,
+		uint16_t buf_idx[],
 		struct rte_comp_xform *compress_xform,
 		struct rte_comp_xform *decompress_xform,
 		enum rte_comp_op_type state,
@@ -346,95 +353,146 @@ test_deflate_comp_decomp(const char *test_buffer,
 	struct comp_testsuite_params *ts_params = &testsuite_params;
 	int ret_status = -1;
 	int ret;
-	struct rte_mbuf *comp_buf = NULL;
-	struct rte_mbuf *uncomp_buf = NULL;
-	struct rte_comp_op *op = NULL;
-	struct rte_comp_op *op_processed = NULL;
-	void *priv_xform = NULL;
-	uint16_t num_deqd;
+	struct rte_mbuf *uncomp_bufs[num_bufs];
+	struct rte_mbuf *comp_bufs[num_bufs];
+	struct rte_comp_op *ops[num_bufs];
+	struct rte_comp_op *ops_processed[num_bufs];
+	void *priv_xforms[num_bufs];
+	uint16_t num_enqd, num_deqd, num_total_deqd;
+	uint16_t num_priv_xforms = 0;
 	unsigned int deqd_retries = 0;
+	struct priv_op_data *priv_data;
 	char *data_ptr;
-
-	/* Prepare the source mbuf with the data */
-	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
-	if (uncomp_buf == NULL) {
+	unsigned int i;
+	const struct rte_compressdev_capabilities *capa =
+		rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+
+	/* Initialize all arrays to NULL */
+	memset(uncomp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
+	memset(comp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
+	memset(ops, 0, sizeof(struct rte_comp_op *) * num_bufs);
+	memset(ops_processed, 0, sizeof(struct rte_comp_op *) * num_bufs);
+	memset(priv_xforms, 0, sizeof(void *) * num_bufs);
+
+	/* Prepare the source mbufs with the data */
+	ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, uncomp_bufs, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Source mbuf could not be allocated "
+			"Source mbufs could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	data_ptr = rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
-	snprintf(data_ptr, strlen(test_buffer) + 1, "%s", test_buffer);
+	for (i = 0; i < num_bufs; i++) {
+		data_ptr = rte_pktmbuf_append(uncomp_bufs[i],
+					strlen(test_bufs[i]) + 1);
+		snprintf(data_ptr, strlen(test_bufs[i]) + 1, "%s",
+					test_bufs[i]);
+	}
 
-	/* Prepare the destination mbuf */
-	comp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
-	if (comp_buf == NULL) {
+	/* Prepare the destination mbufs */
+	ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, comp_bufs, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Destination mbuf could not be allocated "
+			"Destination mbufs could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	rte_pktmbuf_append(comp_buf,
-			strlen(test_buffer) * COMPRESS_BUF_SIZE_RATIO);
+	for (i = 0; i < num_bufs; i++)
+		rte_pktmbuf_append(comp_bufs[i],
+			strlen(test_bufs[i]) * COMPRESS_BUF_SIZE_RATIO);
 
 	/* Build the compression operations */
-	op = rte_comp_op_alloc(ts_params->op_pool);
-	if (op == NULL) {
+	ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Compress operation could not be allocated "
+			"Compress operations could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	op->m_src = uncomp_buf;
-	op->m_dst = comp_buf;
-	op->src.offset = 0;
-	op->src.length = rte_pktmbuf_pkt_len(uncomp_buf);
-	op->dst.offset = 0;
-	if (state == RTE_COMP_OP_STATELESS) {
-		//TODO: FULL or FINAL?
-		op->flush_flag = RTE_COMP_FLUSH_FINAL;
-	} else {
-		RTE_LOG(ERR, USER1,
-			"Stateful operations are not supported "
-			"in these tests yet\n");
-		goto exit;
+	for (i = 0; i < num_bufs; i++) {
+		ops[i]->m_src = uncomp_bufs[i];
+		ops[i]->m_dst = comp_bufs[i];
+		ops[i]->src.offset = 0;
+		ops[i]->src.length = rte_pktmbuf_pkt_len(uncomp_bufs[i]);
+		ops[i]->dst.offset = 0;
+		if (state == RTE_COMP_OP_STATELESS) {
+			//TODO: FULL or FINAL?
+			ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
+		} else {
+			RTE_LOG(ERR, USER1,
+				"Stateful operations are not supported "
+				"in these tests yet\n");
+			goto exit;
+		}
+		ops[i]->input_chksum = 0;
+		/*
+		 * Store original operation index in private data,
+		 * since ordering does not have to be maintained,
+		 * when dequeueing from compressdev, so a comparison
+		 * at the end of the test can be done.
+		 */
+		priv_data = (struct priv_op_data *) (ops[i] + 1);
+		priv_data->orig_idx = i;
 	}
-	op->input_chksum = 0;
 
 	/* Compress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
-		ret = compress_zlib(op,
-			(const struct rte_comp_xform *)&compress_xform,
-			DEFAULT_MEM_LEVEL);
-		if (ret < 0)
-			goto exit;
-
-		op_processed = op;
-	} else {
-		/* Create compress xform private data */
-		ret = rte_compressdev_private_xform_create(0,
-			(const struct rte_comp_xform *)compress_xform,
-			&priv_xform);
-		if (ret < 0) {
-			RTE_LOG(ERR, USER1,
-				"Compression private xform "
-				"could not be created\n");
-			goto exit;
+		for (i = 0; i < num_bufs; i++) {
+			ret = compress_zlib(ops[i],
+				(const struct rte_comp_xform *)compress_xform,
+					DEFAULT_MEM_LEVEL);
+			if (ret < 0)
+				goto exit;
+
+			ops_processed[i] = ops[i];
 		}
+	} else {
+		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
+			/* Create single compress private xform data */
+			ret = rte_compressdev_private_xform_create(0,
+				(const struct rte_comp_xform *)compress_xform,
+				&priv_xforms[0]);
+			if (ret < 0) {
+				RTE_LOG(ERR, USER1,
+					"Compression private xform "
+					"could not be created\n");
+				goto exit;
+			}
+			num_priv_xforms++;
+			/* Attach shareable private xform data to ops */
+			for (i = 0; i < num_bufs; i++)
+				ops[i]->private_xform = priv_xforms[0];
+		} else {
+			/* Create compress private xform data per op */
+			for (i = 0; i < num_bufs; i++) {
+				ret = rte_compressdev_private_xform_create(0,
+					compress_xform, &priv_xforms[i]);
+				if (ret < 0) {
+					RTE_LOG(ERR, USER1,
+						"Compression private xform "
+						"could not be created\n");
+					goto exit;
+				}
+				num_priv_xforms++;
+			}
 
-		/* Attach xform private data to operation */
-		op->private_xform = priv_xform;
+			/* Attach non shareable private xform data to ops */
+			for (i = 0; i < num_bufs; i++)
+				ops[i]->private_xform = priv_xforms[i];
+		}
 
 		/* Enqueue and dequeue all operations */
-		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
-		if (ret == 0) {
+		num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
+		if (num_enqd < num_bufs) {
 			RTE_LOG(ERR, USER1,
-				"The operation could not be enqueued\n");
+				"The operations could not be enqueued\n");
 			goto exit;
 		}
+
+		num_total_deqd = 0;
 		do {
 			/*
 			 * If retrying a dequeue call, wait for 10 ms to allow
@@ -454,121 +512,168 @@ test_deflate_comp_decomp(const char *test_buffer,
 				usleep(DEQUEUE_WAIT_TIME);
 			}
 			num_deqd = rte_compressdev_dequeue_burst(0, 0,
-					&op_processed, 1);
-
+					&ops_processed[num_total_deqd], num_bufs);
+			num_total_deqd += num_deqd;
 			deqd_retries++;
-		} while (num_deqd < 1);
+		} while (num_total_deqd < num_enqd);
 
 		deqd_retries = 0;
 
-		/* Free compress private xform */
-		rte_compressdev_private_xform_free(0, priv_xform);
-		priv_xform = NULL;
+		/* Free compress private xforms */
+		for (i = 0; i < num_priv_xforms; i++) {
+			rte_compressdev_private_xform_free(0, priv_xforms[i]);
+			priv_xforms[i] = NULL;
+		}
+		num_priv_xforms = 0;
 	}
 
 	enum rte_comp_huffman huffman_type =
 		compress_xform->compress.deflate.huffman;
-	RTE_LOG(DEBUG, USER1, "Buffer compressed from %u to %u bytes "
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		RTE_LOG(DEBUG, USER1, "Buffer %u compressed from %u to %u bytes "
 			"(level = %u, huffman = %s)\n",
-			op_processed->consumed, op_processed->produced,
+			buf_idx[priv_data->orig_idx],
+			ops_processed[i]->consumed, ops_processed[i]->produced,
 			compress_xform->compress.level,
 			huffman_type_strings[huffman_type]);
-	RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
-			(float)op_processed->produced /
-			op_processed->consumed * 100);
-	op = NULL;
+		RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
+			(float)ops_processed[i]->produced /
+			ops_processed[i]->consumed * 100);
+		ops[i] = NULL;
+	}
 
 	/*
-	 * Check operation status and free source mbuf (destination mbuf and
+	 * Check operation status and free source mbufs (destination mbuf and
 	 * compress operation information is needed for the decompression stage)
 	 */
-	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
-		RTE_LOG(ERR, USER1,
-			"Some operations were not successful\n");
-		goto exit;
+	for (i = 0; i < num_bufs; i++) {
+		if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
+			RTE_LOG(ERR, USER1,
+				"Some operations were not successful\n");
+			goto exit;
+		}
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		rte_pktmbuf_free(uncomp_bufs[priv_data->orig_idx]);
+		uncomp_bufs[priv_data->orig_idx] = NULL;
 	}
-	rte_pktmbuf_free(uncomp_buf);
-	uncomp_buf = NULL;
 
-	/* Allocate buffer for decompressed data */
-	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
-	if (uncomp_buf == NULL) {
+	/* Allocate buffers for decompressed data */
+	ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, uncomp_bufs, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Destination mbuf could not be allocated "
+			"Destination mbufs could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		rte_pktmbuf_append(uncomp_bufs[i],
+				strlen(test_bufs[priv_data->orig_idx]) + 1);
+	}
 
 	/* Build the decompression operations */
-	op = rte_comp_op_alloc(ts_params->op_pool);
-	if (op == NULL) {
+	ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Decompress operation could not be allocated "
+			"Decompress operations could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	/* Source buffer is the compressed data from the previous operation */
-	op->m_src = op_processed->m_dst;
-	op->m_dst = uncomp_buf;
-	op->src.offset = 0;
-	/*
-	 * Set the length of the compressed data to the
-	 * number of bytes that were produced in the previous stage
-	 */
-	op->src.length = op_processed->produced;
-	op->dst.offset = 0;
-	if (state == RTE_COMP_OP_STATELESS) {
-		//TODO: FULL or FINAL?
-		op->flush_flag = RTE_COMP_FLUSH_FINAL;
-	} else {
-		RTE_LOG(ERR, USER1,
-			"Stateful operations are not supported "
-			"in these tests yet\n");
-		goto exit;
+	/* Source buffer is the compressed data from the previous operations */
+	for (i = 0; i < num_bufs; i++) {
+		ops[i]->m_src = ops_processed[i]->m_dst;
+		ops[i]->m_dst = uncomp_bufs[i];
+		ops[i]->src.offset = 0;
+		/*
+		 * Set the length of the compressed data to the
+		 * number of bytes that were produced in the previous stage
+		 */
+		ops[i]->src.length = ops_processed[i]->produced;
+		ops[i]->dst.offset = 0;
+		if (state == RTE_COMP_OP_STATELESS) {
+			//TODO: FULL or FINAL?
+			ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
+		} else {
+			RTE_LOG(ERR, USER1,
+				"Stateful operations are not supported "
+				"in these tests yet\n");
+			goto exit;
+		}
+		ops[i]->input_chksum = 0;
+		/*
+		 * Copy private data from previous operations,
+		 * to keep the pointer to the original buffer
+		 */
+		memcpy(ops[i] + 1, ops_processed[i] + 1,
+				sizeof(struct priv_op_data));
 	}
-	op->input_chksum = 0;
 
 	/*
-	 * Free the previous compress operation,
+	 * Free the previous compress operations,
 	 * as it is not needed anymore
 	 */
-	rte_comp_op_free(op_processed);
-	op_processed = NULL;
+	for (i = 0; i < num_bufs; i++) {
+		rte_comp_op_free(ops_processed[i]);
+		ops_processed[i] = NULL;
+	}
 
 	/* Decompress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
-		ret = decompress_zlib(op,
-			(const struct rte_comp_xform *)&decompress_xform);
-		if (ret < 0)
-			goto exit;
+		for (i = 0; i < num_bufs; i++) {
+			ret = decompress_zlib(ops[i],
+				(const struct rte_comp_xform *)decompress_xform);
+			if (ret < 0)
+				goto exit;
 
-		op_processed = op;
-	} else {
-		num_deqd = 0;
-		/* Create decompress xform private data */
-		ret = rte_compressdev_private_xform_create(0,
-			(const struct rte_comp_xform *)decompress_xform,
-			&priv_xform);
-		if (ret < 0) {
-			RTE_LOG(ERR, USER1,
-				"Decompression private xform "
-				"could not be created\n");
-			goto exit;
+			ops_processed[i] = ops[i];
 		}
+	} else {
+		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
+			/* Create single decompress private xform data */
+			ret = rte_compressdev_private_xform_create(0,
+				(const struct rte_comp_xform *)decompress_xform,
+				&priv_xforms[0]);
+			if (ret < 0) {
+				RTE_LOG(ERR, USER1,
+					"Decompression private xform "
+					"could not be created\n");
+				goto exit;
+			}
+			num_priv_xforms++;
+			/* Attach shareable private xform data to ops */
+			for (i = 0; i < num_bufs; i++)
+				ops[i]->private_xform = priv_xforms[0];
+		} else {
+			/* Create decompress private xform data per op */
+			for (i = 0; i < num_bufs; i++) {
+				ret = rte_compressdev_private_xform_create(0,
+					decompress_xform, &priv_xforms[i]);
+				if (ret < 0) {
+					RTE_LOG(ERR, USER1,
+						"Deompression private xform "
+						"could not be created\n");
+					goto exit;
+				}
+				num_priv_xforms++;
+			}
 
-		/* Attach xform private data to operation */
-		op->private_xform = priv_xform;
+			/* Attach non shareable private xform data to ops */
+			for (i = 0; i < num_bufs; i++)
+				ops[i]->private_xform = priv_xforms[i];
+		}
 
 		/* Enqueue and dequeue all operations */
-		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
-		if (ret == 0) {
+		num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
+		if (num_enqd < num_bufs) {
 			RTE_LOG(ERR, USER1,
-				"The operation could not be enqueued\n");
+				"The operations could not be enqueued\n");
 			goto exit;
 		}
+
+		num_total_deqd = 0;
 		do {
 			/*
 			 * If retrying a dequeue call, wait for 10 ms to allow
@@ -588,47 +693,66 @@ test_deflate_comp_decomp(const char *test_buffer,
 				usleep(DEQUEUE_WAIT_TIME);
 			}
 			num_deqd = rte_compressdev_dequeue_burst(0, 0,
-					&op_processed, 1);
-
+					&ops_processed[num_total_deqd], num_bufs);
+			num_total_deqd += num_deqd;
 			deqd_retries++;
-		} while (num_deqd < 1);
+		} while (num_total_deqd < num_enqd);
+
+		deqd_retries = 0;
+	}
+
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		RTE_LOG(DEBUG, USER1, "Buffer %u decompressed from %u to %u bytes\n",
+			buf_idx[priv_data->orig_idx],
+			ops_processed[i]->consumed, ops_processed[i]->produced);
+		ops[i] = NULL;
 	}
 
-	RTE_LOG(DEBUG, USER1, "Buffer decompressed from %u to %u bytes\n",
-			op_processed->consumed, op_processed->produced);
-	op = NULL;
 	/*
 	 * Check operation status and free source mbuf (destination mbuf and
 	 * compress operation information is still needed)
 	 */
-	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
-		RTE_LOG(ERR, USER1,
-			"Some operations were not successful\n");
-		goto exit;
+	for (i = 0; i < num_bufs; i++) {
+		if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
+			RTE_LOG(ERR, USER1,
+				"Some operations were not successful\n");
+			goto exit;
+		}
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		rte_pktmbuf_free(comp_bufs[priv_data->orig_idx]);
+		comp_bufs[priv_data->orig_idx] = NULL;
 	}
-	rte_pktmbuf_free(comp_buf);
-	comp_buf = NULL;
 
 	/*
 	 * Compare the original stream with the decompressed stream
 	 * (in size and the data)
 	 */
-	if (compare_buffers(test_buffer, strlen(test_buffer) + 1,
-			rte_pktmbuf_mtod(op_processed->m_dst, const char *),
-			op_processed->produced) < 0)
-		goto exit;
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		const char *buf1 = test_bufs[priv_data->orig_idx];
+		const char *buf2 = rte_pktmbuf_mtod(ops_processed[i]->m_dst,
+				const char *);
+
+		if (compare_buffers(buf1, strlen(buf1) + 1,
+				buf2, ops_processed[i]->produced) < 0)
+			goto exit;
+	}
 
 	ret_status = 0;
 
 exit:
 	/* Free resources */
-	rte_pktmbuf_free(uncomp_buf);
-	rte_pktmbuf_free(comp_buf);
-	rte_comp_op_free(op);
-	rte_comp_op_free(op_processed);
-
-	if (priv_xform != NULL)
-		rte_compressdev_private_xform_free(0, priv_xform);
+	for (i = 0; i < num_bufs; i++) {
+		rte_pktmbuf_free(uncomp_bufs[i]);
+		rte_pktmbuf_free(comp_bufs[i]);
+		rte_comp_op_free(ops[i]);
+		rte_comp_op_free(ops_processed[i]);
+	}
+	for (i = 0; i < num_priv_xforms; i++) {
+		if (priv_xforms[i] != NULL)
+			rte_compressdev_private_xform_free(0, priv_xforms[i]);
+	}
 
 	return ret_status;
 }
@@ -649,7 +773,8 @@ test_compressdev_deflate_stateless_fixed(void)
 		test_buffer = compress_test_bufs[i];
 
 		/* Compress with compressdev, decompress with Zlib */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -657,7 +782,8 @@ test_compressdev_deflate_stateless_fixed(void)
 			return TEST_FAILED;
 
 		/* Compress with Zlib, decompress with compressdev */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -684,7 +810,8 @@ test_compressdev_deflate_stateless_dynamic(void)
 		test_buffer = compress_test_bufs[i];
 
 		/* Compress with compressdev, decompress with Zlib */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -692,7 +819,8 @@ test_compressdev_deflate_stateless_dynamic(void)
 			return TEST_FAILED;
 
 		/* Compress with Zlib, decompress with compressdev */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -703,6 +831,38 @@ test_compressdev_deflate_stateless_dynamic(void)
 	return TEST_SUCCESS;
 }
 
+static int
+test_compressdev_deflate_stateless_multi_op(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	uint16_t num_bufs = RTE_DIM(compress_test_bufs);
+	uint16_t buf_idx[num_bufs];
+	uint16_t i;
+
+	for (i = 0; i < num_bufs; i++)
+		buf_idx[i] = i;
+
+	/* Compress with compressdev, decompress with Zlib */
+	if (test_deflate_comp_decomp(compress_test_bufs, num_bufs,
+			buf_idx,
+			&ts_params->def_comp_xform,
+			&ts_params->def_decomp_xform,
+			RTE_COMP_OP_STATELESS,
+			ZLIB_DECOMPRESS) < 0)
+		return TEST_FAILED;
+
+	/* Compress with Zlib, decompress with compressdev */
+	if (test_deflate_comp_decomp(compress_test_bufs, num_bufs,
+			buf_idx,
+			&ts_params->def_comp_xform,
+			&ts_params->def_decomp_xform,
+			RTE_COMP_OP_STATELESS,
+			ZLIB_COMPRESS) < 0)
+		return TEST_FAILED;
+
+	return TEST_SUCCESS;
+}
+
 static struct unit_test_suite compressdev_testsuite  = {
 	.suite_name = "compressdev unit test suite",
 	.setup = testsuite_setup,
@@ -712,6 +872,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 			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_multi_op),
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v3 3/5] test/compress: add multi level test
  2018-04-27 14:14 ` [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests Pablo de Lara
  2018-04-27 14:14   ` [dpdk-dev] [PATCH v3 1/5] test/compress: add initial " Pablo de Lara
  2018-04-27 14:14   ` [dpdk-dev] [PATCH v3 2/5] test/compress: add multi op test Pablo de Lara
@ 2018-04-27 14:15   ` Pablo de Lara
  2018-04-27 14:15   ` [dpdk-dev] [PATCH v3 4/5] test/compress: add multi xform test Pablo de Lara
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-04-27 14:15 UTC (permalink / raw)
  To: dev; +Cc: fiona.trahe, shally.verma, ahmed.mansour, Ashish.Gupta, Pablo de Lara

Add test that checks if all compression levels
are supported and compress a buffer correctly.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 test/test/test_compressdev.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index 8e67faec2..bb026d74f 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -863,6 +863,37 @@ test_compressdev_deflate_stateless_multi_op(void)
 	return TEST_SUCCESS;
 }
 
+
+static int
+test_compressdev_deflate_stateless_multi_level(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	const char *test_buffer;
+	unsigned int level;
+	uint16_t i;
+	struct rte_comp_xform compress_xform;
+
+	memcpy(&compress_xform, &ts_params->def_comp_xform,
+			sizeof(struct rte_comp_xform));
+
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+		test_buffer = compress_test_bufs[i];
+		for (level = RTE_COMP_LEVEL_MIN; level <= RTE_COMP_LEVEL_MAX;
+				level++) {
+			compress_xform.compress.level = level;
+			/* Compress with compressdev, decompress with Zlib */
+			if (test_deflate_comp_decomp(&test_buffer, 1,
+					&i,
+					&compress_xform,
+					&ts_params->def_decomp_xform,
+					RTE_COMP_OP_STATELESS,
+					ZLIB_DECOMPRESS) < 0)
+				return TEST_FAILED;
+		}
+	}
+
+	return TEST_SUCCESS;
+}
 static struct unit_test_suite compressdev_testsuite  = {
 	.suite_name = "compressdev unit test suite",
 	.setup = testsuite_setup,
@@ -874,6 +905,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 			test_compressdev_deflate_stateless_dynamic),
 		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_CASES_END() /**< NULL terminate unit test array */
 	}
 };
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v3 4/5] test/compress: add multi xform test
  2018-04-27 14:14 ` [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests Pablo de Lara
                     ` (2 preceding siblings ...)
  2018-04-27 14:15   ` [dpdk-dev] [PATCH v3 3/5] test/compress: add multi level test Pablo de Lara
@ 2018-04-27 14:15   ` Pablo de Lara
  2018-05-02 13:49     ` Daly, Lee
  2018-04-27 14:15   ` [dpdk-dev] [PATCH v3 5/5] test/compress: add invalid configuration tests Pablo de Lara
  2018-05-01 13:00   ` [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests Daly, Lee
  5 siblings, 1 reply; 32+ messages in thread
From: Pablo de Lara @ 2018-04-27 14:15 UTC (permalink / raw)
  To: dev; +Cc: fiona.trahe, shally.verma, ahmed.mansour, Ashish.Gupta, Pablo de Lara

Add test that checks if multiple xforms can be
handled on a single enqueue call.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 test/test/test_compressdev.c | 257 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 191 insertions(+), 66 deletions(-)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index bb026d74f..0253d12ea 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -27,7 +27,7 @@
 #define COMPRESS_BUF_SIZE_RATIO 1.3
 #define NUM_MBUFS 16
 #define NUM_OPS 16
-#define NUM_MAX_XFORMS 1
+#define NUM_MAX_XFORMS 16
 #define NUM_MAX_INFLIGHT_OPS 128
 #define CACHE_SIZE 0
 
@@ -52,8 +52,8 @@ struct priv_op_data {
 struct comp_testsuite_params {
 	struct rte_mempool *mbuf_pool;
 	struct rte_mempool *op_pool;
-	struct rte_comp_xform def_comp_xform;
-	struct rte_comp_xform def_decomp_xform;
+	struct rte_comp_xform *def_comp_xform;
+	struct rte_comp_xform *def_decomp_xform;
 };
 
 static struct comp_testsuite_params testsuite_params = { 0 };
@@ -65,6 +65,8 @@ testsuite_teardown(void)
 
 	rte_mempool_free(ts_params->mbuf_pool);
 	rte_mempool_free(ts_params->op_pool);
+	rte_free(ts_params->def_comp_xform);
+	rte_free(ts_params->def_decomp_xform);
 }
 
 static int
@@ -108,19 +110,24 @@ testsuite_setup(void)
 		goto exit;
 	}
 
+	ts_params->def_comp_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
+	ts_params->def_decomp_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
+
 	/* Initializes default values for compress/decompress xforms */
-	ts_params->def_comp_xform.type = RTE_COMP_COMPRESS;
-	ts_params->def_comp_xform.compress.algo = RTE_COMP_ALGO_DEFLATE,
-	ts_params->def_comp_xform.compress.deflate.huffman =
+	ts_params->def_comp_xform->type = RTE_COMP_COMPRESS;
+	ts_params->def_comp_xform->compress.algo = RTE_COMP_ALGO_DEFLATE,
+	ts_params->def_comp_xform->compress.deflate.huffman =
 						RTE_COMP_HUFFMAN_DEFAULT;
-	ts_params->def_comp_xform.compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
-	ts_params->def_comp_xform.compress.chksum = RTE_COMP_CHECKSUM_NONE;
-	ts_params->def_comp_xform.compress.window_size = DEFAULT_WINDOW_SIZE;
+	ts_params->def_comp_xform->compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
+	ts_params->def_comp_xform->compress.chksum = RTE_COMP_CHECKSUM_NONE;
+	ts_params->def_comp_xform->compress.window_size = DEFAULT_WINDOW_SIZE;
 
-	ts_params->def_decomp_xform.type = RTE_COMP_DECOMPRESS;
-	ts_params->def_decomp_xform.decompress.algo = RTE_COMP_ALGO_DEFLATE,
-	ts_params->def_decomp_xform.decompress.chksum = RTE_COMP_CHECKSUM_NONE;
-	ts_params->def_decomp_xform.decompress.window_size = DEFAULT_WINDOW_SIZE;
+	ts_params->def_decomp_xform->type = RTE_COMP_DECOMPRESS;
+	ts_params->def_decomp_xform->decompress.algo = RTE_COMP_ALGO_DEFLATE,
+	ts_params->def_decomp_xform->decompress.chksum = RTE_COMP_CHECKSUM_NONE;
+	ts_params->def_decomp_xform->decompress.window_size = DEFAULT_WINDOW_SIZE;
 
 	return TEST_SUCCESS;
 
@@ -345,8 +352,9 @@ static int
 test_deflate_comp_decomp(const char * const test_bufs[],
 		unsigned int num_bufs,
 		uint16_t buf_idx[],
-		struct rte_comp_xform *compress_xform,
-		struct rte_comp_xform *decompress_xform,
+		struct rte_comp_xform *compress_xforms[],
+		struct rte_comp_xform *decompress_xforms[],
+		unsigned int num_xforms,
 		enum rte_comp_op_type state,
 		enum zlib_direction zlib_dir)
 {
@@ -441,8 +449,9 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 	/* Compress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
 		for (i = 0; i < num_bufs; i++) {
-			ret = compress_zlib(ops[i],
-				(const struct rte_comp_xform *)compress_xform,
+			const struct rte_comp_xform *compress_xform =
+				compress_xforms[i % num_xforms];
+			ret = compress_zlib(ops[i], compress_xform,
 					DEFAULT_MEM_LEVEL);
 			if (ret < 0)
 				goto exit;
@@ -450,11 +459,11 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 			ops_processed[i] = ops[i];
 		}
 	} else {
-		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
-			/* Create single compress private xform data */
+		/* Create compress private xform data */
+		for (i = 0; i < num_xforms; i++) {
 			ret = rte_compressdev_private_xform_create(0,
-				(const struct rte_comp_xform *)compress_xform,
-				&priv_xforms[0]);
+				(const struct rte_comp_xform *)compress_xforms[i],
+				&priv_xforms[i]);
 			if (ret < 0) {
 				RTE_LOG(ERR, USER1,
 					"Compression private xform "
@@ -462,14 +471,18 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 				goto exit;
 			}
 			num_priv_xforms++;
+		}
+
+		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
 			/* Attach shareable private xform data to ops */
 			for (i = 0; i < num_bufs; i++)
-				ops[i]->private_xform = priv_xforms[0];
+				ops[i]->private_xform = priv_xforms[i % num_xforms];
 		} else {
-			/* Create compress private xform data per op */
-			for (i = 0; i < num_bufs; i++) {
+			/* Create rest of the private xforms for the other ops */
+			for (i = num_xforms; i < num_bufs; i++) {
 				ret = rte_compressdev_private_xform_create(0,
-					compress_xform, &priv_xforms[i]);
+					compress_xforms[i % num_xforms],
+					&priv_xforms[i]);
 				if (ret < 0) {
 					RTE_LOG(ERR, USER1,
 						"Compression private xform "
@@ -527,15 +540,18 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 		num_priv_xforms = 0;
 	}
 
-	enum rte_comp_huffman huffman_type =
-		compress_xform->compress.deflate.huffman;
 	for (i = 0; i < num_bufs; i++) {
 		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		uint16_t xform_idx = priv_data->orig_idx % num_xforms;
+		const struct rte_comp_compress_xform *compress_xform =
+				&compress_xforms[xform_idx]->compress;
+		enum rte_comp_huffman huffman_type =
+			compress_xform->deflate.huffman;
 		RTE_LOG(DEBUG, USER1, "Buffer %u compressed from %u to %u bytes "
-			"(level = %u, huffman = %s)\n",
+			"(level = %d, huffman = %s)\n",
 			buf_idx[priv_data->orig_idx],
 			ops_processed[i]->consumed, ops_processed[i]->produced,
-			compress_xform->compress.level,
+			compress_xform->level,
 			huffman_type_strings[huffman_type]);
 		RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
 			(float)ops_processed[i]->produced /
@@ -623,19 +639,23 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 	/* Decompress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
 		for (i = 0; i < num_bufs; i++) {
-			ret = decompress_zlib(ops[i],
-				(const struct rte_comp_xform *)decompress_xform);
+			priv_data = (struct priv_op_data *)(ops[i] + 1);
+			uint16_t xform_idx = priv_data->orig_idx % num_xforms;
+			const struct rte_comp_xform *decompress_xform =
+				decompress_xforms[xform_idx];
+
+			ret = decompress_zlib(ops[i], decompress_xform);
 			if (ret < 0)
 				goto exit;
 
 			ops_processed[i] = ops[i];
 		}
 	} else {
-		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
-			/* Create single decompress private xform data */
+		/* Create decompress private xform data */
+		for (i = 0; i < num_xforms; i++) {
 			ret = rte_compressdev_private_xform_create(0,
-				(const struct rte_comp_xform *)decompress_xform,
-				&priv_xforms[0]);
+				(const struct rte_comp_xform *)decompress_xforms[i],
+				&priv_xforms[i]);
 			if (ret < 0) {
 				RTE_LOG(ERR, USER1,
 					"Decompression private xform "
@@ -643,17 +663,25 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 				goto exit;
 			}
 			num_priv_xforms++;
+		}
+
+		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
 			/* Attach shareable private xform data to ops */
-			for (i = 0; i < num_bufs; i++)
-				ops[i]->private_xform = priv_xforms[0];
-		} else {
-			/* Create decompress private xform data per op */
 			for (i = 0; i < num_bufs; i++) {
+				priv_data = (struct priv_op_data *)(ops[i] + 1);
+				uint16_t xform_idx = priv_data->orig_idx %
+								num_xforms;
+				ops[i]->private_xform = priv_xforms[xform_idx];
+			}
+		} else {
+			/* Create rest of the private xforms for the other ops */
+			for (i = num_xforms; i < num_bufs; i++) {
 				ret = rte_compressdev_private_xform_create(0,
-					decompress_xform, &priv_xforms[i]);
+					decompress_xforms[i % num_xforms],
+					&priv_xforms[i]);
 				if (ret < 0) {
 					RTE_LOG(ERR, USER1,
-						"Deompression private xform "
+						"Decompression private xform "
 						"could not be created\n");
 					goto exit;
 				}
@@ -661,8 +689,11 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 			}
 
 			/* Attach non shareable private xform data to ops */
-			for (i = 0; i < num_bufs; i++)
-				ops[i]->private_xform = priv_xforms[i];
+			for (i = 0; i < num_bufs; i++) {
+				priv_data = (struct priv_op_data *) (ops[i] + 1);
+				uint16_t xform_idx = priv_data->orig_idx;
+				ops[i]->private_xform = priv_xforms[xform_idx];
+			}
 		}
 
 		/* Enqueue and dequeue all operations */
@@ -763,11 +794,13 @@ test_compressdev_deflate_stateless_fixed(void)
 	struct comp_testsuite_params *ts_params = &testsuite_params;
 	const char *test_buffer;
 	uint16_t i;
-	struct rte_comp_xform compress_xform;
+	int ret;
+	struct rte_comp_xform *compress_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
 
-	memcpy(&compress_xform, &ts_params->def_comp_xform,
+	memcpy(compress_xform, ts_params->def_comp_xform,
 			sizeof(struct rte_comp_xform));
-	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
+	compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
 		test_buffer = compress_test_bufs[i];
@@ -777,21 +810,31 @@ test_compressdev_deflate_stateless_fixed(void)
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_DECOMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_DECOMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 
 		/* Compress with Zlib, decompress with compressdev */
 		if (test_deflate_comp_decomp(&test_buffer, 1,
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_COMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_COMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 	}
 
-	return TEST_SUCCESS;
+	ret = TEST_SUCCESS;
+
+exit:
+	rte_free(compress_xform);
+	return ret;
 }
 
 static int
@@ -800,11 +843,13 @@ test_compressdev_deflate_stateless_dynamic(void)
 	struct comp_testsuite_params *ts_params = &testsuite_params;
 	const char *test_buffer;
 	uint16_t i;
-	struct rte_comp_xform compress_xform;
+	int ret;
+	struct rte_comp_xform *compress_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
 
-	memcpy(&compress_xform, &ts_params->def_comp_xform,
+	memcpy(compress_xform, ts_params->def_comp_xform,
 			sizeof(struct rte_comp_xform));
-	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
+	compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
 		test_buffer = compress_test_bufs[i];
@@ -814,21 +859,31 @@ test_compressdev_deflate_stateless_dynamic(void)
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_DECOMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_DECOMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 
 		/* Compress with Zlib, decompress with compressdev */
 		if (test_deflate_comp_decomp(&test_buffer, 1,
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_COMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_COMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 	}
 
-	return TEST_SUCCESS;
+	ret = TEST_SUCCESS;
+
+exit:
+	rte_free(compress_xform);
+	return ret;
 }
 
 static int
@@ -847,6 +902,7 @@ test_compressdev_deflate_stateless_multi_op(void)
 			buf_idx,
 			&ts_params->def_comp_xform,
 			&ts_params->def_decomp_xform,
+			1,
 			RTE_COMP_OP_STATELESS,
 			ZLIB_DECOMPRESS) < 0)
 		return TEST_FAILED;
@@ -856,6 +912,7 @@ test_compressdev_deflate_stateless_multi_op(void)
 			buf_idx,
 			&ts_params->def_comp_xform,
 			&ts_params->def_decomp_xform,
+			1,
 			RTE_COMP_OP_STATELESS,
 			ZLIB_COMPRESS) < 0)
 		return TEST_FAILED;
@@ -863,7 +920,6 @@ test_compressdev_deflate_stateless_multi_op(void)
 	return TEST_SUCCESS;
 }
 
-
 static int
 test_compressdev_deflate_stateless_multi_level(void)
 {
@@ -871,29 +927,96 @@ test_compressdev_deflate_stateless_multi_level(void)
 	const char *test_buffer;
 	unsigned int level;
 	uint16_t i;
-	struct rte_comp_xform compress_xform;
+	int ret;
+	struct rte_comp_xform *compress_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
 
-	memcpy(&compress_xform, &ts_params->def_comp_xform,
+	memcpy(compress_xform, ts_params->def_comp_xform,
 			sizeof(struct rte_comp_xform));
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
 		test_buffer = compress_test_bufs[i];
 		for (level = RTE_COMP_LEVEL_MIN; level <= RTE_COMP_LEVEL_MAX;
 				level++) {
-			compress_xform.compress.level = level;
+			compress_xform->compress.level = level;
 			/* Compress with compressdev, decompress with Zlib */
 			if (test_deflate_comp_decomp(&test_buffer, 1,
 					&i,
 					&compress_xform,
 					&ts_params->def_decomp_xform,
+					1,
 					RTE_COMP_OP_STATELESS,
-					ZLIB_DECOMPRESS) < 0)
-				return TEST_FAILED;
+					ZLIB_DECOMPRESS) < 0) {
+				ret = TEST_FAILED;
+				goto exit;
+			}
 		}
 	}
 
-	return TEST_SUCCESS;
+	ret = TEST_SUCCESS;
+
+exit:
+	rte_free(compress_xform);
+	return ret;
 }
+
+#define NUM_XFORMS 3
+static int
+test_compressdev_deflate_stateless_multi_xform(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	uint16_t num_bufs = NUM_XFORMS;
+	struct rte_comp_xform *compress_xforms[NUM_XFORMS] = {NULL};
+	struct rte_comp_xform *decompress_xforms[NUM_XFORMS] = {NULL};
+	const char *test_buffers[NUM_XFORMS];
+	uint16_t i;
+	unsigned int level = RTE_COMP_LEVEL_MIN;
+	uint16_t buf_idx[num_bufs];
+
+	int ret;
+
+	/* Create multiple xforms with various levels */
+	for (i = 0; i < NUM_XFORMS; i++) {
+		compress_xforms[i] = rte_malloc(NULL,
+				sizeof(struct rte_comp_xform), 0);
+		memcpy(compress_xforms[i], ts_params->def_comp_xform,
+				sizeof(struct rte_comp_xform));
+		compress_xforms[i]->compress.level = level;
+		level++;
+
+		decompress_xforms[i] = rte_malloc(NULL,
+				sizeof(struct rte_comp_xform), 0);
+		memcpy(decompress_xforms[i], ts_params->def_decomp_xform,
+				sizeof(struct rte_comp_xform));
+	}
+
+	for (i = 0; i < NUM_XFORMS; i++) {
+		buf_idx[i] = 0;
+		/* Use the same buffer in all sessions */
+		test_buffers[i] = compress_test_bufs[0];
+	}
+	/* Compress with compressdev, decompress with Zlib */
+	if (test_deflate_comp_decomp(test_buffers, num_bufs,
+			buf_idx,
+			compress_xforms,
+			decompress_xforms,
+			NUM_XFORMS,
+			RTE_COMP_OP_STATELESS,
+			ZLIB_DECOMPRESS) < 0) {
+		ret = TEST_FAILED;
+		goto exit;
+	}
+
+	ret = TEST_SUCCESS;
+exit:
+	for (i = 0; i < NUM_XFORMS; i++) {
+		rte_free(compress_xforms[i]);
+		rte_free(decompress_xforms[i]);
+	}
+
+	return ret;
+}
+
 static struct unit_test_suite compressdev_testsuite  = {
 	.suite_name = "compressdev unit test suite",
 	.setup = testsuite_setup,
@@ -907,6 +1030,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 			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_CASES_END() /**< NULL terminate unit test array */
 	}
 };
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v3 5/5] test/compress: add invalid configuration tests
  2018-04-27 14:14 ` [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests Pablo de Lara
                     ` (3 preceding siblings ...)
  2018-04-27 14:15   ` [dpdk-dev] [PATCH v3 4/5] test/compress: add multi xform test Pablo de Lara
@ 2018-04-27 14:15   ` Pablo de Lara
  2018-05-01 13:00   ` [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests Daly, Lee
  5 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-04-27 14:15 UTC (permalink / raw)
  To: dev; +Cc: fiona.trahe, shally.verma, ahmed.mansour, Ashish.Gupta, Pablo de Lara

Add tests that check if device configuration
is not successful when providing invalid parameters.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 test/test/test_compressdev.c | 49 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index 0253d12ea..bb683b998 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -175,6 +175,51 @@ generic_ut_teardown(void)
 		RTE_LOG(ERR, USER1, "Device could not be closed\n");
 }
 
+static int
+test_compressdev_invalid_configuration(void)
+{
+	struct rte_compressdev_config invalid_config;
+	struct rte_compressdev_config valid_config = {
+		.socket_id = rte_socket_id(),
+		.nb_queue_pairs = 1,
+		.max_nb_priv_xforms = NUM_MAX_XFORMS,
+		.max_nb_streams = 0
+	};
+	struct rte_compressdev_info dev_info;
+
+	/* Invalid configuration with 0 queue pairs */
+	memcpy(&invalid_config, &valid_config,
+			sizeof(struct rte_compressdev_config));
+	invalid_config.nb_queue_pairs = 0;
+
+	TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
+			"Device configuration was successful "
+			"with no queue pairs (invalid)\n");
+
+	/*
+	 * Invalid configuration with too many queue pairs
+	 * (if there is an actual maximum number of queue pairs)
+	 */
+	rte_compressdev_info_get(0, &dev_info);
+	if (dev_info.max_nb_queue_pairs != 0) {
+		memcpy(&invalid_config, &valid_config,
+			sizeof(struct rte_compressdev_config));
+		invalid_config.nb_queue_pairs = dev_info.max_nb_queue_pairs + 1;
+
+		TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
+				"Device configuration was successful "
+				"with too many queue pairs (invalid)\n");
+	}
+
+	/* Invalid queue pair setup, with no number of queue pairs set */
+	TEST_ASSERT_FAIL(rte_compressdev_queue_pair_setup(0, 0,
+				NUM_MAX_INFLIGHT_OPS, rte_socket_id()),
+			"Queue pair setup was successful "
+			"with no queue pairs set (invalid)\n");
+
+	return TEST_SUCCESS;
+}
+
 static int
 compare_buffers(const char *buffer1, uint32_t buffer1_len,
 		const char *buffer2, uint32_t buffer2_len)
@@ -690,7 +735,7 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 
 			/* Attach non shareable private xform data to ops */
 			for (i = 0; i < num_bufs; i++) {
-				priv_data = (struct priv_op_data *) (ops[i] + 1);
+				priv_data = (struct priv_op_data *)(ops[i] + 1);
 				uint16_t xform_idx = priv_data->orig_idx;
 				ops[i]->private_xform = priv_xforms[xform_idx];
 			}
@@ -1022,6 +1067,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 	.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,
-- 
2.14.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests
  2018-04-27 14:14 ` [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests Pablo de Lara
                     ` (4 preceding siblings ...)
  2018-04-27 14:15   ` [dpdk-dev] [PATCH v3 5/5] test/compress: add invalid configuration tests Pablo de Lara
@ 2018-05-01 13:00   ` Daly, Lee
  5 siblings, 0 replies; 32+ messages in thread
From: Daly, Lee @ 2018-05-01 13:00 UTC (permalink / raw)
  To: De Lara Guarch, Pablo, dev
  Cc: Trahe, Fiona, shally.verma, ahmed.mansour, Ashish.Gupta,
	De Lara Guarch, Pablo


<...> 
> Added initial tests for Compressdev library.
> The tests are performed compressing a test buffer (or multiple test buffers)
> with compressdev or Zlib, and decompressing it/them with the other library
> (if compression is done with compressdev, decompression is done with Zlib,
> and viceversa).
> 
> Tests added so far are based on the deflate algorithm,
> including:
> - Fixed huffman on single buffer
> - Dynamic huffman on single buffer
> - Multi compression level test on single buffer
> - Multi buffer
> - Multi xform using the same buffer
> 
> Due to a dependency on Zlib, the test is not enabled by default.
> Once the library is installed, the configuration option
> CONFIG_RTE_COMPRESSDEV_TEST must be set to Y.
> However, if building with Meson, the test will be built automatically, if Zlib is
> installed.
> 
> The test requires a compressdev PMD to be initialized, when running the test
> app. For example:
> 
> ./build/app/test --vdev="compress_X"
> 
> RTE>>compressdev_autotest
> 
> This patchset depends on the Compressdev API patchset:
> http://dpdk.org/ml/archives/dev/2018-April/099580.html
> ("[PATCH v6 00/14] Implement compression API")
> 
<...>
Series-acked-by: Lee Daly <lee.daly@intel.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [dpdk-dev] [PATCH v3 1/5] test/compress: add initial unit tests
  2018-04-27 14:14   ` [dpdk-dev] [PATCH v3 1/5] test/compress: add initial " Pablo de Lara
@ 2018-05-02 13:44     ` Daly, Lee
  2018-05-04  8:49       ` De Lara Guarch, Pablo
  0 siblings, 1 reply; 32+ messages in thread
From: Daly, Lee @ 2018-05-02 13:44 UTC (permalink / raw)
  To: De Lara Guarch, Pablo, dev
  Cc: Trahe, Fiona, shally.verma, ahmed.mansour, Ashish.Gupta,
	De Lara Guarch, Pablo, Ashish Gupta, Shally Verma



> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Pablo de Lara
> Sent: Friday, April 27, 2018 3:15 PM
> To: dev@dpdk.org
> Cc: Trahe, Fiona <fiona.trahe@intel.com>; shally.verma@cavium.com;
> ahmed.mansour@nxp.com; Ashish.Gupta@cavium.com; De Lara Guarch,
> Pablo <pablo.de.lara.guarch@intel.com>; Ashish Gupta
> <ashish.gupta@caviumnetworks.com>; Shally Verma
> <shally.verma@caviumnetworks.com>
> Subject: [dpdk-dev] [PATCH v3 1/5] test/compress: add initial unit tests
> 
> This commit introduces the initial tests for compressdev, performing basic
> compression and decompression operations of sample test buffers, using
> the Zlib library in one direction and compressdev in another direction, to
> make sure that the library is compatible with Zlib.
> 
> Due to the use of Zlib API, the test is disabled by default, to avoid adding a
> new dependency on DPDK.
> 
> Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
> Signed-off-by: Ashish Gupta <ashish.gupta@caviumnetworks.com>
> Signed-off-by: Shally Verma <shally.verma@caviumnetworks.com>


<...>

> +static int
> +testsuite_setup(void)
> +{
> +	struct comp_testsuite_params *ts_params = &testsuite_params;
> +	unsigned int i;
> +
> +	if (rte_compressdev_count() == 0) {
> +		RTE_LOG(ERR, USER1, "Need at least one compress
> device\n");
> +		return -EINVAL;
> +	}
> +
> +	uint32_t max_buf_size = 0;
> +	for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
> +		max_buf_size = RTE_MAX(max_buf_size,
> +				strlen(compress_test_bufs[i]) + 1);
> +
> +	max_buf_size *= COMPRESS_BUF_SIZE_RATIO;
> +	/*
> +	 * Buffers to be used in compression and decompression.
> +	 * Since decompressed data might be larger than
> +	 * compressed data (due to block header),
> +	 * buffers should be big enough for both cases.
> +	 */
> +	ts_params->mbuf_pool = rte_pktmbuf_pool_create("mbuf_pool",
> +			NUM_MBUFS,
> +			CACHE_SIZE, 0,
> +			max_buf_size + RTE_PKTMBUF_HEADROOM,
> +			rte_socket_id());
> +	if (ts_params->mbuf_pool == NULL) {
> +		RTE_LOG(ERR, USER1, "Large mbuf pool could not be
> created\n");
> +		goto exit;

[Lee]At this point there is nothing to be freed yet, therefore TEST_FAILED can be returned here without testsuite_teardown();

> +	}
> +
> +	ts_params->op_pool = rte_comp_op_pool_create("op_pool",
> NUM_OPS,
> +						0, 0, rte_socket_id());
> +	if (ts_params->op_pool == NULL) {
> +		RTE_LOG(ERR, USER1, "Operation pool could not be
> created\n");
> +		goto exit;

[Lee]Similar point here, wasted cycles on freeing memory which has not be allocated yet.
May not be a major issue since this is only done on setup.

> +	}
> +
> +	/* Initializes default values for compress/decompress xforms */
> +	ts_params->def_comp_xform.type = RTE_COMP_COMPRESS;
> +	ts_params->def_comp_xform.compress.algo =
> RTE_COMP_ALGO_DEFLATE,
> +	ts_params->def_comp_xform.compress.deflate.huffman =
> +
> 	RTE_COMP_HUFFMAN_DEFAULT;
> +	ts_params->def_comp_xform.compress.level =
> RTE_COMP_LEVEL_PMD_DEFAULT;
> +	ts_params->def_comp_xform.compress.chksum =
> RTE_COMP_CHECKSUM_NONE;
> +	ts_params->def_comp_xform.compress.window_size =
> DEFAULT_WINDOW_SIZE;
> +
> +	ts_params->def_decomp_xform.type = RTE_COMP_DECOMPRESS;
> +	ts_params->def_decomp_xform.decompress.algo =
> RTE_COMP_ALGO_DEFLATE,
> +	ts_params->def_decomp_xform.decompress.chksum =
> RTE_COMP_CHECKSUM_NONE;
> +	ts_params->def_decomp_xform.decompress.window_size =
> +DEFAULT_WINDOW_SIZE;
> +
> +	return TEST_SUCCESS;
> +
> +exit:
> +	testsuite_teardown();
> +
> +	return TEST_FAILED;
> +}
> +
<...>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [dpdk-dev] [PATCH v3 4/5] test/compress: add multi xform test
  2018-04-27 14:15   ` [dpdk-dev] [PATCH v3 4/5] test/compress: add multi xform test Pablo de Lara
@ 2018-05-02 13:49     ` Daly, Lee
  0 siblings, 0 replies; 32+ messages in thread
From: Daly, Lee @ 2018-05-02 13:49 UTC (permalink / raw)
  To: De Lara Guarch, Pablo, dev
  Cc: Trahe, Fiona, shally.verma, ahmed.mansour, Ashish.Gupta,
	De Lara Guarch, Pablo

Hi Pablo,
Feedback for a small change below.

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Pablo de Lara
> Sent: Friday, April 27, 2018 3:15 PM
> To: dev@dpdk.org
> Cc: Trahe, Fiona <fiona.trahe@intel.com>; shally.verma@cavium.com;
> ahmed.mansour@nxp.com; Ashish.Gupta@cavium.com; De Lara Guarch,
> Pablo <pablo.de.lara.guarch@intel.com>
> Subject: [dpdk-dev] [PATCH v3 4/5] test/compress: add multi xform test
> 
> Add test that checks if multiple xforms can be handled on a single enqueue
> call.
> 
> Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
> ---
>  test/test/test_compressdev.c | 257
> ++++++++++++++++++++++++++++++++-----------
>  1 file changed, 191 insertions(+), 66 deletions(-)
> 
> diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
> index bb026d74f..0253d12ea 100644
> --- a/test/test/test_compressdev.c
> +++ b/test/test/test_compressdev.c
> @@ -27,7 +27,7 @@
>  #define COMPRESS_BUF_SIZE_RATIO 1.3
>  #define NUM_MBUFS 16
>  #define NUM_OPS 16
> -#define NUM_MAX_XFORMS 1
> +#define NUM_MAX_XFORMS 16
>  #define NUM_MAX_INFLIGHT_OPS 128
>  #define CACHE_SIZE 0
> 
> @@ -52,8 +52,8 @@ struct priv_op_data {
>  struct comp_testsuite_params {
>  	struct rte_mempool *mbuf_pool;
>  	struct rte_mempool *op_pool;
> -	struct rte_comp_xform def_comp_xform;
> -	struct rte_comp_xform def_decomp_xform;
> +	struct rte_comp_xform *def_comp_xform;
> +	struct rte_comp_xform *def_decomp_xform;
>  };
> 
>  static struct comp_testsuite_params testsuite_params = { 0 }; @@ -65,6
> +65,8 @@ testsuite_teardown(void)
> 
>  	rte_mempool_free(ts_params->mbuf_pool);
>  	rte_mempool_free(ts_params->op_pool);
> +	rte_free(ts_params->def_comp_xform);
> +	rte_free(ts_params->def_decomp_xform);
>  }
> 
>  static int
> @@ -108,19 +110,24 @@ testsuite_setup(void)
>  		goto exit;
>  	}
> 
> +	ts_params->def_comp_xform =
> +			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
> +	ts_params->def_decomp_xform =
> +			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
> +


Perhaps add a check to ensure this memory has been successfully allocated, as you did you with the mempool malloc above this, in PATCH 1/5.

<...>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [dpdk-dev] [PATCH v3 1/5] test/compress: add initial unit tests
  2018-05-02 13:44     ` Daly, Lee
@ 2018-05-04  8:49       ` De Lara Guarch, Pablo
  0 siblings, 0 replies; 32+ messages in thread
From: De Lara Guarch, Pablo @ 2018-05-04  8:49 UTC (permalink / raw)
  To: Daly, Lee, dev
  Cc: Trahe, Fiona, shally.verma, ahmed.mansour, Ashish.Gupta,
	Ashish Gupta, Shally Verma

Hi Lee,

> -----Original Message-----
> From: Daly, Lee
> Sent: Wednesday, May 2, 2018 2:44 PM
> To: De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>; dev@dpdk.org
> Cc: Trahe, Fiona <fiona.trahe@intel.com>; shally.verma@cavium.com;
> ahmed.mansour@nxp.com; Ashish.Gupta@cavium.com; De Lara Guarch, Pablo
> <pablo.de.lara.guarch@intel.com>; Ashish Gupta
> <ashish.gupta@caviumnetworks.com>; Shally Verma
> <shally.verma@caviumnetworks.com>
> Subject: RE: [dpdk-dev] [PATCH v3 1/5] test/compress: add initial unit tests
> 
> 
> 
> > -----Original Message-----
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Pablo de Lara
> > Sent: Friday, April 27, 2018 3:15 PM
> > To: dev@dpdk.org
> > Cc: Trahe, Fiona <fiona.trahe@intel.com>; shally.verma@cavium.com;
> > ahmed.mansour@nxp.com; Ashish.Gupta@cavium.com; De Lara Guarch,
> Pablo
> > <pablo.de.lara.guarch@intel.com>; Ashish Gupta
> > <ashish.gupta@caviumnetworks.com>; Shally Verma
> > <shally.verma@caviumnetworks.com>
> > Subject: [dpdk-dev] [PATCH v3 1/5] test/compress: add initial unit
> > tests
> >
> > This commit introduces the initial tests for compressdev, performing
> > basic compression and decompression operations of sample test buffers,
> > using the Zlib library in one direction and compressdev in another
> > direction, to make sure that the library is compatible with Zlib.
> >
> > Due to the use of Zlib API, the test is disabled by default, to avoid
> > adding a new dependency on DPDK.
> >
> > Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
> > Signed-off-by: Ashish Gupta <ashish.gupta@caviumnetworks.com>
> > Signed-off-by: Shally Verma <shally.verma@caviumnetworks.com>
> 
> 
> <...>
> 
> > +static int
> > +testsuite_setup(void)
> > +{
> > +	struct comp_testsuite_params *ts_params = &testsuite_params;
> > +	unsigned int i;
> > +
> > +	if (rte_compressdev_count() == 0) {
> > +		RTE_LOG(ERR, USER1, "Need at least one compress
> > device\n");
> > +		return -EINVAL;
> > +	}
> > +
> > +	uint32_t max_buf_size = 0;
> > +	for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
> > +		max_buf_size = RTE_MAX(max_buf_size,
> > +				strlen(compress_test_bufs[i]) + 1);
> > +
> > +	max_buf_size *= COMPRESS_BUF_SIZE_RATIO;
> > +	/*
> > +	 * Buffers to be used in compression and decompression.
> > +	 * Since decompressed data might be larger than
> > +	 * compressed data (due to block header),
> > +	 * buffers should be big enough for both cases.
> > +	 */
> > +	ts_params->mbuf_pool = rte_pktmbuf_pool_create("mbuf_pool",
> > +			NUM_MBUFS,
> > +			CACHE_SIZE, 0,
> > +			max_buf_size + RTE_PKTMBUF_HEADROOM,
> > +			rte_socket_id());
> > +	if (ts_params->mbuf_pool == NULL) {
> > +		RTE_LOG(ERR, USER1, "Large mbuf pool could not be
> > created\n");
> > +		goto exit;
> 
> [Lee]At this point there is nothing to be freed yet, therefore TEST_FAILED can be
> returned here without testsuite_teardown();

Right, will change.

> 
> > +	}
> > +
> > +	ts_params->op_pool = rte_comp_op_pool_create("op_pool",
> > NUM_OPS,
> > +						0, 0, rte_socket_id());
> > +	if (ts_params->op_pool == NULL) {
> > +		RTE_LOG(ERR, USER1, "Operation pool could not be
> > created\n");
> > +		goto exit;
> 
> [Lee]Similar point here, wasted cycles on freeing memory which has not be
> allocated yet.
> May not be a major issue since this is only done on setup.

Well, at this point mbuf_pool has been created, so we need to free that.

> 
> > +	}
> > +
> > +	/* Initializes default values for compress/decompress xforms */
> > +	ts_params->def_comp_xform.type = RTE_COMP_COMPRESS;
> > +	ts_params->def_comp_xform.compress.algo =
> > RTE_COMP_ALGO_DEFLATE,
> > +	ts_params->def_comp_xform.compress.deflate.huffman =
> > +
> > 	RTE_COMP_HUFFMAN_DEFAULT;
> > +	ts_params->def_comp_xform.compress.level =
> > RTE_COMP_LEVEL_PMD_DEFAULT;
> > +	ts_params->def_comp_xform.compress.chksum =
> > RTE_COMP_CHECKSUM_NONE;
> > +	ts_params->def_comp_xform.compress.window_size =
> > DEFAULT_WINDOW_SIZE;
> > +
> > +	ts_params->def_decomp_xform.type = RTE_COMP_DECOMPRESS;
> > +	ts_params->def_decomp_xform.decompress.algo =
> > RTE_COMP_ALGO_DEFLATE,
> > +	ts_params->def_decomp_xform.decompress.chksum =
> > RTE_COMP_CHECKSUM_NONE;
> > +	ts_params->def_decomp_xform.decompress.window_size =
> > +DEFAULT_WINDOW_SIZE;
> > +
> > +	return TEST_SUCCESS;
> > +
> > +exit:
> > +	testsuite_teardown();
> > +
> > +	return TEST_FAILED;
> > +}
> > +
> <...>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v4 0/5] Initial compressdev unit tests
  2018-02-28 14:00 [dpdk-dev] [PATCH 0/5] Initial compressdev unit tests Pablo de Lara
                   ` (6 preceding siblings ...)
  2018-04-27 14:14 ` [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests Pablo de Lara
@ 2018-05-04 10:22 ` Pablo de Lara
  2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 1/5] test/compress: add initial " Pablo de Lara
                     ` (6 more replies)
  7 siblings, 7 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-05-04 10:22 UTC (permalink / raw)
  To: dev
  Cc: fiona.trahe, lee.daly, shally.verma, ahmed.mansour, Ashish.Gupta,
	Pablo de Lara

Added initial tests for Compressdev library.
The tests are performed compressing a test buffer (or multiple test buffers) with
compressdev or Zlib, and decompressing it/them with the other library (if compression is
done with compressdev, decompression is done with Zlib, and viceversa).

Tests added so far are based on the deflate algorithm,
including:
- Fixed huffman on single buffer
- Dynamic huffman on single buffer
- Multi compression level test on single buffer
- Multi buffer
- Multi xform using the same buffer

Due to a dependency on Zlib, the test is not enabled by default.
Once the library is installed, the configuration option CONFIG_RTE_COMPRESSDEV_TEST must be set to Y.
However, if building with Meson, the test will be built automatically, if Zlib is installed.

The test requires a compressdev PMD to be initialized, when running the test app. For example:

./build/app/test --vdev="compress_X"

RTE>>compressdev_autotest

This patchset depends on the Compressdev API patchset:
http://dpdk.org/ml/archives/dev/2018-April/099580.html
("[PATCH v6 00/14] Implement compression API")

Changes in v4:
- Free memory when malloc fails

Changes in v3:
- Remove next pointer in xform setting
- Remove unneeded DIV_CEIL macro
- Add rte_compressdev_close() call after finishing test cases

Changes in v2:
- Add meson build
- Add invalid configuration tests
- Use new Compressdev API:
  * Substitute session with priv xform
  * Check if priv xform is shareable and create one per operation if not

Pablo de Lara (5):
  test/compress: add initial unit tests
  test/compress: add multi op test
  test/compress: add multi level test
  test/compress: add multi xform test
  test/compress: add invalid configuration tests

 config/common_base                       |    5 +
 test/test/Makefile                       |    9 +
 test/test/meson.build                    |    8 +
 test/test/test_compressdev.c             | 1137 ++++++++++++++++++++++
 test/test/test_compressdev_test_buffer.h |  295 ++++++
 5 files changed, 1454 insertions(+)
 create mode 100644 test/test/test_compressdev.c
 create mode 100644 test/test/test_compressdev_test_buffer.h

-- 
2.17.0

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v4 1/5] test/compress: add initial unit tests
  2018-05-04 10:22 ` [dpdk-dev] [PATCH v4 " Pablo de Lara
@ 2018-05-04 10:22   ` Pablo de Lara
  2018-05-14  8:29     ` Verma, Shally
  2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 2/5] test/compress: add multi op test Pablo de Lara
                     ` (5 subsequent siblings)
  6 siblings, 1 reply; 32+ messages in thread
From: Pablo de Lara @ 2018-05-04 10:22 UTC (permalink / raw)
  To: dev
  Cc: fiona.trahe, lee.daly, shally.verma, ahmed.mansour, Ashish.Gupta,
	Pablo de Lara, Ashish Gupta, Shally Verma

This commit introduces the initial tests for compressdev,
performing basic compression and decompression operations
of sample test buffers, using the Zlib library in one direction
and compressdev in another direction, to make sure that
the library is compatible with Zlib.

Due to the use of Zlib API, the test is disabled by default,
to avoid adding a new dependency on DPDK.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Signed-off-by: Ashish Gupta <ashish.gupta@caviumnetworks.com>
Signed-off-by: Shally Verma <shally.verma@caviumnetworks.com>
Acked-by: Lee Daly <lee.daly@intel.com>
---
 config/common_base                       |   5 +
 test/test/Makefile                       |   9 +
 test/test/meson.build                    |   8 +
 test/test/test_compressdev.c             | 725 +++++++++++++++++++++++
 test/test/test_compressdev_test_buffer.h | 295 +++++++++
 5 files changed, 1042 insertions(+)
 create mode 100644 test/test/test_compressdev.c
 create mode 100644 test/test/test_compressdev_test_buffer.h

diff --git a/config/common_base b/config/common_base
index cadad08f0..5cdbcc9ad 100644
--- a/config/common_base
+++ b/config/common_base
@@ -575,6 +575,11 @@ CONFIG_RTE_LIBRTE_SECURITY=y
 CONFIG_RTE_LIBRTE_COMPRESSDEV=y
 CONFIG_RTE_COMPRESS_MAX_DEVS=64
 
+#
+# Compile compressdev unit test
+#
+CONFIG_RTE_COMPRESSDEV_TEST=n
+
 #
 # Compile generic event device library
 #
diff --git a/test/test/Makefile b/test/test/Makefile
index 2630ab484..77d6369d6 100644
--- a/test/test/Makefile
+++ b/test/test/Makefile
@@ -180,6 +180,10 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_RING) += test_pmd_ring_perf.c
 SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_blockcipher.c
 SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c
 
+ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y)
+SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c
+endif
+
 ifeq ($(CONFIG_RTE_LIBRTE_EVENTDEV),y)
 SRCS-y += test_eventdev.c
 SRCS-y += test_event_ring.c
@@ -201,6 +205,11 @@ CFLAGS += $(WERROR_FLAGS)
 CFLAGS += -D_GNU_SOURCE
 
 LDLIBS += -lm
+ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y)
+ifeq ($(CONFIG_RTE_LIBRTE_COMPRESSDEV),y)
+LDLIBS += -lz
+endif
+endif
 
 # Disable VTA for memcpy test
 ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
diff --git a/test/test/meson.build b/test/test/meson.build
index ad0a65080..d71cd3c83 100644
--- a/test/test/meson.build
+++ b/test/test/meson.build
@@ -234,6 +234,14 @@ if dpdk_conf.has('RTE_LIBRTE_KNI')
 endif
 
 test_dep_objs = []
+compress_test_dep = dependency('zlib', required: false)
+if compress_test_dep.found()
+	test_dep_objs += compress_test_dep
+	test_sources += 'test_compressdev.c'
+	test_deps += 'compressdev'
+	test_names += 'compressdev_autotest'
+endif
+
 foreach d:test_deps
 	def_lib = get_option('default_library')
 	test_dep_objs += get_variable(def_lib + '_rte_' + d)
diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
new file mode 100644
index 000000000..e4916c034
--- /dev/null
+++ b/test/test/test_compressdev.c
@@ -0,0 +1,725 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+#include <string.h>
+#include <zlib.h>
+#include <math.h>
+
+#include <rte_cycles.h>
+#include <rte_malloc.h>
+#include <rte_mempool.h>
+#include <rte_mbuf.h>
+#include <rte_compressdev.h>
+
+#include "test_compressdev_test_buffer.h"
+#include "test.h"
+
+#define DEFAULT_WINDOW_SIZE 15
+#define DEFAULT_MEM_LEVEL 8
+#define MAX_DEQD_RETRIES 10
+#define DEQUEUE_WAIT_TIME 10000
+
+/*
+ * 30% extra size for compressed data compared to original data,
+ * in case data size cannot be reduced and it is actually bigger
+ * due to the compress block headers
+ */
+#define COMPRESS_BUF_SIZE_RATIO 1.3
+#define NUM_MBUFS 16
+#define NUM_OPS 16
+#define NUM_MAX_XFORMS 1
+#define NUM_MAX_INFLIGHT_OPS 128
+#define CACHE_SIZE 0
+
+const char *
+huffman_type_strings[] = {
+	[RTE_COMP_HUFFMAN_DEFAULT]	= "PMD default",
+	[RTE_COMP_HUFFMAN_FIXED]	= "Fixed",
+	[RTE_COMP_HUFFMAN_DYNAMIC]	= "Dynamic"
+};
+
+enum zlib_direction {
+	ZLIB_NONE,
+	ZLIB_COMPRESS,
+	ZLIB_DECOMPRESS,
+	ZLIB_ALL
+};
+
+struct comp_testsuite_params {
+	struct rte_mempool *mbuf_pool;
+	struct rte_mempool *op_pool;
+	struct rte_comp_xform def_comp_xform;
+	struct rte_comp_xform def_decomp_xform;
+};
+
+static struct comp_testsuite_params testsuite_params = { 0 };
+
+static void
+testsuite_teardown(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+
+	rte_mempool_free(ts_params->mbuf_pool);
+	rte_mempool_free(ts_params->op_pool);
+}
+
+static int
+testsuite_setup(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	unsigned int i;
+
+	if (rte_compressdev_count() == 0) {
+		RTE_LOG(ERR, USER1, "Need at least one compress device\n");
+		return TEST_FAILED;
+	}
+
+	uint32_t max_buf_size = 0;
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
+		max_buf_size = RTE_MAX(max_buf_size,
+				strlen(compress_test_bufs[i]) + 1);
+
+	max_buf_size *= COMPRESS_BUF_SIZE_RATIO;
+	/*
+	 * Buffers to be used in compression and decompression.
+	 * Since decompressed data might be larger than
+	 * compressed data (due to block header),
+	 * buffers should be big enough for both cases.
+	 */
+	ts_params->mbuf_pool = rte_pktmbuf_pool_create("mbuf_pool",
+			NUM_MBUFS,
+			CACHE_SIZE, 0,
+			max_buf_size + RTE_PKTMBUF_HEADROOM,
+			rte_socket_id());
+	if (ts_params->mbuf_pool == NULL) {
+		RTE_LOG(ERR, USER1, "Large mbuf pool could not be created\n");
+		return TEST_FAILED;
+	}
+
+	ts_params->op_pool = rte_comp_op_pool_create("op_pool", NUM_OPS,
+						0, 0, rte_socket_id());
+	if (ts_params->op_pool == NULL) {
+		RTE_LOG(ERR, USER1, "Operation pool could not be created\n");
+		goto exit;
+	}
+
+	/* Initializes default values for compress/decompress xforms */
+	ts_params->def_comp_xform.type = RTE_COMP_COMPRESS;
+	ts_params->def_comp_xform.compress.algo = RTE_COMP_ALGO_DEFLATE,
+	ts_params->def_comp_xform.compress.deflate.huffman =
+						RTE_COMP_HUFFMAN_DEFAULT;
+	ts_params->def_comp_xform.compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
+	ts_params->def_comp_xform.compress.chksum = RTE_COMP_CHECKSUM_NONE;
+	ts_params->def_comp_xform.compress.window_size = DEFAULT_WINDOW_SIZE;
+
+	ts_params->def_decomp_xform.type = RTE_COMP_DECOMPRESS;
+	ts_params->def_decomp_xform.decompress.algo = RTE_COMP_ALGO_DEFLATE,
+	ts_params->def_decomp_xform.decompress.chksum = RTE_COMP_CHECKSUM_NONE;
+	ts_params->def_decomp_xform.decompress.window_size = DEFAULT_WINDOW_SIZE;
+
+	return TEST_SUCCESS;
+
+exit:
+	testsuite_teardown();
+
+	return TEST_FAILED;
+}
+
+static int
+generic_ut_setup(void)
+{
+	/* Configure compressdev (one device, one queue pair) */
+	struct rte_compressdev_config config = {
+		.socket_id = rte_socket_id(),
+		.nb_queue_pairs = 1,
+		.max_nb_priv_xforms = NUM_MAX_XFORMS,
+		.max_nb_streams = 0
+	};
+
+	if (rte_compressdev_configure(0, &config) < 0) {
+		RTE_LOG(ERR, USER1, "Device configuration failed\n");
+		return -1;
+	}
+
+	if (rte_compressdev_queue_pair_setup(0, 0, NUM_MAX_INFLIGHT_OPS,
+			rte_socket_id()) < 0) {
+		RTE_LOG(ERR, USER1, "Queue pair setup failed\n");
+		return -1;
+	}
+
+	if (rte_compressdev_start(0) < 0) {
+		RTE_LOG(ERR, USER1, "Device could not be started\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+static void
+generic_ut_teardown(void)
+{
+	rte_compressdev_stop(0);
+	if (rte_compressdev_close(0) < 0)
+		RTE_LOG(ERR, USER1, "Device could not be closed\n");
+}
+
+static int
+compare_buffers(const char *buffer1, uint32_t buffer1_len,
+		const char *buffer2, uint32_t buffer2_len)
+{
+	if (buffer1_len != buffer2_len) {
+		RTE_LOG(ERR, USER1, "Buffer lengths are different\n");
+		return -1;
+	}
+
+	if (memcmp(buffer1, buffer2, buffer1_len) != 0) {
+		RTE_LOG(ERR, USER1, "Buffers are different\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+/*
+ * Maps compressdev and Zlib flush flags
+ */
+static int
+map_zlib_flush_flag(enum rte_comp_flush_flag flag)
+{
+	switch (flag) {
+	case RTE_COMP_FLUSH_NONE:
+		return Z_NO_FLUSH;
+	case RTE_COMP_FLUSH_SYNC:
+		return Z_SYNC_FLUSH;
+	case RTE_COMP_FLUSH_FULL:
+		return Z_FULL_FLUSH;
+	case RTE_COMP_FLUSH_FINAL:
+		return Z_FINISH;
+	/*
+	 * There should be only the values above,
+	 * so this should never happen
+	 */
+	default:
+		return -1;
+	}
+}
+
+static int
+compress_zlib(struct rte_comp_op *op,
+		const struct rte_comp_xform *xform, int mem_level)
+{
+	z_stream stream;
+	int zlib_flush;
+	int strategy, window_bits, comp_level;
+	int ret = -1;
+
+	/* initialize zlib stream */
+	stream.zalloc = Z_NULL;
+	stream.zfree = Z_NULL;
+	stream.opaque = Z_NULL;
+
+	if (xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_FIXED)
+		strategy = Z_FIXED;
+	else
+		strategy = Z_DEFAULT_STRATEGY;
+
+	/*
+	 * Window bits is the base two logarithm of the window size (in bytes).
+	 * When doing raw DEFLATE, this number will be negative.
+	 */
+	window_bits = -(xform->compress.window_size);
+
+	comp_level = xform->compress.level;
+
+	if (comp_level != RTE_COMP_LEVEL_NONE)
+		ret = deflateInit2(&stream, comp_level, Z_DEFLATED,
+			window_bits, mem_level, strategy);
+	else
+		ret = deflateInit(&stream, Z_NO_COMPRESSION);
+
+	if (ret != Z_OK) {
+		printf("Zlib deflate could not be initialized\n");
+		goto exit;
+	}
+
+	/* Assuming stateless operation */
+	stream.avail_in = op->src.length;
+	stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
+	stream.avail_out = op->m_dst->data_len;
+	stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
+
+	/* Stateless operation, all buffer will be compressed in one go */
+	zlib_flush = map_zlib_flush_flag(op->flush_flag);
+	ret = deflate(&stream, zlib_flush);
+
+	if (stream.avail_in != 0) {
+		RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
+		goto exit;
+	}
+
+	//TODO: This is only if flush final is used
+	if (ret != Z_STREAM_END)
+		goto exit;
+
+	op->consumed = op->src.length - stream.avail_in;
+	op->produced = op->m_dst->data_len - stream.avail_out;
+	op->status = RTE_COMP_OP_STATUS_SUCCESS;
+
+	deflateReset(&stream);
+
+	ret = 0;
+exit:
+	deflateEnd(&stream);
+
+	return ret;
+}
+
+static int
+decompress_zlib(struct rte_comp_op *op,
+		const struct rte_comp_xform *xform)
+{
+	z_stream stream;
+	int window_bits;
+	int zlib_flush;
+	int ret = TEST_FAILED;
+
+	/* initialize zlib stream */
+	stream.zalloc = Z_NULL;
+	stream.zfree = Z_NULL;
+	stream.opaque = Z_NULL;
+
+	/*
+	 * Window bits is the base two logarithm of the window size (in bytes).
+	 * When doing raw DEFLATE, this number will be negative.
+	 */
+	window_bits = -(xform->decompress.window_size);
+
+	ret = inflateInit2(&stream, window_bits);
+
+	if (ret != Z_OK) {
+		printf("Zlib deflate could not be initialized\n");
+		goto exit;
+	}
+
+	/* Assuming stateless operation */
+	stream.avail_in = op->src.length;
+	stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
+	stream.avail_out = op->m_dst->data_len;
+	stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
+
+	/* Stateless operation, all buffer will be compressed in one go */
+	zlib_flush = map_zlib_flush_flag(op->flush_flag);
+	ret = inflate(&stream, zlib_flush);
+
+	if (stream.avail_in != 0) {
+		RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
+		goto exit;
+	}
+
+	//TODO: This is only if flush final is used
+	if (ret != Z_STREAM_END)
+		goto exit;
+
+	op->consumed = op->src.length - stream.avail_in;
+	op->produced = op->m_dst->data_len - stream.avail_out;
+	op->status = RTE_COMP_OP_STATUS_SUCCESS;
+
+	inflateReset(&stream);
+
+	ret = 0;
+exit:
+	inflateEnd(&stream);
+
+	return ret;
+}
+
+/*
+ * Compresses and decompresses buffer with compressdev API and Zlib API
+ */
+static int
+test_deflate_comp_decomp(const char *test_buffer,
+		struct rte_comp_xform *compress_xform,
+		struct rte_comp_xform *decompress_xform,
+		enum rte_comp_op_type state,
+		enum zlib_direction zlib_dir)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	int ret_status = -1;
+	int ret;
+	struct rte_mbuf *comp_buf = NULL;
+	struct rte_mbuf *uncomp_buf = NULL;
+	struct rte_comp_op *op = NULL;
+	struct rte_comp_op *op_processed = NULL;
+	void *priv_xform = NULL;
+	uint16_t num_deqd;
+	unsigned int deqd_retries = 0;
+	char *data_ptr;
+
+	/* Prepare the source mbuf with the data */
+	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+	if (uncomp_buf == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Source mbuf could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	data_ptr = rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
+	snprintf(data_ptr, strlen(test_buffer) + 1, "%s", test_buffer);
+
+	/* Prepare the destination mbuf */
+	comp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+	if (comp_buf == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Destination mbuf could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	rte_pktmbuf_append(comp_buf,
+			strlen(test_buffer) * COMPRESS_BUF_SIZE_RATIO);
+
+	/* Build the compression operations */
+	op = rte_comp_op_alloc(ts_params->op_pool);
+	if (op == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Compress operation could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	op->m_src = uncomp_buf;
+	op->m_dst = comp_buf;
+	op->src.offset = 0;
+	op->src.length = rte_pktmbuf_pkt_len(uncomp_buf);
+	op->dst.offset = 0;
+	if (state == RTE_COMP_OP_STATELESS) {
+		//TODO: FULL or FINAL?
+		op->flush_flag = RTE_COMP_FLUSH_FINAL;
+	} else {
+		RTE_LOG(ERR, USER1,
+			"Stateful operations are not supported "
+			"in these tests yet\n");
+		goto exit;
+	}
+	op->input_chksum = 0;
+
+	/* Compress data (either with Zlib API or compressdev API */
+	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
+		ret = compress_zlib(op,
+			(const struct rte_comp_xform *)&compress_xform,
+			DEFAULT_MEM_LEVEL);
+		if (ret < 0)
+			goto exit;
+
+		op_processed = op;
+	} else {
+		/* Create compress xform private data */
+		ret = rte_compressdev_private_xform_create(0,
+			(const struct rte_comp_xform *)compress_xform,
+			&priv_xform);
+		if (ret < 0) {
+			RTE_LOG(ERR, USER1,
+				"Compression private xform "
+				"could not be created\n");
+			goto exit;
+		}
+
+		/* Attach xform private data to operation */
+		op->private_xform = priv_xform;
+
+		/* Enqueue and dequeue all operations */
+		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
+		if (ret == 0) {
+			RTE_LOG(ERR, USER1,
+				"The operation could not be enqueued\n");
+			goto exit;
+		}
+		do {
+			/*
+			 * If retrying a dequeue call, wait for 10 ms to allow
+			 * enough time to the driver to process the operations
+			 */
+			if (deqd_retries != 0) {
+				/*
+				 * Avoid infinite loop if not all the
+				 * operations get out of the device
+				 */
+				if (deqd_retries == MAX_DEQD_RETRIES) {
+					RTE_LOG(ERR, USER1,
+						"Not all operations could be "
+						"dequeued\n");
+					goto exit;
+				}
+				usleep(DEQUEUE_WAIT_TIME);
+			}
+			num_deqd = rte_compressdev_dequeue_burst(0, 0,
+					&op_processed, 1);
+
+			deqd_retries++;
+		} while (num_deqd < 1);
+
+		deqd_retries = 0;
+
+		/* Free compress private xform */
+		rte_compressdev_private_xform_free(0, priv_xform);
+		priv_xform = NULL;
+	}
+
+	enum rte_comp_huffman huffman_type =
+		compress_xform->compress.deflate.huffman;
+	RTE_LOG(DEBUG, USER1, "Buffer compressed from %u to %u bytes "
+			"(level = %u, huffman = %s)\n",
+			op_processed->consumed, op_processed->produced,
+			compress_xform->compress.level,
+			huffman_type_strings[huffman_type]);
+	RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
+			(float)op_processed->produced /
+			op_processed->consumed * 100);
+	op = NULL;
+
+	/*
+	 * Check operation status and free source mbuf (destination mbuf and
+	 * compress operation information is needed for the decompression stage)
+	 */
+	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
+		RTE_LOG(ERR, USER1,
+			"Some operations were not successful\n");
+		goto exit;
+	}
+	rte_pktmbuf_free(uncomp_buf);
+	uncomp_buf = NULL;
+
+	/* Allocate buffer for decompressed data */
+	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+	if (uncomp_buf == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Destination mbuf could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
+
+	/* Build the decompression operations */
+	op = rte_comp_op_alloc(ts_params->op_pool);
+	if (op == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Decompress operation could not be allocated "
+			"from the mempool\n");
+		goto exit;
+	}
+
+	/* Source buffer is the compressed data from the previous operation */
+	op->m_src = op_processed->m_dst;
+	op->m_dst = uncomp_buf;
+	op->src.offset = 0;
+	/*
+	 * Set the length of the compressed data to the
+	 * number of bytes that were produced in the previous stage
+	 */
+	op->src.length = op_processed->produced;
+	op->dst.offset = 0;
+	if (state == RTE_COMP_OP_STATELESS) {
+		//TODO: FULL or FINAL?
+		op->flush_flag = RTE_COMP_FLUSH_FINAL;
+	} else {
+		RTE_LOG(ERR, USER1,
+			"Stateful operations are not supported "
+			"in these tests yet\n");
+		goto exit;
+	}
+	op->input_chksum = 0;
+
+	/*
+	 * Free the previous compress operation,
+	 * as it is not needed anymore
+	 */
+	rte_comp_op_free(op_processed);
+	op_processed = NULL;
+
+	/* Decompress data (either with Zlib API or compressdev API */
+	if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
+		ret = decompress_zlib(op,
+			(const struct rte_comp_xform *)&decompress_xform);
+		if (ret < 0)
+			goto exit;
+
+		op_processed = op;
+	} else {
+		num_deqd = 0;
+		/* Create decompress xform private data */
+		ret = rte_compressdev_private_xform_create(0,
+			(const struct rte_comp_xform *)decompress_xform,
+			&priv_xform);
+		if (ret < 0) {
+			RTE_LOG(ERR, USER1,
+				"Decompression private xform "
+				"could not be created\n");
+			goto exit;
+		}
+
+		/* Attach xform private data to operation */
+		op->private_xform = priv_xform;
+
+		/* Enqueue and dequeue all operations */
+		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
+		if (ret == 0) {
+			RTE_LOG(ERR, USER1,
+				"The operation could not be enqueued\n");
+			goto exit;
+		}
+		do {
+			/*
+			 * If retrying a dequeue call, wait for 10 ms to allow
+			 * enough time to the driver to process the operations
+			 */
+			if (deqd_retries != 0) {
+				/*
+				 * Avoid infinite loop if not all the
+				 * operations get out of the device
+				 */
+				if (deqd_retries == MAX_DEQD_RETRIES) {
+					RTE_LOG(ERR, USER1,
+						"Not all operations could be "
+						"dequeued\n");
+					goto exit;
+				}
+				usleep(DEQUEUE_WAIT_TIME);
+			}
+			num_deqd = rte_compressdev_dequeue_burst(0, 0,
+					&op_processed, 1);
+
+			deqd_retries++;
+		} while (num_deqd < 1);
+	}
+
+	RTE_LOG(DEBUG, USER1, "Buffer decompressed from %u to %u bytes\n",
+			op_processed->consumed, op_processed->produced);
+	op = NULL;
+	/*
+	 * Check operation status and free source mbuf (destination mbuf and
+	 * compress operation information is still needed)
+	 */
+	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
+		RTE_LOG(ERR, USER1,
+			"Some operations were not successful\n");
+		goto exit;
+	}
+	rte_pktmbuf_free(comp_buf);
+	comp_buf = NULL;
+
+	/*
+	 * Compare the original stream with the decompressed stream
+	 * (in size and the data)
+	 */
+	if (compare_buffers(test_buffer, strlen(test_buffer) + 1,
+			rte_pktmbuf_mtod(op_processed->m_dst, const char *),
+			op_processed->produced) < 0)
+		goto exit;
+
+	ret_status = 0;
+
+exit:
+	/* Free resources */
+	rte_pktmbuf_free(uncomp_buf);
+	rte_pktmbuf_free(comp_buf);
+	rte_comp_op_free(op);
+	rte_comp_op_free(op_processed);
+
+	if (priv_xform != NULL)
+		rte_compressdev_private_xform_free(0, priv_xform);
+
+	return ret_status;
+}
+
+static int
+test_compressdev_deflate_stateless_fixed(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	const char *test_buffer;
+	uint16_t i;
+	struct rte_comp_xform compress_xform;
+
+	memcpy(&compress_xform, &ts_params->def_comp_xform,
+			sizeof(struct rte_comp_xform));
+	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
+
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+		test_buffer = compress_test_bufs[i];
+
+		/* Compress with compressdev, decompress with Zlib */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_DECOMPRESS) < 0)
+			return TEST_FAILED;
+
+		/* Compress with Zlib, decompress with compressdev */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_COMPRESS) < 0)
+			return TEST_FAILED;
+	}
+
+	return TEST_SUCCESS;
+}
+
+static int
+test_compressdev_deflate_stateless_dynamic(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	const char *test_buffer;
+	uint16_t i;
+	struct rte_comp_xform compress_xform;
+
+	memcpy(&compress_xform, &ts_params->def_comp_xform,
+			sizeof(struct rte_comp_xform));
+	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
+
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+		test_buffer = compress_test_bufs[i];
+
+		/* Compress with compressdev, decompress with Zlib */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_DECOMPRESS) < 0)
+			return TEST_FAILED;
+
+		/* Compress with Zlib, decompress with compressdev */
+		if (test_deflate_comp_decomp(test_buffer,
+				&compress_xform,
+				&ts_params->def_decomp_xform,
+				RTE_COMP_OP_STATELESS,
+				ZLIB_COMPRESS) < 0)
+			return TEST_FAILED;
+	}
+
+	return TEST_SUCCESS;
+}
+
+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(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_CASES_END() /**< NULL terminate unit test array */
+	}
+};
+
+static int
+test_compressdev(void)
+{
+	return unit_test_suite_runner(&compressdev_testsuite);
+}
+
+REGISTER_TEST_COMMAND(compressdev_autotest, test_compressdev);
diff --git a/test/test/test_compressdev_test_buffer.h b/test/test/test_compressdev_test_buffer.h
new file mode 100644
index 000000000..c0492f89a
--- /dev/null
+++ b/test/test/test_compressdev_test_buffer.h
@@ -0,0 +1,295 @@
+#ifndef TEST_COMPRESSDEV_TEST_BUFFERS_H_
+#define TEST_COMPRESSDEV_TEST_BUFFERS_H_
+
+/*
+ * These test buffers are snippets obtained
+ * from the Canterbury and Calgary Corpus
+ * collection.
+ */
+
+/* Snippet of Alice's Adventures in Wonderland */
+static const char test_buf_alice[] =
+	"  Alice was beginning to get very tired of sitting by her sister\n"
+	"on the bank, and of having nothing to do:  once or twice she had\n"
+	"peeped into the book her sister was reading, but it had no\n"
+	"pictures or conversations in it, `and what is the use of a book,'\n"
+	"thought Alice `without pictures or conversation?'\n\n"
+	"  So she was considering in her own mind (as well as she could,\n"
+	"for the hot day made her feel very sleepy and stupid), whether\n"
+	"the pleasure of making a daisy-chain would be worth the trouble\n"
+	"of getting up and picking the daisies, when suddenly a White\n"
+	"Rabbit with pink eyes ran close by her.\n\n"
+	"  There was nothing so VERY remarkable in that; nor did Alice\n"
+	"think it so VERY much out of the way to hear the Rabbit say to\n"
+	"itself, `Oh dear!  Oh dear!  I shall be late!'  (when she thought\n"
+	"it over afterwards, it occurred to her that she ought to have\n"
+	"wondered at this, but at the time it all seemed quite natural);\n"
+	"but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT-\n"
+	"POCKET, and looked at it, and then hurried on, Alice started to\n"
+	"her feet, for it flashed across her mind that she had never\n"
+	"before seen a rabbit with either a waistcoat-pocket, or a watch to\n"
+	"take out of it, and burning with curiosity, she ran across the\n"
+	"field after it, and fortunately was just in time to see it pop\n"
+	"down a large rabbit-hole under the hedge.\n\n"
+	"  In another moment down went Alice after it, never once\n"
+	"considering how in the world she was to get out again.\n\n"
+	"  The rabbit-hole went straight on like a tunnel for some way,\n"
+	"and then dipped suddenly down, so suddenly that Alice had not a\n"
+	"moment to think about stopping herself before she found herself\n"
+	"falling down a very deep well.\n\n"
+	"  Either the well was very deep, or she fell very slowly, for she\n"
+	"had plenty of time as she went down to look about her and to\n"
+	"wonder what was going to happen next.  First, she tried to look\n"
+	"down and make out what she was coming to, but it was too dark to\n"
+	"see anything; then she looked at the sides of the well, and\n"
+	"noticed that they were filled with cupboards and book-shelves;\n"
+	"here and there she saw maps and pictures hung upon pegs.  She\n"
+	"took down a jar from one of the shelves as she passed; it was\n"
+	"labelled `ORANGE MARMALADE', but to her great disappointment it\n"
+	"was empty:  she did not like to drop the jar for fear of killing\n"
+	"somebody, so managed to put it into one of the cupboards as she\n"
+	"fell past it.\n\n"
+	"  `Well!' thought Alice to herself, `after such a fall as this, I\n"
+	"shall think nothing of tumbling down stairs!  How brave they'll\n"
+	"all think me at home!  Why, I wouldn't say anything about it,\n"
+	"even if I fell off the top of the house!' (Which was very likely\n"
+	"true.)\n\n"
+	"  Down, down, down.  Would the fall NEVER come to an end!  `I\n"
+	"wonder how many miles I've fallen by this time?' she said aloud.\n"
+	"`I must be getting somewhere near the centre of the earth.  Let\n"
+	"me see:  that would be four thousand miles down, I think--' (for,\n"
+	"you see, Alice had learnt several things of this sort in her\n"
+	"lessons in the schoolroom, and though this was not a VERY good\n"
+	"opportunity for showing off her knowledge, as there was no one to\n"
+	"listen to her, still it was good practice to say it over) `--yes,\n"
+	"that's about the right distance--but then I wonder what Latitude\n"
+	"or Longitude I've got to?'  (Alice had no idea what Latitude was,\n"
+	"or Longitude either, but thought they were nice grand words to\n"
+	"say.)\n\n"
+	"  Presently she began again.  `I wonder if I shall fall right\n"
+	"THROUGH the earth!  How funny it'll seem to come out among the\n"
+	"people that walk with their heads downward!  The Antipathies, I\n"
+	"think--' (she was rather glad there WAS no one listening, this\n"
+	"time, as it didn't sound at all the right word) `--but I shall\n"
+	"have to ask them what the name of the country is, you know.\n"
+	"Please, Ma'am, is this New Zealand or Australia?' (and she tried\n"
+	"to curtsey as she spoke--fancy CURTSEYING as you're falling\n"
+	"through the air!  Do you think you could manage it?)  `And what\n"
+	"an ignorant little girl she'll think me for asking!  No, it'll\n"
+	"never do to ask:  perhaps I shall see it written up somewhere.'\n"
+	"  Down, down, down.  There was nothing else to do, so Alice soon\n"
+	"began talking again.  `Dinah'll miss me very much to-night, I\n"
+	"should think!'  (Dinah was the cat.)  `I hope they'll remember\n"
+	"her saucer of milk at tea-time.  Dinah my dear!  I wish you were\n"
+	"down here with me!  There are no mice in the air, I'm afraid, but\n"
+	"you might catch a bat, and that's very like a mouse, you know.\n"
+	"But do cats eat bats, I wonder?'  And here Alice began to get\n"
+	"rather sleepy, and went on saying to herself, in a dreamy sort of\n"
+	"way, `Do cats eat bats?  Do cats eat bats?' and sometimes, `Do\n"
+	"bats eat cats?' for, you see, as she couldn't answer either\n"
+	"question, it didn't much matter which way she put it.  She felt\n"
+	"that she was dozing off, and had just begun to dream that she\n"
+	"was walking hand in hand with Dinah, and saying to her very\n"
+	"earnestly, `Now, Dinah, tell me the truth:  did you ever eat a\n"
+	"bat?' when suddenly, thump! thump! down she came upon a heap of\n"
+	"sticks and dry leaves, and the fall was over.\n\n";
+
+/* Snippet of Shakespeare play */
+static const char test_buf_shakespeare[] =
+	"CHARLES	wrestler to Frederick.\n"
+	"\n"
+	"\n"
+	"OLIVER		|\n"
+	"		|\n"
+	"JAQUES (JAQUES DE BOYS:)  	|  sons of Sir Rowland de Boys.\n"
+	"		|\n"
+	"ORLANDO		|\n"
+	"\n"
+	"\n"
+	"ADAM	|\n"
+	"	|  servants to Oliver.\n"
+	"DENNIS	|\n"
+	"\n"
+	"\n"
+	"TOUCHSTONE	a clown.\n"
+	"\n"
+	"SIR OLIVER MARTEXT	a vicar.\n"
+	"\n"
+	"\n"
+	"CORIN	|\n"
+	"	|  shepherds.\n"
+	"SILVIUS	|\n"
+	"\n"
+	"\n"
+	"WILLIAM	a country fellow in love with Audrey.\n"
+	"\n"
+	"	A person representing HYMEN. (HYMEN:)\n"
+	"\n"
+	"ROSALIND	daughter to the banished duke.\n"
+	"\n"
+	"CELIA	daughter to Frederick.\n"
+	"\n"
+	"PHEBE	a shepherdess.\n"
+	"\n"
+	"AUDREY	a country wench.\n"
+	"\n"
+	"	Lords, pages, and attendants, &c.\n"
+	"	(Forester:)\n"
+	"	(A Lord:)\n"
+	"	(First Lord:)\n"
+	"	(Second Lord:)\n"
+	"	(First Page:)\n"
+	"	(Second Page:)\n"
+	"\n"
+	"\n"
+	"SCENE	Oliver's house; Duke Frederick's court; and the\n"
+	"	Forest of Arden.\n"
+	"\n"
+	"\n"
+	"\n"
+	"\n"
+	"	AS YOU LIKE IT\n"
+	"\n"
+	"\n"
+	"ACT I\n"
+	"\n"
+	"\n"
+	"\n"
+	"SCENE I	Orchard of Oliver's house.\n"
+	"\n"
+	"\n"
+	"	[Enter ORLANDO and ADAM]\n"
+	"\n"
+	"ORLANDO	As I remember, Adam, it was upon this fashion\n"
+	"	bequeathed me by will but poor a thousand crowns,\n"
+	"	and, as thou sayest, charged my brother, on his\n"
+	"	blessing, to breed me well: and there begins my\n"
+	"	sadness. My brother Jaques he keeps at school, and\n"
+	"	report speaks goldenly of his profit: for my part,\n"
+	"	he keeps me rustically at home, or, to speak more\n"
+	"	properly, stays me here at home unkept; for call you\n"
+	"	that keeping for a gentleman of my birth, that\n"
+	"	differs not from the stalling of an ox? His horses\n"
+	"	are bred better; for, besides that they are fair\n"
+	"	with their feeding, they are taught their manage,\n"
+	"	and to that end riders dearly hired: but I, his\n"
+	"	brother, gain nothing under him but growth; for the\n"
+	"	which his animals on his dunghills are as much\n"
+	"	bound to him as I. Besides this nothing that he so\n"
+	"	plentifully gives me, the something that nature gave\n"
+	"	me his countenance seems to take from me: he lets\n"
+	"	me feed with his hinds, bars me the place of a\n"
+	"	brother, and, as much as in him lies, mines my\n"
+	"	gentility with my education. This is it, Adam, that\n"
+	"	grieves me; and the spirit of my father, which I\n"
+	"	think is within me, begins to mutiny against this\n"
+	"	servitude: I will no longer endure it, though yet I\n"
+	"	know no wise remedy how to avoid it.\n"
+	"\n"
+	"ADAM	Yonder comes my master, your brother.\n"
+	"\n"
+	"ORLANDO	Go apart, Adam, and thou shalt hear how he will\n";
+
+/* Snippet of source code in Pascal */
+static const char test_buf_pascal[] =
+	"	Ptr    = 1..DMem;\n"
+	"	Loc    = 1..IMem;\n"
+	"	Loc0   = 0..IMem;\n"
+	"	EdgeT  = (hout,lin,hin,lout); {Warning this order is important in}\n"
+	"				      {predicates such as gtS,geS}\n"
+	"	CardT  = (finite,infinite);\n"
+	"	ExpT   = Minexp..Maxexp;\n"
+	"	ManT   = Mininf..Maxinf; \n"
+	"	Pflag  = (PNull,PSoln,PTrace,PPrint);\n"
+	"	Sreal  = record\n"
+	"		    edge:EdgeT;\n"
+	"		    cardinality:CardT;\n"
+	"		    exp:ExpT; {exponent}\n"
+	"		    mantissa:ManT;\n"
+	"		 end;\n"
+	"	Int    = record\n"
+	"		    hi:Sreal;\n"
+	"		    lo:Sreal;\n"
+	"	 end;\n"
+	"	Instr  = record\n"
+	"		    Code:OpType;\n"
+	"		    Pars: array[0..Par] of 0..DMem;\n"
+	"		 end;\n"
+	"	DataMem= record\n"
+	"		    D        :array [Ptr] of Int;\n"
+	"		    S        :array [Loc] of State;\n"
+	"		    LastHalve:Loc;\n"
+	"		    RHalve   :array [Loc] of real;\n"
+	"		 end;\n"
+	"	DataFlags=record\n"
+	"		    PF	     :array [Ptr] of Pflag;\n"
+	"		 end;\n"
+	"var\n"
+	"	Debug  : (none,activity,post,trace,dump);\n"
+	"	Cut    : (once,all);\n"
+	"	GlobalEnd,Verifiable:boolean;\n"
+	"	HalveThreshold:real;\n"
+	"	I      : array [Loc] of Instr; {Memory holding instructions}\n"
+	"	End    : Loc; {last instruction in I}\n"
+	"	ParN   : array [OpType] of -1..Par; {number of parameters for each \n"
+	"			opcode. -1 means no result}\n"
+	"        ParIntersect : array [OpType] of boolean ;\n"
+	"	DInit  : DataMem; {initial memory which is cleared and \n"
+	"				used in first call}\n"
+	"	DF     : DataFlags; {hold flags for variables, e.g. print/trace}\n"
+	"	MaxDMem:0..DMem;\n"
+	"	Shift  : array[0..Digits] of 1..maxint;{array of constant multipliers}\n"
+	"						{used for alignment etc.}\n"
+	"	Dummy  :Positive;\n"
+	"	{constant intervals and Sreals}\n"
+	"	PlusInfS,MinusInfS,PlusSmallS,MinusSmallS,ZeroS,\n"
+	"	PlusFiniteS,MinusFiniteS:Sreal;\n"
+	"	Zero,All,AllFinite:Int;\n"
+	"\n"
+	"procedure deblank;\n"
+	"var Ch:char;\n"
+	"begin\n"
+	"   while (not eof) and (input^ in [' ','	']) do read(Ch);\n"
+	"end;\n"
+	"\n"
+	"procedure InitialOptions;\n"
+	"\n"
+	"#include '/user/profs/cleary/bin/options.i';\n"
+	"\n"
+	"   procedure Option;\n"
+	"   begin\n"
+	"      case Opt of\n"
+	"      'a','A':Debug:=activity;\n"
+	"      'd','D':Debug:=dump;\n"
+	"      'h','H':HalveThreshold:=StringNum/100;\n"
+	"      'n','N':Debug:=none;\n"
+	"      'p','P':Debug:=post;\n"
+	"      't','T':Debug:=trace;\n"
+	"      'v','V':Verifiable:=true;\n"
+	"      end;\n"
+	"   end;\n"
+	"\n"
+	"begin\n"
+	"   Debug:=trace;\n"
+	"   Verifiable:=false;\n"
+	"   HalveThreshold:=67/100;\n"
+	"   Options;\n"
+	"   writeln(Debug);\n"
+	"   writeln('Verifiable:',Verifiable);\n"
+	"   writeln('Halve threshold',HalveThreshold);\n"
+	"end;{InitialOptions}\n"
+	"\n"
+	"procedure NormalizeUp(E,M:integer;var S:Sreal;var Closed:boolean);\n"
+	"begin\n"
+	"with S do\n"
+	"begin\n"
+	"   if M=0 then S:=ZeroS else\n"
+	"   if M>0 then\n";
+
+static const char * const compress_test_bufs[] = {
+	test_buf_alice,
+	test_buf_shakespeare,
+	test_buf_pascal
+};
+
+#endif /* TEST_COMPRESSDEV_TEST_BUFFERS_H_ */
-- 
2.17.0

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v4 2/5] test/compress: add multi op test
  2018-05-04 10:22 ` [dpdk-dev] [PATCH v4 " Pablo de Lara
  2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 1/5] test/compress: add initial " Pablo de Lara
@ 2018-05-04 10:22   ` Pablo de Lara
  2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 3/5] test/compress: add multi level test Pablo de Lara
                     ` (4 subsequent siblings)
  6 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-05-04 10:22 UTC (permalink / raw)
  To: dev
  Cc: fiona.trahe, lee.daly, shally.verma, ahmed.mansour, Ashish.Gupta,
	Pablo de Lara

Add test that checks if multiple operations with
different buffers can be handled on a single enqueue call.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Lee Daly <lee.daly@intel.com>
---
 test/test/test_compressdev.c | 476 +++++++++++++++++++++++------------
 1 file changed, 319 insertions(+), 157 deletions(-)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index e4916c034..629509f9b 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -45,6 +45,10 @@ enum zlib_direction {
 	ZLIB_ALL
 };
 
+struct priv_op_data {
+	uint16_t orig_idx;
+};
+
 struct comp_testsuite_params {
 	struct rte_mempool *mbuf_pool;
 	struct rte_mempool *op_pool;
@@ -97,7 +101,8 @@ testsuite_setup(void)
 	}
 
 	ts_params->op_pool = rte_comp_op_pool_create("op_pool", NUM_OPS,
-						0, 0, rte_socket_id());
+				0, sizeof(struct priv_op_data),
+				rte_socket_id());
 	if (ts_params->op_pool == NULL) {
 		RTE_LOG(ERR, USER1, "Operation pool could not be created\n");
 		goto exit;
@@ -337,7 +342,9 @@ decompress_zlib(struct rte_comp_op *op,
  * Compresses and decompresses buffer with compressdev API and Zlib API
  */
 static int
-test_deflate_comp_decomp(const char *test_buffer,
+test_deflate_comp_decomp(const char * const test_bufs[],
+		unsigned int num_bufs,
+		uint16_t buf_idx[],
 		struct rte_comp_xform *compress_xform,
 		struct rte_comp_xform *decompress_xform,
 		enum rte_comp_op_type state,
@@ -346,95 +353,146 @@ test_deflate_comp_decomp(const char *test_buffer,
 	struct comp_testsuite_params *ts_params = &testsuite_params;
 	int ret_status = -1;
 	int ret;
-	struct rte_mbuf *comp_buf = NULL;
-	struct rte_mbuf *uncomp_buf = NULL;
-	struct rte_comp_op *op = NULL;
-	struct rte_comp_op *op_processed = NULL;
-	void *priv_xform = NULL;
-	uint16_t num_deqd;
+	struct rte_mbuf *uncomp_bufs[num_bufs];
+	struct rte_mbuf *comp_bufs[num_bufs];
+	struct rte_comp_op *ops[num_bufs];
+	struct rte_comp_op *ops_processed[num_bufs];
+	void *priv_xforms[num_bufs];
+	uint16_t num_enqd, num_deqd, num_total_deqd;
+	uint16_t num_priv_xforms = 0;
 	unsigned int deqd_retries = 0;
+	struct priv_op_data *priv_data;
 	char *data_ptr;
-
-	/* Prepare the source mbuf with the data */
-	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
-	if (uncomp_buf == NULL) {
+	unsigned int i;
+	const struct rte_compressdev_capabilities *capa =
+		rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+
+	/* Initialize all arrays to NULL */
+	memset(uncomp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
+	memset(comp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
+	memset(ops, 0, sizeof(struct rte_comp_op *) * num_bufs);
+	memset(ops_processed, 0, sizeof(struct rte_comp_op *) * num_bufs);
+	memset(priv_xforms, 0, sizeof(void *) * num_bufs);
+
+	/* Prepare the source mbufs with the data */
+	ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, uncomp_bufs, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Source mbuf could not be allocated "
+			"Source mbufs could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	data_ptr = rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
-	snprintf(data_ptr, strlen(test_buffer) + 1, "%s", test_buffer);
+	for (i = 0; i < num_bufs; i++) {
+		data_ptr = rte_pktmbuf_append(uncomp_bufs[i],
+					strlen(test_bufs[i]) + 1);
+		snprintf(data_ptr, strlen(test_bufs[i]) + 1, "%s",
+					test_bufs[i]);
+	}
 
-	/* Prepare the destination mbuf */
-	comp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
-	if (comp_buf == NULL) {
+	/* Prepare the destination mbufs */
+	ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, comp_bufs, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Destination mbuf could not be allocated "
+			"Destination mbufs could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	rte_pktmbuf_append(comp_buf,
-			strlen(test_buffer) * COMPRESS_BUF_SIZE_RATIO);
+	for (i = 0; i < num_bufs; i++)
+		rte_pktmbuf_append(comp_bufs[i],
+			strlen(test_bufs[i]) * COMPRESS_BUF_SIZE_RATIO);
 
 	/* Build the compression operations */
-	op = rte_comp_op_alloc(ts_params->op_pool);
-	if (op == NULL) {
+	ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Compress operation could not be allocated "
+			"Compress operations could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	op->m_src = uncomp_buf;
-	op->m_dst = comp_buf;
-	op->src.offset = 0;
-	op->src.length = rte_pktmbuf_pkt_len(uncomp_buf);
-	op->dst.offset = 0;
-	if (state == RTE_COMP_OP_STATELESS) {
-		//TODO: FULL or FINAL?
-		op->flush_flag = RTE_COMP_FLUSH_FINAL;
-	} else {
-		RTE_LOG(ERR, USER1,
-			"Stateful operations are not supported "
-			"in these tests yet\n");
-		goto exit;
+	for (i = 0; i < num_bufs; i++) {
+		ops[i]->m_src = uncomp_bufs[i];
+		ops[i]->m_dst = comp_bufs[i];
+		ops[i]->src.offset = 0;
+		ops[i]->src.length = rte_pktmbuf_pkt_len(uncomp_bufs[i]);
+		ops[i]->dst.offset = 0;
+		if (state == RTE_COMP_OP_STATELESS) {
+			//TODO: FULL or FINAL?
+			ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
+		} else {
+			RTE_LOG(ERR, USER1,
+				"Stateful operations are not supported "
+				"in these tests yet\n");
+			goto exit;
+		}
+		ops[i]->input_chksum = 0;
+		/*
+		 * Store original operation index in private data,
+		 * since ordering does not have to be maintained,
+		 * when dequeueing from compressdev, so a comparison
+		 * at the end of the test can be done.
+		 */
+		priv_data = (struct priv_op_data *) (ops[i] + 1);
+		priv_data->orig_idx = i;
 	}
-	op->input_chksum = 0;
 
 	/* Compress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
-		ret = compress_zlib(op,
-			(const struct rte_comp_xform *)&compress_xform,
-			DEFAULT_MEM_LEVEL);
-		if (ret < 0)
-			goto exit;
-
-		op_processed = op;
-	} else {
-		/* Create compress xform private data */
-		ret = rte_compressdev_private_xform_create(0,
-			(const struct rte_comp_xform *)compress_xform,
-			&priv_xform);
-		if (ret < 0) {
-			RTE_LOG(ERR, USER1,
-				"Compression private xform "
-				"could not be created\n");
-			goto exit;
+		for (i = 0; i < num_bufs; i++) {
+			ret = compress_zlib(ops[i],
+				(const struct rte_comp_xform *)compress_xform,
+					DEFAULT_MEM_LEVEL);
+			if (ret < 0)
+				goto exit;
+
+			ops_processed[i] = ops[i];
 		}
+	} else {
+		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
+			/* Create single compress private xform data */
+			ret = rte_compressdev_private_xform_create(0,
+				(const struct rte_comp_xform *)compress_xform,
+				&priv_xforms[0]);
+			if (ret < 0) {
+				RTE_LOG(ERR, USER1,
+					"Compression private xform "
+					"could not be created\n");
+				goto exit;
+			}
+			num_priv_xforms++;
+			/* Attach shareable private xform data to ops */
+			for (i = 0; i < num_bufs; i++)
+				ops[i]->private_xform = priv_xforms[0];
+		} else {
+			/* Create compress private xform data per op */
+			for (i = 0; i < num_bufs; i++) {
+				ret = rte_compressdev_private_xform_create(0,
+					compress_xform, &priv_xforms[i]);
+				if (ret < 0) {
+					RTE_LOG(ERR, USER1,
+						"Compression private xform "
+						"could not be created\n");
+					goto exit;
+				}
+				num_priv_xforms++;
+			}
 
-		/* Attach xform private data to operation */
-		op->private_xform = priv_xform;
+			/* Attach non shareable private xform data to ops */
+			for (i = 0; i < num_bufs; i++)
+				ops[i]->private_xform = priv_xforms[i];
+		}
 
 		/* Enqueue and dequeue all operations */
-		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
-		if (ret == 0) {
+		num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
+		if (num_enqd < num_bufs) {
 			RTE_LOG(ERR, USER1,
-				"The operation could not be enqueued\n");
+				"The operations could not be enqueued\n");
 			goto exit;
 		}
+
+		num_total_deqd = 0;
 		do {
 			/*
 			 * If retrying a dequeue call, wait for 10 ms to allow
@@ -454,121 +512,168 @@ test_deflate_comp_decomp(const char *test_buffer,
 				usleep(DEQUEUE_WAIT_TIME);
 			}
 			num_deqd = rte_compressdev_dequeue_burst(0, 0,
-					&op_processed, 1);
-
+					&ops_processed[num_total_deqd], num_bufs);
+			num_total_deqd += num_deqd;
 			deqd_retries++;
-		} while (num_deqd < 1);
+		} while (num_total_deqd < num_enqd);
 
 		deqd_retries = 0;
 
-		/* Free compress private xform */
-		rte_compressdev_private_xform_free(0, priv_xform);
-		priv_xform = NULL;
+		/* Free compress private xforms */
+		for (i = 0; i < num_priv_xforms; i++) {
+			rte_compressdev_private_xform_free(0, priv_xforms[i]);
+			priv_xforms[i] = NULL;
+		}
+		num_priv_xforms = 0;
 	}
 
 	enum rte_comp_huffman huffman_type =
 		compress_xform->compress.deflate.huffman;
-	RTE_LOG(DEBUG, USER1, "Buffer compressed from %u to %u bytes "
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		RTE_LOG(DEBUG, USER1, "Buffer %u compressed from %u to %u bytes "
 			"(level = %u, huffman = %s)\n",
-			op_processed->consumed, op_processed->produced,
+			buf_idx[priv_data->orig_idx],
+			ops_processed[i]->consumed, ops_processed[i]->produced,
 			compress_xform->compress.level,
 			huffman_type_strings[huffman_type]);
-	RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
-			(float)op_processed->produced /
-			op_processed->consumed * 100);
-	op = NULL;
+		RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
+			(float)ops_processed[i]->produced /
+			ops_processed[i]->consumed * 100);
+		ops[i] = NULL;
+	}
 
 	/*
-	 * Check operation status and free source mbuf (destination mbuf and
+	 * Check operation status and free source mbufs (destination mbuf and
 	 * compress operation information is needed for the decompression stage)
 	 */
-	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
-		RTE_LOG(ERR, USER1,
-			"Some operations were not successful\n");
-		goto exit;
+	for (i = 0; i < num_bufs; i++) {
+		if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
+			RTE_LOG(ERR, USER1,
+				"Some operations were not successful\n");
+			goto exit;
+		}
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		rte_pktmbuf_free(uncomp_bufs[priv_data->orig_idx]);
+		uncomp_bufs[priv_data->orig_idx] = NULL;
 	}
-	rte_pktmbuf_free(uncomp_buf);
-	uncomp_buf = NULL;
 
-	/* Allocate buffer for decompressed data */
-	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
-	if (uncomp_buf == NULL) {
+	/* Allocate buffers for decompressed data */
+	ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, uncomp_bufs, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Destination mbuf could not be allocated "
+			"Destination mbufs could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		rte_pktmbuf_append(uncomp_bufs[i],
+				strlen(test_bufs[priv_data->orig_idx]) + 1);
+	}
 
 	/* Build the decompression operations */
-	op = rte_comp_op_alloc(ts_params->op_pool);
-	if (op == NULL) {
+	ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
-			"Decompress operation could not be allocated "
+			"Decompress operations could not be allocated "
 			"from the mempool\n");
 		goto exit;
 	}
 
-	/* Source buffer is the compressed data from the previous operation */
-	op->m_src = op_processed->m_dst;
-	op->m_dst = uncomp_buf;
-	op->src.offset = 0;
-	/*
-	 * Set the length of the compressed data to the
-	 * number of bytes that were produced in the previous stage
-	 */
-	op->src.length = op_processed->produced;
-	op->dst.offset = 0;
-	if (state == RTE_COMP_OP_STATELESS) {
-		//TODO: FULL or FINAL?
-		op->flush_flag = RTE_COMP_FLUSH_FINAL;
-	} else {
-		RTE_LOG(ERR, USER1,
-			"Stateful operations are not supported "
-			"in these tests yet\n");
-		goto exit;
+	/* Source buffer is the compressed data from the previous operations */
+	for (i = 0; i < num_bufs; i++) {
+		ops[i]->m_src = ops_processed[i]->m_dst;
+		ops[i]->m_dst = uncomp_bufs[i];
+		ops[i]->src.offset = 0;
+		/*
+		 * Set the length of the compressed data to the
+		 * number of bytes that were produced in the previous stage
+		 */
+		ops[i]->src.length = ops_processed[i]->produced;
+		ops[i]->dst.offset = 0;
+		if (state == RTE_COMP_OP_STATELESS) {
+			//TODO: FULL or FINAL?
+			ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
+		} else {
+			RTE_LOG(ERR, USER1,
+				"Stateful operations are not supported "
+				"in these tests yet\n");
+			goto exit;
+		}
+		ops[i]->input_chksum = 0;
+		/*
+		 * Copy private data from previous operations,
+		 * to keep the pointer to the original buffer
+		 */
+		memcpy(ops[i] + 1, ops_processed[i] + 1,
+				sizeof(struct priv_op_data));
 	}
-	op->input_chksum = 0;
 
 	/*
-	 * Free the previous compress operation,
+	 * Free the previous compress operations,
 	 * as it is not needed anymore
 	 */
-	rte_comp_op_free(op_processed);
-	op_processed = NULL;
+	for (i = 0; i < num_bufs; i++) {
+		rte_comp_op_free(ops_processed[i]);
+		ops_processed[i] = NULL;
+	}
 
 	/* Decompress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
-		ret = decompress_zlib(op,
-			(const struct rte_comp_xform *)&decompress_xform);
-		if (ret < 0)
-			goto exit;
+		for (i = 0; i < num_bufs; i++) {
+			ret = decompress_zlib(ops[i],
+				(const struct rte_comp_xform *)decompress_xform);
+			if (ret < 0)
+				goto exit;
 
-		op_processed = op;
-	} else {
-		num_deqd = 0;
-		/* Create decompress xform private data */
-		ret = rte_compressdev_private_xform_create(0,
-			(const struct rte_comp_xform *)decompress_xform,
-			&priv_xform);
-		if (ret < 0) {
-			RTE_LOG(ERR, USER1,
-				"Decompression private xform "
-				"could not be created\n");
-			goto exit;
+			ops_processed[i] = ops[i];
 		}
+	} else {
+		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
+			/* Create single decompress private xform data */
+			ret = rte_compressdev_private_xform_create(0,
+				(const struct rte_comp_xform *)decompress_xform,
+				&priv_xforms[0]);
+			if (ret < 0) {
+				RTE_LOG(ERR, USER1,
+					"Decompression private xform "
+					"could not be created\n");
+				goto exit;
+			}
+			num_priv_xforms++;
+			/* Attach shareable private xform data to ops */
+			for (i = 0; i < num_bufs; i++)
+				ops[i]->private_xform = priv_xforms[0];
+		} else {
+			/* Create decompress private xform data per op */
+			for (i = 0; i < num_bufs; i++) {
+				ret = rte_compressdev_private_xform_create(0,
+					decompress_xform, &priv_xforms[i]);
+				if (ret < 0) {
+					RTE_LOG(ERR, USER1,
+						"Deompression private xform "
+						"could not be created\n");
+					goto exit;
+				}
+				num_priv_xforms++;
+			}
 
-		/* Attach xform private data to operation */
-		op->private_xform = priv_xform;
+			/* Attach non shareable private xform data to ops */
+			for (i = 0; i < num_bufs; i++)
+				ops[i]->private_xform = priv_xforms[i];
+		}
 
 		/* Enqueue and dequeue all operations */
-		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
-		if (ret == 0) {
+		num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
+		if (num_enqd < num_bufs) {
 			RTE_LOG(ERR, USER1,
-				"The operation could not be enqueued\n");
+				"The operations could not be enqueued\n");
 			goto exit;
 		}
+
+		num_total_deqd = 0;
 		do {
 			/*
 			 * If retrying a dequeue call, wait for 10 ms to allow
@@ -588,47 +693,66 @@ test_deflate_comp_decomp(const char *test_buffer,
 				usleep(DEQUEUE_WAIT_TIME);
 			}
 			num_deqd = rte_compressdev_dequeue_burst(0, 0,
-					&op_processed, 1);
-
+					&ops_processed[num_total_deqd], num_bufs);
+			num_total_deqd += num_deqd;
 			deqd_retries++;
-		} while (num_deqd < 1);
+		} while (num_total_deqd < num_enqd);
+
+		deqd_retries = 0;
+	}
+
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		RTE_LOG(DEBUG, USER1, "Buffer %u decompressed from %u to %u bytes\n",
+			buf_idx[priv_data->orig_idx],
+			ops_processed[i]->consumed, ops_processed[i]->produced);
+		ops[i] = NULL;
 	}
 
-	RTE_LOG(DEBUG, USER1, "Buffer decompressed from %u to %u bytes\n",
-			op_processed->consumed, op_processed->produced);
-	op = NULL;
 	/*
 	 * Check operation status and free source mbuf (destination mbuf and
 	 * compress operation information is still needed)
 	 */
-	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
-		RTE_LOG(ERR, USER1,
-			"Some operations were not successful\n");
-		goto exit;
+	for (i = 0; i < num_bufs; i++) {
+		if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
+			RTE_LOG(ERR, USER1,
+				"Some operations were not successful\n");
+			goto exit;
+		}
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		rte_pktmbuf_free(comp_bufs[priv_data->orig_idx]);
+		comp_bufs[priv_data->orig_idx] = NULL;
 	}
-	rte_pktmbuf_free(comp_buf);
-	comp_buf = NULL;
 
 	/*
 	 * Compare the original stream with the decompressed stream
 	 * (in size and the data)
 	 */
-	if (compare_buffers(test_buffer, strlen(test_buffer) + 1,
-			rte_pktmbuf_mtod(op_processed->m_dst, const char *),
-			op_processed->produced) < 0)
-		goto exit;
+	for (i = 0; i < num_bufs; i++) {
+		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		const char *buf1 = test_bufs[priv_data->orig_idx];
+		const char *buf2 = rte_pktmbuf_mtod(ops_processed[i]->m_dst,
+				const char *);
+
+		if (compare_buffers(buf1, strlen(buf1) + 1,
+				buf2, ops_processed[i]->produced) < 0)
+			goto exit;
+	}
 
 	ret_status = 0;
 
 exit:
 	/* Free resources */
-	rte_pktmbuf_free(uncomp_buf);
-	rte_pktmbuf_free(comp_buf);
-	rte_comp_op_free(op);
-	rte_comp_op_free(op_processed);
-
-	if (priv_xform != NULL)
-		rte_compressdev_private_xform_free(0, priv_xform);
+	for (i = 0; i < num_bufs; i++) {
+		rte_pktmbuf_free(uncomp_bufs[i]);
+		rte_pktmbuf_free(comp_bufs[i]);
+		rte_comp_op_free(ops[i]);
+		rte_comp_op_free(ops_processed[i]);
+	}
+	for (i = 0; i < num_priv_xforms; i++) {
+		if (priv_xforms[i] != NULL)
+			rte_compressdev_private_xform_free(0, priv_xforms[i]);
+	}
 
 	return ret_status;
 }
@@ -649,7 +773,8 @@ test_compressdev_deflate_stateless_fixed(void)
 		test_buffer = compress_test_bufs[i];
 
 		/* Compress with compressdev, decompress with Zlib */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -657,7 +782,8 @@ test_compressdev_deflate_stateless_fixed(void)
 			return TEST_FAILED;
 
 		/* Compress with Zlib, decompress with compressdev */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -684,7 +810,8 @@ test_compressdev_deflate_stateless_dynamic(void)
 		test_buffer = compress_test_bufs[i];
 
 		/* Compress with compressdev, decompress with Zlib */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -692,7 +819,8 @@ test_compressdev_deflate_stateless_dynamic(void)
 			return TEST_FAILED;
 
 		/* Compress with Zlib, decompress with compressdev */
-		if (test_deflate_comp_decomp(test_buffer,
+		if (test_deflate_comp_decomp(&test_buffer, 1,
+				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
 				RTE_COMP_OP_STATELESS,
@@ -703,6 +831,38 @@ test_compressdev_deflate_stateless_dynamic(void)
 	return TEST_SUCCESS;
 }
 
+static int
+test_compressdev_deflate_stateless_multi_op(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	uint16_t num_bufs = RTE_DIM(compress_test_bufs);
+	uint16_t buf_idx[num_bufs];
+	uint16_t i;
+
+	for (i = 0; i < num_bufs; i++)
+		buf_idx[i] = i;
+
+	/* Compress with compressdev, decompress with Zlib */
+	if (test_deflate_comp_decomp(compress_test_bufs, num_bufs,
+			buf_idx,
+			&ts_params->def_comp_xform,
+			&ts_params->def_decomp_xform,
+			RTE_COMP_OP_STATELESS,
+			ZLIB_DECOMPRESS) < 0)
+		return TEST_FAILED;
+
+	/* Compress with Zlib, decompress with compressdev */
+	if (test_deflate_comp_decomp(compress_test_bufs, num_bufs,
+			buf_idx,
+			&ts_params->def_comp_xform,
+			&ts_params->def_decomp_xform,
+			RTE_COMP_OP_STATELESS,
+			ZLIB_COMPRESS) < 0)
+		return TEST_FAILED;
+
+	return TEST_SUCCESS;
+}
+
 static struct unit_test_suite compressdev_testsuite  = {
 	.suite_name = "compressdev unit test suite",
 	.setup = testsuite_setup,
@@ -712,6 +872,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 			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_multi_op),
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };
-- 
2.17.0

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v4 3/5] test/compress: add multi level test
  2018-05-04 10:22 ` [dpdk-dev] [PATCH v4 " Pablo de Lara
  2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 1/5] test/compress: add initial " Pablo de Lara
  2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 2/5] test/compress: add multi op test Pablo de Lara
@ 2018-05-04 10:22   ` Pablo de Lara
  2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 4/5] test/compress: add multi xform test Pablo de Lara
                     ` (3 subsequent siblings)
  6 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-05-04 10:22 UTC (permalink / raw)
  To: dev
  Cc: fiona.trahe, lee.daly, shally.verma, ahmed.mansour, Ashish.Gupta,
	Pablo de Lara

Add test that checks if all compression levels
are supported and compress a buffer correctly.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Lee Daly <lee.daly@intel.com>
---
 test/test/test_compressdev.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index 629509f9b..28e2913e7 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -863,6 +863,37 @@ test_compressdev_deflate_stateless_multi_op(void)
 	return TEST_SUCCESS;
 }
 
+
+static int
+test_compressdev_deflate_stateless_multi_level(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	const char *test_buffer;
+	unsigned int level;
+	uint16_t i;
+	struct rte_comp_xform compress_xform;
+
+	memcpy(&compress_xform, &ts_params->def_comp_xform,
+			sizeof(struct rte_comp_xform));
+
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+		test_buffer = compress_test_bufs[i];
+		for (level = RTE_COMP_LEVEL_MIN; level <= RTE_COMP_LEVEL_MAX;
+				level++) {
+			compress_xform.compress.level = level;
+			/* Compress with compressdev, decompress with Zlib */
+			if (test_deflate_comp_decomp(&test_buffer, 1,
+					&i,
+					&compress_xform,
+					&ts_params->def_decomp_xform,
+					RTE_COMP_OP_STATELESS,
+					ZLIB_DECOMPRESS) < 0)
+				return TEST_FAILED;
+		}
+	}
+
+	return TEST_SUCCESS;
+}
 static struct unit_test_suite compressdev_testsuite  = {
 	.suite_name = "compressdev unit test suite",
 	.setup = testsuite_setup,
@@ -874,6 +905,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 			test_compressdev_deflate_stateless_dynamic),
 		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_CASES_END() /**< NULL terminate unit test array */
 	}
 };
-- 
2.17.0

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v4 4/5] test/compress: add multi xform test
  2018-05-04 10:22 ` [dpdk-dev] [PATCH v4 " Pablo de Lara
                     ` (2 preceding siblings ...)
  2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 3/5] test/compress: add multi level test Pablo de Lara
@ 2018-05-04 10:22   ` Pablo de Lara
  2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 5/5] test/compress: add invalid configuration tests Pablo de Lara
                     ` (2 subsequent siblings)
  6 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-05-04 10:22 UTC (permalink / raw)
  To: dev
  Cc: fiona.trahe, lee.daly, shally.verma, ahmed.mansour, Ashish.Gupta,
	Pablo de Lara

Add test that checks if multiple xforms can be
handled on a single enqueue call.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Lee Daly <lee.daly@intel.com>
---
 test/test/test_compressdev.c | 302 +++++++++++++++++++++++++++--------
 1 file changed, 236 insertions(+), 66 deletions(-)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index 28e2913e7..1f54263ed 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -27,7 +27,7 @@
 #define COMPRESS_BUF_SIZE_RATIO 1.3
 #define NUM_MBUFS 16
 #define NUM_OPS 16
-#define NUM_MAX_XFORMS 1
+#define NUM_MAX_XFORMS 16
 #define NUM_MAX_INFLIGHT_OPS 128
 #define CACHE_SIZE 0
 
@@ -52,8 +52,8 @@ struct priv_op_data {
 struct comp_testsuite_params {
 	struct rte_mempool *mbuf_pool;
 	struct rte_mempool *op_pool;
-	struct rte_comp_xform def_comp_xform;
-	struct rte_comp_xform def_decomp_xform;
+	struct rte_comp_xform *def_comp_xform;
+	struct rte_comp_xform *def_decomp_xform;
 };
 
 static struct comp_testsuite_params testsuite_params = { 0 };
@@ -65,6 +65,8 @@ testsuite_teardown(void)
 
 	rte_mempool_free(ts_params->mbuf_pool);
 	rte_mempool_free(ts_params->op_pool);
+	rte_free(ts_params->def_comp_xform);
+	rte_free(ts_params->def_decomp_xform);
 }
 
 static int
@@ -108,19 +110,34 @@ testsuite_setup(void)
 		goto exit;
 	}
 
+	ts_params->def_comp_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
+	if (ts_params->def_comp_xform == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Default compress xform could not be created\n");
+		goto exit;
+	}
+	ts_params->def_decomp_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
+	if (ts_params->def_decomp_xform == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Default decompress xform could not be created\n");
+		goto exit;
+	}
+
 	/* Initializes default values for compress/decompress xforms */
-	ts_params->def_comp_xform.type = RTE_COMP_COMPRESS;
-	ts_params->def_comp_xform.compress.algo = RTE_COMP_ALGO_DEFLATE,
-	ts_params->def_comp_xform.compress.deflate.huffman =
+	ts_params->def_comp_xform->type = RTE_COMP_COMPRESS;
+	ts_params->def_comp_xform->compress.algo = RTE_COMP_ALGO_DEFLATE,
+	ts_params->def_comp_xform->compress.deflate.huffman =
 						RTE_COMP_HUFFMAN_DEFAULT;
-	ts_params->def_comp_xform.compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
-	ts_params->def_comp_xform.compress.chksum = RTE_COMP_CHECKSUM_NONE;
-	ts_params->def_comp_xform.compress.window_size = DEFAULT_WINDOW_SIZE;
+	ts_params->def_comp_xform->compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
+	ts_params->def_comp_xform->compress.chksum = RTE_COMP_CHECKSUM_NONE;
+	ts_params->def_comp_xform->compress.window_size = DEFAULT_WINDOW_SIZE;
 
-	ts_params->def_decomp_xform.type = RTE_COMP_DECOMPRESS;
-	ts_params->def_decomp_xform.decompress.algo = RTE_COMP_ALGO_DEFLATE,
-	ts_params->def_decomp_xform.decompress.chksum = RTE_COMP_CHECKSUM_NONE;
-	ts_params->def_decomp_xform.decompress.window_size = DEFAULT_WINDOW_SIZE;
+	ts_params->def_decomp_xform->type = RTE_COMP_DECOMPRESS;
+	ts_params->def_decomp_xform->decompress.algo = RTE_COMP_ALGO_DEFLATE,
+	ts_params->def_decomp_xform->decompress.chksum = RTE_COMP_CHECKSUM_NONE;
+	ts_params->def_decomp_xform->decompress.window_size = DEFAULT_WINDOW_SIZE;
 
 	return TEST_SUCCESS;
 
@@ -345,8 +362,9 @@ static int
 test_deflate_comp_decomp(const char * const test_bufs[],
 		unsigned int num_bufs,
 		uint16_t buf_idx[],
-		struct rte_comp_xform *compress_xform,
-		struct rte_comp_xform *decompress_xform,
+		struct rte_comp_xform *compress_xforms[],
+		struct rte_comp_xform *decompress_xforms[],
+		unsigned int num_xforms,
 		enum rte_comp_op_type state,
 		enum zlib_direction zlib_dir)
 {
@@ -441,8 +459,9 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 	/* Compress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
 		for (i = 0; i < num_bufs; i++) {
-			ret = compress_zlib(ops[i],
-				(const struct rte_comp_xform *)compress_xform,
+			const struct rte_comp_xform *compress_xform =
+				compress_xforms[i % num_xforms];
+			ret = compress_zlib(ops[i], compress_xform,
 					DEFAULT_MEM_LEVEL);
 			if (ret < 0)
 				goto exit;
@@ -450,11 +469,11 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 			ops_processed[i] = ops[i];
 		}
 	} else {
-		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
-			/* Create single compress private xform data */
+		/* Create compress private xform data */
+		for (i = 0; i < num_xforms; i++) {
 			ret = rte_compressdev_private_xform_create(0,
-				(const struct rte_comp_xform *)compress_xform,
-				&priv_xforms[0]);
+				(const struct rte_comp_xform *)compress_xforms[i],
+				&priv_xforms[i]);
 			if (ret < 0) {
 				RTE_LOG(ERR, USER1,
 					"Compression private xform "
@@ -462,14 +481,18 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 				goto exit;
 			}
 			num_priv_xforms++;
+		}
+
+		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
 			/* Attach shareable private xform data to ops */
 			for (i = 0; i < num_bufs; i++)
-				ops[i]->private_xform = priv_xforms[0];
+				ops[i]->private_xform = priv_xforms[i % num_xforms];
 		} else {
-			/* Create compress private xform data per op */
-			for (i = 0; i < num_bufs; i++) {
+			/* Create rest of the private xforms for the other ops */
+			for (i = num_xforms; i < num_bufs; i++) {
 				ret = rte_compressdev_private_xform_create(0,
-					compress_xform, &priv_xforms[i]);
+					compress_xforms[i % num_xforms],
+					&priv_xforms[i]);
 				if (ret < 0) {
 					RTE_LOG(ERR, USER1,
 						"Compression private xform "
@@ -527,15 +550,18 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 		num_priv_xforms = 0;
 	}
 
-	enum rte_comp_huffman huffman_type =
-		compress_xform->compress.deflate.huffman;
 	for (i = 0; i < num_bufs; i++) {
 		priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
+		uint16_t xform_idx = priv_data->orig_idx % num_xforms;
+		const struct rte_comp_compress_xform *compress_xform =
+				&compress_xforms[xform_idx]->compress;
+		enum rte_comp_huffman huffman_type =
+			compress_xform->deflate.huffman;
 		RTE_LOG(DEBUG, USER1, "Buffer %u compressed from %u to %u bytes "
-			"(level = %u, huffman = %s)\n",
+			"(level = %d, huffman = %s)\n",
 			buf_idx[priv_data->orig_idx],
 			ops_processed[i]->consumed, ops_processed[i]->produced,
-			compress_xform->compress.level,
+			compress_xform->level,
 			huffman_type_strings[huffman_type]);
 		RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
 			(float)ops_processed[i]->produced /
@@ -623,19 +649,23 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 	/* Decompress data (either with Zlib API or compressdev API */
 	if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
 		for (i = 0; i < num_bufs; i++) {
-			ret = decompress_zlib(ops[i],
-				(const struct rte_comp_xform *)decompress_xform);
+			priv_data = (struct priv_op_data *)(ops[i] + 1);
+			uint16_t xform_idx = priv_data->orig_idx % num_xforms;
+			const struct rte_comp_xform *decompress_xform =
+				decompress_xforms[xform_idx];
+
+			ret = decompress_zlib(ops[i], decompress_xform);
 			if (ret < 0)
 				goto exit;
 
 			ops_processed[i] = ops[i];
 		}
 	} else {
-		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
-			/* Create single decompress private xform data */
+		/* Create decompress private xform data */
+		for (i = 0; i < num_xforms; i++) {
 			ret = rte_compressdev_private_xform_create(0,
-				(const struct rte_comp_xform *)decompress_xform,
-				&priv_xforms[0]);
+				(const struct rte_comp_xform *)decompress_xforms[i],
+				&priv_xforms[i]);
 			if (ret < 0) {
 				RTE_LOG(ERR, USER1,
 					"Decompression private xform "
@@ -643,17 +673,25 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 				goto exit;
 			}
 			num_priv_xforms++;
+		}
+
+		if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
 			/* Attach shareable private xform data to ops */
-			for (i = 0; i < num_bufs; i++)
-				ops[i]->private_xform = priv_xforms[0];
-		} else {
-			/* Create decompress private xform data per op */
 			for (i = 0; i < num_bufs; i++) {
+				priv_data = (struct priv_op_data *)(ops[i] + 1);
+				uint16_t xform_idx = priv_data->orig_idx %
+								num_xforms;
+				ops[i]->private_xform = priv_xforms[xform_idx];
+			}
+		} else {
+			/* Create rest of the private xforms for the other ops */
+			for (i = num_xforms; i < num_bufs; i++) {
 				ret = rte_compressdev_private_xform_create(0,
-					decompress_xform, &priv_xforms[i]);
+					decompress_xforms[i % num_xforms],
+					&priv_xforms[i]);
 				if (ret < 0) {
 					RTE_LOG(ERR, USER1,
-						"Deompression private xform "
+						"Decompression private xform "
 						"could not be created\n");
 					goto exit;
 				}
@@ -661,8 +699,11 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 			}
 
 			/* Attach non shareable private xform data to ops */
-			for (i = 0; i < num_bufs; i++)
-				ops[i]->private_xform = priv_xforms[i];
+			for (i = 0; i < num_bufs; i++) {
+				priv_data = (struct priv_op_data *) (ops[i] + 1);
+				uint16_t xform_idx = priv_data->orig_idx;
+				ops[i]->private_xform = priv_xforms[xform_idx];
+			}
 		}
 
 		/* Enqueue and dequeue all operations */
@@ -763,11 +804,20 @@ test_compressdev_deflate_stateless_fixed(void)
 	struct comp_testsuite_params *ts_params = &testsuite_params;
 	const char *test_buffer;
 	uint16_t i;
-	struct rte_comp_xform compress_xform;
+	int ret;
+	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,
+	memcpy(compress_xform, ts_params->def_comp_xform,
 			sizeof(struct rte_comp_xform));
-	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
+	compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
 		test_buffer = compress_test_bufs[i];
@@ -777,21 +827,31 @@ test_compressdev_deflate_stateless_fixed(void)
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_DECOMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_DECOMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 
 		/* Compress with Zlib, decompress with compressdev */
 		if (test_deflate_comp_decomp(&test_buffer, 1,
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_COMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_COMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 	}
 
-	return TEST_SUCCESS;
+	ret = TEST_SUCCESS;
+
+exit:
+	rte_free(compress_xform);
+	return ret;
 }
 
 static int
@@ -800,11 +860,20 @@ test_compressdev_deflate_stateless_dynamic(void)
 	struct comp_testsuite_params *ts_params = &testsuite_params;
 	const char *test_buffer;
 	uint16_t i;
-	struct rte_comp_xform compress_xform;
+	int ret;
+	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,
+	memcpy(compress_xform, ts_params->def_comp_xform,
 			sizeof(struct rte_comp_xform));
-	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
+	compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
 		test_buffer = compress_test_bufs[i];
@@ -814,21 +883,31 @@ test_compressdev_deflate_stateless_dynamic(void)
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_DECOMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_DECOMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 
 		/* Compress with Zlib, decompress with compressdev */
 		if (test_deflate_comp_decomp(&test_buffer, 1,
 				&i,
 				&compress_xform,
 				&ts_params->def_decomp_xform,
+				1,
 				RTE_COMP_OP_STATELESS,
-				ZLIB_COMPRESS) < 0)
-			return TEST_FAILED;
+				ZLIB_COMPRESS) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
 	}
 
-	return TEST_SUCCESS;
+	ret = TEST_SUCCESS;
+
+exit:
+	rte_free(compress_xform);
+	return ret;
 }
 
 static int
@@ -847,6 +926,7 @@ test_compressdev_deflate_stateless_multi_op(void)
 			buf_idx,
 			&ts_params->def_comp_xform,
 			&ts_params->def_decomp_xform,
+			1,
 			RTE_COMP_OP_STATELESS,
 			ZLIB_DECOMPRESS) < 0)
 		return TEST_FAILED;
@@ -856,6 +936,7 @@ test_compressdev_deflate_stateless_multi_op(void)
 			buf_idx,
 			&ts_params->def_comp_xform,
 			&ts_params->def_decomp_xform,
+			1,
 			RTE_COMP_OP_STATELESS,
 			ZLIB_COMPRESS) < 0)
 		return TEST_FAILED;
@@ -863,7 +944,6 @@ test_compressdev_deflate_stateless_multi_op(void)
 	return TEST_SUCCESS;
 }
 
-
 static int
 test_compressdev_deflate_stateless_multi_level(void)
 {
@@ -871,29 +951,117 @@ test_compressdev_deflate_stateless_multi_level(void)
 	const char *test_buffer;
 	unsigned int level;
 	uint16_t i;
-	struct rte_comp_xform compress_xform;
+	int ret;
+	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,
+	memcpy(compress_xform, ts_params->def_comp_xform,
 			sizeof(struct rte_comp_xform));
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
 		test_buffer = compress_test_bufs[i];
 		for (level = RTE_COMP_LEVEL_MIN; level <= RTE_COMP_LEVEL_MAX;
 				level++) {
-			compress_xform.compress.level = level;
+			compress_xform->compress.level = level;
 			/* Compress with compressdev, decompress with Zlib */
 			if (test_deflate_comp_decomp(&test_buffer, 1,
 					&i,
 					&compress_xform,
 					&ts_params->def_decomp_xform,
+					1,
 					RTE_COMP_OP_STATELESS,
-					ZLIB_DECOMPRESS) < 0)
-				return TEST_FAILED;
+					ZLIB_DECOMPRESS) < 0) {
+				ret = TEST_FAILED;
+				goto exit;
+			}
 		}
 	}
 
-	return TEST_SUCCESS;
+	ret = TEST_SUCCESS;
+
+exit:
+	rte_free(compress_xform);
+	return ret;
+}
+
+#define NUM_XFORMS 3
+static int
+test_compressdev_deflate_stateless_multi_xform(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	uint16_t num_bufs = NUM_XFORMS;
+	struct rte_comp_xform *compress_xforms[NUM_XFORMS] = {NULL};
+	struct rte_comp_xform *decompress_xforms[NUM_XFORMS] = {NULL};
+	const char *test_buffers[NUM_XFORMS];
+	uint16_t i;
+	unsigned int level = RTE_COMP_LEVEL_MIN;
+	uint16_t buf_idx[num_bufs];
+
+	int ret;
+
+	/* Create multiple xforms with various levels */
+	for (i = 0; i < NUM_XFORMS; i++) {
+		compress_xforms[i] = rte_malloc(NULL,
+				sizeof(struct rte_comp_xform), 0);
+		if (compress_xforms[i] == NULL) {
+			RTE_LOG(ERR, USER1,
+				"Compress xform could not be created\n");
+			ret = TEST_FAILED;
+			goto exit;
+		}
+
+		memcpy(compress_xforms[i], ts_params->def_comp_xform,
+				sizeof(struct rte_comp_xform));
+		compress_xforms[i]->compress.level = level;
+		level++;
+
+		decompress_xforms[i] = rte_malloc(NULL,
+				sizeof(struct rte_comp_xform), 0);
+		if (decompress_xforms[i] == NULL) {
+			RTE_LOG(ERR, USER1,
+				"Decompress xform could not be created\n");
+			ret = TEST_FAILED;
+			goto exit;
+		}
+
+		memcpy(decompress_xforms[i], ts_params->def_decomp_xform,
+				sizeof(struct rte_comp_xform));
+	}
+
+	for (i = 0; i < NUM_XFORMS; i++) {
+		buf_idx[i] = 0;
+		/* Use the same buffer in all sessions */
+		test_buffers[i] = compress_test_bufs[0];
+	}
+	/* Compress with compressdev, decompress with Zlib */
+	if (test_deflate_comp_decomp(test_buffers, num_bufs,
+			buf_idx,
+			compress_xforms,
+			decompress_xforms,
+			NUM_XFORMS,
+			RTE_COMP_OP_STATELESS,
+			ZLIB_DECOMPRESS) < 0) {
+		ret = TEST_FAILED;
+		goto exit;
+	}
+
+	ret = TEST_SUCCESS;
+exit:
+	for (i = 0; i < NUM_XFORMS; i++) {
+		rte_free(compress_xforms[i]);
+		rte_free(decompress_xforms[i]);
+	}
+
+	return ret;
 }
+
 static struct unit_test_suite compressdev_testsuite  = {
 	.suite_name = "compressdev unit test suite",
 	.setup = testsuite_setup,
@@ -907,6 +1075,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 			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_CASES_END() /**< NULL terminate unit test array */
 	}
 };
-- 
2.17.0

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [dpdk-dev] [PATCH v4 5/5] test/compress: add invalid configuration tests
  2018-05-04 10:22 ` [dpdk-dev] [PATCH v4 " Pablo de Lara
                     ` (3 preceding siblings ...)
  2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 4/5] test/compress: add multi xform test Pablo de Lara
@ 2018-05-04 10:22   ` Pablo de Lara
  2018-05-08 15:47   ` [dpdk-dev] [PATCH v4 0/5] Initial compressdev unit tests Trahe, Fiona
  2018-05-08 21:26   ` De Lara Guarch, Pablo
  6 siblings, 0 replies; 32+ messages in thread
From: Pablo de Lara @ 2018-05-04 10:22 UTC (permalink / raw)
  To: dev
  Cc: fiona.trahe, lee.daly, shally.verma, ahmed.mansour, Ashish.Gupta,
	Pablo de Lara

Add tests that check if device configuration
is not successful when providing invalid parameters.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Lee Daly <lee.daly@intel.com>
---
 test/test/test_compressdev.c | 49 +++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index 1f54263ed..210f87afe 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -185,6 +185,51 @@ generic_ut_teardown(void)
 		RTE_LOG(ERR, USER1, "Device could not be closed\n");
 }
 
+static int
+test_compressdev_invalid_configuration(void)
+{
+	struct rte_compressdev_config invalid_config;
+	struct rte_compressdev_config valid_config = {
+		.socket_id = rte_socket_id(),
+		.nb_queue_pairs = 1,
+		.max_nb_priv_xforms = NUM_MAX_XFORMS,
+		.max_nb_streams = 0
+	};
+	struct rte_compressdev_info dev_info;
+
+	/* Invalid configuration with 0 queue pairs */
+	memcpy(&invalid_config, &valid_config,
+			sizeof(struct rte_compressdev_config));
+	invalid_config.nb_queue_pairs = 0;
+
+	TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
+			"Device configuration was successful "
+			"with no queue pairs (invalid)\n");
+
+	/*
+	 * Invalid configuration with too many queue pairs
+	 * (if there is an actual maximum number of queue pairs)
+	 */
+	rte_compressdev_info_get(0, &dev_info);
+	if (dev_info.max_nb_queue_pairs != 0) {
+		memcpy(&invalid_config, &valid_config,
+			sizeof(struct rte_compressdev_config));
+		invalid_config.nb_queue_pairs = dev_info.max_nb_queue_pairs + 1;
+
+		TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
+				"Device configuration was successful "
+				"with too many queue pairs (invalid)\n");
+	}
+
+	/* Invalid queue pair setup, with no number of queue pairs set */
+	TEST_ASSERT_FAIL(rte_compressdev_queue_pair_setup(0, 0,
+				NUM_MAX_INFLIGHT_OPS, rte_socket_id()),
+			"Queue pair setup was successful "
+			"with no queue pairs set (invalid)\n");
+
+	return TEST_SUCCESS;
+}
+
 static int
 compare_buffers(const char *buffer1, uint32_t buffer1_len,
 		const char *buffer2, uint32_t buffer2_len)
@@ -700,7 +745,7 @@ test_deflate_comp_decomp(const char * const test_bufs[],
 
 			/* Attach non shareable private xform data to ops */
 			for (i = 0; i < num_bufs; i++) {
-				priv_data = (struct priv_op_data *) (ops[i] + 1);
+				priv_data = (struct priv_op_data *)(ops[i] + 1);
 				uint16_t xform_idx = priv_data->orig_idx;
 				ops[i]->private_xform = priv_xforms[xform_idx];
 			}
@@ -1067,6 +1112,8 @@ static struct unit_test_suite compressdev_testsuite  = {
 	.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,
-- 
2.17.0

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [dpdk-dev] [PATCH v4 0/5] Initial compressdev unit tests
  2018-05-04 10:22 ` [dpdk-dev] [PATCH v4 " Pablo de Lara
                     ` (4 preceding siblings ...)
  2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 5/5] test/compress: add invalid configuration tests Pablo de Lara
@ 2018-05-08 15:47   ` Trahe, Fiona
  2018-05-08 21:26   ` De Lara Guarch, Pablo
  6 siblings, 0 replies; 32+ messages in thread
From: Trahe, Fiona @ 2018-05-08 15:47 UTC (permalink / raw)
  To: De Lara Guarch, Pablo, dev
  Cc: Daly, Lee, shally.verma, ahmed.mansour, Ashish.Gupta, Trahe, Fiona



> -----Original Message-----
> From: De Lara Guarch, Pablo
> Sent: Friday, May 4, 2018 11:22 AM
> To: dev@dpdk.org
> Cc: Trahe, Fiona <fiona.trahe@intel.com>; Daly, Lee <lee.daly@intel.com>; shally.verma@cavium.com;
> ahmed.mansour@nxp.com; Ashish.Gupta@cavium.com; De Lara Guarch, Pablo
> <pablo.de.lara.guarch@intel.com>
> Subject: [PATCH v4 0/5] Initial compressdev unit tests
> 
> Added initial tests for Compressdev library.
> The tests are performed compressing a test buffer (or multiple test buffers) with
> compressdev or Zlib, and decompressing it/them with the other library (if compression is
> done with compressdev, decompression is done with Zlib, and viceversa).
> 
> Tests added so far are based on the deflate algorithm,
> including:
> - Fixed huffman on single buffer
> - Dynamic huffman on single buffer
> - Multi compression level test on single buffer
> - Multi buffer
> - Multi xform using the same buffer
> 
> Due to a dependency on Zlib, the test is not enabled by default.
> Once the library is installed, the configuration option CONFIG_RTE_COMPRESSDEV_TEST must be set to Y.
> However, if building with Meson, the test will be built automatically, if Zlib is installed.
> 
> The test requires a compressdev PMD to be initialized, when running the test app. For example:
> 
> ./build/app/test --vdev="compress_X"
> 
> RTE>>compressdev_autotest
> 
> This patchset depends on the Compressdev API patchset:
> http://dpdk.org/ml/archives/dev/2018-April/099580.html
> ("[PATCH v6 00/14] Implement compression API")
> 
> Changes in v4:
> - Free memory when malloc fails
> 
> Changes in v3:
> - Remove next pointer in xform setting
> - Remove unneeded DIV_CEIL macro
> - Add rte_compressdev_close() call after finishing test cases
> 
> Changes in v2:
> - Add meson build
> - Add invalid configuration tests
> - Use new Compressdev API:
>   * Substitute session with priv xform
>   * Check if priv xform is shareable and create one per operation if not
> 
> Pablo de Lara (5):
>   test/compress: add initial unit tests
>   test/compress: add multi op test
>   test/compress: add multi level test
>   test/compress: add multi xform test
>   test/compress: add invalid configuration tests
> 
>  config/common_base                       |    5 +
>  test/test/Makefile                       |    9 +
>  test/test/meson.build                    |    8 +
>  test/test/test_compressdev.c             | 1137 ++++++++++++++++++++++
>  test/test/test_compressdev_test_buffer.h |  295 ++++++
>  5 files changed, 1454 insertions(+)
>  create mode 100644 test/test/test_compressdev.c
>  create mode 100644 test/test/test_compressdev_test_buffer.h
> 
> --
> 2.17.0
Series Acked-by: Fiona Trahe <fiona.trahe@intel.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [dpdk-dev] [PATCH v4 0/5] Initial compressdev unit tests
  2018-05-04 10:22 ` [dpdk-dev] [PATCH v4 " Pablo de Lara
                     ` (5 preceding siblings ...)
  2018-05-08 15:47   ` [dpdk-dev] [PATCH v4 0/5] Initial compressdev unit tests Trahe, Fiona
@ 2018-05-08 21:26   ` De Lara Guarch, Pablo
  6 siblings, 0 replies; 32+ messages in thread
From: De Lara Guarch, Pablo @ 2018-05-08 21:26 UTC (permalink / raw)
  To: dev; +Cc: Trahe, Fiona, Daly, Lee, shally.verma, ahmed.mansour, Ashish.Gupta



> -----Original Message-----
> From: De Lara Guarch, Pablo
> Sent: Friday, May 4, 2018 11:22 AM
> To: dev@dpdk.org
> Cc: Trahe, Fiona <fiona.trahe@intel.com>; Daly, Lee <lee.daly@intel.com>;
> shally.verma@cavium.com; ahmed.mansour@nxp.com;
> Ashish.Gupta@cavium.com; De Lara Guarch, Pablo
> <pablo.de.lara.guarch@intel.com>
> Subject: [PATCH v4 0/5] Initial compressdev unit tests
> 
> Added initial tests for Compressdev library.
> The tests are performed compressing a test buffer (or multiple test buffers) with
> compressdev or Zlib, and decompressing it/them with the other library (if
> compression is done with compressdev, decompression is done with Zlib, and
> viceversa).
> 
> Tests added so far are based on the deflate algorithm,
> including:
> - Fixed huffman on single buffer
> - Dynamic huffman on single buffer
> - Multi compression level test on single buffer
> - Multi buffer
> - Multi xform using the same buffer
> 
> Due to a dependency on Zlib, the test is not enabled by default.
> Once the library is installed, the configuration option
> CONFIG_RTE_COMPRESSDEV_TEST must be set to Y.
> However, if building with Meson, the test will be built automatically, if Zlib is
> installed.
> 

Applied to dpdk-next-crypto.
Thanks,

Pablo

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [dpdk-dev] [PATCH v4 1/5] test/compress: add initial unit tests
  2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 1/5] test/compress: add initial " Pablo de Lara
@ 2018-05-14  8:29     ` Verma, Shally
  2018-05-14  8:40       ` De Lara Guarch, Pablo
  0 siblings, 1 reply; 32+ messages in thread
From: Verma, Shally @ 2018-05-14  8:29 UTC (permalink / raw)
  To: Pablo de Lara, dev
  Cc: fiona.trahe, lee.daly, ahmed.mansour, Gupta, Ashish, Gupta, Ashish



>-----Original Message-----
>From: Pablo de Lara [mailto:pablo.de.lara.guarch@intel.com]
>Sent: 04 May 2018 15:52
>To: dev@dpdk.org
>Cc: fiona.trahe@intel.com; lee.daly@intel.com; Verma, Shally <Shally.Verma@cavium.com>; ahmed.mansour@nxp.com; Gupta,
>Ashish <Ashish.Gupta@cavium.com>; Pablo de Lara <pablo.de.lara.guarch@intel.com>; Gupta, Ashish <Ashish.Gupta@cavium.com>;
>Verma, Shally <Shally.Verma@cavium.com>
>Subject: [PATCH v4 1/5] test/compress: add initial unit tests
>
>This commit introduces the initial tests for compressdev,
>performing basic compression and decompression operations
>of sample test buffers, using the Zlib library in one direction
>and compressdev in another direction, to make sure that
>the library is compatible with Zlib.
>
>Due to the use of Zlib API, the test is disabled by default,
>to avoid adding a new dependency on DPDK.
>
>Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
>Signed-off-by: Ashish Gupta <ashish.gupta@caviumnetworks.com>
>Signed-off-by: Shally Verma <shally.verma@caviumnetworks.com>
>Acked-by: Lee Daly <lee.daly@intel.com>
>---
> config/common_base                       |   5 +
> test/test/Makefile                       |   9 +
> test/test/meson.build                    |   8 +
> test/test/test_compressdev.c             | 725 +++++++++++++++++++++++
> test/test/test_compressdev_test_buffer.h | 295 +++++++++
> 5 files changed, 1042 insertions(+)
> create mode 100644 test/test/test_compressdev.c
> create mode 100644 test/test/test_compressdev_test_buffer.h
>
//snip

>+ * Compresses and decompresses buffer with compressdev API and Zlib API
>+ */
>+static int
>+test_deflate_comp_decomp(const char *test_buffer,
>+		struct rte_comp_xform *compress_xform,
>+		struct rte_comp_xform *decompress_xform,
>+		enum rte_comp_op_type state,
>+		enum zlib_direction zlib_dir)
>+{
>+	struct comp_testsuite_params *ts_params = &testsuite_params;
>+	int ret_status = -1;
>+	int ret;
>+	struct rte_mbuf *comp_buf = NULL;
>+	struct rte_mbuf *uncomp_buf = NULL;
>+	struct rte_comp_op *op = NULL;
>+	struct rte_comp_op *op_processed = NULL;
>+	void *priv_xform = NULL;
>+	uint16_t num_deqd;
>+	unsigned int deqd_retries = 0;
>+	char *data_ptr;
>+
>+	/* Prepare the source mbuf with the data */
>+	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
>+	if (uncomp_buf == NULL) {
>+		RTE_LOG(ERR, USER1,
>+			"Source mbuf could not be allocated "
>+			"from the mempool\n");
>+		goto exit;
>+	}
>+
>+	data_ptr = rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
>+	snprintf(data_ptr, strlen(test_buffer) + 1, "%s", test_buffer);
>+
>+	/* Prepare the destination mbuf */
>+	comp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
>+	if (comp_buf == NULL) {
>+		RTE_LOG(ERR, USER1,
>+			"Destination mbuf could not be allocated "
>+			"from the mempool\n");
>+		goto exit;
>+	}
>+
>+	rte_pktmbuf_append(comp_buf,
>+			strlen(test_buffer) * COMPRESS_BUF_SIZE_RATIO);
>+
>+	/* Build the compression operations */
>+	op = rte_comp_op_alloc(ts_params->op_pool);
>+	if (op == NULL) {
>+		RTE_LOG(ERR, USER1,
>+			"Compress operation could not be allocated "
>+			"from the mempool\n");
>+		goto exit;
>+	}
>+
>+	op->m_src = uncomp_buf;
>+	op->m_dst = comp_buf;
>+	op->src.offset = 0;
>+	op->src.length = rte_pktmbuf_pkt_len(uncomp_buf);
>+	op->dst.offset = 0;
>+	if (state == RTE_COMP_OP_STATELESS) {
>+		//TODO: FULL or FINAL?
>+		op->flush_flag = RTE_COMP_FLUSH_FINAL;
>+	} else {
>+		RTE_LOG(ERR, USER1,
>+			"Stateful operations are not supported "
>+			"in these tests yet\n");
>+		goto exit;
>+	}
>+	op->input_chksum = 0;
>+
>+	/* Compress data (either with Zlib API or compressdev API */
>+	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
>+		ret = compress_zlib(op,
>+			(const struct rte_comp_xform *)&compress_xform,
[Shally] why are we passing ** here, compress_zlib() input rte_comp_xform*, this will cause a bug here. So, in call to decompress_zlib() below.

Thanks
Shally

>+			DEFAULT_MEM_LEVEL);
>+		if (ret < 0)
>+			goto exit;
>+
>+		op_processed = op;
>+	} else {
>+		/* Create compress xform private data */
>+		ret = rte_compressdev_private_xform_create(0,
>+			(const struct rte_comp_xform *)compress_xform,
>+			&priv_xform);
>+		if (ret < 0) {
>+			RTE_LOG(ERR, USER1,
>+				"Compression private xform "
>+				"could not be created\n");
>+			goto exit;
>+		}
>+
>+		/* Attach xform private data to operation */
>+		op->private_xform = priv_xform;
>+
>+		/* Enqueue and dequeue all operations */
>+		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
>+		if (ret == 0) {
>+			RTE_LOG(ERR, USER1,
>+				"The operation could not be enqueued\n");
>+			goto exit;
>+		}
>+		do {
>+			/*
>+			 * If retrying a dequeue call, wait for 10 ms to allow
>+			 * enough time to the driver to process the operations
>+			 */
>+			if (deqd_retries != 0) {
>+				/*
>+				 * Avoid infinite loop if not all the
>+				 * operations get out of the device
>+				 */
>+				if (deqd_retries == MAX_DEQD_RETRIES) {
>+					RTE_LOG(ERR, USER1,
>+						"Not all operations could be "
>+						"dequeued\n");
>+					goto exit;
>+				}
>+				usleep(DEQUEUE_WAIT_TIME);
>+			}
>+			num_deqd = rte_compressdev_dequeue_burst(0, 0,
>+					&op_processed, 1);
>+
>+			deqd_retries++;
>+		} while (num_deqd < 1);
>+
>+		deqd_retries = 0;
>+
>+		/* Free compress private xform */
>+		rte_compressdev_private_xform_free(0, priv_xform);
>+		priv_xform = NULL;
>+	}
>+
>+	enum rte_comp_huffman huffman_type =
>+		compress_xform->compress.deflate.huffman;
>+	RTE_LOG(DEBUG, USER1, "Buffer compressed from %u to %u bytes "
>+			"(level = %u, huffman = %s)\n",
>+			op_processed->consumed, op_processed->produced,
>+			compress_xform->compress.level,
>+			huffman_type_strings[huffman_type]);
>+	RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
>+			(float)op_processed->produced /
>+			op_processed->consumed * 100);
>+	op = NULL;
>+
>+	/*
>+	 * Check operation status and free source mbuf (destination mbuf and
>+	 * compress operation information is needed for the decompression stage)
>+	 */
>+	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
>+		RTE_LOG(ERR, USER1,
>+			"Some operations were not successful\n");
>+		goto exit;
>+	}
>+	rte_pktmbuf_free(uncomp_buf);
>+	uncomp_buf = NULL;
>+
>+	/* Allocate buffer for decompressed data */
>+	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
>+	if (uncomp_buf == NULL) {
>+		RTE_LOG(ERR, USER1,
>+			"Destination mbuf could not be allocated "
>+			"from the mempool\n");
>+		goto exit;
>+	}
>+
>+	rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
>+
>+	/* Build the decompression operations */
>+	op = rte_comp_op_alloc(ts_params->op_pool);
>+	if (op == NULL) {
>+		RTE_LOG(ERR, USER1,
>+			"Decompress operation could not be allocated "
>+			"from the mempool\n");
>+		goto exit;
>+	}
>+
>+	/* Source buffer is the compressed data from the previous operation */
>+	op->m_src = op_processed->m_dst;
>+	op->m_dst = uncomp_buf;
>+	op->src.offset = 0;
>+	/*
>+	 * Set the length of the compressed data to the
>+	 * number of bytes that were produced in the previous stage
>+	 */
>+	op->src.length = op_processed->produced;
>+	op->dst.offset = 0;
>+	if (state == RTE_COMP_OP_STATELESS) {
>+		//TODO: FULL or FINAL?
>+		op->flush_flag = RTE_COMP_FLUSH_FINAL;
>+	} else {
>+		RTE_LOG(ERR, USER1,
>+			"Stateful operations are not supported "
>+			"in these tests yet\n");
>+		goto exit;
>+	}
>+	op->input_chksum = 0;
>+
>+	/*
>+	 * Free the previous compress operation,
>+	 * as it is not needed anymore
>+	 */
>+	rte_comp_op_free(op_processed);
>+	op_processed = NULL;
>+
>+	/* Decompress data (either with Zlib API or compressdev API */
>+	if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
>+		ret = decompress_zlib(op,
>+			(const struct rte_comp_xform *)&decompress_xform);
>+		if (ret < 0)
>+			goto exit;
>+
>+		op_processed = op;
>+	} else {
>+		num_deqd = 0;
>+		/* Create decompress xform private data */
>+		ret = rte_compressdev_private_xform_create(0,
>+			(const struct rte_comp_xform *)decompress_xform,
>+			&priv_xform);
>+		if (ret < 0) {
>+			RTE_LOG(ERR, USER1,
>+				"Decompression private xform "
>+				"could not be created\n");
>+			goto exit;
>+		}
>+
>+		/* Attach xform private data to operation */
>+		op->private_xform = priv_xform;
>+
>+		/* Enqueue and dequeue all operations */
>+		ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
>+		if (ret == 0) {
>+			RTE_LOG(ERR, USER1,
>+				"The operation could not be enqueued\n");
>+			goto exit;
>+		}
>+		do {
>+			/*
>+			 * If retrying a dequeue call, wait for 10 ms to allow
>+			 * enough time to the driver to process the operations
>+			 */
>+			if (deqd_retries != 0) {
>+				/*
>+				 * Avoid infinite loop if not all the
>+				 * operations get out of the device
>+				 */
>+				if (deqd_retries == MAX_DEQD_RETRIES) {
>+					RTE_LOG(ERR, USER1,
>+						"Not all operations could be "
>+						"dequeued\n");
>+					goto exit;
>+				}
>+				usleep(DEQUEUE_WAIT_TIME);
>+			}
>+			num_deqd = rte_compressdev_dequeue_burst(0, 0,
>+					&op_processed, 1);
>+
>+			deqd_retries++;
>+		} while (num_deqd < 1);
>+	}
>+
>+	RTE_LOG(DEBUG, USER1, "Buffer decompressed from %u to %u bytes\n",
>+			op_processed->consumed, op_processed->produced);
>+	op = NULL;
>+	/*
>+	 * Check operation status and free source mbuf (destination mbuf and
>+	 * compress operation information is still needed)
>+	 */
>+	if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
>+		RTE_LOG(ERR, USER1,
>+			"Some operations were not successful\n");
>+		goto exit;
>+	}
>+	rte_pktmbuf_free(comp_buf);
>+	comp_buf = NULL;
>+
>+	/*
>+	 * Compare the original stream with the decompressed stream
>+	 * (in size and the data)
>+	 */
>+	if (compare_buffers(test_buffer, strlen(test_buffer) + 1,
>+			rte_pktmbuf_mtod(op_processed->m_dst, const char *),
>+			op_processed->produced) < 0)
>+		goto exit;
>+
>+	ret_status = 0;
>+
>+exit:
>+	/* Free resources */
>+	rte_pktmbuf_free(uncomp_buf);
>+	rte_pktmbuf_free(comp_buf);
>+	rte_comp_op_free(op);
>+	rte_comp_op_free(op_processed);
>+
>+	if (priv_xform != NULL)
>+		rte_compressdev_private_xform_free(0, priv_xform);
>+
>+	return ret_status;
>+}
>+
>+static int
>+test_compressdev_deflate_stateless_fixed(void)
>+{
>+	struct comp_testsuite_params *ts_params = &testsuite_params;
>+	const char *test_buffer;
>+	uint16_t i;
>+	struct rte_comp_xform compress_xform;
>+
>+	memcpy(&compress_xform, &ts_params->def_comp_xform,
>+			sizeof(struct rte_comp_xform));
>+	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
>+
>+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
>+		test_buffer = compress_test_bufs[i];
>+
>+		/* Compress with compressdev, decompress with Zlib */
>+		if (test_deflate_comp_decomp(test_buffer,
>+				&compress_xform,
>+				&ts_params->def_decomp_xform,
>+				RTE_COMP_OP_STATELESS,
>+				ZLIB_DECOMPRESS) < 0)
>+			return TEST_FAILED;
>+
>+		/* Compress with Zlib, decompress with compressdev */
>+		if (test_deflate_comp_decomp(test_buffer,
>+				&compress_xform,
>+				&ts_params->def_decomp_xform,
>+				RTE_COMP_OP_STATELESS,
>+				ZLIB_COMPRESS) < 0)
>+			return TEST_FAILED;
>+	}
>+
>+	return TEST_SUCCESS;
>+}
>+
>+static int
>+test_compressdev_deflate_stateless_dynamic(void)
>+{
>+	struct comp_testsuite_params *ts_params = &testsuite_params;
>+	const char *test_buffer;
>+	uint16_t i;
>+	struct rte_comp_xform compress_xform;
>+
>+	memcpy(&compress_xform, &ts_params->def_comp_xform,
>+			sizeof(struct rte_comp_xform));
>+	compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
>+
>+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
>+		test_buffer = compress_test_bufs[i];
>+
>+		/* Compress with compressdev, decompress with Zlib */
>+		if (test_deflate_comp_decomp(test_buffer,
>+				&compress_xform,
>+				&ts_params->def_decomp_xform,
>+				RTE_COMP_OP_STATELESS,
>+				ZLIB_DECOMPRESS) < 0)
>+			return TEST_FAILED;
>+
>+		/* Compress with Zlib, decompress with compressdev */
>+		if (test_deflate_comp_decomp(test_buffer,
>+				&compress_xform,
>+				&ts_params->def_decomp_xform,
>+				RTE_COMP_OP_STATELESS,
>+				ZLIB_COMPRESS) < 0)
>+			return TEST_FAILED;
>+	}
>+
>+	return TEST_SUCCESS;
>+}
>+
>+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(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_CASES_END() /**< NULL terminate unit test array */
>+	}
>+};
>+
>+static int
>+test_compressdev(void)
>+{
>+	return unit_test_suite_runner(&compressdev_testsuite);
>+}
>+
>+REGISTER_TEST_COMMAND(compressdev_autotest, test_compressdev);
>diff --git a/test/test/test_compressdev_test_buffer.h b/test/test/test_compressdev_test_buffer.h
>new file mode 100644
>index 000000000..c0492f89a
>--- /dev/null
>+++ b/test/test/test_compressdev_test_buffer.h
>@@ -0,0 +1,295 @@
>+#ifndef TEST_COMPRESSDEV_TEST_BUFFERS_H_
>+#define TEST_COMPRESSDEV_TEST_BUFFERS_H_
>+
>+/*
>+ * These test buffers are snippets obtained
>+ * from the Canterbury and Calgary Corpus
>+ * collection.
>+ */
>+
>+/* Snippet of Alice's Adventures in Wonderland */
>+static const char test_buf_alice[] =
>+	"  Alice was beginning to get very tired of sitting by her sister\n"
>+	"on the bank, and of having nothing to do:  once or twice she had\n"
>+	"peeped into the book her sister was reading, but it had no\n"
>+	"pictures or conversations in it, `and what is the use of a book,'\n"
>+	"thought Alice `without pictures or conversation?'\n\n"
>+	"  So she was considering in her own mind (as well as she could,\n"
>+	"for the hot day made her feel very sleepy and stupid), whether\n"
>+	"the pleasure of making a daisy-chain would be worth the trouble\n"
>+	"of getting up and picking the daisies, when suddenly a White\n"
>+	"Rabbit with pink eyes ran close by her.\n\n"
>+	"  There was nothing so VERY remarkable in that; nor did Alice\n"
>+	"think it so VERY much out of the way to hear the Rabbit say to\n"
>+	"itself, `Oh dear!  Oh dear!  I shall be late!'  (when she thought\n"
>+	"it over afterwards, it occurred to her that she ought to have\n"
>+	"wondered at this, but at the time it all seemed quite natural);\n"
>+	"but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT-\n"
>+	"POCKET, and looked at it, and then hurried on, Alice started to\n"
>+	"her feet, for it flashed across her mind that she had never\n"
>+	"before seen a rabbit with either a waistcoat-pocket, or a watch to\n"
>+	"take out of it, and burning with curiosity, she ran across the\n"
>+	"field after it, and fortunately was just in time to see it pop\n"
>+	"down a large rabbit-hole under the hedge.\n\n"
>+	"  In another moment down went Alice after it, never once\n"
>+	"considering how in the world she was to get out again.\n\n"
>+	"  The rabbit-hole went straight on like a tunnel for some way,\n"
>+	"and then dipped suddenly down, so suddenly that Alice had not a\n"
>+	"moment to think about stopping herself before she found herself\n"
>+	"falling down a very deep well.\n\n"
>+	"  Either the well was very deep, or she fell very slowly, for she\n"
>+	"had plenty of time as she went down to look about her and to\n"
>+	"wonder what was going to happen next.  First, she tried to look\n"
>+	"down and make out what she was coming to, but it was too dark to\n"
>+	"see anything; then she looked at the sides of the well, and\n"
>+	"noticed that they were filled with cupboards and book-shelves;\n"
>+	"here and there she saw maps and pictures hung upon pegs.  She\n"
>+	"took down a jar from one of the shelves as she passed; it was\n"
>+	"labelled `ORANGE MARMALADE', but to her great disappointment it\n"
>+	"was empty:  she did not like to drop the jar for fear of killing\n"
>+	"somebody, so managed to put it into one of the cupboards as she\n"
>+	"fell past it.\n\n"
>+	"  `Well!' thought Alice to herself, `after such a fall as this, I\n"
>+	"shall think nothing of tumbling down stairs!  How brave they'll\n"
>+	"all think me at home!  Why, I wouldn't say anything about it,\n"
>+	"even if I fell off the top of the house!' (Which was very likely\n"
>+	"true.)\n\n"
>+	"  Down, down, down.  Would the fall NEVER come to an end!  `I\n"
>+	"wonder how many miles I've fallen by this time?' she said aloud.\n"
>+	"`I must be getting somewhere near the centre of the earth.  Let\n"
>+	"me see:  that would be four thousand miles down, I think--' (for,\n"
>+	"you see, Alice had learnt several things of this sort in her\n"
>+	"lessons in the schoolroom, and though this was not a VERY good\n"
>+	"opportunity for showing off her knowledge, as there was no one to\n"
>+	"listen to her, still it was good practice to say it over) `--yes,\n"
>+	"that's about the right distance--but then I wonder what Latitude\n"
>+	"or Longitude I've got to?'  (Alice had no idea what Latitude was,\n"
>+	"or Longitude either, but thought they were nice grand words to\n"
>+	"say.)\n\n"
>+	"  Presently she began again.  `I wonder if I shall fall right\n"
>+	"THROUGH the earth!  How funny it'll seem to come out among the\n"
>+	"people that walk with their heads downward!  The Antipathies, I\n"
>+	"think--' (she was rather glad there WAS no one listening, this\n"
>+	"time, as it didn't sound at all the right word) `--but I shall\n"
>+	"have to ask them what the name of the country is, you know.\n"
>+	"Please, Ma'am, is this New Zealand or Australia?' (and she tried\n"
>+	"to curtsey as she spoke--fancy CURTSEYING as you're falling\n"
>+	"through the air!  Do you think you could manage it?)  `And what\n"
>+	"an ignorant little girl she'll think me for asking!  No, it'll\n"
>+	"never do to ask:  perhaps I shall see it written up somewhere.'\n"
>+	"  Down, down, down.  There was nothing else to do, so Alice soon\n"
>+	"began talking again.  `Dinah'll miss me very much to-night, I\n"
>+	"should think!'  (Dinah was the cat.)  `I hope they'll remember\n"
>+	"her saucer of milk at tea-time.  Dinah my dear!  I wish you were\n"
>+	"down here with me!  There are no mice in the air, I'm afraid, but\n"
>+	"you might catch a bat, and that's very like a mouse, you know.\n"
>+	"But do cats eat bats, I wonder?'  And here Alice began to get\n"
>+	"rather sleepy, and went on saying to herself, in a dreamy sort of\n"
>+	"way, `Do cats eat bats?  Do cats eat bats?' and sometimes, `Do\n"
>+	"bats eat cats?' for, you see, as she couldn't answer either\n"
>+	"question, it didn't much matter which way she put it.  She felt\n"
>+	"that she was dozing off, and had just begun to dream that she\n"
>+	"was walking hand in hand with Dinah, and saying to her very\n"
>+	"earnestly, `Now, Dinah, tell me the truth:  did you ever eat a\n"
>+	"bat?' when suddenly, thump! thump! down she came upon a heap of\n"
>+	"sticks and dry leaves, and the fall was over.\n\n";
>+
>+/* Snippet of Shakespeare play */
>+static const char test_buf_shakespeare[] =
>+	"CHARLES	wrestler to Frederick.\n"
>+	"\n"
>+	"\n"
>+	"OLIVER		|\n"
>+	"		|\n"
>+	"JAQUES (JAQUES DE BOYS:)  	|  sons of Sir Rowland de Boys.\n"
>+	"		|\n"
>+	"ORLANDO		|\n"
>+	"\n"
>+	"\n"
>+	"ADAM	|\n"
>+	"	|  servants to Oliver.\n"
>+	"DENNIS	|\n"
>+	"\n"
>+	"\n"
>+	"TOUCHSTONE	a clown.\n"
>+	"\n"
>+	"SIR OLIVER MARTEXT	a vicar.\n"
>+	"\n"
>+	"\n"
>+	"CORIN	|\n"
>+	"	|  shepherds.\n"
>+	"SILVIUS	|\n"
>+	"\n"
>+	"\n"
>+	"WILLIAM	a country fellow in love with Audrey.\n"
>+	"\n"
>+	"	A person representing HYMEN. (HYMEN:)\n"
>+	"\n"
>+	"ROSALIND	daughter to the banished duke.\n"
>+	"\n"
>+	"CELIA	daughter to Frederick.\n"
>+	"\n"
>+	"PHEBE	a shepherdess.\n"
>+	"\n"
>+	"AUDREY	a country wench.\n"
>+	"\n"
>+	"	Lords, pages, and attendants, &c.\n"
>+	"	(Forester:)\n"
>+	"	(A Lord:)\n"
>+	"	(First Lord:)\n"
>+	"	(Second Lord:)\n"
>+	"	(First Page:)\n"
>+	"	(Second Page:)\n"
>+	"\n"
>+	"\n"
>+	"SCENE	Oliver's house; Duke Frederick's court; and the\n"
>+	"	Forest of Arden.\n"
>+	"\n"
>+	"\n"
>+	"\n"
>+	"\n"
>+	"	AS YOU LIKE IT\n"
>+	"\n"
>+	"\n"
>+	"ACT I\n"
>+	"\n"
>+	"\n"
>+	"\n"
>+	"SCENE I	Orchard of Oliver's house.\n"
>+	"\n"
>+	"\n"
>+	"	[Enter ORLANDO and ADAM]\n"
>+	"\n"
>+	"ORLANDO	As I remember, Adam, it was upon this fashion\n"
>+	"	bequeathed me by will but poor a thousand crowns,\n"
>+	"	and, as thou sayest, charged my brother, on his\n"
>+	"	blessing, to breed me well: and there begins my\n"
>+	"	sadness. My brother Jaques he keeps at school, and\n"
>+	"	report speaks goldenly of his profit: for my part,\n"
>+	"	he keeps me rustically at home, or, to speak more\n"
>+	"	properly, stays me here at home unkept; for call you\n"
>+	"	that keeping for a gentleman of my birth, that\n"
>+	"	differs not from the stalling of an ox? His horses\n"
>+	"	are bred better; for, besides that they are fair\n"
>+	"	with their feeding, they are taught their manage,\n"
>+	"	and to that end riders dearly hired: but I, his\n"
>+	"	brother, gain nothing under him but growth; for the\n"
>+	"	which his animals on his dunghills are as much\n"
>+	"	bound to him as I. Besides this nothing that he so\n"
>+	"	plentifully gives me, the something that nature gave\n"
>+	"	me his countenance seems to take from me: he lets\n"
>+	"	me feed with his hinds, bars me the place of a\n"
>+	"	brother, and, as much as in him lies, mines my\n"
>+	"	gentility with my education. This is it, Adam, that\n"
>+	"	grieves me; and the spirit of my father, which I\n"
>+	"	think is within me, begins to mutiny against this\n"
>+	"	servitude: I will no longer endure it, though yet I\n"
>+	"	know no wise remedy how to avoid it.\n"
>+	"\n"
>+	"ADAM	Yonder comes my master, your brother.\n"
>+	"\n"
>+	"ORLANDO	Go apart, Adam, and thou shalt hear how he will\n";
>+
>+/* Snippet of source code in Pascal */
>+static const char test_buf_pascal[] =
>+	"	Ptr    = 1..DMem;\n"
>+	"	Loc    = 1..IMem;\n"
>+	"	Loc0   = 0..IMem;\n"
>+	"	EdgeT  = (hout,lin,hin,lout); {Warning this order is important in}\n"
>+	"				      {predicates such as gtS,geS}\n"
>+	"	CardT  = (finite,infinite);\n"
>+	"	ExpT   = Minexp..Maxexp;\n"
>+	"	ManT   = Mininf..Maxinf; \n"
>+	"	Pflag  = (PNull,PSoln,PTrace,PPrint);\n"
>+	"	Sreal  = record\n"
>+	"		    edge:EdgeT;\n"
>+	"		    cardinality:CardT;\n"
>+	"		    exp:ExpT; {exponent}\n"
>+	"		    mantissa:ManT;\n"
>+	"		 end;\n"
>+	"	Int    = record\n"
>+	"		    hi:Sreal;\n"
>+	"		    lo:Sreal;\n"
>+	"	 end;\n"
>+	"	Instr  = record\n"
>+	"		    Code:OpType;\n"
>+	"		    Pars: array[0..Par] of 0..DMem;\n"
>+	"		 end;\n"
>+	"	DataMem= record\n"
>+	"		    D        :array [Ptr] of Int;\n"
>+	"		    S        :array [Loc] of State;\n"
>+	"		    LastHalve:Loc;\n"
>+	"		    RHalve   :array [Loc] of real;\n"
>+	"		 end;\n"
>+	"	DataFlags=record\n"
>+	"		    PF	     :array [Ptr] of Pflag;\n"
>+	"		 end;\n"
>+	"var\n"
>+	"	Debug  : (none,activity,post,trace,dump);\n"
>+	"	Cut    : (once,all);\n"
>+	"	GlobalEnd,Verifiable:boolean;\n"
>+	"	HalveThreshold:real;\n"
>+	"	I      : array [Loc] of Instr; {Memory holding instructions}\n"
>+	"	End    : Loc; {last instruction in I}\n"
>+	"	ParN   : array [OpType] of -1..Par; {number of parameters for each \n"
>+	"			opcode. -1 means no result}\n"
>+	"        ParIntersect : array [OpType] of boolean ;\n"
>+	"	DInit  : DataMem; {initial memory which is cleared and \n"
>+	"				used in first call}\n"
>+	"	DF     : DataFlags; {hold flags for variables, e.g. print/trace}\n"
>+	"	MaxDMem:0..DMem;\n"
>+	"	Shift  : array[0..Digits] of 1..maxint;{array of constant multipliers}\n"
>+	"						{used for alignment etc.}\n"
>+	"	Dummy  :Positive;\n"
>+	"	{constant intervals and Sreals}\n"
>+	"	PlusInfS,MinusInfS,PlusSmallS,MinusSmallS,ZeroS,\n"
>+	"	PlusFiniteS,MinusFiniteS:Sreal;\n"
>+	"	Zero,All,AllFinite:Int;\n"
>+	"\n"
>+	"procedure deblank;\n"
>+	"var Ch:char;\n"
>+	"begin\n"
>+	"   while (not eof) and (input^ in [' ','	']) do read(Ch);\n"
>+	"end;\n"
>+	"\n"
>+	"procedure InitialOptions;\n"
>+	"\n"
>+	"#include '/user/profs/cleary/bin/options.i';\n"
>+	"\n"
>+	"   procedure Option;\n"
>+	"   begin\n"
>+	"      case Opt of\n"
>+	"      'a','A':Debug:=activity;\n"
>+	"      'd','D':Debug:=dump;\n"
>+	"      'h','H':HalveThreshold:=StringNum/100;\n"
>+	"      'n','N':Debug:=none;\n"
>+	"      'p','P':Debug:=post;\n"
>+	"      't','T':Debug:=trace;\n"
>+	"      'v','V':Verifiable:=true;\n"
>+	"      end;\n"
>+	"   end;\n"
>+	"\n"
>+	"begin\n"
>+	"   Debug:=trace;\n"
>+	"   Verifiable:=false;\n"
>+	"   HalveThreshold:=67/100;\n"
>+	"   Options;\n"
>+	"   writeln(Debug);\n"
>+	"   writeln('Verifiable:',Verifiable);\n"
>+	"   writeln('Halve threshold',HalveThreshold);\n"
>+	"end;{InitialOptions}\n"
>+	"\n"
>+	"procedure NormalizeUp(E,M:integer;var S:Sreal;var Closed:boolean);\n"
>+	"begin\n"
>+	"with S do\n"
>+	"begin\n"
>+	"   if M=0 then S:=ZeroS else\n"
>+	"   if M>0 then\n";
>+
>+static const char * const compress_test_bufs[] = {
>+	test_buf_alice,
>+	test_buf_shakespeare,
>+	test_buf_pascal
>+};
>+
>+#endif /* TEST_COMPRESSDEV_TEST_BUFFERS_H_ */
>--
>2.17.0

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [dpdk-dev] [PATCH v4 1/5] test/compress: add initial unit tests
  2018-05-14  8:29     ` Verma, Shally
@ 2018-05-14  8:40       ` De Lara Guarch, Pablo
  0 siblings, 0 replies; 32+ messages in thread
From: De Lara Guarch, Pablo @ 2018-05-14  8:40 UTC (permalink / raw)
  To: Verma, Shally, dev
  Cc: Trahe, Fiona, Daly, Lee, ahmed.mansour, Gupta, Ashish, Gupta, Ashish



> -----Original Message-----
> From: Verma, Shally [mailto:Shally.Verma@cavium.com]
> Sent: Monday, May 14, 2018 9:29 AM
> To: De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>; dev@dpdk.org
> Cc: Trahe, Fiona <fiona.trahe@intel.com>; Daly, Lee <lee.daly@intel.com>;
> ahmed.mansour@nxp.com; Gupta, Ashish <Ashish.Gupta@cavium.com>; Gupta,
> Ashish <Ashish.Gupta@cavium.com>
> Subject: RE: [PATCH v4 1/5] test/compress: add initial unit tests
> 
> 
> 
> >-----Original Message-----
> >From: Pablo de Lara [mailto:pablo.de.lara.guarch@intel.com]
> >Sent: 04 May 2018 15:52
> >To: dev@dpdk.org
> >Cc: fiona.trahe@intel.com; lee.daly@intel.com; Verma, Shally
> ><Shally.Verma@cavium.com>; ahmed.mansour@nxp.com; Gupta, Ashish
> ><Ashish.Gupta@cavium.com>; Pablo de Lara
> ><pablo.de.lara.guarch@intel.com>; Gupta, Ashish
> ><Ashish.Gupta@cavium.com>; Verma, Shally <Shally.Verma@cavium.com>
> >Subject: [PATCH v4 1/5] test/compress: add initial unit tests
> >
> >This commit introduces the initial tests for compressdev, performing
> >basic compression and decompression operations of sample test buffers,
> >using the Zlib library in one direction and compressdev in another
> >direction, to make sure that the library is compatible with Zlib.
> >
> >Due to the use of Zlib API, the test is disabled by default, to avoid
> >adding a new dependency on DPDK.
> >
> >Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
> >Signed-off-by: Ashish Gupta <ashish.gupta@caviumnetworks.com>
> >Signed-off-by: Shally Verma <shally.verma@caviumnetworks.com>
> >Acked-by: Lee Daly <lee.daly@intel.com>
> >---
> > config/common_base                       |   5 +
> > test/test/Makefile                       |   9 +
> > test/test/meson.build                    |   8 +
> > test/test/test_compressdev.c             | 725 +++++++++++++++++++++++
> > test/test/test_compressdev_test_buffer.h | 295 +++++++++
> > 5 files changed, 1042 insertions(+)
> > create mode 100644 test/test/test_compressdev.c  create mode 100644
> >test/test/test_compressdev_test_buffer.h
> >
> //snip
> 
> >+ * Compresses and decompresses buffer with compressdev API and Zlib
> >+API  */ static int test_deflate_comp_decomp(const char *test_buffer,
> >+		struct rte_comp_xform *compress_xform,
> >+		struct rte_comp_xform *decompress_xform,
> >+		enum rte_comp_op_type state,
> >+		enum zlib_direction zlib_dir)
> >+{
> >+	struct comp_testsuite_params *ts_params = &testsuite_params;
> >+	int ret_status = -1;
> >+	int ret;
> >+	struct rte_mbuf *comp_buf = NULL;
> >+	struct rte_mbuf *uncomp_buf = NULL;
> >+	struct rte_comp_op *op = NULL;
> >+	struct rte_comp_op *op_processed = NULL;
> >+	void *priv_xform = NULL;
> >+	uint16_t num_deqd;
> >+	unsigned int deqd_retries = 0;
> >+	char *data_ptr;
> >+
> >+	/* Prepare the source mbuf with the data */
> >+	uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
> >+	if (uncomp_buf == NULL) {
> >+		RTE_LOG(ERR, USER1,
> >+			"Source mbuf could not be allocated "
> >+			"from the mempool\n");
> >+		goto exit;
> >+	}
> >+
> >+	data_ptr = rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
> >+	snprintf(data_ptr, strlen(test_buffer) + 1, "%s", test_buffer);
> >+
> >+	/* Prepare the destination mbuf */
> >+	comp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
> >+	if (comp_buf == NULL) {
> >+		RTE_LOG(ERR, USER1,
> >+			"Destination mbuf could not be allocated "
> >+			"from the mempool\n");
> >+		goto exit;
> >+	}
> >+
> >+	rte_pktmbuf_append(comp_buf,
> >+			strlen(test_buffer) * COMPRESS_BUF_SIZE_RATIO);
> >+
> >+	/* Build the compression operations */
> >+	op = rte_comp_op_alloc(ts_params->op_pool);
> >+	if (op == NULL) {
> >+		RTE_LOG(ERR, USER1,
> >+			"Compress operation could not be allocated "
> >+			"from the mempool\n");
> >+		goto exit;
> >+	}
> >+
> >+	op->m_src = uncomp_buf;
> >+	op->m_dst = comp_buf;
> >+	op->src.offset = 0;
> >+	op->src.length = rte_pktmbuf_pkt_len(uncomp_buf);
> >+	op->dst.offset = 0;
> >+	if (state == RTE_COMP_OP_STATELESS) {
> >+		//TODO: FULL or FINAL?
> >+		op->flush_flag = RTE_COMP_FLUSH_FINAL;
> >+	} else {
> >+		RTE_LOG(ERR, USER1,
> >+			"Stateful operations are not supported "
> >+			"in these tests yet\n");
> >+		goto exit;
> >+	}
> >+	op->input_chksum = 0;
> >+
> >+	/* Compress data (either with Zlib API or compressdev API */
> >+	if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
> >+		ret = compress_zlib(op,
> >+			(const struct rte_comp_xform *)&compress_xform,
> [Shally] why are we passing ** here, compress_zlib() input rte_comp_xform*,
> this will cause a bug here. So, in call to decompress_zlib() below.

Hi Shally,

Looks like you are right. However, this code has been already merged and this was "fixed"
in the second patch.

Thanks,
Pablo

> 
> Thanks
> Shally

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2018-05-14  8:40 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-28 14:00 [dpdk-dev] [PATCH 0/5] Initial compressdev unit tests Pablo de Lara
2018-02-28 14:00 ` [dpdk-dev] [PATCH 1/5] compressdev: add const for xform in session init Pablo de Lara
2018-02-28 14:00 ` [dpdk-dev] [PATCH 2/5] test/compress: add initial unit tests Pablo de Lara
2018-02-28 14:00 ` [dpdk-dev] [PATCH 3/5] test/compress: add multi op test Pablo de Lara
2018-02-28 14:00 ` [dpdk-dev] [PATCH 4/5] test/compress: add multi level test Pablo de Lara
2018-02-28 14:00 ` [dpdk-dev] [PATCH 5/5] test/compress: add multi session test Pablo de Lara
2018-04-08 14:00 ` [dpdk-dev] [PATCH v2 0/5] Initial compressdev unit tests Pablo de Lara
2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 1/5] test/compress: add initial " Pablo de Lara
2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 2/5] test/compress: add multi op test Pablo de Lara
2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 3/5] test/compress: add multi level test Pablo de Lara
2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 4/5] test/compress: add multi xform test Pablo de Lara
2018-04-08 14:00   ` [dpdk-dev] [PATCH v2 5/5] test/compress: add invalid configuration tests Pablo de Lara
2018-04-27 14:14 ` [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests Pablo de Lara
2018-04-27 14:14   ` [dpdk-dev] [PATCH v3 1/5] test/compress: add initial " Pablo de Lara
2018-05-02 13:44     ` Daly, Lee
2018-05-04  8:49       ` De Lara Guarch, Pablo
2018-04-27 14:14   ` [dpdk-dev] [PATCH v3 2/5] test/compress: add multi op test Pablo de Lara
2018-04-27 14:15   ` [dpdk-dev] [PATCH v3 3/5] test/compress: add multi level test Pablo de Lara
2018-04-27 14:15   ` [dpdk-dev] [PATCH v3 4/5] test/compress: add multi xform test Pablo de Lara
2018-05-02 13:49     ` Daly, Lee
2018-04-27 14:15   ` [dpdk-dev] [PATCH v3 5/5] test/compress: add invalid configuration tests Pablo de Lara
2018-05-01 13:00   ` [dpdk-dev] [PATCH v3 0/5] Initial compressdev unit tests Daly, Lee
2018-05-04 10:22 ` [dpdk-dev] [PATCH v4 " Pablo de Lara
2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 1/5] test/compress: add initial " Pablo de Lara
2018-05-14  8:29     ` Verma, Shally
2018-05-14  8:40       ` De Lara Guarch, Pablo
2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 2/5] test/compress: add multi op test Pablo de Lara
2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 3/5] test/compress: add multi level test Pablo de Lara
2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 4/5] test/compress: add multi xform test Pablo de Lara
2018-05-04 10:22   ` [dpdk-dev] [PATCH v4 5/5] test/compress: add invalid configuration tests Pablo de Lara
2018-05-08 15:47   ` [dpdk-dev] [PATCH v4 0/5] Initial compressdev unit tests Trahe, Fiona
2018-05-08 21:26   ` De Lara Guarch, Pablo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).