[v4,2/3] test/compress: add out of space test

Message ID 20190111165253.14001-3-marko.kovacevic@intel.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers
Series Compression Unit Tests |

Checks

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

Commit Message

Kovacevic, Marko Jan. 11, 2019, 4:52 p.m. UTC
  This patch adds new out of space testcase to check
that the destination mbuf is smaller than required for
the output of compression to ensure the driver doesn't crash
and returns the valid error case.

Signed-off-by: Kovacevic, Marko <marko.kovacevic@intel.com>
Acked-by: Lee Daly <lee.daly@intel.com>
Acked-by: Fiona Trahe <fiona.trahe@intel.com>

---
v4:
  Added Acks
V3:
  Made requested changes(Pablo)

---
 test/test/test_compressdev.c | 178 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 165 insertions(+), 13 deletions(-)
  

Comments

De Lara Guarch, Pablo Jan. 16, 2019, 5:16 p.m. UTC | #1
Hi Marko,

Minor comments.

> -----Original Message-----
> From: Kovacevic, Marko
> Sent: Friday, January 11, 2019 4:53 PM
> To: dev@dpdk.org
> Cc: akhil.goyal@nxp.com; De Lara Guarch, Pablo
> <pablo.de.lara.guarch@intel.com>; Kovacevic, Marko
> <marko.kovacevic@intel.com>; Kovacevic
> Subject: [PATCH v4 2/3] test/compress: add out of space test
> 
> This patch adds new out of space testcase to check that the destination
> mbuf is smaller than required for the output of compression to ensure the
> driver doesn't crash and returns the valid error case.
> 
> Signed-off-by: Kovacevic, Marko <marko.kovacevic@intel.com>
> Acked-by: Lee Daly <lee.daly@intel.com>
> Acked-by: Fiona Trahe <fiona.trahe@intel.com>
> 
> ---
> v4:
>   Added Acks
> V3:
>   Made requested changes(Pablo)
> 
> ---
>  test/test/test_compressdev.c | 178
> +++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 165 insertions(+), 13 deletions(-)
> 
> diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
> index 20895fc..1e41113 100644
> --- a/test/test/test_compressdev.c
> +++ b/test/test/test_compressdev.c
> @@ -42,6 +42,8 @@
>  #define GZIP_HEADER_SIZE 10
>  #define GZIP_TRAILER_SIZE 8
> 
> +#define OUT_OF_SPACE_BUF 1
> +
>  const char *
>  huffman_type_strings[] = {
>  	[RTE_COMP_HUFFMAN_DEFAULT]	= "PMD default",
> @@ -81,6 +83,7 @@ struct test_data_params {
>  	enum rte_comp_op_type state;
>  	unsigned int sgl;
>  	enum zlib_direction zlib_dir;
> +	unsigned int out_of_space;
>  };
> 
>  static struct comp_testsuite_params testsuite_params = { 0 }; @@ -677,6
> +680,7 @@ test_deflate_comp_decomp(const struct interim_data_params
> *int_data,
>  	unsigned int num_xforms = int_data->num_xforms;
>  	enum rte_comp_op_type state = test_data->state;
>  	unsigned int sgl = test_data->sgl;
> +	unsigned int out_of_space = test_data->out_of_space;
>  	enum zlib_direction zlib_dir = test_data->zlib_dir;
>  	int ret_status = -1;
>  	int ret;
> @@ -693,6 +697,12 @@ test_deflate_comp_decomp(const struct
> interim_data_params *int_data,
>  	unsigned int i;
>  	struct rte_mempool *buf_pool;
>  	uint32_t data_size;
> +	/* Compressing with CompressDev */
> +	unsigned int oos_zlib_decompress =
> +			(zlib_dir == ZLIB_NONE || zlib_dir ==
> ZLIB_DECOMPRESS);
> +	/* Decompressing with CompressDev */
> +	unsigned int oos_zlib_compress =
> +			(zlib_dir == ZLIB_NONE || zlib_dir ==
> ZLIB_COMPRESS);
>  	const struct rte_compressdev_capabilities *capa =
>  		rte_compressdev_capability_get(0,
> RTE_COMP_ALGO_DEFLATE);
>  	char *contig_buf = NULL;
> @@ -749,8 +759,12 @@ test_deflate_comp_decomp(const struct
> interim_data_params *int_data,
> 
>  	if (sgl) {
>  		for (i = 0; i < num_bufs; i++) {
> -			data_size = strlen(test_bufs[i]) *
> -				COMPRESS_BUF_SIZE_RATIO;
> +			if (out_of_space == 1 && oos_zlib_decompress) {
> +				data_size = OUT_OF_SPACE_BUF;
> +			} else {
> +				(data_size = strlen(test_bufs[i]) *
> +					COMPRESS_BUF_SIZE_RATIO);

No need for the parenthesis around this statement (plus, no need for the curly braces).


> +			}
>  			if (prepare_sgl_bufs(NULL, comp_bufs[i],
>  					data_size,
>  					ts_params->small_mbuf_pool,
> @@ -761,8 +775,12 @@ test_deflate_comp_decomp(const struct
> interim_data_params *int_data,
> 
>  	} else {
>  		for (i = 0; i < num_bufs; i++) {
> -			data_size = strlen(test_bufs[i]) *
> -				COMPRESS_BUF_SIZE_RATIO;
> +			if (out_of_space == 1 && oos_zlib_decompress) {
> +				data_size = OUT_OF_SPACE_BUF;
> +			} else {
> +				(data_size = strlen(test_bufs[i]) *
> +					COMPRESS_BUF_SIZE_RATIO);

Same here.

> +			}
>  			rte_pktmbuf_append(comp_bufs[i], data_size);
>  		}
>  	}
> @@ -928,6 +946,18 @@ test_deflate_comp_decomp(const struct
> interim_data_params *int_data,
>  	 * compress operation information is needed for the decompression
> stage)
>  	 */
>  	for (i = 0; i < num_bufs; i++) {
> +		if (out_of_space && oos_zlib_decompress) {
> +			if (ops_processed[i]->status !=
> +
> 	RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED) {

Better to add an extra tab here, even though you cross the 80 char limit.

> +				ret_status = -1;
> +
> +				RTE_LOG(ERR, USER1,
> +				"Out of Space operation was not
> successful\n");

I would reword this to something more clear, like:
Operation without expected out of space status error.
Also, make these changes in the decompression side of the function (code below).
Apart from this:

Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
  

Patch

diff --git a/test/test/test_compressdev.c b/test/test/test_compressdev.c
index 20895fc..1e41113 100644
--- a/test/test/test_compressdev.c
+++ b/test/test/test_compressdev.c
@@ -42,6 +42,8 @@ 
 #define GZIP_HEADER_SIZE 10
 #define GZIP_TRAILER_SIZE 8
 
+#define OUT_OF_SPACE_BUF 1
+
 const char *
 huffman_type_strings[] = {
 	[RTE_COMP_HUFFMAN_DEFAULT]	= "PMD default",
@@ -81,6 +83,7 @@  struct test_data_params {
 	enum rte_comp_op_type state;
 	unsigned int sgl;
 	enum zlib_direction zlib_dir;
+	unsigned int out_of_space;
 };
 
 static struct comp_testsuite_params testsuite_params = { 0 };
@@ -677,6 +680,7 @@  test_deflate_comp_decomp(const struct interim_data_params *int_data,
 	unsigned int num_xforms = int_data->num_xforms;
 	enum rte_comp_op_type state = test_data->state;
 	unsigned int sgl = test_data->sgl;
+	unsigned int out_of_space = test_data->out_of_space;
 	enum zlib_direction zlib_dir = test_data->zlib_dir;
 	int ret_status = -1;
 	int ret;
@@ -693,6 +697,12 @@  test_deflate_comp_decomp(const struct interim_data_params *int_data,
 	unsigned int i;
 	struct rte_mempool *buf_pool;
 	uint32_t data_size;
+	/* Compressing with CompressDev */
+	unsigned int oos_zlib_decompress =
+			(zlib_dir == ZLIB_NONE || zlib_dir == ZLIB_DECOMPRESS);
+	/* Decompressing with CompressDev */
+	unsigned int oos_zlib_compress =
+			(zlib_dir == ZLIB_NONE || zlib_dir == ZLIB_COMPRESS);
 	const struct rte_compressdev_capabilities *capa =
 		rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
 	char *contig_buf = NULL;
@@ -749,8 +759,12 @@  test_deflate_comp_decomp(const struct interim_data_params *int_data,
 
 	if (sgl) {
 		for (i = 0; i < num_bufs; i++) {
-			data_size = strlen(test_bufs[i]) *
-				COMPRESS_BUF_SIZE_RATIO;
+			if (out_of_space == 1 && oos_zlib_decompress) {
+				data_size = OUT_OF_SPACE_BUF;
+			} else {
+				(data_size = strlen(test_bufs[i]) *
+					COMPRESS_BUF_SIZE_RATIO);
+			}
 			if (prepare_sgl_bufs(NULL, comp_bufs[i],
 					data_size,
 					ts_params->small_mbuf_pool,
@@ -761,8 +775,12 @@  test_deflate_comp_decomp(const struct interim_data_params *int_data,
 
 	} else {
 		for (i = 0; i < num_bufs; i++) {
-			data_size = strlen(test_bufs[i]) *
-				COMPRESS_BUF_SIZE_RATIO;
+			if (out_of_space == 1 && oos_zlib_decompress) {
+				data_size = OUT_OF_SPACE_BUF;
+			} else {
+				(data_size = strlen(test_bufs[i]) *
+					COMPRESS_BUF_SIZE_RATIO);
+			}
 			rte_pktmbuf_append(comp_bufs[i], data_size);
 		}
 	}
@@ -928,6 +946,18 @@  test_deflate_comp_decomp(const struct interim_data_params *int_data,
 	 * compress operation information is needed for the decompression stage)
 	 */
 	for (i = 0; i < num_bufs; i++) {
+		if (out_of_space && oos_zlib_decompress) {
+			if (ops_processed[i]->status !=
+				RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED) {
+				ret_status = -1;
+
+				RTE_LOG(ERR, USER1,
+				"Out of Space operation was not successful\n");
+				goto exit;
+			} else
+				continue;
+		}
+
 		if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
 			RTE_LOG(ERR, USER1,
 				"Some operations were not successful\n");
@@ -938,6 +968,11 @@  test_deflate_comp_decomp(const struct interim_data_params *int_data,
 		uncomp_bufs[priv_data->orig_idx] = NULL;
 	}
 
+	if (out_of_space && oos_zlib_decompress) {
+		ret_status = 0;
+		goto exit;
+	}
+
 	/* Allocate buffers for decompressed data */
 	ret = rte_pktmbuf_alloc_bulk(buf_pool, uncomp_bufs, num_bufs);
 	if (ret < 0) {
@@ -951,7 +986,12 @@  test_deflate_comp_decomp(const struct interim_data_params *int_data,
 		for (i = 0; i < num_bufs; i++) {
 			priv_data = (struct priv_op_data *)
 					(ops_processed[i] + 1);
-			data_size = strlen(test_bufs[priv_data->orig_idx]) + 1;
+			if (out_of_space == 1 && oos_zlib_compress)
+				data_size = OUT_OF_SPACE_BUF;
+			else
+				data_size =
+				strlen(test_bufs[priv_data->orig_idx]) + 1;
+
 			if (prepare_sgl_bufs(NULL, uncomp_bufs[i],
 					data_size,
 					ts_params->small_mbuf_pool,
@@ -964,7 +1004,12 @@  test_deflate_comp_decomp(const struct interim_data_params *int_data,
 		for (i = 0; i < num_bufs; i++) {
 			priv_data = (struct priv_op_data *)
 					(ops_processed[i] + 1);
-			data_size = strlen(test_bufs[priv_data->orig_idx]) + 1;
+			if (out_of_space == 1 && oos_zlib_compress)
+				data_size = OUT_OF_SPACE_BUF;
+			else
+				data_size =
+				strlen(test_bufs[priv_data->orig_idx]) + 1;
+
 			rte_pktmbuf_append(uncomp_bufs[i], data_size);
 		}
 	}
@@ -1125,6 +1170,18 @@  test_deflate_comp_decomp(const struct interim_data_params *int_data,
 	 * compress operation information is still needed)
 	 */
 	for (i = 0; i < num_bufs; i++) {
+		if (out_of_space && oos_zlib_compress) {
+			if (ops_processed[i]->status !=
+				RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED) {
+				ret_status = -1;
+
+				RTE_LOG(ERR, USER1,
+				"Out of Space operation was not successful\n");
+				goto exit;
+			} else
+				continue;
+		}
+
 		if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
 			RTE_LOG(ERR, USER1,
 				"Some operations were not successful\n");
@@ -1135,6 +1192,11 @@  test_deflate_comp_decomp(const struct interim_data_params *int_data,
 		comp_bufs[priv_data->orig_idx] = NULL;
 	}
 
+	if (out_of_space && oos_zlib_compress) {
+		ret_status = 0;
+		goto exit;
+	}
+
 	/*
 	 * Compare the original stream with the decompressed stream
 	 * (in size and the data)
@@ -1232,7 +1294,8 @@  test_compressdev_deflate_stateless_fixed(void)
 	struct test_data_params test_data = {
 		RTE_COMP_OP_STATELESS,
 		0,
-		ZLIB_DECOMPRESS
+		ZLIB_DECOMPRESS,
+		0
 	};
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
@@ -1301,7 +1364,8 @@  test_compressdev_deflate_stateless_dynamic(void)
 	struct test_data_params test_data = {
 		RTE_COMP_OP_STATELESS,
 		0,
-		ZLIB_DECOMPRESS
+		ZLIB_DECOMPRESS,
+		0
 	};
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
@@ -1353,7 +1417,8 @@  test_compressdev_deflate_stateless_multi_op(void)
 	struct test_data_params test_data = {
 		RTE_COMP_OP_STATELESS,
 		0,
-		ZLIB_DECOMPRESS
+		ZLIB_DECOMPRESS,
+		0
 	};
 
 	/* Compress with compressdev, decompress with Zlib */
@@ -1401,7 +1466,8 @@  test_compressdev_deflate_stateless_multi_level(void)
 	struct test_data_params test_data = {
 		RTE_COMP_OP_STATELESS,
 		0,
-		ZLIB_DECOMPRESS
+		ZLIB_DECOMPRESS,
+		0
 	};
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
@@ -1489,7 +1555,8 @@  test_compressdev_deflate_stateless_multi_xform(void)
 	struct test_data_params test_data = {
 		RTE_COMP_OP_STATELESS,
 		0,
-		ZLIB_DECOMPRESS
+		ZLIB_DECOMPRESS,
+		0
 	};
 
 	/* Compress with compressdev, decompress with Zlib */
@@ -1533,7 +1600,8 @@  test_compressdev_deflate_stateless_sgl(void)
 	struct test_data_params test_data = {
 		RTE_COMP_OP_STATELESS,
 		1,
-		ZLIB_DECOMPRESS
+		ZLIB_DECOMPRESS,
+		0
 	};
 
 	for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
@@ -1609,7 +1677,8 @@  test_compressdev_deflate_stateless_checksum(void)
 	struct test_data_params test_data = {
 		RTE_COMP_OP_STATELESS,
 		0,
-		ZLIB_DECOMPRESS
+		ZLIB_DECOMPRESS,
+		0
 	};
 
 	/* Check if driver supports crc32 checksum and test */
@@ -1700,6 +1769,87 @@  test_compressdev_deflate_stateless_checksum(void)
 	return ret;
 }
 
+static int
+test_compressdev_out_of_space_buffer(void)
+{
+	struct comp_testsuite_params *ts_params = &testsuite_params;
+	int ret;
+	uint16_t i;
+	const struct rte_compressdev_capabilities *capab;
+
+	RTE_LOG(INFO, USER1, "This is a negative test errors are expected\n");
+
+	capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
+	TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
+
+	if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0)
+		return -ENOTSUP;
+
+	struct rte_comp_xform *compress_xform =
+			rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
+
+	if (compress_xform == NULL) {
+		RTE_LOG(ERR, USER1,
+			"Compress xform could not be created\n");
+		ret = TEST_FAILED;
+		goto exit;
+	}
+
+	struct interim_data_params int_data = {
+		&compress_test_bufs[0],
+		1,
+		&i,
+		&ts_params->def_comp_xform,
+		&ts_params->def_decomp_xform,
+		1
+	};
+
+	struct test_data_params test_data = {
+		RTE_COMP_OP_STATELESS,
+		0,
+		ZLIB_DECOMPRESS,
+		1
+	};
+	/* Compress with compressdev, decompress with Zlib */
+	test_data.zlib_dir = ZLIB_DECOMPRESS;
+	if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+		ret = TEST_FAILED;
+		goto exit;
+	}
+
+	/* Compress with Zlib, decompress with compressdev */
+	test_data.zlib_dir = ZLIB_COMPRESS;
+	if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+		ret = TEST_FAILED;
+		goto exit;
+	}
+
+	if (capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
+		/* Compress with compressdev, decompress with Zlib */
+		test_data.zlib_dir = ZLIB_DECOMPRESS;
+		test_data.sgl = 1;
+		if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
+
+		/* Compress with Zlib, decompress with compressdev */
+		test_data.zlib_dir = ZLIB_COMPRESS;
+		test_data.sgl = 1;
+		if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
+			ret = TEST_FAILED;
+			goto exit;
+		}
+	}
+
+	ret  = TEST_SUCCESS;
+
+exit:
+	rte_free(compress_xform);
+	return ret;
+}
+
+
 static struct unit_test_suite compressdev_testsuite  = {
 	.suite_name = "compressdev unit test suite",
 	.setup = testsuite_setup,
@@ -1721,6 +1871,8 @@  static struct unit_test_suite compressdev_testsuite  = {
 			test_compressdev_deflate_stateless_sgl),
 		TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
 			test_compressdev_deflate_stateless_checksum),
+		TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
+			test_compressdev_out_of_space_buffer),
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };