diff mbox series

[v2,2/2] test/compress: add varied buffer input/outputs

Message ID 20181220145824.37223-2-marko.kovacevic@intel.com (mailing list archive)
State Changes Requested, archived
Delegated to: akhil goyal
Headers show
Series [v2,1/2] test/compress: add out of space test | expand

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Kovacevic, Marko Dec. 20, 2018, 2:58 p.m. UTC
Added unit test to check if a SGL buffer
was added as an input and a Linear Buffer
as output and vice versa so we can test if the
application would process the different buffers
properly.

Signed-off-by: Marko Kovacevic <marko.kovacevic@intel.com>
Acked-by: Lee Daly <lee.daly@intel.com>
---
 test/test/test_compressdev.c | 173 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 130 insertions(+), 43 deletions(-)

Comments

Trahe, Fiona Dec. 21, 2018, 12:44 a.m. UTC | #1
> -----Original Message-----
> From: Kovacevic, Marko
> Sent: Thursday, December 20, 2018 7:58 AM
> To: dev@dpdk.org
> Cc: akhil.goyal@nxp.com; Daly, Lee <lee.daly@intel.com>; Jozwiak, TomaszX
> <tomaszx.jozwiak@intel.com>; O'Hare, Cathal <cathal.ohare@intel.com>; Trahe, Fiona
> <fiona.trahe@intel.com>; Kovacevic, Marko <marko.kovacevic@intel.com>
> Subject: [PATCH v2 2/2] test/compress: add varied buffer input/outputs
> 
> Added unit test to check if a SGL buffer
> was added as an input and a Linear Buffer
> as output and vice versa so we can test if the
> application would process the different buffers
> properly.
> 
> Signed-off-by: Marko Kovacevic <marko.kovacevic@intel.com>
> Acked-by: Lee Daly <lee.daly@intel.com>
Acked-by: Fiona Trahe <fiona.trahe@intel.com>
Pablo de Lara Jan. 9, 2019, 5:02 p.m. UTC | #2
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Marko Kovacevic
> Sent: Thursday, December 20, 2018 2:58 PM
> To: dev@dpdk.org
> Cc: akhil.goyal@nxp.com; Daly, Lee <lee.daly@intel.com>; Jozwiak, TomaszX
> <tomaszx.jozwiak@intel.com>; O'Hare, Cathal <cathal.ohare@intel.com>;
> Trahe, Fiona <fiona.trahe@intel.com>; Kovacevic, Marko
> <marko.kovacevic@intel.com>
> Subject: [dpdk-dev] [PATCH v2 2/2] test/compress: add varied buffer
> input/outputs
> 
> Added unit test to check if a SGL buffer was added as an input and a Linear
> Buffer as output and vice versa so we can test if the application would
> process the different buffers properly.
> 
> Signed-off-by: Marko Kovacevic <marko.kovacevic@intel.com>
> Acked-by: Lee Daly <lee.daly@intel.com>
> ---
>  test/test/test_compressdev.c | 173 ++++++++++++++++++++++++++++++++---
> --------
>  1 file changed, 130 insertions(+), 43 deletions(-)
> 
> diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
> index b2999fa..5d62206 100644
> --- a/test/test/test_compressdev.c
> +++ b/test/test/test_compressdev.c
> @@ -71,6 +71,13 @@ struct comp_testsuite_params {
>  	struct rte_comp_xform *def_decomp_xform;  };
> 
> +enum varied_buff {
> +	 LB_BOTH = 0,	/* both input and output are linear*/
> +	 SGL_BOTH,	/* both input and output are chained */
> +	 SGL_TO_LB,	/* input buffer is chained */
> +	 LB_TO_SGL	/* output buffer is chained */
>

Great idea to have this enum. It really makes the tests more readable :)
> 
> +static int
> +test_compressdev_deflate_stateless_varied_buf(void)
> +{

I think, since these new tests could be integrated in the SGL test, extending the existing ones,
as so far they were only testing SGL in SGL out and this is extending to other combinations.
This way, we don't add another test unnecessarily.

Thanks,
Pablo
diff mbox series

Patch

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index b2999fa..5d62206 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -71,6 +71,13 @@  struct comp_testsuite_params {
 	struct rte_comp_xform *def_decomp_xform;
 };
 
+enum varied_buff {
+	 LB_BOTH = 0,	/* both input and output are linear*/
+	 SGL_BOTH,	/* both input and output are chained */
+	 SGL_TO_LB,	/* input buffer is chained */
+	 LB_TO_SGL	/* output buffer is chained */
+};
+
 static struct comp_testsuite_params testsuite_params = { 0 };
 
 static void
@@ -353,7 +360,7 @@  compress_zlib(struct rte_comp_op *op,
 	}
 
 	/* Assuming stateless operation */
-	/* SGL */
+	/* SGL Input */
 	if (op->m_src->nb_segs > 1) {
 		single_src_buf = rte_malloc(NULL,
 				rte_pktmbuf_pkt_len(op->m_src), 0);
@@ -361,14 +368,10 @@  compress_zlib(struct rte_comp_op *op,
 			RTE_LOG(ERR, USER1, "Buffer could not be allocated\n");
 			goto exit;
 		}
-		single_dst_buf = rte_malloc(NULL,
-				rte_pktmbuf_pkt_len(op->m_dst), 0);
-		if (single_dst_buf == NULL) {
-			RTE_LOG(ERR, USER1, "Buffer could not be allocated\n");
-			goto exit;
-		}
-		if (rte_pktmbuf_read(op->m_src, 0,
-					rte_pktmbuf_pkt_len(op->m_src),
+
+		if (rte_pktmbuf_read(op->m_src, op->src.offset,
+					rte_pktmbuf_pkt_len(op->m_src) -
+					op->src.offset,
 					single_src_buf) == NULL) {
 			RTE_LOG(ERR, USER1,
 				"Buffer could not be read entirely\n");
@@ -377,15 +380,31 @@  compress_zlib(struct rte_comp_op *op,
 
 		stream.avail_in = op->src.length;
 		stream.next_in = single_src_buf;
-		stream.avail_out = rte_pktmbuf_pkt_len(op->m_dst);
-		stream.next_out = single_dst_buf;
 
 	} else {
 		stream.avail_in = op->src.length;
-		stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
+		stream.next_in = rte_pktmbuf_mtod_offset(op->m_src, uint8_t *,
+				op->src.offset);
+	}
+	/* SGL output */
+	if (op->m_dst->nb_segs > 1) {
+
+		single_dst_buf = rte_malloc(NULL,
+				rte_pktmbuf_pkt_len(op->m_dst), 0);
+			if (single_dst_buf == NULL) {
+			RTE_LOG(ERR, USER1, "Buffer could not be allocated\n");
+			goto exit;
+		}
+
+		stream.avail_out = op->m_dst->pkt_len;
+		stream.next_out = single_dst_buf;
+
+	} else {/* linear output */
 		stream.avail_out = op->m_dst->data_len;
-		stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
+		stream.next_out = rte_pktmbuf_mtod_offset(op->m_dst, uint8_t *,
+				op->dst.offset);
 	}
+
 	/* Stateless operation, all buffer will be compressed in one go */
 	zlib_flush = map_zlib_flush_flag(op->flush_flag);
 	ret = deflate(&stream, zlib_flush);
@@ -399,14 +418,14 @@  compress_zlib(struct rte_comp_op *op,
 		goto exit;
 
 	/* Copy data to destination SGL */
-	if (op->m_src->nb_segs > 1) {
+	if (op->m_dst->nb_segs > 1) {
 		uint32_t remaining_data = stream.total_out;
 		uint8_t *src_data = single_dst_buf;
 		struct rte_mbuf *dst_buf = op->m_dst;
 
 		while (remaining_data > 0) {
-			uint8_t *dst_data = rte_pktmbuf_mtod(dst_buf,
-					uint8_t *);
+			uint8_t *dst_data = rte_pktmbuf_mtod_offset(dst_buf,
+						uint8_t *, op->dst.offset);
 			/* Last segment */
 			if (remaining_data < dst_buf->data_len) {
 				memcpy(dst_data, src_data, remaining_data);
@@ -662,7 +681,7 @@  test_deflate_comp_decomp(const char * const test_bufs[],
 		struct rte_comp_xform *decompress_xforms[],
 		unsigned int num_xforms,
 		enum rte_comp_op_type state,
-		unsigned int sgl,
+		enum varied_buff buff_type,
 		enum zlib_direction zlib_dir)
 {
 	struct comp_testsuite_params *ts_params = &testsuite_params;
@@ -693,7 +712,7 @@  test_deflate_comp_decomp(const char * const test_bufs[],
 	memset(ops_processed, 0, sizeof(struct rte_comp_op *) * num_bufs);
 	memset(priv_xforms, 0, sizeof(void *) * num_bufs);
 
-	if (sgl)
+	if (buff_type == SGL_BOTH)
 		buf_pool = ts_params->small_mbuf_pool;
 	else
 		buf_pool = ts_params->large_mbuf_pool;
@@ -708,7 +727,7 @@  test_deflate_comp_decomp(const char * const test_bufs[],
 		goto exit;
 	}
 
-	if (sgl) {
+	if (buff_type == SGL_BOTH || buff_type == SGL_TO_LB) {
 		for (i = 0; i < num_bufs; i++) {
 			data_size = strlen(test_bufs[i]) + 1;
 			if (prepare_sgl_bufs(test_bufs[i], uncomp_bufs[i],
@@ -735,7 +754,7 @@  test_deflate_comp_decomp(const char * const test_bufs[],
 		goto exit;
 	}
 
-	if (sgl) {
+	if (buff_type == SGL_BOTH || buff_type == LB_TO_SGL) {
 		for (i = 0; i < num_bufs; i++) {
 			out_of_space ? data_size = OUT_OF_SPACE_BUF :
 					(data_size = strlen(test_bufs[i]) *
@@ -947,7 +966,7 @@  test_deflate_comp_decomp(const char * const test_bufs[],
 		goto exit;
 	}
 
-	if (sgl) {
+	if (buff_type == SGL_BOTH || buff_type == LB_TO_SGL) {
 		for (i = 0; i < num_bufs; i++) {
 			priv_data = (struct priv_op_data *)
 					(ops_processed[i] + 1);
@@ -1241,7 +1260,7 @@  test_compressdev_deflate_stateless_fixed(void)
 				&ts_params->def_decomp_xform,
 				1,
 				RTE_COMP_OP_STATELESS,
-				0,
+				LB_BOTH,
 				ZLIB_DECOMPRESS) < 0) {
 			ret = TEST_FAILED;
 			goto exit;
@@ -1254,7 +1273,7 @@  test_compressdev_deflate_stateless_fixed(void)
 				&ts_params->def_decomp_xform,
 				1,
 				RTE_COMP_OP_STATELESS,
-				0,
+				LB_BOTH,
 				ZLIB_COMPRESS) < 0) {
 			ret = TEST_FAILED;
 			goto exit;
@@ -1307,7 +1326,7 @@  test_compressdev_deflate_stateless_dynamic(void)
 				&ts_params->def_decomp_xform,
 				1,
 				RTE_COMP_OP_STATELESS,
-				0,
+				LB_BOTH,
 				ZLIB_DECOMPRESS) < 0) {
 			ret = TEST_FAILED;
 			goto exit;
@@ -1320,7 +1339,7 @@  test_compressdev_deflate_stateless_dynamic(void)
 				&ts_params->def_decomp_xform,
 				1,
 				RTE_COMP_OP_STATELESS,
-				0,
+				LB_BOTH,
 				ZLIB_COMPRESS) < 0) {
 			ret = TEST_FAILED;
 			goto exit;
@@ -1352,7 +1371,7 @@  test_compressdev_deflate_stateless_multi_op(void)
 			&ts_params->def_decomp_xform,
 			1,
 			RTE_COMP_OP_STATELESS,
-			0,
+			LB_BOTH,
 			ZLIB_DECOMPRESS) < 0)
 		return TEST_FAILED;
 
@@ -1363,7 +1382,7 @@  test_compressdev_deflate_stateless_multi_op(void)
 			&ts_params->def_decomp_xform,
 			1,
 			RTE_COMP_OP_STATELESS,
-			0,
+			LB_BOTH,
 			ZLIB_COMPRESS) < 0)
 		return TEST_FAILED;
 
@@ -1403,7 +1422,7 @@  test_compressdev_deflate_stateless_multi_level(void)
 					&ts_params->def_decomp_xform,
 					1,
 					RTE_COMP_OP_STATELESS,
-					0,
+					LB_BOTH,
 					ZLIB_DECOMPRESS) < 0) {
 				ret = TEST_FAILED;
 				goto exit;
@@ -1474,7 +1493,7 @@  test_compressdev_deflate_stateless_multi_xform(void)
 			decompress_xforms,
 			NUM_XFORMS,
 			RTE_COMP_OP_STATELESS,
-			0,
+			LB_BOTH,
 			ZLIB_DECOMPRESS) < 0) {
 		ret = TEST_FAILED;
 		goto exit;
@@ -1513,8 +1532,8 @@  test_compressdev_deflate_stateless_sgl(void)
 				&ts_params->def_decomp_xform,
 				1,
 				RTE_COMP_OP_STATELESS,
-				1,
-				ZLIB_DECOMPRESS) < 0)
+				SGL_BOTH,
+				ZLIB_COMPRESS) < 0)
 			return TEST_FAILED;
 
 		/* Compress with Zlib, decompress with compressdev */
@@ -1524,13 +1543,12 @@  test_compressdev_deflate_stateless_sgl(void)
 				&ts_params->def_decomp_xform,
 				1,
 				RTE_COMP_OP_STATELESS,
-				1,
-				ZLIB_COMPRESS) < 0)
+				SGL_BOTH,
+				ZLIB_DECOMPRESS) < 0)
 			return TEST_FAILED;
 	}
 
 	return TEST_SUCCESS;
-
 }
 
 static int
@@ -1592,7 +1610,7 @@  test_compressdev_deflate_stateless_checksum(void)
 					&decompress_xform,
 					1,
 					RTE_COMP_OP_STATELESS,
-					0,
+					LB_BOTH,
 					ZLIB_COMPRESS) < 0) {
 				ret = TEST_FAILED;
 				goto exit;
@@ -1607,7 +1625,7 @@  test_compressdev_deflate_stateless_checksum(void)
 					&decompress_xform,
 					1,
 					RTE_COMP_OP_STATELESS,
-					0,
+					LB_BOTH,
 					ZLIB_NONE) < 0) {
 				ret = TEST_FAILED;
 				goto exit;
@@ -1632,7 +1650,7 @@  test_compressdev_deflate_stateless_checksum(void)
 					&decompress_xform,
 					1,
 					RTE_COMP_OP_STATELESS,
-					0,
+					LB_BOTH,
 					ZLIB_COMPRESS) < 0) {
 				ret = TEST_FAILED;
 				goto exit;
@@ -1646,7 +1664,7 @@  test_compressdev_deflate_stateless_checksum(void)
 					&decompress_xform,
 					1,
 					RTE_COMP_OP_STATELESS,
-					0,
+					LB_BOTH,
 					ZLIB_NONE) < 0) {
 				ret = TEST_FAILED;
 				goto exit;
@@ -1673,7 +1691,7 @@  test_compressdev_deflate_stateless_checksum(void)
 					&decompress_xform,
 					1,
 					RTE_COMP_OP_STATELESS,
-					0,
+					LB_BOTH,
 					ZLIB_NONE) < 0) {
 				ret = TEST_FAILED;
 				goto exit;
@@ -1724,7 +1742,7 @@  test_compressdev_out_of_space_buffer(void)
 			&ts_params->def_decomp_xform,
 			1,
 			RTE_COMP_OP_STATELESS,
-			0,
+			LB_BOTH,
 			ZLIB_DECOMPRESS) == 0 && out_of_space == 1) {
 		ret = TEST_FAILED;
 		goto exit;
@@ -1738,7 +1756,7 @@  test_compressdev_out_of_space_buffer(void)
 			&ts_params->def_decomp_xform,
 			1,
 			RTE_COMP_OP_STATELESS,
-			0,
+			LB_BOTH,
 			ZLIB_COMPRESS) == 0 && out_of_space == 1) {
 		ret = TEST_FAILED;
 		goto exit;
@@ -1753,7 +1771,7 @@  test_compressdev_out_of_space_buffer(void)
 				&ts_params->def_decomp_xform,
 				1,
 				RTE_COMP_OP_STATELESS,
-				1,
+				SGL_BOTH,
 				ZLIB_DECOMPRESS) == 0 && out_of_space == 1) {
 			ret = TEST_FAILED;
 			goto exit;
@@ -1768,7 +1786,7 @@  test_compressdev_out_of_space_buffer(void)
 				&ts_params->def_decomp_xform,
 				1,
 				RTE_COMP_OP_STATELESS,
-				1,
+				SGL_BOTH,
 				ZLIB_COMPRESS) == 0 && out_of_space == 1) {
 			ret = TEST_FAILED;
 			goto exit;
@@ -1784,6 +1802,72 @@  test_compressdev_out_of_space_buffer(void)
 	return ret;
 }
 
+static int
+test_compressdev_deflate_stateless_varied_buf(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	uint16_t i;
+	const char *test_buffer;
+	const struct rte_compressdev_capabilities *capab;
+
+	capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+	TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
+		test_buffer = compress_test_bufs[0];
+
+		if (capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_LB_OUT) {
+			/* Compress with compressdev, decompress with Zlib*/
+			if (test_deflate_comp_decomp(&test_buffer, 1,
+					&i,
+					&ts_params->def_comp_xform,
+					&ts_params->def_decomp_xform,
+					1,
+					RTE_COMP_OP_STATELESS,
+					SGL_TO_LB,
+					ZLIB_DECOMPRESS) < 0)
+				return TEST_FAILED;
+
+			/* Compress with Zlib, decompress with compressdev*/
+			if (test_deflate_comp_decomp(&test_buffer, 1,
+					&i,
+					&ts_params->def_comp_xform,
+					&ts_params->def_decomp_xform,
+					1,
+					RTE_COMP_OP_STATELESS,
+					SGL_TO_LB,
+					ZLIB_COMPRESS) < 0)
+				return TEST_FAILED;
+		}
+
+		if (capab->comp_feature_flags & RTE_COMP_FF_OOP_LB_IN_SGL_OUT) {
+			/* Compress with compressdev, decompress with Zlib*/
+			if (test_deflate_comp_decomp(&test_buffer, 1,
+					&i,
+					&ts_params->def_comp_xform,
+					&ts_params->def_decomp_xform,
+					1,
+					RTE_COMP_OP_STATELESS,
+					LB_TO_SGL,
+					ZLIB_DECOMPRESS) < 0)
+				return TEST_FAILED;
+
+			/* Compress with Zlib, decompress with compressdev*/
+			if (test_deflate_comp_decomp(&test_buffer, 1,
+					&i,
+					&ts_params->def_comp_xform,
+					&ts_params->def_decomp_xform,
+					1,
+					RTE_COMP_OP_STATELESS,
+					LB_TO_SGL,
+					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,
@@ -1807,6 +1891,9 @@  static struct unit_test_suite compressdev_testsuite  = {
 			test_compressdev_deflate_stateless_checksum),
 		TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
 			test_compressdev_out_of_space_buffer),
+		TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+			test_compressdev_deflate_stateless_varied_buf),
+
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };